From 2539e48cf4a44d6444f0761ca1b901be8936d54b Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Sat, 22 Jun 2013 22:17:38 +0530 Subject: [PATCH] Bug 10424 - Search received orders 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 --- 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@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 @@
  • Late orders
  • [% IF ( suggestion ) %]
  • Suggestions
  • [% ELSE %][% END %]
  • Invoices
  • +
  • Received orders
  • [% IF ( CAN_user_acquisition_budget_manage ) %]
  • Budgets
  • Funds
  • 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' %] +Koha › Acquisitions › [% IF ( orderrec_loop ) %] Received orders › Search results[% ELSE %]Search received orders[% END %] + +[% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'calendar.inc' %] + +[% INCLUDE 'datatables-strings.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'acquisitions-search.inc' %] + + + +
    +
    +
    +
    + [% UNLESS ( orderrec_loop ) %]
    +
    + Search received orders +
      +
    1. +
    2. +
    3. +
    4. +
    5. + [% IF (UNIMARC) %] +
    6. + [% END %] +
    7. +
    8. + +
      [% INCLUDE 'date-format.inc' %]
      +
    9. +
    10. + +
      [% INCLUDE 'date-format.inc' %]
      +
    11. +
    +
    + +
    +
    + [% END %] + [% IF ( orderrec_loop ) %]

    Received orders search result

    +
    + + + + + + + + + + + + + + + + + [% FOREACH ordersrec_loo IN orderrec_loop %] + + + + + + + + + + + + + [% END %] + +
    BasketInvoice numberOrder numberSummaryVendorPlaced onReceived onQuantity orderedQuantity receivedUnit price
    [% ordersrec_loo.basketname %] ([% ordersrec_loo.basketno %]) + [% IF ordersrec_loo.invoicenumber %] + [% ordersrec_loo.invoicenumber %] + [% ELSE %] +   + [% END %] + [% ordersrec_loo.ordernumber %][% ordersrec_loo.title |html %] +
    [% ordersrec_loo.author %]
    [% ordersrec_loo.isbn %] +
    [% ordersrec_loo.name %][% ordersrec_loo.creationdate | $KohaDates %] + [% IF ordersrec_loo.datereceived %] + [% ordersrec_loo.datereceived | $KohaDates %] + [% END %] + [% ordersrec_loo.quantity %][% ordersrec_loo.quantityreceived %][% ordersrec_loo.ecost %]
    +
    + [% ELSE %] + [% END %] +
    +
    +
    +[% INCLUDE 'acquisitions-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] -- 1.8.1.2