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

(-)a/C4/Budgets.pm (+12 lines)
Lines 22-27 use strict; Link Here
22
use C4::Context;
22
use C4::Context;
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Patrons;
24
use Koha::Patrons;
25
use Koha::InvoiceAdjustments;
26
use Koha::InvoiceAdjustment;
25
use C4::Debug;
27
use C4::Debug;
26
use vars qw(@ISA @EXPORT);
28
use vars qw(@ISA @EXPORT);
27
29
Lines 349-354 sub GetBudgetSpent { Link Here
349
    my ($shipmentcost_sum) = $sth->fetchrow_array;
351
    my ($shipmentcost_sum) = $sth->fetchrow_array;
350
    $sum += $shipmentcost_sum;
352
    $sum += $shipmentcost_sum;
351
353
354
    my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' });
355
    while ( my $adj = $adjustments->next ){
356
        $sum += $adj->adjustment;
357
    }
358
352
	return $sum;
359
	return $sum;
353
}
360
}
354
361
Lines 375-380 sub GetBudgetOrdered { Link Here
375
    my ($shipmentcost_sum) = $sth->fetchrow_array;
382
    my ($shipmentcost_sum) = $sth->fetchrow_array;
376
    $sum += $shipmentcost_sum;
383
    $sum += $shipmentcost_sum;
377
384
385
    my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' });
386
    while ( my $adj = $adjustments->next ){
387
        $sum += $adj->adjustment;
388
    }
389
378
	return $sum;
390
	return $sum;
379
}
391
}
380
392
(-)a/Koha/InvoiceAdjustment.pm (+44 lines)
Line 0 Link Here
1
package Koha::InvoiceAdjustment;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::InvoiceAdjustment - Koha Invoice Adjustment class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'InvoiceAdjustment';
42
}
43
44
1;
(-)a/Koha/InvoiceAdjustments.pm (+50 lines)
Line 0 Link Here
1
package Koha::InvoiceAdjustments;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Rating;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::InvoiceAdjustments - Koha Invoice Adjustments Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'InvoiceAdjustment';
44
}
45
46
sub object_class {
47
    return 'Koha::InvoiceAdjustment';
48
}
49
50
1;
(-)a/acqui/invoice.pl (+43 lines)
Lines 39-44 use Koha::Acquisition::Booksellers; Link Here
39
use Koha::Acquisition::Currencies;
39
use Koha::Acquisition::Currencies;
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Misc::Files;
41
use Koha::Misc::Files;
42
use Koha::InvoiceAdjustments;
43
use Koha::InvoiceAdjustment;
42
44
43
my $input = new CGI;
45
my $input = new CGI;
44
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
46
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
Lines 109-115 elsif ( $op && $op eq 'delete' ) { Link Here
109
        exit 0;
111
        exit 0;
110
    }
112
    }
111
}
113
}
114
elsif ( $op && $op eq 'mod_adj' ) {
115
    my @adjustment_id  = $input->multi_param('adjustment_id');
116
    my @adjustment     = $input->multi_param('adjustment');
117
    my @reason         = $input->multi_param('reason');
118
    my @budget_id      = $input->multi_param('budget_id');
119
    my @encumber_open  = $input->multi_param('encumber_open');
120
    my @delete         = $input->multi_param('delete');
112
121
122
    for( my $i=0; $i < scalar @adjustment; $i++ ){
123
        warn "Delete is ".$delete[$i];
124
        if( $adjustment_id[$i] eq 'new' ){
125
            next unless ( $adjustment[$i] || $reason[$i] );
126
            my $new_adj = Koha::InvoiceAdjustment->new({
127
                invoiceid => $invoiceid,
128
                adjustment => $adjustment[$i],
129
                reason => $reason[$i],
130
                budget_id => $budget_id[$i] || undef,
131
                encumber_open => $encumber_open[$i],
132
            });
133
            warn Data::Dumper::Dumper( $new_adj->unblessed );
134
            $new_adj->store();
135
        }
136
        elsif ( $delete[$i] == 1 ){
137
            my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] );
138
            $del_adj->delete();
139
        }
140
        else {
141
            my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] );
142
            unless ( 0 && $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $encumber_open[$i] ){
143
                $old_adj->timestamp(undef);
144
                $old_adj->adjustment( $adjustment[$i] );
145
                $old_adj->reason( $reason[$i] );
146
                $old_adj->budget_id( $budget_id[$i] || undef );
147
                $old_adj->encumber_open( $encumber_open[$i] );
148
                $old_adj->update();
149
            }
150
        }
151
    }
152
}
113
153
114
my $details = GetInvoiceDetails($invoiceid);
154
my $details = GetInvoiceDetails($invoiceid);
115
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
155
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
Lines 160-165 foreach my $budget (@$budgets) { Link Here
160
    push @budgets_loop, \%line;
200
    push @budgets_loop, \%line;
161
}
201
}
162
202
203
my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} });
204
if ( $adjustments ) { $template->param( adjustments => $adjustments ); }
205
163
$template->param(
206
$template->param(
164
    invoiceid        => $details->{'invoiceid'},
207
    invoiceid        => $details->{'invoiceid'},
165
    invoicenumber    => $details->{'invoicenumber'},
208
    invoicenumber    => $details->{'invoicenumber'},
(-)a/acqui/ordered.pl (+9 lines)
Lines 33-38 use warnings; Link Here
33
use CGI qw ( -utf8 );
33
use CGI qw ( -utf8 );
34
use C4::Auth;
34
use C4::Auth;
35
use C4::Output;
35
use C4::Output;
36
use Koha::InvoiceAdjustments;
37
use Koha::InvoiceAdjustment;
36
38
37
my $dbh     = C4::Context->dbh;
39
my $dbh     = C4::Context->dbh;
38
my $input   = new CGI;
40
my $input   = new CGI;
Lines 96-107 while ( my $data = $sth->fetchrow_hashref ) { Link Here
96
        $total += $subtotal;
98
        $total += $subtotal;
97
    }
99
    }
98
}
100
}
101
102
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } );
103
while ( my $adj = $adjustments->next ){
104
    $total += $adj->adjustment;
105
}
106
99
$total = sprintf( "%.2f", $total );
107
$total = sprintf( "%.2f", $total );
100
108
101
$template->{VARS}->{'fund'}    = $fund_id;
109
$template->{VARS}->{'fund'}    = $fund_id;
102
$template->{VARS}->{'ordered'} = \@ordered;
110
$template->{VARS}->{'ordered'} = \@ordered;
103
$template->{VARS}->{'total'}   = $total;
111
$template->{VARS}->{'total'}   = $total;
104
$template->{VARS}->{'fund_code'} = $fund_code;
112
$template->{VARS}->{'fund_code'} = $fund_code;
113
$template->{VARS}->{'adjustments'} = $adjustments;
105
114
106
$sth->finish;
115
$sth->finish;
107
116
(-)a/acqui/spent.pl (+8 lines)
Lines 35-40 use C4::Output; Link Here
35
use strict;
35
use strict;
36
use warnings;
36
use warnings;
37
use CGI qw ( -utf8 );
37
use CGI qw ( -utf8 );
38
use Koha::InvoiceAdjustments;
39
use Koha::InvoiceAdjustment;
38
40
39
my $dbh      = C4::Context->dbh;
41
my $dbh      = C4::Context->dbh;
40
my $input    = new CGI;
42
my $input    = new CGI;
Lines 119-124 while (my $data = $sth->fetchrow_hashref) { Link Here
119
}
121
}
120
$sth->finish;
122
$sth->finish;
121
123
124
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } );
125
while ( my $adj = $adjustments->next ){
126
    $total += $adj->adjustment;
127
}
128
122
$total = sprintf( "%.2f", $total );
129
$total = sprintf( "%.2f", $total );
123
130
124
$template->param(
131
$template->param(
Lines 126-131 $template->param( Link Here
126
    spent => \@spent,
133
    spent => \@spent,
127
    subtotal => $subtotal,
134
    subtotal => $subtotal,
128
    shipmentcosts => \@shipmentcosts,
135
    shipmentcosts => \@shipmentcosts,
136
    adjustments => $adjustments,
129
    total => $total,
137
    total => $total,
130
    fund_code => $fund_code
138
    fund_code => $fund_code
131
);
139
);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-1 / +60 lines)
Lines 127-132 Link Here
127
            [% END %]
127
            [% END %]
128
        </fieldset>
128
        </fieldset>
129
      </form>
129
      </form>
130
      <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
131
          <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
132
          <ul>
133
          [% IF (adjustments.count > 0) %]
134
          <h2>Current adjustments</h2>
135
          [% total_adj = 0 %]
136
          [% FOREACH adjustment IN adjustments %]
137
              [% total_adj = total_adj + adjustment.adjustment %]
138
              <li>
139
                  <input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id %]" />
140
                  <label for="adjustment">Amount:</label><input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id %]" value="[% adjustment.adjustment %]" />
141
                  <label for="reason">Reason:</label><input type="text" name="reason" id="reason_[% adjustment.adjustment_id %]" value="[% adjustment.reason %]"/>
142
                  <label for="budget_id">Budget:</label>
143
                      <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
144
                        <option value="">No fund</option>
145
                      [% FOREACH budget IN budgets_loop %]
146
                        [% IF ( budget.budget_id == adjustment.budget_id ) %]
147
                          <option selected="selected" value="[% budget.budget_id %]">
148
                        [% ELSE %]
149
                          <option value="[% budget.budget_id %]">
150
                        [% END %]
151
                          [% budget.budget_name %]
152
                        </option>
153
                      [% END %]
154
                    </select>
155
                  [% IF adjustment.encumber_open %]
156
                  <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]" value="1" checked/>
157
                  [% ELSE %]
158
                  <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]" value="1" />
159
                  [% END %]
160
                  <label for="delete">Delete:</label><input type="checkbox" name="delete" id="delete_[% adjustment_id %]" value="1" />
161
              </li>
162
          [% END %]
163
          [% END %]
164
          <h2>Add an adjustment</h2>
165
              <li>
166
                  <input type="hidden" name="adjustment_id" value="new" />
167
                  <label for="adjustment">Amount:</label><input type="text" name="adjustment" id="adjustment_new]" />
168
                  <label for="reason">Reason:</label><input type="text" name="reason" id="reason_new" value=""/>
169
                  <label for="budget_id">Budget:</label>
170
                      <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
171
                        <option selected="selected" value="">No fund</option>
172
                      [% FOREACH budget IN budgets_loop %]
173
                          <option value="[% budget.budget_id %]">
174
                          [% budget.budget_name %]
175
                        </option>
176
                      [% END %]
177
                    </select>
178
                  <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_new" value="1" />
179
                  <input type="hidden" name="delete" value="">
180
              </li>
181
            </ul>
182
          <input type="hidden" name="op" value="mod_adj" />
183
          <input type="submit" value="Update adjustments" />
184
      </form>
130
      <p>
185
      <p>
131
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
186
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
132
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
187
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
Lines 220-226 Link Here
220
            </tfoot>
275
            </tfoot>
221
          </table>
276
          </table>
222
        [% ELSE %]
277
        [% ELSE %]
223
            <div class="dialog message"><p>No orders yet</p></div>
278
            <div class="dialog message"><p>No orders yet</p>
279
            [% IF adjustments.count > 0 || shipmentcost > 0 %]
280
            <p>Adjustments plus shipping:[% total_adj + shipmentcost | $Price %]</p>
281
            [% END %]
282
            </div>
224
        [% END %]
283
        [% END %]
225
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
284
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
226
            <br />
285
            <br />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt (+10 lines)
Lines 84-89 Link Here
84
[% END %]
84
[% END %]
85
    </tbody>
85
    </tbody>
86
    <tfoot>
86
    <tfoot>
87
    [% IF ( adjustments.count > 0 ) %]
88
            [% FOREACH adjustment IN adjustments %]
89
                <tr>
90
                    <td></td>
91
                    <td colspan="6">Adjustment cost for invoice [% adjustment.invoiceid %]</td>
92
                    <td class="data total">[% adjustment.adjustment %]</td>
93
                </tr>
94
            [% END %]
95
96
    [% END %]
87
    <tr>
97
    <tr>
88
        <td> Total </td>
98
        <td> Total </td>
89
        <td> </td>
99
        <td> </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt (-2 / +12 lines)
Lines 88-98 Link Here
88
    [% END %]
88
    [% END %]
89
89
90
    <tfoot>
90
    <tfoot>
91
        [% IF shipmentcosts.size %]
91
        [% IF shipmentcosts.size || ( adjustments.count > 0 ) %]
92
            <tr valign="top">
92
            <tr valign="top">
93
                <td colspan="9"> Sub total </td>
93
                <td colspan="9"> Sub total </td>
94
                <td class="data"> [% subtotal %] </td>
94
                <td class="data"> [% subtotal %] </td>
95
            </tr>
95
            </tr>
96
        [% END %]
97
        [% IF shipmentcosts.size %]
96
            [% FOREACH shipmentcost IN shipmentcosts %]
98
            [% FOREACH shipmentcost IN shipmentcosts %]
97
                <tr>
99
                <tr>
98
                    <td></td>
100
                    <td></td>
Lines 101-106 Link Here
101
                </tr>
103
                </tr>
102
            [% END %]
104
            [% END %]
103
        [% END %]
105
        [% END %]
106
        [% IF ( adjustments.count > 0 ) %]
107
            [% FOREACH adjustment IN adjustments %]
108
                <tr>
109
                    <td></td>
110
                    <td colspan="8">Adjustment cost for invoice [% adjustment.invoiceid %]</td>
111
                    <td class="data total">[% adjustment.adjustment %]</td>
112
                </tr>
113
            [% END %]
114
        [% END %]
104
        <tr>
115
        <tr>
105
            <td colspan="9">TOTAL</td>
116
            <td colspan="9">TOTAL</td>
106
            <td class="data total">[% total %]</td>
117
            <td class="data total">[% total %]</td>
107
- 

Return to bug 19166