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

(-)a/C4/Serials.pm (-36 / +11 lines)
Lines 75-81 BEGIN { Link Here
75
      &GetSerialInformation                   &AddItem2Serial
75
      &GetSerialInformation                   &AddItem2Serial
76
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
76
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
77
77
78
      &UpdateClaimdateIssues
79
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
78
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
80
      &GetDistributedTo   &SetDistributedTo
79
      &GetDistributedTo   &SetDistributedTo
81
      &getroutinglist     &delroutingmember   &addroutingmember
80
      &getroutinglist     &delroutingmember   &addroutingmember
Lines 259-292 sub AddItem2Serial { Link Here
259
    return $rq->rows;
258
    return $rq->rows;
260
}
259
}
261
260
262
=head2 UpdateClaimdateIssues
263
264
UpdateClaimdateIssues($serialids,[$date]);
265
266
Update Claimdate for issues in @$serialids list with date $date
267
(Take Today if none)
268
269
=cut
270
271
sub UpdateClaimdateIssues {
272
    my ( $serialids, $date ) = @_;
273
274
    return unless ($serialids);
275
276
    my $dbh = C4::Context->dbh;
277
    $date = strftime( "%Y-%m-%d", localtime ) unless ($date);
278
    my $query = "
279
        UPDATE serial
280
        SET claimdate = ?,
281
            status = ?,
282
            claims_count = claims_count + 1
283
        WHERE  serialid in (" . join( ",", map { '?' } @$serialids ) . ")
284
    ";
285
    my $rq = $dbh->prepare($query);
286
    $rq->execute($date, CLAIMED, @$serialids);
287
    return $rq->rows;
288
}
289
290
=head2 GetSubscription
261
=head2 GetSubscription
291
262
292
$subs = GetSubscription($subscriptionid)
263
$subs = GetSubscription($subscriptionid)
Lines 1878-1892 called from claims.pl file Link Here
1878
=cut
1849
=cut
1879
1850
1880
sub updateClaim {
1851
sub updateClaim {
1881
    my ($serialid) = @_;
1852
    my ($serialids) = @_;
1882
    my $dbh        = C4::Context->dbh;
1853
    return unless $serialids;
1883
    $dbh->do(q|
1854
    unless ( ref $serialids ) {
1855
        $serialids = [ $serialids ];
1856
    }
1857
    my $dbh = C4::Context->dbh;
1858
    return $dbh->do(q|
1884
        UPDATE serial
1859
        UPDATE serial
1885
        SET claimdate = NOW(),
1860
        SET claimdate = NOW(),
1886
            claims_count = claims_count + 1
1861
            claims_count = claims_count + 1,
1887
        WHERE serialid = ?
1862
            status = CLAIMED
1888
    |, {}, $serialid );
1863
        WHERE serialid in (| . join( q|,|, (q|?|) x @$serialids ) . q|)|,
1889
    return;
1864
        {}, @$serialids );
1890
}
1865
}
1891
1866
1892
=head2 getsupplierbyserialid
1867
=head2 getsupplierbyserialid
(-)a/serials/claims.pl (-1 / +1 lines)
Lines 73-79 if (@serialnums) { # i.e. they have been flagged to generate claims Link Here
73
    eval {
73
    eval {
74
        $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
74
        $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
75
        if ( not ref $err or not exists $err->{error} ) {
75
        if ( not ref $err or not exists $err->{error} ) {
76
           UpdateClaimdateIssues(\@serialnums);
76
            C4::Serials::updateClaim( \@serialnums );
77
        }
77
        }
78
    };
78
    };
79
    if ( $@ ) {
79
    if ( $@ ) {
(-)a/t/db_dependent/Serials.t (-4 / +1 lines)
Lines 15-21 use C4::Bookseller; Link Here
15
use C4::Biblio;
15
use C4::Biblio;
16
use C4::Budgets;
16
use C4::Budgets;
17
use Koha::DateUtils;
17
use Koha::DateUtils;
18
use Test::More tests => 45;
18
use Test::More tests => 43;
19
19
20
BEGIN {
20
BEGIN {
21
    use_ok('C4::Serials');
21
    use_ok('C4::Serials');
Lines 151-157 if ($old_frequency) { Link Here
151
151
152
# Test calling subs without parameters
152
# Test calling subs without parameters
153
is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
153
is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
154
is(C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date');
155
is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
154
is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
156
is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
155
is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
157
is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number');
156
is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number');
Lines 180-187 is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has Link Here
180
179
181
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
180
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
182
181
183
is(C4::Serials::updateClaim(),undef, 'test updating claim');
184
185
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
182
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
186
183
187
is(C4::Serials::check_routing(), undef, 'test checking route');
184
is(C4::Serials::check_routing(), undef, 'test checking route');
(-)a/t/db_dependent/Serials/Claims.t (-2 / +13 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 13;
2
use Test::More tests => 17;
3
3
4
use C4::Acquisition;
4
use C4::Acquisition;
5
use C4::Bookseller;
5
use C4::Bookseller;
Lines 135-140 is( exists $late_or_missing_issues[0]->{claimdate}, 1, 'GetLateOrMissingIssues r Link Here
135
is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' );
135
is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' );
136
is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' );
136
is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' );
137
137
138
is( updateClaim(), undef, 'updateClaim should return undef if not param passed' );
138
my $serialid_to_claim = $late_or_missing_issues[0]->{serialid};
139
my $serialid_to_claim = $late_or_missing_issues[0]->{serialid};
139
updateClaim( $serialid_to_claim );
140
updateClaim( $serialid_to_claim );
140
141
Lines 144-149 is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late Link Here
144
my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues;
145
my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues;
145
is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
146
is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
146
147
148
my @serials_to_claim = map { $_->{serialid} } @late_or_missing_issues;
149
updateClaim( \@serials_to_claim );
150
@late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
151
is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late' );
152
153
( $serial_claimed ) = grep { ($_->{serialid} == $serials_to_claim[0]) ? $_ : () } @late_or_missing_issues;
154
is( $serial_claimed->{claims_count}, 2, 'The serial should have been claimed' );
155
( $serial_claimed ) = grep { ($_->{serialid} == $serials_to_claim[1]) ? $_ : () } @late_or_missing_issues;
156
is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
157
158
147
my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
159
my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
148
# FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format!
160
# FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format!
149
#is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' );
161
#is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' );
150
- 

Return to bug 12178