AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
, aqorders.quantity
, 0)
- ) AS expected_items
+ ) AS expected_items,
+ SUM( aqorders.uncertainprice ) AS uncertainprices
FROM aqbasket
LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno
WHERE booksellerid = ?};
);
if ( not $order->{subscriptionid} && defined $order->{order_internalnote} ) {
- $dbh->do(q|UPDATE aqorders
- SET order_internalnote = ?|, {}, $order->{order_internalnote});
+ $dbh->do(
+ q|UPDATE aqorders
+ SET order_internalnote = ?
+ WHERE ordernumber = ?|, {},
+ $order->{order_internalnote}, $order->{ordernumber}
+ );
}
# Recalculate tax_value
sub DelOrder {
my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_;
-
my $error;
my $dbh = C4::Context->dbh;
my $query = "
return $sth->fetchrow;
}
-# Note this subroutine should be moved to Koha::Acquisition::Order
-# Will do when a DBIC decision will be taken.
+=head3 populate_order_with_prices
+
+$order = populate_order_with_prices({
+ order => $order #a hashref with the order values
+ booksellerid => $booksellerid #FIXME - should obtain from order basket
+ receiving => 1 # boolean representing order stage, should pass only this or ordering
+ ordering => 1 # boolean representing order stage
+});
+
+
+Sets calculated values for an order - all values are stored with pull precision regardless of rounding preference except fot
+tax value which is calculated on rounded values if requested
+
+For ordering the values set are:
+ rrp_tax_included
+ rrp_tax_excluded
+ ecost_tax_included
+ ecost_tax_excluded
+ tax_value_on_ordering
+For receiving the value set are:
+ unitprice_tax_included
+ unitprice_tax_excluded
+ tax_value_on_receiving
+
+Note: When receiving if the rounded value of the unitprice matches the rounded value of the ecost then then ecost (full precision) is used.
+
+Returns a hashref of the order
+
+FIXME: Move this to Koha::Acquisition::Order.pm
+
+=cut
+
sub populate_order_with_prices {
my ($params) = @_;
# rrp tax excluded = rrp tax included / ( 1 + tax rate )
$order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} );
+ # ecost tax included = rrp tax included ( 1 - discount )
+ $order->{ecost_tax_included} = $order->{rrp_tax_included} * ( 1 - $discount );
+
# ecost tax excluded = rrp tax excluded * ( 1 - discount )
$order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount );
- # ecost tax included = rrp tax included ( 1 - discount )
- $order->{ecost_tax_included} = $order->{rrp_tax_included} * ( 1 - $discount );
+ # tax value = quantity * ecost tax excluded * tax rate
+ $order->{tax_value_on_ordering} = ( get_rounded_price($order->{ecost_tax_included}) - get_rounded_price($order->{ecost_tax_excluded}) ) * $order->{quantity};
+
}
else {
# The user entered the rrp tax excluded
# 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_on_ordering} ) *
- ( 1 - $discount );
- }
+ # ecost tax included = rrp tax excluded * ( 1 + tax rate ) * ( 1 - discount ) = ecost tax excluded * ( 1 + tax rate )
+ $order->{ecost_tax_included} = $order->{ecost_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} );
- # tax value = quantity * ecost tax excluded * tax rate
- $order->{tax_value_on_ordering} =
- $order->{quantity} * get_rounded_price($order->{ecost_tax_excluded}) * $order->{tax_rate_on_ordering};
+ # tax value = quantity * ecost tax included * tax rate
+ $order->{tax_value_on_ordering} = $order->{quantity} * get_rounded_price($order->{ecost_tax_excluded}) * $order->{tax_rate_on_ordering};
+ }
}
if ($receiving) {