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

(-)a/C4/Acquisition.pm (-15 / +31 lines)
Lines 1285-1291 sub NewOrder { Link Here
1285
1285
1286
=head3 NewOrderItem
1286
=head3 NewOrderItem
1287
1287
1288
  &NewOrderItem();
1288
  &NewOrderItem ($itemnumber, $ordernumber);
1289
1289
1290
=cut
1290
=cut
1291
1291
Lines 1750-1779 sub SearchOrders { Link Here
1750
1750
1751
=head3 DelOrder
1751
=head3 DelOrder
1752
1752
1753
  &DelOrder($ordernumber, $biblionumber);
1753
  &DelOrder($ordernumber);
1754
1754
1755
Cancel the order with the given order and biblio numbers. It does not
1755
Cancel the order with the given order, by filling the datecancellationprinted and orderstatus fields.
1756
delete any entries in the aqorders table, it merely marks them as
1756
C<$ordernumber > is mandatory
1757
cancelled.
1757
If no ordernumber is passed, the function returns undef and does not try to update database.
1758
All the items linked with that order are deleted.
1759
Other items are not deleted.
1758
1760
1759
=cut
1761
=cut
1760
1762
1761
sub DelOrder {
1763
sub DelOrder {
1762
    my ($ordernumber,$biblionumber) = @_;
1764
    my ($ordernumber) = @_;
1765
    return unless $ordernumber;
1763
    my $dbh = C4::Context->dbh;
1766
    my $dbh = C4::Context->dbh;
1764
    my $query = "
1767
    my $query = qq {
1765
        UPDATE aqorders
1768
        UPDATE aqorders
1766
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1769
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1767
        WHERE  ordernumber=?
1770
        WHERE  ordernumber = ?
1768
    ";
1771
    };
1769
    my $sth = $dbh->prepare($query);
1772
    my $sth = $dbh->prepare($query);
1770
    $sth->execute($ordernumber );
1773
    $sth->execute($ordernumber );
1771
    $sth->finish;
1774
# get the biblionumber (we need it to run DelItem
1772
    if ($biblionumber) {
1775
    $query = qq{
1773
        my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1776
        SELECT biblionumber
1774
        foreach my $itemnumber (@itemnumbers){
1777
        FROM aqorders
1775
            C4::Items::DelItem( $dbh, $biblionumber, $itemnumber );
1778
        WHERE ordernumber = ?
1776
        }
1779
    };
1780
    $sth = $dbh->prepare($query);
1781
    $sth->execute($ordernumber );
1782
    my $record = $sth->fetchrow_hashref;
1783
# delete items from items and aqorders_items tables
1784
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1785
    foreach my $itemnumber (@itemnumbers) {
1786
        $query = qq{
1787
            DELETE FROM aqorders_items
1788
            WHERE aqorders_items.itemnumber = ?
1789
        };
1790
        $sth = $dbh->prepare($query);
1791
        $sth->execute($itemnumber );
1792
        C4::Items::DelItem( $dbh, $record->{biblionumber}, $itemnumber )  if $record->{biblionumber};
1777
    }
1793
    }
1778
}
1794
}
1779
1795
(-)a/acqui/addorder.pl (-1 / +1 lines)
Lines 323-329 if ( $orderinfo->{quantity} ne '0' ) { Link Here
323
323
324
else { # qty=0, delete the line
324
else { # qty=0, delete the line
325
    my $biblionumber = $input->param('biblionumber');
325
    my $biblionumber = $input->param('biblionumber');
326
    DelOrder($$orderinfo{ordernumber}, $biblionumber );
326
    DelOrder($$orderinfo{ordernumber});
327
    if ($orderinfo->{delbiblio} == 1){
327
    if ($orderinfo->{delbiblio} == 1){
328
     DelBiblio($biblionumber);
328
     DelBiblio($biblionumber);
329
    }
329
    }
(-)a/t/db_dependent/Acquisition.t (-2 / +54 lines)
Lines 7-14 use Modern::Perl; Link Here
7
use POSIX qw(strftime);
7
use POSIX qw(strftime);
8
8
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
use C4::Items qw (AddItem GetItem);
11
use C4::Branch qw (ModBranch);
10
12
11
use Test::More tests => 60;
13
use Test::More tests => 65;
12
14
13
BEGIN {
15
BEGIN {
14
    use_ok('C4::Acquisition');
16
    use_ok('C4::Acquisition');
Lines 220-223 is($order3->{'quantityreceived'}, 2, 'Order not split up'); Link Here
220
is($order3->{'quantity'}, 2, '2 items on order');
222
is($order3->{'quantity'}, 2, '2 items on order');
221
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
223
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
222
224
225
#
226
# test DelOrder
227
# use:
228
# &DelOrder($ordernumber);
229
230
# create 3 items on the same record and link 2 of them to the order
231
232
# Add a branch
233
my $b1 = {
234
    add            => 1,
235
    branchcode     => 'BRA',
236
    branchname     => 'BranchA',
237
    branchaddress1 => 'adr1A',
238
    branchaddress2 => 'adr2A',
239
    branchaddress3 => 'adr3A',
240
    branchzip      => 'zipA',
241
    branchcity     => 'cityA',
242
    branchstate    => 'stateA',
243
    branchcountry  => 'countryA',
244
    branchphone    => 'phoneA',
245
    branchfax      => 'faxA',
246
    branchemail    => 'emailA',
247
    branchurl      => 'urlA',
248
    branchip       => 'ipA',
249
    branchprinter  => undef,
250
    branchnotes    => 'noteA',
251
    opac_info      => 'opacA'
252
};
253
ModBranch($b1);
254
255
my ($item_bibnum1, $item_bibitemnum1, $itemnumber1) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2);
256
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2);
257
my ($item_bibnum3, $item_bibitemnum3, $itemnumber3) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2);
258
NewOrderItem ($itemnumber1, $ordernumber3);
259
NewOrderItem ($itemnumber2, $ordernumber3);
260
261
# If no ordernumber is passed, the function returns undef and does not try to update database
262
my $return_DelOrder = DelOrder ();
263
is($return_DelOrder , undef, 'DelOrder returns undef with no param');
264
# Cancel the order with the given order, by filling the datecancellationprinted and orderstatus fields.
265
DelOrder ($ordernumber3);
266
$order3 = GetOrder( $ordernumber3 );
267
ok(($order3->{'orderstatus'} eq 'cancelled')&& (defined $order3->{'datecancellationprinted'}),'DelOrders update orderstatus and fill datecancellationprinted fields');
268
269
# All the items linked with that order are deleted.
270
is(scalar GetItemnumbersFromOrder($ordernumber3), 0, 'DelOrders delete items linked with cancelled order in aqorders_items table');
271
ok(!defined GetItem($itemnumber1) && !defined GetItem($itemnumber2),  "DelOrder deletes items linked with order in items table");
272
273
# Other items (created manually) are not deleted.
274
is(GetItem($itemnumber3)->{biblionumber},$biblionumber2, "DelOrder does not delete item created manually");
275
223
$dbh->rollback;
276
$dbh->rollback;
224
- 

Return to bug 10869