From 0bbfc9b6dda23a19b5c4c391776f10b7d3405832 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Tue, 13 Aug 2013 10:37:57 +0530 Subject: [PATCH] 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 ++++++++++++++++++++ installer/data/mysql/kohastructure.sql | 12 ++++++ installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 9 ++++ .../prog/en/modules/acqui/neworderempty.tt | 44 +++++++++++++++++++ .../en/modules/admin/preferences/acquisitions.pref | 6 +++ 8 files changed, 123 insertions(+), 1 deletion(-) create mode 100755 acqui/poseqnextvalue.pl diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 1a210b5..d40d517 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1207,7 +1207,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..7e089ac --- /dev/null +++ b/acqui/poseqnextvalue.pl @@ -0,0 +1,45 @@ +#!/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. + +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/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 8a8b70f..f3b68dd 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3214,6 +3214,18 @@ CREATE TABLE IF NOT EXISTS plugin_data ( PRIMARY KEY (plugin_class,plugin_key) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Table structure for table 'po_sequence' +-- + +CREATE TABLE IF NOT EXISTS po_sequence ( + seqid varchar(10) PRIMARY KEY, + seq_value bigint(20) unsigned NOT NULL, + PRIMARY KEY (seqid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index c8caee7..d055e1d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -430,3 +430,5 @@ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) V INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AcqWarnOnDuplicateInvoice','0','Warn librarians when they try to create a duplicate invoice', '', 'YesNo'); INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('AllowTooManyOverride', '1', 'If on, allow staff to override and check out items when the patron has reached the maximum number of allowed checkouts', '', 'YesNo'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('EnablePONumber',0,'Enable purchase order number',NULL,'YesNo'); + diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 74aeb3e..6403b4d 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7067,6 +7067,15 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('EnablePONumber',0,'Enable purchase order number',NULL,'YesNo')"); + $dbh->do("CREATE TABLE IF NOT EXISTS po_sequence (seqid varchar(10) PRIMARY KEY, seq_value bigint(20) unsigned NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;") + $dbh->do(q|INSERT INTO po_sequence values( 'POSEQ', 1)|); + print "Upgrade to $DBversion done (Bug 4456 - Add systempreferences to enabling purchaseordernumber and create new table po_sequence)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 52def80..91e9ef4 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