Debut debuggage fonction commandes fournisseurs
This commit is contained in:
parent
7b61f28c59
commit
f2d42cce82
@ -29,19 +29,21 @@
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/project.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
|
||||
|
||||
if (!$user->rights->fournisseur->commande->lire) accessforbidden();
|
||||
|
||||
|
||||
// Sécurité accés client
|
||||
$socidp=0;
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
$action = '';
|
||||
$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)
|
||||
{
|
||||
$comf = new CommandeFournisseur($db);
|
||||
$comf->fetch($_GET["id"]);
|
||||
$comf = new CommandeFournisseur($db);
|
||||
$comf->fetch($_GET["id"]);
|
||||
|
||||
if ($_POST["p_idprod"] > 0)
|
||||
if ($_POST["p_idprod"] > 0)
|
||||
{
|
||||
$result = $comf->addline("DESC",
|
||||
$_POST["pu"],
|
||||
$_POST["pqty"],
|
||||
$_POST["tva_tx"],
|
||||
$_POST["p_idprod"],
|
||||
$_POST["premise"]);
|
||||
$result = $comf->addline($_POST["desc"],
|
||||
$_POST["pu"],
|
||||
$_POST["pqty"],
|
||||
$_POST["tva_tx"],
|
||||
$_POST["p_idprod"],
|
||||
$_POST["premise"]);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$result = $comf->addline($_POST["desc"],
|
||||
$_POST["pu"],
|
||||
$_POST["qty"],
|
||||
$_POST["tva_tx"],
|
||||
0,
|
||||
$_POST["remise_percent"]);
|
||||
$result = $comf->addline($_POST["desc"],
|
||||
$_POST["pu"],
|
||||
$_POST["qty"],
|
||||
$_POST["tva_tx"],
|
||||
0,
|
||||
$_POST["remise_percent"]);
|
||||
}
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
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"]);
|
||||
}
|
||||
|
||||
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->fetch($_GET["id"]);
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($commande->soc_id);
|
||||
$result = $commande->valid($user);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($commande->soc_id);
|
||||
$result = $commande->valid($user);
|
||||
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->fetch($_GET["id"]);
|
||||
$result = $commande->approve($user);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$result = $commande->approve($user);
|
||||
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->fetch($_GET["id"]);
|
||||
@ -148,56 +153,66 @@ if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->r
|
||||
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->fetch($_GET["id"]);
|
||||
$result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]);
|
||||
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->id = $_GET["id"];
|
||||
$commande->delete();
|
||||
Header("Location: index.php");
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->id = $_GET["id"];
|
||||
$commande->delete();
|
||||
Header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner)
|
||||
{
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
|
||||
$date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
|
||||
|
||||
$result = $commande->Livraison($user, $date_liv, $_POST["type"]);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
|
||||
$date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
|
||||
|
||||
$result = $commande->Livraison($user, $date_liv, $_POST["type"]);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler)
|
||||
{
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$result = $commande->cancel($user);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$result = $commande->cancel($user);
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Créé une commande
|
||||
*/
|
||||
if ($_GET["action"] == 'create')
|
||||
if ($_GET["action"] == 'create')
|
||||
{
|
||||
|
||||
$fourn = new Fournisseur($db);
|
||||
$fourn->fetch($_GET["socid"]);
|
||||
$fourn = new Fournisseur($db);
|
||||
$fourn->fetch($_GET["socid"]);
|
||||
|
||||
if ($fourn->create_commande($user) == 0)
|
||||
if ($fourn->create_commande($user) > 0)
|
||||
{
|
||||
$idc = $fourn->single_open_commande;
|
||||
Header("Location:fiche.php?id=".$idc);
|
||||
$idc = $fourn->single_open_commande;
|
||||
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 '<tr><td width="20%">'.$langs->trans("Supplier")."</td>";
|
||||
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>';
|
||||
@ -387,7 +403,7 @@ if ($_GET["id"] > 0)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
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)
|
||||
{
|
||||
print '<td>';
|
||||
@ -465,7 +481,7 @@ if ($_GET["id"] > 0)
|
||||
$html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre);
|
||||
print '</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> </td>';
|
||||
print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
|
||||
print "</tr>\n";
|
||||
@ -476,54 +492,54 @@ if ($_GET["id"] > 0)
|
||||
print "</table>";
|
||||
print '</div>';
|
||||
|
||||
/*
|
||||
/**
|
||||
* Boutons actions
|
||||
*/
|
||||
if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid')
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($commande->statut == 0 && $num_lignes > 0)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->valider)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=valid">'.$langs->trans("Valid").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 1)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->annuler)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=cancel">'.$langs->trans("CancelOrder").'</a>';
|
||||
}
|
||||
|
||||
if ($user->rights->fournisseur->commande->approuver)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=approve">'.$langs->trans("ApproveOrder").'</a>';
|
||||
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=refuse">'.$langs->trans("RefuseOrder").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 2)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->approuver)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=refuse">'.$langs->trans("RefuseOrder").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 0)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->creer)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
}
|
||||
if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid')
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($commande->statut == 0 && $num_lignes > 0)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->valider)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=valid">'.$langs->trans("Valid").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 1)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->annuler)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=cancel">'.$langs->trans("CancelOrder").'</a>';
|
||||
}
|
||||
|
||||
if ($user->rights->fournisseur->commande->approuver)
|
||||
{
|
||||
print '<a class="butAction" href="fiche.php?id='.$commande->id.'&action=approve">'.$langs->trans("ApproveOrder").'</a>';
|
||||
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=refuse">'.$langs->trans("RefuseOrder").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 2)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->approuver)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=refuse">'.$langs->trans("RefuseOrder").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($commande->statut == 0)
|
||||
{
|
||||
if ($user->rights->fournisseur->commande->creer)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?id='.$commande->id.'&action=delete">'.$langs->trans("Delete").'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
}
|
||||
|
||||
/*
|
||||
* Documents générés
|
||||
|
||||
@ -104,26 +104,26 @@ if ($_GET["id"] > 0)
|
||||
print "</td></tr>";
|
||||
}
|
||||
|
||||
// Auteur
|
||||
print '<tr><td>'.$langs->trans("Author").'</td><td colspan="2">'.$author->fullname.'</td>';
|
||||
print '<td width="50%"> </td></tr>';
|
||||
print "</table>\n";
|
||||
|
||||
print "<br>";
|
||||
|
||||
/*
|
||||
* Historique
|
||||
*
|
||||
*/
|
||||
echo '<br><table class="border" width="100%">';
|
||||
/*
|
||||
* Suivi historique
|
||||
* Date - Statut - Auteur
|
||||
*/
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
$sql = "SELECT l.fk_statut, ".$db->pdate("l.datelog") ."as dl, u.firstname, u.name";
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Date").'</td>';
|
||||
print '<td>'.$langs->trans("Status").'</td><td>'.$langs->trans("Author").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$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 .= " , ".MAIN_DB_PREFIX."user as u ";
|
||||
$sql .= " WHERE l.fk_commande = ".$commande->id." AND u.rowid = l.fk_user";
|
||||
$sql .= " ORDER BY l.rowid DESC";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
@ -132,22 +132,22 @@ if ($_GET["id"] > 0)
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$var=!$var;
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
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="10%"><img src="statut'.$obj->fk_statut.'.png"> ';
|
||||
print '<td width="100px"><img src="statut'.$obj->fk_statut.'.png"> ';
|
||||
|
||||
print $commande->statuts[$obj->fk_statut]."</td>\n";
|
||||
|
||||
print '<td width="70%">'.$obj->firstname. " " . $obj->name.'</td>';
|
||||
|
||||
print "</tr>";
|
||||
|
||||
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>';
|
||||
|
||||
$i++;
|
||||
$var=!$var;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
@ -155,8 +155,8 @@ if ($_GET["id"] > 0)
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '</div>';
|
||||
}
|
||||
else
|
||||
|
||||
@ -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 )
|
||||
{
|
||||
dolibarr_syslog("Fournisseur::Create_Commande : Success");
|
||||
/**
|
||||
* \brief Créé la commande au statut brouillon
|
||||
* \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;
|
||||
|
||||
if ($comm->create($user) > 0)
|
||||
{
|
||||
dolibarr_syslog("Fournisseur::Create_Commande : Success");
|
||||
$this->single_open_commande = $comm->id;
|
||||
|
||||
return $comm->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Fournisseur::Create_Commande : Failed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$this->single_open_commande = $comm->id;
|
||||
|
||||
$result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("Fournisseur::Create_Commande : Failed");
|
||||
$result = -2;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function ProductCommande($user, $product_id)
|
||||
{
|
||||
|
||||
@ -123,20 +123,29 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
|
||||
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) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* \brief Insère ligne de log
|
||||
* \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
|
||||
*
|
||||
@ -395,102 +404,123 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
|
||||
}
|
||||
return $result ;
|
||||
}
|
||||
/**
|
||||
* Créé la commande
|
||||
*
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Create");
|
||||
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) ";
|
||||
$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");
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
dolibarr_syslog("CommandeFournisseur::Create : Success");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Create : Failed 2");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Create : Failed 1");
|
||||
dolibarr_syslog("CommandeFournisseur::Create : ".$this->db->error());
|
||||
dolibarr_syslog("CommandeFournisseur::Create : ".$sql);
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* \brief Créé la commande au statut brouillon
|
||||
* \param user Utilisateur qui crée
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
/* 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) ";
|
||||
$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");
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
|
||||
$sql.= " SET ref='(PROV".$this->id.")'";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
// On logue creation pour historique
|
||||
$this->log($user, 0, time());
|
||||
|
||||
dolibarr_syslog("CommandeFournisseur::Create : Success");
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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
|
||||
*
|
||||
*/
|
||||
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
|
||||
|
||||
/**
|
||||
* \brief Ajoute une ligne de commande
|
||||
* \param desc Description
|
||||
* \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);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
$qty = ereg_replace(",",".",$qty);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
$desc=trim($desc);
|
||||
|
||||
if ($this->brouillon && strlen(trim($desc)))
|
||||
{
|
||||
if (strlen(trim($qty))==0)
|
||||
{
|
||||
$qty=1;
|
||||
}
|
||||
dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
|
||||
|
||||
if ($this->brouillon)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
if (strlen(trim($qty))==0)
|
||||
{
|
||||
$qty=1;
|
||||
}
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
{
|
||||
$prod->get_buyprice($this->fourn_id,$qty);
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
{
|
||||
$desc = $prod->libelle;
|
||||
$txtva = $prod->tva_tx;
|
||||
$desc = $prod->libelle;
|
||||
$txtva = $prod->tva_tx;
|
||||
$pu = $prod->buyprice/$qty;
|
||||
$ref = $prod->ref;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$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."') ;";
|
||||
|
||||
if ( $this->db->query( $sql) )
|
||||
{
|
||||
$this->update_price();
|
||||
|
||||
$prod->get_buyprice($this->fourn_id,$qty);
|
||||
|
||||
$pu = $prod->buyprice/$qty;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$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."') ;";
|
||||
|
||||
if ( $this->db->query( $sql) )
|
||||
{
|
||||
$this->update_price();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user