From 4ac11bddfc95311306877abdcd124672b34fe340 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 10 Sep 2013 15:24:07 +0200 Subject: [PATCH] Bug 10854: Export serial claims with a csv profile. Test plan: - Create a csv profile (or use the default one) with a type 'sql'. - Go to serials/claims.pl, select the wanted csv profile and click on the "Export selected items data". - Verify the csv file is correctly generated. --- installer/data/mysql/en/optional/csv_profiles.sql | 1 + installer/data/mysql/en/optional/csv_profiles.txt | 3 + installer/data/mysql/updatedatabase.pl | 24 ++++ .../prog/en/modules/serials/claims.tt | 15 ++- serials/claims.pl | 2 + serials/lateissues-excel.pl | 134 +++++++------------- 6 files changed, 87 insertions(+), 92 deletions(-) create mode 100644 installer/data/mysql/en/optional/csv_profiles.sql create mode 100644 installer/data/mysql/en/optional/csv_profiles.txt diff --git a/installer/data/mysql/en/optional/csv_profiles.sql b/installer/data/mysql/en/optional/csv_profiles.sql new file mode 100644 index 0000000..234414a --- /dev/null +++ b/installer/data/mysql/en/optional/csv_profiles.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO export_format( profile, description, content, csv_separator, type ) VALUES ( "issues claims", "default csv export for issues claims", "SUPPLIER=aqbooksellers.name|TITLE=subscription.title|ISSUE NUMBER=serial.serialseq|LATE SINCE=serial.planneddate", ";", "sql" ); diff --git a/installer/data/mysql/en/optional/csv_profiles.txt b/installer/data/mysql/en/optional/csv_profiles.txt new file mode 100644 index 0000000..44da487 --- /dev/null +++ b/installer/data/mysql/en/optional/csv_profiles.txt @@ -0,0 +1,3 @@ +csv profiles + +issues claims: Bug XXXXX allow to choose a csv profile for exporting claims. This profile is the default one. diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index eafdbd9..6f0543a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7123,6 +7123,30 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } + + + + + + + + + + + + + +$DBversion = "3.13.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(q{ + INSERT IGNORE INTO export_format( profile, description, content, csv_separator, type ) VALUES ( "issues claims", "default csv export for issues claims", "SUPPLIER=aqbooksellers.name|TITLE=subscription.title|ISSUE NUMBER=serial.serial + }); + print "Upgrade to $DBversion done (Bug 10854: Add the default csv profile for claiming issues)\n"; + SetVersion($DBversion); +} + + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt index 7528e9a..3316878 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt @@ -25,7 +25,6 @@ // Checkboxes : Select All / None $("span.checkall").html(" "+_("Check All")+""); - $("span.exportSelected").html(" "+_("Export selected items data") +"<\/a>"); $("#CheckAll").click(function() { $("#claimst tr:visible :checkbox").attr('checked', $("#CheckAll").is(':checked')); @@ -46,6 +45,7 @@ for (var i = 0; i < selected.length; i++) { url += '&serialid=' + selected[i].value; } + url += '&csv_profile=' + $("#csv_profile_for_export option:selected").val(); // And redirecting to the CSV page location.href = url; return false; @@ -300,7 +300,18 @@ [% END %] -

+ + [% IF csv_profiles %] +

+ Export selected items data + using the following csv profile: + +

+ [% END %] [% IF ( letter ) %]
diff --git a/serials/claims.pl b/serials/claims.pl index 5434b2a..5377478 100755 --- a/serials/claims.pl +++ b/serials/claims.pl @@ -28,6 +28,7 @@ use C4::Bookseller qw( GetBookSeller ); use C4::Context; use C4::Letters; use C4::Branch; # GetBranches GetBranchesLoop +use C4::Csv qw( GetCsvProfiles ); my $input = CGI->new; @@ -98,6 +99,7 @@ $template->param( claimletter => $claimletter, supplierloop => \@supplierinfo, branchloop => $branchloop, + csv_profiles => C4::Csv::GetCsvProfiles( "sql" ), (uc(C4::Context->preference("marcflavour"))) => 1 ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/serials/lateissues-excel.pl b/serials/lateissues-excel.pl index e5cc849..4103d3b 100755 --- a/serials/lateissues-excel.pl +++ b/serials/lateissues-excel.pl @@ -15,116 +15,70 @@ # 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 Modern::Perl; use CGI; use C4::Auth; use C4::Serials; use C4::Acquisition; use C4::Output; use C4::Context; +use C4::Csv qw( GetCsvProfile ); -# use Date::Manip; use Text::CSV_XS; - -# &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005 - - -my $csv = Text::CSV_XS->new( - { - 'quote_char' => '"', - 'escape_char' => '"', - 'sep_char' => ',', - 'binary' => 1 - } - ); - - my $query = new CGI; my $supplierid = $query->param('supplierid'); -my @serialid = $query->param('serialid'); +my @serialids = $query->param('serialid'); my $op = $query->param('op') || q{}; -my $serialidcount = @serialid; -my @loop1; -my @lateissues; -if($op ne 'claims'){ - @lateissues = GetLateIssues($supplierid); - for my $issue (@lateissues){ - push @loop1, - [ $issue->{'name'}, $issue->{'title'}, $issue->{'serialseq'}, $issue->{'planneddate'},]; - } +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 $content = $csv_profile->{content}; +my ( @headers, @fields ); +while ( $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 $totalcount2 = 0; -my @loop2; -my @missingissues; -for (my $k=0;$k<@serialid;$k++){ - @missingissues = GetLateOrMissingIssues($supplierid, $serialid[$k]); - for (my $j=0;$j<@missingissues;$j++){ - my @rows2 = ($missingissues[$j]->{'name'}, # lets build up a row - $missingissues[$j]->{'title'}, - $missingissues[$j]->{'serialseq'}, - $missingissues[$j]->{'planneddate'}, - ); - push (@loop2, \@rows2); +my @rows; +for my $serialid ( @serialids ) { + my @missingissues = GetLateOrMissingIssues($supplierid, $serialid); + my $issue = $missingissues[0]; + my @row; + for my $field ( @fields ) { + push @row, $issue->{$field}; } - $totalcount2 += scalar @missingissues; - # update claim date to let one know they have looked at this missing item - updateClaim($serialid[$k]); -} + push @rows, \@row; -my $heading =''; -my $filename =''; -if($supplierid){ - if($missingissues[0]->{'name'}){ # if exists display supplier name in heading for neatness - # not necessarily needed as the name will appear in supplier column also - $heading = "FOR $missingissues[0]->{'name'}"; - $filename = "_$missingissues[0]->{'name'}"; - } + # update claim date to let one know they have looked at this missing item + updateClaim($serialid); } print $query->header( - -type => 'application/vnd.ms-excel', - -attachment => "claims".$filename.".csv", - ); - -if($op ne 'claims'){ - print "LATE ISSUES ".$heading."\n\n"; - print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n"; + -type => 'plain/text', + -attachment => "serials-claims.csv", +); - for my $row ( @loop1 ) { - - $csv->combine(@$row); - my $string = $csv->string; - print $string, "\n"; - } - - print ",,,,,,,\n\n"; -} -if($serialidcount == 1){ - print "MISSING ISSUE ".$heading."\n\n"; -} else { - print "MISSING ISSUES ".$heading."\n\n"; -} -print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n"; - -for my $row ( @loop2 ) { - - $csv->combine(@$row); - my $string = $csv->string; - print $string, "\n"; - } - -print ",,,,,,,\n"; -print ",,,,,,,\n"; -if($op ne 'claims'){ - my $count = scalar @lateissues; - print ",,Total Number Late, $count\n"; -} -if($serialidcount == 1){ +print join( $csv_profile->{csv_separator}, @headers ) . "\n"; -} else { - print ",,Total Number Missing, $totalcount2\n"; +for my $row ( @rows ) { + $csv->combine(@$row); + my $string = $csv->string; + print $string, "\n"; } -- 1.7.10.4