Bugzilla – Attachment 21376 Details for
Bug 10854
Choose a CSV profile for exporting serial claims
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10854: Export serial claims with a csv profile.
Bug-10854-Export-serial-claims-with-a-csv-profile.patch (text/plain), 9.79 KB, created by
Jonathan Druart
on 2013-09-23 13:16:34 UTC
(
hide
)
Description:
Bug 10854: Export serial claims with a csv profile.
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2013-09-23 13:16:34 UTC
Size:
9.79 KB
patch
obsolete
>From 5ec8f4750e2cfa06844094f3ee170a1dbc2bb31e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >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 89aa61f..6e419e3 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7157,6 +7157,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.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 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("<input type=\"checkbox\" name=\"CheckAll\"> "+_("Check All")+"</input>"); >- $("span.exportSelected").html("<a id=\"ExportSelected\" href=\"/cgi-bin/koha/serials/claims.pl\"> "+_("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 @@ > </tr> > [% END %]</tbody> > </table> >- <p><span class="exportSelected"></span></p> >+ >+ [% IF csv_profiles %] >+ <p> >+ <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Export selected items data</a></span> >+ using the following csv profile: >+ <select id="csv_profile_for_export"> >+ [% FOR csv IN csv_profiles %] >+ <option value="[% csv.export_format_id %]">[% csv.profile %]</option> >+ [% END %] >+ </select> >+ </p> >+ [% END %] > > [% IF ( letter ) %] > <fieldset class="action"> <label for="letter_code">Select notice:</label> >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
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 10854
:
20957
|
21376
|
21402
|
21605
|
21607
|
21608
|
21609
|
21610
|
21654