From afc590c45e982e6b91300d929fe385ce2f7d6857 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Wed, 29 Feb 2012 16:52:13 +0100
Subject: [PATCH 1/1] Bug 7298: Followup rename export scripts

And replace the export lick with a new button
---
 acqui/lateorders-excel.pl                          |   65 ----------
 acqui/lateorders-export.pl                         |   65 ++++++++++
 acqui/lateorders.pl                                |    5 +-
 .../prog/en/modules/acqui/lateorders.tt            |   15 ++-
 .../prog/en/modules/serials/claims.tt              |    4 +-
 serials/lateissues-excel.pl                        |  130 --------------------
 serials/lateissues-export.pl                       |  130 ++++++++++++++++++++
 7 files changed, 209 insertions(+), 205 deletions(-)
 delete mode 100755 acqui/lateorders-excel.pl
 create mode 100755 acqui/lateorders-export.pl
 delete mode 100755 serials/lateissues-excel.pl
 create mode 100755 serials/lateissues-export.pl

diff --git a/acqui/lateorders-excel.pl b/acqui/lateorders-excel.pl
deleted file mode 100755
index 253ec78..0000000
--- a/acqui/lateorders-excel.pl
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-use CGI;
-use C4::Auth;
-use C4::Serials;
-use C4::Acquisition;
-use C4::Output;
-use C4::Context;
-
-use Text::CSV::Encoded;
-use open qw/ :std :utf8 /;
-
-my $csv = Text::CSV::Encoded->new ({
-        encoding    => undef,
-        quote_char  => '"',
-        escape_char => '"',
-        sep_char    => ',',
-        binary      => 1,
-    });
-
-my $query        = new CGI;
-my @ordernumbers = $query->param('ordernumber');
-
-print $query->header(
-    -type       => 'text/csv',
-    -attachment => "lateorders.csv",
-);
-
-print "LATE ORDERS\n\n";
-print "ORDER DATE,ESTIMATED DELIVERY DATE,VENDOR,INFORMATION,TOTAL COST,BASKET,CLAIMS COUNT,CLAIMED DATE\n";
-
-for my $ordernumber ( @ordernumbers ) {
-    my $order = GetOrder $ordernumber;
-    $csv->combine(
-        "(" . $$order{supplierid} . ") " . $$order{orderdate} . " (" . $$order{latesince} . " days)",
-        $$order{estimateddeliverydate},
-        $$order{supplier},
-        $$order{title} . ( $$order{author} ? " Author: $$order{author}" : "" ) . ( $$order{publisher} ? " Published by: $$order{publisher}" : "" ),
-        $$order{unitpricesupplier} . "x" . $$order{quantity} . " = " . $$order{subtotal} . " (" . $$order{budget} . ")",
-        $$order{basketname} . " (" . $$order{basketno} . ")",
-        $$order{claims_count},
-        $$order{claimed_date}
-    );
-    my $string = $csv->string;
-    print $string, "\n";
-}
-
-print ",,Total Number Late, " . scalar @ordernumbers . "\n";
-
diff --git a/acqui/lateorders-export.pl b/acqui/lateorders-export.pl
new file mode 100755
index 0000000..253ec78
--- /dev/null
+++ b/acqui/lateorders-export.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use CGI;
+use C4::Auth;
+use C4::Serials;
+use C4::Acquisition;
+use C4::Output;
+use C4::Context;
+
+use Text::CSV::Encoded;
+use open qw/ :std :utf8 /;
+
+my $csv = Text::CSV::Encoded->new ({
+        encoding    => undef,
+        quote_char  => '"',
+        escape_char => '"',
+        sep_char    => ',',
+        binary      => 1,
+    });
+
+my $query        = new CGI;
+my @ordernumbers = $query->param('ordernumber');
+
+print $query->header(
+    -type       => 'text/csv',
+    -attachment => "lateorders.csv",
+);
+
+print "LATE ORDERS\n\n";
+print "ORDER DATE,ESTIMATED DELIVERY DATE,VENDOR,INFORMATION,TOTAL COST,BASKET,CLAIMS COUNT,CLAIMED DATE\n";
+
+for my $ordernumber ( @ordernumbers ) {
+    my $order = GetOrder $ordernumber;
+    $csv->combine(
+        "(" . $$order{supplierid} . ") " . $$order{orderdate} . " (" . $$order{latesince} . " days)",
+        $$order{estimateddeliverydate},
+        $$order{supplier},
+        $$order{title} . ( $$order{author} ? " Author: $$order{author}" : "" ) . ( $$order{publisher} ? " Published by: $$order{publisher}" : "" ),
+        $$order{unitpricesupplier} . "x" . $$order{quantity} . " = " . $$order{subtotal} . " (" . $$order{budget} . ")",
+        $$order{basketname} . " (" . $$order{basketno} . ")",
+        $$order{claims_count},
+        $$order{claimed_date}
+    );
+    my $string = $csv->string;
+    print $string, "\n";
+}
+
+print ",,Total Number Late, " . scalar @ordernumbers . "\n";
+
diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl
index cf5a107..66d40e8 100755
--- a/acqui/lateorders.pl
+++ b/acqui/lateorders.pl
@@ -81,8 +81,11 @@ if ($op and $op eq "send_alert"){
     my $err;
     eval {
         $err = SendAlerts( 'claimacquisition', \@ordernums, $input->param("letter_code") );    # FIXME: Fallback value?
-        AddClaim ( $_ ) for @ordernums;
+        if ( not $err ) {
+            AddClaim ( $_ ) for @ordernums
+        }
     };
+
     if ( $@ ) {
         $template->param(error_claim => $@);
     } elsif ( defined $err->{error} and $err->{error} eq "no_email" ) {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
index 5ec0e09..0da7b50 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt
@@ -14,8 +14,6 @@ $(document).ready(function() {
         }
     });
 
-    $("span.exportSelected").html("<a id=\"ExportSelected\" href=\"/cgi-bin/koha/acqui/lateorders.pl\"> "+_("Export selected items data") +"<\/a>");
-
     $('#CheckAll').click(function(){ $("#late_orders td").checkCheckboxes();});
     $('#CheckNone').click(function(){ $("#late_orders td").unCheckCheckboxes();});
 
@@ -29,7 +27,7 @@ $(document).ready(function() {
         }
 
         // Building the url from currently checked boxes
-        var url = '/cgi-bin/koha/acqui/lateorders-excel.pl?op=export';
+        var url = '/cgi-bin/koha/acqui/lateorders-export.pl?op=export';
         for (var i = 0; i < selected.length; i++) {
             url += '&amp;ordernumber=' + selected[i].value;
         }
@@ -146,10 +144,13 @@ $(document).ready(function() {
         </tfoot>
     </table>
     <div class="spacer"></div>
-    <p style="display:block;"><span class="exportSelected"></span></p>
-    [% UNLESS lateorder.budget_lock %]
-        <p style="display:block;"><input type="submit"  value="Claim Order" /></p>
-    [% END %]
+
+    <p style="display:block;">
+        <input type="button" value="Export as CSV" id="ExportSelected" />
+        [% UNLESS lateorder.budget_lock %]
+            <input type="submit"  value="Claim Order" />
+        [% END %]
+    </p>
 </form>
 [% ELSE %]<p>There are no late orders.</p>
 [% END %]
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 ceb1570..d663319 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt
@@ -42,7 +42,7 @@
 		}
 		
 		// Building the url from currently checked boxes
-		var url = '/cgi-bin/koha/serials/lateissues-excel.pl?supplierid=&amp;op=claims';
+		var url = '/cgi-bin/koha/serials/lateissues-export.pl?supplierid=&amp;op=claims';
 		for (var i = 0; i < selected.length; i++) {
 		    url += '&amp;serialid=' + selected[i].value;
 		}
@@ -312,7 +312,7 @@
                         [% missingissue.claimdate %]
                         </td>
                         <td>
-                            <a href="/cgi-bin/koha/serials/lateissues-excel.pl?supplierid=[% missingissue.supplieri %]&amp;serialid=[% missingissue.serialid %]&amp;op=claims">Export item data</a>
+                            <a href="/cgi-bin/koha/serials/lateissues-export.pl?supplierid=[% missingissue.supplieri %]&amp;serialid=[% missingissue.serialid %]&amp;op=claims">Export item data</a>
                         </td>
                     </tr>
                 [% END %]</tbody>
diff --git a/serials/lateissues-excel.pl b/serials/lateissues-excel.pl
deleted file mode 100755
index e5cc849..0000000
--- a/serials/lateissues-excel.pl
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# 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 CGI;
-use C4::Auth;
-use C4::Serials;
-use C4::Acquisition;
-use C4::Output;
-use C4::Context;
-
-# 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 $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 $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);
-    }
-    $totalcount2 += scalar @missingissues;
-    # update claim date to let one know they have looked at this missing item
-    updateClaim($serialid[$k]);
-}
-
-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'}";
-    }
-}
-
-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";
-
-    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){
-
-} else {
-    print ",,Total Number Missing, $totalcount2\n";
-}
diff --git a/serials/lateissues-export.pl b/serials/lateissues-export.pl
new file mode 100755
index 0000000..e5cc849
--- /dev/null
+++ b/serials/lateissues-export.pl
@@ -0,0 +1,130 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# 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 CGI;
+use C4::Auth;
+use C4::Serials;
+use C4::Acquisition;
+use C4::Output;
+use C4::Context;
+
+# 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 $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 $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);
+    }
+    $totalcount2 += scalar @missingissues;
+    # update claim date to let one know they have looked at this missing item
+    updateClaim($serialid[$k]);
+}
+
+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'}";
+    }
+}
+
+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";
+
+    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){
+
+} else {
+    print ",,Total Number Missing, $totalcount2\n";
+}
-- 
1.7.7.3