|
Lines 17-24
package C4::Letters;
Link Here
|
| 17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use strict; |
20 |
use Modern::Perl; |
| 21 |
use warnings; |
|
|
| 22 |
|
21 |
|
| 23 |
use MIME::Lite; |
22 |
use MIME::Lite; |
| 24 |
use Mail::Sendmail; |
23 |
use Mail::Sendmail; |
|
Lines 365-376
sub findrelatedto {
Link Here
|
| 365 |
|
364 |
|
| 366 |
=head2 SendAlerts |
365 |
=head2 SendAlerts |
| 367 |
|
366 |
|
| 368 |
parameters : |
367 |
my $err = &SendAlerts($type, $externalid, $letter_code); |
| 369 |
- $type : the type of alert |
|
|
| 370 |
- $externalid : the id of the "object" to query |
| 371 |
- $letter_code : the letter to send. |
| 372 |
|
368 |
|
| 373 |
send an alert to all borrowers having put an alert on a given subject. |
369 |
Parameters: |
|
|
370 |
- $type : the type of alert |
| 371 |
- $externalid : the id of the "object" to query |
| 372 |
- $letter_code : the notice template to use |
| 373 |
|
| 374 |
C<&SendAlerts> sends an email notice directly to a patron or a vendor. |
| 375 |
Currently it supports ($type): |
| 376 |
- claim serial issues (claimissues) |
| 377 |
- claim acquisition orders (claimacquisition) |
| 378 |
- send acquisition orders to the vendor (orderacquisition) |
| 379 |
- notify patrons about newly received serial issues (issue) |
| 380 |
- notify patrons when their account is created (members) |
| 374 |
|
381 |
|
| 375 |
=cut |
382 |
=cut |
| 376 |
|
383 |
|
|
Lines 444-463
sub SendAlerts {
Link Here
|
| 444 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
451 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
| 445 |
} |
452 |
} |
| 446 |
} |
453 |
} |
| 447 |
elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' ) { |
454 |
elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' or $type eq 'orderacquisition' ) { |
| 448 |
|
455 |
|
| 449 |
# prepare the letter... |
456 |
# prepare the letter... |
| 450 |
# search the biblionumber |
457 |
my $strsth; |
| 451 |
my $strsth = $type eq 'claimacquisition' |
458 |
my $sthorders; |
| 452 |
? qq{ |
459 |
my $dataorders; |
|
|
460 |
my $action; |
| 461 |
if ( $type eq 'claimacquisition') { |
| 462 |
$strsth = qq{ |
| 453 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
463 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
| 454 |
FROM aqorders |
464 |
FROM aqorders |
| 455 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
465 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
| 456 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
466 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
| 457 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
467 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
| 458 |
WHERE aqorders.ordernumber IN ( |
468 |
WHERE aqorders.ordernumber IN ( |
|
|
469 |
}; |
| 470 |
|
| 471 |
if (!@$externalid){ |
| 472 |
carp "No order selected"; |
| 473 |
return { error => "no_order_selected" }; |
| 459 |
} |
474 |
} |
| 460 |
: qq{ |
475 |
$strsth .= join( ",", @$externalid ) . ")"; |
|
|
476 |
$action = "AQUISITION CLAIM"; |
| 477 |
$sthorders = $dbh->prepare($strsth); |
| 478 |
$sthorders->execute; |
| 479 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
| 480 |
} |
| 481 |
|
| 482 |
if ($type eq 'claimissues') { |
| 483 |
$strsth = qq{ |
| 461 |
SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*, |
484 |
SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*, |
| 462 |
aqbooksellers.id AS booksellerid |
485 |
aqbooksellers.id AS booksellerid |
| 463 |
FROM serial |
486 |
FROM serial |
|
Lines 466-487
sub SendAlerts {
Link Here
|
| 466 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id |
489 |
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id |
| 467 |
WHERE serial.serialid IN ( |
490 |
WHERE serial.serialid IN ( |
| 468 |
}; |
491 |
}; |
|
|
492 |
|
| 493 |
if (!@$externalid){ |
| 494 |
carp "No issues selected"; |
| 495 |
return { error => "no_issues_selected" }; |
| 496 |
} |
| 497 |
$strsth .= join( ",", @$externalid ) . ")"; |
| 498 |
$action = "CLAIM ISSUE"; |
| 499 |
$sthorders = $dbh->prepare($strsth); |
| 500 |
$sthorders->execute; |
| 501 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
| 502 |
} |
| 503 |
|
| 504 |
if ( $type eq 'orderacquisition') { |
| 505 |
$strsth = qq{ |
| 506 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
| 507 |
FROM aqorders |
| 508 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
| 509 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
| 510 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
| 511 |
WHERE aqbasket.basketno = ? |
| 512 |
AND orderstatus IN ('new','ordered') |
| 513 |
}; |
| 469 |
|
514 |
|
| 470 |
if (!@$externalid){ |
515 |
if (!$externalid){ |
| 471 |
carp "No Order seleted"; |
516 |
carp "No basketnumber given"; |
| 472 |
return { error => "no_order_seleted" }; |
517 |
return { error => "no_basketno" }; |
|
|
518 |
} |
| 519 |
$action = "ACQUISITION ORDER"; |
| 520 |
$sthorders = $dbh->prepare($strsth); |
| 521 |
$sthorders->execute($externalid); |
| 522 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
| 473 |
} |
523 |
} |
| 474 |
|
524 |
|
| 475 |
$strsth .= join( ",", @$externalid ) . ")"; |
|
|
| 476 |
my $sthorders = $dbh->prepare($strsth); |
| 477 |
$sthorders->execute; |
| 478 |
my $dataorders = $sthorders->fetchall_arrayref( {} ); |
| 479 |
|
| 480 |
my $sthbookseller = |
525 |
my $sthbookseller = |
| 481 |
$dbh->prepare("select * from aqbooksellers where id=?"); |
526 |
$dbh->prepare("select * from aqbooksellers where id=?"); |
| 482 |
$sthbookseller->execute( $dataorders->[0]->{booksellerid} ); |
527 |
$sthbookseller->execute( $dataorders->[0]->{booksellerid} ); |
| 483 |
my $databookseller = $sthbookseller->fetchrow_hashref; |
528 |
my $databookseller = $sthbookseller->fetchrow_hashref; |
| 484 |
my $addressee = $type eq 'claimacquisition' ? 'acqprimary' : 'serialsprimary'; |
529 |
|
|
|
530 |
my $addressee = $type eq 'claimacquisition' || $type eq 'orderacquisition' ? 'acqprimary' : 'serialsprimary'; |
| 531 |
|
| 485 |
my $sthcontact = |
532 |
my $sthcontact = |
| 486 |
$dbh->prepare("SELECT * FROM aqcontacts WHERE booksellerid=? AND $type=1 ORDER BY $addressee DESC"); |
533 |
$dbh->prepare("SELECT * FROM aqcontacts WHERE booksellerid=? AND $type=1 ORDER BY $addressee DESC"); |
| 487 |
$sthcontact->execute( $dataorders->[0]->{booksellerid} ); |
534 |
$sthcontact->execute( $dataorders->[0]->{booksellerid} ); |
|
Lines 546-552
sub SendAlerts {
Link Here
|
| 546 |
|
593 |
|
| 547 |
logaction( |
594 |
logaction( |
| 548 |
"ACQUISITION", |
595 |
"ACQUISITION", |
| 549 |
$type eq 'claimissues' ? "CLAIM ISSUE" : "ACQUISITION CLAIM", |
596 |
$action, |
| 550 |
undef, |
597 |
undef, |
| 551 |
"To=" |
598 |
"To=" |
| 552 |
. join( ',', @email ) |
599 |
. join( ',', @email ) |