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 38-43 use Koha::Acquisition::Booksellers; Link Here
38
use Koha::Acquisition::Currencies;
38
use Koha::Acquisition::Currencies;
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Misc::Files;
40
use Koha::Misc::Files;
41
use Koha::InvoiceAdjustments;
41
42
42
my $input = new CGI;
43
my $input = new CGI;
43
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
44
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
Lines 108-114 elsif ( $op && $op eq 'delete' ) { Link Here
108
        exit 0;
109
        exit 0;
109
    }
110
    }
110
}
111
}
112
elsif ( $op && $op eq 'del_adj' ) {
113
    my $adjustment_id  = $input->param('adjustment_id');
114
    my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id );
115
    $del_adj->delete() if ($del_adj);
116
}
117
elsif ( $op && $op eq 'mod_adj' ) {
118
    my @adjustment_id  = $input->multi_param('adjustment_id');
119
    my @adjustment     = $input->multi_param('adjustment');
120
    my @reason         = $input->multi_param('reason');
121
    my @note           = $input->multi_param('note');
122
    my @budget_id      = $input->multi_param('budget_id');
123
    my @encumber_open  = $input->multi_param('encumber_open');
124
    my %e_open = map { $_ => 1 } @encumber_open;
111
125
126
    for( my $i=0; $i < scalar @adjustment; $i++ ){
127
        if( $adjustment_id[$i] eq 'new' ){
128
            next unless ( $adjustment[$i] || $reason[$i] );
129
            my $new_adj = Koha::InvoiceAdjustment->new({
130
                invoiceid => $invoiceid,
131
                adjustment => $adjustment[$i],
132
                reason => $reason[$i],
133
                note => $note[$i],
134
                budget_id => $budget_id[$i] || undef,
135
                encumber_open => $encumber_open[$i],
136
            });
137
            $new_adj->store();
138
        }
139
        else {
140
            my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] );
141
            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] ){
142
                $old_adj->timestamp(undef);
143
                $old_adj->adjustment( $adjustment[$i] );
144
                $old_adj->reason( $reason[$i] );
145
                $old_adj->note( $note[$i] );
146
                $old_adj->budget_id( $budget_id[$i] || undef );
147
                $old_adj->encumber_open( $e_open{$adjustment_id[$i]} ? 1 : 0 );
148
                $old_adj->update();
149
            }
150
        }
151
    }
152
}
112
153
113
my $details = GetInvoiceDetails($invoiceid);
154
my $details = GetInvoiceDetails($invoiceid);
114
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
155
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
Lines 159-164 foreach my $budget (@$budgets) { Link Here
159
    push @budgets_loop, \%line;
200
    push @budgets_loop, \%line;
160
}
201
}
161
202
203
my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} });
204
if ( $adjustments ) { $template->param( adjustments => $adjustments ); }
205
162
$template->param(
206
$template->param(
163
    invoiceid        => $details->{'invoiceid'},
207
    invoiceid        => $details->{'invoiceid'},
164
    invoicenumber    => $details->{'invoicenumber'},
208
    invoicenumber    => $details->{'invoicenumber'},
(-)a/acqui/ordered.pl (+8 lines)
Lines 32-37 use Modern::Perl; Link Here
32
use CGI qw ( -utf8 );
32
use CGI qw ( -utf8 );
33
use C4::Auth;
33
use C4::Auth;
34
use C4::Output;
34
use C4::Output;
35
use Koha::InvoiceAdjustments;
35
36
36
my $dbh     = C4::Context->dbh;
37
my $dbh     = C4::Context->dbh;
37
my $input   = new CGI;
38
my $input   = new CGI;
Lines 95-106 while ( my $data = $sth->fetchrow_hashref ) { Link Here
95
        $total += $subtotal;
96
        $total += $subtotal;
96
    }
97
    }
97
}
98
}
99
100
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } );
101
while ( my $adj = $adjustments->next ){
102
    $total += $adj->adjustment;
103
}
104
98
$total = sprintf( "%.2f", $total );
105
$total = sprintf( "%.2f", $total );
99
106
100
$template->{VARS}->{'fund'}    = $fund_id;
107
$template->{VARS}->{'fund'}    = $fund_id;
101
$template->{VARS}->{'ordered'} = \@ordered;
108
$template->{VARS}->{'ordered'} = \@ordered;
102
$template->{VARS}->{'total'}   = $total;
109
$template->{VARS}->{'total'}   = $total;
103
$template->{VARS}->{'fund_code'} = $fund_code;
110
$template->{VARS}->{'fund_code'} = $fund_code;
111
$template->{VARS}->{'adjustments'} = $adjustments;
104
112
105
$sth->finish;
113
$sth->finish;
106
114
(-)a/acqui/spent.pl (+7 lines)
Lines 34-39 use C4::Auth; Link Here
34
use C4::Output;
34
use C4::Output;
35
use Modern::Perl;
35
use Modern::Perl;
36
use CGI qw ( -utf8 );
36
use CGI qw ( -utf8 );
37
use Koha::InvoiceAdjustments;
37
38
38
my $dbh      = C4::Context->dbh;
39
my $dbh      = C4::Context->dbh;
39
my $input    = new CGI;
40
my $input    = new CGI;
Lines 118-123 while (my $data = $sth->fetchrow_hashref) { Link Here
118
}
119
}
119
$sth->finish;
120
$sth->finish;
120
121
122
my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } );
123
while ( my $adj = $adjustments->next ){
124
    $total += $adj->adjustment;
125
}
126
121
$total = sprintf( "%.2f", $total );
127
$total = sprintf( "%.2f", $total );
122
128
123
$template->param(
129
$template->param(
Lines 125-130 $template->param( Link Here
125
    spent => \@spent,
131
    spent => \@spent,
126
    subtotal => $subtotal,
132
    subtotal => $subtotal,
127
    shipmentcosts => \@shipmentcosts,
133
    shipmentcosts => \@shipmentcosts,
134
    adjustments => $adjustments,
128
    total => $total,
135
    total => $total,
129
    fund_code => $fund_code
136
    fund_code => $fund_code
130
);
137
);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-3 / +115 lines)
Lines 3-8 Link Here
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Price %]
4
[% USE Price %]
5
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
6
[% USE AuthorisedValues %]
7
6
[% INCLUDE 'doc-head-open.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
9
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
8
[% Asset.css("css/datatables.css") %]
10
[% Asset.css("css/datatables.css") %]
Lines 82-87 Link Here
82
            [% END %]
84
            [% END %]
83
        </fieldset>
85
        </fieldset>
84
      </form>
86
      </form>
87
      <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
88
          <input type="hidden" name="invoiceid" value="[% invoiceid %]" />
89
              <table id="invoice_adj_table">
90
                  <tr>
91
                     <th>Id</th>
92
                     <th>Amount</th>
93
                     <th>Reason</th>
94
                     <th>Note</th>
95
                     <th>Fund</th>
96
                     <th>Encumber while invoice open</th>
97
                     <th>&nbsp</th>
98
                  </tr>
99
                  [% IF (adjustments.count > 0) %]
100
                  <tr><td colspan="7">Current adjustments</td></tr>
101
                  [% total_adj = 0 %]
102
                  [% FOREACH adjustment IN adjustments %]
103
                  [% total_adj = total_adj + adjustment.adjustment %]
104
                  <tr>
105
                      <td><input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id %]" />[% adjustment.adjustment_id %]</td>
106
                      <td><input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id %]" value="[% adjustment.adjustment | $Price %]" /></td>
107
                      <td>
108
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
109
                          [% IF reasons %]
110
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
111
                                  <option value="">No reason</option>
112
                              [% FOREACH reason IN reasons %]
113
                                [% IF ( adjustment.reason == reason.authorised_value ) %]
114
                                  <option selected="selected" value="[% reason.authorised_value %]">
115
                                [% ELSE %]
116
                                  <option value="[% reason.authorised_value %]">
117
                                [% END %]
118
                                  [% reason.lib %]
119
                                  </option>
120
                              [% END %]
121
                          </select>
122
                          [% ELSE %]
123
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
124
                          <input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id %]" value="" />
125
                          [% END %]
126
                      </td>
127
                      <td><input type="text" name="note" id="note_new" value="[% adjustment.note %]"/></td>
128
                      <td>
129
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
130
                                  <option value="">No fund</option>
131
                              [% FOREACH budget IN budgets_loop %]
132
                                [% IF ( budget.budget_id == adjustment.budget_id ) %]
133
                                  <option selected="selected" value="[% budget.budget_id %]">
134
                                [% ELSE %]
135
                                  <option value="[% budget.budget_id %]">
136
                                [% END %]
137
                                  [% budget.budget_name %]
138
                                  </option>
139
                              [% END %]
140
                          </select>
141
                      </td>
142
                      [% IF adjustment.encumber_open %]
143
                      <td>
144
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" checked/>
145
                      </td>
146
                      [% ELSE %]
147
                      <td>
148
                          <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]"  value="[% adjustment.adjustment_id %]" />
149
                      </td>
150
                      [% END %]
151
                      <td>
152
                          <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>
153
                      </td>
154
                  </tr>
155
                  [% END %]
156
                  [% END %]
157
                  <tr><td colspan="7">Add an adjustment</td></tr>
158
                      <td><input type="hidden" name="adjustment_id" value="new" />New</td>
159
                      <td><input type="text" name="adjustment" id="adjustment_new]" /></td>
160
                      <td>
161
                          [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
162
                          [% IF reasons %]
163
                          <select id="reason_[% adjustment.adjustment_id %]" name="reason">
164
                                  <option value="">No reason</option>
165
                                [% FOREACH reason IN reasons %]
166
                                  <option value="[% reason.authorised_value %]">
167
                                  [% reason.lib %]
168
                                  </option>
169
                                [% END %]
170
                          </select>
171
                          [% ELSE %]
172
                          <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
173
                          [% END %]
174
                      </td>
175
                      <td><input type="text" name="note" id="note_new" value=""/></td>
176
                      <td>
177
                          <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
178
                               <option selected="selected" value="">No fund</option>
179
                               [% FOREACH budget IN budgets_loop %]
180
                               <option value="[% budget.budget_id %]">
181
                               [% budget.budget_name %]
182
                               </option>
183
                               [% END %]
184
                          </select>
185
                      </td>
186
                      <td><input type="checkbox" name="encumber_open" id="encumber_new" value="1" /></td>
187
                      <td><input type="hidden" name="delete" value=""></td>
188
                  </tr>
189
                </table>
190
          <input type="hidden" name="op" value="mod_adj" />
191
          <input type="submit" value="Update adjustments" />
192
      </form>
85
      <p>
193
      <p>
86
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
194
          <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
87
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
195
          [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %]
Lines 162-172 Link Here
162
                <th>&nbsp;</th>
270
                <th>&nbsp;</th>
163
              </tr>
271
              </tr>
164
              <tr>
272
              <tr>
165
                <th colspan="2">Total + Shipment cost ([% currency.symbol %])</th>
273
                <th colspan="2">Total + Adjustments + Shipment cost ([% currency.symbol %])</th>
166
                <th class="tax_excluded"></th>
274
                <th class="tax_excluded"></th>
167
                <th class="tax_included"></th>
275
                <th class="tax_included"></th>
168
                <th>[% total_quantity %]</th>
276
                <th>[% total_quantity %]</th>
169
                <th class="tax_excluded">[% total_tax_excluded_shipment | $Price %]</th>
277
                <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
170
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
278
                <th class="tax_included">[% total_tax_included_shipment | $Price %]</th>
171
                <th>&nbsp;</th>
279
                <th>&nbsp;</th>
172
                <th>[% total_tax_value | $Price %]</th>
280
                <th>[% total_tax_value | $Price %]</th>
Lines 175-181 Link Here
175
            </tfoot>
283
            </tfoot>
176
          </table>
284
          </table>
177
        [% ELSE %]
285
        [% ELSE %]
178
            <div class="dialog message"><p>No orders yet</p></div>
286
            <div class="dialog message"><p>No orders yet</p>
287
            [% IF adjustments.count > 0 || shipmentcost > 0 %]
288
            <p>Adjustments plus shipping:[% total_adj + shipmentcost | $Price %]</p>
289
            [% END %]
290
            </div>
179
        [% END %]
291
        [% END %]
180
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
292
        [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
181
            <br />
293
            <br />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt (+10 lines)
Lines 73-78 Link Here
73
[% END %]
73
[% END %]
74
    </tbody>
74
    </tbody>
75
    <tfoot>
75
    <tfoot>
76
    [% IF ( adjustments.count > 0 ) %]
77
            [% FOREACH adjustment IN adjustments %]
78
                <tr>
79
                    <td></td>
80
                    <td colspan="6">Adjustment cost for invoice [% adjustment.invoiceid %]</td>
81
                    <td class="data total">[% adjustment.adjustment %]</td>
82
                </tr>
83
            [% END %]
84
85
    [% END %]
76
    <tr>
86
    <tr>
77
        <td> Total </td>
87
        <td> Total </td>
78
        <td> </td>
88
        <td> </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt (-1 / +12 lines)
Lines 77-87 Link Here
77
    [% END %]
77
    [% END %]
78
78
79
    <tfoot>
79
    <tfoot>
80
        [% IF shipmentcosts.size %]
80
        [% IF shipmentcosts.size || ( adjustments.count > 0 ) %]
81
            <tr valign="top">
81
            <tr valign="top">
82
                <td colspan="9"> Sub total </td>
82
                <td colspan="9"> Sub total </td>
83
                <td class="data"> [% subtotal %] </td>
83
                <td class="data"> [% subtotal %] </td>
84
            </tr>
84
            </tr>
85
        [% END %]
86
        [% IF shipmentcosts.size %]
85
            [% FOREACH shipmentcost IN shipmentcosts %]
87
            [% FOREACH shipmentcost IN shipmentcosts %]
86
                <tr>
88
                <tr>
87
                    <td></td>
89
                    <td></td>
Lines 90-95 Link Here
90
                </tr>
92
                </tr>
91
            [% END %]
93
            [% END %]
92
        [% END %]
94
        [% END %]
95
        [% IF ( adjustments.count > 0 ) %]
96
            [% FOREACH adjustment IN adjustments %]
97
                <tr>
98
                    <td></td>
99
                    <td colspan="8">Adjustment cost for invoice [% adjustment.invoiceid %]</td>
100
                    <td class="data total">[% adjustment.adjustment %]</td>
101
                </tr>
102
            [% END %]
103
        [% END %]
93
        <tr>
104
        <tr>
94
            <td colspan="9">TOTAL</td>
105
            <td colspan="9">TOTAL</td>
95
            <td class="data total">[% total %]</td>
106
            <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