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

(-)a/C4/Acquisition.pm (-10 / +10 lines)
Lines 234-240 sub CloseBasket { Link Here
234
    foreach my $order (@orders) {
234
    foreach my $order (@orders) {
235
        $query = qq{
235
        $query = qq{
236
            UPDATE aqorders
236
            UPDATE aqorders
237
            SET orderstatus = 1
237
            SET orderstatus = 'ordered'
238
            WHERE ordernumber = ?;
238
            WHERE ordernumber = ?;
239
        };
239
        };
240
        $sth = $dbh->prepare($query);
240
        $sth = $dbh->prepare($query);
Lines 265-271 sub ReopenBasket { Link Here
265
    foreach my $order (@orders) {
265
    foreach my $order (@orders) {
266
        $query = qq{
266
        $query = qq{
267
            UPDATE aqorders
267
            UPDATE aqorders
268
            SET orderstatus = 0
268
            SET orderstatus = 'new'
269
            WHERE ordernumber = ?;
269
            WHERE ordernumber = ?;
270
        };
270
        };
271
        $sth = $dbh->prepare($query);
271
        $sth = $dbh->prepare($query);
Lines 1471-1477 sub ModReceiveOrder { Link Here
1471
        $sth=$dbh->prepare("
1471
        $sth=$dbh->prepare("
1472
            UPDATE aqorders
1472
            UPDATE aqorders
1473
            SET quantity = ?,
1473
            SET quantity = ?,
1474
                orderstatus = 2
1474
                orderstatus = 'partial'
1475
            WHERE ordernumber = ?
1475
            WHERE ordernumber = ?
1476
        ");
1476
        ");
1477
1477
Lines 1487-1493 sub ModReceiveOrder { Link Here
1487
        $order->{'unitprice'} = $cost;
1487
        $order->{'unitprice'} = $cost;
1488
        $order->{'rrp'} = $rrp;
1488
        $order->{'rrp'} = $rrp;
1489
        $order->{ecost} = $ecost;
1489
        $order->{ecost} = $ecost;
1490
        $order->{'orderstatus'} = 3;    # totally received
1490
        $order->{'orderstatus'} = 'complete';
1491
        $new_ordernumber = NewOrder($order);
1491
        $new_ordernumber = NewOrder($order);
1492
1492
1493
        if ($received_items) {
1493
        if ($received_items) {
Lines 1498-1504 sub ModReceiveOrder { Link Here
1498
    } else {
1498
    } else {
1499
        $sth=$dbh->prepare("update aqorders
1499
        $sth=$dbh->prepare("update aqorders
1500
                            set quantityreceived=?,datereceived=?,invoiceid=?,
1500
                            set quantityreceived=?,datereceived=?,invoiceid=?,
1501
                                unitprice=?,rrp=?,ecost=?,orderstatus=3
1501
                                unitprice=?,rrp=?,ecost=?,orderstatus='complete'
1502
                            where biblionumber=? and ordernumber=?");
1502
                            where biblionumber=? and ordernumber=?");
1503
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1503
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1504
        $sth->finish;
1504
        $sth->finish;
Lines 1549-1555 sub CancelReceipt { Link Here
1549
            SET quantityreceived = ?,
1549
            SET quantityreceived = ?,
1550
                datereceived = ?,
1550
                datereceived = ?,
1551
                invoiceid = ?,
1551
                invoiceid = ?,
1552
                orderstatus = 1
1552
                orderstatus = 'ordered'
1553
            WHERE ordernumber = ?
1553
            WHERE ordernumber = ?
1554
        };
1554
        };
1555
        $sth = $dbh->prepare($query);
1555
        $sth = $dbh->prepare($query);
Lines 1577-1583 sub CancelReceipt { Link Here
1577
        $query = qq{
1577
        $query = qq{
1578
            UPDATE aqorders
1578
            UPDATE aqorders
1579
            SET quantity = ?,
1579
            SET quantity = ?,
1580
                orderstatus = 1
1580
                orderstatus = 'ordered'
1581
            WHERE ordernumber = ?
1581
            WHERE ordernumber = ?
1582
        };
1582
        };
1583
        $sth = $dbh->prepare($query);
1583
        $sth = $dbh->prepare($query);
Lines 1717-1723 sub DelOrder { Link Here
1717
    my $dbh = C4::Context->dbh;
1717
    my $dbh = C4::Context->dbh;
1718
    my $query = "
1718
    my $query = "
1719
        UPDATE aqorders
1719
        UPDATE aqorders
1720
        SET    datecancellationprinted=now(), orderstatus=4
1720
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1721
        WHERE  biblionumber=? AND ordernumber=?
1721
        WHERE  biblionumber=? AND ordernumber=?
1722
    ";
1722
    ";
1723
    my $sth = $dbh->prepare($query);
1723
    my $sth = $dbh->prepare($query);
Lines 2010-2016 sub GetLateOrders { Link Here
2010
        $from .= ' AND borrowers.branchcode LIKE ? ';
2010
        $from .= ' AND borrowers.branchcode LIKE ? ';
2011
        push @query_params, C4::Context->userenv->{branch};
2011
        push @query_params, C4::Context->userenv->{branch};
2012
    }
2012
    }
2013
    $from .= " AND orderstatus <> 4 ";
2013
    $from .= " AND orderstatus <> 'cancelled' ";
2014
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2014
    my $query = "$select $from $having\nORDER BY latesince, basketno, borrowers.branchcode, supplier";
2015
    $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
2015
    $debug and print STDERR "GetLateOrders query: $query\nGetLateOrders args: " . join(" ",@query_params);
2016
    my $sth = $dbh->prepare($query);
2016
    my $sth = $dbh->prepare($query);
Lines 2133-2139 sub GetHistory { Link Here
2133
2133
2134
    $query .= " WHERE 1 ";
2134
    $query .= " WHERE 1 ";
2135
2135
2136
    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne '4';
2136
    $query .= " AND (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') " if $orderstatus ne 'cancelled';
2137
2137
2138
    my @query_params  = ();
2138
    my @query_params  = ();
2139
2139
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 2932-2938 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2932
  `claimed_date` date default NULL, -- last date a claim was generated
2932
  `claimed_date` date default NULL, -- last date a claim was generated
2933
  `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
2933
  `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
2934
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2934
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2935
  `orderstatus` tinyint(2) default 0, -- the current status for this line item
2935
  `orderstatus` varchar(16) default 'new', -- the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled'
2936
  PRIMARY KEY  (`ordernumber`),
2936
  PRIMARY KEY  (`ordernumber`),
2937
  KEY `basketno` (`basketno`),
2937
  KEY `basketno` (`basketno`),
2938
  KEY `biblionumber` (`biblionumber`),
2938
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-5 / +5 lines)
Lines 7017-7027 CREATE TABLE IF NOT EXISTS borrower_files ( Link Here
7017
$DBversion = "3.13.00.XXX";
7017
$DBversion = "3.13.00.XXX";
7018
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7018
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7019
    my $return_count;
7019
    my $return_count;
7020
    $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus tinyint(2) DEFAULT 0 AFTER parent_ordernumber");
7020
    $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus varchar(16) DEFAULT 'new' AFTER parent_ordernumber");
7021
    $dbh->do("UPDATE aqorders SET orderstatus=1 WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
7021
    $dbh->do("UPDATE aqorders SET orderstatus='ordered' WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
7022
    $dbh->do("UPDATE aqorders SET orderstatus=2 WHERE quantity > quantityreceived AND quantityreceived > 0");
7022
    $dbh->do("UPDATE aqorders SET orderstatus='partial' WHERE quantity > quantityreceived AND quantityreceived > 0");
7023
    $dbh->do("UPDATE aqorders SET orderstatus=3 WHERE quantity=quantityreceived");
7023
    $dbh->do("UPDATE aqorders SET orderstatus='complete' WHERE quantity=quantityreceived");
7024
    $dbh->do("UPDATE aqorders SET orderstatus=4 WHERE datecancellationprinted IS NOT NULL");
7024
    $dbh->do("UPDATE aqorders SET orderstatus='cancelled' WHERE datecancellationprinted IS NOT NULL");
7025
    print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";
7025
    print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";
7026
    SetVersion($DBversion);
7026
    SetVersion($DBversion);
7027
}
7027
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt (-11 / +10 lines)
Lines 54-67 Link Here
54
            <label for="orderstatus">Order status: </label>
54
            <label for="orderstatus">Order status: </label>
55
            <select name="orderstatus" id="orderstatus">
55
            <select name="orderstatus" id="orderstatus">
56
                <option value=""></option>
56
                <option value=""></option>
57
                <option value="0">New</option>
57
                <option value="new">New orders</option>
58
                <option value="1">Ordered</option>
58
                <option value="ordered">Pending orders</option>
59
                <option value="2">Partial</option>
59
                <option value="partial">Partially received orders</option>
60
                <option value="3">Complete</option>
60
                <option value="complete">Received orders</option>
61
                <option value="4">Deleted</option>
61
                <option value="cancelled">Cancelled orders</option>
62
            </select>
62
            </select>
63
        </li>
63
        </li>
64
65
        <li>
64
        <li>
66
            <label for="fund">Fund: </label>
65
            <label for="fund">Fund: </label>
67
            <select name="budget" id="fund">
66
            <select name="budget" id="fund">
Lines 145-155 Link Here
145
                    </td>
144
                    </td>
146
                    <td>
145
                    <td>
147
                        [% SWITCH order.orderstatus %]
146
                        [% SWITCH order.orderstatus %]
148
                            [% CASE '0' %]New
147
                            [% CASE 'new' %]New orders
149
                            [% CASE '1' %]Ordered
148
                            [% CASE 'ordered' %]Pending orders
150
                            [% CASE '2' %]Partial
149
                            [% CASE 'partial' %]Partially received orders
151
                            [% CASE '3' %]Complete
150
                            [% CASE 'complete' %]Received orders
152
                            [% CASE '4' %]Deleted
151
                            [% CASE 'cancelled' %]Cancelled orders
153
                        [% END %]
152
                        [% END %]
154
                    </td>
153
                    </td>
155
                    <td>[% order.quantityreceived %]</td>
154
                    <td>[% order.quantityreceived %]</td>
(-)a/t/db_dependent/Acquisition/OrderFromSubscription.t (-1 / +1 lines)
Lines 49-55 my ( $basketno, $ordernumber ) = NewOrder({ Link Here
49
    rrp => $cost,
49
    rrp => $cost,
50
    ecost => $cost,
50
    ecost => $cost,
51
    gstrate => 0.0500,
51
    gstrate => 0.0500,
52
    orderstatus => 0,
52
    orderstatus => 'new',
53
    subscriptionid => $subscription->{subscriptionid},
53
    subscriptionid => $subscription->{subscriptionid},
54
    budget_id => $budget_id,
54
    budget_id => $budget_id,
55
});
55
});
(-)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