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

(-)a/C4/Acquisition.pm (-22 / +323 lines)
Lines 921-927 sub GetPendingOrders { Link Here
921
921
922
  @orders = &GetOrders($basketnumber, $orderby);
922
  @orders = &GetOrders($basketnumber, $orderby);
923
923
924
Looks up the pending (non-cancelled) orders with the given basket
924
Looks up non-cancelled orders (pending and received) with the given basket
925
number. If C<$booksellerID> is non-empty, only orders from that seller
925
number. If C<$booksellerID> is non-empty, only orders from that seller
926
are returned.
926
are returned.
927
927
Lines 929-957 return : Link Here
929
C<&basket> returns a two-element array. C<@orders> is an array of
929
C<&basket> returns a two-element array. C<@orders> is an array of
930
references-to-hash, whose keys are the fields from the aqorders,
930
references-to-hash, whose keys are the fields from the aqorders,
931
biblio, and biblioitems tables in the Koha database.
931
biblio, and biblioitems tables in the Koha database.
932
If the record have been suppressed, its biblionumber is only returned in deletedbiblionumber column.
932
933
933
=cut
934
=cut
934
935
935
sub GetOrders {
936
sub GetOrders {
936
    my ( $basketno, $orderby ) = @_;
937
    my ( $basketno, $orderby ) = @_;
937
    my $dbh   = C4::Context->dbh;
938
    my $dbh   = C4::Context->dbh;
939
    # get all the fields of biblio, and all of biblioitems, except marc (marc blob) and timestamp
940
    # timestamp is used in biblio and in aqorders, so rename biblio.timestamp into biblio_timestamp
941
    # notes are used in biblio, biblioitems and aqorders. Rename biblio.notes and biblio into biblio_notes and biblioitems_notes
938
    my $query  ="
942
    my $query  ="
939
        SELECT biblio.*,biblioitems.*,
943
        SELECT  all_biblio.*,
944
                all_biblioitems.*,
940
                aqorders.*,
945
                aqorders.*,
941
                aqbudgets.*,
946
                aqbudgets.*,
942
                biblio.title,
943
                aqorders_transfers.ordernumber_from AS transferred_from,
947
                aqorders_transfers.ordernumber_from AS transferred_from,
944
                aqorders_transfers.timestamp AS transferred_from_timestamp
948
                aqorders_transfers.timestamp AS transferred_from_timestamp
945
        FROM    aqorders
949
        FROM    aqorders
946
            LEFT JOIN aqbudgets        ON aqbudgets.budget_id = aqorders.budget_id
950
            LEFT JOIN aqbudgets          ON aqbudgets.budget_id = aqorders.budget_id
947
            LEFT JOIN biblio           ON biblio.biblionumber = aqorders.biblionumber
951
            LEFT JOIN (
948
            LEFT JOIN biblioitems      ON biblioitems.biblionumber =biblio.biblionumber
952
                SELECT biblionumber,
953
                       frameworkcode,
954
                       author,
955
                       title,
956
                       unititle,
957
                       notes AS biblio_notes,
958
                       serial,
959
                       seriestitle,
960
                       copyrightdate,
961
                       timestamp AS biblio_timestamp,
962
                       datecreated,
963
                       abstract
964
                FROM biblio
965
                UNION ALL
966
                SELECT biblionumber,
967
                       frameworkcode,
968
                       author,
969
                       title,
970
                       unititle,
971
                       notes AS biblio_notes,
972
                       serial,
973
                       seriestitle,
974
                       copyrightdate,
975
                       timestamp AS biblio_timestamp,
976
                       datecreated,
977
                       abstract
978
                FROM deletedbiblio
979
            ) AS all_biblio              ON ((all_biblio.biblionumber=aqorders.biblionumber) OR (all_biblio.biblionumber=aqorders.deletedbiblionumber))
980
            LEFT JOIN (
981
                SELECT biblionumber,
982
                       biblioitemnumber,
983
                       volume,
984
                       number,
985
                       itemtype,
986
                       isbn,
987
                       issn,
988
                       ean,
989
                       publicationyear,
990
                       publishercode,
991
                       volumedate,
992
                       volumedesc,
993
                       collectiontitle,
994
                       collectionissn,
995
                       collectionvolume,
996
                       editionstatement,
997
                       editionresponsibility,
998
                       illus,
999
                       pages,
1000
                       notes AS biblioitems_notes,
1001
                       size,
1002
                       place,
1003
                       lccn,
1004
                       marc,
1005
                       url,
1006
                       cn_source,
1007
                       cn_class,
1008
                       cn_item,
1009
                       cn_suffix,
1010
                       cn_sort,
1011
                       agerestriction,
1012
                       totalissues,
1013
                       marcxml
1014
                FROM biblioitems
1015
                UNION ALL
1016
                SELECT biblionumber,
1017
                       biblioitemnumber,
1018
                       volume,
1019
                       number,
1020
                       itemtype,
1021
                       isbn,
1022
                       issn,
1023
                       ean,
1024
                       publicationyear,
1025
                       publishercode,
1026
                       volumedate,
1027
                       volumedesc,
1028
                       collectiontitle,
1029
                       collectionissn,
1030
                       collectionvolume,
1031
                       editionstatement,
1032
                       editionresponsibility,
1033
                       illus,
1034
                       pages,
1035
                       notes AS biblioitems_notes,
1036
                       size,
1037
                       place,
1038
                       lccn,
1039
                       marc,
1040
                       url,
1041
                       cn_source,
1042
                       cn_class,
1043
                       cn_item,
1044
                       cn_suffix,
1045
                       cn_sort,
1046
                       agerestriction,
1047
                       totalissues,
1048
                       marcxml
1049
                FROM deletedbiblioitems
1050
            ) AS all_biblioitems         ON ((all_biblioitems.biblionumber=aqorders.biblionumber) OR (all_biblioitems.biblionumber=aqorders.deletedbiblionumber))
949
            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
1051
            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber
950
        WHERE   basketno=?
1052
        WHERE   basketno=?
951
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
1053
            AND (datecancellationprinted IS NULL OR datecancellationprinted='0000-00-00')
952
    ";
1054
    ";
953
1055
    $orderby = "all_biblioitems.publishercode,all_biblio.title" unless $orderby;
954
    $orderby = "biblioitems.publishercode,biblio.title" unless $orderby;
955
    $query .= " ORDER BY $orderby";
1056
    $query .= " ORDER BY $orderby";
956
    my $sth = $dbh->prepare($query);
1057
    my $sth = $dbh->prepare($query);
957
    $sth->execute($basketno);
1058
    $sth->execute($basketno);
Lines 1005-1023 Looks up an order by order number. Link Here
1005
1106
1006
Returns a reference-to-hash describing the order. The keys of
1107
Returns a reference-to-hash describing the order. The keys of
1007
C<$order> are fields from the biblio, biblioitems, aqorders tables of the Koha database.
1108
C<$order> are fields from the biblio, biblioitems, aqorders tables of the Koha database.
1109
If the record have been suppressed, its biblionumber is only returned in deletedbiblionumber column.
1008
1110
1009
=cut
1111
=cut
1010
1112
1011
sub GetOrder {
1113
sub GetOrder {
1012
    my ($ordernumber) = @_;
1114
    my ($ordernumber) = @_;
1013
    my $dbh      = C4::Context->dbh;
1115
    my $dbh      = C4::Context->dbh;
1116
    # get all the fields of biblio, and all of biblioitems, except marc (marc blob) and timestamp
1117
    # timestamp is used in biblio and in aqorders, so rename biblio.timestamp into biblio_timestamp
1118
    # notes are used in biblio, biblioitems and aqorders. Rename biblio.notes and biblio into biblio_notes and biblioitems_notes
1014
    my $query = "
1119
    my $query = "
1015
        SELECT biblioitems.*, biblio.*, aqorders.*
1120
        SELECT all_biblio.*, all_biblioitems.*,
1121
               aqorders.*
1016
        FROM   aqorders
1122
        FROM   aqorders
1017
        LEFT JOIN biblio on           biblio.biblionumber=aqorders.biblionumber
1123
        LEFT JOIN (
1018
        LEFT JOIN biblioitems on       biblioitems.biblionumber=aqorders.biblionumber
1124
                SELECT biblionumber,
1125
                       frameworkcode,
1126
                       author,
1127
                       title,
1128
                       unititle,
1129
                       notes AS biblio_notes,
1130
                       serial,
1131
                       seriestitle,
1132
                       copyrightdate,
1133
                       timestamp AS biblio_timestamp,
1134
                       datecreated,
1135
                       abstract
1136
                FROM biblio
1137
                UNION ALL
1138
                SELECT biblionumber,
1139
                       frameworkcode,
1140
                       author,
1141
                       title,
1142
                       unititle,
1143
                       notes AS biblio_notes,
1144
                       serial,
1145
                       seriestitle,
1146
                       copyrightdate,
1147
                       timestamp AS biblio_timestamp,
1148
                       datecreated,
1149
                       abstract
1150
                FROM deletedbiblio
1151
            ) AS all_biblio              ON ((all_biblio.biblionumber=aqorders.biblionumber) OR (all_biblio.biblionumber=aqorders.deletedbiblionumber))
1152
            LEFT JOIN (
1153
                SELECT biblionumber,
1154
                       biblioitemnumber,
1155
                       volume,
1156
                       number,
1157
                       itemtype,
1158
                       isbn,
1159
                       issn,
1160
                       ean,
1161
                       publicationyear,
1162
                       publishercode,
1163
                       volumedate,
1164
                       volumedesc,
1165
                       collectiontitle,
1166
                       collectionissn,
1167
                       collectionvolume,
1168
                       editionstatement,
1169
                       editionresponsibility,
1170
                       illus,
1171
                       pages,
1172
                       notes AS biblioitems_notes,
1173
                       size,
1174
                       place,
1175
                       lccn,
1176
                       marc,
1177
                       url,
1178
                       cn_source,
1179
                       cn_class,
1180
                       cn_item,
1181
                       cn_suffix,
1182
                       cn_sort,
1183
                       agerestriction,
1184
                       totalissues,
1185
                       marcxml
1186
                FROM biblioitems
1187
                UNION ALL
1188
                SELECT biblionumber,
1189
                       biblioitemnumber,
1190
                       volume,
1191
                       number,
1192
                       itemtype,
1193
                       isbn,
1194
                       issn,
1195
                       ean,
1196
                       publicationyear,
1197
                       publishercode,
1198
                       volumedate,
1199
                       volumedesc,
1200
                       collectiontitle,
1201
                       collectionissn,
1202
                       collectionvolume,
1203
                       editionstatement,
1204
                       editionresponsibility,
1205
                       illus,
1206
                       pages,
1207
                       notes AS biblioitems_notes,
1208
                       size,
1209
                       place,
1210
                       lccn,
1211
                       marc,
1212
                       url,
1213
                       cn_source,
1214
                       cn_class,
1215
                       cn_item,
1216
                       cn_suffix,
1217
                       cn_sort,
1218
                       agerestriction,
1219
                       totalissues,
1220
                       marcxml
1221
                FROM deletedbiblioitems
1222
            ) AS all_biblioitems         ON ((all_biblioitems.biblionumber=aqorders.biblionumber) OR (all_biblioitems.biblionumber=aqorders.deletedbiblionumber))
1019
        WHERE aqorders.ordernumber=?
1223
        WHERE aqorders.ordernumber=?
1020
1021
    ";
1224
    ";
1022
    my $sth= $dbh->prepare($query);
1225
    my $sth= $dbh->prepare($query);
1023
    $sth->execute($ordernumber);
1226
    $sth->execute($ordernumber);
Lines 1026-1031 sub GetOrder { Link Here
1026
    return $data;
1229
    return $data;
1027
}
1230
}
1028
1231
1232
1029
=head3 GetLastOrderNotReceivedFromSubscriptionid
1233
=head3 GetLastOrderNotReceivedFromSubscriptionid
1030
1234
1031
  $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid);
1235
  $order = &GetLastOrderNotReceivedFromSubscriptionid($subscriptionid);
Lines 1113-1120 Else, the upcoming July 1st is used. Link Here
1113
1317
1114
=item defaults entrydate to Now
1318
=item defaults entrydate to Now
1115
1319
1116
The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id".
1320
The following keys are used: "biblionumber", "basketno", "quantity", "notes", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "budget_id".
1117
1118
=back
1321
=back
1119
1322
1120
=cut
1323
=cut
Lines 1257-1263 sub ModItemOrder { Link Here
1257
1460
1258
  my @orders = GetCancelledOrders($basketno, $orderby);
1461
  my @orders = GetCancelledOrders($basketno, $orderby);
1259
1462
1260
Returns cancelled orders for a basket
1463
Returns cancelled orders for a basket.
1464
If the record have been suppressed, its biblionumber is only retuned in deletedbiblionumber column.
1261
1465
1262
=cut
1466
=cut
1263
1467
Lines 1269-1285 sub GetCancelledOrders { Link Here
1269
    my $dbh   = C4::Context->dbh;
1473
    my $dbh   = C4::Context->dbh;
1270
    my $query = "
1474
    my $query = "
1271
        SELECT
1475
        SELECT
1272
            biblio.*,
1476
            all_biblio.*,
1273
            biblioitems.*,
1477
            all_biblioitems.*,
1274
            aqorders.*,
1478
            aqorders.*,
1275
            aqbudgets.*,
1479
            aqbudgets.*,
1276
            aqorders_transfers.ordernumber_to AS transferred_to,
1480
            aqorders_transfers.ordernumber_to AS transferred_to,
1277
            aqorders_transfers.timestamp AS transferred_to_timestamp
1481
            aqorders_transfers.timestamp AS transferred_to_timestamp
1278
        FROM aqorders
1482
        FROM aqorders
1279
          LEFT JOIN aqbudgets   ON aqbudgets.budget_id = aqorders.budget_id
1483
            LEFT JOIN aqbudgets   ON aqbudgets.budget_id = aqorders.budget_id
1280
          LEFT JOIN biblio      ON biblio.biblionumber = aqorders.biblionumber
1484
            LEFT JOIN (
1281
          LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
1485
                SELECT biblionumber,
1282
          LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_from = aqorders.ordernumber
1486
                    frameworkcode,
1487
                    author,
1488
                    title,
1489
                    unititle,
1490
                    notes AS biblio_notes,
1491
                    serial,
1492
                    seriestitle,
1493
                    copyrightdate,
1494
                    timestamp AS biblio_timestamp,
1495
                    datecreated,
1496
                    abstract
1497
                FROM biblio
1498
                UNION ALL
1499
                SELECT biblionumber,
1500
                    frameworkcode,
1501
                    author,
1502
                    title,
1503
                    unititle,
1504
                    notes AS biblio_notes,
1505
                    serial,
1506
                    seriestitle,
1507
                    copyrightdate,
1508
                    timestamp AS biblio_timestamp,
1509
                    datecreated,
1510
                    abstract
1511
                FROM deletedbiblio
1512
            ) AS all_biblio              ON ((all_biblio.biblionumber=aqorders.biblionumber) OR (all_biblio.biblionumber=aqorders.deletedbiblionumber))
1513
            LEFT JOIN (
1514
                SELECT biblionumber,
1515
                    biblioitemnumber,
1516
                    volume,
1517
                    number,
1518
                    itemtype,
1519
                    isbn,
1520
                    issn,
1521
                    ean,
1522
                    publicationyear,
1523
                    publishercode,
1524
                    volumedate,
1525
                    volumedesc,
1526
                    collectiontitle,
1527
                    collectionissn,
1528
                    collectionvolume,
1529
                    editionstatement,
1530
                    editionresponsibility,
1531
                    illus,
1532
                    pages,
1533
                    notes AS biblioitems_notes,
1534
                    size,
1535
                    place,
1536
                    lccn,
1537
                    marc,
1538
                    url,
1539
                    cn_source,
1540
                    cn_class,
1541
                    cn_item,
1542
                    cn_suffix,
1543
                    cn_sort,
1544
                    agerestriction,
1545
                    totalissues,
1546
                    marcxml
1547
                FROM biblioitems
1548
                UNION ALL
1549
                SELECT biblionumber,
1550
                    biblioitemnumber,
1551
                    volume,
1552
                    number,
1553
                    itemtype,
1554
                    isbn,
1555
                    issn,
1556
                    ean,
1557
                    publicationyear,
1558
                    publishercode,
1559
                    volumedate,
1560
                    volumedesc,
1561
                    collectiontitle,
1562
                    collectionissn,
1563
                    collectionvolume,
1564
                    editionstatement,
1565
                    editionresponsibility,
1566
                    illus,
1567
                    pages,
1568
                    notes AS biblioitems_notes,
1569
                    size,
1570
                    place,
1571
                    lccn,
1572
                    marc,
1573
                    url,
1574
                    cn_source,
1575
                    cn_class,
1576
                    cn_item,
1577
                    cn_suffix,
1578
                    cn_sort,
1579
                    agerestriction,
1580
                    totalissues,
1581
                    marcxml
1582
                FROM deletedbiblioitems
1583
            ) AS all_biblioitems         ON ((all_biblioitems.biblionumber=aqorders.biblionumber) OR (all_biblioitems.biblionumber=aqorders.deletedbiblionumber))
1584
            LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_from = aqorders.ordernumber
1283
        WHERE basketno = ?
1585
        WHERE basketno = ?
1284
          AND (datecancellationprinted IS NOT NULL
1586
          AND (datecancellationprinted IS NOT NULL
1285
               AND datecancellationprinted <> '0000-00-00')
1587
               AND datecancellationprinted <> '0000-00-00')
Lines 1295-1301 sub GetCancelledOrders { Link Here
1295
    return @$results;
1597
    return @$results;
1296
}
1598
}
1297
1599
1298
1299
#------------------------------------------------------------#
1600
#------------------------------------------------------------#
1300
1601
1301
=head3 ModReceiveOrder
1602
=head3 ModReceiveOrder
(-)a/C4/Biblio.pm (-5 / +26 lines)
Lines 402-411 sub ModBiblioframework { Link Here
402
402
403
  my $error = &DelBiblio($biblionumber);
403
  my $error = &DelBiblio($biblionumber);
404
404
405
Exported function (core API) for deleting a biblio in koha.
405
Exported function (core API) for deleting a biblio in Koha.
406
Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
406
Action :
407
Also backs it up to deleted* tables
407
It the record has an item, do not delete the record, and return an error message.
408
Checks to make sure there are not issues on any of the items
408
If the record has no item,
409
- deletes biblio record from Zebra and Koha tables (biblio,biblioitems),
410
- backs Koha tables it up to deleted* tables,
411
- delete attached suscriptions
412
- if the record is used in an order, move the biblionumber from aqorders.biblionumber to aqorders.deletedbiblionumber
413
- record the action in logs
414
409
return:
415
return:
410
C<$error> : undef unless an error occurs
416
C<$error> : undef unless an error occurs
411
417
Lines 441-455 sub DelBiblio { Link Here
441
        C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
447
        C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
442
    }
448
    }
443
449
450
    # Get all orders using this record. Must be done before deleting the record to be able to find orders to update after deletion
451
    require C4::Acquisition;
452
    my @orders = C4::Acquisition::GetOrdersByBiblionumber ($biblionumber);
453
444
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
454
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
445
    # for at least 2 reasons :
455
    # for at least 2 reasons :
446
    # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
456
    # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
447
    #   and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
457
    #   and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
448
    ModZebra( $biblionumber, "recordDelete", "biblioserver" );
458
    ModZebra( $biblionumber, "recordDelete", "biblioserver" );
449
459
450
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
460
    # delete the record from biblioitems table and save it in deletedbiblioitems,deleteditems
451
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
461
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
452
    $sth->execute($biblionumber);
462
    $sth->execute($biblionumber);
463
    #FIXME : the loop is probably unneeded
453
    while ( my $biblioitemnumber = $sth->fetchrow ) {
464
    while ( my $biblioitemnumber = $sth->fetchrow ) {
454
465
455
        # delete this biblioitem
466
        # delete this biblioitem
Lines 462-468 sub DelBiblio { Link Here
462
    # delete cascade will prevent deletedbiblioitems rows
473
    # delete cascade will prevent deletedbiblioitems rows
463
    # from being generated by _koha_delete_biblioitems
474
    # from being generated by _koha_delete_biblioitems
464
    $error = _koha_delete_biblio( $dbh, $biblionumber );
475
    $error = _koha_delete_biblio( $dbh, $biblionumber );
476
    return $error if $error;
465
477
478
    #If the record is used in an order, move the biblionumber from aqorders.biblionumber to aqorders.deletedbiblionumber
479
    if (scalar @orders > 0) {
480
        for my $myorder (@orders) {
481
            $sth = $dbh->prepare("UPDATE aqorders
482
                                  SET deletedbiblionumber = ?
483
                                  WHERE ordernumber=?");
484
            $sth->execute($biblionumber,$myorder->{ordernumber});
485
        }
486
    }
466
    logaction( "CATALOGUING", "DELETE", $biblionumber, "" ) if C4::Context->preference("CataloguingLog");
487
    logaction( "CATALOGUING", "DELETE", $biblionumber, "" ) if C4::Context->preference("CataloguingLog");
467
488
468
    return;
489
    return;
(-)a/acqui/basket.pl (-2 / +1 lines)
Lines 383-389 sub get_order_infos { Link Here
383
        $line{'title'} .= " / $seriestitle" if $seriestitle;
383
        $line{'title'} .= " / $seriestitle" if $seriestitle;
384
        $line{'title'} .= " / $volume"      if $volume;
384
        $line{'title'} .= " / $volume"      if $volume;
385
    } else {
385
    } else {
386
        $line{'title'} = "Deleted bibliographic notice, can't find title.";
386
        $line{'title'} = "Can't find title.";
387
    }
387
    }
388
388
389
    my $biblionumber = $order->{'biblionumber'};
389
    my $biblionumber = $order->{'biblionumber'};
Lines 432-438 sub get_order_infos { Link Here
432
            };
432
            };
433
        }
433
        }
434
    }
434
    }
435
436
    return \%line;
435
    return \%line;
437
}
436
}
438
437
(-)a/acqui/neworderempty.pl (+1 lines)
Lines 377-382 $template->param( Link Here
377
    surnamesuggestedby   => $suggestion->{surnamesuggestedby},
377
    surnamesuggestedby   => $suggestion->{surnamesuggestedby},
378
    firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
378
    firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
379
    biblionumber         => $biblionumber,
379
    biblionumber         => $biblionumber,
380
    deletedbiblionumber  => $data->{'deletedbiblionumber'},
380
    uncertainprice       => $data->{'uncertainprice'},
381
    uncertainprice       => $data->{'uncertainprice'},
381
    authorisedbyname     => $borrower->{'firstname'} . " " . $borrower->{'surname'},
382
    authorisedbyname     => $borrower->{'firstname'} . " " . $borrower->{'surname'},
382
    discount_2dp         => sprintf( "%.2f",  $bookseller->{'discount'} ) ,   # for display
383
    discount_2dp         => sprintf( "%.2f",  $bookseller->{'discount'} ) ,   # for display
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 2904-2909 DROP TABLE IF EXISTS `aqorders`; Link Here
2904
CREATE TABLE `aqorders` ( -- information related to the basket line items
2904
CREATE TABLE `aqorders` ( -- information related to the basket line items
2905
  `ordernumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha to each line
2905
  `ordernumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha to each line
2906
  `biblionumber` int(11) default NULL, -- links the order to the biblio being ordered (biblio.biblionumber)
2906
  `biblionumber` int(11) default NULL, -- links the order to the biblio being ordered (biblio.biblionumber)
2907
  `deletedbiblionumber` int(11) default NULL, -- links the order to the deletedbiblio being ordered (deletedbiblio.biblionumber)
2907
  `entrydate` date default NULL, -- the date the bib was added to the basket
2908
  `entrydate` date default NULL, -- the date the bib was added to the basket
2908
  `quantity` smallint(6) default NULL, -- the quantity ordered
2909
  `quantity` smallint(6) default NULL, -- the quantity ordered
2909
  `currency` varchar(3) default NULL, -- the currency used for the purchase
2910
  `currency` varchar(3) default NULL, -- the currency used for the purchase
Lines 2944-2949 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2944
  CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
2945
  CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
2945
  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2946
  CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2946
  CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE,
2947
  CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE,
2948
  CONSTRAINT aqorders_ibfk_4 FOREIGN KEY (deletedbiblionumber) REFERENCES deletedbiblio (biblionumber) ON DELETE SET NULL ON UPDATE CASCADE,
2947
  CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE
2949
  CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE
2948
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2950
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2949
2951
(-)a/installer/data/mysql/updatedatabase.pl (+6 lines)
Lines 7303-7308 if ( CheckVersion($DBversion) ) { Link Here
7303
    });
7303
    });
7304
7304
7305
    print "Upgrade to $DBversion done (Bug 10565 - Add a 'Patron List' feature for storing and manipulating collections of patrons)\n";
7305
    print "Upgrade to $DBversion done (Bug 10565 - Add a 'Patron List' feature for storing and manipulating collections of patrons)\n";
7306
7307
$DBversion = "3.13.00.XXX";
7308
if ( CheckVersion($DBversion) ) {
7309
    $dbh->do("ALTER TABLE aqorders ADD COLUMN deletedbiblionumber INT(11) DEFAULT NULL AFTER biblionumber;");
7310
    $dbh->do("ALTER TABLE aqorders ADD CONSTRAINT `aqorders_ibfk_4` FOREIGN KEY (`deletedbiblionumber`) REFERENCES `deletedbiblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE;");
7311
    print "Upgrade to $DBversion done \n";
7306
    SetVersion($DBversion);
7312
    SetVersion($DBversion);
7307
}
7313
}
7308
7314
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-3 / +8 lines)
Lines 339-346 Link Here
339
                               [% IF (books_loo.biblionumber) %]
339
                               [% IF (books_loo.biblionumber) %]
340
                                   <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% books_loo.biblionumber %]">[% books_loo.title |html %]</a> by [% books_loo.author %]
340
                                   <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% books_loo.biblionumber %]">[% books_loo.title |html %]</a> by [% books_loo.author %]
341
                                   <br />
341
                                   <br />
342
                               [% ELSIF (books_loo.deletedbiblionumber) %]
343
                                   [% books_loo.title |html %] by [% books_loo.author %]
344
                                   <br />
345
                                   <em>(Deleted record)</em>
346
                                   <br />
342
                               [% ELSE %]
347
                               [% ELSE %]
343
                                   <em>Deleted bibliographic record, can't find title</em><br />
348
                                   <em>Can't find title</em><br />
344
                               [% END %]
349
                               [% END %]
345
                                [% IF ( books_loo.isbn ) %] - [% books_loo.isbn %][% END %]
350
                                [% IF ( books_loo.isbn ) %] - [% books_loo.isbn %][% END %]
346
                                [% IF ( books_loo.issn ) %] - [% books_loo.issn %][% END %]
351
                                [% IF ( books_loo.issn ) %] - [% books_loo.issn %][% END %]
Lines 453-462 Link Here
453
                    <td>
458
                    <td>
454
                      <p>
459
                      <p>
455
                        [% IF ( order.order_received ) %] (rcvd)[% END %]
460
                        [% IF ( order.order_received ) %] (rcvd)[% END %]
456
                        [% IF (order.biblionumber) %]
461
                        [% IF (order.biblionumber)||(order.deletedbiblionumber) %]
457
                          [% order.title |html %] by [% order.author %]<br />
462
                          [% order.title |html %] by [% order.author %]<br />
458
                        [% ELSE %]
463
                        [% ELSE %]
459
                          <em>Deleted bibliographic record, can't find title</em><br />
464
                            <em>Can't find title</em><br />
460
                        [% END %]
465
                        [% END %]
461
                        [% IF ( order.notes ) %] [% order.notes %][% END %]
466
                        [% IF ( order.notes ) %] [% order.notes %][% END %]
462
                        [% IF ( order.isbn ) %] - [% order.isbn %][% END %]
467
                        [% IF ( order.isbn ) %] - [% order.isbn %][% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-21 / +22 lines)
Lines 214-220 $(document).ready(function() Link Here
214
            Catalog details
214
            Catalog details
215
            [% IF ( biblionumber ) %]
215
            [% IF ( biblionumber ) %]
216
                <span><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]"> Edit record</a></span>
216
                <span><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]"> Edit record</a></span>
217
            [% END %]
217
            [% ELSIF (deletedbiblionumber) %]
218
	        <span> (Deleted record, not editable)</span>
219
	    [% END %]
218
        </legend>
220
        </legend>
219
        [% UNLESS ( existing ) %]
221
        [% UNLESS ( existing ) %]
220
        <input type="hidden" name="existing" value="no" />
222
        <input type="hidden" name="existing" value="no" />
Lines 234-259 $(document).ready(function() Link Here
234
        [% END %]
236
        [% END %]
235
237
236
        <ol><li>
238
        <ol><li>
237
            [% IF ( biblionumber ) %]
239
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
238
            <span class="label">Title</span>
240
                <span class="label">Title:</span>
239
                <input type="hidden" name="title" value="[% title |html %]" /> <span class="title">[% title |html %]</span>
241
                <input type="hidden" name="title" value="[% title |html %]" /> <span class="title">[% title |html %]</span>
240
            [% ELSE %]
242
	    [% ELSE %]
241
            <label for="entertitle" class="required">Title: </label>
243
            <label for="entertitle" class="required">Title: </label>
242
                <input type="text" id="entertitle" size="50" name="title" value="[% title |html %]" class="focus" />
244
                <input type="text" id="entertitle" size="50" name="title" value="[% title |html %]" class="focus" />
243
            [% END %]
245
            [% END %]
244
        </li>
246
        </li>
245
        <li>
247
        <li>
246
            [% IF ( biblionumber ) %]
248
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
247
            <span class="label">Author: </span>
249
                <span class="label">Author: </span>
248
                <input type="hidden" name="author" id="author" value="[% author %]" />[% author %]
250
                <input type="hidden" name="author" id="author" value="[% author %]" />[% author %]
249
            [% ELSE %]
251
	    [% ELSE %]
250
            <label for="author">Author: </label>
252
            <label for="author">Author: </label>
251
                <input type="text" size="50" name="author" id="author" value="[% author %]" />
253
                <input type="text" size="50" name="author" id="author" value="[% author %]" />
252
            [% END %]
254
            [% END %]
253
        </li>
255
        </li>
254
        <li>
256
        <li>
255
            [% IF ( biblionumber ) %]
257
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
256
            <span class="label">Publisher: </span>
258
                <span class="label">Publisher: </span>
257
                <input type="hidden" name="publishercode" id="publishercode" value="[% publishercode %]" />[% publishercode %]
259
                <input type="hidden" name="publishercode" id="publishercode" value="[% publishercode %]" />[% publishercode %]
258
            [% ELSE %]
260
            [% ELSE %]
259
            <label for="publishercode"> Publisher: </label>
261
            <label for="publishercode"> Publisher: </label>
Lines 261-278 $(document).ready(function() Link Here
261
            [% END %]
263
            [% END %]
262
        </li>
264
        </li>
263
        <li>
265
        <li>
264
            [% IF ( biblionumber ) %]
266
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
265
            <span class="label">Edition: </span>
267
                <span class="label">Edition: </span>
266
                <input type="hidden" name="editionstatement" id="editionstatement" value="[% editionstatement %]" />[% editionstatement %]
268
                <input type="hidden" name="editionstatement" id="editionstatement" value="[% editionstatement %]" />[% editionstatement %]
267
268
            [% ELSE %]
269
            [% ELSE %]
269
            <label for="editionstatement">Edition: </label>
270
            <label for="editionstatement">Edition: </label>
270
                <input type="text" size="20" name="editionstatement" id="editionstatement" value="[% editionstatement %]" />
271
                <input type="text" size="20" name="editionstatement" id="editionstatement" value="[% editionstatement %]" />
271
            [% END %]
272
            [% END %]
272
        </li>
273
        </li>
273
        <li>
274
        <li>
274
            [% IF ( biblionumber ) %]
275
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
275
            <span class="label">Publication year: </span>
276
                <span class="label">Publication year: </span>
276
                <input type="hidden" name="publicationyear" id="publicationyear" value="[% publicationyear %]" />[% publicationyear %]
277
                <input type="hidden" name="publicationyear" id="publicationyear" value="[% publicationyear %]" />[% publicationyear %]
277
            [% ELSE %]
278
            [% ELSE %]
278
            <label for="publicationyear">Publication year: </label>
279
            <label for="publicationyear">Publication year: </label>
Lines 280-287 $(document).ready(function() Link Here
280
            [% END %]
281
            [% END %]
281
        </li>
282
        </li>
282
        <li>
283
        <li>
283
            [% IF ( biblionumber ) %]
284
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
284
            <span class="label">ISBN: </span>
285
                <span class="label">ISBN: </span>
285
                <input type="hidden" name="isbn" id="ISBN" value="[% isbn %]" />[% isbn %]
286
                <input type="hidden" name="isbn" id="ISBN" value="[% isbn %]" />[% isbn %]
286
            [% ELSE %]
287
            [% ELSE %]
287
            <label for="ISBN">ISBN: </label>
288
            <label for="ISBN">ISBN: </label>
Lines 290-297 $(document).ready(function() Link Here
290
        </li>
291
        </li>
291
        [% IF (UNIMARC) %]
292
        [% IF (UNIMARC) %]
292
        <li>
293
        <li>
293
            [% IF ( biblionumber ) %]
294
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
294
            <span class="label">EAN: </span>
295
                <span class="label">EAN: </span>
295
                <input type="hidden" name="ean" id="EAN" value="[% ean %]" />[% ean %]
296
                <input type="hidden" name="ean" id="EAN" value="[% ean %]" />[% ean %]
296
            [% ELSE %]
297
            [% ELSE %]
297
            <label for="EAN">EAN: </label>
298
            <label for="EAN">EAN: </label>
Lines 300-314 $(document).ready(function() Link Here
300
        </li>
301
        </li>
301
        [% END %]
302
        [% END %]
302
        <li>
303
        <li>
303
            [% IF ( biblionumber ) %]
304
            [% IF ( biblionumber )||( deletedbiblionumber ) %]
304
            <span class="label">Series: </span>
305
                <span class="label">Series: </span>
305
                <input type="hidden" name="series" id="series" value="[% seriestitle %]" />[% seriestitle %]
306
                <input type="hidden" name="series" id="series" value="[% seriestitle %]" />[% seriestitle %]
306
            [% ELSE %]
307
            [% ELSE %]
307
            <label for="series">Series: </label>
308
            <label for="series">Series: </label>
308
                <input type="text" size="50" name="series" id="series" value="[% seriestitle %]" />
309
                <input type="text" size="50" name="series" id="series" value="[% seriestitle %]" />
309
            [% END %]
310
            [% END %]
310
        </li>
311
        </li>
311
            [% UNLESS ( biblionumber ) %]
312
            [% UNLESS (( biblionumber )||( deletedbiblionumber )) %]
312
            [% IF ( itemtypeloop ) %]
313
            [% IF ( itemtypeloop ) %]
313
            <li>
314
            <li>
314
                <span class="label">Item type:</span>
315
                <span class="label">Item type:</span>
(-)a/t/db_dependent/Acquisition.t (-7 / +303 lines)
Lines 8-14 use POSIX qw(strftime); Link Here
8
8
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
10
11
use Test::More tests => 41;
11
use Test::More tests => 234;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Acquisition');
14
    use_ok('C4::Acquisition');
Lines 48-64 my $budgetid = C4::Budgets::AddBudget( Link Here
48
);
48
);
49
my $budget = C4::Budgets::GetBudget( $budgetid );
49
my $budget = C4::Budgets::GetBudget( $budgetid );
50
50
51
my ($ordernumber1, $ordernumber2, $ordernumber3);
51
#
52
# FUNCTIONS ABOUT ORDERS + AddClaim
53
# TransferOrder, OrderFromSubscription and GetOrdersByBiblionumber : tested in separated UT
54
#
55
56
#
57
# Test NewOrder
58
#
59
60
# Add a branch
61
my $b1 = {
62
    add            => 1,
63
    branchcode     => 'BRA',
64
    branchname     => 'BranchA',
65
    branchaddress1 => 'adr1A',
66
    branchaddress2 => 'adr2A',
67
    branchaddress3 => 'adr3A',
68
    branchzip      => 'zipA',
69
    branchcity     => 'cityA',
70
    branchstate    => 'stateA',
71
    branchcountry  => 'countryA',
72
    branchphone    => 'phoneA',
73
    branchfax      => 'faxA',
74
    branchemail    => 'emailA',
75
    branchurl      => 'urlA',
76
    branchip       => 'ipA',
77
    branchprinter  => undef,
78
    branchnotes    => 'noteA',
79
    opac_info      => 'opacA'
80
};
81
&C4::Branch::ModBranch($b1);
82
83
my ($mandatoryparams, $return_error,$basketnum,$ordernumber1, $ordernumber2, $ordernumber3);
52
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
84
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
53
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
85
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
54
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder(
86
55
    {
87
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing
88
eval {($basketnum, $ordernumber1 ) = C4::Acquisition::NewOrder()};
89
$return_error = $@;
90
ok ((!(defined $basketnum || defined $ordernumber1)) && (defined $return_error),"NewOrder with no params returns undef and croaks");
91
92
$mandatoryparams = {
56
        basketno => $basketno,
93
        basketno => $basketno,
57
        quantity => 24,
94
        quantity => 24,
58
        biblionumber => $biblionumber1,
95
        biblionumber => $biblionumber1,
59
        budget_id => $budget->{budget_id},
96
        budget_id => $budget->{budget_id},
60
    }
97
    };
61
);
98
my @mandatoryparams_keys = keys %$mandatoryparams;
99
foreach my $mandatoryparams_key (@mandatoryparams_keys) {
100
    my %test_missing_mandatoryparams = %$mandatoryparams;
101
    delete $test_missing_mandatoryparams {$mandatoryparams_key};
102
    eval {($basketnum, $ordernumber1 ) = C4::Acquisition::NewOrder(\%test_missing_mandatoryparams)};
103
    $return_error = $@;
104
    my $expected_error = "Mandatory parameter $mandatoryparams_key missing";
105
    ok ((!(defined $basketnum || defined $ordernumber1)) && ( index ($return_error, $expected_error) >=0 ),"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message");
106
}
107
108
# FIXME to do : test the other features of NewOrder
109
110
my $order1_content = {
111
        basketno => $basketno,
112
        quantity => 2,
113
        biblionumber => $biblionumber1,
114
        budget_id => $budget->{budget_id},
115
        listprice=>50.121111,
116
        ecost => 38.15,
117
        rrp => 40.15,
118
        discount =>5.1111,
119
        branchcode=>"BRA",
120
        uncertainprice=>0,
121
        notes=>"ordernotes",
122
        gstrate=>0.0515
123
    };
124
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder($order1_content);
62
125
63
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder(
126
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder(
64
    {
127
    {
Lines 80-89 my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); Link Here
80
    }
143
    }
81
);
144
);
82
145
146
#
147
# Test DelOrder
148
#
149
150
#
151
# Test ModOrder
152
#
153
154
#
155
# Test NewOrderItem
156
#
157
158
#
159
# Test ModItemOrder
160
#
161
162
#
163
# test GetOrder
164
#
165
# Returns a reference-to-hash describing the order.
166
# The keys of C<$order> are fields from the biblio, biblioitems, aqorders tables
167
# If the record have been suppressed, its biblionumber is only returned in deletedbiblionumber column.
168
# no error control
169
170
#timestamp : 3 different
171
#notes
172
my @expectedfields = qw(biblionumber
173
                        frameworkcode
174
                        author
175
                        title
176
                        unititle
177
                        biblio_notes
178
                        serial
179
                        seriestitle
180
                        copyrightdate
181
                        biblio_timestamp
182
                        datecreated
183
                        abstract
184
                        biblioitemnumber
185
                        volume
186
                        number
187
                        itemtype
188
                        isbn
189
                        issn
190
                        ean
191
                        publicationyear
192
                        publishercode
193
                        volumedate
194
                        volumedesc
195
                        collectiontitle
196
                        collectionissn
197
                        collectionvolume
198
                        editionstatement
199
                        editionresponsibility
200
                        illus
201
                        pages
202
                        biblioitems_notes
203
                        size
204
                        place
205
                        lccn
206
                        marc
207
                        url
208
                        cn_source
209
                        cn_class
210
                        cn_item
211
                        cn_suffix
212
                        cn_sort
213
                        agerestriction
214
                        totalissues
215
                        marcxml
216
                        ordernumber
217
                        entrydate
218
                        quantity
219
                        currency
220
                        listprice
221
                        totalamount
222
                        datereceived
223
                        invoiceid
224
                        freight
225
                        unitprice
226
                        quantityreceived
227
                        cancelledby
228
                        datecancellationprinted
229
                        notes
230
                        supplierreference
231
                        purchaseordernumber
232
                        basketno
233
                        timestamp
234
                        rrp
235
                        ecost
236
                        gstrate
237
                        discount
238
                        budget_id
239
                        budgetgroup_id
240
                        budgetdate
241
                        sort1
242
                        sort2
243
                        sort1_authcat
244
                        sort2_authcat
245
                        uncertainprice
246
                        claims_count
247
                        claimed_date
248
                        subscriptionid
249
                        parent_ordernumber
250
                        deletedbiblionumber);
251
my $myorder1_beforedelete = GetOrder($ordernumber1);
252
my @w = keys %$myorder1_beforedelete;
253
#warn "@w";
254
# my @C=map{!${{map{$_,1}@w}}{$_}&&$_||undef}@expectedfields;
255
#warn @C;
256
is( scalar (keys %$myorder1_beforedelete),79, "If the record is not deleted, GetOrder gets an order with the right number of fields" );
257
for my $field ( @expectedfields ) {
258
    ok( exists( $myorder1_beforedelete->{ $field } ), "If the record is not deleted, GetOrder gets an order with a $field field" );
259
    is(( $myorder1_beforedelete->{ $field } ) , $order1_content->{ $field },"If the record is not deleted, GetOrder gets an order with a correct content in $field" ) if (defined $order1_content->{ $field } && $field !~ /biblionumber/);
260
}
261
is(( $myorder1_beforedelete->{ biblionumber} ) , $order1_content->{ biblionumber},"If the record is not deleted, GetOrder gets an order with a correct biblionumber");
262
is(( $myorder1_beforedelete->{ deletedbiblionumber} ) , undef ,"If the record is not deleted, GetOrder gets an order with a no deletedbiblionumber");
263
264
# GetOrders return correct informations even if the record is deleted
265
&C4::Biblio::DelBiblio ($biblionumber1);
266
my $myorder1_afterdelete = GetOrder($ordernumber1);
267
is( scalar (keys %$myorder1_afterdelete),79, "If the record is deleted, GetOrder gets an order with the right number of fields" );
268
for my $field ( @expectedfields ) {
269
    ok( exists( $myorder1_afterdelete->{ $field } ), "If the record is deleted, GetOrder gets an order with a $field field" );
270
    is (( $myorder1_afterdelete->{ $field } ), $order1_content->{ $field },"If the record is deleted, GetOrder gets an order with a correct content in $field" ) if (defined $order1_content->{ $field } && $field !~ /biblionumber/);
271
}
272
is(( $myorder1_afterdelete->{ deletedbiblionumber} ) , $order1_content->{ biblionumber},"If the record is deleted, GetOrder gets an order with a correct deletedbiblionumber");
273
is(( $myorder1_afterdelete->{ biblionumber} ) , undef ,"If the record is deleted, GetOrder gets an order with a no biblionumber");
274
275
#
276
# test GetOrders
277
#
278
279
#
280
# test GetCancelledOrders
281
#
282
283
#
284
# test SearchOrder
285
#
286
287
#
288
# Test GetHistory
289
#
290
291
#
292
# Test GetLateOrders
293
#
294
295
#
296
# Test GetOrderFromItemnumber
297
#
298
299
#
300
# Test GetLastOrderNotReceivedFromSubscriptionid
301
#
302
303
#
304
# Test GetLastOrderReceivedFromSubscriptionid
305
#
306
307
#
308
# Test GetRecentAcqui
309
#
310
311
#
312
# Test ModReceiveOrder
313
#
314
315
#
316
# Test CancelReceipt
317
#
318
319
#
320
# Test CancelReceipt
321
#
322
323
#
324
# test GetLateOrders
325
#
326
327
#
328
# test GetItemnumbersFromOrder
329
#
330
331
#
332
# test GetPendingOrders
333
#
334
83
my $grouped    = 0;
335
my $grouped    = 0;
84
my $orders = GetPendingOrders( $booksellerid, $grouped );
336
my $orders = GetPendingOrders( $booksellerid, $grouped );
85
isa_ok( $orders, 'ARRAY' );
337
isa_ok( $orders, 'ARRAY' );
86
338
339
#
340
# test AddClaim
341
#
342
87
C4::Acquisition::CloseBasket( $basketno );
343
C4::Acquisition::CloseBasket( $basketno );
88
my @lateorders = GetLateOrders(0);
344
my @lateorders = GetLateOrders(0);
89
my $order = $lateorders[0];
345
my $order = $lateorders[0];
Lines 91-97 AddClaim( $order->{ordernumber} ); Link Here
91
my $neworder = GetOrder( $order->{ordernumber} );
347
my $neworder = GetOrder( $order->{ordernumber} );
92
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
348
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
93
349
94
my @expectedfields = qw( basketno
350
#
351
# test GetPendingOrders again
352
#
353
354
@expectedfields = qw( basketno
95
                         biblionumber
355
                         biblionumber
96
                         invoiceid
356
                         invoiceid
97
                         budgetdate
357
                         budgetdate
Lines 127-130 for my $field ( @expectedfields ) { Link Here
127
    ok( exists( $firstorder->{ $field } ), "This order has a $field field" );
387
    ok( exists( $firstorder->{ $field } ), "This order has a $field field" );
128
}
388
}
129
389
390
#
391
# FUNCTIONS ABOUT INVOICES
392
#
393
394
#
395
# GetInvoice
396
#
397
398
#
399
# GetInvoices
400
#
401
402
#
403
# GetInvoiceDetails
404
#
405
406
#
407
# AddInvoice
408
#
409
410
#
411
# ModInvoice
412
#
413
414
#
415
# CloseInvoice
416
#
417
418
#
419
# ReopenInvoice
420
#
421
422
#
423
# DelInvoice
424
#
425
130
$dbh->rollback;
426
$dbh->rollback;
(-)a/t/db_dependent/Biblio.t (-4 / +133 lines)
Lines 5-18 Link Here
5
5
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
use Test::More tests => 17;
8
use Test::More tests => 28;
9
use MARC::Record;
9
use MARC::Record;
10
use C4::Biblio;
10
use C4::Biblio;
11
use C4::Items;
12
use C4::Branch qw( ModBranch DelBranch );
13
use C4::Budgets qw( AddBudget GetBudget DelBudget AddBudgetPeriod );
14
use C4::Bookseller qw( AddBookseller DelBookseller );
15
use C4::Acquisition qw( NewBasket DelBasket DelOrder NewOrder GetOrder);
16
use C4::Serials qw( NewSubscription GetSubscription );
17
18
my $dbh = C4::Context->dbh;
19
$dbh->{AutoCommit} = 0;
20
$dbh->{RaiseError} = 1;
11
21
12
BEGIN {
22
BEGIN {
13
    use_ok('C4::Biblio');
23
    use_ok('C4::Biblio');
14
}
24
}
15
25
26
# FIXME for the moment, Biblio.t is only working for MARC21
27
16
my $isbn = '0590353403';
28
my $isbn = '0590353403';
17
my $title = 'Foundation';
29
my $title = 'Foundation';
18
30
Lines 109-113 $field->update('123456789X'); Link Here
109
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
121
$controlnumber = GetMarcControlnumber( $marc_record, 'MARC21' );
110
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
122
is( $controlnumber, '123456789X', 'GetMarcControlnumber handles records with 001' );
111
123
112
# clean up after ourselves
124
#
113
DelBiblio($biblionumber);
125
# testing DelBiblio and clean up
126
#
127
# add an item, an order and a subscription
128
# add a branch and an item
129
my $b1 = {
130
    add            => 1,
131
    branchcode     => 'BRA',
132
    branchname     => 'BranchA',
133
    branchaddress1 => 'adr1A',
134
    branchaddress2 => 'adr2A',
135
    branchaddress3 => 'adr3A',
136
    branchzip      => 'zipA',
137
    branchcity     => 'cityA',
138
    branchstate    => 'stateA',
139
    branchcountry  => 'countryA',
140
    branchphone    => 'phoneA',
141
    branchfax      => 'faxA',
142
    branchemail    => 'emailA',
143
    branchurl      => 'urlA',
144
    branchip       => 'ipA',
145
    branchprinter  => undef,
146
    branchnotes    => 'noteA',
147
    opac_info      => 'opacA'
148
};
149
ModBranch($b1);
150
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber);
151
# add an order
152
my $booksellerid = AddBookseller(
153
    {
154
        name => "my vendor",
155
        address1 => "bookseller's address",
156
        phone => "0123456",
157
        active => 1,
158
        deliverytime => 5,
159
    }
160
);
161
162
my $bpid = AddBudgetPeriod({
163
    budget_period_startdate => '01-01-2015',
164
    budget_period_enddate   => '31-12-2015',
165
    budget_description      => "budget desc"
166
});
167
168
my $budgetid = AddBudget(
169
    {
170
        budget_code   => "budget_code_test_1",
171
        budget_name   => "budget_name_test_1",
172
        budget_amount => "1000.00",
173
        budget_active      => 1,
174
        budget_period_id   => $bpid
175
    }
176
);
177
my $basketno = NewBasket($booksellerid, 1);
178
my $budget = GetBudget( $budgetid );
179
( undef, my $ordernumber ) = NewOrder(
180
    {
181
        basketno => $basketno,
182
        quantity => 2,
183
        biblionumber => $biblionumber,
184
        budget_id => $budget->{budget_id},
185
    }
186
);
187
188
# add a subscription
189
my $subscriptionid = NewSubscription(
190
    undef,        "",     undef, undef, $budgetid,      $biblionumber, '01-01-2013',     undef,
191
    undef,        undef,  undef, undef, undef,          undef,         undef,            undef,
192
    '',           undef,  undef, undef, undef,          undef,         '',               undef,
193
    undef,        undef,  undef, undef, '',             undef,         '',               1,
194
    "notes",      undef,  undef, undef, 1,              undef,         undef,            0,
195
    "intnotes",   0,      undef, undef, 0,              undef,         '31-12-2013',
196
);
197
# if an item is attached, DelBiblio returns "This Biblio has items attached, please delete them first before deleting this biblio " and does not delete record
198
my $return_DelBiblio = DelBiblio($biblionumber);
199
is( $return_DelBiblio , 'This Biblio has items attached, please delete them first before deleting this biblio ', 'DelBiblio returns specific error if an item is present' );
200
is(GetBiblioData($biblionumber)->{biblionumber},$biblionumber,'DelBiblio does not delete record if an item is present.');
201
202
# Delete the item.
203
DelItem($dbh, $biblionumber, $itemnumber);
204
# if an order uses the record, and if there is no item, DelBiblio moves record to deleted* tables and updates the order
205
$return_DelBiblio = DelBiblio($biblionumber);
206
is(GetBiblioData($biblionumber),undef,"DelBiblio deletes record if no item is present but if the order is used in an order");
207
isnt( $return_DelBiblio , 'This Biblio has items attached, please delete them first before deleting this biblio ', 'DelBiblio does not return specific error if no item is present' );
208
my $order_after_deletion = GetOrder ($ordernumber);
209
is($order_after_deletion->{biblionumber},undef,"DelBiblio deletes biblionumber in order.biblionumber");
210
is($order_after_deletion->{deletedbiblionumber},$biblionumber,"DelBiblio copies biblionumber in order.deletedbiblionumer");
211
# FIXME to check the record is moved into deletedbiblio and deletedbiblioitems, check if title and isbn in order are the same as before record deletion
212
is($order_after_deletion->{title},$title,"DelBiblio moves biblio table into deletedbiblio table (test on title)");
213
is($order_after_deletion->{isbn},$isbn,"DelBiblio moves biblioitems table into deletedbiblioitems table (test on isbn)");
214
215
# if subscriptions use the record, DelBiblio delete them
216
is(GetSubscription( $subscriptionid ),undef,"DelBiblio deletes subscriptions when deleting record");
217
218
# else (if no subscription, no item, no orders are attached) DelBiblio delete the record
219
# create an other record
220
$isbn = '1290353403';
221
$title = 'Second record';
222
$marc_record=MARC::Record->new;
223
$field = MARC::Field->new('020','','','a' => $isbn);
224
$marc_record->append_fields($field);
225
($biblionumber,$biblioitemnumber) = AddBiblio($marc_record,'');
226
$field = MARC::Field->new('245','','','a' => $title);
227
$marc_record->append_fields($field);
228
ModBiblio($marc_record,$biblionumber,'');
229
# delete this record
230
$return_DelBiblio = DelBiblio($biblionumber);
231
is(GetBiblioData($biblionumber),undef,"DelBiblio deletes record if no item is present but if the order is used in an order");
232
isnt( $return_DelBiblio , 'This Biblio has items attached, please delete them first before deleting this biblio ', 'DelBiblio returns no specific error if no item is present' );
233
234
# check the action is recorded in Koha's log
235
# FIXME todo
236
237
DelOrder($ordernumber, $biblionumber);
238
DelBranch($b1->{branchcode} );
239
DelBasket ($basketno);
240
DelBudget ($budgetid);
241
DelBookseller($booksellerid);
242
243
$dbh->rollback;
114
- 

Return to bug 10758