From cfdda911f958f90bfca8564673fb0208be4a657d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 7 Mar 2014 08:27:30 -0500 Subject: [PATCH] Bug 6427 [Part 22] - Remove unused scripts that reference previous accounts tables, references to old subroutines --- C4/Circulation.pm | 4 - circ/add_message.pl | 5 - circ/del_message.pl | 5 - circ/stats.pl | 189 -------------- .../prog/en/modules/circ/circulation-home.tt | 1 - .../intranet-tmpl/prog/en/modules/circ/stats.tt | 55 ---- .../prog/en/modules/reports/reports-home.tt | 1 - .../prog/en/modules/reports/stats_screen.tt | 131 ---------- offline_circ/enqueue_koc.pl | 1 - offline_circ/process_koc.pl | 12 +- reports/stats.print.pl | 178 ------------- reports/stats.screen.pl | 267 -------------------- 12 files changed, 9 insertions(+), 840 deletions(-) delete mode 100755 circ/stats.pl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/stats_screen.tt delete mode 100755 reports/stats.print.pl delete mode 100755 reports/stats.screen.pl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c968aa9..87dc731 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1981,10 +1981,6 @@ of the return. It is ignored when a dropbox_branch is passed in. C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, the old_issue is immediately anonymised -Ideally, this function would be internal to C, -not exported, but it is currently needed by one -routine in C. - =cut sub MarkIssueReturned { diff --git a/circ/add_message.pl b/circ/add_message.pl index 9c39dc9..1f34020 100755 --- a/circ/add_message.pl +++ b/circ/add_message.pl @@ -26,11 +26,6 @@ use C4::Context; use C4::Auth; use C4::Output; use C4::Members; -use C4::Accounts; -use C4::Stats; -use C4::Koha; -use C4::Overdues; -use C4::Branch; # GetBranches my $input = new CGI; diff --git a/circ/del_message.pl b/circ/del_message.pl index da13bdb..77745b2 100755 --- a/circ/del_message.pl +++ b/circ/del_message.pl @@ -26,11 +26,6 @@ use C4::Context; use C4::Auth; use C4::Output; use C4::Members; -use C4::Accounts; -use C4::Stats; -use C4::Koha; -use C4::Overdues; -use C4::Branch; # GetBranches my $input = new CGI; diff --git a/circ/stats.pl b/circ/stats.pl deleted file mode 100755 index 558a985..0000000 --- a/circ/stats.pl +++ /dev/null @@ -1,189 +0,0 @@ -#!/usr/bin/perl - - -#written 14/1/2000 -#script to display reports - -# Copyright 2000-2002 Katipo Communications -# -# 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; FIXME - Bug 2505 -use CGI; -use C4::Context; -use C4::Output; -use C4::Auth; -use Date::Manip; -use C4::Stats; -use C4::Debug; - -use vars qw($debug); - -my $input = new CGI; -my $time = $input->param('time') || ''; - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "circ/stats.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { reports => 1 }, - debug => 1, - } -); - -my $date; -my $date2; -if ( $time eq 'yesterday' ) { - $date = ParseDate('yesterday'); - $date2 = ParseDate('today'); -} -elsif ( $time eq 'today' ) { - $date = ParseDate('today'); - $date2 = ParseDate('tomorrow'); -} -elsif ( $time eq 'daybefore' ) { - $date = ParseDate('2 days ago'); - $date2 = ParseDate('yesterday'); -} -elsif ( $time eq 'month' ) { - $date = ParseDate('1 month ago'); - $date2 = ParseDate('today'); -} -elsif ( $time =~ /\// ) { - $date = ParseDate($time); - $date2 = ParseDateDelta('+ 1 day'); - $date2 = DateCalc( $date, $date2 ); -} else { - $template->param(notime => '1'); # TODO: add error feedback if time sent, but unrecognized - output_html_with_http_headers $input, $cookie, $template->output; - exit; -} - -$debug and warn "d : $date // d2 : $date2"; -$date = UnixDate( $date, '%Y-%m-%d' ); -$date2 = UnixDate( $date2, '%Y-%m-%d' ); -$debug and warn "d : $date // d2 : $date2"; -my @payments = TotalPaid( $date, $date2 ); -my $count = @payments; -my $total = 0; -my $totalw = 0; -my $oldtime; -my @loop; -my %row; -my $i = 0; - -while ( $i < $count ) { - $debug and warn " pay : " . $payments[$i]{'timestamp'}; - my $time = $payments[$i]{'datetime'}; - my $payments = $payments[$i]{'value'}; - my $charge = 0; - my @temp = split(/ /, $payments[$i]{'datetime'}); - my $date = $temp[0]; - my @charges = - getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} ); - my $count = @charges; - my $temptotalf = 0; - my $temptotalr = 0; - my $temptotalres = 0; - my $temptotalren = 0; - my $temptotalw = 0; - - # FIXME: way too much logic to live only here in a report script - for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) { - $charge += $charges[$i2]->{'amount'}; - %row = ( - name => $charges[$i2]->{'description'}, - type => $charges[$i2]->{'accounttype'}, - time => $charges[$i2]->{'timestamp'}, - amount => $charges[$i2]->{'amount'}, - branch => $charges[$i2]->{'amountoutstanding'} - ); - push( @loop, \%row ); - if ( $payments[$i]{'accountytpe'} ne 'W' ) { - if ( $charges[$i2]->{'accounttype'} eq 'Rent' ) { - $temptotalr += - $charges[$i2]->{'amount'} - - $charges[$i2]->{'amountoutstanding'}; - } - if ( $charges[$i2]->{'accounttype'} eq 'F' - || $charges[$i2]->{'accounttype'} eq 'FU' - || $charges[$i2]->{'accounttype'} eq 'FN' ) - { - $temptotalf += - $charges[$i2]->{'amount'} - - $charges[$i2]->{'amountoutstanding'}; - } - if ( $charges[$i2]->{'accounttype'} eq 'Res' ) { - $temptotalres += - $charges[$i2]->{'amount'} - - $charges[$i2]->{'amountoutstanding'}; - } - if ( $charges[$i2]->{'accounttype'} eq 'R' ) { - $temptotalren += - $charges[$i2]->{'amount'} - - $charges[$i2]->{'amountoutstanding'}; - } - } - } - my $time2 = $payments[$i]{'date'}; - my $branch = Getpaidbranch( $time2, $payments[$i]{'borrowernumber'} ); - my $borrowernumber = $payments[$i]{'borrowernumber'}; - my $oldtime = $payments[$i]{'timestamp'}; - my $oldtype = $payments[$i]{'accounttype'}; - - while ($borrowernumber eq $payments[$i]{'borrowernumber'} - && $oldtype == $payments[$i]{'accounttype'} - && $oldtime eq $payments[$i]{'timestamp'} ) - { - my $xtime2 = $payments[$i]{'date'}; - my $branch = Getpaidbranch( $xtime2, $payments[$i]{'borrowernumber'} ); - if ( $payments[$i]{'accounttype'} eq 'W' ) { - $totalw += $payments[$i]{'amount'}; - } - else { - $payments[$i]{'amount'} = $payments[$i]{'amount'} * -1; - $total += $payments[$i]{'amount'}; - } - - #FIXME: display layer HTML - %row = ( - name => "" - . $payments[$i]{'firstname'} - . $payments[$i]{'surname'} . "", - type => $payments[$i]{'accounttype'}, - time => $payments[$i]{'date'}, - amount => $payments[$i]{'amount'}, - branch => $branch - ); - push( @loop, \%row ); - $oldtype = $payments[$i]{'accounttype'}; - $oldtime = $payments[$i]{'timestamp'}; - $borrowernumber = $payments[$i]{'borrowernumber'}; - $i++; - } -} - -$template->param( - loop1 => \@loop, - totalw => $totalw, - total => $total -); - -output_html_with_http_headers $input, $cookie, $template->output; - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt index e5eaddc..6a58ae8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -45,7 +45,6 @@ - Warning: This report is very resource intensive on systems with large numbers of overdue items.[% END %]
  • Overdues with fines - Limited to your library. See report help for other details.
  • - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt deleted file mode 100644 index d62c1af..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/stats.tt +++ /dev/null @@ -1,55 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Circulation › Statistics -[% INCLUDE 'doc-head-close.inc' %] - - -[% INCLUDE 'header.inc' %] -[% INCLUDE 'circ-search.inc' %] - - - -
    - -
    -
    -
    - - [% IF ( notime ) %] -

    Display statistics for:

    -
      -
    • yesterday
    • -
    • today
    • - [% ELSE %] - [% IF ( loop1 ) %] - - - - - - - - - - [% FOREACH loop IN loop1 %] - - - - - - - - [% END %] -
      Statistics
      NameTypeDate/timeAmountLibrary
      [% loop.name %][% loop.type %][% loop.time %][% loop.amount %][% loop.branch %]
      -

      Total paid: [% total %]
      Total written off: [% totalw %]

      - [% ELSE %] -

      No statistics to report

      - [% END %] - - [% END %] -
    -
    -
    -[% INCLUDE 'circ-menu.inc' %] -
    -
    -[% INCLUDE 'intranet-bottom.inc' %] \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt index c7744fa..2197e10 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt @@ -65,7 +65,6 @@
  • Average loan time
  • Koha database schema
  • Koha reports library
  • -
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/stats_screen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/stats_screen.tt deleted file mode 100644 index df53367..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/stats_screen.tt +++ /dev/null @@ -1,131 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Reports › Till reconciliation -[% INCLUDE 'doc-head-close.inc' %] -[% INCLUDE 'calendar.inc' %] - - -[% INCLUDE 'header.inc' %] -[% INCLUDE 'circ-search.inc' %] - - -
    - -
    -
    -
    - -

    Till reconciliation

    - -
    Search between two dates -
    - - - - - -
    - - -

    Payments

    - - - - - - - - - - - - - - - [% FOREACH loop IN loop1 %] - - - - - - - - - - - - [% END %] -
    LibraryDate/timeSurnameFirst nameDescriptionCharge typeInvoice amountPayment typePayment amount
    [% loop.branch %][% loop.datetime %][% loop.surname %][% loop.firstname %][% loop.description %][% loop.accounttype %][% loop.amount %][% loop.type %][% loop.value %]
    - -

    - Total amount paid: [% totalpaid %] -

    - - -

    Credits

    - - - - - - - - - - - - - [% FOREACH loop IN loop2 %] - - - - - - - - - - [% END %] -
    LibraryDate/timeSurnameFirst nameDescriptionCharge typeInvoice amount
    [% loop.creditbranch %][% loop.creditdate %][% loop.creditsurname %][% loop.creditfirstname %][% loop.creditdescription %][% loop.creditaccounttype %][% loop.creditamount %]
    -

    -

    • Total amount credits: [% totalcredits %]
    • -
    • Total number written off: [% totalwritten %] charges
    -

    - - -

    Refunds

    - - - - - - - - - - - - - [% FOREACH loop IN loop3 %] - - - - - - - - - - [% END %] -
    LibraryDate/timeSurnameFirst nameDescriptionCharge typeInvoice amount
    [% loop.refundbranch %][% loop.refunddate %][% loop.refundsurname %][% loop.refundfirstname %][% loop.refunddescription %][% loop.refundaccounttype %][% loop.refundamount %]
    -

    -

    • Total amount refunds: [% totalrefund %]
    • -
    • Total amount of cash collected: [% totalcash %]
    -

    -
    -
    -
    -[% INCLUDE 'reports-menu.inc' %] -
    -
    -[% INCLUDE 'intranet-bottom.inc' %] diff --git a/offline_circ/enqueue_koc.pl b/offline_circ/enqueue_koc.pl index bfc1e35..f0eb0ce 100755 --- a/offline_circ/enqueue_koc.pl +++ b/offline_circ/enqueue_koc.pl @@ -27,7 +27,6 @@ use C4::Auth; use C4::Koha; use C4::Context; use C4::Biblio; -use C4::Accounts; use C4::Circulation; use C4::Items; use C4::Members; diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl index 75ff319..2753bdf 100755 --- a/offline_circ/process_koc.pl +++ b/offline_circ/process_koc.pl @@ -27,13 +27,14 @@ use C4::Auth; use C4::Koha; use C4::Context; use C4::Biblio; -use C4::Accounts; use C4::Circulation; use C4::Items; use C4::Members; use C4::Stats; use C4::UploadedFile; use C4::BackgroundJob; +use Koha::Accounts; +use Koha::Database; use Date::Calc qw( Add_Delta_Days Date_to_Days ); @@ -357,8 +358,13 @@ sub kocReturnItem { sub kocMakePayment { my ( $circ ) = @_; - my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } ); - recordpayment( $borrower->{'borrowernumber'}, $circ->{'amount'} ); + + my $borrower = + Koha::Database->new()->schema()->resultset('Borrower') + ->single( { cardnumber => $circ->{'cardnumber'} } ); + + AddCredit({ borrower => $borrower, amount => $circ->{'amount'} }); + push @output, { payment => 1, amount => $circ->{'amount'}, diff --git a/reports/stats.print.pl b/reports/stats.print.pl deleted file mode 100755 index 066aafa..0000000 --- a/reports/stats.print.pl +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/perl - -use strict; -#use warnings; FIXME - Bug 2505 -use CGI; -use C4::Output; - -use C4::Auth; -use C4::Context; -use Date::Manip; -use C4::Stats; -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 $input=new CGI; -my $time=$input->param('time'); -my $time2=$input->param('time2'); - -my @loop1; -my @loop2; -my $date; -my $date2; -if ($time eq 'yesterday'){ - $date=ParseDate('yesterday'); - $date2=ParseDate('today'); -} -if ($time eq 'today'){ - $date=ParseDate('today'); - $date2=ParseDate('tomorrow'); -} -if ($time eq 'daybefore'){ - $date=ParseDate('2 days ago'); - $date2=ParseDate('yesterday'); -} -if ($time eq 'month') { - $date = ParseDate('1 month ago'); - $date2 = ParseDate('today'); - -} -if ($time=~ /\//){ - $date=ParseDate($time); - $date2=ParseDateDelta('+ 1 day'); - $date2=DateCalc($date,$date2); -} - -if ($time eq ''){ - $date=ParseDate('today'); - $date2=ParseDate('tomorrow'); -} - -if ($time2 ne ''){ - $date=ParseDate($time); - $date2=ParseDate($time2); -} - -my $date=UnixDate($date,'%Y-%m-%d'); -my $date2=UnixDate($date2,'%Y-%m-%d'); - -#warn "MASON: DATE: $date, $date2"; - -#get a list of every payment -my @payments=TotalPaid($date,$date2); - -my $count=@payments; -# print "MASON: number of payments=$count\n"; - -my $i=0; -my $totalcharges=0; -my $totalcredits=0; -my $totalpaid=0; -my $totalwritten=0; - -# lets get a a list of all individual item charges paid for by that payment -while ($i<$count ){ - - my $count; - my @charges; - - if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!. - @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'}); - $totalcharges++; - $count=@charges; - - # getting each of the charges and putting them into a array to be printed out - #this loops per charge per person - for (my $i2=0;$i2<$count;$i2++){ - - my $hour=substr($payments[$i]{'timestamp'},8,2); - my $min=substr($payments[$i]{'timestamp'},10,2); - my $sec=substr($payments[$i]{'timestamp'},12,2); - my $time="$hour:$min:$sec"; - my $time2="$payments[$i]{'date'}"; -# my $branch=Getpaidbranch($time2,$payments[$i]{'borrowernumber'}); - my $branch=$payments[$i]{'branch'}; - - my @rows1 = ($branch, # lets build up a row - $payments[$i]->{'datetime'}, - $payments[$i]->{'surname'}, - $payments[$i]->{'firstname'}, - $charges[$i2]->{'description'}, - $charges[$i2]->{'accounttype'}, - # rounding amounts to 2dp and adding dollar sign to make excel read it as currency format - "\$".sprintf("%.2f", $charges[$i2]->{'amount'}), - $payments[$i]->{'type'}, - "\$".$payments[$i]->{'value'}); - - push (@loop1, \@rows1); - $totalpaid = $totalpaid + $payments[$i]->{'value'}; - } - } else { - ++$totalwritten; - } - - $i++; #increment the while loop -} - -#get credits and append to the bottom of payments -my @credits=getcredits($date,$date2); - -my $count=@credits; -my $i=0; - -while ($i<$count ){ - - my @rows2 = ($credits[$i]->{'branchcode'}, - $credits[$i]->{'date'}, - $credits[$i]->{'surname'}, - $credits[$i]->{'firstname'}, - $credits[$i]->{'description'}, - $credits[$i]->{'accounttype'}, - "\$".$credits[$i]->{'amount'}); - - push (@loop2, \@rows2); - $totalcredits = $totalcredits + $credits[$i]->{'amount'}; - $i++; -} - -#takes off first char minus sign "-100.00" -$totalcredits = substr($totalcredits, 1); - -print $input->header( - -type => 'application/vnd.ms-excel', - -attachment => "stats.csv", -); -print "Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n"; - - -for my $row ( @loop1 ) { - - $csv->combine(@$row); - my $string = $csv->string; - print $string, "\n"; -} - -print ",,,,,,,\n"; - -for my $row ( @loop2 ) { - - $csv->combine(@$row); - my $string = $csv->string; - print $string, "\n"; -} - -print ",,,,,,,\n"; -print ",,,,,,,\n"; -print ",,Total Amount Paid, $totalpaid\n"; -print ",,Total Number Written, $totalwritten\n"; -print ",,Total Amount Credits, $totalcredits\n"; - diff --git a/reports/stats.screen.pl b/reports/stats.screen.pl deleted file mode 100755 index 16b8f8a..0000000 --- a/reports/stats.screen.pl +++ /dev/null @@ -1,267 +0,0 @@ -#!/usr/bin/perl - -# Copyright Katipo Communications 2006 -# -# 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; FIXME - Bug 2505 -use CGI; -use C4::Output; -use C4::Auth; -use C4::Context; -use C4::Stats; -use C4::Accounts; -use C4::Debug; -use Date::Manip; - -my $input = new CGI; -my $time = $input->param('time'); -my $time2 = $input->param('time2'); -my $op = $input->param('submit'); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "reports/stats_screen.tmpl", - query => $input, - type => "intranet", - authnotrequired => 1, - flagsrequired => { reports => '*' }, - debug => 1, - } -); - -( $time = "today" ) if !$time; -( $time2 = "tomorrow" ) if !$time2; - -my $date = ParseDate($time); -my $date2 = ParseDate($time2); -$date = UnixDate( $date, '%Y-%m-%d' ); -$date2 = UnixDate( $date2, '%Y-%m-%d' ); -$debug and warn "MASON: TIME: $time, $time2"; -$debug and warn "MASON: DATE: $date, $date2"; - -# get a list of every payment -my @payments = TotalPaid( $date, $date2 ); - -my $count = @payments; - -$debug and warn "MASON: number of payments=$count\n"; - -my $i = 0; -my $totalcharges = 0; -my $totalcredits = 0; -my $totalpaid = 0; -my $totalwritten = 0; -my @loop1; -my @loop2; - -# lets get a a list of all individual item charges paid for by that payment - -foreach my $payment (@payments) { - - my @charges; - if ( $payment->{'type'} ne 'writeoff' ) { - - @charges = getcharges( - $payment->{'borrowernumber'}, - $payment->{'timestamp'}, - $payment->{'proccode'} - ); - $totalcharges++; - my $count = @charges; - - # getting each of the charges and putting them into a array to be printed out - #this loops per charge per person - for ( my $i2 = 0 ; $i2 < $count ; $i2++ ) { - my $hour = substr( $payment->{'timestamp'}, 8, 2 ); - my $min = substr( $payment->{'timestamp'}, 10, 2 ); - my $sec = substr( $payment->{'timestamp'}, 12, 2 ); - my $time = "$hour:$min:$sec"; - my $time2 = "$payment->{'date'}"; - - # my $branch=Getpaidbranch($time2,$payment->{'borrowernumber'}); - my $branch = $payment->{'branch'}; - - # lets build up a row - my %rows1 = ( - branch => $branch, - datetime => $payment->{'datetime'}, - surname => $payment->{'surname'}, - firstname => $payment->{'firstname'}, - description => $charges[$i2]->{'description'}, - accounttype => $charges[$i2]->{'accounttype'}, - amount => sprintf( "%.2f", $charges[$i2]->{'amount'} ) - , # rounding amounts to 2dp - type => $payment->{'type'}, - value => sprintf( "%.2f", $payment->{'value'} ) - ); # rounding amounts to 2dp - - push( @loop1, \%rows1 ); - - } - $totalpaid = $totalpaid + $payment->{'value'}; - $debug and warn "totalpaid = $totalpaid"; - } - else { - ++$totalwritten; - } - -} - -#get credits and append to the bottom of payments -my @credits = getcredits( $date, $date2 ); - -my $count = @credits; -my $i = 0; - -while ( $i < $count ) { - - my %rows2 = ( - creditbranch => $credits[$i]->{'branchcode'}, - creditdate => $credits[$i]->{'date'}, - creditsurname => $credits[$i]->{'surname'}, - creditfirstname => $credits[$i]->{'firstname'}, - creditdescription => $credits[$i]->{'description'}, - creditaccounttype => $credits[$i]->{'accounttype'}, - creditamount => sprintf( "%.2f", $credits[$i]->{'amount'} ) - ); - - push( @loop2, \%rows2 ); - $totalcredits = $totalcredits + $credits[$i]->{'amount'}; - $i++; #increment the while loop -} - -#takes off first char minus sign "-100.00" -$totalcredits = substr( $totalcredits, 1 ); - -my $totalrefunds = 0; -my @loop3; -my @refunds = getrefunds( $date, $date2 ); -$count = @refunds; -$i = 0; - -while ( $i < $count ) { - - my %rows3 = ( - refundbranch => $refunds[$i]->{'branchcode'}, - refunddate => $refunds[$i]->{'datetime'}, - refundsurname => $refunds[$i]->{'surname'}, - refundfirstname => $refunds[$i]->{'firstname'}, - refunddescription => $refunds[$i]->{'description'}, - refundaccounttype => $refunds[$i]->{'accounttype'}, - refundamount => sprintf( "%.2f", $refunds[$i]->{'amount'} ) - ); - - push( @loop3, \%rows3 ); - $totalrefunds = $totalrefunds + $refunds[$i]->{'amount'}; - $i++; #increment the while loop -} - -my $totalcash = $totalpaid - $totalrefunds; - -if ( $op eq 'To Excel' ) { - - my $csv = Text::CSV_XS->new( - { - 'quote_char' => '"', - 'escape_char' => '"', - 'sep_char' => ',', - 'binary' => 1 - } - ); - - print $input->header( - -type => 'application/vnd.ms-excel', - -attachment => "stats.csv", - ); - print -"Branch, Datetime, Surname, Firstnames, Description, Type, Invoice amount, Payment type, Payment Amount\n"; - - $DB::single = 1; - - for my $row (@loop1) { - my @array = ( - $row->{'branch'}, $row->{'datetime'}, - $row->{'surname'}, $row->{'firstname'}, - $row->{'description'}, $row->{'accounttype'}, - $row->{'amount'}, $row->{'type'}, - $row->{'value'} - ); - - $csv->combine(@array); - my $string = $csv->string(@array); - print $string, "\n"; - } - print ",,,,,,,\n"; - print -"Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n"; - - for my $row (@loop2) { - - my @array = ( - $row->{'creditbranch'}, $row->{'creditdate'}, - $row->{'creditsurname'}, $row->{'creditfirstname'}, - $row->{'creditdescription'}, $row->{'creditaccounttype'}, - $row->{'creditamount'} - ); - - $csv->combine(@array); - my $string = $csv->string(@array); - print $string, "\n"; - } - print ",,,,,,,\n"; - print -"Branch, Date/time, Surname, Firstname, Description, Charge Type, Invoice Amount\n"; - - for my $row (@loop3) { - my @array = ( - $row->{'refundbranch'}, $row->{'refunddate'}, - $row->{'refundsurname'}, $row->{'refundfirstname'}, - $row->{'refunddescription'}, $row->{'refundaccounttype'}, - $row->{'refundamount'} - ); - - $csv->combine(@array); - my $string = $csv->string(@array); - print $string, "\n"; - - } - - print ",,,,,,,\n"; - print ",,,,,,,\n"; - print ",,Total Amount Paid, $totalpaid\n"; - print ",,Total Number Written, $totalwritten\n"; - print ",,Total Amount Credits, $totalcredits\n"; - print ",,Total Amount Refunds, $totalrefunds\n"; -} -else { - $template->param( - date => $time, - date2 => $time2, - loop1 => \@loop1, - loop2 => \@loop2, - loop3 => \@loop3, - totalpaid => $totalpaid, - totalcredits => $totalcredits, - totalwritten => $totalwritten, - totalrefund => $totalrefunds, - totalcash => $totalcash, - ); - output_html_with_http_headers $input, $cookie, $template->output; -} - -- 1.7.2.5