From b62478a39fb0b2b7328304890cb7487c77f194ed Mon Sep 17 00:00:00 2001 From: Jeroen Peelaerts Date: Sat, 26 Jun 2021 00:12:29 +0200 Subject: [PATCH] Do not allow negative stock (#3214) --- application/controllers/Sales.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 2bdf80a90..29005a8d0 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -456,15 +456,17 @@ class Sales extends Secure_Controller $data['warning'] = $stock_warning; } } - else - { - if(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_STANDARD, NULL, NULL, $price)) + else { + $out_of_stock = $this->sale_lib->out_of_stock($item_id_or_number_or_item_kit_or_receipt, $item_location); + if ($out_of_stock == '') { - $data['error'] = $this->lang->line('sales_unable_to_add_item'); + if (!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_STANDARD, NULL, NULL, $price)) { + $data['error'] = $this->lang->line('sales_unable_to_add_item'); + } } else { - $data['warning'] = $this->sale_lib->out_of_stock($item_id_or_number_or_item_kit_or_receipt, $item_location); + $data['warning'] = $out_of_stock; } }