Bug 32191: Tidy upgrade scripts output
[srvgit] / installer / data / mysql / db_revs / 220600077.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "31713",
5     description => "Add ACCOUNTS_SUMMARY slip notice",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9
10         my $slip_content = <<~'END_CONTENT';
11 [% USE Branches %]
12 [% USE Koha %]
13 [% USE KohaDates %]
14 [% USE Price %]
15 [% PROCESS 'accounts.inc' %]
16 <table>
17   [% IF ( Koha.Preference('LibraryName') ) %]
18     <tr>
19       <th colspan='4' class='centerednames'>
20         <h1>[% Koha.Preference('LibraryName') | html %]</h1>
21       </th>
22     </tr>
23   [% END %]
24
25   <tr>
26     <th colspan='4' class='centerednames'>
27       <h2>[% Branches.GetName( borrower.branchcode ) | html %]</h2>
28     </th>
29   </tr>
30
31   <tr>
32     <th colspan='4' class='centerednames'>
33       <h3>Outstanding accounts</h3>
34     </th>
35   </tr>
36
37   <tr>
38     <th colspan='4' class='centerednames'>
39       <h4>Debts</h4>
40     </th>
41   </tr>
42   [% IF borrower.account.outstanding_debits.total_outstanding %]
43   <tr>
44     <th>Date</th>
45     <th>Charge</th>
46     <th>Amount</th>
47     <th>Outstanding</th>
48   </tr>
49   [% FOREACH debit IN borrower.account.outstanding_debits %]
50   <tr>
51     <td>[% debit.date | $KohaDates %]</td>
52     <td>
53       [% PROCESS account_type_description account=debit %]
54       [%- IF debit.description %], [% debit.description | html %][% END %]
55     </td>
56     <td class='debit'>[% debit.amount | $Price %]</td>
57     <td class='debit'>[% debit.amountoutstanding | $Price %]</td>
58   </tr>
59   [% END %]
60   [% ELSE %]
61   <tr>
62     <td colspan='4'>There are no outstanding debts on your account</td>
63   </tr>
64   [% END %]
65
66   <tr>
67     <th colspan='4' class='centerednames'>
68       <h4>Credits</h4>
69     </th>
70   </tr>
71   [% IF borrower.account.outstanding_credits.total_outstanding %]
72   <tr>
73     <th>Date</th>
74     <th>Credit</th>
75     <th>Amount</th>
76     <th>Outstanding</th>
77   </tr>
78   [% FOREACH credit IN borrower.account.outstanding_credits %]
79   <tr>
80     <td>[% credit.date | $KohaDates %]</td>
81     <td>
82       [% PROCESS account_type_description account=credit %]
83       [%- IF credit.description %], [% credit.description | html %][% END %]
84     </td>
85     <td class='credit'>[% credit.amount *-1 | $Price %]</td>
86     <td class='credit'>[% credit.amountoutstanding *-1 | $Price %]</td>
87   </tr>
88   [% END %]
89   [% ELSE %]
90   <tr>
91     <td colspan='4'>There are no outstanding credits on your account</td>
92   </tr>
93   [% END %]
94
95   <tfoot>
96     <tr>
97       <td colspan='3'>
98         [% IF borrower.account.balance < 0 %]
99           Total credit as of [% today | $KohaDates %]:
100         [% ELSE %]
101           Total outstanding dues as of [% today | $KohaDates %]:
102         [% END %]
103       </td>
104       [% IF ( borrower.account.balance <= 0 ) %]<td class='credit'>[% borrower.account.balance * -1 | $Price %]</td>
105       [% ELSE %]<td class='debit'>[% borrower.account.balance | $Price %]</td>[% END %]
106     </tr>
107   </tfoot>
108 </table>
109 END_CONTENT
110
111         $dbh->do(qq{
112            INSERT IGNORE INTO letter ( module, code, branchcode, name, is_html, title, content, message_transport_type, lang)
113            VALUES ( 'members', 'ACCOUNTS_SUMMARY', '', 'Account balance slip', 1, 'Account summary for [% borrower.firstname %] [% borrower.surname %]', "$slip_content", 'print', 'default' )
114         });
115
116         say $out "Added new letter 'ACCOUNTS_SUMMARY' (print)";
117     },
118 };