From db49e2c29bd4de31dd85a0a1172e94d04b0ea2cb Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Thu, 17 Oct 2013 21:48:47 +0530 Subject: [PATCH 1/2] Bug-4456-Enable addition of PO Number to order The ability to have a running purchase order sequence Test Plan: 1) Set systempreference EnablePONumber to Enable for auto generating purchase order number. 2) Select prefix for ex: Direct to requestor (Create PONUMPREFIX in authorized value and insert values). 3) Create an basket. 4) Create an order. 5) Select prefix value for ex: Direct to requestor. 6) Purchase order number will come in purchase order section for ex: DIR0000001. 7) Click on save button. --- C4/Acquisition.pm | 2 +- acqui/neworderempty.pl | 4 ++ acqui/poseqnextvalue.pl | 45 ++++++++++++++++++++ .../prog/en/modules/acqui/neworderempty.tt | 44 +++++++++++++++++++ .../en/modules/admin/preferences/acquisitions.pref | 6 +++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100755 acqui/poseqnextvalue.pl diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index ed9c215..e102326 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1210,7 +1210,7 @@ sub ModOrder { #See report 10110 and guided_reports.pl my $query = "UPDATE aqorders SET "; - foreach my $orderinfokey (grep(!/ordernumber/, keys %$orderinfo)){ + foreach my $orderinfokey (keys %$orderinfo){ # ... and skip hash entries that are not in the aqorders table # FIXME : probably not the best way to do it (would be better to have a correct hash) next unless grep(/^$orderinfokey$/, @$colnames); diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 9c9eed3..157761f 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -357,11 +357,15 @@ my @gst_values = map { option => $_ }, split( '\|', C4::Context->preference("gist") ); + $template->param( existing => $biblionumber, ordernumber => $ordernumber, # basket informations basketno => $basketno, + purchaseordernumber => $data->{purchaseordernumber}, + prefix => GetAuthorisedValues('PONUMPREFIX'), + enableponumber => C4::Context->preference('EnablePONumber'), basketname => $basket->{'basketname'}, basketnote => $basket->{'note'}, booksellerid => $basket->{'booksellerid'}, diff --git a/acqui/poseqnextvalue.pl b/acqui/poseqnextvalue.pl new file mode 100755 index 0000000..81b6183 --- /dev/null +++ b/acqui/poseqnextvalue.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright (C) 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 3 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, see . + +use strict; +use warnings; +use CGI; +use C4::Auth; +use C4::Output; +use JSON; + +my $input = new CGI; + +my $generateno = sprintf( "%0*d", "7", getnext() ); + +print $input->header('application/json'); +my $json = { generateno => $generateno, }; +my $json_text = to_json( $json, { utf8 => 1 } ); +print $json_text; + +sub getnext { + my $dbh = C4::Context->dbh; + # next two lines should be wrapped in a transaction + $dbh->do( +q{UPDATE po_sequence set seq_value = seq_value + 1 where seqid = 'POSEQ'} + ); + my @row = $dbh->selectrow_array( + q{SELECT seq_value from po_sequence where seqid = 'POSEQ'}); + return $row[0]; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index c261530..08d548e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -144,6 +144,24 @@ $(document).ready(function() }); //]]> + @@ -538,6 +556,32 @@ $(document).ready(function() + [% IF enableponumber %] + [% IF ( ordernumber ) %] +
  • + + +
  • + [% ELSE %] +
  • Select ordernumber prefix for auto-generated purchase order number.

  • +
  • + + [% IF prefix %] + + [% ELSE %] + No prefix authorized values found! Please create one or more authorized values with the category PONUMPREFIX. + [% END %] +
  • + + + + [% END %] + [% END %]
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index f74f991..4a1a6c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -42,6 +42,12 @@ Acquisitions: yes: Warn no: "Do not warn" - when the librarian tries to create an invoice with a duplicate number. + - + - pref: EnablePONumber + choices: + yes: Enable + no: Disable + - Enable purchase order number. Printing: - -- 1.7.9.5