From ada81750c10ded375b2697a001043be6207da5d4 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 17 May 2022 12:53:50 +0200 Subject: [PATCH] NEW: Add Customer Ref on Intervention --- htdocs/fichinter/card.php | 20 ++++- htdocs/fichinter/class/fichinter.class.php | 76 ++++++++++++++++++- htdocs/fichinter/list.php | 29 ++++++- .../install/mysql/migration/15.0.0-16.0.0.sql | 2 + htdocs/install/mysql/tables/llx_fichinter.sql | 1 + 5 files changed, 123 insertions(+), 5 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 0d7e5278a14..a2271dbb063 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -55,6 +55,7 @@ $langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks')); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); +$ref_client = GETPOST('ref_client', 'alpha'); $socid = (int) GETPOST('socid', 'int'); $contratid = (int) GETPOST('contratid', 'int'); $action = GETPOST('action', 'alpha'); @@ -222,6 +223,7 @@ if (empty($reshook)) { $object->author = $user->id; $object->description = GETPOST('description', 'restricthtml'); $object->ref = $ref; + $object->ref_client = $ref_client; $object->model_pdf = GETPOST('model', 'alpha'); $object->note_private = GETPOST('note_private', 'restricthtml'); $object->note_public = GETPOST('note_public', 'restricthtml'); @@ -432,6 +434,7 @@ if (empty($reshook)) { $object->author = $user->id; $object->description = GETPOST('description', 'restricthtml'); $object->ref = $ref; + $object->ref_client = $ref_client; $result = $object->update($user); if ($result < 0) { @@ -449,6 +452,12 @@ if (empty($reshook)) { if ($result < 0) { dol_print_error($db, $object->error); } + } elseif ($action == 'setref_client' && $user->rights->ficheinter->creer) { + // Positionne ref client + $result = $object->setRefClient($user, GETPOST('ref_client','alpha')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) { $result = $object->delete($user); if ($result < 0) { @@ -879,6 +888,11 @@ if ($action == 'create') { // Ref print ''.$langs->trans('Ref').''.$langs->trans("Draft").''; + // Ref customer + print ''.$langs->trans('RefCustomer').''; + print ''; + print ''; + // Description (must be a textarea and not html must be allowed (used in list view) print ''.$langs->trans("Description").''; print ''; @@ -1134,10 +1148,10 @@ if ($action == 'create') { $morehtmlref = '
'; // Ref customer - //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 1); - //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', null, null, '', 1); + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); // Project if (!empty($conf->projet->enabled)) { $langs->load("projects"); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index b5e3a13f3c0..ec603defd62 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -44,6 +44,7 @@ class Fichinter extends CommonObject 'fk_contrat' =>array('type'=>'integer', 'label'=>'Fk contrat', 'enabled'=>1, 'visible'=>-1, 'position'=>25), 'ref' =>array('type'=>'varchar(30)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'showoncombobox'=>1, 'position'=>30), 'ref_ext' =>array('type'=>'varchar(255)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>0, 'position'=>35), + 'ref_client' =>array('type'=>'varchar(255)', 'label'=>'RefCustomer', 'enabled'=>1, 'visible'=>-1, 'position'=>36), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>40, 'index'=>1), 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>45), 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>50), @@ -146,6 +147,12 @@ class Fichinter extends CommonObject */ public $fk_project = 0; + /** + * Customer Ref + * @var string + */ + public $ref_client; + /** * @var array extraparams */ @@ -253,6 +260,9 @@ class Fichinter extends CommonObject if (!is_numeric($this->duration)) { $this->duration = 0; } + if (isset($this->ref_client)) { + $this->ref_client = trim($this->ref_client); + } if ($this->socid <= 0) { $this->error = 'ErrorFicheinterCompanyDoesNotExist'; @@ -271,6 +281,7 @@ class Fichinter extends CommonObject $sql .= "fk_soc"; $sql .= ", datec"; $sql .= ", ref"; + $sql .= ", ref_client"; $sql .= ", entity"; $sql .= ", fk_user_author"; $sql .= ", fk_user_modif"; @@ -286,6 +297,7 @@ class Fichinter extends CommonObject $sql .= $this->socid; $sql .= ", '".$this->db->idate($now)."'"; $sql .= ", '".$this->db->escape($this->ref)."'"; + $sql .= ", '".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null")."'"; $sql .= ", ".((int) $conf->entity); $sql .= ", ".((int) $user->id); $sql .= ", ".((int) $user->id); @@ -372,6 +384,9 @@ class Fichinter extends CommonObject if (!dol_strlen($this->fk_project)) { $this->fk_project = 0; } + if (isset($this->ref_client)) { + $this->ref_client = trim($this->ref_client); + } $error = 0; @@ -380,6 +395,7 @@ class Fichinter extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; $sql .= "description = '".$this->db->escape($this->description)."'"; $sql .= ", duree = ".((int) $this->duration); + $sql .= ", ref_client = ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null"); $sql .= ", fk_projet = ".((int) $this->fk_project); $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null"); @@ -422,7 +438,7 @@ class Fichinter extends CommonObject */ public function fetch($rowid, $ref = '') { - $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; + $sql = "SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut,"; $sql .= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,"; $sql .= " f.date_valid as datev,"; $sql .= " f.tms as datem,"; @@ -443,6 +459,7 @@ class Fichinter extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->ref; + $this->ref_client = $obj->ref_client; $this->description = $obj->description; $this->socid = $obj->fk_soc; $this->statut = $obj->fk_statut; @@ -1289,6 +1306,7 @@ class Fichinter extends CommonObject // Initialise parametres $this->id = 0; $this->ref = 'SPECIMEN'; + $this->ref_client = 'SPECIMEN CLIENT'; $this->specimen = 1; $this->socid = 1; $this->datec = $now; @@ -1377,6 +1395,62 @@ class Fichinter extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Set customer reference number + * + * @param User $user Object user that modify + * @param string $ref_client Customer reference + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + */ + public function setRefClient($user, $ref_client, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->ficheinter->creer)) { + $error = 0; + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'"); + $sql .= " WHERE rowid = ".((int) $this->id); + + dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $this->errors[] = $this->db->error(); + $error++; + } + + if (!$error) { + $this->oldcopy = clone $this; + $this->ref_client = $ref_client; + } + + if (!$notrigger && empty($error)) { + // Call trigger + $result = $this->call_trigger('FICHINTER_MODIFY', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } + + if (!$error) { + $this->db->commit(); + return 1; + } else { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } + } else { + return -1; + } + } } /** diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index f0e028ea92f..d83a1438f1a 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -58,6 +58,7 @@ $toselect = GETPOST('toselect', 'array'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'interventionlist'; $search_ref = GETPOST('search_ref') ?GETPOST('search_ref', 'alpha') : GETPOST('search_inter', 'alpha'); +$search_ref_client = GETPOST('search_ref_client', 'alpha'); $search_company = GETPOST('search_company', 'alpha'); $search_desc = GETPOST('search_desc', 'alpha'); $search_projet_ref = GETPOST('search_projet_ref', 'alpha'); @@ -122,6 +123,7 @@ if (!empty($conf->global->FICHINTER_DISABLE_DETAILS)) { // Definition of fields for list $arrayfields = array( 'f.ref'=>array('label'=>'Ref', 'checked'=>1), + 'f.ref_client'=>array('label'=>'RefCustomer', 'checked'=>1), 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1), 'pr.ref'=>array('label'=>'Project', 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1)), 'c.ref'=>array('label'=>'Contract', 'checked'=>1, 'enabled'=>(empty($conf->contrat->enabled) ? 0 : 1)), @@ -166,6 +168,7 @@ if (empty($reshook)) { // Purge search criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_ref = ""; + $search_ref_client = ""; $search_company = ""; $search_projet_ref = ""; $search_contrat_ref = ""; @@ -218,7 +221,7 @@ foreach ($arrayfields as $tmpkey => $tmpval) { } $sql = "SELECT"; -$sql .= " f.ref, f.rowid, f.fk_statut as status, f.description, f.datec as date_creation, f.tms as date_update, f.note_public, f.note_private,"; +$sql .= " f.ref, f.ref_client, f.rowid, f.fk_statut as status, f.description, f.datec as date_creation, f.tms as date_update, f.note_public, f.note_private,"; if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) { $sql .= " fd.rowid as lineid, fd.description as descriptiondetail, fd.date as dp, fd.duree,"; } @@ -267,6 +270,9 @@ $sql .= " AND f.fk_soc = s.rowid"; if ($search_ref) { $sql .= natural_search('f.ref', $search_ref); } +if ($search_ref_client) { + $sql .= natural_search('f.ref_client', $search_ref_client); +} if ($search_company) { $sql .= natural_search('s.nom', $search_company); } @@ -351,6 +357,9 @@ if ($resql) { if ($search_ref) { $param .= "&search_ref=".urlencode($search_ref); } + if ($search_ref_client) { + $param .= "&search_ref_client=".urlencode($search_ref_client); + } if ($search_company) { $param .= "&search_company=".urlencode($search_company); } @@ -447,6 +456,11 @@ if ($resql) { print ''; print ''; } + if (!empty($arrayfields['f.ref_client']['checked'])) { + print ''; + print ''; + print ''; + } if (!empty($arrayfields['s.nom']['checked'])) { print ''; print ''; @@ -526,6 +540,9 @@ if ($resql) { if (!empty($arrayfields['f.ref']['checked'])) { print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); } + if (!empty($arrayfields['f.ref_client']['checked'])) { + print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], "f.ref_client", "", $param, '', $sortfield, $sortorder); + } if (!empty($arrayfields['s.nom']['checked'])) { print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder); } @@ -582,6 +599,7 @@ if ($resql) { $objectstatic->id = $obj->rowid; $objectstatic->ref = $obj->ref; + $objectstatic->ref_client = $obj->ref_client; $objectstatic->statut = $obj->status; $objectstatic->status = $obj->status; @@ -630,6 +648,15 @@ if ($resql) { $totalarray['nbfield']++; } } + if (!empty($arrayfields['f.ref_client']['checked'])) { + // Customer ref + print ''; + print $obj->ref_client; + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } if (!empty($arrayfields['s.nom']['checked'])) { print ''; print $companystatic->getNomUrl(1, '', 44); diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 501aa0fe751..8b00bee9b3c 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -361,4 +361,6 @@ ALTER TABLE llx_c_email_template ADD COLUMN email_to varchar(255); ALTER TABLE llx_c_email_template ADD COLUMN email_tocc varchar(255); ALTER TABLE llx_c_email_template ADD COLUMN email_tobcc varchar(255); +ALTER TABLE llx_fichinter ADD COLUMN ref_client varchar(255) after ref_ext; + diff --git a/htdocs/install/mysql/tables/llx_fichinter.sql b/htdocs/install/mysql/tables/llx_fichinter.sql index 7c1ef4cf184..999dd55b7f3 100644 --- a/htdocs/install/mysql/tables/llx_fichinter.sql +++ b/htdocs/install/mysql/tables/llx_fichinter.sql @@ -25,6 +25,7 @@ create table llx_fichinter fk_contrat integer DEFAULT 0, -- contrat auquel est rattache la fiche ref varchar(30) NOT NULL, -- number ref_ext varchar(255), + ref_client varchar(255), -- customer intervention number entity integer DEFAULT 1 NOT NULL, -- multi company id tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, datec datetime, -- date de creation