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

(-)a/C4/Acquisition.pm (-42 / +43 lines)
Lines 1622-1669 sub CancelReceipt { Link Here
1622
    } else {
1622
    } else {
1623
        # The order line has a parent, increase parent quantity and delete
1623
        # The order line has a parent, increase parent quantity and delete
1624
        # the order line.
1624
        # the order line.
1625
        $query = qq{
1625
        unless ( $order_obj->basket->is_standing ) {
1626
            SELECT quantity, datereceived
1626
            $query = qq{
1627
            FROM aqorders
1627
                SELECT quantity, datereceived
1628
            WHERE ordernumber = ?
1628
                FROM aqorders
1629
        };
1629
                WHERE ordernumber = ?
1630
        $sth = $dbh->prepare($query);
1630
            };
1631
        $sth->execute($parent_ordernumber);
1631
            $sth = $dbh->prepare($query);
1632
        my $parent_order = $sth->fetchrow_hashref;
1632
            $sth->execute($parent_ordernumber);
1633
        unless($parent_order) {
1633
            my $parent_order = $sth->fetchrow_hashref;
1634
            warn "Parent order $parent_ordernumber does not exist.";
1634
            unless($parent_order) {
1635
            return;
1635
                warn "Parent order $parent_ordernumber does not exist.";
1636
        }
1636
                return;
1637
        if($parent_order->{'datereceived'}) {
1637
            }
1638
            warn "CancelReceipt: parent order is received.".
1638
            if($parent_order->{'datereceived'}) {
1639
                " Can't cancel receipt.";
1639
                warn "CancelReceipt: parent order is received.".
1640
            return;
1640
                    " Can't cancel receipt.";
1641
        }
1641
                return;
1642
        $query = qq{
1642
            }
1643
            UPDATE aqorders
1643
            $query = qq{
1644
            SET quantity = ?,
1644
                UPDATE aqorders
1645
                orderstatus = 'ordered'
1645
                SET quantity = ?,
1646
            WHERE ordernumber = ?
1646
                    orderstatus = 'ordered'
1647
        };
1647
                WHERE ordernumber = ?
1648
        $sth = $dbh->prepare($query);
1648
            };
1649
        my $rv = $sth->execute(
1649
            $sth = $dbh->prepare($query);
1650
            $order->{'quantity'} + $parent_order->{'quantity'},
1650
            my $rv = $sth->execute(
1651
            $parent_ordernumber
1651
                $order->{'quantity'} + $parent_order->{'quantity'},
1652
        );
1652
                $parent_ordernumber
1653
        unless($rv) {
1653
            );
1654
            warn "Cannot update parent order line, so do not cancel".
1654
            unless($rv) {
1655
                " receipt";
1655
                warn "Cannot update parent order line, so do not cancel".
1656
            return;
1656
                    " receipt";
1657
        }
1657
                return;
1658
            }
1658
1659
1659
        # Recalculate tax_value
1660
            # Recalculate tax_value
1660
        $dbh->do(q|
1661
            $dbh->do(q|
1661
            UPDATE aqorders
1662
                UPDATE aqorders
1662
            SET
1663
                SET
1663
                tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1664
                    tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1664
                tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1665
                    tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1665
            WHERE ordernumber = ?
1666
                WHERE ordernumber = ?
1666
        |, undef, $parent_ordernumber);
1667
            |, undef, $parent_ordernumber);
1668
        }
1667
1669
1668
        _cancel_items_receipt( $order_obj, $parent_ordernumber );
1670
        _cancel_items_receipt( $order_obj, $parent_ordernumber );
1669
        # Delete order line
1671
        # Delete order line
1670
- 

Return to bug 17667