use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Orders;
use Koha::Biblios;
+use Koha::Exceptions;
use Koha::Items;
use Koha::Number::Price;
use Koha::Libraries;
&DelInvoice
&MergeInvoices
- &GetItemnumbersFromOrder
-
&AddClaim
&GetBiblioCountByBasketno
}
-# Returns the itemnumber(s) associated with the ordernumber given in parameter
-sub GetItemnumbersFromOrder {
- my ($ordernumber) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "SELECT itemnumber FROM aqorders_items WHERE ordernumber=?";
- my $sth = $dbh->prepare($query);
- $sth->execute($ordernumber);
- my @tab;
-
- while (my $order = $sth->fetchrow_hashref) {
- push @tab, $order->{'itemnumber'};
- }
-
- return @tab;
-
-}
-
-
-
-
-
-
=head1 NAME
C4::Acquisition - Koha functions for dealing with orders and acquisitions
my @rows;
if ($csv_profile_id) {
my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
- die "There is no valid csv profile given" unless $csv_profile;
+ Koha::Exceptions::ObjectNotFound->throw( 'There is no valid csv profile given') unless $csv_profile;
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1});
my $csv_profile_content = $csv_profile->content;
COUNT(DISTINCT aqorders.biblionumber) AS total_biblios,
SUM(
IF(aqorders.datereceived IS NULL
- AND aqorders.datecancellationprinted IS NULL
+ AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
, aqorders.quantity
, 0)
) AS expected_items
LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno
WHERE booksellerid = ?};
+ $query.=" GROUP BY aqbasket.basketno, aqbasket.basketname, aqbasket.note, aqbasket.booksellernote, aqbasket.contractnumber, aqbasket.creationdate, aqbasket.closedate, aqbasket.booksellerid, aqbasket.authorisedby, aqbasket.booksellerinvoicenumber, aqbasket.basketgroupid, aqbasket.deliveryplace, aqbasket.billingplace, aqbasket.branch, aqbasket.is_standing, aqbasket.create_items";
+
unless ( $allbaskets ) {
- $query.=" AND (closedate IS NULL OR (aqorders.quantity > aqorders.quantityreceived AND datecancellationprinted IS NULL))";
+ # Don't show the basket if it's NOT CLOSED or is FULLY RECEIVED
+ $query.=" HAVING (closedate IS NULL OR (
+ SUM(
+ IF(aqorders.datereceived IS NULL
+ AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
+ , aqorders.quantity
+ , 0)
+ ) > 0))"
}
- $query.=" GROUP BY aqbasket.basketno, aqbasket.basketname, aqbasket.note, aqbasket.booksellernote, aqbasket.contractnumber, aqbasket.creationdate, aqbasket.closedate, aqbasket.booksellerid, aqbasket.authorisedby, aqbasket.booksellerinvoicenumber, aqbasket.basketgroupid, aqbasket.deliveryplace, aqbasket.billingplace, aqbasket.branch, aqbasket.is_standing, aqbasket.create_items";
my $sth = $dbh->prepare($query);
$sth->execute($supplierid);
UPDATE aqorders
SET quantity = ?,
orderstatus = 'partial'|;
- $query .= q|, order_internalnote = ?| if defined $order->{order_internalnote};
$query .= q| WHERE ordernumber = ?|;
my $sth = $dbh->prepare($query);
$sth->execute(
( $is_standing ? 1 : ($order->{quantity} - $quantrec) ),
- ( defined $order->{order_internalnote} ? $order->{order_internalnote} : () ),
$order->{ordernumber}
);
+ if ( not $order->{subscriptionid} && defined $order->{order_internalnote} ) {
+ $dbh->do(q|UPDATE aqorders
+ SET order_internalnote = ?|, {}, $order->{order_internalnote});
+ }
+
# Recalculate tax_value
$dbh->do(q|
UPDATE aqorders
orderstatus = 'complete'
|;
+ $query .= q|
+ , replacementprice = ?
+ | if defined $order->{replacementprice};
+
$query .= q|
, unitprice = ?, unitprice_tax_included = ?, unitprice_tax_excluded = ?
| if defined $order->{unitprice};
my $sth = $dbh->prepare( $query );
my @params = ( $quantrec, $datereceived, $invoice->{invoiceid}, ( $budget_id ? $budget_id : $order->{budget_id} ) );
+ if ( defined $order->{replacementprice} ) {
+ push @params, $order->{replacementprice};
+ }
+
if ( defined $order->{unitprice} ) {
push @params, $order->{unitprice}, $order->{unitprice_tax_included}, $order->{unitprice_tax_excluded};
}
my $parent_ordernumber = $order->{'parent_ordernumber'};
- my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
my $order_obj = Koha::Acquisition::Orders->find( $ordernumber ); # FIXME rewrite all this subroutine using this object
+ my @itemnumbers = $order_obj->items->get_column('itemnumber');
if($parent_ordernumber == $ordernumber || not $parent_ordernumber) {
# The order line has no parent, just mark it as not received
my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceiptIsCancelled");
if ( @affects ) {
for my $in ( @itemnumbers ) {
- my $item = Koha::Items->find( $in );
+ my $item = Koha::Items->find( $in ); # FIXME We do not need that, we already have Koha::Items from $order_obj->items
my $biblio = $item->biblio;
my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $biblio->frameworkcode );
my $item_marc = C4::Items::GetMarcItem( $biblio->biblionumber, $in );
my ( $order, $parent_ordernumber ) = @_;
$parent_ordernumber ||= $order->ordernumber;
- my @itemnumbers = GetItemnumbersFromOrder($order->ordernumber); # FIXME Must be $order->items
+ my $items = $order->items;
if ( $order->basket->effective_create_items eq 'receiving' ) {
# Remove items that were created at receipt
my $query = qq{
};
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare($query);
- foreach my $itemnumber (@itemnumbers) {
- $sth->execute($itemnumber, $itemnumber);
+ while ( my $item = $items->next ) {
+ $sth->execute($item->itemnumber, $item->itemnumber);
}
} else {
# Update items
- foreach my $itemnumber (@itemnumbers) {
- ModItemOrder($itemnumber, $parent_ordernumber);
+ while ( my $item = $items->next ) {
+ ModItemOrder($item->itemnumber, $parent_ordernumber);
}
}
}
}
$sth->finish;
- my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
- foreach my $itemnumber (@itemnumbers){
- my $delcheck = C4::Items::DelItemCheck( $bibnum, $itemnumber );
+ my $order = Koha::Acquisition::Orders->find($ordernumber);
+ my $items = $order->items;
+ while ( my $item = $items->next ) { # Should be moved to Koha::Acquisition::Order->delete
+ my $delcheck = C4::Items::DelItemCheck( $bibnum, $item->itemnumber );
if($delcheck != 1) {
$error->{'delitem'} = 1;
my $ordernumber = $params{ordernumber};
my $search_children_too = $params{search_children_too} || 0;
my $created_by = $params{created_by} || [];
+ my $ordernumbers = $params{ordernumbers} || [];
my @order_loop;
my $total_qty = 0;
my $total_qtyreceived = 0;
my $total_price = 0;
+ #get variation of isbn
+ my @isbn_params;
+ my @isbns;
+ if ($isbn){
+ if ( C4::Context->preference("SearchWithISBNVariations") ){
+ @isbns = C4::Koha::GetVariationsOfISBN( $isbn );
+ foreach my $isb (@isbns){
+ push @isbn_params, '?';
+ }
+ }
+ unless (@isbns){
+ push @isbns, $isbn;
+ push @isbn_params, '?';
+ }
+ }
+
my $dbh = C4::Context->dbh;
my $query ="
SELECT
push @query_params, "%$author%";
}
- if ( $isbn ) {
- $query .= " AND biblioitems.isbn LIKE ? ";
- push @query_params, "%$isbn%";
+ if ( @isbns ) {
+ $query .= " AND ( biblioitems.isbn LIKE " . join (" OR biblioitems.isbn LIKE ", @isbn_params ) . ")";
+ foreach my $isb (@isbns){
+ push @query_params, "%$isb%";
+ }
}
+
if ( $ean ) {
$query .= " AND biblioitems.ean = ? ";
push @query_params, "$ean";
push @query_params, @$created_by;
}
+ if ( @$ordernumbers ) {
+ $query .= ' AND (aqorders.ordernumber IN ( ' . join (',', ('?') x @$ordernumbers ) . '))';
+ push @query_params, @$ordernumbers;
+ }
if ( C4::Context->preference("IndependentBranches") ) {
unless ( C4::Context->IsSuperLibrarian() ) {
my $dbh = C4::Context->dbh;
my $query = qq{
- SELECT aqinvoices.*, aqbooksellers.name AS suppliername,
+ SELECT aqinvoices.invoiceid, aqinvoices.invoicenumber, aqinvoices.booksellerid, aqinvoices.shipmentdate, aqinvoices.billingdate, aqinvoices.closedate, aqinvoices.shipmentcost, aqinvoices.shipmentcost_budgetid, aqinvoices.message_id,
+ aqbooksellers.name AS suppliername,
COUNT(
DISTINCT IF(
aqorders.datereceived IS NOT NULL,
}
$query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs;
- $query .= " GROUP BY aqinvoices.invoiceid ";
+ $query .= " GROUP BY aqinvoices.invoiceid, aqinvoices.invoicenumber, aqinvoices.booksellerid, aqinvoices.shipmentdate, aqinvoices.billingdate, aqinvoices.closedate, aqinvoices.shipmentcost, aqinvoices.shipmentcost_budgetid, aqinvoices.message_id, aqbooksellers.name";
if($args{order_by}) {
my ($column, $direction) = split / /, $args{order_by};