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

(-)a/installer/data/mysql/atomicupdate/bug_26734.perl (-40 / +145 lines)
Lines 1-45 Link Here
1
$DBversion = 'XXX';
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
2
if ( CheckVersion($DBversion) ) {
3
3
4
    # ACCOUNT_CREDIT UPDATES
4
    # ACCOUNT_CREDIT UPDATES
5
    # replace patron variable with credit.patron
5
    # backup existing notice to action_logs
6
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% credit.patron') WHERE code = 'ACCOUNT_CREDIT' ");
6
    my $credit_arr = $dbh->selectall_arrayref(
7
    # replace library variable with credit.library.branchname
7
        "SELECT lang FROM letter WHERE code = 'ACCOUNT_CREDIT'", { Slice => {} });
8
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% credit.library.branchname') WHERE code = 'ACCOUNT_CREDIT' ");
8
    my $c_sth = $dbh->prepare(q{
9
9
      INSERT INTO action_logs ( timestamp, module, action, object, info, interface )
10
    # replace offsets variable with credit.offsets
10
      SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli'
11
    $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' credit.offsets %]') WHERE code = 'ACCOUNT_CREDIT' ");
11
      FROM letter
12
    # replace change_given variable with change
12
      WHERE lang = ? AND code = 'ACCOUNT_CREDIT'
13
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% change_given', '[% change') WHERE code = 'ACCOUNT_CREDIT' ");
13
    });
14
14
15
    # replace accounts foreach with basic check
15
    for my $c ( @{$credit_arr} ) {
16
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF credit %]') WHERE code = 'ACCOUNT_CREDIT' ");
16
        $c_sth->execute( $c->{lang} );
17
    # replace account with credit
17
    }
18
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'credit.') WHERE code = 'ACCOUNT_CREDIT' ");
18
19
    # replace amountcredit with amount >= 0
19
    # replace notice with default
20
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( credit.amountcredit )', '( credit.amount <= 0 )') WHERE code = 'ACCOUNT_CREDIT' ");
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);
21
75
22
    # ACCOUNT_DEBIT UPDATES
76
    # ACCOUNT_DEBIT UPDATES
23
    # replace patron variable with debit.patron
77
    # backup existing notice to action_logs
24
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% debit.patron') WHERE code = 'ACCOUNT_DEBIT' ");
78
    my $debit_arr = $dbh->selectall_arrayref(
25
    # replace library variable with debit.library.branchname
79
        "SELECT lang FROM letter WHERE code = 'ACCOUNT_DEBIT'", { Slice => {} });
26
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% debit.library.branchname') WHERE code = 'ACCOUNT_DEBIT' ");
80
    my $d_sth = $dbh->prepare(q{
27
    # replace offsets variable with debit.offsets
81
      INSERT INTO action_logs ( timestamp, module, action, object, info, interface )
28
    $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' debit.offsets %]') WHERE code = 'ACCOUNT_DEBIT' ");
82
      SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli'
29
83
      FROM letter
30
    # replace accounts foreach with basic check
84
      WHERE lang = ? AND code = 'ACCOUNT_DEBIT'
31
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF debit %]') WHERE code = 'ACCOUNT_DEBIT' ");
85
    });
32
    # replace account with debit
86
33
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'debit.') WHERE code = 'ACCOUNT_DEBIT' ");
87
    for my $d ( @{$debit_arr} ) {
34
    # replace amountcredit with amount >= 0
88
        $d_sth->execute( $d->{lang} );
35
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountcredit )', '( debit.amount <= 0 )') WHERE code = 'ACCOUNT_DEBIT' ");
89
    }
36
    # replace amountoutstandingcredit with amount >= 0
90
37
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountoutstandingcredit )', '( debit.amountoutstanding <= 0 )') WHERE code = 'ACCOUNT_DEBIT' ");
91
    # replace notice with default
38
92
    my $d_notice = q{
39
    # replace total variable with debit.patron.account.balance
93
[% USE Price %]
40
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% total ', '[% debit.patron.account.balance ') WHERE code = 'ACCOUNT_DEBIT' ");
94
[% PROCESS 'accounts.inc' %]
41
    # replace totalcredit variable with debit.patron.account.balance <= 0
95
<table>
42
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'totalcredit', 'debit.patron.account.balance <= 0') WHERE code = 'ACCOUNT_DEBIT' ");
96
  [% IF ( LibraryName ) %]
43
97
    <tr>
44
    NewVersion( $DBversion, 26734, "Update notices to use standard variables");
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
  <tfoot>
140
    <tr>
141
      <td colspan="4">Total outstanding dues as on date: </td>
142
      [% IF ( debit.patron.account.balance <= 0 ) %]<td class="credit">[% ELSE %]<td class="debit">[% END %][% debit.patron.account.balance | $Price %]</td>
143
    </tr>
144
  </tfoot>
145
</table>
146
    };
147
    my $d_insert = $dbh->prepare("UPDATE letter SET content = ?, is_html = 1 WHERE code = 'ACCOUNT_DEBIT'");
148
    $d_insert->execute($d_notice);
149
150
    NewVersion( $DBversion, 26734, "Update notices to use defaults" );
45
}
151
}
46
- 

Return to bug 26734