From d43c3227dbe82e7f96f8ac5f59b54edc1a5f84bb Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Fri, 15 Mar 2024 12:11:01 +0100 Subject: [PATCH] Add signed status CRUD to contract and fichinter --- htdocs/contrat/class/contrat.class.php | 42 ++++++++++++++++ htdocs/core/class/commonobject.class.php | 49 +++++++++++++++++++ htdocs/fichinter/class/fichinter.class.php | 41 ++++++++++++++++ .../install/mysql/migration/19.0.0-20.0.0.sql | 4 +- htdocs/install/mysql/tables/llx_contrat.sql | 2 +- htdocs/install/mysql/tables/llx_fichinter.sql | 2 +- 6 files changed, 136 insertions(+), 4 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 232084addce7a..06644ff5a177a 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -184,6 +184,12 @@ class Contrat extends CommonObject */ public $date_contrat; + /** + * Status of the contract (0=NoSignature, 1=SignedBySender, 2=SignedByReceiver, 9=SignedByAll) + * @var int + */ + public $signed_status = 0; + public $commercial_signature_id; public $fk_commercial_signature; public $commercial_suivi_id; @@ -255,6 +261,7 @@ class Contrat extends CommonObject 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 35), 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 40), 'date_contrat' => array('type' => 'datetime', 'label' => 'Date contrat', 'enabled' => 1, 'visible' => -1, 'position' => 45), + 'signed_status' => array('type' => 'smallint(6)', 'label' => 'SignedStatus', 'enabled' => 1, 'visible' => -1, 'position' => 50, 'arrayofkeyval' => array(0 => 'NoSignature', 1 => 'SignedSender', 2 => 'SignedReceiver', 9 => 'SignedAll')), 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'notnull' => 1, 'position' => 70), 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => -1, 'position' => 75), 'fk_commercial_signature' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'SaleRepresentative Signature', 'enabled' => 1, 'visible' => -1, 'position' => 80), @@ -275,6 +282,25 @@ class Contrat extends CommonObject const STATUS_VALIDATED = 1; const STATUS_CLOSED = 2; + /* + * No signature + */ + const STATUS_NO_SIGNATURE = 0; + + /* + * Signed by sender + */ + CONST STATUS_SIGNED_SENDER = 1; + + /* + * Signed by receiver + */ + CONST STATUS_SIGNED_RECEIVER = 2; + + /* + * Signed by all + */ + CONST STATUS_SIGNED_ALL = 9; // To handle future kind of signature (ex: tripartite contract) /** @@ -2953,6 +2979,22 @@ public function getKanbanView($option = '', $arraydata = null) $return .= ''; return $return; } + + // @Todo getLibSignedStatus, LibSignedStatus + + /** + * Set signed status + * + * @param User $user Object user that modify + * @param int $status Newsigned status to set (often a constant like self::STATUS_XXX) + * @param int $notrigger 1 = Does not execute triggers, 0 = Execute triggers + * @param string $triggercode Trigger code to use + * @return int 0 < if KO, > 0 if OK + */ + public function setSignedStatus(User $user, int $status = 0, int $notrigger = 0, $triggercode = ''): int + { + return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode); + } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 44de1d1210904..985f23625e864 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10467,6 +10467,55 @@ public function setStatusCommon($user, $status, $notrigger = 0, $triggercode = ' } } + /** + * Set to a signed status + * + * @param User $user Object user that modify + * @param int $status New status to set (often a constant like self::STATUS_XXX) + * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @param string $triggercode Trigger code to use + * @return int Return integer <0 if KO, >0 if OK + */ + public function setSignedStatusCommon($user, $status, $notrigger = 0, $triggercode = '') + { + $error = 0; + + $this->db->begin(); + + $statusfield = 'signed_status'; + + $sql = "UPDATE ".$this->db->prefix().$this->table_element; + $sql .= " SET ".$statusfield." = ".((int) $status); + $sql .= " WHERE rowid = ".((int) $this->id); + + if ($this->db->query($sql)) { + if (!$error) { + $this->oldcopy = clone $this; + } + + if (!$error && !$notrigger) { + // Call trigger + $result = $this->call_trigger($triggercode, $user); + if ($result < 0) { + $error++; + } + } + + if (!$error) { + $this->status = $status; + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return -1; + } + } else { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } + /** * Initialise object with example values diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 010427ab2a4e3..f5b57037c0d6e 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -58,6 +58,7 @@ class Fichinter extends CommonObject 'datee' => array('type' => 'date', 'label' => 'Datee', 'enabled' => 1, 'visible' => -1, 'position' => 90), 'datet' => array('type' => 'date', 'label' => 'Datet', 'enabled' => 1, 'visible' => -1, 'position' => 95), 'duree' => array('type' => 'double', 'label' => 'Duree', 'enabled' => 1, 'visible' => -1, 'position' => 100), + 'signed_status' => array('type' => 'smallint(6)', 'label' => 'SignedStatus', 'enabled' => 1, 'visible' => -1, 'position' => 101, 'arrayofkeyval' => array(0 => 'NoSignature', 1 => 'SignedSender', 2 => 'SignedReceiver', 9 => 'SignedAll')), 'description' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'visible' => -1, 'position' => 105, 'showoncombobox' => 2), 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 110), 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 115), @@ -134,6 +135,12 @@ class Fichinter extends CommonObject */ public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate + /** + * Signed Status of the intervention (0=NoSignature, 1=SignedBySender, 2=SignedByReceiver, 9=SignedByAll) + * @var int + */ + public $signed_status = 0; + /** * @var string description */ @@ -185,6 +192,26 @@ class Fichinter extends CommonObject */ const STATUS_CLOSED = 3; + /* + * No signature + */ + const STATUS_NO_SIGNATURE = 0; + + /* + * Signed by sender + */ + CONST STATUS_SIGNED_SENDER = 1; + + /* + * Signed by receiver + */ + CONST STATUS_SIGNED_RECEIVER = 2; + + /* + * Signed by all + */ + CONST STATUS_SIGNED_ALL = 9; // To handle future kind of signature (ex: tripartite contract) + /** * Date delivery * @var string|int Delivery int @@ -1600,6 +1627,20 @@ public function getKanbanView($option = '', $arraydata = null) $return .= ''; return $return; } + + /** + * Set signed status + * + * @param User $user Object user that modify + * @param int $status Newsigned status to set (often a constant like self::STATUS_XXX) + * @param int $notrigger 1 = Does not execute triggers, 0 = Execute triggers + * @param string $triggercode Trigger code to use + * @return int 0 < if KO, > 0 if OK + */ + public function setSignedStatus(User $user, int $status = 0, int $notrigger = 0, $triggercode = ''): int + { + return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode); + } } /** diff --git a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql index 7d23c0a4554fe..9c9f6dd01ee21 100644 --- a/htdocs/install/mysql/migration/19.0.0-20.0.0.sql +++ b/htdocs/install/mysql/migration/19.0.0-20.0.0.sql @@ -232,8 +232,8 @@ ALTER TABLE llx_knowledgemanagement_knowledgerecord MODIFY COLUMN answer longtex -- Rename const to add customer categories on not customer/prospect third-party if enabled UPDATE llx_const SET name = 'THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT' WHERE name = 'THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER'; -ALTER TABLE llx_fichinter ADD COLUMN signed_status integer DEFAULT NULL AFTER duree; -ALTER TABLE llx_contrat ADD COLUMN signed_status integer DEFAULT NULL AFTER date_contrat; +ALTER TABLE llx_fichinter ADD COLUMN signed_status smallint DEFAULT NULL AFTER duree; +ALTER TABLE llx_contrat ADD COLUMN signed_status smallint DEFAULT NULL AFTER date_contrat; ALTER TABLE llx_mailing ADD COLUMN messtype varchar(16) DEFAULT 'email' after rowid; diff --git a/htdocs/install/mysql/tables/llx_contrat.sql b/htdocs/install/mysql/tables/llx_contrat.sql index 2e01e909127a6..53c970611027b 100644 --- a/htdocs/install/mysql/tables/llx_contrat.sql +++ b/htdocs/install/mysql/tables/llx_contrat.sql @@ -29,7 +29,7 @@ create table llx_contrat tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, datec datetime, -- creation date date_contrat datetime, - signed_status integer DEFAULT NULL, -- signed status + signed_status smallint DEFAULT NULL, -- signed status statut smallint DEFAULT 0, -- not used. deprecated fin_validite datetime, date_cloture datetime, diff --git a/htdocs/install/mysql/tables/llx_fichinter.sql b/htdocs/install/mysql/tables/llx_fichinter.sql index 4065f3c64b838..5832ce07e9fca 100644 --- a/htdocs/install/mysql/tables/llx_fichinter.sql +++ b/htdocs/install/mysql/tables/llx_fichinter.sql @@ -39,7 +39,7 @@ create table llx_fichinter datee date, -- date de fin d'intervention datet date, -- date de terminaison de l'intervention duree real, -- duree totale de l'intervention - signed_status integer DEFAULT NULL, -- signed status + signed_status smallint DEFAULT NULL, -- signed status description text, note_private text, note_public text,