From 383b2a75decf3395f1f27559a481b4b00d0c488b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 10 Sep 2013 15:24:07 +0200 Subject: [PATCH] Bug 10854: add ability to export serial claims using 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. Signed-off-by: Bernardo Gonzalez Kriegel Work as described. No koha-qa errors On top of 10853 (solving merge conflict) Need to do homework to test. Add subscription and serial claim notice. 1) Create a new CSV profile, type SQL, copy sample fields 2) Go to claims, select vendor 3) Go to Export selected items with created profile 4) CSV (in my case I use | as separator) download successfully 5) All fields present, file correct Signed-off-by: Katrin Fischer Passes all tests and QA script. Works as advertised, keeps existing format by porting it to a SQL profile. Signed-off-by: Galen Charlton --- .../data/mysql/en/optional/csv_profiles.sql | 1 + .../data/mysql/en/optional/csv_profiles.txt | 3 + installer/data/mysql/updatedatabase.pl | 24 ++++ .../prog/en/modules/serials/claims.tt | 21 ++- serials/claims.pl | 2 + serials/lateissues-excel.pl | 134 ++++++------------ 6 files changed, 88 insertions(+), 97 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 0000000000..ac427602f8 --- /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 to claim", "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 0000000000..af07c867e2 --- /dev/null +++ b/installer/data/mysql/en/optional/csv_profiles.txt @@ -0,0 +1,3 @@ +csv profiles + +issues to claim: Bug 10854 allows 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 566715eab2..4f3d17391c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7204,6 +7204,30 @@ if ( CheckVersion($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 to claim", "default csv export for issues claims", "SUPPLIER=aqbooksellers.name|TITLE=subscription.title|ISSUE NUMBER=serial.serialseq|LATE SINCE=serial.planneddate", ",", "sql" ) + }); + 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 1346b57812..b2b5c1ada5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt @@ -14,7 +14,7 @@ var sTable = $("#claimst").dataTable($.extend(true, {}, dataTablesDefaults, { "sDom": 't', "aoColumnDefs": [ - { "aTargets": [ 0,1,-1 ], "bSortable": false, "bSearchable": false } + { "aTargets": [ 0,1 ], "bSortable": false, "bSearchable": false } ], "bPaginate": false })); @@ -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; @@ -261,7 +261,6 @@ Status Since Claim date - Begin claim [% FOREACH missingissue IN missingissues %] @@ -294,13 +293,21 @@ [% missingissue.claimdate %] - - Export item data - [% 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 5434b2aea9..5377478ed1 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 e5cc8498d1..4103d3bfa7 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"; } -- 2.39.5