Skip to content

Commit

Permalink
Add signed status CRUD to contract and fichinter
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Mar 15, 2024
1 parent e9849a3 commit d43c322
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 4 deletions.
42 changes: 42 additions & 0 deletions htdocs/contrat/class/contrat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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)


/**
Expand Down Expand Up @@ -2953,6 +2979,22 @@ public function getKanbanView($option = '', $arraydata = null)
$return .= '</div>';
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);
}
}


Expand Down
49 changes: 49 additions & 0 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions htdocs/fichinter/class/fichinter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1600,6 +1627,20 @@ public function getKanbanView($option = '', $arraydata = null)
$return .= '</div>';
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);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions htdocs/install/mysql/migration/19.0.0-20.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_contrat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_fichinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d43c322

Please sign in to comment.