This commit permits to update the tax rate on receiving.
Signed-off-by: Laurence Rault <laurence.rault@biblibre.com>
Signed-off-by: Francois Charbonnier <francois.charbonnier@inlibro.com>
Signed-off-by: Sonia Bouis <sonia.bouis@univ-lyon3.fr>
Signed-off-by: Sonia Bouis <koha@univ-lyon3.fr>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
| if defined $order->{unitprice};
$query .= q|
- , rrp = ?, rrp_tax_included = ?, rrp_tax_excluded = ?
- | if defined $order->{rrp};
+ ,tax_value_on_receiving = ?
+ | if defined $order->{tax_value_on_receiving};
$query .= q|
- , ecost = ?, ecost_tax_included = ?, ecost_tax_excluded = ?
- | if defined $order->{ecost};
+ ,tax_rate_on_receiving = ?
+ | if defined $order->{tax_rate_on_receiving};
$query .= q|
, order_internalnote = ?
if ( defined $order->{unitprice} ) {
push @params, $order->{unitprice}, $order->{unitprice_tax_included}, $order->{unitprice_tax_excluded};
}
- if ( defined $order->{rrp} ) {
- push @params, $order->{rrp}, $order->{rrp_tax_included}, $order->{rrp_tax_excluded};
+
+ if ( defined $order->{tax_value_on_receiving} ) {
+ push @params, $order->{tax_value_on_receiving};
}
- if ( defined $order->{ecost} ) {
- push @params, $order->{ecost}, $order->{ecost_tax_included}, $order->{ecost_tax_excluded};
+
+ if ( defined $order->{tax_rate_on_receiving} ) {
+ push @params, $order->{tax_rate_on_receiving};
}
+
if ( defined $order->{order_internalnote} ) {
push @params, $order->{order_internalnote};
}
$discount /= 100 if $discount > 1;
if ($ordering) {
+ $order->{tax_rate_on_ordering} //= $order->{tax_rate};
if ( $bookseller->{listincgst} ) {
# The user entered the rrp tax included
$order->{rrp_tax_included} = $order->{rrp};
# rrp tax excluded = rrp tax included / ( 1 + tax rate )
- $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} );
+ $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
# ecost tax excluded = rrp tax excluded * ( 1 - discount )
$order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
$order->{rrp_tax_excluded} = $order->{rrp};
# rrp tax included = rrp tax excluded * ( 1 - tax rate )
- $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate} );
+ $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
# ecost tax excluded = rrp tax excluded * ( 1 - discount )
$order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
# ecost tax included = rrp tax excluded * ( 1 - tax rate ) * ( 1 - discount )
$order->{ecost_tax_included} =
$order->{rrp_tax_excluded} *
- ( 1 + $order->{tax_rate} ) *
+ ( 1 + $order->{tax_rate_on_ordering} ) *
( 1 - $discount );
}
# tax value = quantity * ecost tax excluded * tax rate
- $order->{tax_value} = $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate};
+ $order->{tax_value_on_ordering} =
+ $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate_on_ordering};
}
if ($receiving) {
+ $order->{tax_rate_on_receiving} //= $order->{tax_rate};
if ( $bookseller->{invoiceincgst} ) {
# Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
# we need to keep the exact ecost value
$order->{unitprice_tax_included} = $order->{unitprice};
# unit price tax excluded = unit price tax included / ( 1 + tax rate )
- $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} );
+ $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_receiving} );
}
else {
# Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value
# The user entered the unit price tax excluded
$order->{unitprice_tax_excluded} = $order->{unitprice};
+
# unit price tax included = unit price tax included * ( 1 + tax rate )
- $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} );
+ $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_receiving} );
}
# tax value = quantity * unit price tax excluded * tax rate
- $order->{tax_value} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate};
+ $order->{tax_value_on_receiving} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate_on_receiving};
}
return $order;
$template->param( uncertainprices => 1 );
}
+ $line->{tax_rate} = $line->{tax_rate_on_ordering};
+ $line->{tax_value} = $line->{tax_value_on_ordering};
+
push @books_loop, $line;
$foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate};
$line{total_tax_included} = $line{ecost_tax_included} * $line{quantity};
$line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity};
+ $line{tax_value} = $line{tax_value_on_ordering};
+ $line{tax_rate} = $line{tax_rate_on_ordering};
if ( $line{uncertainprice} ) {
$line{rrp_tax_excluded} .= ' (Uncertain)';
croak $@;
}
+ $ord->{tax_value} = $ord->{tax_value_on_ordering};
+ $ord->{tax_rate} = $ord->{tax_rate_on_ordering};
$ord->{total_tax_included} = $ord->{ecost_tax_included} * $ord->{quantity};
$ord->{total_tax_excluded} = $ord->{ecost_tax_excluded} * $ord->{quantity};
my $origquantityrec = $input->param('origquantityrec');
my $quantityrec = $input->param('quantityrec');
my $quantity = $input->param('quantity');
-my $unitprice = $input->param('cost');
+my $unitprice = $input->param('unitprice');
my $datereceived = $input->param('datereceived'),
my $invoiceid = $input->param('invoiceid');
my $invoice = GetInvoice($invoiceid);
}
$order->{order_internalnote} = $input->param("order_internalnote");
+ $order->{tax_rate_on_receiving} = $input->param("tax_rate");
$order->{unitprice} = $unitprice;
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
$line->{total_tax_excluded} = Koha::Number::Price->new( $line->{unitprice_tax_excluded} * $line->{quantity} )->format;
$line->{total_tax_included} = Koha::Number::Price->new( $line->{unitprice_tax_included} * $line->{quantity} )->format;
+ $line->{tax_value} = $line->{tax_value_on_receiving};
+ $line->{tax_rate} = $line->{tax_rate_on_receiving};
+
$foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate};
$foot{$$line{tax_rate}}{tax_value} += $$line{tax_value};
$total_tax_value += $$line{tax_value};
$budget_id = $lastOrderReceived->{budgetid};
$data->{listprice} = $lastOrderReceived->{listprice};
$data->{uncertainprice} = $lastOrderReceived->{uncertainprice};
- $data->{tax_rate} = $lastOrderReceived->{tax_rate};
+ $data->{tax_rate} = $lastOrderReceived->{tax_rate_on_ordering};
$data->{discount} = $lastOrderReceived->{discount};
$data->{rrp} = $lastOrderReceived->{rrp};
$data->{ecost} = $lastOrderReceived->{ecost};
quantityrec => $quantity,
rrp => $data->{'rrp'},
gst_values => \@gst_values,
- tax_rate => $data->{tax_rate} ? $data->{tax_rate}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0,
+ tax_rate => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0,
listprice => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice),
total => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ),
ecost => sprintf( "%.2f", $data->{ecost} || 0),
}
$order->{quantityreceived} = '' if $order->{quantityreceived} == 0;
-$order->{unitprice} = '' if $order->{unitprice} == 0;
-
-my $rrp;
-my $ecost;
-my $unitprice;
-if ( $bookseller->{listincgst} ) {
- if ( $bookseller->{invoiceincgst} ) {
- $rrp = $order->{rrp};
- $ecost = $order->{ecost};
- $unitprice = $order->{unitprice};
- } else {
- $rrp = $order->{rrp} / ( 1 + $order->{tax_rate} );
- $ecost = $order->{ecost} / ( 1 + $order->{tax_rate} );
- $unitprice = $order->{unitprice} / ( 1 + $order->{tax_rate} );
+
+my $unitprice = $order->{unitprice};
+my ( $rrp, $ecost );
+if ( $bookseller->{invoiceincgst} ) {
+ $rrp = $order->{rrp_tax_included};
+ $ecost = $order->{ecost_tax_included};
+ unless ( $unitprice != 0 and defined $unitprice) {
+ $unitprice = $order->{ecost_tax_included};
}
} else {
- if ( $bookseller->{invoiceincgst} ) {
- $rrp = $order->{rrp} * ( 1 + $order->{tax_rate} );
- $ecost = $order->{ecost} * ( 1 + $order->{tax_rate} );
- $unitprice = $order->{unitprice} * ( 1 + $order->{tax_rate} );
- } else {
- $rrp = $order->{rrp};
- $ecost = $order->{ecost};
- $unitprice = $order->{unitprice};
+ $rrp = $order->{rrp_tax_excluded};
+ $ecost = $order->{ecost_tax_excluded};
+ unless ( $unitprice != 0 and defined $unitprice) {
+ $unitprice = $order->{ecost_tax_excluded};
}
- }
+}
+
+my $tax_rate;
+if( defined $order->{tax_rate_on_receiving} ) {
+ $tax_rate = $order->{tax_rate_on_receiving} + 0.0;
+} else {
+ $tax_rate = $order->{tax_rate_on_ordering} + 0.0;
+}
my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
my $datereceived = $order->{datereceived} ? dt_from_string( $order->{datereceived} ) : dt_from_string;
+# get option values for gist syspref
+my @gst_values = map {
+ option => $_ + 0.0
+}, split( '\|', C4::Context->preference("gist") );
+
$template->param(
AcqCreateItem => $AcqCreateItem,
count => 1,
quantity => $order->{'quantity'},
quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
quantityreceived => $order->{'quantityreceived'},
- rrp => sprintf( "%.2f", $rrp ),
- ecost => sprintf( "%.2f", $ecost ),
+ rrp => $rrp,
+ ecost => $ecost,
+ unitprice => $unitprice,
+ tax_rate => $tax_rate,
memberfirstname => $member->{firstname} || "",
membersurname => $member->{surname} || "",
invoiceid => $invoice->{invoiceid},
suggestionid => $suggestion->{suggestionid},
surnamesuggestedby => $suggestion->{surnamesuggestedby},
firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
+ gst_values => \@gst_values,
);
my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
$template->{'VARS'}->{'budget_loop'} = \@budget_loop;
-# regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
-# and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
-# So if $unitprice == 0 we don't create unitprice
-if ( $unitprice != 0) {
- $template->param(
- unitprice => sprintf( "%.2f", $unitprice),
- );
-}
-
my $op = $input->param('op');
if ($op and $op eq 'edit'){
$template->param(edit => 1);
my $booksellerid = $invoice->{booksellerid};
my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
-my $gst = $bookseller->{tax_rate} // C4::Context->preference("gist") // 0;
my @orders = @{ $invoice->{orders} };
my $countlines = scalar @orders;
$line{holds} += scalar( @$holds );
}
$line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
+
+ $line{tax_value} = $line{tax_value_on_receiving};
+ $line{tax_rate} = $line{tax_rate_on_receiving};
$foot{$line{tax_rate}}{tax_rate} = $line{tax_rate};
$foot{$line{tax_rate}}{tax_value} += $line{tax_value};
$total_tax_excluded += $line{unitprice_tax_excluded} * $line{quantity};
<input type="hidden" name="invoiceid" value="[% invoiceid %]" />
<input type="hidden" name="ordernumber" value="[% ordernumber %]" />
<input type="hidden" name="booksellerid" value="[% booksellerid %]" />
- <input type="hidden" name="tax_rate" value="[% tax_rate %]" />
</div>
<div class="yui-u">
<fieldset class="rows">
[% END %][%# IF (AcqCreateItemReceiving) %]
</li>
+ [% IF ( gst_values ) %]
+ <li>
+ <label for="tax_rate">Tax rate: </label>
+ <select name="tax_rate" id="tax_rate">
+ [% FOREACH gst IN gst_values %]
+ [% IF gst.option == tax_rate %]
+ <option value="[% gst.option %]" selected="selected">[% gst.option * 100 | format("%.1f") %]%</option>
+ [% ELSE %]
+ <option value="[% gst.option %]">[% gst.option * 100 | format("%.1f") %]%</option>
+ [% END %]
+ [% END %]
+ </select>
+ </li>
+ [% ELSE %]
+ <input type="hidden" name="tax_rate" value="0" />
+ [% END %]
+
<li><label for="rrp">Replacement cost: </label>[% rrp | $Price %]</li>
<li><label for="ecost">Budgeted cost: </label>[% ecost | $Price %]</li>
- <li><label for="cost">Actual cost:</label>
- [% IF ( unitprice ) %]
- <input type="text" size="20" name="cost" id="cost" value="[% unitprice | $Price %]" />
- [% ELSE %]
- <input type="text" size="20" name="cost" id="cost" value="[% ecost | $Price %]" />
- [% END %]</li>
+ <li>
+ <label for="unitprice">Actual cost:</label>
+ <input type="text" size="20" name="unitprice" id="unitprice" value="[% unitprice | $Price %]" />
+ </li>
<li><label for="order_internalnote">Internal note: </label><textarea name="order_internalnote" width="40" rows="8" >[% order_internalnote %]</textarea></li>
[% IF order_vendornote %]
<li><label for="order_vendornote">Vendor note: </label><span>[% order_vendornote %]</span></li>
);
compare(
{
- got => $order_0_0->{tax_value},
+ got => $order_0_0->{tax_value_on_ordering},
expected => 7.38,
conf => '0 0',
field => 'tax_value'
}
);
+ #
$order_0_0 = C4::Acquisition::populate_order_with_prices(
{
order => $order_0_0,
);
compare(
{
- got => $order_0_0->{tax_value},
+ got => $order_0_0->{tax_value_on_receiving},
expected => 7.38,
conf => '0 0',
field => 'tax_value'
);
compare(
{
- got => $order_1_1->{tax_value},
+ got => $order_1_1->{tax_value_on_ordering},
expected => 7.03,
conf => '1 1',
field => 'tax_value'
);
compare(
{
- got => $order_1_1->{tax_value},
+ got => $order_1_1->{tax_value_on_receiving},
expected => 7.03,
conf => '1 1',
field => 'tax_value'
);
compare(
{
- got => $order_1_0->{tax_value},
+ got => $order_1_0->{tax_value_on_ordering},
expected => 7.03,
conf => '1 0',
field => 'tax_value'
);
compare(
{
- got => $order_1_0->{tax_value},
+ got => $order_1_0->{tax_value_on_receiving},
expected => 7.03,
conf => '1 0',
field => 'tax_value'
);
compare(
{
- got => $order_0_1->{tax_value},
+ got => $order_0_1->{tax_value_on_ordering},
expected => 7.38,
conf => '0 1',
field => 'tax_value'
);
compare(
{
- got => $order_0_1->{tax_value},
+ got => $order_0_1->{tax_value_on_receiving},
expected => 7.38,
conf => '0 1',
field => 'tax_value'