Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 119 lines (97 sloc) 2.877 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#!/usr/bin/env perl

use strict;
use warnings;
use CGI;
use C4::Auth;
use C4::Serials;
use C4::Acquisition;
use C4::Output;
use Koha;
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 %supplierlist = GetSuppliersWithLateIssues;
my @select_supplier;

my @loop1;
my ($count, @lateissues);
if($op ne 'claims'){
    ($count, @lateissues) = GetLateIssues($supplierid);
    for my $issue (@lateissues){
        push @loop1,
      [ $issue->{'name'}, $issue->{'title'}, $issue->{'serialseq'}, $issue->{'planneddate'},];
    }
}
my $totalcount2 = 0;
my @loop2;
my ($count2, @missingissues);
for (my $k=0;$k<@serialid;$k++){
    ($count2, @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 = $totalcount2 + $count2;
    # 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'){
    print ",,Total Number Late, $count\n";
}
if($serialidcount == 1){

} else {
    print ",,Total Number Missing, $totalcount2\n";
}
Something went wrong with that request. Please try again.