From 3f1f4829e477fcae08d2bd54aee8979e5a6794d3 Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 10 Jan 2024 09:07:28 +0100 Subject: [PATCH] Added cancel status & setCancel method --- htdocs/comm/propal/class/propal.class.php | 56 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 28d62bafb87..011bda8a035 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -136,14 +136,14 @@ class Propal extends CommonObject * Status of the quote * @var int * @deprecated Try to use $status now - * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED + * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED, Propal::STATUS_CANCELED */ public $statut; /** * Status of the quote * @var int - * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED + * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED, Propal::STATUS_CANCELED */ public $status; @@ -373,6 +373,10 @@ class Propal extends CommonObject ); // END MODULEBUILDER PROPERTIES + /** + * Canceled status + */ + const STATUS_CANCELED = -1; /** * Draft status */ @@ -2859,6 +2863,54 @@ class Propal extends CommonObject } } + /** + * Cancel the proposal + * + * @return int Return integer if KO <0 , if OK >0 + */ + public function setCancel() + { + global $user; + + $error = 0; + + $this->db->begin(); + + $sql = "UPDATE ". MAIN_DB_PREFIX . "propal"; + $sql .= " SET fk_statut = " . self::STATUS_CANCELED . ","; + $sql .= " fk_user_modif = " . ((int) $user->id); + $sql .= " WHERE rowid = " . ((int) $this->id); + + dol_syslog(get_class($this)."::cancel", LOG_DEBUG); + if ($this->db->query($sql)) { + if (!$error) { + // Call trigger + $result = $this->call_trigger('PROPAL_CANCEL', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + + if (!$error) { + $this->status = self::STATUS_CANCELED; + $this->db->commit(); + return 1; + } else { + foreach ($this->errors as $errmsg) { + dol_syslog(get_class($this)."::cancel ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1; + } + } else { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status