Mongolian updates
[koha.git] / reports / issues_stats.pl
index 201c676..add5ad4 100755 (executable)
@@ -30,6 +30,7 @@ use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Output;
 use C4::Circulation;
+use C4::Reports;
 use C4::Dates qw/format_date format_date_in_iso/;
 use C4::Members;
 
@@ -60,7 +61,6 @@ my $calc     = $input->param("Cellvalue");
 my $output   = $input->param("output");
 my $basename = $input->param("basename");
 my $mime     = $input->param("MIME");
-my $del      = $input->param("sep");
 my ($template, $borrowernumber, $cookie) = get_template_and_user({
        template_name => $fullreportname,
        query => $input,
@@ -69,6 +69,8 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user({
        flagsrequired => {reports => 1},
        debug => 0,
 });
+our $sep     = $input->param("sep");
+$sep = "\t" if ($sep eq 'tabulation');
 $template->param(do_it => $do_it,
        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
 );
@@ -101,7 +103,6 @@ if ($do_it) {
                             -filename=>"$basename.csv" );
                my $cols  = @$results[0]->{loopcol};
                my $lines = @$results[0]->{looprow};
-               my $sep = C4::Context->preference("delimiter");
 # header top-right
                print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
 # Other header
@@ -132,23 +133,10 @@ my %select;
 
 # create itemtype arrayref for <select>.
 my @itemtypeloop;
-for my $itype ( keys(%$itemtypes)) {
+for my $itype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description}} keys(%$itemtypes)) {
        push @itemtypeloop, { code => $itype , description => $itemtypes->{$itype}->{description} } ;
 }
 
-my $branches=GetBranches();
-my @branchloop;
-foreach (keys %$branches) {
-       my $thisbranch = ''; # FIXME 
-       my %row = (
-               branchcode => $_,
-               selected => ($thisbranch eq $_ ? 1 : 0),
-               code => $branches->{$_}->{'branchcode'},
-               description => $branches->{$_}->{'branchname'},
-       );
-       push @branchloop, \%row;
-}
-
     # location list
 my @locations;
 foreach (sort keys %$locations) {
@@ -156,7 +144,7 @@ foreach (sort keys %$locations) {
 }
     
 my @ccodes;
-foreach (keys %$ccodes) {
+foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
        push @ccodes, { code => $_, description => $ccodes->{$_} };
 }
 
@@ -170,20 +158,14 @@ my $CGIextChoice=CGI::scrolling_list(
        -size     => 1,
        -multiple => 0 );
     
-my @dels = ( C4::Context->preference("delimiter") );
-my $CGIsepChoice=CGI::scrolling_list(
-       -name     => 'sep',
-       -id       => 'sep',
-       -values   => \@dels,
-       -size     => 1,
-       -multiple => 0 );
+my $CGIsepChoice=GetDelimiterChoices;
  
 $template->param(
        categoryloop => $categoryloop,
        itemtypeloop => \@itemtypeloop,
        locationloop => \@locations,
           ccodeloop => \@ccodes,
-         branchloop => \@branchloop,
+         branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
        hassort1=> $hassort1,
        hassort2=> $hassort2,
        Bsort1 => $Bsort1,
@@ -355,8 +337,8 @@ sub calculate {
        } else {
                $colfield = $column;
        }
-       $colorder = ($colfield =~ /dayname/) ? "weekday($line)" :
-                               ($colfield =~ /^month/ ) ? "  month($line)" : $colfield;
+       $colorder = ($colfield =~ /dayname/) ? "weekday($column)" :
+                               ($colfield =~ /^month/ ) ? "  month($column)" : $colfield;
        my $strsth2 = "SELECT distinctrow $colfield FROM statistics, ";
        # get stats on items if ccode or location, otherwise borrowers.
        $strsth2 .= ($colsource eq 'items' ) ?