From 67d4ed2b5a1a333b7b3c551ae1a3120242537f5c Mon Sep 17 00:00:00 2001 From: Maxime Pelletier Date: Mon, 14 May 2012 14:07:24 -0400 Subject: [PATCH] Bug 8612 New syspref to configure fields for the basket export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New syspref to configure fields for the basket export --- C4/Acquisition.pm | 45 +++++++++---------- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++ .../en/modules/admin/preferences/acquisitions.pref | 4 ++ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 2e3fb00..44e10e5 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -237,40 +237,37 @@ sub GetBasketAsCSV { my $csv = Text::CSV->new(); my $output; + my $fields = C4::Context->preference("BasketExportFields"); + my @fields = split(/,/, $fields); + # TODO: Translate headers - my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp); + my @headers = 'contractname'; + push @headers, @fields; - $csv->combine(@headers); - $output = $csv->string() . "\n"; + $csv->combine(@headers); + $output = $csv->string() . "\n"; my @rows; foreach my $order (@orders) { - my @cols; - # newlines are not valid characters for Text::CSV combine() + my @cols; + # newlines are not valid characters for Text::CSV combine() $order->{'notes'} =~ s/[\r\n]+//g; - push(@cols, - $contract->{'contractname'}, - $order->{'ordernumber'}, - $order->{'entrydate'}, - $order->{'isbn'}, - $order->{'author'}, - $order->{'title'}, - $order->{'publishercode'}, - $order->{'collectiontitle'}, - $order->{'notes'}, - $order->{'quantity'}, - $order->{'rrp'}, - ); - push (@rows, \@cols); + push(@cols, $contract->{'contractname'}); + foreach my $fieldName (@fields) { #Add value from orders for each fields set in the sysprefs + #Strip trailing and ending whitespaces + $fieldName =~ s/^\s+//; + $fieldName =~ s/\s+$//; + push @cols, $order->{$fieldName}; + } + push (@rows, \@cols); } foreach my $row (@rows) { - $csv->combine(@$row); - $output .= $csv->string() . "\n"; - + $csv->combine(@$row); + $output .= $csv->string() . "\n"; } - - return $output; + + return $output; } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 05a3261..000391d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -365,3 +365,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsIntranet', '1', NULL , 'Allow holds to be suspended from the intranet.', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SuspendHoldsOpac', '1', NULL , 'Allow holds to be suspended from the OPAC.', 'YesNo'); +INSERT INTO systempreferences (variable, value) VALUES ('BasketExportFields', 'ordernumber,entrydate,isbn,author,title,publishercode,collectiontitle,notes,quantity,rrp'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 2d4d2ab..4850c2e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5249,6 +5249,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = 'XXX'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable, value) VALUES ('BasketExportFields', 'ordernumber,entrydate,isbn,author,title,publishercode,collectiontitle,notes,quantity,rrp');"); + print "Upgrade to $DBversion done (Add BasketExportFields syspref)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 ebae997..a5a32a1 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 @@ -19,6 +19,10 @@ Acquisitions: 1: always ask for confirmation. 2: do not ask for confirmation. - + - Fields shown when exporting a basket. Fields from these tables are allowed : biblio, biblioitems, aqorders and aqbudgets + - pref: BasketExportFields + class: multi + - - Show baskets - pref: AcqViewBaskets choices: -- 1.7.2.5