Bug 23354: (QA follow-up) Make db update idempotent
[koha-equinox.git] / installer / data / mysql / atomicupdate / bug_23354.perl
1 $DBversion = 'XXX'; # will be replaced by the RM
2 if( CheckVersion( $DBversion ) ) {
3
4     $dbh->do(q{
5         INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'Purchase' );
6     });
7
8     $dbh->do(q{
9         INSERT IGNORE INTO account_credit_types ( code, description, can_be_added_manually, is_system )
10         VALUES ('PURCHASE', 'Purchase', 0, 1);
11     });
12
13     my $sth = $dbh->prepare(q{
14         SELECT COUNT(*) FROM authorised_values WHERE category = 'PAYMENT_TYPE' AND authorised_value = 'CASH'
15     });
16     $sth->execute;
17     my $already_exists = $sth->fetchrow;
18     if ( not $already_exists ) {
19         $dbh->do(q{
20            INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('PAYMENT_TYPE','CASH','Cash')
21         });
22     }
23
24     # Updating field in account_debit_types
25     unless ( column_exists('account_debit_types', 'can_be_invoiced') ) {
26         $dbh->do(
27             qq{
28                 ALTER TABLE account_debit_types
29                 CHANGE COLUMN
30                   can_be_added_manually can_be_invoiced tinyint(1) NOT NULL DEFAULT 1
31               }
32         );
33     }
34     unless ( column_exists('account_debit_types', 'can_be_sold') ) {
35         $dbh->do(
36             qq{
37                 ALTER IGNORE TABLE account_debit_types
38                 ADD
39                   can_be_sold tinyint(1) DEFAULT 0
40                 AFTER
41                   can_be_invoiced
42               }
43         );
44     }
45
46     $dbh->do(q{
47 INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES
48 ('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', '[% PROCESS "accounts.inc" %]
49 <table>
50 [% IF ( LibraryName ) %]
51  <tr>
52     <th colspan="2" class="centerednames">
53         <h3>[% LibraryName | html %]</h3>
54     </th>
55  </tr>
56 [% END %]
57  <tr>
58     <th colspan="2" class="centerednames">
59         <h2>[% Branches.GetName( payment.branchcode ) | html %]</h2>
60     </th>
61  </tr>
62 <tr>
63     <th colspan="2" class="centerednames">
64         <h3>[% payment.date | $KohaDates %]</h3>
65 </tr>
66 <tr>
67   <td>Transaction ID: </td>
68   <td>[% payment.accountlines_id %]</td>
69 </tr>
70 <tr>
71   <td>Operator ID: </td>
72   <td>[% payment.manager_id %]</td>
73 </tr>
74 <tr>
75   <td>Payment type: </td>
76   <td>[% payment.payment_type %]</td>
77 </tr>
78  <tr></tr>
79  <tr>
80     <th colspan="2" class="centerednames">
81         <h2><u>Fee receipt</u></h2>
82     </th>
83  </tr>
84  <tr></tr>
85  <tr>
86     <th>Description of charges</th>
87     <th>Amount</th>
88   </tr>
89
90   [% FOREACH offset IN offsets %]
91     <tr>
92         <td>[% PROCESS account_type_description account=offset.debit %]</td>
93         <td>[% offset.amount * -1 | $Price %]</td>
94     </tr>
95   [% END %]
96
97 <tfoot>
98   <tr class="highlight">
99     <td>Total: </td>
100     <td>[% payment.amount * -1| $Price %]</td>
101   </tr>
102   <tr>
103     <td>Tendered: </td>
104     <td>[% collected | $Price %]</td>
105   </tr>
106   <tr>
107     <td>Change: </td>
108     <td>[% change | $Price %]</td>
109     </tr>
110 </tfoot>
111 </table>', 'print', 'default');
112     });
113
114     SetVersion( $DBversion );
115     print "Upgrade to $DBversion done (Bug 23354 - Add 'Purchase' account offset type)\n";
116     print "Upgrade to $DBversion done (Bug 23354 - Add 'RECEIPT' notice for Point of Sale)\n";
117 }