Bugzilla – Attachment 43442 Details for
Bug 12770
Notice template tool enhancement
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12770 - Notice template tool enhancement
Bug-12770---Notice-template-tool-enhancement.patch (text/plain), 7.87 KB, created by
Eivin Giske Skaaren
on 2015-10-15 18:05:22 UTC
(
hide
)
Description:
Bug 12770 - Notice template tool enhancement
Filename:
MIME Type:
Creator:
Eivin Giske Skaaren
Created:
2015-10-15 18:05:22 UTC
Size:
7.87 KB
patch
obsolete
>From c2051d48770997481857cfc149f10742e576b619 Mon Sep 17 00:00:00 2001 >From: simith <simith@inlibro.com> >Date: Thu, 11 Dec 2014 14:22:07 -0500 >Subject: [PATCH] Bug 12770 - Notice template tool enhancement > >Fixed merge conflict and rebased. > >Tested OK. Values now show up i table. > >Signed-off-by: Eivin Giske Skaaren <eivin@sysmystic.com> >--- > C4/Letters.pm | 36 +++++++++++++++++++++++--- > misc/cronjobs/overdue_notices.pl | 53 +++++++++++++++++++++++++++++++++++--- > 2 files changed, 82 insertions(+), 7 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 6f148a9..b138cb1 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -721,7 +721,9 @@ sub GetPreparedLetter { > > sub _substitute_tables { > my ( $letter, $tables ) = @_; >- while ( my ($table, $param) = each %$tables ) { >+ >+ foreach my $table (keys %$tables) { >+ my $param = $tables->{$table}; > next unless $param; > > my $ref = ref $param; >@@ -729,8 +731,35 @@ sub _substitute_tables { > my $values; > if ($ref && $ref eq 'HASH') { > $values = $param; >- } >- else { >+ } elsif ($ref && $ref eq 'ARRAY') { >+ my $tag = $table; >+ >+ my $hash_ref = pop($param); >+ foreach my $table (keys %$hash_ref) { >+ my $param = $hash_ref->{$table}; >+ if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) { >+ my $subcontent = $1; >+ >+ my $sth = _parseletter_sth($table); >+ unless ($sth) { >+ warn "_parseletter_sth('$table') failed to return a valid sth. No substitution will be done for that table."; >+ return; >+ } >+ >+ $sth->execute( $param ); >+ my @lines; >+ while( $values = $sth->fetchrow_hashref) >+ { >+ my %subletter = ( title => '', content => $subcontent ); >+ my $line = _parseletter ( \%subletter, $table, $values ); >+ push @lines, $line->{content}; >+ } >+ $letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se; >+ my $temp; >+ } >+ } >+ }else { >+ my @pk; > my $sth = _parseletter_sth($table); > unless ($sth) { > warn "_parseletter_sth('$table') failed to return a valid sth. No substitution will be done for that table."; >@@ -762,6 +791,7 @@ sub _parseletter_sth { > ($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : > ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : > ($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : >+ ($table eq 'accountlines' ) ? "SELECT * , FORMAT(amountoutstanding, 2) as amountoutstanding FROM $table WHERE date = DATE(NOW()) AND amountoutstanding > 0 AND itemnumber = ?" : > ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" : > ($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : > ($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : >diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl >index 482be02..3e7b23c 100755 >--- a/misc/cronjobs/overdue_notices.pl >+++ b/misc/cronjobs/overdue_notices.pl >@@ -556,8 +556,9 @@ END_SQL > next; > } > } >+ > if (defined $borrowernumber && $borrowernumber eq $data->{'borrowernumber'}){ >-# we have already dealt with this borrower >+ # we have already dealt with this borrower > $verbose and warn "already dealt with this borrower $borrowernumber"; > next; > } >@@ -668,10 +669,30 @@ END_SQL > @message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) } > unless @message_transport_types; > >+ #calculate letter fee >+ my $noticefee = 0; >+ if ($letter->{'fee'}){ >+ $noticefee = $letter->{'fee'}; >+ } else { >+ if (C4::Context->preference('DefaultNoticeFee')){ >+ $noticefee = C4::Context->preference('DefaultNoticeFee'); >+ } >+ } >+ >+ #total of fines >+ my $userfines = 0; >+ my $dbh = C4::Context->dbh(); >+ my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines where date = DATE(NOW()) AND itemnumber IS NOT NULL AND amountoutstanding > 0 AND borrowernumber=?|; >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $borrowernumber ); >+ my $fine = $sth->fetchrow_hashref(); >+ if ($fine->{fineamount}) { >+ $userfines = $fine->{fineamount}; >+ } >+ $userfines = $userfines + $noticefee; > > my $print_sent = 0; # A print notice is not yet sent for this patron > for my $mtt ( @message_transport_types ) { >- > my $letter = parse_letter( > { letter_code => $overdue_rules->{"letter$i"}, > borrowernumber => $borrowernumber, >@@ -681,6 +702,8 @@ END_SQL > bib => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'? > 'items.content' => $titles, > 'count' => $itemcount, >+ 'total' => sprintf("%.2f", $userfines), >+ 'noticefee' => $noticefee, > }, > message_transport_type => $mtt, > } >@@ -873,7 +896,6 @@ sub parse_letter { > $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/; > $item_format = $1; > } >- > $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL); > # if active currency isn't correct ISO code fallback to sprintf > $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'}; >@@ -887,13 +909,36 @@ sub parse_letter { > } > } > >+ #find all fines to create invoice table >+ my $dbh = C4::Context->dbh(); >+ my $sth = $dbh->prepare( <<"END_SQL" ); >+SELECT items.biblionumber, items.itemnumber >+FROM items,accountlines >+ where date = DATE(NOW()) >+ AND accountlines.itemnumber IS NOT NULL >+ AND amountoutstanding > 0 >+ AND items.itemnumber = accountlines.itemnumber >+ AND borrowernumber=? group by items.itemnumber >+END_SQL >+ >+ $sth->execute($params->{'borrowernumber'}); >+ my @account_tables; >+ while ( my $item = $sth->fetchrow_hashref() ) { >+ push @account_tables, { >+ 'biblio' => $item->{'biblionumber'}, >+ 'items' => $item->{'itemnumber'}, >+ 'accountlines' => [{'accountlines' => $item->{'itemnumber'}}], >+ }; >+ } >+ > return C4::Letters::GetPreparedLetter ( > module => 'circulation', > letter_code => $params->{'letter_code'}, > branchcode => $params->{'branchcode'}, > tables => \%tables, > substitute => $substitute, >- repeat => { item => \@item_tables }, >+ repeat => { item => \@item_tables, >+ itemaccountlines => \@account_tables}, > message_transport_type => $params->{message_transport_type}, > ); > } >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12770
:
34336
| 43442