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

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

Return to bug 17667