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 / +114 lines)
Lines 1-6 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE Price %]
3
[% USE Price %]
4
[% USE AuthorisedValues %]
4
5
5
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
7
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
Lines 127-132 Link Here
127
            [% END %]
128
            [% END %]
128
        </fieldset>
129
        </fieldset>
129
      </form>
130
      </form>
131
      <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
132
          <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
133
              <table id="invoice_adj_table">
134
                  <tr>
135
                     <th>Id</th>
136
                     <th>Amount</th>
137
                     <th>Reason</th>
138
                     <th>Note</th>
139
                     <th>Fund</th>
140
                     <th>Encumber while invoice open</th>
141
                     <th>&nbsp</th>
142
                  </tr>
143
                  [% IF (adjustments.count > 0) %]
144
                  <tr><td colspan="7">Current adjustments</td></tr>
145
                  [% total_adj = 0 %]
146
                  [% FOREACH adjustment IN adjustments %]
147
                  [% total_adj = total_adj + adjustment.adjustment %]
148
                  <tr>
149
                      <td><input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id %]" />[% adjustment.adjustment_id %]</td>
150
                      <td><input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id %]" value="[% adjustment.adjustment | $Price %]" /></td>
151
                      <td>
152
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
153
                          [% IF reasons %]
154
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
155
                                  <option value="">No reason</option>
156
                              [% FOREACH reason IN reasons %]
157
                                [% IF ( adjustment.reason == reason.authorised_value ) %]
158
                                  <option selected="selected" value="[% reason.authorised_value %]">
159
                                [% ELSE %]
160
                                  <option value="[% reason.authorised_value %]">
161
                                [% END %]
162
                                  [% reason.lib %]
163
                                  </option>
164
                              [% END %]
165
                          </select>
166
                          [% ELSE %]
167
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
168
                          <input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id %]" value="" />
169
                          [% END %]
170
                      </td>
171
                      <td><input type="text" name="note" id="note_new" value="[% adjustment.note %]"/></td>
172
                      <td>
173
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
174
                                  <option value="">No fund</option>
175
                              [% FOREACH budget IN budgets_loop %]
176
                                [% IF ( budget.budget_id == adjustment.budget_id ) %]
177
                                  <option selected="selected" value="[% budget.budget_id %]">
178
                                [% ELSE %]
179
                                  <option value="[% budget.budget_id %]">
180
                                [% END %]
181
                                  [% budget.budget_name %]
182
                                  </option>
183
                              [% END %]
184
                          </select>
185
                      </td>
186
                      [% IF adjustment.encumber_open %]
187
                      <td>
188
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" checked/>
189
                      </td>
190
                      [% ELSE %]
191
                      <td>
192
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" />
193
                      </td>
194
                      [% END %]
195
                      <td>
196
                          <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>
197
                      </td>
198
                  </tr>
199
                  [% END %]
200
                  [% END %]
201
                  <tr><td colspan="7">Add an adjustment</td></tr>
202
                      <td><input type="hidden" name="adjustment_id" value="new" />New</td>
203
                      <td><input type="text" name="adjustment" id="adjustment_new]" /></td>
204
                      <td>
205
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
206
                          [% IF reasons %]
207
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
208
                                  <option value="">No reason</option>
209
                                [% FOREACH reason IN reasons %]
210
                                  <option value="[% reason.authorised_value %]">
211
                                  [% reason.lib %]
212
                                  </option>
213
                                [% END %]
214
                          </select>
215
                          [% ELSE %]
216
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
217
                          [% END %]
218
                      </td>
219
                      <td><input type="text" name="note" id="note_new" value=""/></td>
220
                      <td>
221
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
222
                               <option selected="selected" value="">No fund</option>
223
                               [% FOREACH budget IN budgets_loop %]
224
                               <option value="[% budget.budget_id %]">
225
                               [% budget.budget_name %]
226
                               </option>
227
                               [% END %]
228
                          </select>
229
                      </td>
230
                      <td><input type="checkbox" name="encumber_open" id="encumber_new" value="1" /></td>
231
                      <td><input type="hidden" name="delete" value=""></td>
232
                  </tr>
233
                </table>
234
          <input type="hidden" name="op" value="mod_adj" />
235
          <input type="submit" value="Update adjustments" />
236
      </form>
130
      <p>
237
      <p>
131
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
238
          <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 %]
239
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
Lines 207-217 Link Here
207
                <th>&nbsp;</th>
314
                <th>&nbsp;</th>
208
              </tr>
315
              </tr>
209
              <tr>
316
              <tr>
210
                <th colspan="2">Total + Shipment cost ([% currency.symbol %])</th>
317
                <th colspan="2">Total + Adjustments + Shipment cost ([% currency.symbol %])</th>
211
                <th class="tax_excluded"></th>
318
                <th class="tax_excluded"></th>
212
                <th class="tax_included"></th>
319
                <th class="tax_included"></th>
213
                <th>[% total_quantity %]</th>
320
                <th>[% total_quantity %]</th>
214
                <th class="tax_excluded">[% total_tax_excluded_shipment | $Price %]</th>
321
                <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
215
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
322
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
216
                <th>&nbsp;</th>
323
                <th>&nbsp;</th>
217
                <th>[% total_tax_value | $Price %]</th>
324
                <th>[% total_tax_value | $Price %]</th>
Lines 220-226 Link Here
220
            </tfoot>
327
            </tfoot>
221
          </table>
328
          </table>
222
        [% ELSE %]
329
        [% ELSE %]
223
            <div class="dialog message"><p>No orders yet</p></div>
330
            <div class="dialog message"><p>No orders yet</p>
331
            [% IF adjustments.count > 0 || shipmentcost > 0 %]
332
            <p>Adjustments plus shipping:[% total_adj + shipmentcost | $Price %]</p>
333
            [% END %]
334
            </div>
224
        [% END %]
335
        [% END %]
225
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
336
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
226
            <br />
337
            <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 / +68 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;
68

Return to bug 19166