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

(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 862-867 our $PERL_DEPS = { Link Here
862
        'required' => '0',
862
        'required' => '0',
863
        'min_ver'  => '0.07',
863
        'min_ver'  => '0.07',
864
    },
864
    },
865
    'CAM::PDF' => {
866
        'usage' => 'Tests',
867
        'required' => 0,
868
        'min_ver' => '1.60',
869
    },
865
};
870
};
866
871
867
1;
872
1;
(-)a/C4/Letters.pm (+79 lines)
Lines 26-31 use Encode; Link Here
26
use Carp;
26
use Carp;
27
use Template;
27
use Template;
28
use Module::Load::Conditional qw(can_load);
28
use Module::Load::Conditional qw(can_load);
29
use PDF::FromHTML;
29
30
30
use C4::Members;
31
use C4::Members;
31
use C4::Members::Attributes qw(GetBorrowerAttributes);
32
use C4::Members::Attributes qw(GetBorrowerAttributes);
Lines 37-42 use Koha::SMS::Providers; Link Here
37
38
38
use Koha::Email;
39
use Koha::Email;
39
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
40
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::Acquisition::Booksellers;
40
42
41
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
43
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
42
44
Lines 659-664 sub SendAlerts { Link Here
659
    return 1;
661
    return 1;
660
}
662
}
661
663
664
=head2 PrintClaimIssueNotice
665
666
Returns a 'claimissues' notice for given serial ids and letter code as PDF
667
668
    my $pdf = PrintClaimIssueNotice(\@serialids, $letter_code);
669
670
    print $cgi->header('application/pdf');
671
    print $pdf;
672
673
674
Returns undef if:
675
676
=over
677
678
=item * a parameter is missing
679
680
=item * C<@serialids> is empty
681
682
=item * C<@serialids> does not contain any existing serial id
683
684
=item * C<$letter_code> does not exist
685
686
=back
687
688
=cut
689
690
sub PrintClaimIssueNotice {
691
    my ($serialids, $letter_code) = @_;
692
693
    return unless ref $serialids eq 'ARRAY';
694
    return unless @$serialids > 0;
695
    return unless $letter_code;
696
697
    my $dbh = C4::Context->dbh;
698
699
    my $serialids_str = join(',', ('?') x @$serialids);
700
    my $serials = $dbh->selectall_arrayref(qq{
701
        SELECT subscription.*, biblio.*, serial.*
702
        FROM serial
703
        LEFT JOIN subscription ON serial.subscriptionid = subscription.subscriptionid
704
        LEFT JOIN biblio ON serial.biblionumber = biblio.biblionumber
705
        WHERE serial.serialid IN ($serialids_str)
706
    }, {Slice => {}}, @$serialids);
707
708
    return unless @$serials;
709
710
    my $booksellerid = $serials->[0]->{aqbooksellerid};
711
    my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid);
712
713
    my $userenv = C4::Context->userenv;
714
    my $letter = GetPreparedLetter(
715
        module => 'claimissues',
716
        letter_code => $letter_code,
717
        branchcode => $userenv->{branch},
718
        message_transport_type => 'print',
719
        tables => {
720
            'branches'    => $userenv->{branch},
721
            'aqbooksellers' => $bookseller->unblessed,
722
        },
723
        repeat => $serials,
724
        want_librarian => 1,
725
    ) or return;
726
727
    my $content = $letter->{content};
728
    if ($letter->{is_html}) {
729
        $content = _wrap_html($content, $letter->{title});
730
    }
731
732
    my $output = '';
733
    my $pdf = PDF::FromHTML->new(encoding => 'utf-8');
734
    $pdf->load_file(\$content);
735
    $pdf->convert();
736
    $pdf->write_file(\$output);
737
738
    return $output;
739
}
740
662
=head2 GetPreparedLetter( %params )
741
=head2 GetPreparedLetter( %params )
663
742
664
    %params hash:
743
    %params hash:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt (-1 / +24 lines)
Lines 124-129 Link Here
124
124
125
//]]>
125
//]]>
126
</script>
126
</script>
127
128
<script>
129
    $(document).ready(function() {
130
        $('#print-notification').on('click', function(e) {
131
            e.preventDefault();
132
            var form = $(this).parents('form')
133
            var op = form.find('input[name="op"]');
134
135
            op.val('print_alert');
136
            form.submit();
137
            op.val('send_alert');
138
        });
139
    });
140
</script>
127
</head>
141
</head>
128
<body id="ser_claims" class="ser">
142
<body id="ser_claims" class="ser">
129
    [% INCLUDE 'header.inc' %]
143
    [% INCLUDE 'header.inc' %]
Lines 307-313 Link Here
307
                    </select>
321
                    </select>
308
                    <input type="hidden" name="op" value="send_alert" />
322
                    <input type="hidden" name="op" value="send_alert" />
309
                    <input type="hidden" name="supplierid" value="[% supplierid %]" />
323
                    <input type="hidden" name="supplierid" value="[% supplierid %]" />
310
                    <input type="submit" name="submit" class="button" value="Send notification" />
324
                    <div class="btn-group">
325
                        <button type="submit" class="btn btn-default btn-xs">Send notification</button>
326
                        <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
327
                            <span class="caret"></span>
328
                            <span class="sr-only">Toggle dropdown</span>
329
                        </button>
330
                        <ul class="dropdown-menu">
331
                            <li><a id="print-notification" href="#">Print notification</a></li>
332
                        </ul>
333
                    </div>
311
                </fieldset>
334
                </fieldset>
312
            [% END %]
335
            [% END %]
313
        </form>
336
        </form>
(-)a/serials/claims.pl (-17 / +30 lines)
Lines 65-89 for my $field ( @$additional_fields ) { Link Here
65
}
65
}
66
66
67
67
68
my @serialnums=$input->multi_param('serialid');
68
my @serialnums = $input->multi_param('serialid');
69
if (@serialnums) { # i.e. they have been flagged to generate claims
69
if (@serialnums) { # i.e. they have been flagged to generate claims
70
    my $err;
70
    my $op = $input->param('op');
71
    eval {
71
    my $letter_code = $input->param('letter_code');
72
        $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
72
73
        if ( not ref $err or not exists $err->{error} ) {
73
    if ($op eq 'print_alert') {
74
            C4::Serials::updateClaim( \@serialnums );
74
        my $pdf = C4::Letters::PrintClaimIssueNotice(\@serialnums, $letter_code);
75
        }
75
        print $input->header(
76
    };
76
            -type => 'application/pdf',
77
    if ( $@ ) {
77
            -attachment => 'claims.pdf',
78
        $template->param(error_claim => $@);
78
        );
79
    } elsif ( ref $err and exists $err->{error} ) {
79
        print $pdf;
80
        if ( $err->{error} eq "no_email" ) {
80
        exit;
81
            $template->param( error_claim => 'no_vendor_email' );
82
        } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
83
            $template->param( error_claim => 'bad_or_missing_sender' );
84
        }
85
    } else {
81
    } else {
86
        $template->param( info_claim => 1 );
82
        my $err;
83
        eval {
84
            $err = SendAlerts('claimissues',\@serialnums, $letter_code);
85
            if ( not ref $err or not exists $err->{error} ) {
86
                C4::Serials::updateClaim( \@serialnums );
87
            }
88
        };
89
        if ( $@ ) {
90
            $template->param(error_claim => $@);
91
        } elsif ( ref $err and exists $err->{error} ) {
92
            if ( $err->{error} eq "no_email" ) {
93
                $template->param( error_claim => 'no_vendor_email' );
94
            } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
95
                $template->param( error_claim => 'bad_or_missing_sender' );
96
            }
97
        } else {
98
            $template->param( info_claim => 1 );
99
        }
87
    }
100
    }
88
}
101
}
89
102
(-)a/t/db_dependent/Letters.t (-2 / +41 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 => 82;
21
use Test::More tests => 83;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 45-50 use Koha::Database; Link Here
45
use Koha::DateUtils qw( dt_from_string output_pref );
45
use Koha::DateUtils qw( dt_from_string output_pref );
46
use Koha::Acquisition::Order;
46
use Koha::Acquisition::Order;
47
use Koha::Acquisition::Booksellers;
47
use Koha::Acquisition::Booksellers;
48
use Koha::Acquisition::Bookseller;
48
use Koha::Acquisition::Bookseller::Contacts;
49
use Koha::Acquisition::Bookseller::Contacts;
49
use Koha::Libraries;
50
use Koha::Libraries;
50
use Koha::Notice::Templates;
51
use Koha::Notice::Templates;
Lines 628-630 subtest 'SendQueuedMessages' => sub { Link Here
628
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
629
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
629
630
630
};
631
};
631
- 
632
633
subtest 'PrintClaimIssueNotice' => sub {
634
    plan tests => 6;
635
636
    my $bookseller = Koha::Acquisition::Bookseller->new()->store();
637
    my $subscriptionid = NewSubscription(undef, "", $bookseller->id, 0, undef,
638
        $biblionumber, '2013-01-01', 1, undef, undef, undef, undef, undef,
639
        undef, undef, undef, undef, 1, undef, undef, '2013-01-01', undef, 1,
640
        undef, undef, 0, undef, 0, undef, undef, 0, undef, '2013-12-31', 0);
641
    my ($serials_count, @serials) = GetSerials($subscriptionid);
642
643
    my $letter = 'CLAIMSERIAL';
644
    my $content = 'Date:<<subscription.firstacquidate>>';
645
    $dbh->do(qq{
646
        INSERT INTO letter
647
        (module, code, name, is_html, title, content, message_transport_type)
648
        VALUES
649
        ('claimissues', '$letter', 'Claim', 1, 'Claim', '$content', 'print')
650
    });
651
652
    my @serialids = map { $_->{serialid} } @serials;
653
    is(C4::Letters::PrintClaimIssueNotice(), undef, 'returns undef with no args');
654
    is(C4::Letters::PrintClaimIssueNotice(\@serialids), undef, 'returns undef with no letter code');
655
    is(C4::Letters::PrintClaimIssueNotice(undef, $letter), undef, 'returns undef with no serial ids');
656
    is(C4::Letters::PrintClaimIssueNotice([], $letter), undef, 'returns undef with no serial ids');
657
658
    my $pdf = C4::Letters::PrintClaimIssueNotice(\@serialids, $letter);
659
    is(substr($pdf, 0, 4), '%PDF', 'output is a PDF');
660
661
    SKIP: {
662
        eval { require CAM::PDF };
663
664
        skip "CAM::PDF is not installed", 1 if $@;
665
666
        my $cam = CAM::PDF->new($pdf);
667
        my $text = $cam->getPageContent(1);
668
        like($text, qr/Date:2013-01-01/, 'PDF contains Date:2013-01-01');
669
    }
670
};

Return to bug 18796