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

(-)a/C4/Members.pm (-39 / +9 lines)
Lines 590-608 sub ModMember { Link Here
590
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
590
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
591
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
591
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
592
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
592
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
593
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
593
594
594
    my $rs = $schema->resultset('Borrower')->search({
595
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
595
        borrowernumber => $new_borrower->{borrowernumber},
596
     });
597
596
598
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
597
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
599
598
600
    my $execute_success = $rs->update($new_borrower);
599
    my $execute_success = $patron->store if $patron->set($new_borrower);
601
    if ($execute_success ne '0E0') { # only proceed if the update was a success
600
601
    if ($execute_success) { # only proceed if the update was a success
602
        # If the patron changes to a category with enrollment fee, we add a fee
602
        # If the patron changes to a category with enrollment fee, we add a fee
603
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
603
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
604
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
604
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
605
                AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
605
                $patron->add_enrolment_fee_if_needed;
606
            }
606
            }
607
        }
607
        }
608
608
Lines 690-697 sub AddMember { Link Here
690
    $new_member->{checkprevcheckout} ||= 'inherit';
690
    $new_member->{checkprevcheckout} ||= 'inherit';
691
    delete $new_member->{borrowernumber};
691
    delete $new_member->{borrowernumber};
692
692
693
    my $rs = $schema->resultset('Borrower');
693
    my $patron = Koha::Patron->new($new_member)->store;
694
    $data{borrowernumber} = $rs->create($new_member)->id;
694
    $data{borrowernumber} = $patron->id;
695
695
696
    # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
696
    # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
697
    # cronjob will use for syncing with NL
697
    # cronjob will use for syncing with NL
Lines 705-714 sub AddMember { Link Here
705
        });
705
        });
706
    }
706
    }
707
707
708
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
709
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
708
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
710
709
711
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
710
    $patron->add_enrolment_fee_if_needed;
712
711
713
    return $data{borrowernumber};
712
    return $data{borrowernumber};
714
}
713
}
Lines 1968-2002 sub AddMember_Opac { Link Here
1968
    return ( $borrowernumber, $borrower{'password'} );
1967
    return ( $borrowernumber, $borrower{'password'} );
1969
}
1968
}
1970
1969
1971
=head2 AddEnrolmentFeeIfNeeded
1972
1973
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
1974
1975
Add enrolment fee for a patron if needed.
1976
1977
=cut
1978
1979
sub AddEnrolmentFeeIfNeeded {
1980
    my ( $categorycode, $borrowernumber ) = @_;
1981
    # check for enrollment fee & add it if needed
1982
    my $dbh = C4::Context->dbh;
1983
    my $sth = $dbh->prepare(q{
1984
        SELECT enrolmentfee
1985
        FROM categories
1986
        WHERE categorycode=?
1987
    });
1988
    $sth->execute( $categorycode );
1989
    if ( $sth->err ) {
1990
        warn sprintf('Database returned the following error: %s', $sth->errstr);
1991
        return;
1992
    }
1993
    my ($enrolmentfee) = $sth->fetchrow;
1994
    if ($enrolmentfee && $enrolmentfee > 0) {
1995
        # insert fee in patron debts
1996
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
1997
    }
1998
}
1999
2000
=head2 HasOverdues
1970
=head2 HasOverdues
2001
1971
2002
=cut
1972
=cut
(-)a/Koha/Patron.pm (-2 / +21 lines)
Lines 229-240 sub renew_account { Link Here
229
229
230
    $self->dateexpiry($expiry_date)->store;
230
    $self->dateexpiry($expiry_date)->store;
231
231
232
    C4::Members::AddEnrolmentFeeIfNeeded( $self->categorycode, $self->borrowernumber );
232
    $self->add_enrolment_fee_if_needed;
233
233
234
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
234
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
235
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
235
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
236
}
236
}
237
237
238
239
=head3 add_enrolment_fee_if_needed
240
241
my $enrolment_fee = $patron->add_enrolment_fee_if_needed;
242
243
Add enrolment fee for a patron if needed.
244
245
=cut
246
247
sub add_enrolment_fee_if_needed {
248
    my ($self) = @_;
249
    my $patron_category = Koha::Patron::Categories->find( $self->categorycode );
250
    my $enrolment_fee = $patron_category->enrolmentfee;
251
    if ( $enrolment_fee && $enrolment_fee > 0 ) {
252
        # insert fee in patron debts
253
        C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee );
254
    }
255
    return $enrolment_fee || 0;
256
}
257
238
=head3 type
258
=head3 type
239
259
240
=cut
260
=cut
241
- 

Return to bug 16912