|
Lines 30-35
use C4::Log;
Link Here
|
| 30 |
use C4::SMS; |
30 |
use C4::SMS; |
| 31 |
use C4::Debug; |
31 |
use C4::Debug; |
| 32 |
use Date::Calc qw( Add_Delta_Days ); |
32 |
use Date::Calc qw( Add_Delta_Days ); |
|
|
33 |
use C4::Dates qw/format_date/; |
| 33 |
use Encode; |
34 |
use Encode; |
| 34 |
use Carp; |
35 |
use Carp; |
| 35 |
|
36 |
|
|
Lines 477-488
sub parseletter_sth {
Link Here
|
| 477 |
carp "ERROR: parseletter_sth() called without argument (table)"; |
478 |
carp "ERROR: parseletter_sth() called without argument (table)"; |
| 478 |
return; |
479 |
return; |
| 479 |
} |
480 |
} |
| 480 |
# check cache first |
481 |
my $itemselect = |
|
|
482 |
'SELECT barcode, itemcallnumber, location, holdingbranch, date_due, issuedate, author, title from items ' |
| 483 |
. 'left join issues on issues.itemnumber = items.itemnumber ' |
| 484 |
. 'LEFT JOIN biblio on items.biblionumber = biblio.biblionumber ' |
| 485 |
. 'WHERE items.itemnumber = ? '; |
| 486 |
# check cache first |
| 481 |
(defined $handles{$table}) and return $handles{$table}; |
487 |
(defined $handles{$table}) and return $handles{$table}; |
| 482 |
my $query = |
488 |
my $query = |
| 483 |
($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : |
489 |
($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : |
| 484 |
($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : |
490 |
($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : |
| 485 |
($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : |
491 |
($table eq 'items' ) ? $itemselect : |
| 486 |
($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : |
492 |
($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : |
| 487 |
($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : |
493 |
($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : |
| 488 |
($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" : |
494 |
($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" : |
|
Lines 510-515
sub parseletter {
Link Here
|
| 510 |
warn "parseletter_sth('$table') failed to return a valid sth. No substitution will be done for that table."; |
516 |
warn "parseletter_sth('$table') failed to return a valid sth. No substitution will be done for that table."; |
| 511 |
return; |
517 |
return; |
| 512 |
} |
518 |
} |
|
|
519 |
my $check_in_notice; |
| 520 |
if ($table eq 'items') { |
| 521 |
if ($pk2 && $pk2 eq 'CHECKIN') { |
| 522 |
$check_in_notice = 1; |
| 523 |
} |
| 524 |
$pk2 = undef; |
| 525 |
} |
| 513 |
if ( $pk2 ) { |
526 |
if ( $pk2 ) { |
| 514 |
$sth->execute($pk, $pk2); |
527 |
$sth->execute($pk, $pk2); |
| 515 |
} else { |
528 |
} else { |
|
Lines 531-547
sub parseletter {
Link Here
|
| 531 |
)->output(); |
544 |
)->output(); |
| 532 |
} |
545 |
} |
| 533 |
|
546 |
|
| 534 |
|
|
|
| 535 |
# and get all fields from the table |
547 |
# and get all fields from the table |
| 536 |
my $columns = C4::Context->dbh->prepare("SHOW COLUMNS FROM $table"); |
548 |
if ($table ne 'items' ) { |
| 537 |
$columns->execute; |
549 |
my $columns = C4::Context->dbh->prepare("SHOW COLUMNS FROM $table"); |
| 538 |
while ( ( my $field ) = $columns->fetchrow_array ) { |
550 |
$columns->execute; |
| 539 |
my $replacefield = "<<$table.$field>>"; |
551 |
while ( ( my $field ) = $columns->fetchrow_array ) { |
| 540 |
$values->{$field} =~ s/\p{P}(?=$)//g if $values->{$field}; |
552 |
my $replacefield = "<<$table.$field>>"; |
| 541 |
my $replacedby = $values->{$field} || ''; |
553 |
$values->{$field} =~ s/\p{P}(?=$)//g if $values->{$field}; |
| 542 |
($letter->{title} ) and $letter->{title} =~ s/$replacefield/$replacedby/g; |
554 |
my $replacedby = $values->{$field} || ''; |
| 543 |
($letter->{content}) and $letter->{content} =~ s/$replacefield/$replacedby/g; |
555 |
($letter->{title} ) and $letter->{title} =~ s/$replacefield/$replacedby/g; |
|
|
556 |
($letter->{content}) and $letter->{content} =~ s/$replacefield/$replacedby/g; |
| 557 |
} |
| 544 |
} |
558 |
} |
|
|
559 |
|
| 560 |
if ($table eq 'items') { |
| 561 |
if ($check_in_notice) { |
| 562 |
# need to get dates from old_issues |
| 563 |
my $dates = C4::Context->dbh->selectrow_arrayref( |
| 564 |
'SELECT issuedate, date_due FROM old_issues where itemnumber = ? AND DATE(timestamp) = CURDATE() ORDER BY timestamp DESC LIMIT 1', |
| 565 |
{}, $pk); |
| 566 |
$values->{issuedate} = ${ $dates}[0]; |
| 567 |
$values->{date_due} = ${ $dates}[1]; |
| 568 |
} |
| 569 |
$values->{issuedate} = format_date($values->{issuedate}); |
| 570 |
$values->{date_due} = format_date($values->{date_due}); |
| 571 |
$values->{content} = join "\t", $values->{issuedate}, $values->{title}, $values->{barcode}, $values->{author}; |
| 572 |
for my $field ( qw( issuedate date_due barcode holdingbranch location itemcallnumber content)) { |
| 573 |
my $replacefield = "<<$table.$field>>"; |
| 574 |
my $replacedby = $values->{$field} || ''; |
| 575 |
($letter->{title} ) and $letter->{title} =~ s/$replacefield/$replacedby/g; |
| 576 |
($letter->{content}) and $letter->{content} =~ s/$replacefield/$replacedby/g; |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 545 |
return $letter; |
580 |
return $letter; |
| 546 |
} |
581 |
} |
| 547 |
|
582 |
|