Debut debuggage fonction commandes fournisseurs

This commit is contained in:
Laurent Destailleur 2005-10-10 19:48:22 +00:00
parent 7b61f28c59
commit f2d42cce82
4 changed files with 298 additions and 249 deletions

View File

@ -29,19 +29,21 @@
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
// Sécurité accés client // Sécurité accés client
$socidp=0;
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socidp = $user->societe_id; $socidp = $user->societe_id;
} }
/* /*
* *
*/ */
@ -74,28 +76,29 @@ if ($_POST["action"] == 'setremise' && $user->rights->commande->creer)
*/ */
if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->creer) if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->creer)
{ {
$comf = new CommandeFournisseur($db); $comf = new CommandeFournisseur($db);
$comf->fetch($_GET["id"]); $comf->fetch($_GET["id"]);
if ($_POST["p_idprod"] > 0) if ($_POST["p_idprod"] > 0)
{ {
$result = $comf->addline("DESC", $result = $comf->addline($_POST["desc"],
$_POST["pu"], $_POST["pu"],
$_POST["pqty"], $_POST["pqty"],
$_POST["tva_tx"], $_POST["tva_tx"],
$_POST["p_idprod"], $_POST["p_idprod"],
$_POST["premise"]); $_POST["premise"]);
} }
else else
{ {
$result = $comf->addline($_POST["desc"], $result = $comf->addline($_POST["desc"],
$_POST["pu"], $_POST["pu"],
$_POST["qty"], $_POST["qty"],
$_POST["tva_tx"], $_POST["tva_tx"],
0, 0,
$_POST["remise_percent"]); $_POST["remise_percent"]);
} }
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer)
@ -122,25 +125,27 @@ if ($_GET["action"] == 'deleteline' && $user->rights->fournisseur->commande->cre
$result = $comf->delete_line($_GET["lineid"]); $result = $comf->delete_line($_GET["lineid"]);
} }
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->valider) if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->valider)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->soc_id); $soc->fetch($commande->soc_id);
$result = $commande->valid($user); $result = $commande->valid($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->approve($user); $result = $commande->approve($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
@ -148,41 +153,45 @@ if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->r
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
} }
if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->commander) if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]); $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->creer ) if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->creer )
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->id = $_GET["id"]; $commande->id = $_GET["id"];
$commande->delete(); $commande->delete();
Header("Location: index.php"); Header("Location: index.php");
exit;
} }
if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$result = $commande->Livraison($user, $date_liv, $_POST["type"]); $result = $commande->Livraison($user, $date_liv, $_POST["type"]);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler) if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler)
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$result = $commande->cancel($user); $result = $commande->cancel($user);
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
/* /*
@ -191,13 +200,19 @@ if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->r
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
{ {
$fourn = new Fournisseur($db); $fourn = new Fournisseur($db);
$fourn->fetch($_GET["socid"]); $fourn->fetch($_GET["socid"]);
if ($fourn->create_commande($user) == 0) if ($fourn->create_commande($user) > 0)
{ {
$idc = $fourn->single_open_commande; $idc = $fourn->single_open_commande;
Header("Location:fiche.php?id=".$idc); Header("Location:fiche.php?id=".$idc);
exit;
}
else
{
$mesg=$fourn->error;
print "x $mesg x";
} }
} }
@ -305,7 +320,8 @@ if ($_GET["id"] > 0)
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Supplier")."</td>"; print '<tr><td width="20%">'.$langs->trans("Supplier")."</td>";
print '<td colspan="5">'; print '<td colspan="5">';
print '<b><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>'; print '<b><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$soc->id.'">';
print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'</a></b></td>';
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
@ -387,7 +403,7 @@ if ($_GET["id"] > 0)
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td>".$objp->ref."</td>\n"; print '<td><a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</td>';
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
print '<td>'; print '<td>';
@ -465,7 +481,7 @@ if ($_GET["id"] > 0)
$html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre); $html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre);
print '</td>'; print '</td>';
print '<td align="center"><input type="text" size="2" name="pqty" value="1"></td>'; print '<td align="center"><input type="text" size="2" name="pqty" value="1"></td>';
print '<td align="right"><input type="text" size="4" name="premise" value="0"> %</td>'; print '<td align="right"><input type="text" size="3" name="premise" value="0">%</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>'; print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
print "</tr>\n"; print "</tr>\n";
@ -476,54 +492,54 @@ if ($_GET["id"] > 0)
print "</table>"; print "</table>";
print '</div>'; print '</div>';
/* /**
* Boutons actions * Boutons actions
*/ */
if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid') if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if ($commande->statut == 0 && $num_lignes > 0) if ($commande->statut == 0 && $num_lignes > 0)
{ {
if ($user->rights->fournisseur->commande->valider) if ($user->rights->fournisseur->commande->valider)
{ {
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=valid">'.$langs->trans("Valid").'</a>'; print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=valid">'.$langs->trans("Valid").'</a>';
} }
} }
if ($commande->statut == 1) if ($commande->statut == 1)
{ {
if ($user->rights->fournisseur->commande->annuler) if ($user->rights->fournisseur->commande->annuler)
{ {
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>'; print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
} }
if ($user->rights->fournisseur->commande->approuver) if ($user->rights->fournisseur->commande->approuver)
{ {
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>'; print '<a class="butAction" href="fiche.php?id='.$commande->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
} }
} }
if ($commande->statut == 2) if ($commande->statut == 2)
{ {
if ($user->rights->fournisseur->commande->approuver) if ($user->rights->fournisseur->commande->approuver)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
} }
} }
if ($commande->statut == 0) if ($commande->statut == 0)
{ {
if ($user->rights->fournisseur->commande->creer) if ($user->rights->fournisseur->commande->creer)
{ {
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
} }
} }
print "</div>"; print "</div>";
} }
/* /*
* Documents générés * Documents générés

View File

@ -104,26 +104,26 @@ if ($_GET["id"] > 0)
print "</td></tr>"; print "</td></tr>";
} }
// Auteur
print '<tr><td>'.$langs->trans("Author").'</td><td colspan="2">'.$author->fullname.'</td>';
print '<td width="50%">&nbsp;</td></tr>';
print "</table>\n"; print "</table>\n";
print "<br>";
/*
* Suivi historique
* Date - Statut - Auteur
*/
print '<table class="noborder" width="100%">';
/* print '<tr class="liste_titre"><td>'.$langs->trans("Date").'</td>';
* Historique print '<td>'.$langs->trans("Status").'</td><td>'.$langs->trans("Author").'</td>';
* print '</tr>';
*/
echo '<br><table class="border" width="100%">';
$sql = "SELECT l.fk_statut, ".$db->pdate("l.datelog") ."as dl, u.firstname, u.name"; $sql = "SELECT l.fk_statut, ".$db->pdate("l.datelog") ."as dl, u.rowid, u.code, u.firstname, u.name";
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_log as l "; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_log as l ";
$sql .= " , ".MAIN_DB_PREFIX."user as u "; $sql .= " , ".MAIN_DB_PREFIX."user as u ";
$sql .= " WHERE l.fk_commande = ".$commande->id." AND u.rowid = l.fk_user"; $sql .= " WHERE l.fk_commande = ".$commande->id." AND u.rowid = l.fk_user";
$sql .= " ORDER BY l.rowid DESC"; $sql .= " ORDER BY l.rowid DESC";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
@ -132,22 +132,22 @@ if ($_GET["id"] > 0)
$var=True; $var=True;
while ($i < $num) while ($i < $num)
{ {
$var=!$var;
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td width="20%">'.dolibarr_print_date($obj->dl,"%a %d %b %Y %H:%M:%S")."</td>\n"; print '<td width="20%">'.dolibarr_print_date($obj->dl,"%a %d %b %Y %H:%M:%S")."</td>\n";
print '<td width="10%"><img src="statut'.$obj->fk_statut.'.png">&nbsp;'; print '<td width="100px"><img src="statut'.$obj->fk_statut.'.png">&nbsp;';
print $commande->statuts[$obj->fk_statut]."</td>\n"; print $commande->statuts[$obj->fk_statut]."</td>\n";
print '<td width="70%">'.$obj->firstname. " " . $obj->name.'</td>'; print '<td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->rowid.'">';
print img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'</td>';
print "</tr>"; print '</tr>';
$i++; $i++;
$var=!$var;
} }
$db->free($resql); $db->free($resql);
} }
@ -155,8 +155,8 @@ if ($_GET["id"] > 0)
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
} }
print "</table>"; print "</table>";
print '</div>'; print '</div>';
} }
else else

View File

@ -103,29 +103,32 @@ class Fournisseur extends Societe {
} }
function create_commande($user)
{
$result = -1;
dolibarr_syslog("Fournisseur::Create_Commande");
$comm = new CommandeFournisseur($this->db);
$comm->soc_id = $this->id;
if ( $comm->create($user) == 0 ) /**
{ * \brief Créé la commande au statut brouillon
dolibarr_syslog("Fournisseur::Create_Commande : Success"); * \param user Utilisateur qui crée
* \return int <0 si ko, id de la commande créée si ok
*/
function create_commande($user)
{
dolibarr_syslog("Fournisseur::Create_Commande");
$comm = new CommandeFournisseur($this->db);
$comm->soc_id = $this->id;
$this->single_open_commande = $comm->id; if ($comm->create($user) > 0)
{
dolibarr_syslog("Fournisseur::Create_Commande : Success");
$this->single_open_commande = $comm->id;
$result = 0; return $comm->id;
} }
else else
{ {
dolibarr_syslog("Fournisseur::Create_Commande : Failed"); dolibarr_syslog("Fournisseur::Create_Commande : Failed");
$result = -2; return -1;
} }
}
return $result;
}
function ProductCommande($user, $product_id) function ProductCommande($user, $product_id)
{ {

View File

@ -123,20 +123,29 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
return $result ; return $result ;
} }
/**
* Log
*
*/
function log($user, $statut, $datelog)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_log (datelog, fk_commande, fk_statut, fk_user)";
$sql .= " VALUES (".$this->db->idate($datelog).",".$this->id.", $statut, ".$user->id.")";
if ( $this->db->query($sql) ) /**
{ * \brief Insère ligne de log
return 0; * \param user Utilisateur qui modifie la commande
} * \param statut Statut de la commande
* \param datelog Date de modification
* \return int <0 si ko, >0 si ok
*/
function log($user, $statut, $datelog)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_log (datelog, fk_commande, fk_statut, fk_user)";
$sql.= " VALUES (".$this->db->idate($datelog).",".$this->id.", $statut, ".$user->id.")";
if ( $this->db->query($sql) )
{
return 1;
}
else
{
return -1;
}
} }
/** /**
* Valide la commande * Valide la commande
* *
@ -395,102 +404,123 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
} }
return $result ; return $result ;
} }
/**
* Créé la commande /**
* * \brief Créé la commande au statut brouillon
*/ * \param user Utilisateur qui crée
function create($user) * \return int <0 si ko, >0 si ok
*/
function create($user)
{ {
dolibarr_syslog("CommandeFournisseur::Create"); dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id);
dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id);
/* On positionne en mode brouillon la commande */
$this->brouillon = 1;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur (fk_soc, date_creation, fk_user_author, fk_statut) "; $this->db->begin();
$sql .= " VALUES (".$this->soc_id.", now(), ".$user->id.",0)";
if ( $this->db->query($sql) ) /* On positionne en mode brouillon la commande */
{ $this->brouillon = 1;
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur (fk_soc, date_creation, fk_user_author, fk_statut) ";
if ($this->db->query($sql)) $sql .= " VALUES (".$this->soc_id.", now(), ".$user->id.",0)";
{
/* if ( $this->db->query($sql) )
* {
* $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
*/
dolibarr_syslog("CommandeFournisseur::Create : Success"); $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
return 0; $sql.= " SET ref='(PROV".$this->id.")'";
} $sql.= " WHERE rowid=".$this->id;
else if ($this->db->query($sql))
{ {
dolibarr_syslog("CommandeFournisseur::Create : Failed 2"); // On logue creation pour historique
return -2; $this->log($user, 0, time());
}
} dolibarr_syslog("CommandeFournisseur::Create : Success");
else $this->db->commit();
{ return 1;
dolibarr_syslog("CommandeFournisseur::Create : Failed 1"); }
dolibarr_syslog("CommandeFournisseur::Create : ".$this->db->error()); else
dolibarr_syslog("CommandeFournisseur::Create : ".$sql); {
return -1; $this->error=$this->db->error()." - ".$sql;
} dolibarr_syslog("CommandeFournisseur::Create: Failed -2 - ".$this->error);
$this->db->rollback();
return -2;
}
}
else
{
$this->error=$this->db->error()." - ".$sql;
dolibarr_syslog("CommandeFournisseur::Create: Failed -1 - ".$this->error);
$this->db->rollback();
return -1;
}
} }
/**
* Ajoute une ligne de commande /**
* * \brief Ajoute une ligne de commande
*/ * \param desc Description
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) * \param pu Prix unitaire
* \param qty Quantité
* \param txtva Taux tva
* \param fk_product Id produit
* \param remise_percent Remise
* \param int <0 si ko, >0 si ok
*/
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{ {
$qty = ereg_replace(",",".",$qty); $qty = ereg_replace(",",".",$qty);
$pu = ereg_replace(",",".",$pu); $pu = ereg_replace(",",".",$pu);
$desc=trim($desc);
if ($this->brouillon && strlen(trim($desc))) dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
{
if (strlen(trim($qty))==0)
{
$qty=1;
}
if ($fk_product > 0) if ($this->brouillon)
{ {
$prod = new Product($this->db, $fk_product); $this->db->begin();
if ($prod->fetch($fk_product) > 0)
{
$desc = $prod->libelle;
$txtva = $prod->tva_tx;
$prod->get_buyprice($this->fourn_id,$qty); if (strlen(trim($qty))==0)
{
$qty=1;
}
$pu = $prod->buyprice/$qty; if ($fk_product > 0)
} {
} $prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0)
{
$prod->get_buyprice($this->fourn_id,$qty);
$remise = 0; $desc = $prod->libelle;
$price = round(ereg_replace(",",".",$pu), 2); $txtva = $prod->tva_tx;
$subprice = $price; $pu = $prod->buyprice/$qty;
if (trim(strlen($remise_percent)) > 0) $ref = $prod->ref;
{ }
$remise = round(($pu * $remise_percent / 100), 2); }
$price = $pu - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price,qty,tva_tx, remise_percent, subprice, remise, ref)"; $remise = 0;
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."','".$ref."') ;"; $price = round(ereg_replace(",",".",$pu), 2);
$subprice = $price;
if (trim(strlen($remise_percent)) > 0)
{
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
if ( $this->db->query( $sql) ) $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)";
{ $sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."','".$ref."') ;";
$this->update_price();
return 0;
}
else
{
return -1; if ( $this->db->query( $sql) )
} {
} $this->update_price();
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
} }
/** /**