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} )->round;
2927
    #          $order->{unitpricegsti} / ( 1 + $order->{gstrate} );
2927
            $order->{unitpricegste} = Koha::Number::Price->new(
2928
    #    }
2928
              $order->{unitpricegsti} / ( 1 + $order->{gstrate} ) )->round;
2929
    #    else {
2929
        }
2930
    #        $order->{unitpricegste} = $order->{unitprice};
2930
        else {
2931
    #        $order->{unitpricegsti} =
2931
            $order->{unitpricegste} = Koha::Number::Price->new( $order->{unitprice} )->round;
2932
    #          $order->{unitpricegste} * ( 1 + $order->{gstrate} );
2932
            $order->{unitpricegsti} = Koha::Number::Price->new(
2933
    #    }
2933
              $order->{unitpricegste} * ( 1 + $order->{gstrate} ) )->round;
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} )->round;
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 (-5 / +206 lines)
Lines 21-27 my $today; Link Here
21
for my $currency_format ( qw( US FR ) ) {
21
for my $currency_format ( qw( US FR ) ) {
22
    t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
22
    t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
23
    subtest 'Configuration 1: 0 0' => sub {
23
    subtest 'Configuration 1: 0 0' => sub {
24
        plan tests => 7;
24
        plan tests => 12;
25
        $bookseller_module->mock(
25
        $bookseller_module->mock(
26
            'fetch',
26
            'fetch',
27
            sub {
27
            sub {
Lines 110-119 for my $currency_format ( qw( US FR ) ) { Link Here
110
                field    => 'totalgste'
110
                field    => 'totalgste'
111
            }
111
            }
112
        );
112
        );
113
114
        $order_0_0 = C4::Acquisition::populate_order_with_prices(
115
            {
116
                order        => $order_0_0,
117
                booksellerid => 'just_something',
118
                receiving    => 1,
119
            }
120
        );
121
        # Note that this configuration is *not* correct!
122
        # unitpricegsti should be 75.28
123
        # totalgst should be 150.56
124
        compare(
125
            {
126
                got      => $order_0_0->{unitpricegsti},
127
                expected => 77.49,
128
                conf     => '0 0',
129
                field    => 'unitpricegsti'
130
            }
131
        );
132
        compare(
133
            {
134
                got      => $order_0_0->{unitpricegste},
135
                expected => 73.80,
136
                conf     => '0 0',
137
                field    => 'unitpricegste'
138
            }
139
        );
140
        compare(
141
            {
142
                got      => $order_0_0->{gstvalue},
143
                expected => 7.38,
144
                conf     => '0 0',
145
                field    => 'gstvalue'
146
            }
147
        );
148
        compare(
149
            {
150
                got      => $order_0_0->{totalgsti},
151
                expected => 154.98,
152
                conf     => '0 0',
153
                field    => 'totalgsti'
154
            }
155
        );
156
        compare(
157
            {
158
                got      => $order_0_0->{totalgste},
159
                expected => 147.60,
160
                conf     => '0 0',
161
                field    => 'totalgste'
162
            }
163
        );
113
    };
164
    };
114
165
115
    subtest 'Configuration 1: 1 1' => sub {
166
    subtest 'Configuration 1: 1 1' => sub {
116
        plan tests => 7;
167
        plan tests => 12;
117
        $bookseller_module->mock(
168
        $bookseller_module->mock(
118
            'fetch',
169
            'fetch',
119
            sub {
170
            sub {
Lines 203-212 for my $currency_format ( qw( US FR ) ) { Link Here
203
                field    => 'totalgste'
254
                field    => 'totalgste'
204
            }
255
            }
205
        );
256
        );
257
258
        $order_1_1 = C4::Acquisition::populate_order_with_prices(
259
            {
260
                order        => $order_1_1,
261
                booksellerid => 'just_something',
262
                receiving    => 1,
263
            }
264
        );
265
        # Note that this configuration is *not* correct!
266
        # gstvalue should be 7.03
267
        compare(
268
            {
269
                got      => $order_1_1->{unitpricegsti},
270
                expected => 73.80,
271
                conf     => '1 1',
272
                field    => 'unitpricegsti'
273
            }
274
        );
275
        compare(
276
            {
277
                got      => $order_1_1->{unitpricegste},
278
                expected => 70.29,
279
                conf     => '1 1',
280
                field    => 'unitpricegste'
281
            }
282
        );
283
        compare(
284
            {
285
                got      => $order_1_1->{gstvalue},
286
                expected => 7.02,
287
                conf     => '1 1',
288
                field    => 'gstvalue'
289
            }
290
        );
291
        compare(
292
            {
293
                got      => $order_1_1->{totalgsti},
294
                expected => 147.60,
295
                conf     => '1 1',
296
                field    => 'totalgsti'
297
            }
298
        );
299
        compare(
300
            {
301
                got      => $order_1_1->{totalgste},
302
                expected => 140.58,
303
                conf     => '1 1',
304
                field    => 'totalgste'
305
            }
306
        );
206
    };
307
    };
207
308
208
    subtest 'Configuration 1: 1 0' => sub {
309
    subtest 'Configuration 1: 1 0' => sub {
209
        plan tests => 7;
310
        plan tests => 12;
210
        $bookseller_module->mock(
311
        $bookseller_module->mock(
211
            'fetch',
312
            'fetch',
212
            sub {
313
            sub {
Lines 298-307 for my $currency_format ( qw( US FR ) ) { Link Here
298
                field    => 'totalgste'
399
                field    => 'totalgste'
299
            }
400
            }
300
        );
401
        );
402
403
        $order_1_0 = C4::Acquisition::populate_order_with_prices(
404
            {
405
                order        => $order_1_0,
406
                booksellerid => 'just_something',
407
                receiving    => 1,
408
            }
409
        );
410
        # Note that this configuration is *not* correct!
411
        # unitpricegsti should be 71.69
412
        # totalgsti should be 143.38
413
        # gstvalue should be 7.03
414
        compare(
415
            {
416
                got      => $order_1_0->{unitpricegsti},
417
                expected => 73.80,
418
                conf     => '1 0',
419
                field    => 'unitpricegsti'
420
            }
421
        );
422
        compare(
423
            {
424
                got      => $order_1_0->{unitpricegste},
425
                expected => 70.29,
426
                conf     => '1 0',
427
                field    => 'unitpricegste'
428
            }
429
        );
430
        compare(
431
            {
432
                got      => $order_1_0->{gstvalue},
433
                expected => 7.02,
434
                conf     => '1 0',
435
                field    => 'gstvalue'
436
            }
437
        );
438
        compare(
439
            {
440
                got      => $order_1_0->{totalgsti},
441
                expected => 147.60,
442
                conf     => '1 0',
443
                field    => 'totalgsti'
444
            }
445
        );
446
        compare(
447
            {
448
                got      => $order_1_0->{totalgste},
449
                expected => 140.58,
450
                conf     => '1 0',
451
                field    => 'totalgste'
452
            }
453
        );
301
    };
454
    };
302
455
303
    subtest 'Configuration 1: 0 1' => sub {
456
    subtest 'Configuration 1: 0 1' => sub {
304
        plan tests => 7;
457
        plan tests => 12;
305
        $bookseller_module->mock(
458
        $bookseller_module->mock(
306
            'fetch',
459
            'fetch',
307
            sub {
460
            sub {
Lines 390-395 for my $currency_format ( qw( US FR ) ) { Link Here
390
                field    => 'totalgste'
543
                field    => 'totalgste'
391
            }
544
            }
392
        );
545
        );
546
547
        $order_0_1 = C4::Acquisition::populate_order_with_prices(
548
            {
549
                order        => $order_0_1,
550
                booksellerid => 'just_something',
551
                receiving    => 1,
552
            }
553
        );
554
        # Note that this configuration is correct
555
        compare(
556
            {
557
                got      => $order_0_1->{unitpricegsti},
558
                expected => 77.49,
559
                conf     => '0 1',
560
                field    => 'unitpricegsti'
561
            }
562
        );
563
        compare(
564
            {
565
                got      => $order_0_1->{unitpricegste},
566
                expected => 73.80,
567
                conf     => '0 1',
568
                field    => 'unitpricegste'
569
            }
570
        );
571
        compare(
572
            {
573
                got      => $order_0_1->{gstvalue},
574
                expected => 7.38,
575
                conf     => '0 1',
576
                field    => 'gstvalue'
577
            }
578
        );
579
        compare(
580
            {
581
                got      => $order_0_1->{totalgsti},
582
                expected => 154.98,
583
                conf     => '0 1',
584
                field    => 'totalgsti'
585
            }
586
        );
587
        compare(
588
            {
589
                got      => $order_0_1->{totalgste},
590
                expected => 147.60,
591
                conf     => '0 1',
592
                field    => 'totalgste'
593
            }
594
        );
393
    };
595
    };
394
}
596
}
395
597
396
- 

Return to bug 12976