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

(-)a/Koha/Patron.pm (+47 lines)
Lines 21-26 package Koha::Patron; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use List::MoreUtils    qw( any none uniq notall zip6);
23
use List::MoreUtils    qw( any none uniq notall zip6);
24
use Scalar::Util       qw( looks_like_number );
24
use JSON               qw( to_json );
25
use JSON               qw( to_json );
25
use Unicode::Normalize qw( NFKD );
26
use Unicode::Normalize qw( NFKD );
26
use Try::Tiny;
27
use Try::Tiny;
Lines 1653-1658 sub add_enrolment_fee_if_needed { Link Here
1653
    return $enrolment_fee || 0;
1654
    return $enrolment_fee || 0;
1654
}
1655
}
1655
1656
1657
=head3 add_print_notice_charge_if_needed
1658
1659
my $result = $patron->add_print_notice_charge_if_needed($params);
1660
1661
Add a print notice charge for a patron if needed.
1662
1663
$params - hash reference containing:
1664
  - amount: charge amount (optional, uses system preference if not provided)
1665
  - notice_code: the notice code for the charge description
1666
  - library_id: library branch for the charge (optional)
1667
1668
Returns the account line object if a charge was added, undef otherwise.
1669
1670
=cut
1671
1672
sub add_print_notice_charge_if_needed {
1673
    my ( $self, $params ) = @_;
1674
1675
    return unless $params && ref($params) eq 'HASH';
1676
1677
    # Get charge amount from patron category (0 = disabled)
1678
    my $charge_amount = defined $params->{amount} ? $params->{amount} : $self->category->print_notice_charge;
1679
1680
    # Return early for invalid amounts
1681
    return unless defined $charge_amount;
1682
    return unless Scalar::Util::looks_like_number($charge_amount);
1683
    return unless $charge_amount > 0;
1684
1685
    my $userenv = C4::Context->userenv;
1686
    my $library_id = $params->{library_id} || ($userenv ? $userenv->{branch} : undef);
1687
1688
    my $result;
1689
    try {
1690
        $result = $self->account->add_debit({
1691
            amount      => $charge_amount,
1692
            type        => 'PRINT_NOTICE',
1693
            interface   => C4::Context->interface,
1694
            library_id  => $library_id,
1695
        });
1696
    } catch {
1697
        return;
1698
    };
1699
1700
    return $result;
1701
}
1702
1656
=head3 checkouts
1703
=head3 checkouts
1657
1704
1658
my $checkouts = $patron->checkouts
1705
my $checkouts = $patron->checkouts
(-)a/admin/categories.pl (+3 lines)
Lines 64-69 if ( $op eq 'add_form' ) { Link Here
64
    my $dateofbirthrequired                    = $input->param('dateofbirthrequired');
64
    my $dateofbirthrequired                    = $input->param('dateofbirthrequired');
65
    my $enrolmentfee                           = $input->param('enrolmentfee');
65
    my $enrolmentfee                           = $input->param('enrolmentfee');
66
    my $reservefee                             = $input->param('reservefee');
66
    my $reservefee                             = $input->param('reservefee');
67
    my $print_notice_charge                    = $input->param('print_notice_charge');
67
    my $hidelostitems                          = $input->param('hidelostitems');
68
    my $hidelostitems                          = $input->param('hidelostitems');
68
    my $overduenoticerequired                  = $input->param('overduenoticerequired');
69
    my $overduenoticerequired                  = $input->param('overduenoticerequired');
69
    my $category_type                          = $input->param('category_type');
70
    my $category_type                          = $input->param('category_type');
Lines 104-109 if ( $op eq 'add_form' ) { Link Here
104
        $category->dateofbirthrequired($dateofbirthrequired);
105
        $category->dateofbirthrequired($dateofbirthrequired);
105
        $category->enrolmentfee($enrolmentfee);
106
        $category->enrolmentfee($enrolmentfee);
106
        $category->reservefee($reservefee);
107
        $category->reservefee($reservefee);
108
        $category->print_notice_charge($print_notice_charge);
107
        $category->hidelostitems($hidelostitems);
109
        $category->hidelostitems($hidelostitems);
108
        $category->overduenoticerequired($overduenoticerequired);
110
        $category->overduenoticerequired($overduenoticerequired);
109
        $category->category_type($category_type);
111
        $category->category_type($category_type);
Lines 143-148 if ( $op eq 'add_form' ) { Link Here
143
                dateofbirthrequired                    => $dateofbirthrequired,
145
                dateofbirthrequired                    => $dateofbirthrequired,
144
                enrolmentfee                           => $enrolmentfee,
146
                enrolmentfee                           => $enrolmentfee,
145
                reservefee                             => $reservefee,
147
                reservefee                             => $reservefee,
148
                print_notice_charge                    => $print_notice_charge,
146
                hidelostitems                          => $hidelostitems,
149
                hidelostitems                          => $hidelostitems,
147
                overduenoticerequired                  => $overduenoticerequired,
150
                overduenoticerequired                  => $overduenoticerequired,
148
                category_type                          => $category_type,
151
                category_type                          => $category_type,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt (+14 lines)
Lines 208-213 Link Here
208
                        <label for="reservefee">Hold fee: </label>
208
                        <label for="reservefee">Hold fee: </label>
209
                        <input type="text" name="reservefee" id="reservefee" size="6" value="[% category.reservefee | $Price on_editing => 1 %]" />
209
                        <input type="text" name="reservefee" id="reservefee" size="6" value="[% category.reservefee | $Price on_editing => 1 %]" />
210
                    </li>
210
                    </li>
211
                    <li>
212
                        <label for="print_notice_charge">Print notice charge: </label>
213
                        <input type="text" name="print_notice_charge" id="print_notice_charge" size="6" value="[% category.print_notice_charge | $Price on_editing => 1 %]" />
214
                        <div class="hint">Charge for print notices (0.00 = disabled)</div>
215
                    </li>
216
211
                    <li>
217
                    <li>
212
                        <label for="category_type" class="required">Category type: </label>
218
                        <label for="category_type" class="required">Category type: </label>
213
                        <select name="category_type" id="category_type">
219
                        <select name="category_type" id="category_type">
Lines 572-577 Link Here
572
                <tr><th scope="row">Receives overdue notices: </th><td>[% IF category. overduenoticerequired %]Yes[% ELSE %]No[% END %]</td></tr>
578
                <tr><th scope="row">Receives overdue notices: </th><td>[% IF category. overduenoticerequired %]Yes[% ELSE %]No[% END %]</td></tr>
573
                <tr><th scope="row">Lost items in staff interface:</th><td>[% IF category.hidelostitems %]Hidden by default[% ELSE %]Shown[% END %]</td></tr>
579
                <tr><th scope="row">Lost items in staff interface:</th><td>[% IF category.hidelostitems %]Hidden by default[% ELSE %]Shown[% END %]</td></tr>
574
                <tr><th scope="row">Hold fee: </th><td>[% category.reservefee | $Price %]</td></tr>
580
                <tr><th scope="row">Hold fee: </th><td>[% category.reservefee | $Price %]</td></tr>
581
                <tr><th scope="row">Print notice charge: </th><td>[% IF category.print_notice_charge > 0 %][% category.print_notice_charge | $Price %][% ELSE %]Disabled[% END %]</td></tr>
575
582
576
                [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %]
583
                [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %]
577
                    <tr>
584
                    <tr>
Lines 653-658 Link Here
653
                            <th scope="col" data-colname="overdue">Overdue</th>
660
                            <th scope="col" data-colname="overdue">Overdue</th>
654
                            <th scope="col" data-colname="lost_items">Lost items</th>
661
                            <th scope="col" data-colname="lost_items">Lost items</th>
655
                            <th scope="col" data-colname="hold_fee">Hold fee</th>
662
                            <th scope="col" data-colname="hold_fee">Hold fee</th>
663
                            <th scope="col" data-colname="print_notice_charge">Print notice charge</th>
664
656
                            [% IF ( EnhancedMessagingPreferences ) %]
665
                            [% IF ( EnhancedMessagingPreferences ) %]
657
                                <th scope="col" data-colname="messaging">Messaging</th>
666
                                <th scope="col" data-colname="messaging">Messaging</th>
658
                            [% END %]
667
                            [% END %]
Lines 731-736 Link Here
731
                                [% ELSE %]
740
                                [% ELSE %]
732
                                    <td>-</td>
741
                                    <td>-</td>
733
                                [% END %]
742
                                [% END %]
743
                                [% IF (category.print_notice_charge > 0) %]
744
                                    <td>[% category.print_notice_charge | $Price %]</td>
745
                                [% ELSE %]
746
                                    <td>-</td>
747
                                [% END %]
734
                                [% IF Koha.Preference('EnhancedMessagingPreferences') %]
748
                                [% IF Koha.Preference('EnhancedMessagingPreferences') %]
735
                                    <td style="white-space: nowrap; font-size:80%;">
749
                                    <td style="white-space: nowrap; font-size:80%;">
736
                                        [% SET default_messaging = category.default_messaging %]
750
                                        [% SET default_messaging = category.default_messaging %]
(-)a/misc/cronjobs/gather_print_notices.pl (-4 / +2 lines)
Lines 205-211 sub print_notices { Link Here
205
        if ( $send ) {
205
        if ( $send ) {
206
            foreach my $message ( @$branch_messages ) {
206
            foreach my $message ( @$branch_messages ) {
207
                # Apply print notice charges if enabled
207
                # Apply print notice charges if enabled
208
                if (!$skip_charges && C4::Context->preference('PrintNoticeCharging')) {
208
                if (!$skip_charges) {
209
                    apply_print_notice_charge($message);
209
                    apply_print_notice_charge($message);
210
                }
210
                }
211
211
Lines 382-389 sub apply_print_notice_charge { Link Here
382
    }
382
    }
383
383
384
    eval {
384
    eval {
385
        my $account = Koha::Account->new({ patron_id => $patron->borrowernumber });
385
        my $result = $patron->add_print_notice_charge_if_needed({
386
        $account->add_print_notice_charge({
387
            notice_code => $message->{letter_code},
386
            notice_code => $message->{letter_code},
388
            library_id  => $message->{branchcode},
387
            library_id  => $message->{branchcode},
389
        });
388
        });
390
- 

Return to bug 4858