<<

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, $is_standing, $create_items );

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.
$is_standing is the "is_standing" field in the aqbasket table.
$create_items should be set to 'ordering', 'receiving' or 'cataloguing' (or undef, in which case the AcqCreateItem syspref takes precedence).

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 Koha::Patron->unblessed

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 information 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( $basketno, { orderby => 'biblio.title', cancelled => 0|1 } );

Looks up the pending (non-cancelled) orders with the given basket number.

If cancelled is set, only cancelled orders will be returned.

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.

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.

ModReceiveOrder

    my ( $date_received, $new_ordernumber ) = ModReceiveOrder(
        {
            biblionumber         => $biblionumber,
            order                => $order,
            quantityreceived     => $quantityreceived,
            user                 => $user,
            invoice              => $invoice,
            budget_id            => $budget_id,
            received_itemnumbers => \@received_itemnumbers,
            order_internalnote   => $order_internalnote,
        }
    );

Updates an order, to reflect the fact that it was received, at least in part.

If a partial order is received, splits the order into two.

Updates the order with biblionumber $biblionumber and ordernumber $order-{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, ean => $ean, booksellerid => $booksellerid, basketno => $basketno, basketname => $basketname, basketgroupname => $basketgroupname, owner => $owner, pending => $pending ordered => $ordered biblionumber => $biblionumber, budget_id => $budget_id });

Searches for orders filtered by criteria.

$ordernumber Finds matching orders or transferred orders by ordernumber. $search Finds orders matching %$search% in title, author, or isbn. $owner Finds order for the logged in user. $pending Finds pending orders. Ignores completed and cancelled orders. $ordered Finds orders to receive only (status 'ordered' or 'partial').

@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 transferred to BOOKSELLER on DATE' and create new order with internal note 'Transferred from BOOKSELLER on DATE'. Move all attached items to the new order. Received orders cannot be transferred. Return the ordernumber of created order.

FUNCTIONS ABOUT PARCELS

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 = GetHistory( %params );

Retreives some acquisition history information

params: title author name isbn ean from_placed_on to_placed_on basket - search both basket name and number booksellerinvoicenumber basketgroupname budget orderstatus (note that orderstatus '' will retrieve orders of any status except cancelled) biblionumber get_canceled_order (if set to a true value, cancelled orders will be included)

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' }

GetRecentAcqui

  $results = GetRecentAcqui($days);

$results is a ref to a table which containts hashref

AddClaim

  &AddClaim($ordernumber);

Add a claim for an order

GetInvoices

    my @invoices = GetInvoices(
        invoicenumber => $invoicenumber,
        supplierid => $supplierid,
        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 => output_pref({ dt=>dt_from_string, dateonly=>1, otputpref=>'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

GetOrderUsers

    $order_users_ids = &GetOrderUsers($ordernumber);

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

ModOrderUsers

    my @order_users_ids = (1, 2, 3);
    &ModOrderUsers($ordernumber, @basketusers_ids);

Delete all users from order users list, and add users in @order_users_ids to this users list.

FillWithDefaultValues

FillWithDefaultValues( $marc_record );

This will update the record with default value defined in the ACQ framework. For all existing fields, if a default value exists and there are no subfield, it will be created. If the field does not exist, it will be created too.

AUTHOR

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

<<