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

(-)a/C4/Serials.pm (-36 / +11 lines)
Lines 77-83 BEGIN { Link Here
77
      &GetSerialInformation                   &AddItem2Serial
77
      &GetSerialInformation                   &AddItem2Serial
78
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
78
      &PrepareSerialsData &GetNextExpected    &ModNextExpected
79
79
80
      &UpdateClaimdateIssues
81
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
80
      &GetSuppliersWithLateIssues             &getsupplierbyserialid
82
      &GetDistributedTo   &SetDistributedTo
81
      &GetDistributedTo   &SetDistributedTo
83
      &getroutinglist     &delroutingmember   &addroutingmember
82
      &getroutinglist     &delroutingmember   &addroutingmember
Lines 261-294 sub AddItem2Serial { Link Here
261
    return $rq->rows;
260
    return $rq->rows;
262
}
261
}
263
262
264
=head2 UpdateClaimdateIssues
265
266
UpdateClaimdateIssues($serialids,[$date]);
267
268
Update Claimdate for issues in @$serialids list with date $date
269
(Take Today if none)
270
271
=cut
272
273
sub UpdateClaimdateIssues {
274
    my ( $serialids, $date ) = @_;
275
276
    return unless ($serialids);
277
278
    my $dbh = C4::Context->dbh;
279
    $date = strftime( "%Y-%m-%d", localtime ) unless ($date);
280
    my $query = "
281
        UPDATE serial
282
        SET claimdate = ?,
283
            status = ?,
284
            claims_count = claims_count + 1
285
        WHERE  serialid in (" . join( ",", map { '?' } @$serialids ) . ")
286
    ";
287
    my $rq = $dbh->prepare($query);
288
    $rq->execute($date, CLAIMED, @$serialids);
289
    return $rq->rows;
290
}
291
292
=head2 GetSubscription
263
=head2 GetSubscription
293
264
294
$subs = GetSubscription($subscriptionid)
265
$subs = GetSubscription($subscriptionid)
Lines 1895-1909 called from claims.pl file Link Here
1895
=cut
1866
=cut
1896
1867
1897
sub updateClaim {
1868
sub updateClaim {
1898
    my ($serialid) = @_;
1869
    my ($serialids) = @_;
1899
    my $dbh        = C4::Context->dbh;
1870
    return unless $serialids;
1900
    $dbh->do(q|
1871
    unless ( ref $serialids ) {
1872
        $serialids = [ $serialids ];
1873
    }
1874
    my $dbh = C4::Context->dbh;
1875
    return $dbh->do(q|
1901
        UPDATE serial
1876
        UPDATE serial
1902
        SET claimdate = NOW(),
1877
        SET claimdate = NOW(),
1903
            claims_count = claims_count + 1
1878
            claims_count = claims_count + 1,
1904
        WHERE serialid = ?
1879
            status = ?
1905
    |, {}, $serialid );
1880
        WHERE serialid in (| . join( q|,|, (q|?|) x @$serialids ) . q|)|,
1906
    return;
1881
        {}, CLAIMED, @$serialids );
1907
}
1882
}
1908
1883
1909
=head2 getsupplierbyserialid
1884
=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 => 48;
18
use Test::More tests => 46;
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 182-189 is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has Link Here
182
181
183
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
182
is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
184
183
185
is(C4::Serials::updateClaim(),undef, 'test updating claim');
186
187
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
184
is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
188
185
189
is(C4::Serials::check_routing(), undef, 'test checking route');
186
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