C4::Acquisition - Koha functions for dealing with orders and acquisitions
use C4::Acquisition;
The functions in this module deal with acquisitions, managing book orders, basket and parcels.
$aqbasket = &GetBasket($basketnumber);
get all basket informations in aqbasket for a given basket
returns: informations for a given basket returned as a hashref.
$basket = &NewBasket( $booksellerid, $authorizedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace );
Create a new basket in aqbasket table
$booksellerid
is a foreign key in the aqbasket table$authorizedby
is the username of who created the basketThe other parameters are optional, see ModBasketHeader for more info on them.
&CloseBasket($basketno);
close a basket (becomes unmodifiable, except for receives)
&ReopenBasket($basketno);
reopen a basket
&GetBasketAsCSV($basketno);
Export a basket as CSV
$cgi parameter is needed for column name translation
&GetBasketGroupAsCSV($basketgroupid);
Export a basket group as CSV
$cgi parameter is needed for column name translation
&CloseBasketgroup($basketgroupno);
close a basketgroup
&ReOpenBaskergroup($basketgroupno);
reopen a basketgroup
&DelBasket($basketno);
Deletes the basket that has basketno field $basketno in the aqbasket table.
$basketno
is the primary key of the basket in the aqbasket table.&ModBasket($basketinfo);
Modifies a basket, using a hashref $basketinfo for the relevant information, only $basketinfo->{'basketno'} is required.
$basketno
is the primary key of the basket in the aqbasket table.&ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid);
Modifies a basket's header.
$basketno
is the "basketno" field in the "aqbasket" table;$basketname
is the "basketname" field in the "aqbasket" table;$note
is the "note" field in the "aqbasket" table;$booksellernote
is the "booksellernote" field in the "aqbasket" table;$contractnumber
is the "contractnumber" (foreign) key in the "aqbasket" table.$booksellerid
is the id (foreign) key in the "aqbooksellers" table for the vendor.$deliveryplace
is the "deliveryplace" field in the aqbasket table.$billingplace
is the "billingplace" field in the aqbasket table.@results = &GetBasketsByBookseller($booksellerid, $extra);
Returns a list of hashes of all the baskets that belong to bookseller 'booksellerid'.
$booksellerid
is the 'id' field of the bookseller in the aqbooksellers table$extra
is the extra sql parameters, can be$extra->{groupby}: group baskets by column ex. $extra->{groupby} = aqbasket.basketgroupid $extra->{orderby}: order baskets by column $extra->{limit}: limit number of results (can be helpful for pagination)
my $baskets = GetBasketsInfosByBookseller($supplierid, $allbaskets);
The optional second parameter allbaskets is a boolean allowing you to select all baskets from the supplier; by default only active baskets (open or closed but still something to receive) are returned.
Returns in a arrayref of hashref all about booksellers baskets, plus: total_biblios: Number of distinct biblios in basket total_items: Number of items in basket expected_items: Number of non-received items in basket
$basketusers_ids = &GetBasketUsers($basketno);
Returns a list of all borrowernumbers that are in basket users list
my @basketusers_ids = (1, 2, 3); &ModBasketUsers($basketno, @basketusers_ids);
Delete all users from basket users list, and add users in @basketusers_ids
to this users list.
my $bool = CanUserManageBasket($borrower, $basket[, $userflags]); my $bool = CanUserManageBasket($borrowernumber, $basketno[, $userflags]);
Check if a borrower can manage a basket, according to system preference AcqViewBaskets, user permissions and basket properties (creator, users list, branch).
First parameter can be either a borrowernumber or a hashref as returned by C4::Members::GetMember.
Second parameter can be either a basketno or a hashref as returned by C4::Acquisition::GetBasket.
The third parameter is optional. If given, it should be a hashref as returned by C4::Auth::getuserflags. If not, getuserflags is called.
If user is authorised to manage basket, returns 1. Otherwise returns 0.
$baskets = &GetBasketsByBasketgroup($basketgroupid);
Returns a reference to all baskets that belong to basketgroup $basketgroupid.
$basketgroupid = NewBasketgroup(\%hashref);
Adds a basketgroup to the aqbasketgroups table, and add the initial baskets to it.
$hashref->{'booksellerid'} is the 'id' field of the bookseller in the aqbooksellers table,
$hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
$hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
$hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
ModBasketgroup(\%hashref);
Modifies a basketgroup in the aqbasketgroups table, and add the baskets to it.
$hashref->{'id'} is the 'id' field of the basketgroup in the aqbasketgroup table, this parameter is mandatory,
$hashref->{'name'} is the 'name' field of the basketgroup in the aqbasketgroups table,
$hashref->{'basketlist'} is a list reference of the 'id's of the baskets that belong to this group,
$hashref->{'billingplace'} is the 'billingplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'deliveryplace'} is the 'deliveryplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgroup in the aqbasketgroups table,
$hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table,
$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise.
DelBasketgroup($basketgroupid);
Deletes a basketgroup in the aqbasketgroups table, and removes the reference to it from the baskets,
$basketgroupid
is the 'id' field of the basket in the aqbasketgroup table$basketgroup = &GetBasketgroup($basketgroupid);
Returns a reference to the hash containing all infermation about the basketgroup.
$basketgroups = &GetBasketgroups($booksellerid);
Returns a reference to the array of all the basketgroups of bookseller $booksellerid.
@orders = &GetOrders($basketnumber, $orderby);
Looks up the pending (non-cancelled) orders with the given basket number. If $booksellerID
is non-empty, only orders from that seller are returned.
return : &basket
returns a two-element array. @orders
is an array of references-to-hash, whose keys are the fields from the aqorders, biblio, and biblioitems tables in the Koha database.
@orders = &GetOrdersByBiblionumber($biblionumber);
Looks up the orders with linked to a specific $biblionumber, including cancelled orders and received orders.
return : @orders
is an array of references-to-hash, whose keys are the fields from the aqorders, biblio, and biblioitems tables in the Koha database.
$order = &GetOrder($ordernumber);
Looks up an order by order number.
Returns a reference-to-hash describing the order. The keys of $order
are fields from the biblio, biblioitems, aqorders tables of the Koha database.
$order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid);
Returns a reference-to-hash describing the last order not received for a subscription.
$order = &GetLastOrderReceivedFromSubscriptionid($subscriptionid);
Returns a reference-to-hash describing the last order received for a subscription.
&NewOrder(\%hashref);
Adds a new order to the database. Any argument that isn't described below is the new value of the field with the same name in the aqorders table of the Koha database.
The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id".
&NewOrderItem();
&ModOrder(\%hashref);
Modifies an existing order. Updates the order with order number $hashref->{'ordernumber'} and biblionumber $hashref->{'biblionumber'}. All other keys of the hash update the fields with the same name in the aqorders table of the Koha database.
ModItemOrder($itemnumber, $ordernumber);
Modifies the ordernumber of an item in aqorders_items.
my @orders = GetCancelledOrders($basketno, $orderby);
Returns cancelled orders for a basket
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, $cost, $ecost, $invoiceid, rrp, budget_id, datereceived, \@received_itemnumbers);
Updates an order, to reflect the fact that it was received, at least in part. All arguments not mentioned below update the fields with the same name in the aqorders table of the Koha database.
If a partial order is received, splits the order into two.
Updates the order with bibilionumber $biblionumber
and ordernumber $ordernumber
.
my $parent_ordernumber = CancelReceipt($ordernumber); Cancel an order line receipt and update the parent order line, as if no receipt was made. If items are created at receipt (AcqCreateItem = receiving) then delete these items.
@results = &SearchOrders({ ordernumber => $ordernumber, search => $search, biblionumber => $biblionumber, ean => $ean, booksellerid => $booksellerid, basketno => $basketno, owner => $owner, pending => $pending });
Searches for orders.
$owner
Finds order for the logged in user. $pending
Finds pending orders. Ignores completed and cancelled orders.
@results
is an array of references-to-hash with the keys are fields from aqorders, biblio, biblioitems and aqbasket tables.
&DelOrder($biblionumber, $ordernumber);
Cancel the order with the given order and biblio numbers. It does not delete any entries in the aqorders table, it merely marks them as cancelled.
my $newordernumber = TransferOrder($ordernumber, $basketno);
Transfer an order line to a basket. Mark $ordernumber as cancelled with an internal note 'Cancelled and transfered to BOOKSELLER on DATE' and create new order with internal note 'Transfered from BOOKSELLER on DATE'. Move all attached items to the new order. Received orders cannot be transfered. Return the ordernumber of created order.
@results = &GetParcel($booksellerid, $code, $date);
Looks up all of the received items from the supplier with the given bookseller ID at the given date, for the given code (bookseller Invoice number). Ignores cancelled and completed orders.
@results
is an array of references-to-hash. The keys of each element are fields from the aqorders, biblio, and biblioitems tables of the Koha database.
@results
is sorted alphabetically by book title.
$results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);
get a lists of parcels.
* Input arg :
* return: a pointer on a hash list containing parcel informations as such :
@results = &GetLateOrders;
Searches for bookseller with late orders.
return: the table of supplier with late issues. This table is full of hashref.
(\@order_loop, $total_qty, $total_price, $total_qtyreceived) = GetHistory( %params );
Retreives some acquisition history information
params: title author name from_placed_on to_placed_on basket - search both basket name and number booksellerinvoicenumber
returns: $order_loop is a list of hashrefs that each look like this: { 'author' => 'Twain, Mark', 'basketno' => '1', 'biblionumber' => '215', 'count' => 1, 'creationdate' => 'MM/DD/YYYY', 'datereceived' => undef, 'ecost' => '1.00', 'id' => '1', 'invoicenumber' => undef, 'name' => '', 'ordernumber' => '1', 'quantity' => 1, 'quantityreceived' => undef, 'title' => 'The Adventures of Huckleberry Finn' } $total_qty is the sum of all of the quantities in $order_loop $total_price is the cost of each in $order_loop times the quantity $total_qtyreceived is the sum of all of the quantityreceived entries in $order_loop
$results = GetRecentAcqui($days);
$results
is a ref to a table which containts hashref
$contractlist = &GetContracts($booksellerid, $activeonly);
Looks up the contracts that belong to a bookseller
Returns a list of contracts
$booksellerid
is the "id" field in the "aqbooksellers" table.$activeonly
if exists get only contracts that are still active.$contract = &GetContract($contractID);
Looks up the contract that has PRIMKEY (contractnumber) value $contractID
Returns a contract
&AddClaim($ordernumber);
Add a claim for an order
my @invoices = GetInvoices( invoicenumber => $invoicenumber, suppliername => $suppliername, shipmentdatefrom => $shipmentdatefrom, # ISO format shipmentdateto => $shipmentdateto, # ISO format billingdatefrom => $billingdatefrom, # ISO format billingdateto => $billingdateto, # ISO format isbneanissn => $isbn_or_ean_or_issn, title => $title, author => $author, publisher => $publisher, publicationyear => $publicationyear, branchcode => $branchcode, order_by => $order_by );
Return a list of invoices that match all given criteria.
$order_by is "column_name (asc|desc)", where column_name is any of 'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate', 'shipmentcost', 'shipmentcost_budgetid'.
asc is the default if omitted
my $invoice = GetInvoice($invoiceid);
Get informations about invoice with given $invoiceid
Return a hash filled with aqinvoices.* fields
my $invoice = GetInvoiceDetails($invoiceid)
Return informations about an invoice + the list of related order lines
Orders informations are in $invoice->{orders} (array ref)
my $invoiceid = AddInvoice( invoicenumber => $invoicenumber, booksellerid => $booksellerid, shipmentdate => $shipmentdate, billingdate => $billingdate, closedate => $closedate, shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipmentcost_budgetid );
Create a new invoice and return its id or undef if it fails.
ModInvoice( invoiceid => $invoiceid, # Mandatory invoicenumber => $invoicenumber, booksellerid => $booksellerid, shipmentdate => $shipmentdate, billingdate => $billingdate, closedate => $closedate, shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipmentcost_budgetid );
Modify an invoice, invoiceid is mandatory.
Return undef if it fails.
CloseInvoice($invoiceid);
Close an invoice.
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef);
ReopenInvoice($invoiceid);
Reopen an invoice
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso'))
DelInvoice($invoiceid);
Delete an invoice if there are no items attached to it.
MergeInvoices($invoiceid, \@sourceids);
Merge the invoices identified by the IDs in \@sourceids into the invoice identified by $invoiceid.
$biblio_count = &GetBiblioCountByBasketno($basketno);
Looks up the biblio's count that has basketno value $basketno
Returns a quantity
Koha Development Team <http://koha-community.org/>