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

(-)a/C4/Acquisition.pm (-17 / +20 lines)
Lines 2919-2941 sub populate_order_with_prices { Link Here
2919
        }
2919
        }
2920
    }
2920
    }
2921
2921
2922
    # Not used yet
2922
    if ($receiving) {
2923
    #if ($receiving) {
2923
        # The following is completely wrong. Will be fixed later.
2924
    #    if ( $bookseller->{invoiceincgst} ) {
2924
        # See the unit tests to know what is wrong.
2925
    #        $order->{unitpricegsti} = $order->{unitprice};
2925
        if ( $bookseller->{listincgst} ) {
2926
    #        $order->{unitpricegste} =
2926
            $order->{unitpricegsti} = Koha::Number::Price->new( $order->{unitprice} )->format;
2927
    #          $order->{unitpricegsti} / ( 1 + $order->{gstrate} );
2927
            $order->{unitpricegste} = Koha::Number::Price->new(
2928
    #    }
2928
              $order->{unitpricegsti} / ( 1 + $order->{gstrate} ) )->format;
2929
    #    else {
2929
        }
2930
    #        $order->{unitpricegste} = $order->{unitprice};
2930
        else {
2931
    #        $order->{unitpricegsti} =
2931
            $order->{unitpricegste} = Koha::Number::Price->new( $order->{unitprice} )->format;
2932
    #          $order->{unitpricegste} * ( 1 + $order->{gstrate} );
2932
            $order->{unitpricegsti} = Koha::Number::Price->new(
2933
    #    }
2933
              $order->{unitpricegste} * ( 1 + $order->{gstrate} ) )->format;
2934
    #    $order->{gstvalue} =
2934
        }
2935
    #      $order->{quantityreceived} *
2935
        $order->{gstvalue} = Koha::Number::Price->new(
2936
    #      $order->{unitpricegste} *
2936
          ( $order->{unitpricegsti} - $order->{unitpricegste} )
2937
    #      $order->{gstrate};
2937
          * $order->{quantityreceived} )->format;
2938
    #}
2938
2939
        $order->{totalgste} = $order->{unitpricegste} * $order->{quantity};
2940
        $order->{totalgsti} = $order->{unitpricegsti} * $order->{quantity};
2941
    }
2939
2942
2940
    return $order;
2943
    return $order;
2941
}
2944
}
(-)a/acqui/invoice.pl (-18 / +8 lines)
Lines 121-129 my $total_gste = 0; Link Here
121
my $total_gsti = 0;
121
my $total_gsti = 0;
122
my $total_gstvalue = 0;
122
my $total_gstvalue = 0;
123
foreach my $order (@$orders) {
123
foreach my $order (@$orders) {
124
    $order = C4::Acquisition::populate_order_with_prices(
125
        {
126
            order        => $order,
127
            booksellerid => $bookseller->{id},
128
            receiving    => 1,
129
        }
130
    );
124
    my $line = get_infos( $order, $bookseller);
131
    my $line = get_infos( $order, $bookseller);
125
132
126
    $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti};
133
    $foot{$$line{gstgsti}}{gstrate} = $$line{gstrate};
127
    $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
134
    $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
128
    $total_gstvalue += $$line{gstvalue};
135
    $total_gstvalue += $$line{gstvalue};
129
    $foot{$$line{gstgsti}}{quantity}  += $$line{quantity};
136
    $foot{$$line{gstgsti}}{quantity}  += $$line{quantity};
Lines 193-215 sub get_infos { Link Here
193
    my %line = %{ $order };
200
    my %line = %{ $order };
194
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
201
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
195
    $line{budget_name}    = $budget->{budget_name};
202
    $line{budget_name}    = $budget->{budget_name};
196
    if ( $bookseller->{'listincgst'} ) {
197
        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
198
        $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
199
        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} );
200
        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) );
201
        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
202
        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
203
        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
204
    } else {
205
        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
206
        $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
207
        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) );
208
        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} );
209
        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
210
        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
211
        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
212
    }
213
203
214
    if ( $line{uncertainprice} ) {
204
    if ( $line{uncertainprice} ) {
215
        $template->param( uncertainprices => 1 );
205
        $template->param( uncertainprices => 1 );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-16 / +17 lines)
Lines 1-5 Link Here
1
[% USE Koha %]
1
[% USE Koha %]
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE Price %]
3
4
4
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
6
<title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
Lines 161-173 Link Here
161
                    [% END %]
162
                    [% END %]
162
                  </td>
163
                  </td>
163
                  <td><p>[% order.branchcode %]</p></td>
164
                  <td><p>[% order.branchcode %]</p></td>
164
                  <td class="number gste">[% order.actualcostgste %]</td>
165
                  <td class="number gste">[% order.unitpricegste | $Price %]</td>
165
                  <td class="number gsti">[% order.actualcostgsti %]</td>
166
                  <td class="number gsti">[% order.unitpricegsti | $Price %]</td>
166
                  <td class="number">[% order.quantity %]</td>
167
                  <td class="number">[% order.quantity %]</td>
167
                  <td class="number gste">[% order.totalgste %]</td>
168
                  <td class="number gste">[% order.totalgste | $Price %]</td>
168
                  <td class="number gsti">[% order.totalgsti %]</td>
169
                  <td class="number gsti">[% order.totalgsti | $Price %]</td>
169
                  <td class="number">[% order.gstgsti %]</td>
170
                  <td class="number">[% order.gstrate * 100 | $Price %]</td>
170
                  <td class="number">[% order.gstvalue %]</td>
171
                  <td class="number">[% order.gstvalue | $Price %]</td>
171
                  <td>[% order.budget_name %]</td>
172
                  <td>[% order.budget_name %]</td>
172
                </tr>
173
                </tr>
173
              [% END %]
174
              [% END %]
Lines 175-187 Link Here
175
            <tfoot>
176
            <tfoot>
176
              [% FOR tf IN foot_loop %]
177
              [% FOR tf IN foot_loop %]
177
                <tr>
178
                <tr>
178
                    <th colspan='3'>Total (GST [% tf.gstgsti %] %)</th>
179
                    <th colspan='3'>Total (GST [% tf.gstrate * 100 | $Price %] %)</th>
179
                    <th class="gste"/><th class="gsti"/>
180
                    <th class="gste"/><th class="gsti"/>
180
                    <th>[% tf.quantity %]</th>
181
                    <th>[% tf.quantity %]</th>
181
                    <th class="gste">[% tf.totalgste %]</th>
182
                    <th class="gste">[% tf.totalgste | $Price %]</th>
182
                    <th class="gsti">[% tf.totalgsti %]</th>
183
                    <th class="gsti">[% tf.totalgsti | $Price %]</th>
183
                    <th>&nbsp;</th>
184
                    <th>&nbsp;</th>
184
                    <th>[% tf.gstvalue %]</th>
185
                    <th>[% tf.gstvalue | $Price %]</th>
185
                    <th>&nbsp;</th>
186
                    <th>&nbsp;</th>
186
                </tr>
187
                </tr>
187
              [% END %]
188
              [% END %]
Lines 189-198 Link Here
189
                <th colspan='3'>Total ([% currency %])</th>
190
                <th colspan='3'>Total ([% currency %])</th>
190
                <th class="gste"/><th class="gsti"/>
191
                <th class="gste"/><th class="gsti"/>
191
                <th>[% total_quantity %]</th>
192
                <th>[% total_quantity %]</th>
192
                <th class="gste">[% total_gste %]</th>
193
                <th class="gste">[% total_gste | $Price %]</th>
193
                <th class="gsti">[% total_gsti %]</th>
194
                <th class="gsti">[% total_gsti | $Price %]</th>
194
                <th>&nbsp;</th>
195
                <th>&nbsp;</th>
195
                <th>[% total_gstvalue %]</th>
196
                <th>[% total_gstvalue | $Price %]</th>
196
                <th>&nbsp;</th>
197
                <th>&nbsp;</th>
197
              </tr>
198
              </tr>
198
              <tr>
199
              <tr>
Lines 200-209 Link Here
200
                <th class="gste"></th>
201
                <th class="gste"></th>
201
                <th class="gsti"></th>
202
                <th class="gsti"></th>
202
                <th>[% total_quantity %]</th>
203
                <th>[% total_quantity %]</th>
203
                <th class="gste">[% total_gste_shipment %]</th>
204
                <th class="gste">[% total_gste_shipment | $Price %]</th>
204
                <th class="gsti">[% total_gsti_shipment %]</th>
205
                <th class="gsti">[% total_gsti_shipment | $Price %]</th>
205
                <th>&nbsp;</th>
206
                <th>&nbsp;</th>
206
                <th>[% total_gstvalue %]</th>
207
                <th>[% total_gstvalue | $Price %]</th>
207
                <th>&nbsp;</th>
208
                <th>&nbsp;</th>
208
              </tr>
209
              </tr>
209
            </tfoot>
210
            </tfoot>
(-)a/t/Prices.t (-8 / +206 lines)
Lines 19-25 my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 ); Link Here
19
my $today;
19
my $today;
20
20
21
subtest 'Configuration 1: 0 0' => sub {
21
subtest 'Configuration 1: 0 0' => sub {
22
    plan tests => 7;
22
    plan tests => 12;
23
    $bookseller_module->mock(
23
    $bookseller_module->mock(
24
        'fetch',
24
        'fetch',
25
        sub {
25
        sub {
Lines 108-117 subtest 'Configuration 1: 0 0' => sub { Link Here
108
            field    => 'totalgste'
108
            field    => 'totalgste'
109
        }
109
        }
110
    );
110
    );
111
112
    $order_0_0 = C4::Acquisition::populate_order_with_prices(
113
        {
114
            order        => $order_0_0,
115
            booksellerid => 'just_something',
116
            receiving    => 1,
117
        }
118
    );
119
    # Note that this configuration is *not* correct!
120
    # unitpricegsti should be 75.28
121
    # totalgst should be 150.56
122
    compare(
123
        {
124
            got      => $order_0_0->{unitpricegsti},
125
            expected => 77.49,
126
            conf     => '0 0',
127
            field    => 'unitpricegsti'
128
        }
129
    );
130
    compare(
131
        {
132
            got      => $order_0_0->{unitpricegste},
133
            expected => 73.80,
134
            conf     => '0 0',
135
            field    => 'unitpricegste'
136
        }
137
    );
138
    compare(
139
        {
140
            got      => $order_0_0->{gstvalue},
141
            expected => 7.38,
142
            conf     => '0 0',
143
            field    => 'gstvalue'
144
        }
145
    );
146
    compare(
147
        {
148
            got      => $order_0_0->{totalgsti},
149
            expected => 154.98,
150
            conf     => '0 0',
151
            field    => 'totalgsti'
152
        }
153
    );
154
    compare(
155
        {
156
            got      => $order_0_0->{totalgste},
157
            expected => 147.60,
158
            conf     => '0 0',
159
            field    => 'totalgste'
160
        }
161
    );
111
};
162
};
112
163
113
subtest 'Configuration 1: 1 1' => sub {
164
subtest 'Configuration 1: 1 1' => sub {
114
    plan tests => 7;
165
    plan tests => 12;
115
    $bookseller_module->mock(
166
    $bookseller_module->mock(
116
        'fetch',
167
        'fetch',
117
        sub {
168
        sub {
Lines 142-148 subtest 'Configuration 1: 1 1' => sub { Link Here
142
            ordering     => 1,
193
            ordering     => 1,
143
        }
194
        }
144
    );
195
    );
145
146
    # Note that this configuration is *not* correct
196
    # Note that this configuration is *not* correct
147
    # gstvalue should be 7.03 instead of 7.02
197
    # gstvalue should be 7.03 instead of 7.02
148
    compare(
198
    compare(
Lines 201-210 subtest 'Configuration 1: 1 1' => sub { Link Here
201
            field    => 'totalgste'
251
            field    => 'totalgste'
202
        }
252
        }
203
    );
253
    );
254
255
    $order_1_1 = C4::Acquisition::populate_order_with_prices(
256
        {
257
            order        => $order_1_1,
258
            booksellerid => 'just_something',
259
            receiving    => 1,
260
        }
261
    );
262
    # Note that this configuration is *not* correct!
263
    # gstvalue should be 7.03
264
    compare(
265
        {
266
            got      => $order_1_1->{unitpricegsti},
267
            expected => 73.80,
268
            conf     => '1 1',
269
            field    => 'unitpricegsti'
270
        }
271
    );
272
    compare(
273
        {
274
            got      => $order_1_1->{unitpricegste},
275
            expected => 70.29,
276
            conf     => '1 1',
277
            field    => 'unitpricegste'
278
        }
279
    );
280
    compare(
281
        {
282
            got      => $order_1_1->{gstvalue},
283
            expected => 7.02,
284
            conf     => '1 1',
285
            field    => 'gstvalue'
286
        }
287
    );
288
    compare(
289
        {
290
            got      => $order_1_1->{totalgsti},
291
            expected => 147.60,
292
            conf     => '1 1',
293
            field    => 'totalgsti'
294
        }
295
    );
296
    compare(
297
        {
298
            got      => $order_1_1->{totalgste},
299
            expected => 140.58,
300
            conf     => '1 1',
301
            field    => 'totalgste'
302
        }
303
    );
204
};
304
};
205
305
206
subtest 'Configuration 1: 1 0' => sub {
306
subtest 'Configuration 1: 1 0' => sub {
207
    plan tests => 7;
307
    plan tests => 12;
208
    $bookseller_module->mock(
308
    $bookseller_module->mock(
209
        'fetch',
309
        'fetch',
210
        sub {
310
        sub {
Lines 235-245 subtest 'Configuration 1: 1 0' => sub { Link Here
235
            ordering     => 1,
335
            ordering     => 1,
236
        }
336
        }
237
    );
337
    );
238
239
    # Note that this configuration is *not* correct!
338
    # Note that this configuration is *not* correct!
240
    # rrp gsti should be 82 (what we inserted!)
339
    # rrp gsti should be 82 (what we inserted!)
241
    # gstvalue should be 7.03 instead of 7.02
340
    # gstvalue should be 7.03 instead of 7.02
242
243
    compare(
341
    compare(
244
        {
342
        {
245
            got      => $order_1_0->{rrpgsti},
343
            got      => $order_1_0->{rrpgsti},
Lines 296-305 subtest 'Configuration 1: 1 0' => sub { Link Here
296
            field    => 'totalgste'
394
            field    => 'totalgste'
297
        }
395
        }
298
    );
396
    );
397
398
    $order_1_0 = C4::Acquisition::populate_order_with_prices(
399
        {
400
            order        => $order_1_0,
401
            booksellerid => 'just_something',
402
            receiving    => 1,
403
        }
404
    );
405
    # Note that this configuration is *not* correct!
406
    # unitpricegsti should be 71.69
407
    # totalgsti should be 143.38
408
    # gstvalue should be 7.03
409
    compare(
410
        {
411
            got      => $order_1_0->{unitpricegsti},
412
            expected => 73.80,
413
            conf     => '1 0',
414
            field    => 'unitpricegsti'
415
        }
416
    );
417
    compare(
418
        {
419
            got      => $order_1_0->{unitpricegste},
420
            expected => 70.29,
421
            conf     => '1 0',
422
            field    => 'unitpricegste'
423
        }
424
    );
425
    compare(
426
        {
427
            got      => $order_1_0->{gstvalue},
428
            expected => 7.02,
429
            conf     => '1 0',
430
            field    => 'gstvalue'
431
        }
432
    );
433
    compare(
434
        {
435
            got      => $order_1_0->{totalgsti},
436
            expected => 147.60,
437
            conf     => '1 0',
438
            field    => 'totalgsti'
439
        }
440
    );
441
    compare(
442
        {
443
            got      => $order_1_0->{totalgste},
444
            expected => 140.58,
445
            conf     => '1 0',
446
            field    => 'totalgste'
447
        }
448
    );
299
};
449
};
300
450
301
subtest 'Configuration 1: 0 1' => sub {
451
subtest 'Configuration 1: 0 1' => sub {
302
    plan tests => 7;
452
    plan tests => 12;
303
    $bookseller_module->mock(
453
    $bookseller_module->mock(
304
        'fetch',
454
        'fetch',
305
        sub {
455
        sub {
Lines 388-393 subtest 'Configuration 1: 0 1' => sub { Link Here
388
            field    => 'totalgste'
538
            field    => 'totalgste'
389
        }
539
        }
390
    );
540
    );
541
542
    $order_0_1 = C4::Acquisition::populate_order_with_prices(
543
        {
544
            order        => $order_0_1,
545
            booksellerid => 'just_something',
546
            receiving    => 1,
547
        }
548
    );
549
    # Note that this configuration is correct
550
    compare(
551
        {
552
            got      => $order_0_1->{unitpricegsti},
553
            expected => 77.49,
554
            conf     => '0 1',
555
            field    => 'unitpricegsti'
556
        }
557
    );
558
    compare(
559
        {
560
            got      => $order_0_1->{unitpricegste},
561
            expected => 73.80,
562
            conf     => '0 1',
563
            field    => 'unitpricegste'
564
        }
565
    );
566
    compare(
567
        {
568
            got      => $order_0_1->{gstvalue},
569
            expected => 7.38,
570
            conf     => '0 1',
571
            field    => 'gstvalue'
572
        }
573
    );
574
    compare(
575
        {
576
            got      => $order_0_1->{totalgsti},
577
            expected => 154.98,
578
            conf     => '0 1',
579
            field    => 'totalgsti'
580
        }
581
    );
582
    compare(
583
        {
584
            got      => $order_0_1->{totalgste},
585
            expected => 147.60,
586
            conf     => '0 1',
587
            field    => 'totalgste'
588
        }
589
    );
391
};
590
};
392
591
393
sub compare {
592
sub compare {
394
- 

Return to bug 12976