}
}
- # Not used yet
- #if ($receiving) {
- # if ( $bookseller->{invoiceincgst} ) {
- # $order->{unitpricegsti} = $order->{unitprice};
- # $order->{unitpricegste} =
- # $order->{unitpricegsti} / ( 1 + $order->{gstrate} );
- # }
- # else {
- # $order->{unitpricegste} = $order->{unitprice};
- # $order->{unitpricegsti} =
- # $order->{unitpricegste} * ( 1 + $order->{gstrate} );
- # }
- # $order->{gstvalue} =
- # $order->{quantityreceived} *
- # $order->{unitpricegste} *
- # $order->{gstrate};
- #}
+ if ($receiving) {
+ # The following is completely wrong. Will be fixed later.
+ # See the unit tests to know what is wrong.
+ if ( $bookseller->{listincgst} ) {
+ $order->{unitpricegsti} = Koha::Number::Price->new( $order->{unitprice} )->round;
+ $order->{unitpricegste} = Koha::Number::Price->new(
+ $order->{unitpricegsti} / ( 1 + $order->{gstrate} ) )->round;
+ }
+ else {
+ $order->{unitpricegste} = Koha::Number::Price->new( $order->{unitprice} )->round;
+ $order->{unitpricegsti} = Koha::Number::Price->new(
+ $order->{unitpricegste} * ( 1 + $order->{gstrate} ) )->round;
+ }
+ $order->{gstvalue} = Koha::Number::Price->new(
+ ( $order->{unitpricegsti} - $order->{unitpricegste} )
+ * $order->{quantityreceived} )->round;
+
+ $order->{totalgste} = $order->{unitpricegste} * $order->{quantity};
+ $order->{totalgsti} = $order->{unitpricegsti} * $order->{quantity};
+ }
return $order;
}
my $total_gsti = 0;
my $total_gstvalue = 0;
foreach my $order (@$orders) {
+ $order = C4::Acquisition::populate_order_with_prices(
+ {
+ order => $order,
+ booksellerid => $bookseller->{id},
+ receiving => 1,
+ }
+ );
my $line = get_infos( $order, $bookseller);
- $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti};
+ $foot{$$line{gstgsti}}{gstrate} = $$line{gstrate};
$foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
$total_gstvalue += $$line{gstvalue};
$foot{$$line{gstgsti}}{quantity} += $$line{quantity};
my %line = %{ $order };
$line{order_received} = ( $qty == $order->{'quantityreceived'} );
$line{budget_name} = $budget->{budget_name};
- if ( $bookseller->{'listincgst'} ) {
- $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
- $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} );
- $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) );
- $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
- $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
- $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
- } else {
- $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) );
- $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} );
- $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
- $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
- $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
- }
if ( $line{uncertainprice} ) {
$template->param( uncertainprices => 1 );
[% USE Koha %]
[% USE KohaDates %]
+[% USE Price %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha › Acquisitions › Invoice</title>
[% END %]
</td>
<td><p>[% order.branchcode %]</p></td>
- <td class="number gste">[% order.actualcostgste %]</td>
- <td class="number gsti">[% order.actualcostgsti %]</td>
+ <td class="number gste">[% order.unitpricegste | $Price %]</td>
+ <td class="number gsti">[% order.unitpricegsti | $Price %]</td>
<td class="number">[% order.quantity %]</td>
- <td class="number gste">[% order.totalgste %]</td>
- <td class="number gsti">[% order.totalgsti %]</td>
- <td class="number">[% order.gstgsti %]</td>
- <td class="number">[% order.gstvalue %]</td>
+ <td class="number gste">[% order.totalgste | $Price %]</td>
+ <td class="number gsti">[% order.totalgsti | $Price %]</td>
+ <td class="number">[% order.gstrate * 100 | $Price %]</td>
+ <td class="number">[% order.gstvalue | $Price %]</td>
<td>[% order.budget_name %]</td>
</tr>
[% END %]
<tfoot>
[% FOR tf IN foot_loop %]
<tr>
- <th colspan='2'>Total (GST [% tf.gstgsti %] %)</th>
+ <th colspan='2'>Total (GST [% tf.gstrate * 100 | $Price %] %)</th>
<th class="gste"/><th class="gsti"/>
<th>[% tf.quantity %]</th>
- <th class="gste">[% tf.totalgste %]</th>
- <th class="gsti">[% tf.totalgsti %]</th>
+ <th class="gste">[% tf.totalgste | $Price %]</th>
+ <th class="gsti">[% tf.totalgsti | $Price %]</th>
<th> </th>
- <th>[% tf.gstvalue %]</th>
+ <th>[% tf.gstvalue | $Price %]</th>
<th> </th>
</tr>
[% END %]
<th colspan='2'>Total ([% currency %])</th>
<th class="gste"/><th class="gsti"/>
<th>[% total_quantity %]</th>
- <th class="gste">[% total_gste %]</th>
- <th class="gsti">[% total_gsti %]</th>
+ <th class="gste">[% total_gste | $Price %]</th>
+ <th class="gsti">[% total_gsti | $Price %]</th>
<th> </th>
- <th>[% total_gstvalue %]</th>
+ <th>[% total_gstvalue | $Price %]</th>
<th> </th>
</tr>
<tr>
<th class="gste"></th>
<th class="gsti"></th>
<th>[% total_quantity %]</th>
- <th class="gste">[% total_gste_shipment %]</th>
- <th class="gsti">[% total_gsti_shipment %]</th>
+ <th class="gste">[% total_gste_shipment | $Price %]</th>
+ <th class="gsti">[% total_gsti_shipment | $Price %]</th>
<th> </th>
- <th>[% total_gstvalue %]</th>
+ <th>[% total_gstvalue | $Price %]</th>
<th> </th>
</tr>
</tfoot>
for my $currency_format ( qw( US FR ) ) {
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
subtest 'Configuration 1: 0 0' => sub {
- plan tests => 7;
+ plan tests => 12;
$bookseller_module->mock(
'fetch',
sub {
field => 'totalgste'
}
);
+
+ $order_0_0 = C4::Acquisition::populate_order_with_prices(
+ {
+ order => $order_0_0,
+ booksellerid => 'just_something',
+ receiving => 1,
+ }
+ );
+ # Note that this configuration is *not* correct!
+ # unitpricegsti should be 75.28
+ # totalgst should be 150.56
+ compare(
+ {
+ got => $order_0_0->{unitpricegsti},
+ expected => 77.49,
+ conf => '0 0',
+ field => 'unitpricegsti'
+ }
+ );
+ compare(
+ {
+ got => $order_0_0->{unitpricegste},
+ expected => 73.80,
+ conf => '0 0',
+ field => 'unitpricegste'
+ }
+ );
+ compare(
+ {
+ got => $order_0_0->{gstvalue},
+ expected => 7.38,
+ conf => '0 0',
+ field => 'gstvalue'
+ }
+ );
+ compare(
+ {
+ got => $order_0_0->{totalgsti},
+ expected => 154.98,
+ conf => '0 0',
+ field => 'totalgsti'
+ }
+ );
+ compare(
+ {
+ got => $order_0_0->{totalgste},
+ expected => 147.60,
+ conf => '0 0',
+ field => 'totalgste'
+ }
+ );
};
subtest 'Configuration 1: 1 1' => sub {
- plan tests => 7;
+ plan tests => 12;
$bookseller_module->mock(
'fetch',
sub {
field => 'totalgste'
}
);
+
+ $order_1_1 = C4::Acquisition::populate_order_with_prices(
+ {
+ order => $order_1_1,
+ booksellerid => 'just_something',
+ receiving => 1,
+ }
+ );
+ # Note that this configuration is *not* correct!
+ # gstvalue should be 7.03
+ compare(
+ {
+ got => $order_1_1->{unitpricegsti},
+ expected => 73.80,
+ conf => '1 1',
+ field => 'unitpricegsti'
+ }
+ );
+ compare(
+ {
+ got => $order_1_1->{unitpricegste},
+ expected => 70.29,
+ conf => '1 1',
+ field => 'unitpricegste'
+ }
+ );
+ compare(
+ {
+ got => $order_1_1->{gstvalue},
+ expected => 7.02,
+ conf => '1 1',
+ field => 'gstvalue'
+ }
+ );
+ compare(
+ {
+ got => $order_1_1->{totalgsti},
+ expected => 147.60,
+ conf => '1 1',
+ field => 'totalgsti'
+ }
+ );
+ compare(
+ {
+ got => $order_1_1->{totalgste},
+ expected => 140.58,
+ conf => '1 1',
+ field => 'totalgste'
+ }
+ );
};
subtest 'Configuration 1: 1 0' => sub {
- plan tests => 7;
+ plan tests => 12;
$bookseller_module->mock(
'fetch',
sub {
field => 'totalgste'
}
);
+
+ $order_1_0 = C4::Acquisition::populate_order_with_prices(
+ {
+ order => $order_1_0,
+ booksellerid => 'just_something',
+ receiving => 1,
+ }
+ );
+ # Note that this configuration is *not* correct!
+ # unitpricegsti should be 71.69
+ # totalgsti should be 143.38
+ # gstvalue should be 7.03
+ compare(
+ {
+ got => $order_1_0->{unitpricegsti},
+ expected => 73.80,
+ conf => '1 0',
+ field => 'unitpricegsti'
+ }
+ );
+ compare(
+ {
+ got => $order_1_0->{unitpricegste},
+ expected => 70.29,
+ conf => '1 0',
+ field => 'unitpricegste'
+ }
+ );
+ compare(
+ {
+ got => $order_1_0->{gstvalue},
+ expected => 7.02,
+ conf => '1 0',
+ field => 'gstvalue'
+ }
+ );
+ compare(
+ {
+ got => $order_1_0->{totalgsti},
+ expected => 147.60,
+ conf => '1 0',
+ field => 'totalgsti'
+ }
+ );
+ compare(
+ {
+ got => $order_1_0->{totalgste},
+ expected => 140.58,
+ conf => '1 0',
+ field => 'totalgste'
+ }
+ );
};
subtest 'Configuration 1: 0 1' => sub {
- plan tests => 7;
+ plan tests => 12;
$bookseller_module->mock(
'fetch',
sub {
field => 'totalgste'
}
);
+
+ $order_0_1 = C4::Acquisition::populate_order_with_prices(
+ {
+ order => $order_0_1,
+ booksellerid => 'just_something',
+ receiving => 1,
+ }
+ );
+ # Note that this configuration is correct
+ compare(
+ {
+ got => $order_0_1->{unitpricegsti},
+ expected => 77.49,
+ conf => '0 1',
+ field => 'unitpricegsti'
+ }
+ );
+ compare(
+ {
+ got => $order_0_1->{unitpricegste},
+ expected => 73.80,
+ conf => '0 1',
+ field => 'unitpricegste'
+ }
+ );
+ compare(
+ {
+ got => $order_0_1->{gstvalue},
+ expected => 7.38,
+ conf => '0 1',
+ field => 'gstvalue'
+ }
+ );
+ compare(
+ {
+ got => $order_0_1->{totalgsti},
+ expected => 154.98,
+ conf => '0 1',
+ field => 'totalgsti'
+ }
+ );
+ compare(
+ {
+ got => $order_0_1->{totalgste},
+ expected => 147.60,
+ conf => '0 1',
+ field => 'totalgste'
+ }
+ );
};
}