View | Details | Raw Unified | Return to bug 10481
Collapse All | Expand All

(-)a/C4/Members.pm (-24 / +42 lines)
Lines 721-726 sub ModMember { Link Here
721
            $data{password} = md5_base64($data{password});
721
            $data{password} = md5_base64($data{password});
722
        }
722
        }
723
    }
723
    }
724
    my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
724
	my $execute_success=UpdateInTable("borrowers",\%data);
725
	my $execute_success=UpdateInTable("borrowers",\%data);
725
    if ($execute_success) { # only proceed if the update was a success
726
    if ($execute_success) { # only proceed if the update was a success
726
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
727
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
Lines 731-742 sub ModMember { Link Here
731
            # is adult check guarantees;
732
            # is adult check guarantees;
732
            UpdateGuarantees(%data);
733
            UpdateGuarantees(%data);
733
        }
734
        }
735
736
        # If the patron changes to a category with enrollment fee, we add a fee
737
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
738
            AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
739
        }
740
734
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
741
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
735
    }
742
    }
736
    return $execute_success;
743
    return $execute_success;
737
}
744
}
738
745
739
740
=head2 AddMember
746
=head2 AddMember
741
747
742
  $borrowernumber = &AddMember(%borrower);
748
  $borrowernumber = &AddMember(%borrower);
Lines 773-791 sub AddMember { Link Here
773
779
774
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
780
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
775
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
781
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
776
    
782
777
    # check for enrollment fee & add it if needed
783
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
778
    my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
779
    $sth->execute($data{'categorycode'});
780
    my ($enrolmentfee) = $sth->fetchrow;
781
    if ($sth->err) {
782
        warn sprintf('Database returned the following error: %s', $sth->errstr);
783
        return;
784
    }
785
    if ($enrolmentfee && $enrolmentfee > 0) {
786
        # insert fee in patron debts
787
        manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
788
    }
789
784
790
    return $data{'borrowernumber'};
785
    return $data{'borrowernumber'};
791
}
786
}
Lines 1845-1859 UPDATE borrowers Link Here
1845
SET  dateexpiry='$date' 
1840
SET  dateexpiry='$date' 
1846
WHERE borrowernumber='$borrowerid'
1841
WHERE borrowernumber='$borrowerid'
1847
EOF
1842
EOF
1848
    # add enrolmentfee if needed
1843
1849
    $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
1844
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
1850
    $sth->execute($borrower->{'categorycode'});
1845
1851
    my ($enrolmentfee) = $sth->fetchrow;
1846
    logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog");
1852
    if ($enrolmentfee && $enrolmentfee > 0) {
1853
        # insert fee in patron debts
1854
        manualinvoice($borrower->{'borrowernumber'}, '', '', 'A', $enrolmentfee);
1855
    }
1856
     logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog");
1857
    return $date if ($sth);
1847
    return $date if ($sth);
1858
    return 0;
1848
    return 0;
1859
}
1849
}
Lines 2509-2514 sub AddMember_Opac { Link Here
2509
    return ( $borrowernumber, $password );
2499
    return ( $borrowernumber, $password );
2510
}
2500
}
2511
2501
2502
=head2 AddEnroltmenFeeIfNeeded
2503
2504
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
2505
2506
Add enrolment fee for a patron if needed.
2507
2508
=cut
2509
2510
sub AddEnrolmentFeeIfNeeded {
2511
    my ( $categorycode, $borrowernumber ) = @_;
2512
    # check for enrollment fee & add it if needed
2513
    my $dbh = C4::Context->dbh;
2514
    my $sth = $dbh->prepare(q{
2515
        SELECT enrolmentfee
2516
        FROM categories
2517
        WHERE categorycode=?
2518
    });
2519
    $sth->execute( $categorycode );
2520
    if ( $sth->err ) {
2521
        warn sprintf('Database returned the following error: %s', $sth->errstr);
2522
        return;
2523
    }
2524
    my ($enrolmentfee) = $sth->fetchrow;
2525
    if ($enrolmentfee && $enrolmentfee > 0) {
2526
        # insert fee in patron debts
2527
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
2528
    }
2529
}
2530
2512
END { }    # module clean-up code here (global destructor)
2531
END { }    # module clean-up code here (global destructor)
2513
2532
2514
1;
2533
1;
2515
- 

Return to bug 10481