Skip to content
Snippets Groups Projects
Commit e45fdcaa authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Meilleur gestion erreur creation contrat.

Fix: On distingue bien le commerical principal de suivi, du commercial de signature
parent 9e5aff61
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,8 @@ class Contrat
var $societe;
var $user_service;
var $user_cloture;
var $commercial_signature_id;
var $commercial_suivi_id;
var $statuts=array();
......@@ -63,7 +65,9 @@ class Contrat
$this->user_cloture = new User($DB);
// Statut 0=ouvert, 1=actif, 2=cloturé
$this->statuts=array($langs->trans("Opened"),$langs->trans("Running"),$langs->trans("Closed"));
$this->statuts[0]=$langs->trans("Opened");
$this->statuts[1]=$langs->trans("Running");
$this->statuts[2]=$langs->trans("Closed");
}
......@@ -264,9 +268,12 @@ class Contrat
function create($user,$lang='',$conf='')
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, fk_commercial_signature, fk_commercial_suivi, date_contrat)";
$sql .= " VALUES (now(),".$this->soc_id.",".$user->id.",".$this->commercial_id.",".$this->commercial_id;
$sql.= " VALUES (now(),".$this->soc_id.",".$user->id;
$sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");
$sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");
$sql.= ",".$this->db->idate($this->date_contrat) .")";
if ($this->db->query($sql))
$resql=$this->db->query($sql);
if ($resql)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");
......@@ -280,6 +287,7 @@ class Contrat
}
else
{
$this->error=$lang->trans("UnknownError: ".$this->db->error()." - sql=".$sql);
dolibarr_syslog("Contrat::create - 10");
$result = -1;
}
......
......@@ -69,7 +69,8 @@ if ($_POST["action"] == 'add')
$contrat->soc_id = $_POST["soc_id"];
$contrat->date_contrat = $datecontrat;
$contrat->commercial_id = $_POST["commercial"];
$contrat->commercial_suivi_id = $_POST["commercial_suivi_id"];
$contrat->commercial_signature_id = $_POST["commercial_signature_id"];
$contrat->note = $_POST["note"];
$contrat->projetid = $_POST["projetid"];
$contrat->remise_percent = $_POST["remise_percent"];
......@@ -80,12 +81,16 @@ if ($_POST["action"] == 'add')
$contrat->add_product($_POST["idprod3"],$_POST["qty3"],$_POST["remise_percent3"]);
$contrat->add_product($_POST["idprod4"],$_POST["qty4"],$_POST["remise_percent4"]);
*/
$result = $contrat->create($user,$lang,$conf);
if ($result == 0)
$result = $contrat->create($user,$langs,$conf);
if ($result >= 0)
{
Header("Location: fiche.php?id=".$contrat->id);
exit;
}
else {
$mesg='<div class="error">'.$contrat->error.'</div>';
}
print $mesg;
$_GET["id"] = $contrat->id;
$action = '';
......@@ -120,6 +125,7 @@ if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
if ($result >= 0)
{
Header("Location: fiche.php?id=".$contrat->id);
exit;
}
else
{
......@@ -252,9 +258,34 @@ if ($_GET["action"] == 'create')
print '<tr><td>'.$langs->trans("Customer").':</td><td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$obj->nom.'</a></td></tr>';
print '<tr><td width="20%">'.$langs->trans("Commercial").'</td><td>';
// Commercial suivi
print '<tr><td width="20%" nowrap>'.$langs->trans("SalesRepresentativeFollowUp").'</td><td>';
print '<select name="commercial_suivi_id">';
print '<option value="-1">&nbsp;</option>';
$sql = "SELECT rowid, name, firstname FROM ".MAIN_DB_PREFIX."user ORDER BY name ";
$resql=$db->query( $sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ( $num > 0 )
{
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row($resql);
print '<option value="'.$row[0].'">'.$row[1] . " " . $row[2].'</option>';
$i++;
}
}
$db->free($resql);
}
print '</select></td></tr>';
print '<select name="commercial">';
// Commercial signature
print '<tr><td width="20%" nowrap>'.$langs->trans("SalesRepresentativeSignature").'</td><td>';
print '<select name="commercial_signature_id">';
print '<option value="-1">&nbsp;</option>';
$sql = "SELECT rowid, name, firstname FROM ".MAIN_DB_PREFIX."user ORDER BY name ";
$resql=$db->query( $sql);
if ($resql)
......@@ -266,7 +297,7 @@ if ($_GET["action"] == 'create')
while ($i < $num)
{
$row = $db->fetch_row($resql);
print '<option value="'.$row[0].'">'.$row[1] . " " . $row[2];
print '<option value="'.$row[0].'">'.$row[1] . " " . $row[2].'</option>';
$i++;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment