From 759b0395bef916cfdac1ce47a01ac58eff0022a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Aug 2008 00:30:52 +0000 Subject: [PATCH] Fix: Bad price when cloning a product with a price with tax --- htdocs/product.class.php | 131 ++-- htdocs/product/fiche.php | 1404 +++++++++++++++++++------------------- 2 files changed, 769 insertions(+), 766 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 1c80e1433b0..2ce6007f3a0 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -48,8 +48,8 @@ class Product extends CommonObject var $libelle; var $description; //! Prix de vente - var $price; - var $price_ttc; + var $price; // Price without tax + var $price_ttc; // Price with tax //! Base de prix (ttc ou ht) var $price_base_type; //! Tableau des prix multiples @@ -122,14 +122,14 @@ class Product extends CommonObject $this->canvas = ''; if ($id>0) $this->fetch($id); } + /** - * \brief V�rifie que la r�f�rence et libell� du produit est non null - * \return int 1 si ok, 0 sinon + * \brief Check that ref and label are ok + * \return int >1 if OK, <=0 if KO */ function check() { - $this->ref = ereg_replace("'","",stripslashes($this->ref)); - $this->ref = ereg_replace("\"","",stripslashes($this->ref)); + $this->ref = sanitize_string(stripslashes($this->ref)); $err = 0; if (strlen(trim($this->ref)) == 0) @@ -149,9 +149,9 @@ class Product extends CommonObject } /** - \brief Insert product in database - \param user Utilisateur qui effectue l'insertion - \return int id du produit ou numero d'erreur < 0 + * \brief Insert product in database + * \param user Utilisateur qui effectue l'insertion + * \return int id du produit ou numero d'erreur < 0 */ function create($user) { @@ -163,20 +163,18 @@ class Product extends CommonObject if ($this->tva_tx=='') $this->tva_tx = 0; if ($this->price=='') $this->price = 0; if ($this->status=='') $this->status = 0; + $price_ht=0; $price_ttc=0; - if ($this->price > 0) + if ($this->price_base_type == 'TTC' && $this->price_ttc > 0) { - if ($this->price_base_type == 'TTC') - { - $price_ttc = price2num($this->price,'MU'); - $price_ht = price2num($this->price / (1 + ($this->tva_tx / 100)),'MU'); - } - else - { - $price_ht = price2num($this->price,'MU'); - $price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU'); - } + $price_ttc = price2num($this->price_ttc,'MU'); + $price_ht = price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),'MU'); + } + if ($this->price_base_type != 'TTC' && $this->price > 0) + { + $price_ht = price2num($this->price,'MU'); + $price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU'); } // Check parameters @@ -186,15 +184,15 @@ class Product extends CommonObject return -1; } - dolibarr_syslog("Product::Create ref=".$this->ref." price=".$this->price." tva_tx=".$this->tva_tx." Categorie : ".$this->catid); + dolibarr_syslog("Product::Create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type." Categorie : ".$this->catid); if ($this->ref) { $this->db->begin(); - + $sql = "SELECT count(*)"; $sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'"; - + $result = $this->db->query($sql) ; if ($result) { @@ -216,7 +214,7 @@ class Product extends CommonObject $sql.= price2num($price_ttc).","; $sql.= "'".$this->price_base_type."',"; $sql.= "'".$this->canvas."')"; - + dolibarr_syslog("Product::Create sql=".$sql); $result = $this->db->query($sql); if ( $result ) @@ -266,7 +264,7 @@ class Product extends CommonObject else { // Le produit existe deja - $this->_setErrNo("Create",257); + $this->error='ErrorProductAlreadyExists'; } } else @@ -286,7 +284,6 @@ class Product extends CommonObject else { $this->db->rollback(); - $this->_setErrNo("Create",265); return -1; } } @@ -325,7 +322,7 @@ class Product extends CommonObject /** - \brief Mise � jour du produit en base + \brief Mise a jour du produit en base \param id id du produit \param user utilisateur qui effectue l'insertion \return int 1 si ok, -1 si ref deja existante, -2 autre erreur @@ -393,7 +390,7 @@ class Product extends CommonObject } /** - * \brief V�rification de l'utilisation du produit en base + * \brief Verification de l'utilisation du produit en base * \param id id du produit */ function verif_prod_use($id) @@ -802,7 +799,7 @@ class Product extends CommonObject $price_ttc = price2num($newprice) * (1 + ($newvat / 100)); $price_ttc = price2num($price_ttc,'MU'); } - + // Ne pas mettre de quote sur le num�riques decimaux. // Ceci provoque des sotckage avec arrondis en base au lieu des valeurs exactes. $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; @@ -949,16 +946,16 @@ class Product extends CommonObject $result = $this->db->query($sql) ; if ($result) { - $result = $this->db->fetch_array(); - $prodid = $result["rowid"]; + $result = $this->db->fetch_array(); + $prodid = $result["rowid"]; } else { - dolibarr_print_error($this->db); - return -1; + dolibarr_print_error($this->db); + return -1; } } - + $this->multiprices[1] = $this->price; $this->multiprices_ttc[1] = $this->price_ttc; $this->multiprices_base_type[1] = $this->price_base_type; @@ -974,33 +971,33 @@ class Product extends CommonObject $result = $this->db->query($sql) ; if ( $result ) { - $result = $this->db->fetch_array(); - - if($result["price"] != "" && $result["price"] != "0.00") - { - $this->multiprices[$i]=$result["price"]; - $this->multiprices_ttc[$i]=$result["price_ttc"]; - $this->multiprices_base_type[$i] = $result["price_base_type"]; - } - else - { - $this->multiprices[$i]=$this->price; - $this->multiprices_ttc[$i]=$this->price_ttc; - $this->multiprices_base_type[$i] = $this->price_base_type; - } + $result = $this->db->fetch_array(); + + if ($result["price"] != "" && $result["price"] != "0.00") + { + $this->multiprices[$i]=$result["price"]; + $this->multiprices_ttc[$i]=$result["price_ttc"]; + $this->multiprices_base_type[$i] = $result["price_base_type"]; + } + else + { + $this->multiprices[$i]=$this->price; + $this->multiprices_ttc[$i]=$this->price_ttc; + $this->multiprices_base_type[$i] = $this->price_base_type; + } } else { - dolibarr_print_error($this->db); - return -1; + dolibarr_print_error($this->db); + return -1; } } - - } + + } - $res=$this->load_stock(); + $res=$this->load_stock(); - return $res; + return $res; } else { @@ -1594,7 +1591,7 @@ class Product extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur "; $sql .= " (datec, fk_product, fk_soc, ref_fourn, fk_user_author)"; $sql .= " VALUES (now(), ".$this->id.", ".$id_fourn.", '".$ref_fourn."', ".$user->id.")"; - + if ($this->db->query($sql)) { $this->product_fourn_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur"); @@ -2021,7 +2018,7 @@ class Product extends CommonObject { $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; $sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$nbpiece.", 0, ".$user->id.")"; - + dolibarr_syslog("Product::create_stock sql=".$sql); $resql=$this->db->query($sql); if ($resql) @@ -2106,7 +2103,7 @@ class Product extends CommonObject { $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; $sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$op[$mouvement].", 0, ".$user->id.")"; - + dolibarr_syslog("Product::ajust_stock sql=".$sql); $resql=$this->db->query($sql); if ($resql) @@ -2202,7 +2199,7 @@ class Product extends CommonObject $this->stock_reel = $this->stock_reel + $row[0]; $i++; } - + $this->no_stock = 0; } else @@ -2241,7 +2238,7 @@ class Product extends CommonObject if (file_exists($dir)) { $originImage = $dir . $file['name']; - + // Cree fichier en taille origine $result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1); @@ -2294,7 +2291,7 @@ class Product extends CommonObject // Cree fichier en taille origine $content = file_get_contents($files); - + $nom = basename($files); $im = fopen($dir.$nom,'wb'); fwrite($im, $content); @@ -2317,7 +2314,7 @@ class Product extends CommonObject if (file_exists($dir)) { $handle=opendir($dir); - + while (($file = readdir($handle)) != false) { if (is_file($dir.$file)) return true; @@ -2355,7 +2352,7 @@ class Product extends CommonObject { $nbphoto++; $photo = $file; - + if ($size == 1) { // Format vignette // On determine nom du fichier vignette $photo_vignette=''; @@ -2427,14 +2424,14 @@ class Product extends CommonObject if (file_exists($dir)) { $handle=opendir($dir); - + while (($file = readdir($handle)) != false) { if (is_file($dir.$file)) { $nbphoto++; $photo = $file; - + // On determine nom du fichier vignette $photo_vignette=''; if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) @@ -2454,7 +2451,7 @@ class Product extends CommonObject if ($nbmax && $nbphoto >= $nbmax) break; } } - + closedir($handle); } @@ -2470,10 +2467,10 @@ class Product extends CommonObject $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette $filename = eregi_replace($dir,'',$file); // Nom du fichier - + // On efface l'image d'origine unlink($file); - + // Si elle existe, on efface la vignette if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$filename,$regs)) { diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 9d1f05d7a71..3e64ac6e98c 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -48,11 +48,11 @@ if (!$user->rights->produit->lire) accessforbidden(); */ if ($_GET["action"] == 'fastappro') { - $product = new Product($db); - $product->fetch($_GET["id"]); - $result = $product->fastappro($user); - Header("Location: fiche.php?id=".$_GET["id"]); - exit; + $product = new Product($db); + $product->fetch($_GET["id"]); + $result = $product->fastappro($user); + Header("Location: fiche.php?id=".$_GET["id"]); + exit; } @@ -60,7 +60,7 @@ if ($_GET["action"] == 'fastappro') if ($_POST["action"] == 'add' && $user->rights->produit->creer) { $error=0; - + if (empty($_POST["libelle"])) { $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Label')).'
'; @@ -69,7 +69,7 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) $_GET["type"] = $_POST["type"]; $error++; } - + if (! $error) { if ($_POST["canvas"] <> '' && file_exists('canvas/product.'.$_POST["canvas"].'.class.php') ) @@ -82,11 +82,12 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) { $product = new Product($db); } - + $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; - $product->price = $_POST["price"]; $product->price_base_type = $_POST["price_base_type"]; + if ($product->price_base_type == 'TTC') $product->price_ttc = $_POST["price"]; + else $product->price = $_POST["price"]; $product->tva_tx = $_POST["tva_tx"]; $product->type = $_POST["type"]; $product->status = $_POST["statut"]; @@ -117,14 +118,14 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) } } } - + if ( $value != $current_lang ) $e_product = $product; - + // Produit spécifique // $_POST n'est pas utilise dans la classe Product // mais dans des classes qui hérite de Product $id = $product->create($user, $_POST); - + if ($id > 0) { Header("Location: fiche.php?id=".$id); @@ -142,8 +143,8 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) // Action mise a jour d'un produit ou service if ($_POST["action"] == 'update' && - $_POST["cancel"] <> $langs->trans("Cancel") && - $user->rights->produit->creer) +$_POST["cancel"] <> $langs->trans("Cancel") && +$user->rights->produit->creer) { $product = new Product($db); if ($product->fetch($_POST["id"])) @@ -162,7 +163,7 @@ if ($_POST["action"] == 'update' && $product->weight_units = $_POST["weight_units"]; $product->volume = $_POST["volume"]; $product->volume_units = $_POST["volume_units"]; - + if ($product->check()) { if ($product->update($product->id, $user) > 0) @@ -183,13 +184,13 @@ if ($_POST["action"] == 'update' && $_GET["id"] = $_POST["id"]; $mesg = $langs->trans("ErrorProductBadRefOrLabel"); } - + // Produit spécifique if ($product->canvas <> '' && file_exists('canvas/product.'.$product->canvas.'.class.php') ) { $class = 'Product'.ucfirst($product->canvas); include_once('canvas/product.'.$product->canvas.'.class.php'); - + $product = new $class($db); if ($product->FetchCanvas($_POST["id"])) { @@ -202,70 +203,75 @@ if ($_POST["action"] == 'update' && // clone d'un produit if ($_GET["action"] == 'clone' && $user->rights->produit->creer) { - $db->begin(); - - $product = new Product($db); - $originalId = $_GET["id"]; - if ($product->fetch($_GET["id"]) > 0) - { - $product->ref = "Clone ".$product->ref; - $product->status = 0; - $product->id = null; - - if ($product->check()) + $db->begin(); + + $product = new Product($db); + $originalId = $_GET["id"]; + if ($product->fetch($_GET["id"]) > 0) { - $id = $product->create($user); - if ($id > 0) - { - // $product->clone_fournisseurs($originalId, $id); - - $db->commit(); - - Header("Location: fiche.php?id=$id"); - $db->close(); - exit; - } - else if ($id == -3) - { - $db->rollback(); - - $_error = 1; - $_GET["action"] = ""; - dolibarr_print_error($product->db); - } - else - { - $db->rollback(); - dolibarr_print_error($product->db); - } + $product->ref = "Clone ".$product->ref; + $product->status = 0; + $product->id = null; + + if ($product->check()) + { + $id = $product->create($user); + if ($id > 0) + { + // $product->clone_fournisseurs($originalId, $id); + + $db->commit(); + $db->close(); + + Header("Location: fiche.php?id=$id"); + exit; + } + else + { + if ($product->error == 'ErrorProductAlreadyExists') + { + $db->rollback(); + + $_error = 1; + $_GET["action"] = ""; + + $mesg='
'.$langs->trans("ErrorProductAlreadyExists",$product->ref).'
'; + //dolibarr_print_error($product->db); + } + else + { + $db->rollback(); + dolibarr_print_error($product->db); + } + } + } + } + else + { + $db->rollback(); + dolibarr_print_error($product->db); } - } - else - { - $db->rollback(); - dolibarr_print_error($product->db); - } } /* -* Suppression d'un produit/service pas encore affect -*/ + * Suppression d'un produit/service pas encore affect + */ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->produit->supprimer) { - $product = new Product($db); - $product->fetch($_GET['id']); - $result = $product->delete($_GET['id']); - - if ($result == 0) - { - Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.$product->ref); - exit; - } - else - { - $reload = 0; - $_GET['action']=''; - } + $product = new Product($db); + $product->fetch($_GET['id']); + $result = $product->delete($_GET['id']); + + if ($result == 0) + { + Header('Location: '.DOL_URL_ROOT.'/product/liste.php?delprod='.$product->ref); + exit; + } + else + { + $reload = 0; + $_GET['action']=''; + } } @@ -274,208 +280,49 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user- */ if ($_POST["action"] == 'addinpropal') { - $propal = New Propal($db); - $result=$propal->fetch($_POST["propalid"]); - if ($result <= 0) - { - dolibarr_print_error($db,$propal->error); - exit; - } - - $soc = new Societe($db); - $result=$soc->fetch($propal->socid,$user); - if ($result <= 0) - { - dolibarr_print_error($db,$soc->error); - exit; - } - - $prod = new Product($db); - $result=$prod->fetch($_GET['id']); - if ($result <= 0) - { - dolibarr_print_error($db,$prod->error); - exit; - } - - $desc = $prod->description; - $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); - - $price_base_type = 'HT'; - - // multiprix - if ($conf->global->PRODUIT_MULTIPRICES == 1) - { - $pu_ht = $prod->multiprices[$soc->price_level]; - $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; - $price_base_type = $prod->multiprices_base_type[$soc->price_level]; - } - else - { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_base_type = $prod->price_base_type; - } - - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $prod->tva_tx) + $propal = New Propal($db); + $result=$propal->fetch($_POST["propalid"]); + if ($result <= 0) { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); - } + dolibarr_print_error($db,$propal->error); + exit; } - - $result = $propal->addline($propal->id, - $desc, - $pu_ht, - $_POST["qty"], - $tva_tx, - $prod->id, - $_POST["remise_percent"], - $price_base_type, - $pu_ttc - ); - if ($result > 0) - { - Header("Location: ".DOL_URL_ROOT."/comm/propal.php?propalid=".$propal->id); - return; - } - - $mesg = $langs->trans("ErrorUnknown").": $result"; -} -/* - * Ajout du produit dans une commande - */ -if ($_POST["action"] == 'addincommande') -{ - $commande = new Commande($db); - $result=$commande->fetch($_POST["commandeid"]); - if ($result <= 0) - { - dolibarr_print_error($db,$commande->error); - exit; - } - - $soc = new Societe($db); - $result=$soc->fetch($commande->socid,$user); - if ($result <= 0) - { - dolibarr_print_error($db,$soc->error); - exit; - } - - $prod = new Product($db); - $result=$prod->fetch($_GET['id']); - if ($result <= 0) - { - dolibarr_print_error($db,$prod->error); - exit; - } - - $desc = $prod->description; - $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); - - // multiprix - if ($conf->global->PRODUIT_MULTIPRICES == 1) - { - $pu_ht = $prod->multiprices[$soc->price_level]; - $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; - $price_base_type = $prod->multiprices_base_type[$soc->price_level]; - } - else - { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_base_type = $prod->price_base_type; - } - - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $prod->tva_tx) + $soc = new Societe($db); + $result=$soc->fetch($propal->socid,$user); + if ($result <= 0) { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); - } + dolibarr_print_error($db,$soc->error); + exit; } - - $result = $commande->addline($commande->id, - $desc, - $pu_ht, - $_POST["qty"], - $tva_tx, - $prod->id, - $_POST["remise_percent"], - '', - '', //Todo: voir si fk_remise_except est encore valable car n'apparait plus dans les propales - $price_base_type, - $pu_ttc - ); - if ($result > 0) - { - Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id); - exit; - } -} + $prod = new Product($db); + $result=$prod->fetch($_GET['id']); + if ($result <= 0) + { + dolibarr_print_error($db,$prod->error); + exit; + } -/* - * Ajout du produit dans une facture - */ -if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer) -{ - $facture = New Facture($db); - $result=$facture->fetch($_POST["factureid"]); - if ($result <= 0) - { - dolibarr_print_error($db,$facture->error); - exit; - } - - $soc = new Societe($db); - $soc->fetch($facture->socid,$user); - if ($result <= 0) - { - dolibarr_print_error($db,$soc->error); - exit; - } - - $prod = new Product($db); - $result = $prod->fetch($_GET["id"]); - if ($result <= 0) - { - dolibarr_print_error($db,$prod->error); - exit; - } - - $desc = $prod->description; - $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); + $desc = $prod->description; + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); - // multiprix - if ($conf->global->PRODUIT_MULTIPRICES == 1) - { - $pu_ht = $prod->multiprices[$soc->price_level]; - $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; - $price_base_type = $prod->multiprices_base_type[$soc->price_level]; - } - else - { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; + $price_base_type = 'HT'; + + // multiprix + if ($conf->global->PRODUIT_MULTIPRICES == 1) + { + $pu_ht = $prod->multiprices[$soc->price_level]; + $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; + $price_base_type = $prod->multiprices_base_type[$soc->price_level]; + } + else + { + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; $price_base_type = $prod->price_base_type; } - + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($tva_tx != $prod->tva_tx) @@ -483,41 +330,200 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer) if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } + } else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } - - $result = $facture->addline($facture->id, - $desc, - $pu_ht, - $_POST["qty"], - $tva_tx, - $prod->id, - $_POST["remise_percent"], + + $result = $propal->addline($propal->id, + $desc, + $pu_ht, + $_POST["qty"], + $tva_tx, + $prod->id, + $_POST["remise_percent"], + $price_base_type, + $pu_ttc + ); + if ($result > 0) + { + Header("Location: ".DOL_URL_ROOT."/comm/propal.php?propalid=".$propal->id); + return; + } + + $mesg = $langs->trans("ErrorUnknown").": $result"; +} + +/* + * Ajout du produit dans une commande + */ +if ($_POST["action"] == 'addincommande') +{ + $commande = new Commande($db); + $result=$commande->fetch($_POST["commandeid"]); + if ($result <= 0) + { + dolibarr_print_error($db,$commande->error); + exit; + } + + $soc = new Societe($db); + $result=$soc->fetch($commande->socid,$user); + if ($result <= 0) + { + dolibarr_print_error($db,$soc->error); + exit; + } + + $prod = new Product($db); + $result=$prod->fetch($_GET['id']); + if ($result <= 0) + { + dolibarr_print_error($db,$prod->error); + exit; + } + + $desc = $prod->description; + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); + + // multiprix + if ($conf->global->PRODUIT_MULTIPRICES == 1) + { + $pu_ht = $prod->multiprices[$soc->price_level]; + $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; + $price_base_type = $prod->multiprices_base_type[$soc->price_level]; + } + else + { + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; + } + + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + + $result = $commande->addline($commande->id, + $desc, + $pu_ht, + $_POST["qty"], + $tva_tx, + $prod->id, + $_POST["remise_percent"], + '', + '', //Todo: voir si fk_remise_except est encore valable car n'apparait plus dans les propales + $price_base_type, + $pu_ttc + ); + + if ($result > 0) + { + Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id); + exit; + } +} + +/* + * Ajout du produit dans une facture + */ +if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer) +{ + $facture = New Facture($db); + $result=$facture->fetch($_POST["factureid"]); + if ($result <= 0) + { + dolibarr_print_error($db,$facture->error); + exit; + } + + $soc = new Societe($db); + $soc->fetch($facture->socid,$user); + if ($result <= 0) + { + dolibarr_print_error($db,$soc->error); + exit; + } + + $prod = new Product($db); + $result = $prod->fetch($_GET["id"]); + if ($result <= 0) + { + dolibarr_print_error($db,$prod->error); + exit; + } + + $desc = $prod->description; + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); + + // multiprix + if ($conf->global->PRODUIT_MULTIPRICES == 1) + { + $pu_ht = $prod->multiprices[$soc->price_level]; + $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; + $price_base_type = $prod->multiprices_base_type[$soc->price_level]; + } + else + { + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_base_type = $prod->price_base_type; + } + + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } + } + + $result = $facture->addline($facture->id, + $desc, + $pu_ht, + $_POST["qty"], + $tva_tx, + $prod->id, + $_POST["remise_percent"], '', '', '', '', '', - $price_base_type, - $pu_ttc - ); - - if ($result > 0) - { - Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id); - exit; - } + $price_base_type, + $pu_ttc + ); + + if ($result > 0) + { + Header("Location: ".DOL_URL_ROOT."/compta/facture.php?facid=".$facture->id); + exit; + } } if ($_POST["cancel"] == $langs->trans("Cancel")) { - $action = ''; - Header("Location: fiche.php?id=".$_POST["id"]); - exit; + $action = ''; + Header("Location: fiche.php?id=".$_POST["id"]); + exit; } @@ -538,13 +544,13 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) { $class = 'Product'.ucfirst($_GET["canvas"]); include_once($filecanvas); - + $product = new $class($db,0,$user); } else { $product = new Product($db); - } + } } $product->assign_smarty_values($smarty, 'create'); @@ -554,21 +560,21 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) $product = $e_product; } } - + llxHeader("","",$langs->trans("CardProduct".$product->type)); - if ($mesg) print "$mesg\n"; + if ($mesg) print $mesg."\n"; if (! $conf->global->PRODUCT_CANVAS_ABILITY || !$_GET["canvas"]) { print '
'; print ''; print ''."\n"; - + if ($_GET["type"]==1) $title=$langs->trans("NewService"); else $title=$langs->trans("NewProduct"); print_fiche_titre($title); - + print ''; print ''; print ''; - + // Stock min level if ($_GET["type"] != 1 && $conf->stock->enabled) { @@ -598,10 +604,10 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) { print ''; } - + // Description (utilisé dans facture, propale...) print '"; - + if ($_GET["type"] == 1) { print ''; } - + // Note (invisible sur facture, propales...) print '"; print '
'.$langs->trans("Ref").''; @@ -586,7 +592,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); $html->select_array('statut',$statutarray,$_POST["statut"]); print '
'.$langs->trans("Description").''; - + if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); @@ -613,9 +619,9 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) print ''; } - + print "
'.$langs->trans("Duration").'  '; @@ -638,7 +644,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) print $html->select_measuring_units("volume_units","volume"); print '
'.$langs->trans("NoteNotVisibleOnBill").''; if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) @@ -654,9 +660,9 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) } print "
'; - + print '
'; - + print ''; if($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -680,26 +686,26 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); print ''; } - + // VAT print ''; - + print '
'.$langs->trans("VATRate").''; print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,''); print '
'; print '
'; - + print ''; print ''; print '
'; - + print '
'; } else { //RODO - // On assigne les valeurs meme en creation car elles sont definies si + // On assigne les valeurs meme en creation car elles sont definies si // on revient en erreur // $smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$_GET["canvas"].'/'; @@ -711,47 +717,47 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) } /** -* -* Fiche produit -* -*/ + * + * Fiche produit + * + */ if ($_GET["id"] || $_GET["ref"]) { $product = new Product($db); - + if ($_GET["ref"]) - { + { $result = $product->fetch('',$_GET["ref"]); $_GET["id"] = $product->id; - } + } elseif ($_GET["id"]) - { + { $result = $product->fetch($_GET["id"]); - } - + } + // Gestion des produits specifiques $product->canvas = ''; if ($conf->global->PRODUCT_CANVAS_ABILITY) { if ($product->canvas <> '' && file_exists('canvas/product.'.$product->canvas.'.class.php') ) - { - $class = 'Product'.ucfirst($product->canvas); - include_once('canvas/product.'.$product->canvas.'.class.php'); - $product = new $class($db); - - $result = $product->FetchCanvas($_GET["id"],'',$_GET["action"]); - - $smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$product->canvas.'/'; - - $product->assign_smarty_values($smarty,$_GET["action"]); - } + { + $class = 'Product'.ucfirst($product->canvas); + include_once('canvas/product.'.$product->canvas.'.class.php'); + $product = new $class($db); + + $result = $product->FetchCanvas($_GET["id"],'',$_GET["action"]); + + $smarty->template_dir = DOL_DOCUMENT_ROOT.'/product/canvas/'.$product->canvas.'/'; + + $product->assign_smarty_values($smarty,$_GET["action"]); + } } // END TODO RODO FINISH THIS PART - + llxHeader("","",$langs->trans("CardProduct".$product->type)); - + if ( $result ) - { + { if ($_GET["action"] <> 'edit') { $head=product_prepare_head($product, $user); @@ -761,9 +767,9 @@ if ($_GET["id"] || $_GET["ref"]) // Confirmation de la suppression de la facture if ($_GET["action"] == 'delete') { - $html = new Form($db); - $html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete"); - print "
\n"; + $html = new Form($db); + $html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete"); + print "
\n"; } print($mesg); @@ -771,8 +777,8 @@ if ($_GET["id"] || $_GET["ref"]) if ($_GET["action"] <> 'edit' && $product->canvas <> '') { /* - * Smarty en mode visu - */ + * Smarty en mode visu + */ $smarty->assign('fiche_cursor_prev',$previous_ref); $smarty->assign('fiche_cursor_next',$next_ref); @@ -783,17 +789,17 @@ if ($_GET["id"] || $_GET["ref"]) print "\n\n"; } - + if ($_GET["action"] <> 'edit' && $product->canvas == '') { // En mode visu print ''; - + // Reference print ''; - + $nblignes=6; if ($product->isproduct() && $conf->stock->enabled) $nblignes++; if ($product->isservice()) $nblignes++; @@ -805,15 +811,15 @@ if ($_GET["id"] || $_GET["ref"]) print ''; } print ''; - + // Libelle print ''; - + // MultiPrix if($conf->global->PRODUIT_MULTIPRICES == 1) { print ''; - + if ($product->price_base_type == 'TTC') { print ''; for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) { print ''; - + if ($product->multiprices_base_type["$i"] == 'TTC') { print ''; } } @@ -867,15 +873,15 @@ if ($_GET["id"] || $_GET["ref"]) // TVA print ''; - + // Statut print ''; - + // Description print ''; - + if ($product->isservice()) { // Duration @@ -889,7 +895,7 @@ if ($_GET["id"] || $_GET["ref"]) $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year")); } print $langs->trans($dur[$product->duration_unit])." "; - + print ''; } else @@ -921,25 +927,25 @@ if ($_GET["id"] || $_GET["ref"]) print "
'.$langs->trans("Ref").''; print $html->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").' 1'.price($product->price_ttc); @@ -822,13 +828,13 @@ if ($_GET["id"] || $_GET["ref"]) { print ''.price($product->price); } - + print ' '.$langs->trans($product->price_base_type); print '
'.$langs->trans("SellingPrice").' '.$i.''.price($product->multiprices_ttc["$i"]); @@ -837,7 +843,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ''.price($product->multiprices["$i"]); } - + if ($product->multiprices_base_type["$i"]) { print ' '.$langs->trans($product->multiprices_base_type["$i"]); @@ -846,7 +852,7 @@ if ($_GET["id"] || $_GET["ref"]) { print ' '.$langs->trans($product->price_base_type); } - + print '
'.$langs->trans("VATRate").''.vatrate($product->tva_tx,true).'
'.$langs->trans("Status").''; print $product->getLibStatut(2); print '
'.$langs->trans("Description").''.nl2br($product->description).'
\n"; print "\n\n"; } - } - - /* - * Fiche en mode edition - */ - if ($_GET["action"] == 'edit' && $user->rights->produit->creer) - { - if ($product->isservice()) { - print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Service').' : '.$product->ref, ""); - } else { - print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Product').' : '.$product->ref, ""); - } - - if ($mesg) { - print '
'.$mesg.'

'; - } - - if ( $product->canvas == '') + } + + /* + * Fiche en mode edition + */ + if ($_GET["action"] == 'edit' && $user->rights->produit->creer) { + if ($product->isservice()) { + print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Service').' : '.$product->ref, ""); + } else { + print_fiche_titre($langs->trans('Modify').' '.$langs->trans('Product').' : '.$product->ref, ""); + } + + if ($mesg) { + print '
'.$mesg.'

'; + } + + if ( $product->canvas == '') + { print "\n"; print "
\n"; print ''; @@ -953,91 +959,91 @@ if ($_GET["id"] || $_GET["ref"]) print ''.$langs->trans("Status").''; print ''; print ''; - + if ($product->isproduct() && $conf->stock->enabled) - { - print "".''.$langs->trans("StockLimit").''; - print ''; - print ''; - } + { + print "".''.$langs->trans("StockLimit").''; + print ''; + print ''; + } else - { - print ''; - } + { + print ''; + } // Description (utilisé dans facture, propale...) print ''.$langs->trans("Description").''; print "\n"; if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) - { - require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('desc',$product->description,160,'dolibarr_notes','',false); - $doleditor->Create(); - } + { + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('desc',$product->description,160,'dolibarr_notes','',false); + $doleditor->Create(); + } else - { - print '"; - } + { + print '"; + } print ""; print "\n"; if ($product->isservice()) - { - // Duration - print ''.$langs->trans("Duration").''; - print '  '; - print 'duration_unit=='h'?' checked':'').'>'.$langs->trans("Hour"); - print '  '; - print 'duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); - print '  '; - print 'duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); - print '  '; - print 'duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); - print '  '; - print 'duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); + { + // Duration + print ''.$langs->trans("Duration").''; + print '  '; + print 'duration_unit=='h'?' checked':'').'>'.$langs->trans("Hour"); + print '  '; + print 'duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); + print '  '; + print 'duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); + print '  '; + print 'duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); + print '  '; + print 'duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); - print ''; - } + print ''; + } else - { - // Weight / Volume - print ''.$langs->trans("Weight").''; - print ' '; - print $html->select_measuring_units("weight_units", "weight", $product->weight_units); - print ''; - print ''.$langs->trans("Volume").''; - print ' '; - print $html->select_measuring_units("volume_units", "volume", $product->volume_units); - print ''; - } + { + // Weight / Volume + print ''.$langs->trans("Weight").''; + print ' '; + print $html->select_measuring_units("weight_units", "weight", $product->weight_units); + print ''; + print ''.$langs->trans("Volume").''; + print ' '; + print $html->select_measuring_units("volume_units", "volume", $product->volume_units); + print ''; + } // Note print ''.$langs->trans("NoteNotVisibleOnBill").''; if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) - { - require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('note',$product->note,200,'dolibarr_notes','',false); - $doleditor->Create(); - } + { + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('note',$product->note,200,'dolibarr_notes','',false); + $doleditor->Create(); + } else - { - print '"; - } + { + print '"; + } print ""; print ' '; @@ -1045,20 +1051,20 @@ if ($_GET["id"] || $_GET["ref"]) print ''; print '
'; print "\n"; - } - else - { + } + else + { $tvaarray = load_tva($db,"tva_tx",$conf->defaulttx,$mysoc,'',''); $smarty->assign('tva_taux_value', $tvaarray['value']); $smarty->assign('tva_taux_libelle', $tvaarray['label']); $smarty->display($product->canvas.'-edit.tpl'); + } } - } } else if (!$_GET["action"] == 'create') { - Header("Location: index.php"); - exit; + Header("Location: index.php"); + exit; } @@ -1082,20 +1088,20 @@ if ($_GET["action"] == '') } /* - if ($product->isproduct() && $user->rights->commande->creer) - { - $langs->load('orders'); - print ''; - print $langs->trans("CreateCustomerOrder").''; - } + if ($product->isproduct() && $user->rights->commande->creer) + { + $langs->load('orders'); + print ''; + print $langs->trans("CreateCustomerOrder").''; + } - if ($product->isproduct() && $user->rights->fournisseur->commande->creer) - { - $langs->load('orders'); - print ''; - print $langs->trans("CreateSupplierOrder").''; - } - */ + if ($product->isproduct() && $user->rights->fournisseur->commande->creer) + { + $langs->load('orders'); + print ''; + print $langs->trans("CreateSupplierOrder").''; + } + */ $product_is_used = $product->verif_prod_use($product->id); if ($user->rights->produit->supprimer) @@ -1120,83 +1126,83 @@ print "\n
\n"; if ($_GET["id"] && $_GET["action"] == '' && $product->status) { - $propal = New Propal($db); + $propal = New Propal($db); - print ''; + print '
'; - // Propals - if($conf->propal->enabled && $user->rights->propale->creer) - { - $langs->load("propal"); - - print ''; - - if ($user->rights->societe->client->voir) + // Propals + if($conf->propal->enabled && $user->rights->propale->creer) { + $langs->load("propal"); + + print ''; + + if ($user->rights->societe->client->voir) + { print ''; - } - else - { + } + else + { print ''; - } + } - print ''; + print ''; - // Liste de "Mes propals" - print ''; + print ''; - if ($user->rights->societe->client->voir) - { + if ($user->rights->societe->client->voir) + { // Liste de "Other propals" print ''; + } + + print ''; } - print ''; - } - - $commande = New Commande($db); + $commande = New Commande($db); - // Commande - if($conf->commande->enabled && $user->rights->commande->creer) - { - $langs->load("orders"); - - print ''; - - if ($user->rights->societe->client->voir) + // Commande + if($conf->commande->enabled && $user->rights->commande->creer) { + $langs->load("orders"); + + print ''; + + if ($user->rights->societe->client->voir) + { print ''; - } - else - { + } + else + { print ''; - } + } - print ''; + print ''; - // Liste de "Mes commandes" - print ''; + print ''; - if ($user->rights->societe->client->voir) - { + if ($user->rights->societe->client->voir) + { // Liste de "Other orders" print ''; + + print ''; } - print ''; - print ''; - } - - // Factures - if($conf->facture->enabled && $user->rights->facture->creer) - { - - - print ''; - - if ($user->rights->societe->client->voir) + // Factures + if($conf->facture->enabled && $user->rights->facture->creer) { + + + print ''; + + if ($user->rights->societe->client->voir) + { print ''; - } - else - { + } + else + { print ''; - } + } - print ''; + print ''; - // Liste de Mes factures - print ''; + print ''; - if ($user->rights->societe->client->voir) - { + if ($user->rights->societe->client->voir) + { print ''; + } + print "
'; - print $langs->trans("AddToMyProposals") . '
'; + print $langs->trans("AddToMyProposals") . ''; print $langs->trans("AddToOtherProposals").' 
'; + // Liste de "Mes propals" + print '
'; - $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; - $sql .=" WHERE p.fk_soc = s.rowid AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id; - $sql .= " ORDER BY p.datec DESC, tms DESC"; + $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.ref,".$db->pdate("p.datep")." as dp"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; + $sql .=" WHERE p.fk_soc = s.rowid AND p.fk_statut = 0 AND p.fk_user_author = ".$user->id; + $sql .= " ORDER BY p.datec DESC, tms DESC"; - $result=$db->query($sql); - if ($result) - { + $result=$db->query($sql); + if ($result) + { $var=true; $num = $db->num_rows($result); print ''; if ($num) - { - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ''; - print ""; - print "\n"; - print "\n"; - print "\n"; - print ''; - print ''; - print ''; - $i++; - } - } + { + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print ''; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ''; + print ''; + print ''; + $i++; + } + } else { - print ""; + print ""; } print "
"; - print ''; - print "propalid."\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."socid."\">".dolibarr_trunc($objp->nom,18)."".dolibarr_print_date($objp->dp,"%d %b")."'; - print ''.$langs->trans("ReductionShort"); - print '%'; - print " ".$product->stock_proposition; - print ''; - print ''; - print '
"; + print ''; + print "propalid."\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."socid."\">".dolibarr_trunc($objp->nom,18)."".dolibarr_print_date($objp->dp,"%d %b")."'; + print ''.$langs->trans("ReductionShort"); + print '%'; + print " ".$product->stock_proposition; + print ''; + print ''; + print '
"; - print $langs->trans("NoOpenedPropals"); - print "
"; + print $langs->trans("NoOpenedPropals"); + print "
"; $db->free($result); - } + } - print '
'; @@ -1205,112 +1211,112 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) print ''; if (is_array($otherprop) && sizeof($otherprop)) - { - $var=!$var; - print ''; - print ''; - print ''; - print ''; - } + { + $var=!$var; + print ''; + print ''; + print ''; + print ''; + } else - { - print "'; - } + { + print "'; + } print '
'; - print ''; - print $langs->trans("OtherPropals").''; - $html->select_array("propalid", $otherprop); - print '
'.$langs->trans("Qty"); - print ''.$langs->trans("ReductionShort"); - print '%'; - print ''; - print ''; - print '
'; + print ''; + print $langs->trans("OtherPropals").''; + $html->select_array("propalid", $otherprop); + print '
'.$langs->trans("Qty"); + print ''.$langs->trans("ReductionShort"); + print '%'; + print ''; + print ''; + print '
"; - print $langs->trans("NoOtherOpenedPropals"); - print '
"; + print $langs->trans("NoOtherOpenedPropals"); + print '
'; print '
'; - print $langs->trans("AddToMyOrders").'
'; + print $langs->trans("AddToMyOrders").''; print $langs->trans("AddToOtherOrders").' 
'; - $sql = "SELECT s.nom, s.rowid as socid, c.rowid as commandeid, c.ref,".$db->pdate("c.date_commande")." as dc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; - $sql .=" WHERE c.fk_soc = s.rowid AND c.fk_statut = 0 AND c.fk_user_author = ".$user->id; - $sql .= " ORDER BY c.date_creation DESC"; + // Liste de "Mes commandes" + print '
'; + $sql = "SELECT s.nom, s.rowid as socid, c.rowid as commandeid, c.ref,".$db->pdate("c.date_commande")." as dc"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; + $sql .=" WHERE c.fk_soc = s.rowid AND c.fk_statut = 0 AND c.fk_user_author = ".$user->id; + $sql .= " ORDER BY c.date_creation DESC"; - $result=$db->query($sql); - if ($result) - { + $result=$db->query($sql); + if ($result) + { $num = $db->num_rows($result); $var=true; print ''; if ($num) - { - $i = 0; - while ($i < $num) - { - $objc = $db->fetch_object($result); - $var=!$var; - print ''; - print ""; - print "\n"; - print "\n"; - print "\n"; - print ''; - print ''; - print ''; - $i++; - } - } + { + $i = 0; + while ($i < $num) + { + $objc = $db->fetch_object($result); + $var=!$var; + print ''; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ''; + print ''; + print ''; + $i++; + } + } else - { - print "'; - } + { + print "'; + } print "
"; - print ''; - print "commandeid."\">".img_object($langs->trans("ShowOrder"),"order")." ".$objc->ref."socid."\">".dolibarr_trunc($objc->nom,18)."".dolibarr_print_date($objc->dc,"%d %b")."'; - print ''.$langs->trans("ReductionShort"); - print '%'; - print " ".$product->stock_proposition; - print ''; - print ''; - print '
"; + print ''; + print "commandeid."\">".img_object($langs->trans("ShowOrder"),"order")." ".$objc->ref."socid."\">".dolibarr_trunc($objc->nom,18)."".dolibarr_print_date($objc->dc,"%d %b")."'; + print ''.$langs->trans("ReductionShort"); + print '%'; + print " ".$product->stock_proposition; + print ''; + print ''; + print '
"; - print $langs->trans("NoOpenedOrders"); - print '
"; + print $langs->trans("NoOpenedOrders"); + print '
"; $db->free($result); - } + } - print '
'; @@ -1318,110 +1324,110 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) $othercom = $commande->liste_array(1, ' <> '.$user->id); print ''; if (is_array($othercom) && sizeof($othercom)) - { - $var=!$var; - print ''; - print ''; - print ''; - print ''; - } + { + $var=!$var; + print ''; + print ''; + print ''; + print ''; + } else - { - print "'; - } + { + print "'; + } print '
'; - print ''; - print $langs->trans("OtherOrders").''; - $html->select_array("commandeid", $othercom); - print '
'.$langs->trans("Qty"); - print ''.$langs->trans("ReductionShort"); - print '%'; - print ''; - print ''; - print '
'; + print ''; + print $langs->trans("OtherOrders").''; + $html->select_array("commandeid", $othercom); + print '
'.$langs->trans("Qty"); + print ''.$langs->trans("ReductionShort"); + print '%'; + print ''; + print ''; + print '
"; - print $langs->trans("NoOtherOpenedOrders"); - print '
"; + print $langs->trans("NoOtherOpenedOrders"); + print '
'; + } + print '
'; - print $langs->trans("AddToMyBills").'
'; + print $langs->trans("AddToMyBills").''; print $langs->trans("AddToOtherBills").' 
'; - $sql = "SELECT s.nom, s.rowid as socid, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; - $sql .=" WHERE f.fk_soc = s.rowid AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id; - $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; + // Liste de Mes factures + print '
'; + $sql = "SELECT s.nom, s.rowid as socid, f.rowid as factureid, f.facnumber,".$db->pdate("f.datef")." as df"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; + $sql .=" WHERE f.fk_soc = s.rowid AND f.fk_statut = 0 AND f.fk_user_author = ".$user->id; + $sql .= " ORDER BY f.datec DESC, f.rowid DESC"; - $result=$db->query($sql); - if ($result) - { + $result=$db->query($sql); + if ($result) + { $num = $db->num_rows($result); $var=true; print ''; if ($num) - { - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ''; - print ""; - print "\n"; - print "\n"; - print "\n"; - print ''; - print ''; - print ''; - $i++; - } - } + { + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print ''; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ''; + print ''; + print ''; + $i++; + } + } else { - print "'; + print "'; } print "
"; - print ''; - print "factureid."\">".img_object($langs->trans("ShowBills"),"bill")." ".$objp->facnumber."socid."\">".dolibarr_trunc($objp->nom,18)."".dolibarr_print_date($objp->df,"%d %b")."'; - print ''.$langs->trans("ReductionShort"); - print '%'; - print ''; - print ''; - print '
"; + print ''; + print "factureid."\">".img_object($langs->trans("ShowBills"),"bill")." ".$objp->facnumber."socid."\">".dolibarr_trunc($objp->nom,18)."".dolibarr_print_date($objp->df,"%d %b")."'; + print ''.$langs->trans("ReductionShort"); + print '%'; + print ''; + print ''; + print '
"; - print $langs->trans("NoDraftBills"); - print '
"; + print $langs->trans("NoDraftBills"); + print '
"; $db->free($result); - } - else - { + } + else + { dolibarr_print_error($db); - } + } - print '
'; // Liste de Autres factures @@ -1434,14 +1440,14 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) $result=$db->query($sql); if ($result) - { - $num = $db->num_rows($result); - $var=true; - print ''; - if ($num) { - $i = 0; - while ($i < $num) - { + { + $num = $db->num_rows($result); + $var=true; + print '
'; + if ($num) { + $i = 0; + while ($i < $num) + { $objp = $db->fetch_object($result); $var=!$var; @@ -1461,28 +1467,28 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) print ''; print ''; $i++; - } - } - else { - print "'; - } - print "
"; - print $langs->trans("NoOtherDraftBills"); - print '
"; - $db->free($result); - } + } + } + else { + print "
"; + print $langs->trans("NoOtherDraftBills"); + print '
"; + $db->free($result); + } else - { - dolibarr_print_error($db); - } + { + dolibarr_print_error($db); + } + } + + print ''; } - print ''; - } + print ''; - print ''; - - print '
'; + print '
'; } @@ -1500,7 +1506,7 @@ function load_tva($db,$name='tauxtva', $defaulttx='', $societe_vendeuse='', $soc global $langs,$conf,$mysoc; $retarray=array(); - + if (is_object($societe_vendeuse->pays_code)) { $code_pays=$societe_vendeuse->pays_code; @@ -1540,9 +1546,9 @@ function load_tva($db,$name='tauxtva', $defaulttx='', $societe_vendeuse='', $soc for ($i = 0 ; $i < $nbdetaux ; $i++) { $retarray['value'][$i] = $txtva[$i]; - $retarray['label'][$i] = $libtva[$i]; + $retarray['label'][$i] = $libtva[$i]; } - + return $retarray; } ?>