diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php
index 7bd028a7608..62dcde615bf 100644
--- a/htdocs/comm/addpropal.php
+++ b/htdocs/comm/addpropal.php
@@ -41,6 +41,9 @@ $langs->load("bills");
$langs->load("orders");
$langs->load("deliveries");
+$action=GETPOST('action');
+$mesg=GETPOST('mesg');
+
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
@@ -64,9 +67,10 @@ print_fiche_titre($langs->trans("NewProp"));
$form=new Form($db);
+dol_htmloutput_mesg($mesg);
// Add new proposal
-if ($_GET["action"] == 'create')
+if ($action == 'create')
{
$soc = new Societe($db);
$result=$soc->fetch($_GET["socid"]);
@@ -341,7 +345,7 @@ if ($_GET["action"] == 'create')
print "";
}
-$db->close();
-
llxFooter();
+
+$db->close();
?>
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 340f6cdcfc7..42236b90473 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -216,9 +216,20 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propale
if ($_POST['action'] == 'setdate')
{
- $object->fetch($id);
- $result=$object->set_date($user,dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']));
- if ($result < 0) dol_print_error($db,$object->error);
+ $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+
+ if (empty($datep))
+ {
+ $error++;
+ $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'
';
+ }
+
+ if (! $error)
+ {
+ $object->fetch($id);
+ $result=$object->set_date($user,$datep);
+ if ($result < 0) dol_print_error($db,$object->error);
+ }
}
if ($_POST['action'] == 'setecheance')
{
@@ -250,127 +261,141 @@ if ($_POST['action'] == 'set_ref_client' && $user->rights->propale->creer)
// Create proposal
if ($_POST['action'] == 'add' && $user->rights->propale->creer)
{
- $object->socid=$_POST['socid'];
+ $object->socid=$socid;
$object->fetch_thirdparty();
- $db->begin();
+ $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $date_delivery=dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
- // Si on a selectionne une propal a copier, on realise la copie
- if($_POST['createmode']=='copy' && $_POST['copie_propal'])
+ if (empty($datep))
{
- if ($object->fetch($_POST['copie_propal']) > 0)
- {
- $object->ref = $_POST['ref'];
- $object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- $object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
- $object->availability_id = $_POST['availability_id'];
- $object->demand_reason_id = $_POST['demand_reason_id'];
- $object->fk_delivery_address = $_POST['fk_address'];
- $object->duree_validite = $_POST['duree_validite'];
- $object->cond_reglement_id = $_POST['cond_reglement_id'];
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->remise_percent = $_POST['remise_percent'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->socid = $_POST['socid'];
- $object->contactid = $_POST['contactidp'];
- $object->fk_project = $_POST['projectid'];
- $object->modelpdf = $_POST['model'];
- $object->author = $user->id; // deprecated
- $object->note = $_POST['note'];
- $object->statut = 0;
-
- $id = $object->create_from($user);
- }
- else
- {
- $mesg = ''.$langs->trans("ErrorFailedToCopyProposal",$_POST['copie_propal']).'
';
- }
- }
- else
- {
- $object->ref = $_POST['ref'];
- $object->ref_client = $_POST['ref_client'];
- $object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- $object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
- $object->availability_id = $_POST['availability_id'];
- $object->demand_reason_id = $_POST['demand_reason_id'];
- $object->fk_delivery_address = $_POST['fk_address'];
- $object->duree_validite = $_POST['duree_validite'];
- $object->cond_reglement_id = $_POST['cond_reglement_id'];
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
-
- $object->contactid = $_POST['contactidp'];
- $object->fk_project = $_POST['projectid'];
- $object->modelpdf = $_POST['model'];
- $object->author = $user->id; // deprecated
- $object->note = $_POST['note'];
-
- $object->origin = $_POST['origin'];
- $object->origin_id = $_POST['originid'];
-
- for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $xid = 'idprod'.$i;
- $xqty = 'qty'.$i;
- $xremise = 'remise'.$i;
- $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
- }
- }
-
- $id = $object->create($user);
+ $error++;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'
';
+ header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create&mesg='.urlencode($mesg));
+ exit;
}
- if ($id > 0)
+ if (! $error)
{
- $error=0;
+ $db->begin();
- // Insertion contact par defaut si defini
- if ($_POST["contactidp"])
- {
- $result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external');
+ // Si on a selectionne une propal a copier, on realise la copie
+ if($_POST['createmode']=='copy' && $_POST['copie_propal'])
+ {
+ if ($object->fetch($_POST['copie_propal']) > 0)
+ {
+ $object->ref = $_POST['ref'];
+ $object->datep = $datep;
+ $object->date_livraison = $date_delivery;
+ $object->availability_id = $_POST['availability_id'];
+ $object->demand_reason_id = $_POST['demand_reason_id'];
+ $object->fk_delivery_address = $_POST['fk_address'];
+ $object->duree_validite = $_POST['duree_validite'];
+ $object->cond_reglement_id = $_POST['cond_reglement_id'];
+ $object->mode_reglement_id = $_POST['mode_reglement_id'];
+ $object->remise_percent = $_POST['remise_percent'];
+ $object->remise_absolue = $_POST['remise_absolue'];
+ $object->socid = $_POST['socid'];
+ $object->contactid = $_POST['contactidp'];
+ $object->fk_project = $_POST['projectid'];
+ $object->modelpdf = $_POST['model'];
+ $object->author = $user->id; // deprecated
+ $object->note = $_POST['note'];
+ $object->statut = 0;
- if ($result > 0)
- {
- $error=0;
- }
- else
- {
- $mesg = ''.$langs->trans("ErrorFailedToAddContact").'
';
- $error=1;
- }
- }
+ $id = $object->create_from($user);
+ }
+ else
+ {
+ $mesg = ''.$langs->trans("ErrorFailedToCopyProposal",$_POST['copie_propal']).'
';
+ }
+ }
+ else
+ {
+ $object->ref = $_POST['ref'];
+ $object->ref_client = $_POST['ref_client'];
+ $object->datep = $datep;
+ $object->date_livraison = $date_delivery;
+ $object->availability_id = $_POST['availability_id'];
+ $object->demand_reason_id = $_POST['demand_reason_id'];
+ $object->fk_delivery_address = $_POST['fk_address'];
+ $object->duree_validite = $_POST['duree_validite'];
+ $object->cond_reglement_id = $_POST['cond_reglement_id'];
+ $object->mode_reglement_id = $_POST['mode_reglement_id'];
- if (! $error)
- {
- $db->commit();
+ $object->contactid = $_POST['contactidp'];
+ $object->fk_project = $_POST['projectid'];
+ $object->modelpdf = $_POST['model'];
+ $object->author = $user->id; // deprecated
+ $object->note = $_POST['note'];
- // Define output language
- $outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager);
+ $object->origin = $_POST['origin'];
+ $object->origin_id = $_POST['originid'];
- Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
- exit;
- }
- else
- {
- $db->rollback();
- }
- }
- else
- {
- dol_print_error($db,$object->error);
- $db->rollback();
- exit;
+ for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
+ {
+ if ($_POST['idprod'.$i])
+ {
+ $xid = 'idprod'.$i;
+ $xqty = 'qty'.$i;
+ $xremise = 'remise'.$i;
+ $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
+ }
+ }
+
+ $id = $object->create($user);
+ }
+
+ if ($id > 0)
+ {
+ $error=0;
+
+ // Insertion contact par defaut si defini
+ if ($_POST["contactidp"])
+ {
+ $result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external');
+
+ if ($result > 0)
+ {
+ $error=0;
+ }
+ else
+ {
+ $mesg = ''.$langs->trans("ErrorFailedToAddContact").'
';
+ $error=1;
+ }
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+
+ // Define output language
+ $outputlangs = $langs;
+ $newlang='';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager);
+
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ dol_print_error($db,$object->error);
+ $db->rollback();
+ exit;
+ }
}
}
@@ -607,11 +632,9 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile']
}
}
+// Go back to draft
if ($action == 'modif' && $user->rights->propale->creer)
{
- /*
- * Repasse la propale en mode brouillon
- */
$object->fetch($id);
$object->fetch_thirdparty();
$object->set_draft($user);
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index bc873b2e2c2..67cba1aaff4 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -612,7 +612,7 @@ class Propal extends CommonObject
if (empty($this->availability_id)) $this->availability_id=0;
if (empty($this->demand_reason_id)) $this->demand_reason_id=0;
- dol_syslog("Propal::Create");
+ dol_syslog(get_class($this)."::create");
// Check parameters
$soc = new Societe($this->db);
@@ -620,9 +620,15 @@ class Propal extends CommonObject
if ($result < 0)
{
$this->error="Failed to fetch company";
- dol_syslog("Propal::create ".$this->error, LOG_ERR);
+ dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
return -3;
}
+ if (empty($this->datep))
+ {
+ $this->error="Date of proposal is required";
+ dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
+ return -4;
+ }
if (! empty($this->ref))
{
$result=$this->verifyNumRef(); // Check ref is not yet used
@@ -683,7 +689,7 @@ class Propal extends CommonObject
$sql.= ", ".$conf->entity;
$sql.= ")";
- dol_syslog("Propal::create sql=".$sql, LOG_DEBUG);
+ dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -694,7 +700,7 @@ class Propal extends CommonObject
if (empty($this->ref)) $this->ref='(PROV'.$this->id.')';
$sql = 'UPDATE '.MAIN_DB_PREFIX."propal SET ref='".$this->ref."' WHERE rowid=".$this->id;
- dol_syslog("Propal::create sql=".$sql);
+ dol_syslog(get_class($this)."::create sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql) $error++;
@@ -805,13 +811,13 @@ class Propal extends CommonObject
if (! $error)
{
$this->db->commit();
- dol_syslog("Propal::Create done id=".$this->id);
+ dol_syslog(get_class($this)."::create done id=".$this->id);
return $this->id;
}
else
{
$this->error=$this->db->error();
- dol_syslog("Propal::Create -2 ".$this->error, LOG_ERR);
+ dol_syslog(get_class($this)."::create -2 ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
@@ -819,7 +825,7 @@ class Propal extends CommonObject
else
{
$this->error=$this->db->error();
- dol_syslog("Propal::Create -1 ".$this->error, LOG_ERR);
+ dol_syslog(get_class($this)."::create -1 ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
@@ -1201,9 +1207,16 @@ class Propal extends CommonObject
*/
function set_date($user, $date)
{
- if ($user->rights->propale->creer)
+ if (empty($date))
{
- $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = ".$this->db->idate($date);
+ $this->error='ErrorBadParameter';
+ dol_syslog(get_class($this)."::set_date ".$this->error, LOG_ERR);
+ return -1;
+ }
+
+ if ($user->rights->propale->creer)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'";
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
dol_syslog(get_class($this)."::set_date sql=".$sql);
@@ -1231,9 +1244,9 @@ class Propal extends CommonObject
*/
function set_echeance($user, $date_fin_validite)
{
- if ($user->rights->propale->creer)
+ if ($user->rights->propale->creer)
{
- $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".$this->db->idate($date_fin_validite);
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null');
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
if ($this->db->query($sql) )
{
@@ -1243,7 +1256,7 @@ class Propal extends CommonObject
else
{
$this->error=$this->db->error();
- dol_syslog("Propal::set_echeance Erreur SQL".$this->error, LOG_ERR);
+ dol_syslog(get_class($this)."::set_echeance Erreur SQL".$this->error, LOG_ERR);
return -1;
}
}
@@ -1261,7 +1274,7 @@ class Propal extends CommonObject
if ($user->rights->propale->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
- $sql.= " SET date_livraison = ".($date_livraison!=''?$this->db->idate($date_livraison):'null');
+ $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
$sql.= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
@@ -1272,7 +1285,7 @@ class Propal extends CommonObject
else
{
$this->error=$this->db->error();
- dol_syslog("Propal::set_date_livraison Erreur SQL");
+ dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
return -1;
}
}
@@ -1465,8 +1478,8 @@ class Propal extends CommonObject
}
}
-
-
+
+
/**
* Close the commercial proposal
*
@@ -1478,23 +1491,23 @@ class Propal extends CommonObject
function reopen($user, $statut, $note)
{
global $langs,$conf;
-
+
$this->statut = $statut;
$error=0;
-
+
$this->db->begin();
-
+
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_statut = ".$statut.", note = '".$this->db->escape($note)."', date_cloture=".$this->db->idate(mktime()).", fk_user_cloture=".$user->id;
$sql.= " WHERE rowid = ".$this->id;
-
+
$resql=$this->db->query($sql);
if ($resql)
{
}
}
-
+
/**
* Close the commercial proposal