From 9c340d7af8d24c24f03522b4e1bc8672c2a8faef Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 15 Mar 2014 12:45:56 +0100 Subject: [PATCH 1/3] Task 672 : Prevent use of product not available --- htdocs/admin/stock.php | 64 +++++++++++++++++++ htdocs/commande/class/commande.class.php | 17 ++++- htdocs/compta/facture/class/facture.class.php | 8 ++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 424ce0e0b8d..9b80662c180 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -77,6 +77,16 @@ if($action) if($action == 'STOCK_USE_VIRTUAL_STOCK') { $res = dolibarr_set_const($db, "STOCK_USE_VIRTUAL_STOCK", GETPOST('STOCK_USE_VIRTUAL_STOCK','alpha'),'chaine',0,'',$conf->entity); } + + if($action == 'STOCK_MUST_BE_ENOUGH_FOR_INVOICE') { + $res = dolibarr_set_const($db, "STOCK_MUST_BE_ENOUGH_FOR_INVOICE", GETPOST('STOCK_MUST_BE_ENOUGH_FOR_INVOICE','alpha'),'chaine',0,'',$conf->entity); + } + if($action == 'STOCK_MUST_BE_ENOUGH_FOR_ORDER') { + $res = dolibarr_set_const($db, "STOCK_MUST_BE_ENOUGH_FOR_ORDER", GETPOST('STOCK_MUST_BE_ENOUGH_FOR_ORDER','alpha'),'chaine',0,'',$conf->entity); + } + if($action == 'STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT') { + $res = dolibarr_set_const($db, "STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", GETPOST('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT','alpha'),'chaine',0,'',$conf->entity); + } if (! $res > 0) $error++; @@ -236,6 +246,60 @@ if (! empty($conf->fournisseur->enabled)) print ''; +// Optio to force stock to be enough before adding a line into document +print '
'; +print ''; +print ''; +print " \n"; +print " \n"; +print ''."\n"; + +if($conf->invoice->enabled) { + $var = !$var; + print ""; + print ''; + print '\n"; + print "\n"; +} + +if($conf->order->enabled) { + $var = !$var; + print ""; + print ''; + print '\n"; + print "\n"; +} + +if($conf->expedition->enabled) { + $var = !$var; + print ""; + print ''; + print '\n"; + print "\n"; +} +print '
".$langs->trans("RuleForStockAvailability")." 
'.$langs->trans("StockMustBeEnoughForInvoice").''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_INVOICE",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE,1); + print ''; + print '
'; + print "
'.$langs->trans("StockMustBeEnoughForOrder").''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_ORDER",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER,1); + print ''; + print '
'; + print "
'.$langs->trans("StockMustBeEnoughForShipment").''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT,1); + print ''; + print '
'; + print "
'; + $virtualdiffersfromphysical=0; if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 5566ce4d90d..3dfdaeb706a 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1037,7 +1037,7 @@ class Commande extends CommonOrder */ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0) { - global $mysoc; + global $mysoc, $conf, $langs; $commandeid=$this->id; @@ -1102,6 +1102,20 @@ class Commande extends CommonOrder $rangmax = $this->line_max($fk_parent_line); $rangtouse = $rangmax + 1; } + + $product_type=$type; + if ($fk_product) + { + $product=new Product($this->db); + $result=$product->fetch($fk_product); + $product_type=$product->type; + + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } + } // TODO A virer // Anciens indicateurs: $price, $remise (a ne plus utiliser) @@ -1126,6 +1140,7 @@ class Commande extends CommonOrder $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; $this->line->fk_product=$fk_product; + $this->line->product_type=$product_type; $this->line->fk_remise_except=$fk_remise_except; $this->line->remise_percent=$remise_percent; $this->line->subprice=$pu_ht; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ec86fbcbaec..f5f526341ff 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2000,7 +2000,7 @@ class Facture extends CommonInvoice */ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type= self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0) { - global $mysoc; + global $mysoc, $conf, $langs; $facid=$this->id; @@ -2072,6 +2072,12 @@ class Facture extends CommonInvoice $product=new Product($this->db); $result=$product->fetch($fk_product); $product_type=$product->type; + + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } } // Insert line From b6a2fa61c8b52a6a8bf975b66c08aa16228f2781 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 15 Mar 2014 12:47:01 +0100 Subject: [PATCH 2/3] Task 672 : only for product not services --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3dfdaeb706a..522016edfd9 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1110,7 +1110,7 @@ class Commande extends CommonOrder $result=$product->fetch($fk_product); $product_type=$product->type; - if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER && $product->stock_reel < $qty) { + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER && $product_type == 0 && $product->stock_reel < $qty) { $this->error=$langs->trans('ErrorStockIsNotEnough'); $this->db->rollback(); return -3; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f5f526341ff..9e51dfc29ed 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2073,7 +2073,7 @@ class Facture extends CommonInvoice $result=$product->fetch($fk_product); $product_type=$product->type; - if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE && $product->stock_reel < $qty) { + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE && $product_type == 0 && $product->stock_reel < $qty) { $this->error=$langs->trans('ErrorStockIsNotEnough'); $this->db->rollback(); return -3; From 1911f6fcdc23f69661b851e89bdb4c4e595918c0 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 15 Mar 2014 14:59:27 +0100 Subject: [PATCH 3/3] Task 672 : add stock limitation on shipment + translation --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/expedition/class/expedition.class.php | 21 +++++++++++++++++++ htdocs/langs/en_US/deliveries.lang | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 522016edfd9..c84c1aba64b 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1104,7 +1104,7 @@ class Commande extends CommonOrder } $product_type=$type; - if ($fk_product) + if (!empty($fk_product)) { $product=new Product($this->db); $result=$product->fetch($fk_product); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9e51dfc29ed..09fbc867bc4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2067,7 +2067,7 @@ class Facture extends CommonInvoice } $product_type=$type; - if ($fk_product) + if (!empty($fk_product)) { $product=new Product($this->db); $result=$product->fetch($fk_product); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 914ec871951..5ac1ba15a77 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -710,12 +710,33 @@ class Expedition extends CommonObject */ function addline($entrepot_id, $id, $qty) { + global $conf, $langs; + $num = count($this->lines); $line = new ExpeditionLigne($this->db); $line->entrepot_id = $entrepot_id; $line->origin_line_id = $id; $line->qty = $qty; + + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { + $orderline = new OrderLine($this->db); + $orderline->fetch($id); + $fk_product = $orderline->fk_product; + + if (!empty($orderline->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($fk_product); + $product_type=$product->type; + + if($product_type == 0 && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } + } + } $this->lines[$num] = $line; } diff --git a/htdocs/langs/en_US/deliveries.lang b/htdocs/langs/en_US/deliveries.lang index c440bea0163..fc4ff2436d4 100644 --- a/htdocs/langs/en_US/deliveries.lang +++ b/htdocs/langs/en_US/deliveries.lang @@ -22,4 +22,5 @@ ToAndDate=To___________________________________ on ____/_____/__________ GoodStatusDeclaration=Have received the goods above in good condition, Deliverer=Deliverer : Sender=Sender -Recipient=Recipient \ No newline at end of file +Recipient=Recipient +ErrorStockIsNotEnough=There's not enough stock \ No newline at end of file