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

(-)a/C4/Members.pm (-37 / +7 lines)
Lines 535-553 sub ModMember { Link Here
535
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
535
    $new_borrower->{dateexpiry}      ||= undef if exists $new_borrower->{dateexpiry};
536
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
536
    $new_borrower->{debarred}        ||= undef if exists $new_borrower->{debarred};
537
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
537
    $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
538
    $new_borrower->{guarantorid}     ||= undef if exists $new_borrower->{guarantorid};
538
539
539
    my $rs = $schema->resultset('Borrower')->search({
540
    my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
540
        borrowernumber => $new_borrower->{borrowernumber},
541
     });
542
541
543
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
542
    delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
544
543
545
    my $execute_success = $rs->update($new_borrower);
544
    my $execute_success = $patron->store if $patron->set($new_borrower);
546
    if ($execute_success ne '0E0') { # only proceed if the update was a success
545
546
    if ($execute_success) { # only proceed if the update was a success
547
        # If the patron changes to a category with enrollment fee, we add a fee
547
        # If the patron changes to a category with enrollment fee, we add a fee
548
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
548
        if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
549
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
549
            if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
550
                AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
550
                $patron->add_enrolment_fee_if_needed;
551
            }
551
            }
552
        }
552
        }
553
553
Lines 651-660 sub AddMember { Link Here
651
        });
651
        });
652
    }
652
    }
653
653
654
    # mysql_insertid is probably bad.  not necessarily accurate and mysql-specific at best.
655
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
654
    logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
656
655
657
    AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
656
    $patron->add_enrolment_fee_if_needed;
658
657
659
    return $data{borrowernumber};
658
    return $data{borrowernumber};
660
}
659
}
Lines 1680-1714 sub AddMember_Opac { Link Here
1680
    return ( $borrowernumber, $borrower{'password'} );
1679
    return ( $borrowernumber, $borrower{'password'} );
1681
}
1680
}
1682
1681
1683
=head2 AddEnrolmentFeeIfNeeded
1684
1685
    AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
1686
1687
Add enrolment fee for a patron if needed.
1688
1689
=cut
1690
1691
sub AddEnrolmentFeeIfNeeded {
1692
    my ( $categorycode, $borrowernumber ) = @_;
1693
    # check for enrollment fee & add it if needed
1694
    my $dbh = C4::Context->dbh;
1695
    my $sth = $dbh->prepare(q{
1696
        SELECT enrolmentfee
1697
        FROM categories
1698
        WHERE categorycode=?
1699
    });
1700
    $sth->execute( $categorycode );
1701
    if ( $sth->err ) {
1702
        warn sprintf('Database returned the following error: %s', $sth->errstr);
1703
        return;
1704
    }
1705
    my ($enrolmentfee) = $sth->fetchrow;
1706
    if ($enrolmentfee && $enrolmentfee > 0) {
1707
        # insert fee in patron debts
1708
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
1709
    }
1710
}
1711
1712
=head2 DeleteExpiredOpacRegistrations
1682
=head2 DeleteExpiredOpacRegistrations
1713
1683
1714
    Delete accounts that haven't been upgraded from the 'temporary' category
1684
    Delete accounts that haven't been upgraded from the 'temporary' category
(-)a/Koha/Patron.pm (-2 / +20 lines)
Lines 305-311 sub renew_account { Link Here
305
305
306
    $self->dateexpiry($expiry_date)->store;
306
    $self->dateexpiry($expiry_date)->store;
307
307
308
    C4::Members::AddEnrolmentFeeIfNeeded( $self->categorycode, $self->borrowernumber );
308
    $self->add_enrolment_fee_if_needed;
309
309
310
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
310
    logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog");
311
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
311
    return dt_from_string( $expiry_date )->truncate( to => 'day' );
Lines 359-364 sub move_to_deleted { Link Here
359
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
359
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
360
}
360
}
361
361
362
=head3 add_enrolment_fee_if_needed
363
364
my $enrolment_fee = $patron->add_enrolment_fee_if_needed;
365
366
Add enrolment fee for a patron if needed.
367
368
=cut
369
370
sub add_enrolment_fee_if_needed {
371
    my ($self) = @_;
372
    my $patron_category = Koha::Patron::Categories->find( $self->categorycode );
373
    my $enrolment_fee = $patron_category->enrolmentfee;
374
    if ( $enrolment_fee && $enrolment_fee > 0 ) {
375
        # insert fee in patron debts
376
        C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee );
377
    }
378
    return $enrolment_fee || 0;
379
}
380
362
=head3 type
381
=head3 type
363
382
364
=cut
383
=cut
365
- 

Return to bug 16912