Bugzilla – Attachment 58075 Details for
Bug 8612
CSV export profile to have custom fields in export csv basket
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8612 - Clean basket.pl getting rid of subroutines with sql query and use GetBasketAsCSV instead
Bug-8612---Clean-basketpl-getting-rid-of-subroutin.patch (text/plain), 9.20 KB, created by
Josef Moravec
on 2016-12-09 13:28:51 UTC
(
hide
)
Description:
Bug 8612 - Clean basket.pl getting rid of subroutines with sql query and use GetBasketAsCSV instead
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-12-09 13:28:51 UTC
Size:
9.20 KB
patch
obsolete
>From 083bfba7fa11b550c3a82e50638afe27dc6dc45b Mon Sep 17 00:00:00 2001 >From: genevieve <genevieve.plantin@inlibro.com> >Date: Mon, 14 Sep 2015 14:02:38 -0400 >Subject: [PATCH] Bug 8612 - Clean basket.pl getting rid of subroutines with > sql query and use GetBasketAsCSV instead > >GetBasketAsCSV now has a new argument the profile_csv_id, when this param is defined, it loads the profile_content, searches the value of the predefined fields and assembles the data to create the output of the csv file. > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > C4/Acquisition.pm | 115 +++++++++++++++++++++++++++++++++++++----------------- > acqui/basket.pl | 72 +--------------------------------- > 2 files changed, 81 insertions(+), 106 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 6ad5ff7..aec8425 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -276,7 +276,7 @@ $cgi parameter is needed for column name translation > =cut > > sub GetBasketAsCSV { >- my ($basketno, $cgi) = @_; >+ my ($basketno, $cgi, $csv_profile_id) = @_; > my $basket = GetBasket($basketno); > my @orders = GetOrders($basketno); > my $contract = GetContract({ >@@ -284,48 +284,93 @@ sub GetBasketAsCSV { > }); > > my $template = C4::Templates::gettemplate("acqui/csv/basket.tt", "intranet", $cgi); >- > my @rows; >- foreach my $order (@orders) { >- my $bd = GetBiblioData( $order->{'biblionumber'} ); >- my $row = { >- contractname => $contract->{'contractname'}, >- ordernumber => $order->{'ordernumber'}, >- entrydate => $order->{'entrydate'}, >- isbn => $order->{'isbn'}, >- author => $bd->{'author'}, >- title => $bd->{'title'}, >- publicationyear => $bd->{'publicationyear'}, >- publishercode => $bd->{'publishercode'}, >- collectiontitle => $bd->{'collectiontitle'}, >- notes => $order->{'order_vendornote'}, >- quantity => $order->{'quantity'}, >- rrp => $order->{'rrp'}, >- }; >- for my $place ( qw( deliveryplace billingplace ) ) { >- if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) { >- $row->{$place} = $library->branchname >+ if ($csv_profile_id) { >+ my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id ); >+ die "There is no valid csv profile given" unless $csv_profile; >+ >+ my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1}); >+ my $csv_profile_content = $csv_profile->{content}; >+ my ( @headers, @fields ); >+ while ( $csv_profile_content =~ / >+ ([^=]+) # header >+ = >+ ([^\|]+) # fieldname (table.row or row) >+ \|? /gxms >+ ) { >+ push @headers, $1; >+ my $field = $2; >+ $field =~ s/[^\.]*\.?//; # Remove the table name if exists. >+ push @fields, $field; >+ } >+ for my $order (@orders) { >+ my @row; >+ my $bd = GetBiblioData( $order->{'biblionumber'} ); >+ my @biblioitems = GetBiblioItemByBiblioNumber( $order->{'biblionumber'}); >+ for my $biblioitem (@biblioitems) { >+ if ($biblioitem->{isbn} eq $order->{isbn}) { >+ $order = {%$order, %$biblioitem}; >+ } >+ } >+ if ($contract) { >+ $order = {%$order, %$contract}; >+ } >+ $order = {%$order, %$basket, %$bd}; >+ for my $field (@fields) { >+ push @row, $order->{$field}; > } >+ push @rows, \@row; > } >- foreach(qw( >- contractname author title publishercode collectiontitle notes >- deliveryplace billingplace >- ) ) { >- # Double the quotes to not be interpreted as a field end >- $row->{$_} =~ s/"/""/g if $row->{$_}; >+ my $content = join( $csv_profile->{csv_separator}, @headers ) . "\n"; >+ for my $row ( @rows ) { >+ $csv->combine(@$row); >+ my $string = $csv->string; >+ $content .= $string . "\n"; > } >- push @rows, $row; >+ return $content; > } >+ else { >+ foreach my $order (@orders) { >+ my $bd = GetBiblioData( $order->{'biblionumber'} ); >+ my $row = { >+ contractname => $contract->{'contractname'}, >+ ordernumber => $order->{'ordernumber'}, >+ entrydate => $order->{'entrydate'}, >+ isbn => $order->{'isbn'}, >+ author => $bd->{'author'}, >+ title => $bd->{'title'}, >+ publicationyear => $bd->{'publicationyear'}, >+ publishercode => $bd->{'publishercode'}, >+ collectiontitle => $bd->{'collectiontitle'}, >+ notes => $order->{'order_vendornote'}, >+ quantity => $order->{'quantity'}, >+ rrp => $order->{'rrp'}, >+ }; >+ for my $place ( qw( deliveryplace billingplace ) ) { >+ if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) { >+ $row->{$place} = $library->branchname >+ } >+ } >+ foreach(qw( >+ contractname author title publishercode collectiontitle notes >+ deliveryplace billingplace >+ ) ) { >+ # Double the quotes to not be interpreted as a field end >+ $row->{$_} =~ s/"/""/g if $row->{$_}; >+ } >+ push @rows, $row; >+ } > >- @rows = sort { >- if(defined $a->{publishercode} and defined $b->{publishercode}) { >- $a->{publishercode} cmp $b->{publishercode}; >- } >- } @rows; >+ @rows = sort { >+ if(defined $a->{publishercode} and defined $b->{publishercode}) { >+ $a->{publishercode} cmp $b->{publishercode}; >+ } >+ } @rows; > >- $template->param(rows => \@rows); >+ $template->param(rows => \@rows); > >- return $template->output; >+ return $template->output; >+ } > } > > >diff --git a/acqui/basket.pl b/acqui/basket.pl >index eec3058..f5739e2 100755 >--- a/acqui/basket.pl >+++ b/acqui/basket.pl >@@ -167,21 +167,7 @@ if ( $op eq 'delete_confirm' ) { > print GetBasketAsCSV($query->param('basketno'), $query); > } else { > my $csv_profile_id = $query->param('csv_profile'); >- my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id ); >- die "There is no valid csv profile given" unless $csv_profile; >- >- my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->{csv_separator},'binary'=>1}); >- my $csv_profile_content = $csv_profile->{content}; >- >- my $basket_info = get_basket_csv_profile_info($csv_profile_content, $query->param('basketno')); >- >- print join( $csv_profile->{csv_separator}, @{$basket_info->{headers}} ) . "\n"; >- >- for my $row ( @{$basket_info->{rows}} ) { >- $csv->combine(@$row); >- my $string = $csv->string; >- print $string, "\n"; >- } >+ print GetBasketAsCSV($query->param('basketno'), $query, $csv_profile_id); > } > exit; > } elsif ($op eq 'email') { >@@ -525,62 +511,6 @@ sub get_order_infos { > return \%line; > } > >-sub get_basket_DB_info{ >- my ( $basketno ) = @_; >- return () unless $basketno; >- my $dbh = C4::Context->dbh; >- my $query =" >- SELECT biblio.*,biblioitems.*, aqbasket.*,aqcontract.*, >- aqorders.*, >- aqbudgets.* >- FROM aqorders >- LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno >- LEFT JOIN aqcontract ON aqbasket.contractnumber = aqcontract.contractnumber >- LEFT JOIN aqbudgets ON aqbudgets.budget_id = aqorders.budget_id >- LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber >- LEFT JOIN biblioitems ON biblioitems.biblionumber =biblio.biblionumber >- WHERE aqorders.basketno=? >- AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00') >- ORDER BY biblioitems.publishercode,biblio.title >- "; >- my $result_set = >- $dbh->selectall_arrayref( $query, { Slice => {} }, $basketno ); >- return @{$result_set}; >-} >- >-sub get_basket_csv_profile_info{ >- my ($csv_profile_content,$basketno) = @_; >- >- my ( @headers, @fields ); >- while ( $csv_profile_content =~ / >- ([^=]+) # header >- = >- ([^\|]+) # fieldname (table.row or row) >- \|? /gxms >- ) { >- push @headers, $1; >- my $field = $2; >- $field =~ s/[^\.]*\.?//; # Remove the table name if exists. >- push @fields, $field; >- } >- >- my @rows; >- my @basket_info = get_basket_DB_info($basketno); >- >- for my $basket_info ( @basket_info ) { >- my @row; >- for my $field ( @fields ) { >- push @row, $basket_info->{$field}; >- } >- push @rows, \@row; >- } >- my $hash_ref; >- $hash_ref->{ 'headers' } = \@headers; >- $hash_ref->{ 'rows' } = \@rows; >- >- return $hash_ref; >-} >- > sub edi_close_and_order { > my $confirm = $query->param('confirm') || $confirm_pref eq '2'; > if ($confirm) { >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8612
:
11514
|
36860
|
37289
|
37293
|
41224
|
41225
|
41226
|
41227
|
42532
|
42533
|
42534
|
47591
|
47592
|
47593
|
56222
|
56223
|
56224
|
56225
|
57012
|
57013
|
57024
|
57025
|
57026
|
57027
|
57028
|
57029
|
57079
|
58073
|
58074
|
58075
|
58076
|
58077
|
58078
|
58079
|
58985
|
58986
|
58987
|
58988
|
58989
|
58990
|
58991
|
58992
|
59757
|
60480
|
61264
|
61265
|
61266
|
61267
|
61405
|
61520
|
63048
|
63049
|
63050
|
63051
|
63052
|
63053
|
63054
|
63055
|
63056
|
63104
|
63158
|
63279
|
63910
|
63911
|
63912
|
63913
|
63914
|
63915
|
63964
|
63966