From 176da5881f6177c48ed19ba73d8cd90b6f654bbe Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 25 Jan 2018 10:14:03 +0000 Subject: [PATCH] Bug 20119 - Ability to print claims for late orders Test plan: - create a notice: module: claimacquisition, code: ACQCLAIM: transport: print - create at least a bookseller, basket and orders, - close the basket and change the closedate to make orders late, - go to cgi-bin/koha/acqui/lateorders.pl, - select one or more order(s) to claim and click on "Print claim", - check the pdf downloaded [2018-03-15] Rebased-by: Alex Arnaud --- C4/Letters.pm | 66 ++++++++++++++++++++++ acqui/lateorders.pl | 12 ++++ .../prog/en/modules/acqui/lateorders.tt | 11 ++++ 3 files changed, 89 insertions(+) diff --git a/C4/Letters.pm b/C4/Letters.pm index 219779b..58b99e4 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -662,6 +662,72 @@ sub SendAlerts { return 1; } +=head2 PrintClaimOrderNotice + +Returns a 'claimorders' notice for given order ids and letter code as PDF + + my $pdf = PrintClaimOrderNotice(\@orderids, $letter_code); + + print $cgi->header('application/pdf'); + print $pdf; + +=cut + +sub PrintClaimOrderNotice { + my ($orderids, $letter_code) = @_; + + return unless ref $orderids eq 'ARRAY'; + return unless @$orderids > 0; + return unless $letter_code; + + my $dbh = C4::Context->dbh; + + my $orderids_str = join(',', ('?') x @$orderids); + my $orders = $dbh->selectall_arrayref(qq{ + SELECT aqorders.*, aqbasket.*, biblio.* + FROM aqorders + LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber + LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno + WHERE aqorders.ordernumber IN ($orderids_str) + }, {Slice => {}}, @$orderids); + + return unless @$orders; + + my $booksellerid = $orders->[0]->{aqbooksellerid}; + + my $schema = Koha::Database->new->schema; + my $bookseller = + $schema->resultset('Aqbookseller')->find( { id => $booksellerid }, + { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); + + my $userenv = C4::Context->userenv; + my $letter = GetPreparedLetter( + module => 'claimacquisition', + letter_code => $letter_code, + branchcode => $userenv->{branch}, + message_transport_type => 'print', + tables => { + 'branches' => $userenv->{branch}, + 'aqbooksellers' => $bookseller, + }, + want_librarian => 1, + repeat => $orders, + ) or return; + + my $content = $letter->{content}; + if ($letter->{is_html}) { + $content = _wrap_html($content, $letter->{title}); + } + + my $output = ''; + my $pdf = PDF::FromHTML->new(encoding => 'utf-8'); + $pdf->load_file(\$content); + $pdf->convert(); + $pdf->write_file(\$output); + + return $output; +} + =head2 GetPreparedLetter( %params ) %params hash: diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl index 9febcf6..77bd139 100755 --- a/acqui/lateorders.pl +++ b/acqui/lateorders.pl @@ -122,6 +122,18 @@ if ($op and $op eq "send_alert"){ } } +if ($op and $op eq "print_alert") { + my @orderids = $input->multi_param('ordernumber'); + + my $pdf = C4::Letters::PrintClaimOrderNotice(\@orderids, 'ACQCLAIM'); + print $input->header( + -type => 'application/pdf', + -attachment => 'claims.pdf', + ); + print $pdf; + exit; +} + my @parameters = ( $delay ); push @parameters, $estimateddeliverydatefrom_dt ? $estimateddeliverydatefrom_dt->ymd() diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt index 4c142a1..7b0e863 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt @@ -148,6 +148,7 @@ [% UNLESS lateorder.budget_lock %] + [% END %]

@@ -249,6 +250,16 @@ location.href = url; return false; }); + + $('#print-claim').on('click', function(e) { + e.preventDefault(); + var form = $(this).parents('form') + var op = form.find('input[name="op"]'); + + op.val('print_alert'); + form.submit(); + op.val('send_alert'); + }); }); [% END %] -- 2.7.4