use Modern::Perl;
return {
bug_number => "24381",
description => "Update accounts notices",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
# ACCOUNT_CREDIT
my $account_credit = q{
[%- USE AuthorisedValues -%]
[%- USE KohaDates -%]
[%- USE Price -%]
[%- PROCESS "accounts.inc" -%]
[% IF ( LibraryName ) %]
[% LibraryName | html %]
|
[% END %]
[% IF credit.library %]
[% credit.library.branchname | html %]
|
[% END %]
[% today | $KohaDates %]
|
Transaction ID: |
[% credit.accountlines_id %] |
Operator ID: |
[% credit.manager_id %] |
[% IF credit.payment_type %]
Payment type: |
[% AuthorisedValues.GetByCode('PAYMENT_TYPE', credit.payment_type) %] |
[% END %]
[%- PROCESS credit_type_description credit_type = credit.credit_type -%] receipt
|
[% IF ( credit.credit_type_code == 'PAYMENT' ) %]
Received with thanks from [% credit.patron.firstname | html %] [% credit.patron.surname | html %]
Card number: [% credit.patron.cardnumber | html %]
|
[% ELSIF ( credit.credit_type_code == 'CREDIT' ) %]
Credit added to account for [% credit.patron.firstname | html %] [% credit.patron.surname | html %]
Card number: [% credit.patron.cardnumber | html %]
|
[% ELSIF ( credit.credit_type_code == 'WRITEOFF' ) %]
Writeoff added to account for [% credit.patron.firstname | html %] [% credit.patron.surname | html %]
Card number: [% credit.patron.cardnumber | html %]
|
[% END %]
[% IF credit.amountoutstanding + 0 != 0 %]
Description of credit |
Amount |
[%- PROCESS credit_type_description credit_type = credit.credit_type -%] |
[% credit.amount * -1 | $Price %] |
Total available: |
[% credit.amountoutstanding * -1 | $Price %] |
[% END %]
[% IF credit.amount != credit.amountoutstanding %]
Description of charges |
Amount |
[% FOREACH offset IN credit.credit_offsets %]
[% PROCESS account_type_description account=offset.debit %][% IF ( offset.debit.itemnumber ) %] - [% offset.debit.item.biblio.title %][% END %] |
[% offset.amount * -1 | $Price %] |
[% END %]
[% END %]
Total: |
[% credit.amount * -1 | $Price %] |
[% IF change.defined %]
Change given: |
[% change | $Price %] |
[% END %]
|
Account balance as on date: |
[% credit.patron.account.balance * -1 | $Price %] |
};
my $account_credit_old = q{[%IF(LibraryName)%][%LibraryName|html%]
[%END%]Feereceipt
|
[%Branches.GetName(patron.branchcode)|html%]
|
Receivedwiththanksfrom[%patron.firstname|html%][%patron.surname|html%]
Cardnumber:[%patron.cardnumber|html%]
Date | Descriptionofcharges | Note | Amount |
[%FOREACHaccountINaccounts%][%account.date|$KohaDates%] | [%PROCESSaccount_type_descriptionaccount=account%][%-IFaccount.description%],[%account.description|html%][%END%] | [%account.note|html%] | [%IF(account.amountcredit)%][%ELSE%][%END%][%account.amount|$Price%][%END%]Totaloutstandingduesasondate:[%IF(totalcredit)%][%ELSE%][%END%][%total|$Price%]
};
my $sth = $dbh->prepare(q{
UPDATE letter SET content = ? WHERE code = 'ACCOUNT_CREDIT' AND REPLACE(REPLACE(content, ' ', ''), '\n','') = ?
});
$sth->execute( $account_credit, $account_credit_old );
# replace patron variable with credit.patron
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% credit.patron') WHERE code = 'ACCOUNT_CREDIT' ");
# replace library variable with credit.library.branchname
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% credit.library.branchname') WHERE code = 'ACCOUNT_CREDIT' ");
# replace offsets variable with credit.offsets
$dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' credit.offsets %]') WHERE code = 'ACCOUNT_CREDIT' ");
# replace change_given variable with change
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% change_given', '[% change') WHERE code = 'ACCOUNT_CREDIT' ");
# ACCOUNT_DEBIT
my $account_debit = q{
[% PROCESS "accounts.inc" %]
[%- USE Price -%]
[%- USE KohaDates -%]
[% IF ( LibraryName ) %]
[% LibraryName | html %]
|
[% END %]
[% IF debit.library %]
[% debit.library.branchname | html %]
|
[% END %]
Fee ID: |
[% debit.accountlines_id %] |
[% IF credit.manager_id %]
Operator ID: |
[% credit.manager_id %] |
[% END %]
Invoice
|
Bill to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %]
Card number: [% debit.patron.cardnumber | html %]
|
[% IF debit.amountoutstanding != 0 %]
Date |
Description of charges |
Amount |
[% debit.date | $KohaDates %] |
[% PROCESS account_type_description account=debit %] |
[% debit.amount | $Price %] |
Total owed: |
[% debit.amount | $Price %] |
[% END %]
[% IF debit.amount != debit.amountoutstanding %]
Date |
Description of payments |
Amount |
[% FOREACH offset IN debit.debit_offsets %]
[% offset.credit.date | $KohaDates %] |
[% PROCESS account_type_description account=offset.credit %] |
[% offset.amount * -1 | $Price %] |
[% END %]
Total paid: |
[% debit.amount - debit.amountoutstanding | $Price %] |
[% END %]
|
Total outstanding: |
[% debit.amountoutstanding | $Price %] |
};
my $account_debit_old = q{[%IF(LibraryName)%][%LibraryName|html%]
[%END%]INVOICE
|
[%Branches.GetName(patron.branchcode)|html%]
|
Billto:[%patron.firstname|html%][%patron.surname|html%]
Cardnumber:[%patron.cardnumber|html%]
Date | Descriptionofcharges | Note | AmountAmountoutstanding
[%FOREACHaccountINaccounts%][%account.date|$KohaDates%] | [%PROCESSaccount_type_descriptionaccount=account%][%-IFaccount.description%],[%account.description|html%][%END%] | [%account.note|html%] | [%IF(account.amountcredit)%][%ELSE%][%END%][%account.amount|$Price%][%IF(account.amountoutstandingcredit)%][%ELSE%][%END%][%account.amountoutstanding|$Price%][%END%]Totaloutstandingduesasondate:[%IF(totalcredit)%][%ELSE%][%END%][%total|$Price%]
};
$sth = $dbh->prepare(q{
UPDATE letter SET content = ? WHERE code = 'ACCOUNT_DEBIT' AND REPLACE(REPLACE(content, ' ', ''), '\n','') = ?
});
$sth->execute($account_debit, $account_debit_old);
# replace patron variable with debit.patron
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% debit.patron') WHERE code = 'ACCOUNT_DEBIT' ");
# replace library variable with debit.library.branchname
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% debit.library.branchname') WHERE code = 'ACCOUNT_DEBIT' ");
# replace offsets variable with debit.offsets
$dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' debit.offsets %]') WHERE code = 'ACCOUNT_DEBIT' ");
# replace total variable with debit.patron.account.balance
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% total ', '[% debit.patron.account.balance ') WHERE code = 'ACCOUNT_DEBIT' ");
# replace totalcredit variable with debit.patron.account.balance <= 0
$dbh->do("UPDATE letter SET content = REPLACE(content, 'totalcredit', 'debit.patron.account.balance <= 0') WHERE code = 'ACCOUNT_DEBIT' ");
# RECEIPT
my $receipt = q{
[% PROCESS "accounts.inc" %]
[%- USE KohaDates -%]
[%- USE Price -%]
[% IF ( LibraryName ) %]
[% LibraryName | html %]
|
[% END %]
[% IF credit.library %]
[% payment.library.branchname | html %]
|
[% END %]
[% payment.date | $KohaDates %]
|
Transaction ID: |
[% payment.accountlines_id %] |
Operator ID: |
[% payment.manager_id %] |
Payment type: |
[% payment.payment_type %] |
Payment receipt
|
Description of charges |
Amount |
[% FOREACH offset IN payment.credit_offsets %]
[% PROCESS account_type_description account=offset.debit %] |
[% offset.amount * -1 | $Price %] |
[% END %]
Total: |
[% payment.amount * -1 | $Price %] |
Tendered: |
[% tendered | $Price %] |
Change given: |
[% change | $Price %] |
};
my $receipt_old = q{[%PROCESS"accounts.inc"%][%IF(LibraryName)%][%LibraryName|html%]
[%END%][%Branches.GetName(payment.branchcode)|html%]
|
[%payment.date|$KohaDates%]
|
TransactionID: | [%payment.accountlines_id%] |
OperatorID: | [%payment.manager_id%] |
Paymenttype: | [%payment.payment_type%] |
|
Feereceipt
|
|
Descriptionofcharges | Amount |
[%FOREACHoffsetINoffsets%][%PROCESSaccount_type_descriptionaccount=offset.debit%] | [%offset.amount*-1|$Price%] |
[%END%]Total: | [%payment.amount*-1|$Price%] | Tendered: | [%collected|$Price%] |
Change: | [%change|$Price%] |
};
$sth = $dbh->prepare(q{
UPDATE letter SET content = ? WHERE code = 'RECEIPT' AND REPLACE(REPLACE(content, ' ', ''), '\n','') = ?
});
$sth->execute($receipt,$receipt_old);
# replace offsets variable with debit.offsets
$dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' payment.offsets %]') WHERE code = 'RECEIPT' ");
# replace collected variable with tendered
$dbh->do("UPDATE letter SET content = REPLACE(content, '[% collected', '[% tendered') WHERE code = 'RECEIPT' ");
},
};