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

(-)a/C4/Serials.pm (-32 / +45 lines)
Lines 1373-1409 sub NewSubscription { Link Here
1373
    ) = @_;
1373
    ) = @_;
1374
    my $dbh = C4::Context->dbh;
1374
    my $dbh = C4::Context->dbh;
1375
1375
1376
    $_ ||= undef # Set to undef for integer values, not empty string
1376
    my $subscription = Koha::Subscription->new(
1377
      for (
1377
        {
1378
        $aqbooksellerid, $lastvalue1, $innerloop1, $lastvalue2,
1378
            librarian         => $auser,
1379
        $innerloop2,     $lastvalue3, $innerloop3,
1379
            branchcode        => $branchcode,
1380
      );
1380
            aqbooksellerid    => $aqbooksellerid,
1381
    #save subscription (insert into database)
1381
            cost              => $cost,
1382
    my $query = qq|
1382
            aqbudgetid        => $aqbudgetid,
1383
        INSERT INTO subscription
1383
            biblionumber      => $biblionumber,
1384
            (librarian, branchcode, aqbooksellerid, cost, aqbudgetid,
1384
            startdate         => $startdate,
1385
            biblionumber, startdate, periodicity, numberlength, weeklength,
1385
            periodicity       => $periodicity,
1386
            monthlength, lastvalue1, innerloop1, lastvalue2, innerloop2,
1386
            numberlength      => $numberlength,
1387
            lastvalue3, innerloop3, status, notes, letter, firstacquidate,
1387
            weeklength        => $weeklength,
1388
            irregularity, numberpattern, locale, callnumber,
1388
            monthlength       => $monthlength,
1389
            manualhistory, internalnotes, serialsadditems, staffdisplaycount,
1389
            lastvalue1        => $lastvalue1,
1390
            opacdisplaycount, graceperiod, location, enddate, skip_serialseq,
1390
            innerloop1        => $innerloop1,
1391
            itemtype, previousitemtype, mana_id)
1391
            lastvalue2        => $lastvalue2,
1392
        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?)
1392
            innerloop2        => $innerloop2,
1393
        |;
1393
            lastvalue3        => $lastvalue3,
1394
    my $sth = $dbh->prepare($query);
1394
            innerloop3        => $innerloop3,
1395
    $sth->execute(
1395
            status            => $status,
1396
        $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber,
1396
            notes             => $notes,
1397
        $startdate, $periodicity, $numberlength, $weeklength,
1397
            letter            => $letter,
1398
        $monthlength, $lastvalue1, $innerloop1, $lastvalue2, $innerloop2,
1398
            firstacquidate    => $firstacquidate,
1399
        $lastvalue3, $innerloop3, $status, $notes, $letter,
1399
            irregularity      => $irregularity,
1400
        $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber,
1400
            numberpattern     => $numberpattern,
1401
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
1401
            locale            => $locale,
1402
        $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq,
1402
            callnumber        => $callnumber,
1403
        $itemtype, $previousitemtype, $mana_id
1403
            manualhistory     => $manualhistory,
1404
    );
1404
            internalnotes     => $internalnotes,
1405
1405
            serialsadditems   => $serialsadditems,
1406
    my $subscriptionid = $dbh->{'mysql_insertid'};
1406
            staffdisplaycount => $staffdisplaycount,
1407
            opacdisplaycount  => $opacdisplaycount,
1408
            graceperiod       => $graceperiod,
1409
            location          => $location,
1410
            enddate           => $enddate,
1411
            skip_serialseq    => $skip_serialseq,
1412
            itemtype          => $itemtype,
1413
            previousitemtype  => $previousitemtype,
1414
            mana_id           => $mana_id,
1415
        }
1416
    )->store;
1417
    $subscription->discard_changes;
1418
    my $subscriptionid = $subscription->subscriptionid;
1419
    my ( $query, $sth );
1407
    unless ($enddate) {
1420
    unless ($enddate) {
1408
        $enddate = GetExpirationDate( $subscriptionid, $startdate );
1421
        $enddate = GetExpirationDate( $subscriptionid, $startdate );
1409
        $query = qq|
1422
        $query = qq|
Lines 1425-1431 sub NewSubscription { Link Here
1425
    $sth->execute( $biblionumber, $subscriptionid, $startdate);
1438
    $sth->execute( $biblionumber, $subscriptionid, $startdate);
1426
1439
1427
    # reread subscription to get a hash (for calculation of the 1st issue number)
1440
    # reread subscription to get a hash (for calculation of the 1st issue number)
1428
    my $subscription = GetSubscription($subscriptionid);
1441
    $subscription = GetSubscription($subscriptionid); # We should not do that
1429
    my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1442
    my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
1430
1443
1431
    # calculate issue number
1444
    # calculate issue number
(-)a/t/db_dependent/Serials.t (-2 / +14 lines)
Lines 18-24 use Koha::DateUtils; Link Here
18
use Koha::Acquisition::Booksellers;
18
use Koha::Acquisition::Booksellers;
19
use t::lib::Mocks;
19
use t::lib::Mocks;
20
use t::lib::TestBuilder;
20
use t::lib::TestBuilder;
21
use Test::More tests => 47;
21
use Test::More tests => 48;
22
22
23
BEGIN {
23
BEGIN {
24
    use_ok('C4::Serials');
24
    use_ok('C4::Serials');
Lines 349-351 subtest "Do not generate an expected if one already exists" => sub { Link Here
349
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
349
    @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
350
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
350
    is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
351
};
351
};
352
- 
352
353
subtest "NewSubscription" => sub {
354
    plan tests => 1;
355
    my $subscriptionid = NewSubscription(
356
        "",      "",     "", "", $budget_id, $biblionumber,
357
        '2013-01-01', $frequency_id, "", "",  "",
358
        "",      "",  "", "", "", "",
359
        1,          $notes,"", '2013-01-01', "", $pattern_id,
360
        "",       "",  0,    $internalnotes,  0,
361
        "", "", 0,          "",         '2013-12-31', 0
362
    );
363
    ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface");
364
};

Return to bug 22812