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

(-)a/C4/Acquisition.pm (-10 / +10 lines)
Lines 235-241 sub CloseBasket { Link Here
235
    foreach my $order (@orders) {
235
    foreach my $order (@orders) {
236
        $query = qq{
236
        $query = qq{
237
            UPDATE aqorders
237
            UPDATE aqorders
238
            SET orderstatus = 1
238
            SET orderstatus = 'ordered'
239
            WHERE ordernumber = ?;
239
            WHERE ordernumber = ?;
240
        };
240
        };
241
        $sth = $dbh->prepare($query);
241
        $sth = $dbh->prepare($query);
Lines 266-272 sub ReopenBasket { Link Here
266
    foreach my $order (@orders) {
266
    foreach my $order (@orders) {
267
        $query = qq{
267
        $query = qq{
268
            UPDATE aqorders
268
            UPDATE aqorders
269
            SET orderstatus = 0
269
            SET orderstatus = 'new'
270
            WHERE ordernumber = ?;
270
            WHERE ordernumber = ?;
271
        };
271
        };
272
        $sth = $dbh->prepare($query);
272
        $sth = $dbh->prepare($query);
Lines 1384-1390 sub ModReceiveOrder { Link Here
1384
        $sth=$dbh->prepare("
1384
        $sth=$dbh->prepare("
1385
            UPDATE aqorders
1385
            UPDATE aqorders
1386
            SET quantity = ?,
1386
            SET quantity = ?,
1387
                orderstatus = 2
1387
                orderstatus = 'partial'
1388
            WHERE ordernumber = ?
1388
            WHERE ordernumber = ?
1389
        ");
1389
        ");
1390
1390
Lines 1400-1406 sub ModReceiveOrder { Link Here
1400
        $order->{'unitprice'} = $cost;
1400
        $order->{'unitprice'} = $cost;
1401
        $order->{'rrp'} = $rrp;
1401
        $order->{'rrp'} = $rrp;
1402
        $order->{ecost} = $ecost;
1402
        $order->{ecost} = $ecost;
1403
        $order->{'orderstatus'} = 3;    # totally received
1403
        $order->{'orderstatus'} = 'complete';
1404
        my $basketno;
1404
        my $basketno;
1405
        ( $basketno, $new_ordernumber ) = NewOrder($order);
1405
        ( $basketno, $new_ordernumber ) = NewOrder($order);
1406
1406
Lines 1412-1418 sub ModReceiveOrder { Link Here
1412
    } else {
1412
    } else {
1413
        $sth=$dbh->prepare("update aqorders
1413
        $sth=$dbh->prepare("update aqorders
1414
                            set quantityreceived=?,datereceived=?,invoiceid=?,
1414
                            set quantityreceived=?,datereceived=?,invoiceid=?,
1415
                                unitprice=?,rrp=?,ecost=?,orderstatus=3
1415
                                unitprice=?,rrp=?,ecost=?,orderstatus='complete'
1416
                            where biblionumber=? and ordernumber=?");
1416
                            where biblionumber=? and ordernumber=?");
1417
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1417
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1418
        $sth->finish;
1418
        $sth->finish;
Lines 1463-1469 sub CancelReceipt { Link Here
1463
            SET quantityreceived = ?,
1463
            SET quantityreceived = ?,
1464
                datereceived = ?,
1464
                datereceived = ?,
1465
                invoiceid = ?,
1465
                invoiceid = ?,
1466
                orderstatus = 1
1466
                orderstatus = 'ordered'
1467
            WHERE ordernumber = ?
1467
            WHERE ordernumber = ?
1468
        };
1468
        };
1469
        $sth = $dbh->prepare($query);
1469
        $sth = $dbh->prepare($query);
Lines 1491-1497 sub CancelReceipt { Link Here
1491
        $query = qq{
1491
        $query = qq{
1492
            UPDATE aqorders
1492
            UPDATE aqorders
1493
            SET quantity = ?,
1493
            SET quantity = ?,
1494
                orderstatus = 1
1494
                orderstatus = 'ordered'
1495
            WHERE ordernumber = ?
1495
            WHERE ordernumber = ?
1496
        };
1496
        };
1497
        $sth = $dbh->prepare($query);
1497
        $sth = $dbh->prepare($query);
Lines 1631-1637 sub DelOrder { Link Here
1631
    my $dbh = C4::Context->dbh;
1631
    my $dbh = C4::Context->dbh;
1632
    my $query = "
1632
    my $query = "
1633
        UPDATE aqorders
1633
        UPDATE aqorders
1634
        SET    datecancellationprinted=now(), orderstatus=4
1634
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1635
        WHERE  biblionumber=? AND ordernumber=?
1635
        WHERE  biblionumber=? AND ordernumber=?
1636
    ";
1636
    ";
1637
    my $sth = $dbh->prepare($query);
1637
    my $sth = $dbh->prepare($query);
Lines 1924-1930 sub GetLateOrders { Link Here
1924
        $from .= ' AND borrowers.branchcode LIKE ? ';
1924
        $from .= ' AND borrowers.branchcode LIKE ? ';
1925
        push @query_params, C4::Context->userenv->{branch};
1925
        push @query_params, C4::Context->userenv->{branch};
1926
    }
1926
    }
1927
    $from .= " AND orderstatus <> 4 ";
1927
    $from .= " AND orderstatus <> 'cancelled' ";
1928
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
1928
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
1929
    $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
1929
    $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
1930
    my $sth = $dbh->prepare($query);
1930
    my $sth = $dbh->prepare($query);
Lines 2047-2053 sub GetHistory { Link Here
2047
2047
2048
    $query .= " WHERE 1 ";
2048
    $query .= " WHERE 1 ";
2049
2049
2050
    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne '4';
2050
    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne 'cancelled';
2051
2051
2052
    my @query_params  = ();
2052
    my @query_params  = ();
2053
2053
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 2931-2937 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2931
  `claimed_date` date default NULL, -- last date a claim was generated
2931
  `claimed_date` date default NULL, -- last date a claim was generated
2932
  `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
2932
  `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
2933
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2933
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2934
  `orderstatus` tinyint(2) default 0, -- the current status for this line item
2934
  `orderstatus` varchar(16) default 'new', -- the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled'
2935
  PRIMARY KEY  (`ordernumber`),
2935
  PRIMARY KEY  (`ordernumber`),
2936
  KEY `basketno` (`basketno`),
2936
  KEY `basketno` (`basketno`),
2937
  KEY `biblionumber` (`biblionumber`),
2937
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-5 / +5 lines)
Lines 7113-7123 if ( CheckVersion($DBversion) ) { Link Here
7113
$DBversion = "3.13.00.XXX";
7113
$DBversion = "3.13.00.XXX";
7114
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7114
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7115
    my $return_count;
7115
    my $return_count;
7116
    $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus tinyint(2) DEFAULT 0 AFTER parent_ordernumber");
7116
    $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus varchar(16) DEFAULT 'new' AFTER parent_ordernumber");
7117
    $dbh->do("UPDATE aqorders SET orderstatus=1 WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
7117
    $dbh->do("UPDATE aqorders SET orderstatus='ordered' WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
7118
    $dbh->do("UPDATE aqorders SET orderstatus=2 WHERE quantity > quantityreceived AND quantityreceived > 0");
7118
    $dbh->do("UPDATE aqorders SET orderstatus='partial' WHERE quantity > quantityreceived AND quantityreceived > 0");
7119
    $dbh->do("UPDATE aqorders SET orderstatus=3 WHERE quantity=quantityreceived");
7119
    $dbh->do("UPDATE aqorders SET orderstatus='complete' WHERE quantity=quantityreceived");
7120
    $dbh->do("UPDATE aqorders SET orderstatus=4 WHERE datecancellationprinted IS NOT NULL");
7120
    $dbh->do("UPDATE aqorders SET orderstatus='cancelled' WHERE datecancellationprinted IS NOT NULL");
7121
    print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";
7121
    print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";
7122
    SetVersion($DBversion);
7122
    SetVersion($DBversion);
7123
}
7123
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt (-11 / +10 lines)
Lines 52-65 Link Here
52
            <label for="orderstatus">Order status: </label>
52
            <label for="orderstatus">Order status: </label>
53
            <select name="orderstatus" id="orderstatus">
53
            <select name="orderstatus" id="orderstatus">
54
                <option value=""></option>
54
                <option value=""></option>
55
                <option value="0">New</option>
55
                <option value="new">New orders</option>
56
                <option value="1">Ordered</option>
56
                <option value="ordered">Pending orders</option>
57
                <option value="2">Partial</option>
57
                <option value="partial">Partially received orders</option>
58
                <option value="3">Complete</option>
58
                <option value="complete">Received orders</option>
59
                <option value="4">Deleted</option>
59
                <option value="cancelled">Cancelled orders</option>
60
            </select>
60
            </select>
61
        </li>
61
        </li>
62
63
        <li>
62
        <li>
64
            <label for="fund">Fund: </label>
63
            <label for="fund">Fund: </label>
65
            <select name="budget" id="fund">
64
            <select name="budget" id="fund">
Lines 143-153 Link Here
143
                    </td>
142
                    </td>
144
                    <td>
143
                    <td>
145
                        [% SWITCH order.orderstatus %]
144
                        [% SWITCH order.orderstatus %]
146
                            [% CASE '0' %]New
145
                            [% CASE 'new' %]New orders
147
                            [% CASE '1' %]Ordered
146
                            [% CASE 'ordered' %]Pending orders
148
                            [% CASE '2' %]Partial
147
                            [% CASE 'partial' %]Partially received orders
149
                            [% CASE '3' %]Complete
148
                            [% CASE 'complete' %]Received orders
150
                            [% CASE '4' %]Deleted
149
                            [% CASE 'cancelled' %]Cancelled orders
151
                        [% END %]
150
                        [% END %]
152
                    </td>
151
                    </td>
153
                    <td>[% order.quantityreceived %]</td>
152
                    <td>[% order.quantityreceived %]</td>
(-)a/t/db_dependent/Acquisition/OrderFromSubscription.t (-1 / +1 lines)
Lines 70-76 my $ordernumber; Link Here
70
    rrp => $cost,
70
    rrp => $cost,
71
    ecost => $cost,
71
    ecost => $cost,
72
    gstrate => 0.0500,
72
    gstrate => 0.0500,
73
    orderstatus => 0,
73
    orderstatus => 'new',
74
    subscriptionid => $subscription->{subscriptionid},
74
    subscriptionid => $subscription->{subscriptionid},
75
    budget_id => $budget_id,
75
    budget_id => $budget_id,
76
});
76
});
(-)a/t/db_dependent/Acquisition/close_reopen_basket.t (-18 / +16 lines)
Lines 2-12 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More;
5
use Test::More tests => 6;
6
use C4::Acquisition;
6
use C4::Acquisition;
7
use C4::Biblio qw( AddBiblio DelBiblio );
7
use C4::Biblio qw( AddBiblio DelBiblio );
8
use C4::Bookseller;
8
use C4::Bookseller;
9
use C4::Budgets;
9
use C4::Budgets;
10
use C4::Context;
11
12
# Start transaction
13
my $dbh = C4::Context->dbh;
14
$dbh->{AutoCommit} = 0;
15
$dbh->{RaiseError} = 1;
16
17
$dbh->do(q{
18
    DELETE FROM aqorders;
19
});
10
20
11
my $booksellerid = C4::Bookseller::AddBookseller(
21
my $booksellerid = C4::Bookseller::AddBookseller(
12
    {
22
    {
Lines 56-81 my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno ); Link Here
56
is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
66
is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
57
my @orders = C4::Acquisition::GetOrders( $basketno );
67
my @orders = C4::Acquisition::GetOrders( $basketno );
58
is( scalar(@orders), 2, "2 orders are created" );
68
is( scalar(@orders), 2, "2 orders are created" );
59
is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new before closing the basket" );
69
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new before closing the basket" );
60
70
61
C4::Acquisition::CloseBasket( $basketno );
71
C4::Acquisition::CloseBasket( $basketno );
62
@orders = C4::Acquisition::GetOrders( $basketno );
72
@orders = C4::Acquisition::GetOrders( $basketno );
63
is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
73
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
64
74
65
C4::Acquisition::ReopenBasket( $basketno );
75
C4::Acquisition::ReopenBasket( $basketno );
66
@orders = C4::Acquisition::GetOrders( $basketno );
76
@orders = C4::Acquisition::GetOrders( $basketno );
67
is ( scalar( map { $_->{orderstatus} == 1 ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" );
77
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" );
68
is ( scalar( map { $_->{orderstatus} == 0 ? 1 : () } @orders ), 2, "2 order are new, the basket is reopen" );
78
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopen" );
69
70
71
END {
72
    C4::Acquisition::DelOrder( 1, $ordernumber1 );
73
    C4::Acquisition::DelOrder( 2, $ordernumber2 );
74
    C4::Budgets::DelBudget( $budgetid );
75
    C4::Acquisition::DelBasket( $basketno );
76
    C4::Bookseller::DelBookseller( $booksellerid );
77
    C4::Biblio::DelBiblio($biblionumber1);
78
    C4::Biblio::DelBiblio($biblionumber2);
79
};
80
79
81
done_testing;
80
$dbh->rollback;
82
- 

Return to bug 5336