From ad289df9eeb74d0cd4c9f452ab6cf93a8687d105 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Fri, 16 May 2014 10:43:53 +0300 Subject: [PATCH 1/6] Bug 12285: Allow easy printing of patron's fines. Add a printing option to the staff client patron details page to print a slip of patron's fines. To test: 1) Apply patch. 2) Check in tools > Notices & Slips that you have FINESLIP slip, and a print message there. If not, run updatedatabase.pl 3) Either create some fines for a patron, or look up a patron with existing fines. 4) From that patron's detail page, and the Print-menu in the toolbar, select "Print fines" 5) You should get a slip of the patron's fines. I removed superfluous $ signs in sample_notices.sql and updatedatabase.pl Patch works now as expected. However, it needs now a Sign-off by somebody else. Signed-off-by: Aleisha Rebased-by: Emmi Takkinen Signed-off-by: Owen Leonard --- C4/Members.pm | 60 +++++++++++++++++++ ...-allow_easy_printing_of_patrons_fines.perl | 10 ++++ .../mysql/en/mandatory/sample_notices.yml | 23 +++++++ .../prog/en/includes/members-toolbar.inc | 1 + .../intranet-tmpl/prog/js/members-menu.js | 5 ++ members/printslip.pl | 4 ++ 6 files changed, 103 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_12285-allow_easy_printing_of_patrons_fines.perl diff --git a/C4/Members.pm b/C4/Members.pm index 5478e0de32..c591adf366 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -50,6 +50,7 @@ BEGIN { GetBorrowersToExpunge IssueSlip + &FineSlip checkuserpassword get_cardnumber_length @@ -683,6 +684,65 @@ WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; return $cnt eq '0E0'? 0: $cnt; } +sub GetBorrowerFines { + my ($borrowernumber) = @_; + my $dbh = C4::Context->dbh; + my $query = qq{ + SELECT * FROM accountlines + LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber + LEFT JOIN items ON accountlines.itemnumber = items.itemnumber + WHERE accountlines.borrowernumber = ? + ORDER BY accountlines.timestamp + }; + my $sth = $dbh->prepare( $query ); + $sth->execute( $borrowernumber ); + my $data = $sth->fetchall_arrayref({}); + return $data; +} + +sub FineSlip { + my ($borrowernumber, $branch) = @_; + + #my $now = POSIX::strftime("%Y-%m-%d", localtime); + + my $issueslist = GetBorrowerFines($borrowernumber); + + my $total = 0.0; + + foreach my $it (@$issueslist){ + my $dt = dt_from_string( $it->{'date'} ); + $it->{'date_due'} = output_pref({ dt => $dt, dateonly => 1 }); + $it->{'amount'} = sprintf('%.2f', $it->{'amount'}); + $total = $total + $it->{'amount'}; + $it->{'barcode'} = '-' if (!defined($it->{'barcode'})); + } + my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist; + + my %repeat = ( + 'fines' => [ map { + 'fines' => $_, + 'borrowers' => $_, + 'items' => $_ + }, @issues ], + ); + + return C4::Letters::GetPreparedLetter ( + module => 'circulation', + letter_code => 'FINESLIP', + branchcode => $branch, + tables => { + 'branches' => $branch, + 'borrowers' => $borrowernumber, + }, + substitute => { + 'total.amount' => sprintf('%.2f', $total), + 'total.fines' => scalar(@issues) + }, + repeat => \%repeat, + message_transport_type => 'print', + ); +} + END { } # module clean-up code here (global destructor) 1; diff --git a/installer/data/mysql/atomicupdate/bug_12285-allow_easy_printing_of_patrons_fines.perl b/installer/data/mysql/atomicupdate/bug_12285-allow_easy_printing_of_patrons_fines.perl new file mode 100644 index 0000000000..78970f0cd4 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_12285-allow_easy_printing_of_patrons_fines.perl @@ -0,0 +1,10 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # you can use $dbh here like: + # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); + + $dbh->do( qq| INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type) VALUES ( "circulation", "FINESLIP", "", "Patron fines -slip", "1", "Fines and fees slip", "<> <>
<>
Fines: <>
  • <>, <>
    Barcode: <>
    <>
Total: <>", "print")| ); + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 12285, "Allow easy printing of patron's fines"); +} diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml index 088c56bbac..d534d61629 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1745,3 +1745,26 @@ tables: - "

This is to confirm that someone enabled two factor authentication on your account.

" - "

If you did not do this, someone else may be using your account. Please contact technical support.

" - "

Your library

" + + - module: circulation + code: FINESLIP + branchcode: "" + name: "Patron fines -slip" + is_html: 1 + title: "Fines and fees slip" + message_transport_type: pront + lang: default + content: + - "<> <>
" + - "<>
" + - "Fines: <>" + - "
    " + - "" + - "
  • "" + - "<>, <>
    " + - "Barcode: <>
    " + - "<>" + - "
  • " + - "
    " + - "
" + - "Total: <>" \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc index 056d855bd9..b28ee923ea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -24,6 +24,7 @@
  • Print summary
  • Print slip
  • Print quick slip
  • +
  • Print fines
  • [% IF patron.has_overdues %]
  • Print overdues
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js index 7a3336aebf..c55b027374 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js @@ -82,6 +82,11 @@ $(document).ready(function(){ $(".btn-group").removeClass("open"); return false; }); + $("#printfineslip").click(function(){ + printx_window("fineslip"); + $(".btn-group").removeClass("open"); + return false; + }); $("#printclearscreen").click(function(){ printx_window("slip"); window.location.replace("/cgi-bin/koha/circ/circulation.pl"); diff --git a/members/printslip.pl b/members/printslip.pl index 368d84cc7f..4cdeb0d3de 100755 --- a/members/printslip.pl +++ b/members/printslip.pl @@ -94,6 +94,10 @@ if ( $print eq 'checkinslip' ) { $slip = $letter->{content}; $is_html = $letter->{is_html}; +} elsif ($print eq 'fineslip') { + my $letter = C4::Members::FineSlip($borrowernumber, $session->param('branch') || $branch); + $slip = $letter->{content}; + $is_html = $letter->{is_html}; } elsif (my $letter = IssueSlip ($session->param('branch') || $branch, $borrowernumber, $print eq "qslip")) { $slip = $letter->{content}; $is_html = $letter->{is_html}; -- 2.25.1