Bladeren bron

Merge pull request #20882 from FHenry/dev_new_add_ref_clinet_intervention

NEW: Add Customer Ref on Intervention
Laurent Destailleur 3 jaren geleden
bovenliggende
commit
0f268b682a

+ 1 - 1
htdocs/comm/propal/card.php

@@ -1644,7 +1644,7 @@ if ($action == 'create') {
 
 	// 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 '<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:GETPOST('ref_client')).'"></td>';
 	print '</tr>';
 
 	// Third party

+ 8 - 0
htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php

@@ -612,6 +612,14 @@ class pdf_soleil extends ModelePDFFicheinter
 		$pdf->SetTextColor(0, 0, 60);
 		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
 
+		if (!empty($object->ref_client)) {
+			$posy += 4;
+			$pdf->SetXY($posx, $posy);
+			$pdf->SetTextColor(0, 0, 60);
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer") . " : " . dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
+		}
+
+
 		if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
 			$posy += 4;
 			$pdf->SetXY($posx, $posy);

+ 17 - 3
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 '<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)
 		print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
 		print '<td>';
@@ -1134,10 +1148,10 @@ if ($action == 'create') {
 
 	$morehtmlref = '<div class="refidno">';
 	// 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 .= '<br><span class="hideonsmartphone">'.$langs->trans('ThirdParty').' : </span>'.$object->thirdparty->getNomUrl(1, 'customer');
 	// Project
 	if (!empty($conf->projet->enabled)) {
 		$langs->load("projects");

+ 75 - 1
htdocs/fichinter/class/fichinter.class.php

@@ -44,6 +44,7 @@ class Fichinter extends CommonObject
 	'fk_contrat' =>array('type'=>'integer', 'label'=>'Fk contrat', 'enabled'=>'$conf->contrat->enabled', '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;
@@ -1376,6 +1394,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;
+		}
+	}
 }
 
 /**

+ 28 - 1
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 '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="8">';
 		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'])) {
 		print '<td class="liste_titre">';
 		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'])) {
 		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 '<td class="nowrap tdoverflowmax200">';
+			print $obj->ref_client;
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+		}
 		if (!empty($arrayfields['s.nom']['checked'])) {
 			print '<td>';
 			print $companystatic->getNomUrl(1, '', 44);

+ 2 - 0
htdocs/install/mysql/migration/15.0.0-16.0.0.sql

@@ -374,6 +374,8 @@ 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;
+
 ALTER TABLE llx_c_holiday_types ADD COLUMN sortorder smallint;
 
 ALTER TABLE llx_expedition MODIFY COLUMN ref_customer varchar(255);

+ 1 - 0
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