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

(-)a/C4/Members.pm (-21 lines)
Lines 85-92 BEGIN { Link Here
85
85
86
        &IssueSlip
86
        &IssueSlip
87
        GetBorrowersWithEmail
87
        GetBorrowersWithEmail
88
89
        GetOverduesForPatron
90
    );
88
    );
91
89
92
    #Modify data
90
    #Modify data
Lines 1658-1682 WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|; Link Here
1658
    return $cnt eq '0E0'? 0: $cnt;
1656
    return $cnt eq '0E0'? 0: $cnt;
1659
}
1657
}
1660
1658
1661
sub GetOverduesForPatron {
1662
    my ( $borrowernumber ) = @_;
1663
1664
    my $sql = "
1665
        SELECT *
1666
        FROM issues, items, biblio, biblioitems
1667
        WHERE items.itemnumber=issues.itemnumber
1668
          AND biblio.biblionumber   = items.biblionumber
1669
          AND biblio.biblionumber   = biblioitems.biblionumber
1670
          AND issues.borrowernumber = ?
1671
          AND date_due < NOW()
1672
    ";
1673
1674
    my $sth = C4::Context->dbh->prepare( $sql );
1675
    $sth->execute( $borrowernumber );
1676
1677
    return $sth->fetchall_arrayref({});
1678
}
1679
1680
END { }    # module clean-up code here (global destructor)
1659
END { }    # module clean-up code here (global destructor)
1681
1660
1682
1;
1661
1;
(-)a/Koha/Object.pm (-2 / +43 lines)
Lines 190-195 sub unblessed { Link Here
190
    return { $self->_result->get_columns };
190
    return { $self->_result->get_columns };
191
}
191
}
192
192
193
=head3 $object->unblessed_all_relateds
194
195
my $everything_into_one_hashref = $object->unblessed_all_relateds
196
197
The unblessed method only retrieves column' values for the column of the object.
198
In a *few* cases we want to retrieve the information of all the prefetched data.
199
200
=cut
201
202
sub unblessed_all_relateds {
203
    my ($self) = @_;
204
205
    my %data;
206
    my $related_resultsets = $self->_result->{related_resultsets} || {};
207
    my $rs = $self;
208
    while ( $related_resultsets and %$related_resultsets ) {
209
        my @relations = keys %{ $related_resultsets };
210
        if ( @relations ) {
211
            my $relation = $relations[0];
212
            $rs = $rs->related_resultset($relation)->get_cache;
213
            $rs = $rs->[0]; # Does it makes sense to have several values here?
214
            my $object_class = Koha::Object::_get_object_class( $rs->result_class );
215
            my $koha_object = $object_class->_new_from_dbic( $rs );
216
            $related_resultsets = $rs->{related_resultsets};
217
            %data = ( %data, %{ $koha_object->unblessed } );
218
        }
219
    }
220
    %data = ( %data, %{ $self->unblessed } );
221
    return \%data;
222
}
223
193
=head3 $object->_result();
224
=head3 $object->_result();
194
225
195
Returns the internal DBIC Row object
226
Returns the internal DBIC Row object
Lines 221-226 sub _columns { Link Here
221
    return $self->{_columns};
252
    return $self->{_columns};
222
}
253
}
223
254
255
sub _get_object_class {
256
    my ( $type ) = @_;
257
    return unless $type;
258
259
    if( $type->can('koha_object_class') ) {
260
        return $type->koha_object_class;
261
    }
262
    $type =~ s|Schema::Result::||;
263
    return ${type};
264
}
224
265
225
=head3 AUTOLOAD
266
=head3 AUTOLOAD
226
267
Lines 246-258 sub AUTOLOAD { Link Here
246
        }
287
        }
247
    }
288
    }
248
289
249
    my @known_methods = qw( is_changed id in_storage get_column );
290
    my @known_methods = qw( is_changed id in_storage get_column related_resultset );
250
291
251
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
292
    Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods;
252
293
253
    my $r = eval { $self->_result->$method(@_) };
294
    my $r = eval { $self->_result->$method(@_) };
254
    if ( $@ ) {
295
    if ( $@ ) {
255
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) );
296
        Koha::Exceptions::Object::MethodNotFound->throw( "No method $method for " . ref($self) . " " . $@ );
256
    }
297
    }
257
    return $r;
298
    return $r;
258
}
299
}
(-)a/Koha/Patron.pm (+24 lines)
Lines 449-454 sub add_enrolment_fee_if_needed { Link Here
449
    return $enrolment_fee || 0;
449
    return $enrolment_fee || 0;
450
}
450
}
451
451
452
=head3 get_overdues
453
454
my $overdue_items = $patron->get_overdues
455
456
Return the overdued items
457
458
=cut
459
460
sub get_overdues {
461
    my ($self) = @_;
462
    # FIXME add date_due < now
463
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
464
    my $issues = Koha::Issues->search(
465
        {
466
            'me.borrowernumber' => $self->borrowernumber,
467
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
468
        },
469
        {
470
            prefetch => { item => { biblio => 'biblioitems' } },
471
        }
472
    );
473
    return $issues;
474
}
475
452
=head3 type
476
=head3 type
453
477
454
=cut
478
=cut
(-)a/members/print_overdues.pl (-2 / +3 lines)
Lines 24-32 use CGI; Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Auth;
25
use C4::Auth;
26
use C4::Output;
26
use C4::Output;
27
use C4::Members qw(GetOverduesForPatron);
28
use C4::Overdues qw(parse_overdues_letter);
27
use C4::Overdues qw(parse_overdues_letter);
29
28
29
use Koha::Patrons;
30
30
my $input = new CGI;
31
my $input = new CGI;
31
32
32
my $flagsrequired = { circulate => "circulate_remaining_permissions" };
33
my $flagsrequired = { circulate => "circulate_remaining_permissions" };
Lines 45-51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
45
my $borrowernumber = $input->param('borrowernumber');
46
my $borrowernumber = $input->param('borrowernumber');
46
my $branchcode     = C4::Context->userenv->{'branch'};
47
my $branchcode     = C4::Context->userenv->{'branch'};
47
48
48
my $overdues = GetOverduesForPatron($borrowernumber);
49
my $overdues = Koha::Patrons->find($borrowernumber)->get_overdues->unblessed_all_relateds;
49
50
50
my $letter = parse_overdues_letter(
51
my $letter = parse_overdues_letter(
51
    {
52
    {
(-)a/t/db_dependent/Koha/Patrons.t (-8 / +15 lines)
Lines 516-522 subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Link Here
516
};
516
};
517
517
518
subtest 'get_overdues' => sub {
518
subtest 'get_overdues' => sub {
519
    plan tests => 3;
519
    plan tests => 7;
520
520
521
    my $library = $builder->build( { source => 'Branch' } );
521
    my $library = $builder->build( { source => 'Branch' } );
522
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
522
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
Lines 568-581 subtest 'get_overdues' => sub { Link Here
568
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
568
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
569
    AddIssue( $patron, $item_3->{barcode} );
569
    AddIssue( $patron, $item_3->{barcode} );
570
570
571
    my $overdues = C4::Members::GetOverduesForPatron( $patron->{borrowernumber} );
571
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
572
    is( @$overdues, 2, 'GetOverduesForPatron should return the correct number of elements' );
572
    my $overdues = $patron->get_overdues;
573
    is( $overdues->[0]->{itemnumber}, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
573
    is( $overdues->count, 2, 'Patron should have 2 overdues');
574
    is( $overdues->[1]->{itemnumber}, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
574
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
575
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
576
577
    my $o = $overdues->reset->next;
578
    my $unblessed_overdue = $o->unblessed_all_relateds;
579
    is( exists( $unblessed_overdue->{issuedate} ), 1, 'Fields from the issues table should be filled' );
580
    is( exists( $unblessed_overdue->{itemcallnumber} ), 1, 'Fields from the items table should be filled' );
581
    is( exists( $unblessed_overdue->{title} ), 1, 'Fields from the biblio table should be filled' );
582
    is( exists( $unblessed_overdue->{itemtype} ), 1, 'Fields from the biblioitems table should be filled' );
575
583
576
    # Clean stuffs
584
    # Clean stuffs
577
    Koha::Issues->search( { borrowernumber => $patron->{borrowernumber} } )->delete;
585
    Koha::Issues->search( { borrowernumber => $patron->borrowernumber } )->delete;
578
    Koha::Patrons->find( $patron->{borrowernumber} )->delete;
586
    $patron->delete;
579
};
587
};
580
588
581
$retrieved_patron_1->delete;
589
$retrieved_patron_1->delete;
582
- 

Return to bug 17553