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

(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-21 / +36 lines)
Lines 251-293 Items and holds from other libraries will still be included for the given patron Link Here
251
=cut
251
=cut
252
252
253
sub GetOverdueIssues {
253
sub GetOverdueIssues {
254
    my ( $patron_branchcode ) = @_;
254
    my ($patron_branchcode) = @_;
255
255
256
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = '$patron_branchcode'" : q{};
256
    my $patron_branchcode_filter = $patron_branchcode ? "AND borrowers.branchcode = '$patron_branchcode'" : q{};
257
257
258
    my $query = "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
258
    my $query =
259
        "SELECT borrowers.borrowernumber, borrowers.cardnumber, borrowers.title as patron_title, borrowers.firstname, borrowers.surname,
259
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
260
                borrowers.phone, borrowers.email, borrowers.branchcode, biblio.biblionumber, biblio.title, items.barcode, issues.date_due,
260
                max(overduerules.branchcode) as rulebranch, TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, delay1, delay2, delay3,
261
                TO_DAYS(NOW())-TO_DAYS(date_due) as daysoverdue, borrowers.categorycode as categorycode, items.itemtype as itemtype,
261
                issues.branchcode as site, branches.branchname as site_name
262
                issues.branchcode as site, branches.branchname as site_name
262
                FROM borrowers JOIN issues USING (borrowernumber)
263
                FROM borrowers JOIN issues USING (borrowernumber)
263
                JOIN items USING (itemnumber)
264
                JOIN items USING (itemnumber)
264
                JOIN biblio USING (biblionumber)
265
                JOIN biblio USING (biblionumber)
265
                JOIN branches ON (issues.branchcode = branches.branchcode)
266
                JOIN branches ON (issues.branchcode = branches.branchcode)
266
                JOIN overduerules USING (categorycode)
267
                WHERE ( overduerules.branchcode = borrowers.branchcode )
267
                JOIN overduerules_transport_types USING ( overduerules_id )
268
                WHERE ( overduerules.branchcode = borrowers.branchcode or overduerules.branchcode = '')
269
                AND overduerules_transport_types.message_transport_type = 'itiva'
270
                AND ( (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay1
271
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay2
272
                  OR  (TO_DAYS(NOW())-TO_DAYS(date_due) ) = delay3 )
273
                $patron_branchcode_filter
268
                $patron_branchcode_filter
274
                GROUP BY items.itemnumber
269
                GROUP BY items.itemnumber
270
                ORDER BY items.itemtype, borrowers.categorycode, branches.branchcode
275
                ";
271
                ";
276
    my $sth = $dbh->prepare($query);
272
    my $sth = $dbh->prepare($query);
277
    $sth->execute();
273
    $sth->execute();
274
275
    my @trigger_numbers;
276
    my $triggers = Koha::CirculationRules->search(
277
        { rule_name => { 'like' => 'overdue_%_mtt' }, rule_value => { like => '%itiva%' } } );
278
    for my $trigger ( $triggers->all ) {
279
        my $trigger_number = $trigger->rule_name;
280
        $trigger_number =~ s/(.*)(\d+)(.*)/\2/;
281
        push @trigger_numbers, $trigger_number unless grep { $_ == $trigger_number } @trigger_numbers;
282
    }
283
    my @rules = map { "overdue_$_" . "delay", "overdue_$_" . "notice", "overdue_$_" . "mtt" } @trigger_numbers;
284
278
    my @results;
285
    my @results;
279
    while ( my $issue = $sth->fetchrow_hashref() ) {
286
    while ( my $issue = $sth->fetchrow_hashref() ) {
280
        if ( $issue->{'daysoverdue'} == $issue->{'delay1'} ) {
287
        my $effective_rules = Koha::CirculationRules->get_effective_rules(
281
            $issue->{'level'} = 1;
288
            {
282
        } elsif ( $issue->{'daysoverdue'} == $issue->{'delay2'} ) {
289
                categorycode => $issue->{'categorycode'},
283
            $issue->{'level'} = 2;
290
                branchcode   => $issue->{'branchcode'},
284
        } elsif ( $issue->{'daysoverdue'} == $issue->{'delay3'} ) {
291
                itemtype     => $issue->{'itemtype'},
285
            $issue->{'level'} = 3;
292
                rules        => \@rules
286
        } else {
293
            }
287
294
        );
288
            # this shouldn't ever happen, based our SQL criteria
295
296
        my $i = 1;
297
        PERIOD while (1) {
298
            last PERIOD if ( !defined( $effective_rules->{ "overdue_$i" . 'delay' } ) );
299
            if (   $effective_rules->{ "overdue_$i" . 'mtt' } =~ /itiva/
300
                && $issue->{'daysoverdue'} == $effective_rules->{ "overdue_$i" . 'delay' } )
301
            {
302
                $issue->{'level'} = $i;
303
                push @results, $issue;
304
            }
305
            $i++;
289
        }
306
        }
290
        push @results, $issue;
291
    }
307
    }
292
    return @results;
308
    return @results;
293
}
309
}
294
- 

Return to bug 10190