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

(-)a/C4/Members.pm (-24 / +42 lines)
Lines 753-758 sub ModMember { Link Here
753
            $data{password} = md5_base64($data{password});
753
            $data{password} = md5_base64($data{password});
754
        }
754
        }
755
    }
755
    }
756
    my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
756
	my $execute_success=UpdateInTable("borrowers",\%data);
757
	my $execute_success=UpdateInTable("borrowers",\%data);
757
    if ($execute_success) { # only proceed if the update was a success
758
    if ($execute_success) { # only proceed if the update was a success
758
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
759
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
Lines 763-774 sub ModMember { Link Here
763
            # is adult check guarantees;
764
            # is adult check guarantees;
764
            UpdateGuarantees(%data);
765
            UpdateGuarantees(%data);
765
        }
766
        }
767
768
        # If the patron changes to a category with enrollment fee, we add a fee
769
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
770
            AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
771
        }
772
766
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
773
        logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
767
    }
774
    }
768
    return $execute_success;
775
    return $execute_success;
769
}
776
}
770
777
771
772
=head2 AddMember
778
=head2 AddMember
773
779
774
  $borrowernumber = &AddMember(%borrower);
780
  $borrowernumber = &AddMember(%borrower);
Lines 805-823 sub AddMember { Link Here
805
811
806
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
812
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
807
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
813
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
808
    
814
809
    # check for enrollment fee & add it if needed
815
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
810
    my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
811
    $sth->execute($data{'categorycode'});
812
    my ($enrolmentfee) = $sth->fetchrow;
813
    if ($sth->err) {
814
        warn sprintf('Database returned the following error: %s', $sth->errstr);
815
        return;
816
    }
817
    if ($enrolmentfee && $enrolmentfee > 0) {
818
        # insert fee in patron debts
819
        manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
820
    }
821
816
822
    return $data{'borrowernumber'};
817
    return $data{'borrowernumber'};
823
}
818
}
Lines 1877-1891 UPDATE borrowers Link Here
1877
SET  dateexpiry='$date' 
1872
SET  dateexpiry='$date' 
1878
WHERE borrowernumber='$borrowerid'
1873
WHERE borrowernumber='$borrowerid'
1879
EOF
1874
EOF
1880
    # add enrolmentfee if needed
1875
1881
    $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
1876
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
1882
    $sth->execute($borrower->{'categorycode'});
1877
1883
    my ($enrolmentfee) = $sth->fetchrow;
1878
    logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog");
1884
    if ($enrolmentfee && $enrolmentfee > 0) {
1885
        # insert fee in patron debts
1886
        manualinvoice($borrower->{'borrowernumber'}, '', '', 'A', $enrolmentfee);
1887
    }
1888
     logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog");
1889
    return $date if ($sth);
1879
    return $date if ($sth);
1890
    return 0;
1880
    return 0;
1891
}
1881
}
Lines 2541-2546 sub AddMember_Opac { Link Here
2541
    return ( $borrowernumber, $password );
2531
    return ( $borrowernumber, $password );
2542
}
2532
}
2543
2533
2534
=head2 AddEnroltmenFeeIfNeeded
2535
2536
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
2537
2538
Add enrolment fee for a patron if needed.
2539
2540
=cut
2541
2542
sub AddEnrolmentFeeIfNeeded {
2543
    my ( $categorycode, $borrowernumber ) = @_;
2544
    # check for enrollment fee & add it if needed
2545
    my $dbh = C4::Context->dbh;
2546
    my $sth = $dbh->prepare(q{
2547
        SELECT enrolmentfee
2548
        FROM categories
2549
        WHERE categorycode=?
2550
    });
2551
    $sth->execute( $categorycode );
2552
    if ( $sth->err ) {
2553
        warn sprintf('Database returned the following error: %s', $sth->errstr);
2554
        return;
2555
    }
2556
    my ($enrolmentfee) = $sth->fetchrow;
2557
    if ($enrolmentfee && $enrolmentfee > 0) {
2558
        # insert fee in patron debts
2559
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
2560
    }
2561
}
2562
2544
END { }    # module clean-up code here (global destructor)
2563
END { }    # module clean-up code here (global destructor)
2545
2564
2546
1;
2565
1;
2547
- 

Return to bug 10481