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

(-)a/C4/Reports/Guided.pm (-3 / +3 lines)
Lines 984-990 sub EmailReport { Link Here
984
    my $params     = shift;
984
    my $params     = shift;
985
    my $report_id  = $params->{report_id};
985
    my $report_id  = $params->{report_id};
986
    my $from       = $params->{from};
986
    my $from       = $params->{from};
987
    my $email      = $params->{email};
987
    my $email_col  = $params->{email} || 'email';
988
    my $module     = $params->{module};
988
    my $module     = $params->{module};
989
    my $code       = $params->{code};
989
    my $code       = $params->{code};
990
    my $branch     = $params->{branch} || "";
990
    my $branch     = $params->{branch} || "";
Lines 1017-1028 sub EmailReport { Link Here
1017
        my $email;
1017
        my $email;
1018
        my $err_count = scalar @errors;
1018
        my $err_count = scalar @errors;
1019
        push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber};
1019
        push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber};
1020
        push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( (defined $email && defined $row->{$email}) || defined $row->{email} );
1020
        push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( defined $row->{$email_col} );
1021
        push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} );
1021
        push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} );
1022
        push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}});
1022
        push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}});
1023
1023
1024
        my $from_address = $from || $row->{from};
1024
        my $from_address = $from || $row->{from};
1025
        my $to_address = $email ? $row->{$email} : $row->{email};
1025
        my $to_address = $row->{$email_col};
1026
        push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template );
1026
        push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template );
1027
        $counter++;
1027
        $counter++;
1028
        next if scalar @errors > $err_count; #If any problems, try next
1028
        next if scalar @errors > $err_count; #If any problems, try next
(-)a/t/db_dependent/Reports/Guided.t (-6 / +10 lines)
Lines 361-372 count(h.reservedate) AS 'holds' Link Here
361
361
362
subtest 'Email report test' => sub {
362
subtest 'Email report test' => sub {
363
363
364
    plan tests => 9;
364
    plan tests => 12;
365
365
366
    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber };
366
    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber };
367
    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber };
367
    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber };
368
    my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com' } })->{ borrowernumber };
368
    my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com', emailpro => undef } })->{ borrowernumber };
369
    my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
369
    my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email,emailpro FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
370
    my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id };
370
    my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id };
371
371
372
    my $letter1 = $builder->build({
372
    my $letter1 = $builder->build({
Lines 411-416 subtest 'Email report test' => sub { Link Here
411
    is( $emails->[0]{letter}->{content}, "mailer", "Message has expected content");
411
    is( $emails->[0]{letter}->{content}, "mailer", "Message has expected content");
412
    is( $emails->[1]{letter}->{content}, "norman", "Message has expected content");
412
    is( $emails->[1]{letter}->{content}, "norman", "Message has expected content");
413
413
414
    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code}, from => 'the@future.ooh', email => 'emailpro' });
415
    is_deeply( $errors, [{'NO_EMAIL_COL'=>3}],"We report missing email in emailpro column");
416
    is( $emails->[0]->{to_address}, 'b@c.com', "Message uses correct email");
417
    is( $emails->[1]->{to_address}, 'd@e.com', "Message uses correct email");
418
414
};
419
};
415
420
416
$schema->storage->txn_rollback;
421
$schema->storage->txn_rollback;
417
- 

Return to bug 24511