diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index c958ebb480c..7ade0e9c004 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -750,41 +750,68 @@ class Commande return -1; } } - /** - * Mets à jour une ligne de commande - * - */ - function update_line($rowid, $desc, $pu, $qty, $remise_percent=0) - { - if ($this->brouillon) - { - if (strlen(trim($qty))==0) - { - $qty=1; - } - $remise = 0; - $price = round(ereg_replace(",",".",$pu), 2); - $subprice = $price; - if (trim(strlen($remise_percent)) > 0) - { - $remise = round(($pu * $remise_percent / 100), 2); - $price = $pu - $remise; - } - else - { - $remise_percent=0; - } - $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;"; - if ( $this->db->query( $sql) ) - { - $this->update_price($this->id); - } - else - { - dolibarr_print_error($this->db); - } - } + /** + * \brief Mets à jour une ligne de commande + * \param rowid Id de la ligne de facture + * \param desc Description de la ligne + * \param pu Prix unitaire + * \param qty Quantité + * \param remise_percent Pourcentage de remise de la ligne + * \param tva_tx Taux TVA + * \return int < 0 si erreur, > 0 si ok + */ + function update_line($rowid, $desc, $pu, $qty, $remise_percent=0, $tva_tx) + { + dolibarr_syslog("Commande::UpdateLine"); + + if ($this->brouillon) + { + $this->db->begin(); + + if (strlen(trim($qty))==0) + { + $qty=1; + } + $remise = 0; + $price = ereg_replace(",",".",$pu); + $subprice = $price; + if (trim(strlen($remise_percent)) > 0) + { + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; + } + else + { + $remise_percent=0; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet"; + $sql.= " SET description='".addslashes($desc)."',price=$price,subprice=$subprice,"; + $sql.= " remise=$remise,remise_percent=$remise_percent,qty=$qty,tva_tx='".$tva_tx."'"; + $sql.= " WHERE rowid = ".$rowid; + + $result=$this->db->query( $sql); + if ( $result ) + { + $this->update_price($this->id); + + $this->db->commit(); + + return $result; + } + else + { + $this->db->rollback(); + + dolibarr_print_error($this->db); + return -1; + } + + } + else { + return -2; + } } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index dc77ef21ec9..d355e3752d5 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -81,6 +81,10 @@ if ($_POST["action"] == 'add' && $user->rights->commande->creer) $commande->add_product($_POST["idprod2"],$_POST["qty2"],$_POST["remise_percent2"]); $commande->add_product($_POST["idprod3"],$_POST["qty3"],$_POST["remise_percent3"]); $commande->add_product($_POST["idprod4"],$_POST["qty4"],$_POST["remise_percent4"]); + $commande->add_product($_POST["idprod5"],$_POST["qty5"],$_POST["remise_percent5"]); + $commande->add_product($_POST["idprod6"],$_POST["qty6"],$_POST["remise_percent6"]); + $commande->add_product($_POST["idprod7"],$_POST["qty7"],$_POST["remise_percent7"]); + $commande->add_product($_POST["idprod8"],$_POST["qty8"],$_POST["remise_percent8"]); $commande_id = $commande->create($user); @@ -89,10 +93,6 @@ if ($_POST["action"] == 'add' && $user->rights->commande->creer) $action = ''; } -/* - * - */ - if ($_POST["action"] == 'setremise' && $user->rights->commande->creer) { $commande = new Commande($db); @@ -113,47 +113,54 @@ if ($_POST["action"] == 'addligne' && $user->rights->commande->creer) /* * Ajout d'une ligne produit dans la commande */ - $commande = new Commande($db); - $ret=$commande->fetch($_POST["id"]); - - if (isset($_POST["p_idprod"])) + if ($_POST["qty"] && (($_POST["pu"] && $_POST["desc"]) || $_POST["p_idprod"])) { - $result = $commande->addline( - $_POST["np_desc"], - $_POST["pu"], - $_POST["pqty"], - $_POST["tva_tx"], - $_POST["p_idprod"], - $_POST["premise"]); + $commande = new Commande($db); + $ret=$commande->fetch($_POST["id"]); + + if (isset($_POST["p_idprod"])) + { + $result = $commande->addline( + $_POST["np_desc"], + $_POST["pu"], + $_POST["qty"], + $_POST["tva_tx"], + $_POST["p_idprod"], + $_POST["remise_percent"]); + } + else + { + $result = $commande->addline( + $_POST["desc"], + $_POST["pu"], + $_POST["qty"], + $_POST["tva_tx"], + 0, + $_POST["remise_percent"]); + } } - else - { - $result = $commande->addline( - $_POST["desc"], - $_POST["pu"], - $_POST["qty"], - $_POST["tva_tx"], - 0, - $_POST["remise_percent"]); - } - } -if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) +if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer && $_POST["save"] == $langs->trans("Save")) { - $commande = new Commande($db,"",$_GET["id"]); - if ($commande->fetch($_GET["id"]) ) - { - $result = $commande->update_line($_POST["elrowid"], + $commande = new Commande($db,"",$_POST["id"]); + if (! $commande->fetch($_POST["id"]) > 0) dolibarr_print_error($db); + + $result = $commande->update_line($_POST["elrowid"], $_POST["eldesc"], $_POST["elprice"], $_POST["elqty"], - $_POST["elremise_percent"]); - } - else - { - print "Erreur"; - } + $_POST["elremise_percent"], + $_POST["eltva_tx"] + ); + + $_GET["id"]=$_POST["id"]; // Pour réaffichage de la fiche en cours d'édition +} + +if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer && $_POST["cancel"] == $langs->trans("Cancel")) +{ + Header("Location: fiche.php?id=".$_POST["id"]); // Pour réaffichage de la fiche en cours d'édition + exit; } if ($_GET["action"] == 'deleteline' && $user->rights->commande->creer) @@ -326,7 +333,7 @@ if ($_GET["action"] == 'create' && $user->rights->commande->creer) /* * */ - print ''; + print ''; print "\n"; print "\n"; @@ -606,8 +613,8 @@ else print ''.$langs->trans('VAT').''; print ''.$langs->trans('PriceUHT').''; print ''.$langs->trans('Qty').''; - print ''.$langs->trans('Discount').''; - print ''.$langs->trans('AmountHT').''; + print ''.$langs->trans('Discount').''; + print ''.$langs->trans('AmountHT').''; print '  '; print "\n"; } @@ -617,7 +624,7 @@ else $objp = $db->fetch_object($resql); $var=!$var; - // Affiche ligne de commande en mode non edit + // Ligne en mode visu if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; @@ -636,11 +643,8 @@ else print "\n"; } print ''.$objp->tva_tx.'%'; - print ''.price($objp->subprice)."\n"; - print ''.$objp->qty.''; - if ($objp->remise_percent > 0) { print ''.$objp->remise_percent."%\n"; @@ -668,13 +672,14 @@ else print ''; } - // Affiche ligne de commande en mode non edit - if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) + // Ligne en mode update + if ($_GET["action"] == 'editline' && $user->rights->commande->creer && $_GET["rowid"] == $objp->rowid) { - print "
"; + print ''; print ''; + print ''; print ''; - print ""; + print ''; print ''; if ($objp->fk_product > 0) { @@ -687,13 +692,13 @@ else } print ''; print ''; - //print $html->select_tva("tva_tx",$objp->tva_taux); - print $objp->tva_tx."%"; // Taux tva dépend du produit, donc on ne doit pas pouvoir le changer ici + print $html->select_tva("eltva_tx",$objp->tva_tx); print ''; print ''; print ''; print '%'; - print ''; + print ''; + print '
'; print ''; print '
'; } @@ -756,8 +761,8 @@ else print ''; print ''; print ' '; - print ''; - print '%'; + print ''; + print '%'; print ''; print "\n";