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

Return to bug 10869