Bug 26734: (QA follow-up) Add warning to database update
[koha.git] / installer / data / mysql / atomicupdate / bug_26734.perl
1 $DBversion = 'XXX';
2 if ( CheckVersion($DBversion) ) {
3
4     # ACCOUNT_CREDIT UPDATES
5     # backup existing notice to action_logs
6     my $credit_arr = $dbh->selectall_arrayref(
7         "SELECT lang FROM letter WHERE code = 'ACCOUNT_CREDIT'", { Slice => {} });
8     my $c_sth = $dbh->prepare(q{
9       INSERT INTO action_logs ( timestamp, module, action, object, info, interface )
10       SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli'
11       FROM letter
12       WHERE lang = ? AND code = 'ACCOUNT_CREDIT'
13     });
14
15     for my $c ( @{$credit_arr} ) {
16         $c_sth->execute( $c->{lang} );
17     }
18
19     # replace notice with default
20     my $c_notice = q{
21 [% USE Price %]
22 [% PROCESS 'accounts.inc' %]
23 <table>
24 [% IF ( LibraryName ) %]
25  <tr>
26     <th colspan="4" class="centerednames">
27         <h3>[% LibraryName | html %]</h3>
28     </th>
29  </tr>
30 [% END %]
31  <tr>
32     <th colspan="4" class="centerednames">
33         <h2><u>Fee receipt</u></h2>
34     </th>
35  </tr>
36  <tr>
37     <th colspan="4" class="centerednames">
38         <h2>[% Branches.GetName( credit.patron.branchcode ) | html %]</h2>
39     </th>
40  </tr>
41  <tr>
42     <th colspan="4">
43         Received with thanks from  [% credit.patron.firstname | html %] [% credit.patron.surname | html %] <br />
44         Card number: [% credit.patron.cardnumber | html %]<br />
45     </th>
46  </tr>
47   <tr>
48     <th>Date</th>
49     <th>Description of charges</th>
50     <th>Note</th>
51     <th>Amount</th>
52  </tr>
53
54  <tr class="highlight">
55     <td>[% credit.date | $KohaDates %]</td>
56     <td>
57       [% PROCESS account_type_description account=credit %]
58       [%- IF credit.description %], [% credit.description | html %][% END %]
59     </td>
60     <td>[% credit.note | html %]</td>
61     <td class="credit">[% credit.amount | $Price %]</td>
62  </tr>
63
64 <tfoot>
65   <tr>
66     <td colspan="3">Total outstanding dues as on date: </td>
67     [% IF ( credit.patron.account.balance >= 0 ) %]<td class="credit">[% ELSE %]<td class="debit">[% END %][% credit.patron.account.balance | $Price %]</td>
68   </tr>
69 </tfoot>
70 </table>
71     };
72
73     my $c_insert = $dbh->prepare("UPDATE letter SET content = ?, is_html = 1 WHERE code = 'ACCOUNT_CREDIT'");
74     $c_insert->execute($c_notice);
75
76     # ACCOUNT_DEBIT UPDATES
77     # backup existing notice to action_logs
78     my $debit_arr = $dbh->selectall_arrayref(
79         "SELECT lang FROM letter WHERE code = 'ACCOUNT_DEBIT'", { Slice => {} });
80     my $d_sth = $dbh->prepare(q{
81       INSERT INTO action_logs ( timestamp, module, action, object, info, interface )
82       SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli'
83       FROM letter
84       WHERE lang = ? AND code = 'ACCOUNT_DEBIT'
85     });
86
87     for my $d ( @{$debit_arr} ) {
88         $d_sth->execute( $d->{lang} );
89     }
90
91     # replace notice with default
92     my $d_notice = q{
93 [% USE Price %]
94 [% PROCESS 'accounts.inc' %]
95 <table>
96   [% IF ( LibraryName ) %]
97     <tr>
98       <th colspan="5" class="centerednames">
99         <h3>[% LibraryName | html %]</h3>
100       </th>
101     </tr>
102   [% END %]
103
104   <tr>
105     <th colspan="5" class="centerednames">
106       <h2><u>INVOICE</u></h2>
107     </th>
108   </tr>
109   <tr>
110     <th colspan="5" class="centerednames">
111       <h2>[% Branches.GetName( debit.patron.branchcode ) | html %]</h2>
112     </th>
113   </tr>
114   <tr>
115     <th colspan="5" >
116       Bill to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %] <br />
117       Card number: [% debit.patron.cardnumber | html %]<br />
118     </th>
119   </tr>
120   <tr>
121     <th>Date</th>
122     <th>Description of charges</th>
123     <th>Note</th>
124     <th style="text-align:right;">Amount</th>
125     <th style="text-align:right;">Amount outstanding</th>
126   </tr>
127
128   <tr class="highlight">
129     <td>[% debit.date | $KohaDates%]</td>
130     <td>
131       [% PROCESS account_type_description account=debit %]
132       [%- IF debit.description %], [% debit.description | html %][% END %]
133     </td>
134     <td>[% debit.note | html %]</td>
135     <td class="debit">[% debit.amount | $Price %]</td>
136     <td class="debit">[% debit.amountoutstanding | $Price %]</td>
137   </tr>
138
139   [% IF ( tendered ) %]
140     <tr>
141       <td colspan="3">Amount tendered: </td>
142       <td>[% tendered | $Price %]</td>
143     </tr>
144     <tr>
145       <td colspan="3">Change given: </td>
146       <td>[% change | $Price %]</td>
147     </tr>
148   [% END %]
149
150   <tfoot>
151     <tr>
152       <td colspan="4">Total outstanding dues as on date: </td>
153       [% IF ( debit.patron.account.balance <= 0 ) %]<td class="credit">[% ELSE %]<td class="debit">[% END %][% debit.patron.account.balance | $Price %]</td>
154     </tr>
155   </tfoot>
156 </table>
157     };
158     my $d_insert = $dbh->prepare("UPDATE letter SET content = ?, is_html = 1 WHERE code = 'ACCOUNT_DEBIT'");
159     $d_insert->execute($d_notice);
160
161     NewVersion( $DBversion, 26734, "Update notices to use defaults" );
162     warn "Warning - ACCOUNT_DEBIT and ACCOUNT_CREDIT slip templates have been replaced. Backups have been made to the action logs for your reference.";
163 }