[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dolibarr-dev] patch: different types de produits
From: |
Franky Van Liedekerke |
Subject: |
[Dolibarr-dev] patch: different types de produits |
Date: |
Mon, 12 Feb 2007 17:02:15 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20070130) |
Bonjour,
sur mon site de test, vous pouvez tester encore toujours mon patch avec:
- correction gestions de stock
- différent types de produits (les sousproduits maintenant sont le type
"assembly", avec un tout petit query sql on peut converter les
sousproduits qui existent déjà).
https://holem.belnet.be/dolibarr/htdocs
(j'ai fait un sync avec cvs ce matin, et fait un update du db avec le
script de migration)
Dans attach, vous trouvez le patch qui fait tout.
Franky
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/comm/propal.php
dolibarr.new/htdocs/comm/propal.php
--- dolibarr/htdocs/comm/propal.php 2007-02-12 11:14:55.000000000 +0100
+++ dolibarr.new/htdocs/comm/propal.php 2007-02-12 11:24:19.000000000 +0100
@@ -534,7 +534,7 @@
// Ecrase $txtva par celui du produit
if ($_POST['idprod'])
{
- $prod = new Product($db, $_POST['idprod']);
+ $prod = new Product($db);
$prod->fetch($_POST['idprod']);
// multiprix
@@ -575,6 +575,43 @@
$_POST['remise_percent']
);
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ **/
+ if($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ {
+ $prod = new Product($db);
+ $prod->fetch($_POST['idprod']);
+ $prods_arbo = array();
+ if ($prod->isproduct_stockkit()) {
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ }
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ //print "id : ".$value[1].' :qty:
'.$value[0].'<br>';
+ $prod_arbo = new Product($db);
+ $prod_arbo->fetch($value[1]);
+ if($soc->tva_assuj == "0")
+ $tva_tx = 0;
+ else
+ $tva_tx =
get_default_tva($mysoc,$soc,$prod_arbo->tva_tx);
+ $propal->addline(
+ $_POST['propalid'],
+ $prod_arbo->description,
+ $prod_arbo->price,
+ $value[0]*$_POST['qty'],
+ $tva_tx,
+ $value[1],
+ $_POST['remise_percent']
+ );
+ }
+ }
+ }
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ **/
+
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT
."/langs");
@@ -736,6 +773,7 @@
}
+
/*
* Affichage page
*/
@@ -750,7 +788,6 @@
* Affichage fiche propal en mode visu
*
*/
-
if ($mesg) print "$mesg<br>";
$societe = new Societe($db);
@@ -759,6 +796,7 @@
$head = propal_prepare_head($propal);
dolibarr_fiche_head($head, 'comm', $langs->trans('Proposal'));
+
/*
* Confirmation de la suppression de la propale
*/
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/commande/commande.class.php
dolibarr.new/htdocs/commande/commande.class.php
--- dolibarr/htdocs/commande/commande.class.php 2007-01-15 14:36:02.000000000
+0100
+++ dolibarr.new/htdocs/commande/commande.class.php 2007-02-12
11:24:19.000000000 +0100
@@ -316,14 +316,20 @@
if ($this->db->query($sql) )
{
+ # if we maintain stock
if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS ==
1)
{
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
- $prod = new Product($this->db,
$this->lignes[$i]->fk_product);
+ $prod = new Product($this->db);
+ $prod->fetch($this->lignes[$i]->fk_product);
+ $prods_arbo = array();
+ # if the product type is 2 (assembly product)
+ if ($prod->isproduct_assembly()) {
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
+ }
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
@@ -331,7 +337,7 @@
// on décompte le stock de tous les sousproduits
$mouvS = new MouvementStock($this->db);
$entrepot_id = "1";
- $result=$mouvS->livraison($user, $value[1],
$entrepot_id, $value[0]);
+ $result=$mouvS->livraison($user, $value[1],
$entrepot_id, $value[0]*$this->lignes[$i]->qty);
}
}
@@ -368,6 +374,12 @@
{
dolibarr_print_error($this->db);
}
+ // since the order is canceled, remove all ordered lines as well
+ foreach($this->lignes as $ligne) {
+ $product = new Product($this->db);
+ $product->fetch($ligne->fk_product);
+ $product->ajust_stock_commande($ligne->qty, 1);
+ }
}
}
@@ -615,7 +627,7 @@
* \TODO Remplacer les appels a cette fonction par generation
objet Ligne
* inséré dans tableau $this->products
*/
- function add_product($idproduct, $qty, $remise_percent=0)
+ function add_product($idproduct, $qty, $remise_percent=0, $recursive=1)
{
global $conf, $mysoc;
@@ -646,25 +658,28 @@
$this->lines[] = $line;
- /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS À LA COMMANDE
- if($conf->global->PRODUIT_SOUSPRODUITS == 1)
- {
- $prod = new Product($this->db, $idproduct);
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ */
+ if($recursive && $conf->global->PRODUIT_SOUSPRODUITS == 1) {
+ $prod = new Product($this->db);
+ $prod->fetch($idproduct);
+ $prods_arbo = array();
+ if ($prod->isproduct_stockkit()) {
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
- if(sizeof($prods_arbo) > 0)
- {
- foreach($prods_arbo as $key => $value)
- {
+ }
+ if(sizeof($prods_arbo) > 0) {
+ foreach($prods_arbo as $key => $value) {
// print "id : ".$value[1].' :qty: '.$value[0].'<br>';
+ // because $prods_arbo contains all subproducts (recursive)
+ // it is no longer needed to go recursive
if(! in_array($value[1],$this->products))
- $this->add_product($value[1], $value[0]);
-
+ $this->add_product($value[1], $value[0], $remise_percent,
0);
}
}
-
}
- **/
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ */
}
}
@@ -999,7 +1014,7 @@
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid =
l.fk_product)';
$sql.= ' WHERE l.fk_commande = '.$this->id;
- if ($only_product==1) $sql .= ' AND p.fk_product_type = 0';
+ if ($only_product==1) $sql .= ' AND p.fk_product_type <> 1';
$sql .= ' ORDER BY l.rang';
$result = $this->db->query($sql);
@@ -1050,7 +1065,7 @@
$nb=0;
foreach($this->lignes as $ligne)
{
- if ($ligne->fk_product_type == 0) $nb++;
+ if ($ligne->fk_product_type != 1) $nb++;
}
return $nb;
}
@@ -1194,32 +1209,21 @@
{
if ($this->statut == 0)
{
- $sql = "SELECT fk_product, qty";
- $sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
- $sql.= " WHERE rowid = '$idligne';";
-
- $result = $this->db->query($sql);
- if ($result)
- {
- while ($obj = $this->db->fetch_object($result))
- {
+ foreach($this->lignes as $ligne) {
+ if ($ligne->id==$idligne) {
$product = new Product($this->db);
- $product->id = $obj->fk_product;
- $product->ajust_stock_commande($obj->qty, 1);
- }
- $this->db->free($result);
- }
+ $product->fetch($ligne->fk_product);
+ $product->ajust_stock_commande($ligne->qty, 1);
- $Ligne = new CommandeLigne($this->db);
- $Ligne->id = $idligne;
- $Ligne->fk_commande = $this->id; // On en a besoin dans les triggers
- $result = $Ligne->Delete();
+ $result = $ligne->Delete();
$this->update_price();
-
return $result;
}
}
+ }
+ return -1;
+ }
/**
* \brief Applique une remise relative
@@ -1731,7 +1735,7 @@
$op = ($delta > 0) ? 0 : 1;
$product = new Product($this->db);
- $product->id = $LigneOld->produit_id;
+ $product->fetch($LigneOld->produit_id);
$product->ajust_stock_commande(abs($delta), $op);
}
@@ -1817,6 +1821,11 @@
$result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
// Fin appel triggers
+ foreach($this->lignes as $ligne) {
+ $product = new Product($this->db);
+ $product->fetch($ligne->fk_product);
+ $product->ajust_stock_commande($ligne->qty, 1);
+ }
$this->db->commit();
return 1;
}
@@ -2279,7 +2288,7 @@
if ($this->fk_product)
{
$product = new Product($this->db);
- $product->id = $this->fk_product;
+ $product->fetch($this->db);
$product->ajust_stock_commande($this->qty, 0);
}
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/commande/fiche.php
dolibarr.new/htdocs/commande/fiche.php
--- dolibarr/htdocs/commande/fiche.php 2007-02-12 11:14:55.000000000 +0100
+++ dolibarr.new/htdocs/commande/fiche.php 2007-02-12 11:24:19.000000000
+0100
@@ -59,6 +59,7 @@
{
$socid = $user->societe_id;
}
+
if ($user->societe_id >0 && isset($_GET["id"]) && $_GET["id"]>0)
{
$commande = new Commande($db);
@@ -68,8 +69,6 @@
}
}
-
-
// Récupération de l'id de projet
$projetid = 0;
if ($_GET["projetid"])
@@ -274,7 +273,7 @@
// Ecrase $txtva par celui du produit
if ($_POST['idprod'])
{
- $prod = new Product($db, $_POST['idprod']);
+ $prod = new Product($db);
$prod->fetch($_POST['idprod']);
$libelle = $prod->libelle;
@@ -318,6 +317,43 @@
$_POST['remise_percent']
);
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ **/
+ if($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ {
+ $prod = new Product($db);
+ $prod->fetch($_POST['idprod']);
+ $prods_arbo = array();
+ if ($prod->isproduct_stockkit()) {
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ }
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ //print "id : ".$value[1].' :qty:
'.$value[0].'<br>';
+ $prod_arbo = new Product($db);
+ $prod_arbo->fetch($value[1]);
+ if($soc->tva_assuj == "0")
+ $tva_tx = 0;
+ else
+ $tva_tx =
get_default_tva($mysoc,$soc,$prod_arbo->tva_tx);
+ $commande->addline(
+ $_POST['id'],
+ $prod_arbo->description,
+ $prod_arbo->price,
+ $value[0]*$_POST['qty'],
+ $tva_tx,
+ $value[1],
+ $_POST['remise_percent']
+ );
+ }
+ }
+ }
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA COMMANDE
+ **/
+
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright
dolibarr/htdocs/expedition/expedition.class.php
dolibarr.new/htdocs/expedition/expedition.class.php
--- dolibarr/htdocs/expedition/expedition.class.php 2007-01-05
19:20:47.000000000 +0100
+++ dolibarr.new/htdocs/expedition/expedition.class.php 2007-02-12
11:24:19.000000000 +0100
@@ -355,6 +355,13 @@
dolibarr_syslog("expedition.class.php::valid
".$this->error);
return -3;
}
+ // The product is now no longer ordered
+ // so we remove it from the list
+ // so the stock available number is correct
+ // as: stock avail=stock-ordered
+ $product = new Product($this->db);
+ $product->fetch($obj->fk_product);
+ $product->ajust_stock_commande($obj->qty, 1);
$i++;
}
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/html.form.class.php
dolibarr.new/htdocs/html.form.class.php
--- dolibarr/htdocs/html.form.class.php 2007-02-12 11:14:55.000000000 +0100
+++ dolibarr.new/htdocs/html.form.class.php 2007-02-12 11:24:19.000000000
+0100
@@ -2904,6 +2904,32 @@
return 1;
}
+
+ function select_product_types($selected='',$htmlname='type')
+ {
+ global $langs;
+
+ print '<select class="flat" name="'.$htmlname.'">';
+ $product_types=array('0','2','3');
+ foreach ($product_types as $id)
+ {
+ if ($selected == $id)
+ {
+ print '<option value="'.$id.'" selected="true">';
+ }
+ else
+ {
+ print '<option value="'.$id.'">';
+ }
+ if ($id == 0) print $langs->trans("Raw");
+ if ($id == 2) print $langs->trans("Assembly");
+ if ($id == 3) print $langs->trans("Stockkit");
+ print '</option>';
+ }
+ print '</select>';
+ }
+
+
}
?>
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/langs/en_US/products.lang
dolibarr.new/htdocs/langs/en_US/products.lang
--- dolibarr/htdocs/langs/en_US/products.lang 2007-01-14 15:37:36.000000000
+0100
+++ dolibarr.new/htdocs/langs/en_US/products.lang 2007-02-12
11:24:19.000000000 +0100
@@ -27,6 +27,8 @@
LastProducts=Last products
CardProduct0=Product card
CardProduct1=Service card
+CardProduct2=Assembly Product card
+CardProduct3=Stockkit Product card
CardContract=Contract card
Warehouse=Warehouse
Warehouses=Warehouses
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/langs/fr_FR/products.lang
dolibarr.new/htdocs/langs/fr_FR/products.lang
--- dolibarr/htdocs/langs/fr_FR/products.lang 2007-01-14 15:37:36.000000000
+0100
+++ dolibarr.new/htdocs/langs/fr_FR/products.lang 2007-02-12
11:24:19.000000000 +0100
@@ -27,6 +27,8 @@
LastProducts=Derniers produits
CardProduct0=Fiche produit
CardProduct1=Fiche service
+CardProduct2=Fiche produit Assembly
+CardProduct3=Fiche produit Stockkit
CardContract=Fiche contrat
Warehouse=Entrepôt
Warehouses=Entrepôts
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/lib/product.lib.php
dolibarr.new/htdocs/lib/product.lib.php
--- dolibarr/htdocs/lib/product.lib.php 2007-02-01 09:08:57.000000000 +0100
+++ dolibarr.new/htdocs/lib/product.lib.php 2007-02-12 11:24:19.000000000
+0100
@@ -82,7 +82,7 @@
}
// sousproduits
- if($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ if($product->isproduct_assembly() || $product->isproduct_stockkit())
{
$head[$h][0] =
DOL_URL_ROOT."/product/sousproduits/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('AssociatedProducts');
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/product/fiche.php
dolibarr.new/htdocs/product/fiche.php
--- dolibarr/htdocs/product/fiche.php 2007-02-01 09:08:57.000000000 +0100
+++ dolibarr.new/htdocs/product/fiche.php 2007-02-12 11:24:19.000000000
+0100
@@ -142,6 +142,7 @@
$product->description = $_POST["desc"];
$product->note = $_POST["note"];
$product->status = $_POST["statut"];
+ $product->type = $_POST["type"];
$product->seuil_stock_alerte = $_POST["seuil_stock_alerte"];
$product->stock_loc = $_POST["stock_loc"];
$product->duration_value = $_POST["duration_value"];
@@ -431,7 +432,6 @@
{
print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">';
- print '<input type="hidden" name="type" value="'.$_GET["type"].'">'."\n";
if ($_GET["type"]==1) $title=$langs->trans("NewService");
else $title=$langs->trans("NewProduct");
@@ -481,6 +481,16 @@
print '</select>';
print '</td></tr>';
+ if ($_GET["type"]!=1 && $conf->global->PRODUIT_SOUSPRODUITS == 1) {
+ print '<tr><td>'.$langs->trans("Type").'</td><td>';
+ print $html->select_product_types(0,"type");
+ print '</td></tr>';
+ } elseif ($_GET["type"]!=1 && $conf->global->PRODUIT_SOUSPRODUITS == 0) {
+ print '<input type="hidden" name="type" value="0">';
+ } else {
+ print '<input type="hidden" name="type" value="1">';
+ }
+
if ($_GET["type"] != 1 && $conf->stock->enabled)
{
print '<tr><td>Seuil stock</td><td>';
@@ -727,6 +737,13 @@
print $product->getLibStatut(2);
print '</td></tr>';
+ // Type
+ if ($conf->global->PRODUIT_SOUSPRODUITS == 1) {
+ print '<tr><td>'.$langs->trans("Type").'</td><td>';
+ print $product->typestring;
+ print '</td></tr>';
+ }
+
// TVA
print
'<tr><td>'.$langs->trans("VATRate").'</td><td>'.$product->tva_tx.'%</td></tr>';
@@ -832,6 +849,12 @@
print '<option value="0"
selected="true">'.$langs->trans("NotOnSell").'</option>';
}
print '</td></tr>';
+ if ($conf->global->PRODUIT_SOUSPRODUITS == 1 &&
$product->isproduct()) {
+ print '<tr><td>'.$langs->trans("Type").'</td><td colspan="2">';
+ print $html->select_product_types($product->type,"type");
+ print '</td></tr>';
+ }
+
if ($product->isproduct() && $conf->stock->enabled)
{
print "<tr>".'<td>Seuil stock</td><td colspan="2">';
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/product/stock/product.php
dolibarr.new/htdocs/product/stock/product.php
--- dolibarr/htdocs/product/stock/product.php 2007-02-01 09:08:57.000000000
+0100
+++ dolibarr.new/htdocs/product/stock/product.php 2007-02-12
11:24:19.000000000 +0100
@@ -41,7 +41,7 @@
$user->getrights('produit');
$mesg = '';
-if (! $user->rights->produit->lire || ! $product->type == 0 || !
$conf->stock->enabled)
+if (! $user->rights->produit->lire || ! $conf->stock->enabled)
{
accessforbidden();
}
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/product.class.php
dolibarr.new/htdocs/product.class.php
--- dolibarr/htdocs/product.class.php 2007-02-02 09:12:22.000000000 +0100
+++ dolibarr.new/htdocs/product.class.php 2007-02-12 11:27:33.000000000
+0100
@@ -32,7 +32,6 @@
/**
\class Product
\brief Classe permettant la gestion des produits prédéfinis
- \todo comment $typeprodserv
*/
class Product
@@ -72,7 +71,6 @@
var $stats_facture=array();
var $multilangs=array();
- var $typeprodserv;
//! Intitule de l'erreur
var $error;
//! Numero de l'erreur
@@ -92,7 +90,7 @@
global $langs;
$this->db = $DB;
- $this->id = $id ;
+ $this->id = 0 ;
$this->status = 0;
$this->seuil_stock_alerte = 0;
@@ -310,6 +308,7 @@
$sql .= ",weight = " . ($this->new_weight!='' ? "'".$this->new_weight."'"
: 'null');
$sql .= ",weight_units = '" . $this->new_weight_units."'";
$sql .= ",seuil_stock_alerte = '" . $this->seuil_stock_alerte."'";
+ $sql .= ",fk_product_type = '" . $this->type."'";
$sql .= ",description = '" . addslashes($this->description) ."'";
$sql .= ",stock_loc = '" . addslashes($this->stock_loc) ."'";
$sql .= ",note = '" . addslashes($this->note) ."'";
@@ -936,6 +935,10 @@
$result = $this->db->query($sql) ;
if ( $result )
{
+ $num=$this->db->num_rows($result);
+ if ($num != 1) {
+ accessforbidden($langs->trans("NoProductMatching"));
+ }
$result = $this->db->fetch_array();
$this->id = $result["rowid"];
@@ -961,6 +964,21 @@
$this->stock_in_command = $result["stock_commande"];
+ switch ($this->type) {
+ case 0;
+ $this->typestring = $langs->trans("Raw");
+ break;
+ case 1;
+ $this->typestring = $langs->trans("Service");
+ break;
+ case 2;
+ $this->typestring = $langs->trans("Assembly");
+ break;
+ case 3;
+ $this->typestring = $langs->trans("Stockkit");
+ break;
+ }
+
$this->label_url = '<a
href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>';
$this->db->free();
@@ -1585,29 +1603,29 @@
* \brief Remplit le tableau des sous-produits
* \return int < 0 si erreur, > 0 si ok
*/
- function load_subproduct()
- {
- $this->subproducts_id = array();
- $i = 0;
-
- $sql = "SELECT fk_product_subproduct FROM
".MAIN_DB_PREFIX."product_subproduct";
- $sql .= " WHERE fk_product=$this->id;";
-
- if ($result = $this->db->query($sql))
- {
- while ($row = $this->db->fetch_row($result) )
- {
- $this->subproducts_id[$i] = $row[0];
- $i++;
- }
- $this->db->free($result);
- return 0;
- }
- else
- {
- return -1;
- }
- }
+# function load_subproduct()
+# {
+# $this->subproducts_id = array();
+# $i = 0;
+#
+# $sql = "SELECT fk_product_subproduct FROM
".MAIN_DB_PREFIX."product_subproduct";
+# $sql .= " WHERE fk_product=$this->id;";
+#
+# if ($result = $this->db->query($sql))
+# {
+# while ($row = $this->db->fetch_row($result) )
+# {
+# $this->subproducts_id[$i] = $row[0];
+# $i++;
+# }
+# $this->db->free($result);
+# return 0;
+# }
+# else
+# {
+# return -1;
+# }
+# }
/**
@@ -2175,7 +2193,7 @@
* \param mouvement 0 = ajout, 1 = suppression
* \return int < 0 si erreur, > 0 si ok
*/
- function ajust_stock_commande($nbpiece, $mouvement)
+ function ajust_stock_commande($nbpiece, $mouvement, $recursive=1)
{
$op[0] = "+" . trim($nbpiece);
$op[1] = "-" . trim($nbpiece);
@@ -2189,13 +2207,37 @@
if ($this->db->query($sql) )
{
- $this->load_subproduct();
-
- for ($i = 0 ; $i < sizeof($this->subproducts_id) ; $i++)
- {
+ /* For stockkit: all lines are on the commande, so no need to do
+ * adjust the stock seperately
+ * For assembly: we could leave it invisible, but we do the stock
+ * adjust anyway, so even the command has the correct influence
+ * on the avaliable stock
+ */
+ if ($recursive && $this->isproduct_assembly()) {
+ $this -> get_sousproduits_arbo ();
+ $prods_arbo = $this->get_each_prod();
+ if(sizeof($prods_arbo) > 0) {
+ foreach($prods_arbo as $key => $value) {
+ // print "id : ".$value[1].' :qty: '.$value[0].'<br>';
$product = new Product($this->db);
- $product->id = $this->subproducts_id[$i];
- $product->ajust_stock_commande($nbpiece, $mouvement);
+ $product->fetch($value[1]);
+ /* no longer recursive now, since all products are already
+ * in the array $prods_arbo
+ * and otherwise some products would be adjusted twice
+ */
+
$product->ajust_stock_commande($nbpiece*$value[0],$mouvement,0);
+ }
+ }
+
+
+
+ #$this->load_subproduct();
+ #for ($i = 0 ; $i < sizeof($this->subproducts_id) ; $i++)
+ # {
+ # $product = new Product($this->db);
+ # $product->id = $this->subproducts_id[$i];
+ # $product->ajust_stock_commande($nbpiece, $mouvement);
+ # }
}
$this->db->commit();
@@ -2530,5 +2572,28 @@
}
}
+ function isproduct_raw() {
+ if ($this->type == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ function isproduct_assembly() {
+ if ($this->type == 2) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ function isproduct_stockkit() {
+ if ($this->type == 3) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
}
?>
diff -aubwr --ignore-matching-lines='$Id:' --ignore-matching-lines='$Revision:'
--ignore-matching-lines=Copyright dolibarr/htdocs/propal.class.php
dolibarr.new/htdocs/propal.class.php
--- dolibarr/htdocs/propal.class.php 2006-09-19 00:43:45.000000000 +0200
+++ dolibarr.new/htdocs/propal.class.php 2007-02-12 11:24:19.000000000
+0100
@@ -133,7 +133,7 @@
* \TODO Remplacer les appels a cette fonction par generation
objet Ligne
* inséré dans tableau $this->products
*/
- function add_product($idproduct, $qty, $remise_percent=0)
+ function add_product($idproduct, $qty, $remise_percent=0, $recursive=1)
{
global $conf, $mysoc;
@@ -176,6 +176,34 @@
$line->tva_tx=$tva_tx;
$this->products[]=$line;
+
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA
COMMANDE
+ **/
+ if($recursive && $conf->global->PRODUIT_SOUSPRODUITS ==
1)
+ {
+ $prod = new Product($this->db);
+ $prod->fetch($idproduct);
+ $prods_arbo = array();
+ if ($prod->isproduct_stockkit()) {
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ }
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ // print "id : ".$value[1].'
:qty: '.$value[0].'<br>';
+ // because $prods_arbo contains
all subproducts (recursive)
+ // it is no longer needed to go
recursive
+
+ $this->add_product($value[1],
$value[0]*$qty,$remise_percent, 0);
+
+ }
+ }
+
+ }
+ /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS A LA
COMMANDE
+ **/
}
}
- [Dolibarr-dev] patch: different types de produits,
Franky Van Liedekerke <=