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

(-)a/C4/Members.pm (-39 / +9 lines)
Lines 541-559 sub ModMember { Link Here
541
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
541
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
542
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
542
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
543
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
543
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
544
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
544
545
545
    my $rs = $schema->resultset('Borrower')->search({
546
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
546
        borrowernumber => $new_borrower->{borrowernumber},
547
     });
548
547
549
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
548
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
550
549
551
    my $execute_success = $rs->update($new_borrower);
550
    my $execute_success = $patron->store if $patron->set($new_borrower);
552
    if ($execute_success ne '0E0') { # only proceed if the update was a success
551
552
    if ($execute_success) { # only proceed if the update was a success
553
        # If the patron changes to a category with enrollment fee, we add a fee
553
        # If the patron changes to a category with enrollment fee, we add a fee
554
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
554
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
555
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
555
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
556
                AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
556
                $patron->add_enrolment_fee_if_needed;
557
            }
557
            }
558
        }
558
        }
559
559
Lines 641-648 sub AddMember { Link Here
641
    $new_member->{checkprevcheckout} ||= 'inherit';
641
    $new_member->{checkprevcheckout} ||= 'inherit';
642
    delete $new_member->{borrowernumber};
642
    delete $new_member->{borrowernumber};
643
643
644
    my $rs = $schema->resultset('Borrower');
644
    my $patron = Koha::Patron->new($new_member)->store;
645
    $data{borrowernumber} = $rs->create($new_member)->id;
645
    $data{borrowernumber} = $patron->id;
646
646
647
    # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
647
    # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
648
    # cronjob will use for syncing with NL
648
    # cronjob will use for syncing with NL
Lines 656-665 sub AddMember { Link Here
656
        });
656
        });
657
    }
657
    }
658
658
659
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
660
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
659
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
661
660
662
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
661
    $patron->add_enrolment_fee_if_needed;
663
662
664
    return $data{borrowernumber};
663
    return $data{borrowernumber};
665
}
664
}
Lines 1771-1805 sub AddMember_Opac { Link Here
1771
    return ( $borrowernumber, $borrower{'password'} );
1770
    return ( $borrowernumber, $borrower{'password'} );
1772
}
1771
}
1773
1772
1774
=head2 AddEnrolmentFeeIfNeeded
1775
1776
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
1777
1778
Add enrolment fee for a patron if needed.
1779
1780
=cut
1781
1782
sub AddEnrolmentFeeIfNeeded {
1783
    my ( $categorycode, $borrowernumber ) = @_;
1784
    # check for enrollment fee & add it if needed
1785
    my $dbh = C4::Context->dbh;
1786
    my $sth = $dbh->prepare(q{
1787
        SELECT enrolmentfee
1788
        FROM categories
1789
        WHERE categorycode=?
1790
    });
1791
    $sth->execute( $categorycode );
1792
    if ( $sth->err ) {
1793
        warn sprintf('Database returned the following error: %s', $sth->errstr);
1794
        return;
1795
    }
1796
    my ($enrolmentfee) = $sth->fetchrow;
1797
    if ($enrolmentfee && $enrolmentfee > 0) {
1798
        # insert fee in patron debts
1799
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
1800
    }
1801
}
1802
1803
=head2 DeleteExpiredOpacRegistrations
1773
=head2 DeleteExpiredOpacRegistrations
1804
1774
1805
    Delete accounts that haven't been upgraded from the 'temporary' category
1775
    Delete accounts that haven't been upgraded from the 'temporary' category
(-)a/Koha/Patron.pm (-2 / +20 lines)
Lines 228-234 sub renew_account { Link Here
228
228
229
    $self->dateexpiry($expiry_date)->store;
229
    $self->dateexpiry($expiry_date)->store;
230
230
231
    C4::Members::AddEnrolmentFeeIfNeeded( $self->categorycode, $self->borrowernumber );
231
    $self->add_enrolment_fee_if_needed;
232
232
233
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
233
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
234
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
234
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
Lines 267-272 sub track_login { Link Here
267
    $self->lastseen( dt_from_string() )->store;
267
    $self->lastseen( dt_from_string() )->store;
268
}
268
}
269
269
270
=head3 add_enrolment_fee_if_needed
271
272
my $enrolment_fee = $patron->add_enrolment_fee_if_needed;
273
274
Add enrolment fee for a patron if needed.
275
276
=cut
277
278
sub add_enrolment_fee_if_needed {
279
    my ($self) = @_;
280
    my $patron_category = Koha::Patron::Categories->find( $self->categorycode );
281
    my $enrolment_fee = $patron_category->enrolmentfee;
282
    if ( $enrolment_fee && $enrolment_fee > 0 ) {
283
        # insert fee in patron debts
284
        C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee );
285
    }
286
    return $enrolment_fee || 0;
287
}
288
270
=head3 type
289
=head3 type
271
290
272
=cut
291
=cut
273
- 

Return to bug 16912