From 1d058290825745f8ab43a6a4327667bb7773c6ba Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Fri, 16 May 2014 10:43:53 +0300 Subject: [PATCH] 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. --- C4/Members.pm | 62 ++++++++++++++++++++ .../data/mysql/en/mandatory/sample_notices.sql | 15 +++++ installer/data/mysql/updatedatabase.pl | 21 +++++++ .../prog/en/includes/members-toolbar.inc | 6 ++ members/printslip.pl | 6 +- 5 files changed, 109 insertions(+), 1 deletion(-) diff --git a/C4/Members.pm b/C4/Members.pm index 33106cf..b6d2a2e 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -101,6 +101,7 @@ BEGIN { &GetMessagesCount &IssueSlip + &FineSlip GetBorrowersWithEmail HasOverdues @@ -2405,6 +2406,67 @@ sub IssueSlip { ); } + +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', + ); +} + + =head2 GetBorrowersWithEmail ([$borrnum,$userid], ...) = GetBorrowersWithEmail('me@example.com'); diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 2281739..a887580 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -142,3 +142,18 @@ Thank you. Your library.' ); + +INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type) +VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines', '<> <>
+<>
+Fines: <> +
    + +
  • <>, <>
    +Bar code: <>
    +<> + +
+Total: <> +', 'print' +); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index c68ba51..09cd422 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8560,6 +8560,27 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(" +INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type) +VALUES ( 'circulation', 'FINESLIP', '', 'Patron fines -slip', '1', 'Fines', '<> <>
+<>
+Fines: <> +
    + +
  • <>, <>
    +Bar code: <>
    +<> + +
+Total: <> +', 'print' +);"); + print "Upgrade to $DBversion done (Bug 12285 - Allow easy printing of patron fines slip)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 caa2fbf..8113c99 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -38,6 +38,11 @@ $(document).ready(function(){ $(".btn-group").removeClass("open"); return false; }); + $("#printfineslip").click(function(){ + printx_window("fineslip"); + $(".btn-group").removeClass("open"); + return false; + }); $("#searchtohold").click(function(){ searchToHold(); return false; @@ -124,6 +129,7 @@ function searchToHold(){ [% IF ( CAN_user_borrowers ) %]
  • Print summary
  • [% END %]
  • Print slip
  • Print quick slip
  • +
  • Print fines
  • Search to hold diff --git a/members/printslip.pl b/members/printslip.pl index 71fdda2..0c23442 100755 --- a/members/printslip.pl +++ b/members/printslip.pl @@ -76,7 +76,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $borrowernumber = $input->param('borrowernumber'); my $branch=C4::Context->userenv->{'branch'}; my ($slip, $is_html); -if (my $letter = IssueSlip ($session->param('branch') || $branch, $borrowernumber, $print eq "qslip")) { +if ($print eq 'fineslip') { + my $letter = 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}; } -- 1.7.10.4