[Koha-patches] [PATCH] Bug 10424 - Search received orders

Srdjan srdjan at catalyst.net.nz
Fri Jul 26 06:06:02 CEST 2013


From: Amit Gupta <amitddng135 at gmail.com>

Search against order numbers and pull up the related
invoice to see when the item was received.

This allows users to see details of received orders,
including the details against which invoice the order is
received.

Test Plan:
1) Create a basket.
2) Create a orders under basket and close the basket.
3) Click on Receive shipment button and enter the invoice no and
shipment date.
4) Click on Receive link to receive the items.
5) Click on Received orders link on the left hand side.
6) This allow user to search by orderline, basket, title, author,
ISBN, vendor and date received.
7) Users will be able to see details of received orders.

Sponsored-by: Staffordshire University/Halton Borough Council/PTFS Europe

Signed-off-by: Srdjan <srdjan at catalyst.net.nz>
---
 C4/Acquisition.pm                                  | 139 +++++++++++++++++++++
 acqui/receivedorders.pl                            | 109 ++++++++++++++++
 .../prog/en/includes/acquisitions-menu.inc         |   1 +
 .../prog/en/modules/acqui/receivedorders.tt        | 110 ++++++++++++++++
 4 files changed, 359 insertions(+)
 create mode 100755 acqui/receivedorders.pl
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/receivedorders.tt

diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index 1a210b5..c8bc7d4 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -72,6 +72,7 @@ BEGIN {
         &CloseInvoice
         &ReopenInvoice
         &DelInvoice
+        &GetReceivedorder
 
         &GetItemnumbersFromOrder
 
@@ -2061,6 +2062,144 @@ sub GetHistory {
     return \@order_loop, $total_qty, $total_price, $total_qtyreceived;
 }
 
+=head3 GetReceivedorder
+
+    $orderrec_loop = GetReceivedorder( %params );
+
+Returns an arrayref of received orders
+
+params:
+    title
+    author
+    name
+    datereceivedfrom
+    datereceivedto
+    basket                  - search both basket name and number
+    ordernumber             - search by ordernumber
+
+returns:
+    $order_loop is a reference to an array of hashrefs that each look like this:
+            {
+                'author'           => 'Twain, Mark',
+                'basketno'         => '1',
+                'biblionumber'     => '215',
+                'datereceived'     => 'MM/DD/YYYY'
+                'name'             => '',
+                'ordernumber'      => '1',
+                'quantity'         => 1,
+                'quantityreceived' => undef,
+                'title'            => 'The Adventures of Huckleberry Finn'
+            }
+
+=cut
+
+sub GetReceivedorder {
+    croak "No search params" unless @_;
+    my %params = @_;
+    my $title = $params{title};
+    my $author = $params{author};
+    my $isbn   = $params{isbn};
+    my $ean    = $params{ean};
+    my $name = $params{name};
+    my $datereceivedfrom = $params{datereceivedfrom};
+    my $datereceivedto = $params{datereceivedto};
+    my $basket = $params{basket};
+    my $order = $params{ordernumber};
+
+    my $query ="
+        SELECT
+            biblio.title,
+            biblio.author,
+            biblioitems.isbn,
+            biblioitems.ean,
+            aqorders.basketno,
+            aqbasket.basketname,
+            aqbooksellers.name,
+            aqbasket.creationdate,
+            aqorders.datereceived,
+            aqorders.quantity,
+            aqorders.quantityreceived,
+            aqorders.ecost,
+            aqorders.ordernumber,
+            aqorders.invoiceid,
+            aqinvoices.invoicenumber,
+            aqbooksellers.id as id,
+            aqorders.biblionumber
+        FROM aqorders
+        LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
+        LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
+        LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber
+        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
+        LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid";
+
+    $query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
+    if ( C4::Context->preference("IndependentBranches") );
+
+    $query .= " WHERE (aqorders.datereceived IS NOT NULL) ";
+
+    my @query_params  = ();
+
+    if ( $title ) {
+        $query .= " AND biblio.title LIKE ? ";
+        $title =~ s/\s+/%/g;
+        push @query_params, "%$title%";
+    }
+
+    if ( $author ) {
+        $query .= " AND biblio.author LIKE ? ";
+        push @query_params, "%$author%";
+    }
+
+    if ( $isbn ) {
+        $query .= " AND biblioitems.isbn LIKE ? ";
+        push @query_params, "%$isbn%";
+    }
+    if ( defined $ean and $ean ) {
+        $query .= " AND biblioitems.ean = ? ";
+        push @query_params, "$ean";
+    }
+    if ( $name ) {
+        $query .= " AND aqbooksellers.name LIKE ? ";
+        push @query_params, "%$name%";
+    }
+    if ( $datereceivedfrom ) {
+        $query .= " AND aqorders.datereceived >= ? ";
+        push @query_params, $datereceivedfrom;
+    }
+
+    if ( $datereceivedto ) {
+        $query .= " AND aqorders.datereceived <= ? ";
+        push @query_params, $datereceivedto;
+    }
+
+    if ($basket) {
+        if ($basket =~ m/^\d+$/) {
+            $query .= " AND aqorders.basketno = ? ";
+            push @query_params, $basket;
+        } else {
+            $query .= " AND aqbasket.basketname LIKE ? ";
+            push @query_params, "%$basket%";
+        }
+    }
+
+    if ($order =~ m/^\d+$/) {
+            $query .= " AND aqorders.ordernumber = ? ";
+            push @query_params, $order;
+        }
+
+    if ( C4::Context->preference("IndependentBranches") ) {
+        my $userenv = C4::Context->userenv;
+        if ( $userenv && ($userenv->{flags} || 0) != 1 ) {
+            $query .= " AND (borrowers.branchcode = ? OR borrowers.branchcode ='' ) ";
+            push @query_params, $userenv->{branch};
+        }
+    }
+    $query .= " ORDER BY id";
+
+    my $dbh = C4::Context->dbh;
+    return $dbh->selectall_arrayref( $query, { Slice => {} }, @query_params );
+}
+
 =head2 GetRecentAcqui
 
   $results = GetRecentAcqui($days);
diff --git a/acqui/receivedorders.pl b/acqui/receivedorders.pl
new file mode 100755
index 0000000..c69c3cb
--- /dev/null
+++ b/acqui/receivedorders.pl
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright 2013 Amit Gupta(amitddng135 at gmail.com)
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+=head1 NAME
+
+receivedorders.pl
+
+=head1 DESCRIPTION
+
+this script offer a interface to search among order.
+
+=head1 CGI PARAMETERS
+
+=over 4
+
+=item title
+if the script has to filter the results on title.
+
+=item author
+if the script has to filter the results on author.
+
+=item name
+if the script has to filter the results on supplier.
+
+=item datereceivedfrom
+to filter on started date.
+
+=item datereceivedto
+to filter on ended date.
+
+=back
+
+=cut
+
+use strict;
+use warnings;
+use CGI;
+use C4::Auth;    # get_template_and_user
+use C4::Output;
+use C4::Acquisition qw/GetReceivedorder/;
+use C4::Dates;
+use C4::Debug;
+
+my $input = new CGI();
+my $title                   = $input->param('title');
+my $ordernumber             = $input->param('ordernumber');
+my $author                  = $input->param('author');
+my $isbn                    = $input->param('isbn');
+my $name                    = $input->param('name' );
+my $ean                     = $input->param('ean');
+my $basket                  = $input->param( 'basket' );
+my $do_search               = $input->param('do_search') || 0;
+my $from                    = C4::Dates->new($input->param('from'));
+my $to                      = C4::Dates->new($input->param('to'));
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "acqui/receivedorders.tmpl",
+        query           => $input,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { acquisition => '*' },
+        debug           => 1,
+    }
+);
+
+my ( $from_iso, $to_iso, $d );
+if ( $d = $input->param('from') ) {
+    $from_iso = C4::Dates->new($d)->output('iso');
+}
+if ( $d = $input->param('iso') ) {
+    $to_iso = C4::Dates->new($d)->output('iso');
+}
+
+my $orderrec_loop;
+
+if ($do_search) {
+    $orderrec_loop = GetReceivedorder(
+        title => $title,
+        author => $author,
+        isbn   => $isbn,
+        ean   => $ean,
+        name => $name,
+        datereceivedfrom => $from_iso,
+        datereceivedto => $to_iso,
+        basket => $basket,
+        ordernumber => $ordernumber,
+    );
+}
+
+$template->param( orderrec_loop => $orderrec_loop,);
+
+output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
index 439118d..d37c4b6 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc
@@ -2,6 +2,7 @@
 	<li><a href="/cgi-bin/koha/acqui/lateorders.pl">Late orders</a></li>
 	[% IF ( suggestion ) %]<li><a href="/cgi-bin/koha/suggestion/suggestion.pl">Suggestions</a></li>[% ELSE %][% END %]
     <li><a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a></li>
+    <li><a href="/cgi-bin/koha/acqui/receivedorders.pl">Received orders</a></li>
     [% IF ( CAN_user_acquisition_budget_manage ) %]
     <li><a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a></li>
     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a></li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/receivedorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/receivedorders.tt
new file mode 100644
index 0000000..185c6c1
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/receivedorders.tt
@@ -0,0 +1,110 @@
+[% USE KohaDates %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha › Acquisitions › [% IF ( orderrec_loop ) %] Received orders › Search results[% ELSE %]Search received orders[% END %]</title>
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+[% INCLUDE 'doc-head-close.inc' %]
+[% INCLUDE 'calendar.inc' %]
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+[% INCLUDE 'datatables-strings.inc' %]
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+<script type="text/javascript">
+$(document).ready(function() {
+    var orderrecsearch = $("#orderrecsearch").dataTable($.extend(true, {}, dataTablesDefaults, {
+    "sPaginationType": "four_button"
+    } ) );
+});
+</script>
+</head>
+<body id="acq_recsearch" class="acq">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'acquisitions-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> › [% IF ( orderrec_loop ) %]<a href="/cgi-bin/koha/acqui/receivedorders.pl">Search received orders</a> › Search results[% ELSE %]Search received orders[% END %]</div>
+
+<div id="doc3" class="yui-t2">
+<div id="bd">
+<div id="yui-main">
+<div class="yui-b">
+    [% UNLESS ( orderrec_loop ) %]<form action="/cgi-bin/koha/acqui/receivedorders.pl" method="post">
+        <fieldset class="rows">
+        <legend>Search received orders</legend>
+        <ol>
+            <li><label for="ordernumber">Order: </label> <input type="text" name="ordernumber" id="ordernumber" value="[% ordernumber %]" /></li>
+            <li><label for="basket">Basket: </label> <input type="text" name="basket" id="basket" value="[% basket %]" /></li>
+            <li><label for="title">Title: </label> <input type="text" name="title" id="title" value="[% title %]" /></li>
+            <li><label for="author">Author: </label> <input type="text" name="author" id="author" value="[% author %]" /></li>
+            <li><label for="isbn">ISBN: </label> <input type="text" name="isbn" id="isbn" value="[% isbn %]" /></li>
+            [% IF (UNIMARC) %]
+                <li><label for="ean">EAN: </label> <input type="text" name="ean" id="ean" value="[% ean %]" /></li>
+            [% END %]
+            <li><label for="name">Vendor: </label> <input type="text" name="name" id="name" value="[% name %]" /></li>
+            <li><label for="from">Received from: </label>
+            <input type="text" size="10" id="from" name="from" value="[% from_placed_on %]" class="datepickerfrom" />
+                    <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+            </li>
+            <li><label for="to">Receive to: </label>
+            <input type="text" size="10" id="to" name="to" value="[% to_placed_on %]" class="datepickerto" />
+                    <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+            </li>
+        </ol>
+        </fieldset>
+        <input type="hidden" name="do_search" value="1" />
+        <fieldset class="action"><input type="submit" value="Search" /></fieldset>
+        </form>
+    [% END %]
+    [% IF ( orderrec_loop ) %]<h1>Received orders search result</h1>
+        <div id="acqui_recsearch">
+        <table id="orderrecsearch">
+        <thead>
+        <tr>
+            <th>Basket</th>
+            <th>Invoice number</th>
+            <th>Order number</th>
+            <th>Summary</th>
+            <th>Vendor</th>
+            <th>Placed on</th>
+            <th>Received on</th>
+            <th>Quantity ordered</th>
+            <th>Quantity received</th>
+            <th>Unit price</th>
+        </tr>
+        </thead>
+        <tbody>
+        [% FOREACH ordersrec_loo IN orderrec_loop %]
+        <tr>
+            <td>[% ordersrec_loo.basketname %] (<a href="basket.pl?basketno=[% ordersrec_loo.basketno %]">[% ordersrec_loo.basketno %]</a>)</td>
+            <td>
+                [% IF  ordersrec_loo.invoicenumber  %]
+                    <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% ordersrec_loo.invoiceid %]">[% ordersrec_loo.invoicenumber %]</a>
+                [% ELSE %]
+                     
+                [% END %]
+            </td>
+            <td>[% ordersrec_loo.ordernumber %]</td>
+            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersrec_loo.biblionumber %]">[% ordersrec_loo.title |html %]</a>
+                <br />[% ordersrec_loo.author %] <br /> [% ordersrec_loo.isbn %]
+            </td>
+            <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% ordersrec_loo.id %]">[% ordersrec_loo.name %]</a></td>
+            <td>[% ordersrec_loo.creationdate | $KohaDates %]</td>
+            <td>
+                [% IF ordersrec_loo.datereceived %]
+                    [% ordersrec_loo.datereceived | $KohaDates %]
+                [% END %]
+            </td>
+            <td>[% ordersrec_loo.quantity %]</td>
+            <td>[% ordersrec_loo.quantityreceived %]</td>
+            <td>[% ordersrec_loo.ecost %]</td>
+        </tr>
+        [% END %]
+        </tbody>
+        </table>
+        </div>
+        [% ELSE %]
+        [% END %]
+</div>
+</div>
+<div class="yui-b">
+[% INCLUDE 'acquisitions-menu.inc' %]
+</div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
-- 
1.8.1.2


More information about the Koha-patches mailing list