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

(-)a/installer/data/mysql/atomicupdate/bug_26734.perl (-40 / +139 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(
9
9
"INSERT INTO action_logs ( timestamp, module, action, info, interface ) VALUES ( NOW(), 'NOTICES', ?, (SELECT content FROM letter WHERE lang = ? AND code = 'ACCOUNT_CREDIT' ), 'cli' )"
10
    # replace offsets variable with credit.offsets
10
    );
11
    $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' credit.offsets %]') WHERE code = 'ACCOUNT_CREDIT' ");
11
12
    # replace change_given variable with change
12
    for my $c ( @{$credit_arr} ) {
13
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% change_given', '[% change') WHERE code = 'ACCOUNT_CREDIT' ");
13
        $c_sth->execute( 'ACCOUNT_CREDIT_' . $c->{lang}, $c->{lang} );
14
14
    }
15
    # replace accounts foreach with basic check
15
16
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF credit %]') WHERE code = 'ACCOUNT_CREDIT' ");
16
    # replace notice with default
17
    # replace account with credit
17
    my $c_notice = q{
18
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'credit.') WHERE code = 'ACCOUNT_CREDIT' ");
18
[% USE Price %]
19
    # replace amountcredit with amount >= 0
19
[% PROCESS 'accounts.inc' %]
20
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( credit.amountcredit )', '( credit.amount <= 0 )') WHERE code = 'ACCOUNT_CREDIT' ");
20
<table>
21
[% IF ( LibraryName ) %]
22
 <tr>
23
    <th colspan="4" class="centerednames">
24
        <h3>[% LibraryName | html %]</h3>
25
    </th>
26
 </tr>
27
[% END %]
28
 <tr>
29
    <th colspan="4" class="centerednames">
30
        <h2><u>Fee receipt</u></h2>
31
    </th>
32
 </tr>
33
 <tr>
34
    <th colspan="4" class="centerednames">
35
        <h2>[% Branches.GetName( credit.patron.branchcode ) | html %]</h2>
36
    </th>
37
 </tr>
38
 <tr>
39
    <th colspan="4">
40
        Received with thanks from  [% credit.patron.firstname | html %] [% credit.patron.surname | html %] <br />
41
        Card number: [% credit.patron.cardnumber | html %]<br />
42
    </th>
43
 </tr>
44
  <tr>
45
    <th>Date</th>
46
    <th>Description of charges</th>
47
    <th>Note</th>
48
    <th>Amount</th>
49
 </tr>
50
51
 <tr class="highlight">
52
    <td>[% credit.date | $KohaDates %]</td>
53
    <td>
54
      [% PROCESS account_type_description account=credit %]
55
      [%- IF credit.description %], [% credit.description | html %][% END %]
56
    </td>
57
    <td>[% credit.note | html %]</td>
58
    <td class="credit">[% credit.amount | $Price %]</td>
59
 </tr>
60
61
<tfoot>
62
  <tr>
63
    <td colspan="3">Total outstanding dues as on date: </td>
64
    [% IF ( credit.patron.account.balance >= 0 ) %]<td class="credit">[% ELSE %]<td class="debit">[% END %][% credit.patron.account.balance | $Price %]</td>
65
  </tr>
66
</tfoot>
67
</table>
68
    };
69
70
    my $c_insert = $dbh->prepare("UPDATE letter SET content = ? WHERE code = 'ACCOUNT_CREDIT'");
71
    $c_insert->execute($c_notice);
21
72
22
    # ACCOUNT_DEBIT UPDATES
73
    # ACCOUNT_DEBIT UPDATES
23
    # replace patron variable with debit.patron
74
    # backup existing notice to action_logs
24
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% debit.patron') WHERE code = 'ACCOUNT_DEBIT' ");
75
    my $debit_arr = $dbh->selectall_arrayref(
25
    # replace library variable with debit.library.branchname
76
        "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' ");
77
    my $d_sth = $dbh->prepare(
27
    # replace offsets variable with debit.offsets
78
"INSERT INTO action_logs ( timestamp, module, action, info, interface ) VALUES ( NOW(), 'NOTICES', ?, (SELECT content FROM letter WHERE lang = ? AND code = 'ACCOUNT_DEBIT' ), 'cli' )"
28
    $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' debit.offsets %]') WHERE code = 'ACCOUNT_DEBIT' ");
79
    );
29
80
30
    # replace accounts foreach with basic check
81
    for my $d ( @{$debit_arr} ) {
31
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF debit %]') WHERE code = 'ACCOUNT_DEBIT' ");
82
        $d_sth->exedute( 'ACCOUNT_DEBIT_' . $d->{lang}, $d->{lang} );
32
    # replace account with debit
83
    }
33
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'debit.') WHERE code = 'ACCOUNT_DEBIT' ");
84
34
    # replace amountcredit with amount >= 0
85
    # replace notice with default
35
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountcredit )', '( debit.amount <= 0 )') WHERE code = 'ACCOUNT_DEBIT' ");
86
    my $d_notice = q{
36
    # replace amountoutstandingcredit with amount >= 0
87
[% USE Price %]
37
    $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountoutstandingcredit )', '( debit.amountoutstanding <= 0 )') WHERE code = 'ACCOUNT_DEBIT' ");
88
[% PROCESS 'accounts.inc' %]
38
89
<table>
39
    # replace total variable with debit.patron.account.balance
90
  [% IF ( LibraryName ) %]
40
    $dbh->do("UPDATE letter SET content = REPLACE(content, '[% total ', '[% debit.patron.account.balance ') WHERE code = 'ACCOUNT_DEBIT' ");
91
    <tr>
41
    # replace totalcredit variable with debit.patron.account.balance <= 0
92
      <th colspan="5" class="centerednames">
42
    $dbh->do("UPDATE letter SET content = REPLACE(content, 'totalcredit', 'debit.patron.account.balance <= 0') WHERE code = 'ACCOUNT_DEBIT' ");
93
        <h3>[% LibraryName | html %]</h3>
43
94
      </th>
44
    NewVersion( $DBversion, 26734, "Update notices to use standard variables");
95
    </tr>
96
  [% END %]
97
98
  <tr>
99
    <th colspan="5" class="centerednames">
100
      <h2><u>INVOICE</u></h2>
101
    </th>
102
  </tr>
103
  <tr>
104
    <th colspan="5" class="centerednames">
105
      <h2>[% Branches.GetName( debit.patron.branchcode ) | html %]</h2>
106
    </th>
107
  </tr>
108
  <tr>
109
    <th colspan="5" >
110
      Bill to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %] <br />
111
      Card number: [% debit.patron.cardnumber | html %]<br />
112
    </th>
113
  </tr>
114
  <tr>
115
    <th>Date</th>
116
    <th>Description of charges</th>
117
    <th>Note</th>
118
    <th style="text-align:right;">Amount</th>
119
    <th style="text-align:right;">Amount outstanding</th>
120
  </tr>
121
122
  <tr class="highlight">
123
    <td>[% debit.date | $KohaDates%]</td>
124
    <td>
125
      [% PROCESS account_type_description account=debit %]
126
      [%- IF debit.description %], [% debit.description | html %][% END %]
127
    </td>
128
    <td>[% debit.note | html %]</td>
129
    <td class="debit">[% debit.amount | $Price %]</td>
130
    <td class="debit">[% debit.amountoutstanding | $Price %]</td>
131
  </tr>
132
133
  <tfoot>
134
    <tr>
135
      <td colspan="4">Total outstanding dues as on date: </td>
136
      [% IF ( debit.patron.account.balance <= 0 ) %]<td class="credit">[% ELSE %]<td class="debit">[% END %][% debit.patron.account.balance | $Price %]</td>
137
    </tr>
138
  </tfoot>
139
</table>
140
    };
141
    my $d_insert = $dbh->prepare("UPDATE letter SET content = ? WHERE code = 'ACCOUNT_DEBIT'");
142
    $d_insert->execute($d_notice);
143
144
    NewVersion( $DBversion, 26734, "Update notices to use defaults" );
45
}
145
}
46
- 

Return to bug 26734