|
Lines 1324-1381
sub ModItemOrder {
Link Here
|
| 1324 |
|
1324 |
|
| 1325 |
=head3 ModReceiveOrder |
1325 |
=head3 ModReceiveOrder |
| 1326 |
|
1326 |
|
| 1327 |
&ModReceiveOrder({ |
1327 |
my ( $date_received, $new_ordernumber ) = ModReceiveOrder( |
| 1328 |
biblionumber => $biblionumber, |
1328 |
{ |
| 1329 |
ordernumber => $ordernumber, |
1329 |
biblionumber => $biblionumber, |
| 1330 |
quantityreceived => $quantityreceived, |
1330 |
order => $order, |
| 1331 |
user => $user, |
1331 |
quantityreceived => $quantityreceived, |
| 1332 |
cost => $cost, |
1332 |
user => $user, |
| 1333 |
ecost => $ecost, |
1333 |
invoice => $invoice, |
| 1334 |
invoiceid => $invoiceid, |
1334 |
budget_id => $budget_id, |
| 1335 |
rrp => $rrp, |
1335 |
received_itemnumbers => \@received_itemnumbers, |
| 1336 |
budget_id => $budget_id, |
1336 |
order_internalnote => $order_internalnote, |
| 1337 |
datereceived => $datereceived, |
1337 |
} |
| 1338 |
received_itemnumbers => \@received_itemnumbers, |
1338 |
); |
| 1339 |
order_internalnote => $order_internalnote, |
|
|
| 1340 |
order_vendornote => $order_vendornote, |
| 1341 |
}); |
| 1342 |
|
1339 |
|
| 1343 |
Updates an order, to reflect the fact that it was received, at least |
1340 |
Updates an order, to reflect the fact that it was received, at least |
| 1344 |
in part. All arguments not mentioned below update the fields with the |
1341 |
in part. |
| 1345 |
same name in the aqorders table of the Koha database. |
|
|
| 1346 |
|
1342 |
|
| 1347 |
If a partial order is received, splits the order into two. |
1343 |
If a partial order is received, splits the order into two. |
| 1348 |
|
1344 |
|
| 1349 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
1345 |
Updates the order with biblionumber C<$biblionumber> and ordernumber |
| 1350 |
C<$ordernumber>. |
1346 |
C<$order->{ordernumber}>. |
| 1351 |
|
1347 |
|
| 1352 |
=cut |
1348 |
=cut |
| 1353 |
|
1349 |
|
| 1354 |
|
1350 |
|
| 1355 |
sub ModReceiveOrder { |
1351 |
sub ModReceiveOrder { |
| 1356 |
my ( $params ) = @_; |
1352 |
my ($params) = @_; |
| 1357 |
my $biblionumber = $params->{biblionumber}; |
1353 |
my $biblionumber = $params->{biblionumber}; |
| 1358 |
my $ordernumber = $params->{ordernumber}; |
1354 |
my $order = { %{ $params->{order} } }; # Copy the order, we don't want to modify it |
| 1359 |
my $quantrec = $params->{quantityreceived}; |
1355 |
my $invoice = $params->{invoice}; |
| 1360 |
my $user = $params->{user}; |
1356 |
my $quantrec = $params->{quantityreceived}; |
| 1361 |
my $cost = $params->{cost}; |
1357 |
my $user = $params->{user}; |
| 1362 |
my $ecost = $params->{ecost}; |
1358 |
my $budget_id = $params->{budget_id}; |
| 1363 |
my $invoiceid = $params->{invoiceid}; |
|
|
| 1364 |
my $rrp = $params->{rrp}; |
| 1365 |
my $budget_id = $params->{budget_id}; |
| 1366 |
my $datereceived = $params->{datereceived}; |
| 1367 |
my $received_items = $params->{received_items}; |
1359 |
my $received_items = $params->{received_items}; |
| 1368 |
my $order_internalnote = $params->{order_internalnote}; |
|
|
| 1369 |
my $order_vendornote = $params->{order_vendornote}; |
| 1370 |
|
1360 |
|
| 1371 |
my $dbh = C4::Context->dbh; |
1361 |
my $dbh = C4::Context->dbh; |
| 1372 |
$datereceived = output_pref( |
1362 |
my $datereceived = ( $invoice and $invoice->{datereceived} ) ? $invoice->{datereceived} : dt_from_string; |
| 1373 |
{ |
|
|
| 1374 |
dt => ( $datereceived ? dt_from_string( $datereceived ) : dt_from_string ), |
| 1375 |
dateformat => 'iso', |
| 1376 |
dateonly => 1, |
| 1377 |
} |
| 1378 |
); |
| 1379 |
my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber ); |
1363 |
my $suggestionid = GetSuggestionFromBiblionumber( $biblionumber ); |
| 1380 |
if ($suggestionid) { |
1364 |
if ($suggestionid) { |
| 1381 |
ModSuggestion( {suggestionid=>$suggestionid, |
1365 |
ModSuggestion( {suggestionid=>$suggestionid, |
|
Lines 1384-1398
sub ModReceiveOrder {
Link Here
|
| 1384 |
); |
1368 |
); |
| 1385 |
} |
1369 |
} |
| 1386 |
|
1370 |
|
| 1387 |
my $result_set = $dbh->selectall_arrayref( |
1371 |
my $new_ordernumber = $order->{ordernumber}; |
| 1388 |
q{SELECT * FROM aqorders WHERE biblionumber=? AND aqorders.ordernumber=?}, |
|
|
| 1389 |
{ Slice => {} }, $biblionumber, $ordernumber |
| 1390 |
); |
| 1391 |
|
| 1392 |
# we assume we have a unique order |
| 1393 |
my $order = $result_set->[0]; |
| 1394 |
|
| 1395 |
my $new_ordernumber = $ordernumber; |
| 1396 |
if ( $order->{quantity} > $quantrec ) { |
1372 |
if ( $order->{quantity} > $quantrec ) { |
| 1397 |
# Split order line in two parts: the first is the original order line |
1373 |
# Split order line in two parts: the first is the original order line |
| 1398 |
# without received items (the quantity is decreased), |
1374 |
# without received items (the quantity is decreased), |
|
Lines 1402-1429
q{SELECT * FROM aqorders WHERE biblionumber=? AND aqorders.ordernumber=?},
Link Here
|
| 1402 |
UPDATE aqorders |
1378 |
UPDATE aqorders |
| 1403 |
SET quantity = ?, |
1379 |
SET quantity = ?, |
| 1404 |
orderstatus = 'partial'|; |
1380 |
orderstatus = 'partial'|; |
| 1405 |
$query .= q|, order_internalnote = ?| if defined $order_internalnote; |
1381 |
$query .= q|, order_internalnote = ?| if defined $order->{order_internalnote}; |
| 1406 |
$query .= q|, order_vendornote = ?| if defined $order_vendornote; |
|
|
| 1407 |
$query .= q| WHERE ordernumber = ?|; |
1382 |
$query .= q| WHERE ordernumber = ?|; |
| 1408 |
my $sth = $dbh->prepare($query); |
1383 |
my $sth = $dbh->prepare($query); |
| 1409 |
|
1384 |
|
| 1410 |
$sth->execute( |
1385 |
$sth->execute( |
| 1411 |
$order->{quantity} - $quantrec, |
1386 |
$order->{quantity} - $quantrec, |
| 1412 |
( defined $order_internalnote ? $order_internalnote : () ), |
1387 |
( defined $order->{order_internalnote} ? $order->{order_internalnote} : () ), |
| 1413 |
( defined $order_vendornote ? $order_vendornote : () ), |
1388 |
$order->{ordernumber} |
| 1414 |
$ordernumber |
|
|
| 1415 |
); |
1389 |
); |
| 1416 |
|
1390 |
|
| 1417 |
delete $order->{'ordernumber'}; |
1391 |
delete $order->{ordernumber}; |
| 1418 |
$order->{'budget_id'} = ( $budget_id || $order->{'budget_id'} ); |
1392 |
$order->{budget_id} = ( $budget_id || $order->{budget_id} ); |
| 1419 |
$order->{'quantity'} = $quantrec; |
1393 |
$order->{quantity} = $quantrec; |
| 1420 |
$order->{'quantityreceived'} = $quantrec; |
1394 |
$order->{quantityreceived} = $quantrec; |
| 1421 |
$order->{'datereceived'} = $datereceived; |
1395 |
$order->{datereceived} = $datereceived; |
| 1422 |
$order->{'invoiceid'} = $invoiceid; |
1396 |
$order->{invoiceid} = $invoice->{invoiceid}; |
| 1423 |
$order->{'unitprice'} = $cost; |
1397 |
$order->{orderstatus} = 'complete'; |
| 1424 |
$order->{'rrp'} = $rrp; |
|
|
| 1425 |
$order->{ecost} = $ecost; |
| 1426 |
$order->{'orderstatus'} = 'complete'; |
| 1427 |
$new_ordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; |
1398 |
$new_ordernumber = Koha::Acquisition::Order->new($order)->insert->{ordernumber}; |
| 1428 |
|
1399 |
|
| 1429 |
if ($received_items) { |
1400 |
if ($received_items) { |
|
Lines 1433-1461
q{SELECT * FROM aqorders WHERE biblionumber=? AND aqorders.ordernumber=?},
Link Here
|
| 1433 |
} |
1404 |
} |
| 1434 |
} else { |
1405 |
} else { |
| 1435 |
my $query = q| |
1406 |
my $query = q| |
| 1436 |
update aqorders |
1407 |
UPDATE aqorders |
| 1437 |
set quantityreceived=?,datereceived=?,invoiceid=?, |
1408 |
SET quantityreceived = ?, |
| 1438 |
unitprice=?,rrp=?,ecost=?,budget_id=?,orderstatus='complete'|; |
1409 |
datereceived = ?, |
| 1439 |
$query .= q|, order_internalnote = ?| if defined $order_internalnote; |
1410 |
invoiceid = ?, |
| 1440 |
$query .= q|, order_vendornote = ?| if defined $order_vendornote; |
1411 |
budget_id = ?, |
|
|
1412 |
orderstatus = 'complete' |
| 1413 |
|; |
| 1414 |
|
| 1415 |
$query .= q| |
| 1416 |
, unitprice = ?, unitprice_tax_included = ?, unitprice_tax_excluded = ? |
| 1417 |
| if defined $order->{unitprice}; |
| 1418 |
|
| 1419 |
$query .= q| |
| 1420 |
, rrp = ?, rrp_tax_included = ?, rrp_tax_excluded = ? |
| 1421 |
| if defined $order->{rrp}; |
| 1422 |
|
| 1423 |
$query .= q| |
| 1424 |
, ecost = ?, ecost_tax_included = ?, ecost_tax_excluded = ? |
| 1425 |
| if defined $order->{ecost}; |
| 1426 |
|
| 1427 |
$query .= q| |
| 1428 |
, order_internalnote = ? |
| 1429 |
| if defined $order->{order_internalnote}; |
| 1430 |
|
| 1441 |
$query .= q| where biblionumber=? and ordernumber=?|; |
1431 |
$query .= q| where biblionumber=? and ordernumber=?|; |
|
|
1432 |
|
| 1442 |
my $sth = $dbh->prepare( $query ); |
1433 |
my $sth = $dbh->prepare( $query ); |
| 1443 |
$sth->execute( |
1434 |
my @params = ( $quantrec, $datereceived, $invoice->{invoiceid}, $budget_id ); |
| 1444 |
$quantrec, |
1435 |
|
| 1445 |
$datereceived, |
1436 |
if ( defined $order->{unitprice} ) { |
| 1446 |
$invoiceid, |
1437 |
push @params, $order->{unitprice}, $order->{unitprice_tax_included}, $order->{unitprice_tax_excluded}; |
| 1447 |
$cost, |
1438 |
} |
| 1448 |
$rrp, |
1439 |
if ( defined $order->{rrp} ) { |
| 1449 |
$ecost, |
1440 |
push @params, $order->{rrp}, $order->{rrp_tax_included}, $order->{rrp_tax_excluded}; |
| 1450 |
( $budget_id ? $budget_id : $order->{budget_id} ), |
1441 |
} |
| 1451 |
( defined $order_internalnote ? $order_internalnote : () ), |
1442 |
if ( defined $order->{ecost} ) { |
| 1452 |
( defined $order_vendornote ? $order_vendornote : () ), |
1443 |
push @params, $order->{ecost}, $order->{ecost_tax_included}, $order->{ecost_tax_excluded}; |
| 1453 |
$biblionumber, |
1444 |
} |
| 1454 |
$ordernumber |
1445 |
if ( defined $order->{order_internalnote} ) { |
| 1455 |
); |
1446 |
push @params, $order->{order_internalnote}; |
|
|
1447 |
} |
| 1448 |
|
| 1449 |
push @params, ( $biblionumber, $order->{ordernumber} ); |
| 1450 |
|
| 1451 |
$sth->execute( @params ); |
| 1456 |
|
1452 |
|
| 1457 |
# All items have been received, sent a notification to users |
1453 |
# All items have been received, sent a notification to users |
| 1458 |
NotifyOrderUsers( $ordernumber ); |
1454 |
NotifyOrderUsers( $order->{ordernumber} ); |
| 1459 |
|
1455 |
|
| 1460 |
} |
1456 |
} |
| 1461 |
return ($datereceived, $new_ordernumber); |
1457 |
return ($datereceived, $new_ordernumber); |
|
Lines 2830-2879
sub populate_order_with_prices {
Link Here
|
| 2830 |
$order->{ecost} = Koha::Number::Price->new( $order->{ecost} )->round; |
2826 |
$order->{ecost} = Koha::Number::Price->new( $order->{ecost} )->round; |
| 2831 |
if ($ordering) { |
2827 |
if ($ordering) { |
| 2832 |
if ( $bookseller->{listincgst} ) { |
2828 |
if ( $bookseller->{listincgst} ) { |
| 2833 |
$order->{rrpgsti} = $order->{rrp}; |
2829 |
$order->{rrp_tax_included} = $order->{rrp}; |
| 2834 |
$order->{rrpgste} = Koha::Number::Price->new( |
2830 |
$order->{rrp_tax_excluded} = Koha::Number::Price->new( |
| 2835 |
$order->{rrpgsti} / ( 1 + $order->{gstrate} ) )->round; |
2831 |
$order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ) )->round; |
| 2836 |
$order->{ecostgsti} = $order->{ecost}; |
2832 |
$order->{ecost_tax_included} = $order->{ecost}; |
| 2837 |
$order->{ecostgste} = Koha::Number::Price->new( |
2833 |
$order->{ecost_tax_excluded} = Koha::Number::Price->new( |
| 2838 |
$order->{ecost} / ( 1 + $order->{gstrate} ) )->round; |
2834 |
$order->{ecost} / ( 1 + $order->{tax_rate} ) )->round; |
| 2839 |
$order->{gstvalue} = Koha::Number::Price->new( |
2835 |
$order->{tax_value} = Koha::Number::Price->new( |
| 2840 |
( $order->{ecostgsti} - $order->{ecostgste} ) * |
2836 |
( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) * |
| 2841 |
$order->{quantity} )->round; |
2837 |
$order->{quantity} )->round; |
| 2842 |
$order->{totalgste} = $order->{ecostgste} * $order->{quantity}; |
|
|
| 2843 |
$order->{totalgsti} = $order->{ecostgsti} * $order->{quantity}; |
| 2844 |
} |
2838 |
} |
| 2845 |
else { |
2839 |
else { |
| 2846 |
$order->{rrpgste} = $order->{rrp}; |
2840 |
$order->{rrp_tax_excluded} = $order->{rrp}; |
| 2847 |
$order->{rrpgsti} = Koha::Number::Price->new( |
2841 |
$order->{rrp_tax_included} = Koha::Number::Price->new( |
| 2848 |
$order->{rrp} * ( 1 + $order->{gstrate} ) )->round; |
2842 |
$order->{rrp} * ( 1 + $order->{tax_rate} ) )->round; |
| 2849 |
$order->{ecostgste} = $order->{ecost}; |
2843 |
$order->{ecost_tax_excluded} = $order->{ecost}; |
| 2850 |
$order->{ecostgsti} = Koha::Number::Price->new( |
2844 |
$order->{ecost_tax_included} = Koha::Number::Price->new( |
| 2851 |
$order->{ecost} * ( 1 + $order->{gstrate} ) )->round; |
2845 |
$order->{ecost} * ( 1 + $order->{tax_rate} ) )->round; |
| 2852 |
$order->{gstvalue} = Koha::Number::Price->new( |
2846 |
$order->{tax_value} = Koha::Number::Price->new( |
| 2853 |
( $order->{ecostgsti} - $order->{ecostgste} ) * |
2847 |
( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) * |
| 2854 |
$order->{quantity} )->round; |
2848 |
$order->{quantity} )->round; |
| 2855 |
$order->{totalgste} = $order->{ecostgste} * $order->{quantity}; |
|
|
| 2856 |
$order->{totalgsti} = $order->{ecostgsti} * $order->{quantity}; |
| 2857 |
} |
2849 |
} |
| 2858 |
} |
2850 |
} |
| 2859 |
|
2851 |
|
| 2860 |
if ($receiving) { |
2852 |
if ($receiving) { |
| 2861 |
if ( $bookseller->{listincgst} ) { |
2853 |
if ( $bookseller->{listincgst} ) { |
| 2862 |
$order->{unitpricegsti} = Koha::Number::Price->new( $order->{unitprice} )->round; |
2854 |
$order->{unitprice_tax_included} = Koha::Number::Price->new( $order->{unitprice} )->round; |
| 2863 |
$order->{unitpricegste} = Koha::Number::Price->new( |
2855 |
$order->{unitprice_tax_excluded} = Koha::Number::Price->new( |
| 2864 |
$order->{unitpricegsti} / ( 1 + $order->{gstrate} ) )->round; |
2856 |
$order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ) )->round; |
| 2865 |
} |
2857 |
} |
| 2866 |
else { |
2858 |
else { |
| 2867 |
$order->{unitpricegste} = Koha::Number::Price->new( $order->{unitprice} )->round; |
2859 |
$order->{unitprice_tax_excluded} = Koha::Number::Price->new( $order->{unitprice} )->round; |
| 2868 |
$order->{unitpricegsti} = Koha::Number::Price->new( |
2860 |
$order->{unitprice_tax_included} = Koha::Number::Price->new( |
| 2869 |
$order->{unitpricegste} * ( 1 + $order->{gstrate} ) )->round; |
2861 |
$order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ) )->round; |
| 2870 |
} |
2862 |
} |
| 2871 |
$order->{gstvalue} = Koha::Number::Price->new( |
2863 |
$order->{tax_value} = Koha::Number::Price->new( |
| 2872 |
( $order->{unitpricegsti} - $order->{unitpricegste} ) |
2864 |
( $order->{unitprice_tax_included} - $order->{unitprice_tax_excluded} ) |
| 2873 |
* $order->{quantityreceived} )->round; |
2865 |
* $order->{quantityreceived} )->round; |
| 2874 |
|
2866 |
|
| 2875 |
$order->{totalgste} = $order->{unitpricegste} * $order->{quantity}; |
|
|
| 2876 |
$order->{totalgsti} = $order->{unitpricegsti} * $order->{quantity}; |
| 2877 |
} |
2867 |
} |
| 2878 |
|
2868 |
|
| 2879 |
return $order; |
2869 |
return $order; |