|
@@ -140,6 +140,16 @@ class Propal extends CommonObject
|
|
|
*/
|
|
|
public $date_validation;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var integer|string $date_signature;
|
|
|
+ */
|
|
|
+ public $date_signature;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var User $user_signature
|
|
|
+ */
|
|
|
+ public $user_signature;
|
|
|
+
|
|
|
/**
|
|
|
* @var integer|string date of the quote;
|
|
|
*/
|
|
@@ -1232,7 +1242,7 @@ class Propal extends CommonObject
|
|
|
/*if (! $error && $this->fk_delivery_address)
|
|
|
{
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
|
|
- $sql.= " SET fk_delivery_address = ".$this->fk_delivery_address;
|
|
|
+ $sql.= " SET fk_delivery_address = ".((int) $this->fk_delivery_address);
|
|
|
$sql.= " WHERE ref = '".$this->db->escape($this->ref)."'";
|
|
|
$sql.= " AND entity = ".setEntity($this);
|
|
|
|
|
@@ -2203,7 +2213,7 @@ class Propal extends CommonObject
|
|
|
$this->db->begin();
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
|
|
- $sql .= " SET fk_input_reason = ".$id;
|
|
|
+ $sql .= " SET fk_input_reason = ".((int) $id);
|
|
|
$sql .= " WHERE rowid = ".$this->id;
|
|
|
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
@@ -2322,13 +2332,13 @@ class Propal extends CommonObject
|
|
|
$remise = trim($remise) ?trim($remise) : 0;
|
|
|
|
|
|
if (!empty($user->rights->propal->creer)) {
|
|
|
- $remise = price2num($remise);
|
|
|
+ $remise = price2num($remise, 2);
|
|
|
|
|
|
$error = 0;
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
- $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
|
|
|
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".((float) $remise);
|
|
|
$sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
|
|
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
@@ -2380,17 +2390,18 @@ class Propal extends CommonObject
|
|
|
public function set_remise_absolue($user, $remise, $notrigger = 0)
|
|
|
{
|
|
|
// phpcs:enable
|
|
|
- $remise = trim($remise) ?trim($remise) : 0;
|
|
|
+ if (empty($remise)) {
|
|
|
+ $remise = 0;
|
|
|
+ }
|
|
|
+ $remise = price2num($remise);
|
|
|
|
|
|
if (!empty($user->rights->propal->creer)) {
|
|
|
- $remise = price2num($remise);
|
|
|
-
|
|
|
$error = 0;
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
- $sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
|
|
|
- $sql .= " SET remise_absolue = ".$remise;
|
|
|
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
|
|
+ $sql .= " SET remise_absolue = ".((float) $remise);
|
|
|
$sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
|
|
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
|
@@ -2435,19 +2446,17 @@ class Propal extends CommonObject
|
|
|
* Reopen the commercial proposal
|
|
|
*
|
|
|
* @param User $user Object user that close
|
|
|
- * @param int $statut Statut
|
|
|
+ * @param int $status Status
|
|
|
* @param string $note Comment
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
|
- public function reopen($user, $statut, $note = '', $notrigger = 0)
|
|
|
+ public function reopen($user, $status, $note = '', $notrigger = 0)
|
|
|
{
|
|
|
-
|
|
|
- $this->statut = $statut;
|
|
|
$error = 0;
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
|
|
- $sql .= " SET fk_statut = ".$this->statut.",";
|
|
|
+ $sql .= " SET fk_statut = ".$status.",";
|
|
|
if (!empty($note)) {
|
|
|
$sql .= " note_private = '".$this->db->escape($note)."',";
|
|
|
}
|
|
@@ -2484,11 +2493,105 @@ class Propal extends CommonObject
|
|
|
$this->db->rollback();
|
|
|
return -1 * $error;
|
|
|
} else {
|
|
|
+ $this->statut = $status;
|
|
|
+ $this->status = $status;
|
|
|
+
|
|
|
$this->db->commit();
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sign the commercial proposal
|
|
|
+ *
|
|
|
+ * @param User $user Object user that close
|
|
|
+ * @param int $statut Status
|
|
|
+ * @param string $note Complete private note with this note
|
|
|
+ * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
|
|
|
+ * @return int <0 if KO, >0 if OK
|
|
|
+ */
|
|
|
+ public function signature($user, $statut, $note = '', $notrigger = 0)
|
|
|
+ {
|
|
|
+ global $langs,$conf;
|
|
|
+
|
|
|
+ $error = 0;
|
|
|
+ $now = dol_now();
|
|
|
+
|
|
|
+ $this->db->begin();
|
|
|
+
|
|
|
+ $newprivatenote = dol_concatdesc($this->note_private, $note);
|
|
|
+
|
|
|
+ $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
|
|
+ $sql .= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($newprivatenote)."', date_signature='".$this->db->idate($now)."', fk_user_signature=".$user->id;
|
|
|
+ $sql .= " WHERE rowid = ".$this->id;
|
|
|
+
|
|
|
+ $resql = $this->db->query($sql);
|
|
|
+ if ($resql) {
|
|
|
+ $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
|
|
|
+ $trigger_name = 'PROPAL_CLOSE_REFUSED';
|
|
|
+
|
|
|
+ if ($statut == self::STATUS_SIGNED) {
|
|
|
+ $trigger_name = 'PROPAL_CLOSE_SIGNED';
|
|
|
+ $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->model_pdf;
|
|
|
+
|
|
|
+ // The connected company is classified as a client
|
|
|
+ $soc=new Societe($this->db);
|
|
|
+ $soc->id = $this->socid;
|
|
|
+ $result = $soc->set_as_client();
|
|
|
+
|
|
|
+ if ($result < 0) {
|
|
|
+ $this->error=$this->db->lasterror();
|
|
|
+ $this->db->rollback();
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
|
|
+ // Define output language
|
|
|
+ $outputlangs = $langs;
|
|
|
+ if (!empty($conf->global->MAIN_MULTILANGS)) {
|
|
|
+ $outputlangs = new Translate("", $conf);
|
|
|
+ $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
|
|
|
+ $outputlangs->setDefaultLang($newlang);
|
|
|
+ }
|
|
|
+
|
|
|
+ //$ret=$object->fetch($id); // Reload to get new records
|
|
|
+ $this->generateDocument($modelpdf, $outputlangs);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$error) {
|
|
|
+ $this->oldcopy= clone $this;
|
|
|
+ $this->statut = $statut;
|
|
|
+ $this->date_signature = $now;
|
|
|
+ $this->note_private = $newprivatenote;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$notrigger && empty($error)) {
|
|
|
+ // Call trigger
|
|
|
+ $result=$this->call_trigger($trigger_name, $user);
|
|
|
+ if ($result < 0) {
|
|
|
+ $error++;
|
|
|
+ }
|
|
|
+ // End call triggers
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$error ) {
|
|
|
+ $this->db->commit();
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ $this->statut = $this->oldcopy->statut;
|
|
|
+ $this->date_signature = $this->oldcopy->date_signature;
|
|
|
+ $this->note_private = $this->oldcopy->note_private;
|
|
|
+
|
|
|
+ $this->db->rollback();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error=$this->db->lasterror();
|
|
|
+ $this->db->rollback();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Close the commercial proposal
|
|
@@ -2511,7 +2614,7 @@ class Propal extends CommonObject
|
|
|
$newprivatenote = dol_concatdesc($this->note_private, $note);
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
|
|
- $sql .= " SET fk_statut = ".$status.", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
|
|
|
+ $sql .= " SET fk_statut = ".((int) $status).", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
|
|
|
$sql .= " WHERE rowid = ".$this->id;
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
@@ -2884,7 +2987,7 @@ class Propal extends CommonObject
|
|
|
// Delete extrafields of lines and lines
|
|
|
if (!$error && !empty($this->table_element_line)) {
|
|
|
$tabletodelete = $this->table_element_line;
|
|
|
- $sqlef = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete."_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".$this->id.")";
|
|
|
+ $sqlef = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete."_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".((int) $this->id).")";
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".$this->id;
|
|
|
if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
|
|
|
$error++;
|
|
@@ -2995,7 +3098,7 @@ class Propal extends CommonObject
|
|
|
$this->db->begin();
|
|
|
|
|
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
|
|
- $sql .= ' SET fk_availability = '.$availability_id;
|
|
|
+ $sql .= ' SET fk_availability = '.((int) $availability_id);
|
|
|
$sql .= ' WHERE rowid='.((int) $this->id);
|
|
|
|
|
|
dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG);
|
|
@@ -3059,7 +3162,7 @@ class Propal extends CommonObject
|
|
|
$this->db->begin();
|
|
|
|
|
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
|
|
|
- $sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
|
|
+ $sql .= ' SET fk_input_reason = '.((int) $demand_reason_id);
|
|
|
$sql .= ' WHERE rowid='.((int) $this->id);
|
|
|
|
|
|
dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG);
|
|
@@ -3113,8 +3216,8 @@ class Propal extends CommonObject
|
|
|
public function info($id)
|
|
|
{
|
|
|
$sql = "SELECT c.rowid, ";
|
|
|
- $sql .= " c.datec, c.date_valid as datev, c.date_cloture as dateo,";
|
|
|
- $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture";
|
|
|
+ $sql .= " c.datec, c.date_valid as datev, c.date_signature, c.date_cloture as dateo,";
|
|
|
+ $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture";
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."propal as c";
|
|
|
$sql .= " WHERE c.rowid = ".((int) $id);
|
|
|
|
|
@@ -3128,6 +3231,7 @@ class Propal extends CommonObject
|
|
|
|
|
|
$this->date_creation = $this->db->jdate($obj->datec);
|
|
|
$this->date_validation = $this->db->jdate($obj->datev);
|
|
|
+ $this->date_signature = $this->db->jdate($obj->date_signature);
|
|
|
$this->date_cloture = $this->db->jdate($obj->dateo);
|
|
|
|
|
|
$cuser = new User($this->db);
|
|
@@ -3140,6 +3244,12 @@ class Propal extends CommonObject
|
|
|
$this->user_validation = $vuser;
|
|
|
}
|
|
|
|
|
|
+ if ($obj->fk_user_signature) {
|
|
|
+ $user_signature = new User($this->db);
|
|
|
+ $user_signature->fetch($obj->fk_user_signature);
|
|
|
+ $this->user_signature = $user_signature;
|
|
|
+ }
|
|
|
+
|
|
|
if ($obj->fk_user_cloture) {
|
|
|
$cluser = new User($this->db);
|
|
|
$cluser->fetch($obj->fk_user_cloture);
|