Added cancel status & setCancel method

This commit is contained in:
William Mead
2024-01-10 09:07:28 +01:00
parent 02051ebf38
commit 3f1f4829e4

View File

@@ -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