<<

NAME

C4::Acquisition - Koha functions for dealing with orders and acquisitions

SYNOPSIS

use C4::Acquisition;

DESCRIPTION

The functions in this module deal with acquisitions, managing book orders, basket and parcels.

FUNCTIONS

FUNCTIONS ABOUT BASKETS

GetBasket

  $aqbasket = &GetBasket($basketnumber);

get all basket informations in aqbasket for a given basket

returns: informations for a given basket returned as a hashref.

NewBasket

  $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 basket

The other parameters are optional, see ModBasketHeader for more info on them.

CloseBasket

  &CloseBasket($basketno);

close a basket (becomes unmodifiable, except for receives)

ReopenBasket

  &ReopenBasket($basketno);

reopen a basket

GetBasketAsCSV

  &GetBasketAsCSV($basketno);

Export a basket as CSV

$cgi parameter is needed for column name translation

GetBasketGroupAsCSV

&GetBasketGroupAsCSV($basketgroupid);

Export a basket group as CSV

$cgi parameter is needed for column name translation

CloseBasketgroup

  &CloseBasketgroup($basketgroupno);

close a basketgroup

ReOpenBaskergroup($basketgroupno)

  &ReOpenBaskergroup($basketgroupno);

reopen a basketgroup

DelBasket

  &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

  &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

  &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.

GetBasketsByBookseller

  @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)

GetBasketsInfosByBookseller

    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

GetBasketUsers

    $basketusers_ids = &GetBasketUsers($basketno);

Returns a list of all borrowernumbers that are in basket users list

ModBasketUsers

    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.

CanUserManageBasket

    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.

GetBasketsByBasketgroup

  $baskets = &GetBasketsByBasketgroup($basketgroupid);

Returns a reference to all baskets that belong to basketgroup $basketgroupid.

NewBasketgroup

  $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

  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

  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

FUNCTIONS ABOUT ORDERS

GetBasketgroup

  $basketgroup = &GetBasketgroup($basketgroupid);

Returns a reference to the hash containing all infermation about the basketgroup.

GetBasketgroups

  $basketgroups = &GetBasketgroups($booksellerid);

Returns a reference to the array of all the basketgroups of bookseller $booksellerid.

FUNCTIONS ABOUT ORDERS

GetOrders

  @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.

GetOrdersByBiblionumber

  @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.

GetOrder

  $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.

GetLastOrderNotReceivedFromSubscriptionid

  $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid);

Returns a reference-to-hash describing the last order not received for a subscription.

GetLastOrderReceivedFromSubscriptionid

  $order = &GetLastOrderReceivedFromSubscriptionid($subscriptionid);

Returns a reference-to-hash describing the last order received for a subscription.

NewOrder

  &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.

$hashref->{'basketno'} is the basketno foreign key in aqorders, it is mandatory
$hashref->{'ordernumber'} is a "minimum order number."
$hashref->{'budgetdate'} is effectively ignored. If it's undef (anything false) or the string 'now', the current day is used. Else, the upcoming July 1st is used.
$hashref->{'subscription'} may be either "yes", or anything else for "no".
$hashref->{'uncertainprice'} may be 0 for "the price is known" or 1 for "the price is uncertain"
defaults entrydate to Now

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

  &NewOrderItem();

ModOrder

  &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

    ModItemOrder($itemnumber, $ordernumber);

Modifies the ordernumber of an item in aqorders_items.

GetCancelledOrders

  my @orders = GetCancelledOrders($basketno, $orderby);

Returns cancelled orders for a basket

ModReceiveOrder

  &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.

CancelReceipt

    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.

SearchOrders

@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

  &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.

TransferOrder

    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.

FUNCTIONS ABOUT PARCELS

GetParcel

  @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.

GetParcels

  $results = &GetParcels($bookseller, $order, $code, $datefrom, $dateto);

get a lists of parcels.

* Input arg :

$bookseller is the bookseller this function has to get parcels.
$order To know on what criteria the results list has to be ordered.
$code is the booksellerinvoicenumber.
$datefrom & $dateto to know on what date this function has to filter its search.

* return: a pointer on a hash list containing parcel informations as such :

Creation date
Last operation
Number of biblio
Number of items

GetLateOrders

  @results = &GetLateOrders;

Searches for bookseller with late orders.

return: the table of supplier with late issues. This table is full of hashref.

GetHistory

  (\@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

GetRecentAcqui

  $results = GetRecentAcqui($days);

$results is a ref to a table which containts hashref

GetContracts

  $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.

GetContract

  $contract = &GetContract($contractID);

Looks up the contract that has PRIMKEY (contractnumber) value $contractID

Returns a contract

AddClaim

&AddClaim($ordernumber);

Add a claim for an order

GetInvoices

    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

GetInvoice

    my $invoice = GetInvoice($invoiceid);

Get informations about invoice with given $invoiceid

Return a hash filled with aqinvoices.* fields

GetInvoiceDetails

    my $invoice = GetInvoiceDetails($invoiceid)

Return informations about an invoice + the list of related order lines

Orders informations are in $invoice->{orders} (array ref)

AddInvoice

    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

    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

    CloseInvoice($invoiceid);

Close an invoice.

Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef);

ReopenInvoice

    ReopenInvoice($invoiceid);

Reopen an invoice

Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso'))

DelInvoice

    DelInvoice($invoiceid);

Delete an invoice if there are no items attached to it.

MergeInvoices

    MergeInvoices($invoiceid, \@sourceids);

Merge the invoices identified by the IDs in \@sourceids into the invoice identified by $invoiceid.

GetBiblioCountByBasketno

$biblio_count = &GetBiblioCountByBasketno($basketno);

Looks up the biblio's count that has basketno value $basketno

Returns a quantity

AUTHOR

Koha Development Team <http://koha-community.org/>

<<