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

(-)a/C4/Budgets.pm (+21 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;
25
use C4::Debug;
26
use C4::Debug;
26
use vars qw(@ISA @EXPORT);
27
use vars qw(@ISA @EXPORT);
27
28
Lines 349-354 sub GetBudgetSpent { Link Here
349
    my ($shipmentcost_sum) = $sth->fetchrow_array;
350
    my ($shipmentcost_sum) = $sth->fetchrow_array;
350
    $sum += $shipmentcost_sum;
351
    $sum += $shipmentcost_sum;
351
352
353
    my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' });
354
    while ( my $adj = $adjustments->next ){
355
        $sum += $adj->adjustment;
356
    }
357
352
	return $sum;
358
	return $sum;
353
}
359
}
354
360
Lines 365-370 sub GetBudgetOrdered { Link Here
365
	$sth->execute($budget_id);
371
	$sth->execute($budget_id);
366
	my $sum =  $sth->fetchrow_array;
372
	my $sum =  $sth->fetchrow_array;
367
373
374
    $sth = $dbh->prepare(qq|
375
        SELECT SUM(shipmentcost) AS sum
376
        FROM aqinvoices
377
        WHERE shipmentcost_budgetid = ?
378
          AND closedate IS NULL
379
    |);
380
    $sth->execute($budget_id);
381
    my ($shipmentcost_sum) = $sth->fetchrow_array;
382
    $sum += $shipmentcost_sum;
383
384
    my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' });
385
    while ( my $adj = $adjustments->next ){
386
        $sum += $adj->adjustment;
387
    }
388
368
	return $sum;
389
	return $sum;
369
}
390
}
370
391
(-)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 (+51 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
use Koha::InvoiceAdjustment;
20
21
use Carp;
22
23
use Koha::Database;
24
25
use Koha::Rating;
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::InvoiceAdjustments - Koha Invoice Adjustments Object set class
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 type
40
41
=cut
42
43
sub _type {
44
    return 'InvoiceAdjustment';
45
}
46
47
sub object_class {
48
    return 'Koha::InvoiceAdjustment';
49
}
50
51
1;
(-)a/acqui/invoice.pl (+44 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;
42
43
43
my $input = new CGI;
44
my $input = new CGI;
44
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
45
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
Lines 109-115 elsif ( $op && $op eq 'delete' ) { Link Here
109
        exit 0;
110
        exit 0;
110
    }
111
    }
111
}
112
}
113
elsif ( $op && $op eq 'del_adj' ) {
114
    my $adjustment_id  = $input->param('adjustment_id');
115
    my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id );
116
    $del_adj->delete() if ($del_adj);
117
}
118
elsif ( $op && $op eq 'mod_adj' ) {
119
    my @adjustment_id  = $input->multi_param('adjustment_id');
120
    my @adjustment     = $input->multi_param('adjustment');
121
    my @reason         = $input->multi_param('reason');
122
    my @note           = $input->multi_param('note');
123
    my @budget_id      = $input->multi_param('budget_id');
124
    my @encumber_open  = $input->multi_param('encumber_open');
125
    my %e_open = map { $_ => 1 } @encumber_open;
112
126
127
    for( my $i=0; $i < scalar @adjustment; $i++ ){
128
        if( $adjustment_id[$i] eq 'new' ){
129
            next unless ( $adjustment[$i] || $reason[$i] );
130
            my $new_adj = Koha::InvoiceAdjustment->new({
131
                invoiceid => $invoiceid,
132
                adjustment => $adjustment[$i],
133
                reason => $reason[$i],
134
                note => $note[$i],
135
                budget_id => $budget_id[$i] || undef,
136
                encumber_open => $encumber_open[$i],
137
            });
138
            $new_adj->store();
139
        }
140
        else {
141
            my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] );
142
            unless ( $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $e_open{$adjustment_id[$i]} && $old_adj->note eq $note[$i] ){
143
                $old_adj->timestamp(undef);
144
                $old_adj->adjustment( $adjustment[$i] );
145
                $old_adj->reason( $reason[$i] );
146
                $old_adj->note( $note[$i] );
147
                $old_adj->budget_id( $budget_id[$i] || undef );
148
                $old_adj->encumber_open( $e_open{$adjustment_id[$i]} ? 1 : 0 );
149
                $old_adj->update();
150
            }
151
        }
152
    }
153
}
113
154
114
my $details = GetInvoiceDetails($invoiceid);
155
my $details = GetInvoiceDetails($invoiceid);
115
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
156
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
Lines 160-165 foreach my $budget (@$budgets) { Link Here
160
    push @budgets_loop, \%line;
201
    push @budgets_loop, \%line;
161
}
202
}
162
203
204
my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} });
205
if ( $adjustments ) { $template->param( adjustments => $adjustments ); }
206
163
$template->param(
207
$template->param(
164
    invoiceid        => $details->{'invoiceid'},
208
    invoiceid        => $details->{'invoiceid'},
165
    invoicenumber    => $details->{'invoicenumber'},
209
    invoicenumber    => $details->{'invoicenumber'},
(-)a/acqui/ordered.pl (+8 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;
36
37
37
my $dbh     = C4::Context->dbh;
38
my $dbh     = C4::Context->dbh;
38
my $input   = new CGI;
39
my $input   = new CGI;
Lines 96-107 while ( my $data = $sth->fetchrow_hashref ) { Link Here
96
        $total += $subtotal;
97
        $total += $subtotal;
97
    }
98
    }
98
}
99
}
100
101
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } );
102
while ( my $adj = $adjustments->next ){
103
    $total += $adj->adjustment;
104
}
105
99
$total = sprintf( "%.2f", $total );
106
$total = sprintf( "%.2f", $total );
100
107
101
$template->{VARS}->{'fund'}    = $fund_id;
108
$template->{VARS}->{'fund'}    = $fund_id;
102
$template->{VARS}->{'ordered'} = \@ordered;
109
$template->{VARS}->{'ordered'} = \@ordered;
103
$template->{VARS}->{'total'}   = $total;
110
$template->{VARS}->{'total'}   = $total;
104
$template->{VARS}->{'fund_code'} = $fund_code;
111
$template->{VARS}->{'fund_code'} = $fund_code;
112
$template->{VARS}->{'adjustments'} = $adjustments;
105
113
106
$sth->finish;
114
$sth->finish;
107
115
(-)a/acqui/spent.pl (+7 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;
38
39
39
my $dbh      = C4::Context->dbh;
40
my $dbh      = C4::Context->dbh;
40
my $input    = new CGI;
41
my $input    = new CGI;
Lines 119-124 while (my $data = $sth->fetchrow_hashref) { Link Here
119
}
120
}
120
$sth->finish;
121
$sth->finish;
121
122
123
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } );
124
while ( my $adj = $adjustments->next ){
125
    $total += $adj->adjustment;
126
}
127
122
$total = sprintf( "%.2f", $total );
128
$total = sprintf( "%.2f", $total );
123
129
124
$template->param(
130
$template->param(
Lines 126-131 $template->param( Link Here
126
    spent => \@spent,
132
    spent => \@spent,
127
    subtotal => $subtotal,
133
    subtotal => $subtotal,
128
    shipmentcosts => \@shipmentcosts,
134
    shipmentcosts => \@shipmentcosts,
135
    adjustments => $adjustments,
129
    total => $total,
136
    total => $total,
130
    fund_code => $fund_code
137
    fund_code => $fund_code
131
);
138
);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-3 / +115 lines)
Lines 2-7 Link Here
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE Price %]
3
[% USE Price %]
4
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
5
[% USE AuthorisedValues %]
6
5
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
8
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
7
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
9
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
Lines 81-86 Link Here
81
            [% END %]
83
            [% END %]
82
        </fieldset>
84
        </fieldset>
83
      </form>
85
      </form>
86
      <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
87
          <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
88
              <table id="invoice_adj_table">
89
                  <tr>
90
                     <th>Id</th>
91
                     <th>Amount</th>
92
                     <th>Reason</th>
93
                     <th>Note</th>
94
                     <th>Fund</th>
95
                     <th>Encumber while invoice open</th>
96
                     <th>&nbsp</th>
97
                  </tr>
98
                  [% IF (adjustments.count > 0) %]
99
                  <tr><td colspan="7">Current adjustments</td></tr>
100
                  [% total_adj = 0 %]
101
                  [% FOREACH adjustment IN adjustments %]
102
                  [% total_adj = total_adj + adjustment.adjustment %]
103
                  <tr>
104
                      <td><input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id %]" />[% adjustment.adjustment_id %]</td>
105
                      <td><input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id %]" value="[% adjustment.adjustment | $Price %]" /></td>
106
                      <td>
107
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
108
                          [% IF reasons %]
109
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
110
                                  <option value="">No reason</option>
111
                              [% FOREACH reason IN reasons %]
112
                                [% IF ( adjustment.reason == reason.authorised_value ) %]
113
                                  <option selected="selected" value="[% reason.authorised_value %]">
114
                                [% ELSE %]
115
                                  <option value="[% reason.authorised_value %]">
116
                                [% END %]
117
                                  [% reason.lib %]
118
                                  </option>
119
                              [% END %]
120
                          </select>
121
                          [% ELSE %]
122
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
123
                          <input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id %]" value="" />
124
                          [% END %]
125
                      </td>
126
                      <td><input type="text" name="note" id="note_new" value="[% adjustment.note %]"/></td>
127
                      <td>
128
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
129
                                  <option value="">No fund</option>
130
                              [% FOREACH budget IN budgets_loop %]
131
                                [% IF ( budget.budget_id == adjustment.budget_id ) %]
132
                                  <option selected="selected" value="[% budget.budget_id %]">
133
                                [% ELSE %]
134
                                  <option value="[% budget.budget_id %]">
135
                                [% END %]
136
                                  [% budget.budget_name %]
137
                                  </option>
138
                              [% END %]
139
                          </select>
140
                      </td>
141
                      [% IF adjustment.encumber_open %]
142
                      <td>
143
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" checked/>
144
                      </td>
145
                      [% ELSE %]
146
                      <td>
147
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" />
148
                      </td>
149
                      [% END %]
150
                      <td>
151
                          <a class="btn btn-default btn-xs" href="/cgi-bin/koha/acqui/invoice.pl?op=del_adj&adjustment_id=[% adjustment.adjustment_id %]&invoiceid=[% invoiceid %]"><i class="fa fa-trash"></i> Delete</a>
152
                      </td>
153
                  </tr>
154
                  [% END %]
155
                  [% END %]
156
                  <tr><td colspan="7">Add an adjustment</td></tr>
157
                      <td><input type="hidden" name="adjustment_id" value="new" />New</td>
158
                      <td><input type="text" name="adjustment" id="adjustment_new]" /></td>
159
                      <td>
160
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
161
                          [% IF reasons %]
162
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
163
                                  <option value="">No reason</option>
164
                                [% FOREACH reason IN reasons %]
165
                                  <option value="[% reason.authorised_value %]">
166
                                  [% reason.lib %]
167
                                  </option>
168
                                [% END %]
169
                          </select>
170
                          [% ELSE %]
171
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
172
                          [% END %]
173
                      </td>
174
                      <td><input type="text" name="note" id="note_new" value=""/></td>
175
                      <td>
176
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
177
                               <option selected="selected" value="">No fund</option>
178
                               [% FOREACH budget IN budgets_loop %]
179
                               <option value="[% budget.budget_id %]">
180
                               [% budget.budget_name %]
181
                               </option>
182
                               [% END %]
183
                          </select>
184
                      </td>
185
                      <td><input type="checkbox" name="encumber_open" id="encumber_new" value="1" /></td>
186
                      <td><input type="hidden" name="delete" value=""></td>
187
                  </tr>
188
                </table>
189
          <input type="hidden" name="op" value="mod_adj" />
190
          <input type="submit" value="Update adjustments" />
191
      </form>
84
      <p>
192
      <p>
85
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
193
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
86
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
194
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
Lines 161-171 Link Here
161
                <th>&nbsp;</th>
269
                <th>&nbsp;</th>
162
              </tr>
270
              </tr>
163
              <tr>
271
              <tr>
164
                <th colspan="2">Total + Shipment cost ([% currency.symbol %])</th>
272
                <th colspan="2">Total + Adjustments + Shipment cost ([% currency.symbol %])</th>
165
                <th class="tax_excluded"></th>
273
                <th class="tax_excluded"></th>
166
                <th class="tax_included"></th>
274
                <th class="tax_included"></th>
167
                <th>[% total_quantity %]</th>
275
                <th>[% total_quantity %]</th>
168
                <th class="tax_excluded">[% total_tax_excluded_shipment | $Price %]</th>
276
                <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
169
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
277
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
170
                <th>&nbsp;</th>
278
                <th>&nbsp;</th>
171
                <th>[% total_tax_value | $Price %]</th>
279
                <th>[% total_tax_value | $Price %]</th>
Lines 174-180 Link Here
174
            </tfoot>
282
            </tfoot>
175
          </table>
283
          </table>
176
        [% ELSE %]
284
        [% ELSE %]
177
            <div class="dialog message"><p>No orders yet</p></div>
285
            <div class="dialog message"><p>No orders yet</p>
286
            [% IF adjustments.count > 0 || shipmentcost > 0 %]
287
            <p>Adjustments plus shipping:[% total_adj + shipmentcost | $Price %]</p>
288
            [% END %]
289
            </div>
178
        [% END %]
290
        [% END %]
179
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
291
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
180
            <br />
292
            <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 (-1 / +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>
(-)a/t/db_dependent/Koha/InvoiceAdjustments.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 6;
23
24
use Koha::Database;
25
26
use t::lib::TestBuilder;
27
28
BEGIN {
29
    use_ok('Koha::InvoiceAdjustments');
30
}
31
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $builder = t::lib::TestBuilder->new;
36
my $nb_of_adjs = Koha::InvoiceAdjustments->search->count;
37
my $budget_id = $builder->build({source=>'Aqbudget'})->{budget_id};
38
my $invoice_id = $builder->build({source=>'Aqinvoice'})->{invoiceid};
39
40
my $new_adj = Koha::InvoiceAdjustment->new({
41
    note => 'noted',
42
    invoiceid => $invoice_id,
43
    adjustment => '3',
44
    reason => 'unreasonable',
45
    budget_id => $budget_id,
46
})->store;
47
48
like( $new_adj->adjustment_id, qr|^\d+$|, 'Adding a new adjustment should have set the adjustment_id');
49
50
my $new_adj2 = Koha::InvoiceAdjustment->new({
51
    note => 'not noted',
52
    invoiceid => $invoice_id,
53
    adjustment => '-3',
54
    reason => 'unreasonable',
55
    budget_id => $budget_id,
56
})->store;
57
58
ok( $new_adj->adjustment_id < $new_adj2->adjustment_id, 'Adding a new adjustment should increment');
59
is( Koha::InvoiceAdjustments->search->count, $nb_of_adjs + 2, 'The 2 adjustments should have been added' );
60
61
my $retrieved_adj = Koha::InvoiceAdjustments->find( $new_adj->adjustment_id );
62
is( $retrieved_adj->reason, $new_adj->reason, 'Find an adjustment by id should return the correct adjustment' );
63
64
$retrieved_adj->delete;
65
is( Koha::InvoiceAdjustments->search->count, $nb_of_adjs + 1, 'Delete should have deleted the adjustment' );
66
67
$schema->storage->txn_rollback;

Return to bug 19166