NEW: Add Customer Ref on Intervention

This commit is contained in:
Florian HENRY 2022-05-17 12:53:50 +02:00
parent 07f2b78758
commit ada81750c1
5 changed files with 123 additions and 5 deletions

View File

@ -55,6 +55,7 @@ $langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks'));
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$ref_client = GETPOST('ref_client', 'alpha');
$socid = (int) GETPOST('socid', 'int'); $socid = (int) GETPOST('socid', 'int');
$contratid = (int) GETPOST('contratid', 'int'); $contratid = (int) GETPOST('contratid', 'int');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
@ -222,6 +223,7 @@ if (empty($reshook)) {
$object->author = $user->id; $object->author = $user->id;
$object->description = GETPOST('description', 'restricthtml'); $object->description = GETPOST('description', 'restricthtml');
$object->ref = $ref; $object->ref = $ref;
$object->ref_client = $ref_client;
$object->model_pdf = GETPOST('model', 'alpha'); $object->model_pdf = GETPOST('model', 'alpha');
$object->note_private = GETPOST('note_private', 'restricthtml'); $object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml'); $object->note_public = GETPOST('note_public', 'restricthtml');
@ -432,6 +434,7 @@ if (empty($reshook)) {
$object->author = $user->id; $object->author = $user->id;
$object->description = GETPOST('description', 'restricthtml'); $object->description = GETPOST('description', 'restricthtml');
$object->ref = $ref; $object->ref = $ref;
$object->ref_client = $ref_client;
$result = $object->update($user); $result = $object->update($user);
if ($result < 0) { if ($result < 0) {
@ -449,6 +452,12 @@ if (empty($reshook)) {
if ($result < 0) { if ($result < 0) {
dol_print_error($db, $object->error); 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) { } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) {
$result = $object->delete($user); $result = $object->delete($user);
if ($result < 0) { if ($result < 0) {
@ -879,6 +888,11 @@ if ($action == 'create') {
// Ref // Ref
print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
// Ref customer
print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
print '</tr>';
// Description (must be a textarea and not html must be allowed (used in list view) // Description (must be a textarea and not html must be allowed (used in list view)
print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>'; print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
print '<td>'; print '<td>';
@ -1134,10 +1148,10 @@ if ($action == 'create') {
$morehtmlref = '<div class="refidno">'; $morehtmlref = '<div class="refidno">';
// Ref customer // Ref customer
//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 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->fichinter->creer, 'string', '', null, null, '', 1); $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
// Thirdparty // Thirdparty
$morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); $morehtmlref .= '<br><span class="hideonsmartphone">'.$langs->trans('ThirdParty').' : </span>'.$object->thirdparty->getNomUrl(1, 'customer');
// Project // Project
if (!empty($conf->projet->enabled)) { if (!empty($conf->projet->enabled)) {
$langs->load("projects"); $langs->load("projects");

View File

@ -44,6 +44,7 @@ class Fichinter extends CommonObject
'fk_contrat' =>array('type'=>'integer', 'label'=>'Fk contrat', 'enabled'=>1, 'visible'=>-1, 'position'=>25), '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' =>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_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), '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), '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), 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
@ -146,6 +147,12 @@ class Fichinter extends CommonObject
*/ */
public $fk_project = 0; public $fk_project = 0;
/**
* Customer Ref
* @var string
*/
public $ref_client;
/** /**
* @var array extraparams * @var array extraparams
*/ */
@ -253,6 +260,9 @@ class Fichinter extends CommonObject
if (!is_numeric($this->duration)) { if (!is_numeric($this->duration)) {
$this->duration = 0; $this->duration = 0;
} }
if (isset($this->ref_client)) {
$this->ref_client = trim($this->ref_client);
}
if ($this->socid <= 0) { if ($this->socid <= 0) {
$this->error = 'ErrorFicheinterCompanyDoesNotExist'; $this->error = 'ErrorFicheinterCompanyDoesNotExist';
@ -271,6 +281,7 @@ class Fichinter extends CommonObject
$sql .= "fk_soc"; $sql .= "fk_soc";
$sql .= ", datec"; $sql .= ", datec";
$sql .= ", ref"; $sql .= ", ref";
$sql .= ", ref_client";
$sql .= ", entity"; $sql .= ", entity";
$sql .= ", fk_user_author"; $sql .= ", fk_user_author";
$sql .= ", fk_user_modif"; $sql .= ", fk_user_modif";
@ -286,6 +297,7 @@ class Fichinter extends CommonObject
$sql .= $this->socid; $sql .= $this->socid;
$sql .= ", '".$this->db->idate($now)."'"; $sql .= ", '".$this->db->idate($now)."'";
$sql .= ", '".$this->db->escape($this->ref)."'"; $sql .= ", '".$this->db->escape($this->ref)."'";
$sql .= ", '".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null")."'";
$sql .= ", ".((int) $conf->entity); $sql .= ", ".((int) $conf->entity);
$sql .= ", ".((int) $user->id); $sql .= ", ".((int) $user->id);
$sql .= ", ".((int) $user->id); $sql .= ", ".((int) $user->id);
@ -372,6 +384,9 @@ class Fichinter extends CommonObject
if (!dol_strlen($this->fk_project)) { if (!dol_strlen($this->fk_project)) {
$this->fk_project = 0; $this->fk_project = 0;
} }
if (isset($this->ref_client)) {
$this->ref_client = trim($this->ref_client);
}
$error = 0; $error = 0;
@ -380,6 +395,7 @@ class Fichinter extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
$sql .= "description = '".$this->db->escape($this->description)."'"; $sql .= "description = '".$this->db->escape($this->description)."'";
$sql .= ", duree = ".((int) $this->duration); $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 .= ", fk_projet = ".((int) $this->fk_project);
$sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); $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"); $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 = '') 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.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
$sql .= " f.date_valid as datev,"; $sql .= " f.date_valid as datev,";
$sql .= " f.tms as datem,"; $sql .= " f.tms as datem,";
@ -443,6 +459,7 @@ class Fichinter extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->ref; $this->ref = $obj->ref;
$this->ref_client = $obj->ref_client;
$this->description = $obj->description; $this->description = $obj->description;
$this->socid = $obj->fk_soc; $this->socid = $obj->fk_soc;
$this->statut = $obj->fk_statut; $this->statut = $obj->fk_statut;
@ -1289,6 +1306,7 @@ class Fichinter extends CommonObject
// Initialise parametres // Initialise parametres
$this->id = 0; $this->id = 0;
$this->ref = 'SPECIMEN'; $this->ref = 'SPECIMEN';
$this->ref_client = 'SPECIMEN CLIENT';
$this->specimen = 1; $this->specimen = 1;
$this->socid = 1; $this->socid = 1;
$this->datec = $now; $this->datec = $now;
@ -1377,6 +1395,62 @@ class Fichinter extends CommonObject
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); 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;
}
}
} }
/** /**

View File

@ -58,6 +58,7 @@ $toselect = GETPOST('toselect', 'array');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'interventionlist'; $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'interventionlist';
$search_ref = GETPOST('search_ref') ?GETPOST('search_ref', 'alpha') : GETPOST('search_inter', 'alpha'); $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_company = GETPOST('search_company', 'alpha');
$search_desc = GETPOST('search_desc', 'alpha'); $search_desc = GETPOST('search_desc', 'alpha');
$search_projet_ref = GETPOST('search_projet_ref', '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 // Definition of fields for list
$arrayfields = array( $arrayfields = array(
'f.ref'=>array('label'=>'Ref', 'checked'=>1), 'f.ref'=>array('label'=>'Ref', 'checked'=>1),
'f.ref_client'=>array('label'=>'RefCustomer', 'checked'=>1),
's.nom'=>array('label'=>'ThirdParty', 'checked'=>1), 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
'pr.ref'=>array('label'=>'Project', 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 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)), 'c.ref'=>array('label'=>'Contract', 'checked'=>1, 'enabled'=>(empty($conf->contrat->enabled) ? 0 : 1)),
@ -166,6 +168,7 @@ if (empty($reshook)) {
// Purge search criteria // 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 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 = "";
$search_ref_client = "";
$search_company = ""; $search_company = "";
$search_projet_ref = ""; $search_projet_ref = "";
$search_contrat_ref = ""; $search_contrat_ref = "";
@ -218,7 +221,7 @@ foreach ($arrayfields as $tmpkey => $tmpval) {
} }
$sql = "SELECT"; $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) { if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
$sql .= " fd.rowid as lineid, fd.description as descriptiondetail, fd.date as dp, fd.duree,"; $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) { if ($search_ref) {
$sql .= natural_search('f.ref', $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) { if ($search_company) {
$sql .= natural_search('s.nom', $search_company); $sql .= natural_search('s.nom', $search_company);
} }
@ -351,6 +357,9 @@ if ($resql) {
if ($search_ref) { if ($search_ref) {
$param .= "&search_ref=".urlencode($search_ref); $param .= "&search_ref=".urlencode($search_ref);
} }
if ($search_ref_client) {
$param .= "&search_ref_client=".urlencode($search_ref_client);
}
if ($search_company) { if ($search_company) {
$param .= "&search_company=".urlencode($search_company); $param .= "&search_company=".urlencode($search_company);
} }
@ -447,6 +456,11 @@ if ($resql) {
print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="8">'; print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="8">';
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['f.ref_client']['checked'])) {
print '<td class="liste_titre">';
print '<input type="text" class="flat" name="search_ref_client" value="'.$search_ref_client.'" size="8">';
print '</td>';
}
if (!empty($arrayfields['s.nom']['checked'])) { if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input type="text" class="flat" name="search_company" value="'.$search_company.'" size="10">'; print '<input type="text" class="flat" name="search_company" value="'.$search_company.'" size="10">';
@ -526,6 +540,9 @@ if ($resql) {
if (!empty($arrayfields['f.ref']['checked'])) { if (!empty($arrayfields['f.ref']['checked'])) {
print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); 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'])) { if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder); 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->id = $obj->rowid;
$objectstatic->ref = $obj->ref; $objectstatic->ref = $obj->ref;
$objectstatic->ref_client = $obj->ref_client;
$objectstatic->statut = $obj->status; $objectstatic->statut = $obj->status;
$objectstatic->status = $obj->status; $objectstatic->status = $obj->status;
@ -630,6 +648,15 @@ if ($resql) {
$totalarray['nbfield']++; $totalarray['nbfield']++;
} }
} }
if (!empty($arrayfields['f.ref_client']['checked'])) {
// Customer ref
print '<td class="nowrap tdoverflowmax200">';
print $obj->ref_client;
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['s.nom']['checked'])) { if (!empty($arrayfields['s.nom']['checked'])) {
print '<td>'; print '<td>';
print $companystatic->getNomUrl(1, '', 44); print $companystatic->getNomUrl(1, '', 44);

View File

@ -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_tocc varchar(255);
ALTER TABLE llx_c_email_template ADD COLUMN email_tobcc 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;

View File

@ -25,6 +25,7 @@ create table llx_fichinter
fk_contrat integer DEFAULT 0, -- contrat auquel est rattache la fiche fk_contrat integer DEFAULT 0, -- contrat auquel est rattache la fiche
ref varchar(30) NOT NULL, -- number ref varchar(30) NOT NULL, -- number
ref_ext varchar(255), ref_ext varchar(255),
ref_client varchar(255), -- customer intervention number
entity integer DEFAULT 1 NOT NULL, -- multi company id entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
datec datetime, -- date de creation datec datetime, -- date de creation