View | Details | Raw Unified | Return to bug 15971
Collapse All | Expand All

(-)a/C4/Letters.pm (-4 / +5 lines)
Lines 393-414 sub SendAlerts { Link Here
393
393
394
        if ($type eq 'claimissues') {
394
        if ($type eq 'claimissues') {
395
            $strsth = qq{
395
            $strsth = qq{
396
            SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*,
396
            SELECT serial.*,subscription.*, biblio.*, biblioitems.*, aqbooksellers.*,
397
            aqbooksellers.id AS booksellerid
397
            aqbooksellers.id AS booksellerid
398
            FROM serial
398
            FROM serial
399
            LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
399
            LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
400
            LEFT JOIN biblio ON serial.biblionumber=biblio.biblionumber
400
            LEFT JOIN biblio ON serial.biblionumber=biblio.biblionumber
401
            LEFT JOIN biblioitems ON serial.biblionumber = biblioitems.biblionumber
401
            LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
402
            LEFT JOIN aqbooksellers ON subscription.aqbooksellerid=aqbooksellers.id
402
            WHERE serial.serialid IN (
403
            WHERE serial.serialid IN (
403
            };
404
            };
404
405
405
            if (!@$externalid){
406
            if (!@$externalid){
406
                carp "No Order selected";
407
                carp "No issues selected";
407
                return { error => "no_order_selected" };
408
                return { error => "no_issues_selected" };
408
            }
409
            }
409
410
410
            $strsth .= join( ",", ('?') x @$externalid ) . ")";
411
            $strsth .= join( ",", ('?') x @$externalid ) . ")";
411
            $action = "CLAIM ISSUE";
412
            $action = "SERIAL CLAIM";
412
            $sthorders = $dbh->prepare($strsth);
413
            $sthorders = $dbh->prepare($strsth);
413
            $sthorders->execute( @$externalid );
414
            $sthorders->execute( @$externalid );
414
            $dataorders = $sthorders->fetchall_arrayref( {} );
415
            $dataorders = $sthorders->fetchall_arrayref( {} );
(-)a/t/db_dependent/Letters.t (-1 / +95 lines)
Lines 18-24 Link Here
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 Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 64;
21
use Test::More tests => 65;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 490-495 is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notificatio Link Here
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
490
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
491
}
491
}
492
492
493
subtest 'SendAlerts - claimissue' => sub {
494
    plan tests => 8;
495
496
    use C4::Serials;
497
498
    $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimissues','TESTSERIALCLAIM','Serial claim test','Serial claim test','<<serial.serialid>>|<<subscription.startdate>>|<<biblio.title>>|<<biblioitems.issn>>');});
499
500
    my $bookseller = Koha::Acquisition::Bookseller->new(
501
        {
502
            name => "my vendor",
503
            address1 => "bookseller's address",
504
            phone => "0123456",
505
            active => 1,
506
            deliverytime => 5,
507
        }
508
    )->store;
509
    my $booksellerid = $bookseller->id;
510
511
    Koha::Acquisition::Bookseller::Contact->new( { name => 'Leo Tolstoy', phone => '0123456x2', claimissues => 1, booksellerid => $booksellerid } )->store;
512
513
    my $bib = MARC::Record->new();
514
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
515
        $bib->append_fields(
516
            MARC::Field->new('011', ' ', ' ', a => 'xxxx-yyyy'),
517
            MARC::Field->new('200', ' ', ' ', a => 'Silence in the library'),
518
        );
519
    } else {
520
        $bib->append_fields(
521
            MARC::Field->new('022', ' ', ' ', a => 'xxxx-yyyy'),
522
            MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
523
        );
524
    }
525
    my ($biblionumber) = AddBiblio($bib, '');
526
527
    $dbh->do(q|UPDATE subscription_numberpatterns SET numberingmethod='No. {X}' WHERE id=1|);
528
    my $subscriptionid = NewSubscription(
529
         undef, "", $booksellerid, undef, undef, $biblionumber,
530
        '2013-01-01', 1, undef, undef,  undef,
531
        undef,  undef,  undef, undef, undef, undef,
532
        1, 'public',undef, '2013-01-01', undef, 1,
533
        undef, undef,  0, 'internal',  0,
534
        undef, undef, 0,  undef, '2013-12-31', 0
535
    );
536
537
    my ($serials_count, @serials) = GetSerials($subscriptionid);
538
    my  @serialids = ($serials[0]->{serialid});
539
540
    my $err;
541
    warning_like {
542
        $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ) }
543
        qr/^Bookseller .* without emails at/,
544
        "Warn on vendor without email address";
545
546
    $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
547
    $bookseller->contacts->next->email('testemail@mydomain.com')->store;
548
549
    # Ensure that the preference 'LetterLog' is set to logging
550
    t::lib::Mocks::mock_preference( 'LetterLog', 'on' );
551
552
    # SendAlerts needs branchemail or KohaAdminEmailAddress as sender
553
    C4::Context->_new_userenv('DUMMY');
554
    C4::Context->set_userenv( 0, 0, 0, 'firstname', 'surname', $library->{branchcode}, 'My Library', 0, '', '');
555
    t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
556
557
    {
558
    warning_is {
559
        $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) }
560
        "Fake sendmail",
561
        "SendAlerts is using the mocked sendmail routine (claimissues)";
562
    is($err, 1, "Successfully sent claim");
563
    is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim");
564
    is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", 'Serial claim letter for 1 issue constructed successfully');
565
    }
566
567
    {
568
    my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
569
    my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0];
570
    ModSerialStatus( $serials[0]->{serialid}, "No. 1", $publisheddate, $publisheddate, $publisheddate, '3', 'a note' );
571
    ($serials_count, @serials) = GetSerials($subscriptionid);
572
    push @serialids, ($serials[1]->{serialid});
573
574
    $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' );
575
    is($mail{'Message'}, "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy\n$serialids[1]|2013-01-01|Silence in the library|xxxx-yyyy", "Serial claim letter for 2 issues constructed successfully");
576
577
    $dbh->do(q{DELETE FROM letter WHERE code = 'TESTSERIALCLAIM';});
578
    warning_like {
579
        $err = SendAlerts( 'orderacquisition', $basketno , 'TESTSERIALCLAIM' ) }
580
        qr/No orderacquisition TESTSERIALCLAIM letter transported by email/,
581
        "GetPreparedLetter warns about missing notice template";
582
    is($err->{'error'}, 'no_letter', "No TESTSERIALCLAIM letter was defined");
583
    }
584
585
};
586
493
subtest 'GetPreparedLetter' => sub {
587
subtest 'GetPreparedLetter' => sub {
494
    plan tests => 4;
588
    plan tests => 4;
495
589
(-)a/tools/letter.pl (-10 / +1 lines)
Lines 230-244 sub add_form { Link Here
230
        push @{$field_selection}, add_fields('aqbooksellers', 'aqbasket', 'aqorders', 'biblio', 'biblioitems');
230
        push @{$field_selection}, add_fields('aqbooksellers', 'aqbasket', 'aqorders', 'biblio', 'biblioitems');
231
    }
231
    }
232
    elsif ($module eq 'claimissues') {
232
    elsif ($module eq 'claimissues') {
233
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
233
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription', 'biblio', 'biblioitems');
234
        push @{$field_selection},
235
        {
236
            value => q{},
237
            text => '---BIBLIO---'
238
        };
239
        foreach(qw(title author serial)) {
240
            push @{$field_selection}, {value => "biblio.$_", text => ucfirst $_ };
241
        }
242
    }
234
    }
243
    elsif ($module eq 'serial') {
235
    elsif ($module eq 'serial') {
244
        push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial');
236
        push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial');
245
- 

Return to bug 15971