From 89684748c586cf2484ea8e1511874b7befdbbab6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 24 Feb 2015 19:55:59 +0100 Subject: [PATCH] Debug incdec option. --- htdocs/langs/en_US/products.lang | 2 +- htdocs/product/class/product.class.php | 35 ++-- htdocs/product/composition/card.php | 212 +++++++++++++++---------- 3 files changed, 152 insertions(+), 97 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 3d52da2cd03..841f497b674 100755 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -251,6 +251,6 @@ PriceExpressionEditorHelp4=In product/service price only: #supplier_min_price PriceMode=Price mode PriceNumeric=Number DefaultPrice=Default price -ComposedProductDecreaseStock=Decrease Stock for sub-product +ComposedProductDIncDecStock=Increase/Decrease stock on parent change ComposedProduct=Sub-product MinSupplierPrice=Minimun supplier price diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index fe67938766d..43da5af3cea 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2253,18 +2253,20 @@ class Product extends CommonObject } /** - * Lie un produit associe au produit/service + * Link a product/service to a parent product/service * - * @param int $id_pere Id du produit auquel sera lie le produit a lier - * @param int $id_fils Id du produit a lier + * @param int $id_pere Id of parent product/service + * @param int $id_fils Id of child product/service * @param int $qty Quantity + * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease * @return int < 0 if KO, > 0 if OK */ - function add_sousproduit($id_pere, $id_fils,$qty) + function add_sousproduit($id_pere, $id_fils, $qty, $incdec=1) { // Clean parameters if (! is_numeric($id_pere)) $id_pere=0; if (! is_numeric($id_fils)) $id_fils=0; + if (! is_numeric($incdec)) $incdec=0; $result=$this->del_sousproduit($id_pere, $id_fils); if ($result < 0) return $result; @@ -2290,8 +2292,8 @@ class Product extends CommonObject } else { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty)'; - $sql .= ' VALUES ('.$id_pere.', '.$id_fils.', '.$qty.')'; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association(fk_product_pere,fk_product_fils,qty,incdec)'; + $sql .= ' VALUES ('.$id_pere.', '.$id_fils.', '.$qty.', '.$incdec.')'; if (! $this->db->query($sql)) { dol_print_error($this->db); @@ -2309,25 +2311,25 @@ class Product extends CommonObject /** * Modify composed product * - * @param int $id_pere Id of master product - * @param int $id_fils Id of linked product + * @param int $id_pere Id of parent product/service + * @param int $id_fils Id of child product/service * @param int $qty Quantity - * @param int $incdec increase/descrease stock or not - * * @return int < 0 if KO, > 0 if OK + * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @return int < 0 if KO, > 0 if OK */ - function update_sousproduit($id_pere, $id_fils,$qty, $incdec=1) + function update_sousproduit($id_pere, $id_fils, $qty, $incdec=1) { // Clean parameters if (! is_numeric($id_pere)) $id_pere=0; if (! is_numeric($id_fils)) $id_fils=0; if (! is_numeric($incdec)) $incdec=1; if (! is_numeric($qty)) $qty=1; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.'product_association SET '; $sql.= 'qty='.$qty; $sql.= ',incdec='.$incdec; $sql .= ' WHERE fk_product_pere='.$id_pere.' AND fk_product_fils='.$id_fils; - + if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -2337,7 +2339,7 @@ class Product extends CommonObject { return 1; } - + } /** @@ -2375,7 +2377,7 @@ class Product extends CommonObject */ function is_sousproduit($fk_parent, $fk_child) { - $sql = "SELECT fk_product_pere, qty"; + $sql = "SELECT fk_product_pere, qty, incdec"; $sql.= " FROM ".MAIN_DB_PREFIX."product_association"; $sql.= " WHERE fk_product_pere = '".$fk_parent."'"; $sql.= " AND fk_product_fils = '".$fk_child."'"; @@ -2389,6 +2391,7 @@ class Product extends CommonObject { $obj = $this->db->fetch_object($result); $this->is_sousproduit_qty = $obj->qty; + $this->is_sousproduit_incdec = $obj->incdec; return true; } @@ -2668,7 +2671,7 @@ class Product extends CommonObject $type=(! empty($desc_pere[2]) ? $desc_pere[2] :''); $label=(! empty($desc_pere[3]) ? $desc_pere[3] :''); $incdec=!empty($desc_pere[4]) ? $desc_pere[4] : 0; - + if ($multiply < 1) $multiply=1; //print "XXX We add id=".$id." - label=".$label." - nb=".$nb." - multiply=".$multiply." fullpath=".$compl_path.$label."\n"; diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index 9efa7772cb0..1d551dd9ab1 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -64,18 +64,19 @@ if ($id > 0 || ! empty($ref)) * Actions */ +if ($cancel) $action =''; + // Action association d'un sousproduit -if ($action == 'add_prod' && -$cancel <> $langs->trans("Cancel") && -($user->rights->produit->creer || $user->rights->service->creer)) +if ($action == 'add_prod' && ($user->rights->produit->creer || $user->rights->service->creer)) { $error=0; for ($i=0; $i<$_POST["max_prod"]; $i++) { - if ($_POST["prod_id_chk".$i] > 0) + if ($_POST["prod_qty_".$i] > 0) { - if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) > 0) + if ($product->add_sousproduit($id, $_POST["prod_id_".$i], $_POST["prod_qty_".$i], $_POST["prod_incdec_".$i]) > 0) { + //var_dump($id.' - '.$_POST["prod_id_".$i].' - '.$_POST["prod_qty_".$i]);exit; $action = 'edit'; } else @@ -109,25 +110,17 @@ $cancel <> $langs->trans("Cancel") && exit; } } -else if($action==='save_composed_product') { - +else if($action==='save_composed_product') +{ $TProduct = GETPOST('TProduct', 'array'); - if(!empty($TProduct)) { - - foreach ($TProduct as $id_product => $row) { + if(!empty($TProduct)) + { + foreach ($TProduct as $id_product => $row) + { $product->update_sousproduit($id, $id_product,$row['qty'], isset($row['incdec']) ? 1 : 0 ); } - } - - -} - -if ($cancel == $langs->trans("Cancel")) -{ - $action = ''; - header("Location: card.php?id=".$_POST["id"]); - exit; + $action=''; } @@ -255,94 +248,134 @@ if ($id > 0 || ! empty($ref)) $atleastonenotdefined=0; print ''; print $langs->trans("ProductAssociationList").'
'; - - print '
'; + + print ''; print ''; print ''; - + print ''; - - print ''; - + + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->stock->enabled)) print ''; + print ''; + print ''; + print ''; + foreach($prods_arbo as $value) { $productstatic->id=$value['id']; $productstatic->type=$value['type']; - + $productstatic->label=$value['label']; + $class=($class=='impair')?'pair':'impair'; - + print ''; if ($value['level'] <= 1) { $notdefined=0; - $productstatic->ref=$value['fullpath']; + $productstatic->ref=$value['ref']; $nb_of_subproduct = $value['nb']; - + print ''; - - if($user->rights->produit->creer || $user->rights->service->creer) { - print ''; - print ''; - + print ''; + + // Best buying price + print ''; + + $totalline=price2num($value['nb'] * $product_fourn->fourn_unitprice, 'MT'); + $total+=$totalline; + print ''; + + // Stock + if (! empty($conf->stock->enabled)) print ''; // Real stock + + // Qty + IncDec + if ($user->rights->produit->creer || $user->rights->service->creer) + { + print ''; + print ''; + } else{ print ''; print ''; } - - - - print ''; - $totalline=price2num($value['nb'] * $product_fourn->fourn_unitprice, 'MT'); - $total+=$totalline; - print ''; - if (! empty($conf->stock->enabled)) print ''; // Real stock } - else { - $productstatic->ref=$value['label']; + else + { + //$productstatic->ref=$value['label']; + $productstatic->ref=$value['ref']; print ''; - print ''; + print ''; + + print ''; + print ''; + + if (! empty($conf->stock->enabled)) print ''; // Real stock + print ''; print ''; - print ''; // Real stock } print ''; } print ''; - print ''; + print ''; + + // Minimum buying price + print ''; - print ''; + + print ''; + + // Stock if (! empty($conf->stock->enabled)) print ''; + + print ''; + print ''; print ''; print '
'.$langs->trans('ComposedProduct').''.$langs->trans('Qty').''.$langs->trans('ComposedProductDecreaseStock').''.$langs->trans('MinSupplierPrice').''.$langs->trans('Price').''.$langs->trans('Stock').'
'.$langs->trans('ComposedProduct').''.$langs->trans('Label').''.$langs->trans('MinSupplierPrice').''.$langs->trans('Stock').''.$langs->trans('Qty').''.$langs->trans('ComposedProductDIncDecStock').'
'.$productstatic->getNomUrl(1,'composition').''.$productstatic->label.''; + if ($product_fourn->find_min_price_product_fournisseur($productstatic->id) > 0) + { + print '   '.$langs->trans("BuyingPriceMinShort").': '; + if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(0,0); + else { print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++; } + } + print ''; + print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : '').price($product_fourn->fourn_unitprice,'','',0,0,-1,$conf->currency)); + print ''.$value['stock'].''.$nb_of_subproduct.''.($value['incdec']==1?'x':'' ).''; - if ($product_fourn->find_min_price_product_fournisseur($productstatic->id) > 0) - { - print $langs->trans("BuyingPriceMinShort").': '; - if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(0,0); - else { print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++; } - } - print ''.($notdefined?'':price($totalline,'','',0,0,-1,$conf->currency)).''.$langs->trans("Stock").': '.$value['stock'].''; - for ($i=0; $i < $value['level']; $i++) - { - print '     '; - } + for ($i=0; $i < $value['level']; $i++) print '     '; // Add indentation print $productstatic->getNomUrl(1,'composition').''.$value['nb'].''.$productstatic->label.'  '.$value['nb'].'  '; - print ' '; - if (! empty($conf->stock->enabled)) print '
'.$langs->trans("TotalBuyingPriceMin").': '; - if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')'; + print ''; + print $langs->trans("TotalBuyingPriceMin"); print ''.($atleastonenotdefined?'':price($total,'','',0,0,-1,$conf->currency)).''; + if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')'; + print ($atleastonenotdefined?'':price($total,'','',0,0,-1,$conf->currency)); + print ' '; + if ($user->rights->produit->creer || $user->rights->service->creer) + { + print ''; + } + print ''; + if ($user->rights->produit->creer || $user->rights->service->creer) + { + print ''; + } + print '
'; - - if($user->rights->produit->creer || $user->rights->service->creer) { - print '
'; - } - + + /*if($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + }*/ + print '
'; - + print ''; } // Number of parent virtual products print ''.$langs->trans("ParentProductsNumber").''; print $form->textwithpicto(count($prodsfather), $langs->trans('IfZeroItIsNotUsedByVirtualProduct')); - print ''; + print ''; if (count($prodsfather) > 0) { @@ -409,10 +442,11 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - print ''; print ''; if ($resql) { @@ -464,19 +498,37 @@ if ($id > 0 || ! empty($ref)) if ($conf->global->MAIN_MULTILANGS && $objp->labelm) $labeltoshow=$objp->labelm; print ''; + + if($product->is_sousproduit($id, $objp->rowid)) { - $addchecked = ' checked="checked"'; + //$addchecked = ' checked="checked"'; $qty=$product->is_sousproduit_qty; + $incdec=$product->is_sousproduit_incdec; } else { - $addchecked = ''; - $qty="1"; + //$addchecked = ''; + $qty=0; + $incdec=0; } - print ''; - print ''; + // Contained into package + /*print '';*/ + // Qty + print ''; + + // Inc Dec + print ''; + print ''; } $i++; @@ -493,9 +545,9 @@ if ($id > 0 || ! empty($ref)) if($num > 0) { print '
'; - print 'trans("Update").'">'; + print 'trans("Update").'">'; print '     '; - print ''; + print ''; print '
'; }
'.$langs->trans("Ref").''; + print ''.$langs->trans("ComposedProduct").''; print ''.$langs->trans("Label").''; - print ''.$langs->trans("IsInPackage").''; + //print ''.$langs->trans("IsInPackage").''; print ''.$langs->trans("Qty").''; + print ''.$langs->trans('ComposedProductDIncDecStock').'
'.$labeltoshow.''; - print ''; + print ''; + if ($qty) print ''; + else + { + // TODO Hide field and show it when setting a qty + print ''; + //print ''; + } + print '