Przeglądaj źródła

NEW Enhance the import. Can use 'auto' for the ref (import of orders)

Laurent Destailleur 3 lat temu
rodzic
commit
2690f4459f
33 zmienionych plików z 311 dodań i 108 usunięć
  1. 17 1
      htdocs/commande/list.php
  2. 63 0
      htdocs/core/commonfieldsinimport.inc.php
  3. 1 1
      htdocs/core/extrafieldsinexport.inc.php
  4. 75 0
      htdocs/core/extrafieldsinimport.inc.php
  5. 1 1
      htdocs/core/modules/barcode/mod_barcode_product_standard.php
  6. 1 1
      htdocs/core/modules/facture/mod_facture_mars.php
  7. 1 1
      htdocs/core/modules/facture/mod_facture_mercure.php
  8. 3 1
      htdocs/core/modules/facture/mod_facture_terre.php
  9. 3 2
      htdocs/core/modules/facture/modules_facture.php
  10. 4 2
      htdocs/core/modules/fichinter/modules_fichinter.php
  11. 3 3
      htdocs/core/modules/holiday/mod_holiday_immaculate.php
  12. 3 3
      htdocs/core/modules/holiday/modules_holiday.php
  13. 23 4
      htdocs/core/modules/import/import_csv.modules.php
  14. 25 6
      htdocs/core/modules/import/import_xlsx.modules.php
  15. 23 31
      htdocs/core/modules/modCommande.class.php
  16. 1 1
      htdocs/core/modules/product_batch/mod_lot_advanced.php
  17. 3 3
      htdocs/core/modules/product_batch/mod_lot_free.php
  18. 2 2
      htdocs/core/modules/product_batch/mod_lot_standard.php
  19. 2 2
      htdocs/core/modules/product_batch/mod_sn_advanced.php
  20. 3 3
      htdocs/core/modules/product_batch/mod_sn_free.php
  21. 1 1
      htdocs/core/modules/product_batch/mod_sn_standard.php
  22. 2 2
      htdocs/core/modules/reception/mod_reception_beryl.php
  23. 2 2
      htdocs/core/modules/reception/modules_reception.php
  24. 1 1
      htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php
  25. 4 2
      htdocs/core/modules/supplier_order/modules_commandefournisseur.php
  26. 3 3
      htdocs/core/modules/supplier_proposal/mod_supplier_proposal_marbre.php
  27. 3 3
      htdocs/core/modules/supplier_proposal/mod_supplier_proposal_saphir.php
  28. 4 4
      htdocs/core/modules/supplier_proposal/modules_supplier_proposal.php
  29. 1 1
      htdocs/core/modules/takepos/mod_takepos_ref_universal.php
  30. 5 2
      htdocs/core/modules/takepos/modules_takepos.php
  31. 4 4
      htdocs/core/modules/ticket/modules_ticket.php
  32. 1 1
      htdocs/modulebuilder/template/class/myobject.class.php
  33. 23 14
      htdocs/modulebuilder/template/core/modules/modMyModule.class.php

+ 17 - 1
htdocs/commande/list.php

@@ -201,6 +201,7 @@ $arrayfields = array(
 	'c.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES)), 'position'=>140),
 	'shippable'=>array('label'=>"Shippable", 'checked'=>1,'enabled'=>(!empty($conf->expedition->enabled)), 'position'=>990),
 	'c.facture'=>array('label'=>"Billed", 'checked'=>1, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)), 'position'=>995),
+	'c.import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>999),
 	'c.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
 );
 // Extra fields
@@ -441,7 +442,7 @@ $sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture
 $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
 $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,';
 $sql .= ' c.fk_cond_reglement,c.fk_mode_reglement,c.fk_shipping_method,';
-$sql .= ' c.fk_input_reason';
+$sql .= ' c.fk_input_reason, c.import_key';
 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
 	$sql .= ", cc.fk_categorie, cc.fk_soc";
 }
@@ -1275,6 +1276,11 @@ if ($resql) {
 		print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
 		print '</td>';
 	}
+	// Import key
+	if (!empty($arrayfields['c.import_key']['checked'])) {
+		print '<td class="liste_titre maxwidthonsmartphone" align="center">';
+		print '</td>';
+	}
 	// Status
 	if (!empty($arrayfields['c.fk_statut']['checked'])) {
 		print '<td class="liste_titre maxwidthonsmartphone center">';
@@ -1436,6 +1442,9 @@ if ($resql) {
 	if (!empty($arrayfields['c.facture']['checked'])) {
 		print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
 	}
+	if (!empty($arrayfields['c.import_key']['checked'])) {
+		print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
+	}
 	if (!empty($arrayfields['c.fk_statut']['checked'])) {
 		print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
 	}
@@ -2063,6 +2072,13 @@ if ($resql) {
 				$totalarray['nbfield']++;
 			}
 		}
+		// Import key
+		if (!empty($arrayfields['c.import_key']['checked'])) {
+			print '<td class="nowrap center">'.$obj->import_key.'</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+		}
 		// Status
 		if (!empty($arrayfields['c.fk_statut']['checked'])) {
 			print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';

+ 63 - 0
htdocs/core/commonfieldsinimport.inc.php

@@ -0,0 +1,63 @@
+<?php
+
+if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement)) {
+	//print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
+	dol_print_error('', 'include of file commonfieldsinimport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set');
+	exit;
+}
+if (empty($keyforalias)) {
+	$keyforalias = 't';
+}
+
+dol_include_once($keyforclassfile);
+if (class_exists($keyforclass)) {
+	$tmpobject = new $keyforclass($this->db);
+
+	// Add common fields
+	foreach ($tmpobject->fields as $keyfield => $valuefield) {
+		$fieldname = $keyforalias.'.'.$keyfield;
+		$fieldlabel = ucfirst($valuefield['label']);
+		$typeFilter = "Text";
+		$typefield = preg_replace('/\(.*$/', '', $valuefield['type']); // double(24,8) -> double
+		switch ($typefield) {
+			case 'int':
+			case 'integer':
+			case 'double':
+			case 'price':
+				$typeFilter = "Numeric";
+				break;
+			case 'date':
+			case 'datetime':
+			case 'timestamp':
+				$typeFilter = "Date";
+				break;
+			case 'boolean':
+				$typeFilter = "Boolean";
+				break;
+			/*
+			 * case 'sellist':
+			 * $tmp='';
+			 * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
+			 * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
+			 * $tmpkeys=array_keys($tmpparam['options']);
+			 * $tmp=array_shift($tmpkeys);
+			 * }
+			 * if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
+			 * break;
+			 */
+		}
+		$helpfield = '';
+		if (!empty($valuefield['help'])) {
+			$helpfield = preg_replace('/\(.*$/', '', $valuefield['help']);
+		}
+		if ($valuefield['enabled']) {
+			$this->import_fields_array[$r][$fieldname] = $fieldlabel;
+			$this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
+			$this->import_entities_array[$r][$fieldname] = $keyforelement;
+			$this->import_help_array[$r][$fieldname] = $helpfield;
+		}
+	}
+} else {
+	dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
+}
+// End add common fields

+ 1 - 1
htdocs/core/extrafieldsinexport.inc.php

@@ -12,7 +12,7 @@ if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra)) {
 
 // Add extra fields
 $sql = "SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields";
-$sql .= " WHERE elementtype = '".$this->db->escape($keyforselect)."' AND type != 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC';
+$sql .= " WHERE elementtype = '".$this->db->escape($keyforselect)."' AND type <> 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC';
 //print $sql;
 $resql = $this->db->query($sql);
 if ($resql) {    // This can fail when class is used on old database (during migration for example)

+ 75 - 0
htdocs/core/extrafieldsinimport.inc.php

@@ -0,0 +1,75 @@
+<?php
+
+// $keyforselect = name of main table
+// keyforelement = name of picto
+// $keyforaliasextra = a key to avoid conflict with extrafields of other objects
+
+if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra)) {
+	//print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
+	dol_print_error('', 'include of file extrafieldsinimport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set');
+	exit;
+}
+
+// Add extra fields
+$sql = "SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields";
+$sql .= " WHERE elementtype = '".$this->db->escape($keyforselect)."' AND type <> 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC';
+//print $sql;
+$resql = $this->db->query($sql);
+if ($resql) {    // This can fail when class is used on old database (during migration for example)
+	while ($obj = $this->db->fetch_object($resql)) {
+		$fieldname = $keyforaliasextra.'.'.$obj->name;
+		$fieldlabel = ucfirst($obj->label);
+		$typeFilter = "Text";
+		$typefield = preg_replace('/\(.*$/', '', $obj->type); // double(24,8) -> double
+		switch ($typefield) {
+			case 'int':
+			case 'integer':
+			case 'double':
+			case 'price':
+				$typeFilter = "Numeric";
+				break;
+			case 'date':
+			case 'datetime':
+			case 'timestamp':
+				$typeFilter = "Date";
+				break;
+			case 'boolean':
+				$typeFilter = "Boolean";
+				break;
+			case 'checkbox':
+			case 'select':
+				if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) {
+					$tmpparam = jsonOrUnserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...)
+					if ($tmpparam['options'] && is_array($tmpparam['options'])) {
+						$typeFilter = "Select:".$obj->param;
+					}
+				}
+				break;
+			case 'sellist':
+				$tmp = '';
+				$tmpparam = jsonOrUnserialize($obj->param); // $tmp may be array 'options' => array 'c_currencies:code_iso:code_iso' => null
+				if (is_array($tmpparam) && array_key_exists('options', $tmpparam) &&  $tmpparam['options'] && is_array($tmpparam['options'])) {
+					$tmpkeys = array_keys($tmpparam['options']);
+					$tmp = array_shift($tmpkeys);
+				}
+				if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
+					$typeFilter = "List:".$tmp;
+				}
+				break;
+		}
+		if ($obj->type != 'separate') {
+			// If not a computed field
+			if (empty($obj->fieldcomputed)) {
+				$this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
+				$this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
+				$this->import_entities_array[$r][$fieldname] = $keyforelement;
+			} else {
+				// If this is a computed field
+				$this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
+				$this->import_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute';
+				$this->import_entities_array[$r][$fieldname] = $keyforelement;
+			}
+		}
+	}
+}
+// End add axtra fields

+ 1 - 1
htdocs/core/modules/barcode/mod_barcode_product_standard.php

@@ -176,7 +176,7 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
 	 * @param	string		$type       	Type of barcode (EAN, ISBN, ...)
 	 * @return 	string      				Value if OK, '' if module not configured, <0 if KO
 	 */
-	public function getNextValue($objproduct = null, $type = '')
+	public function getNextValue($objproduct, $type = '')
 	{
 		global $db, $conf;
 

+ 1 - 1
htdocs/core/modules/facture/mod_facture_mars.php

@@ -150,7 +150,7 @@ class mod_facture_mars extends ModeleNumRefFactures
 	 * @param	Societe		$objsoc		Object third party
 	 * @param   Facture		$invoice	Object invoice
 	 * @param   string		$mode       'next' for next value or 'last' for last value
-	 * @return  string       			Value
+	 * @return  string       			Value if OK, 0 if KO
 	 */
 	public function getNextValue($objsoc, $invoice, $mode = 'next')
 	{

+ 1 - 1
htdocs/core/modules/facture/mod_facture_mercure.php

@@ -171,7 +171,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
 			$this->error = $numFinal;
 		}
 
-		return  $numFinal;
+		return $numFinal;
 	}
 
 

+ 3 - 1
htdocs/core/modules/facture/mod_facture_terre.php

@@ -185,7 +185,7 @@ class mod_facture_terre extends ModeleNumRefFactures
 	 * @param   Societe		$objsoc		Object third party
 	 * @param   Facture		$invoice	Object invoice
 	 * @param   string		$mode       'next' for next value or 'last' for last value
-	 * @return  string       			Next ref value or last ref if $mode is 'last'
+	 * @return  string       			Next ref value or last ref if $mode is 'last', <= 0 if KO
 	 */
 	public function getNextValue($objsoc, $invoice, $mode = 'next')
 	{
@@ -259,6 +259,8 @@ class mod_facture_terre extends ModeleNumRefFactures
 		} else {
 			dol_print_error('', 'Bad parameter for getNextValue');
 		}
+
+		return 0;
 	}
 
 	/**

+ 3 - 2
htdocs/core/modules/facture/modules_facture.php

@@ -132,10 +132,11 @@ abstract class ModeleNumRefFactures
 	 * Renvoi prochaine valeur attribuee
 	 *
 	 * @param	Societe		$objsoc		Objet societe
-	 * @param   Facture		$facture	Objet facture
+	 * @param   Facture		$invoice	Objet facture
+	 * @param   string		$mode       'next' for next value or 'last' for last value
 	 * @return  string      			Value
 	 */
-	public function getNextValue($objsoc, $facture)
+	public function getNextValue($objsoc, $invoice, $mode = 'next')
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 4 - 2
htdocs/core/modules/fichinter/modules_fichinter.php

@@ -122,9 +122,11 @@ abstract class ModeleNumRefFicheinter
 	/**
 	 * 	Return the next assigned value
 	 *
-	 * 	@return     string      Value
+	 *  @param	Societe		$objsoc     Object thirdparty
+	 *  @param  Object		$object		Object we need next value for
+	 *  @return string      			Value if KO, <0 if KO
 	 */
-	public function getNextValue()
+	public function getNextValue($objsoc = 0, $object = '')
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 3 - 3
htdocs/core/modules/holiday/mod_holiday_immaculate.php

@@ -117,11 +117,11 @@ class mod_holiday_immaculate extends ModelNumRefHolidays
 	/**
 	 *	Return next value
 	 *
-	 *	@param	Societe		$user     	user object
+	 *	@param	Societe		$objsoc     third party object
 	 *	@param	Object		$holiday	holiday object
 	 *	@return string      			Value if OK, 0 if KO
 	 */
-	public function getNextValue($user, $holiday)
+	public function getNextValue($objsoc, $holiday)
 	{
 		global $db, $conf;
 
@@ -134,7 +134,7 @@ class mod_holiday_immaculate extends ModelNumRefHolidays
 			return 0;
 		}
 
-		$numFinal = get_next_value($db, $mask, 'holiday', 'ref', '', $user, $holiday->date_create);
+		$numFinal = get_next_value($db, $mask, 'holiday', 'ref', '', $objsoc, $holiday->date_create);
 
 		return  $numFinal;
 	}

+ 3 - 3
htdocs/core/modules/holiday/modules_holiday.php

@@ -126,10 +126,10 @@ class ModelNumRefHolidays
 	 *	Return next value
 	 *
 	 *	@param	Societe		$objsoc     third party object
-	 *	@param	Object		$contract	contract object
-	 *	@return	string					Value
+	 *	@param	Object		$holiday	Holiday object
+	 *	@return	string					Value if OK, 0 if KO
 	 */
-	public function getNextValue($objsoc, $contract)
+	public function getNextValue($objsoc, $holiday)
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 23 - 4
htdocs/core/modules/import/import_csv.modules.php

@@ -324,7 +324,8 @@ class ImportCsv extends ModeleImports
 		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
 
 		//var_dump($array_match_file_to_database);
-		//var_dump($arrayrecord);
+		//var_dump($arrayrecord); exit;
+
 		$array_match_database_to_file = array_flip($array_match_file_to_database);
 		$sort_array_match_file_to_database = $array_match_file_to_database;
 		ksort($sort_array_match_file_to_database);
@@ -367,12 +368,15 @@ class ImportCsv extends ModeleImports
 					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
 				}
 
-				// array of fields to column index
+				// Define array to convert fields ('c.ref', ...) into column index (1, ...)
 				$arrayfield = array();
 				foreach ($sort_array_match_file_to_database as $key => $val) {
 					$arrayfield[$val] = ($key - 1);
 				}
 
+				// $arrayrecord start at key 0
+				// $sort_array_match_file_to_database start at key 1
+
 				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
 				foreach ($sort_array_match_file_to_database as $key => $val) {
 					$fieldalias = preg_replace('/\..*$/i', '', $val);
@@ -595,9 +599,24 @@ class ImportCsv extends ModeleImports
 										if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
 											require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
 											$modForNumber = new $classModForNumber;
-											$defaultref = $modForNumber->getNextValue(null, null);
+
+											$tmpobject = null;
+											// Set the object when we can
+											if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) {
+												$pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject'];
+												require_once DOL_DOCUMENT_ROOT.$pathForObject;
+												$tmpclassobject = $objimport->array_import_convertvalue[0][$val]['classobject'];
+												$tmpobject = new $tmpclassobject($this->db);
+												foreach ($arrayfield as $tmpkey => $tmpval) {	// $arrayfield is array('c.ref'=>0, ...)
+													if (in_array($tmpkey, array('t.date', 'c.date_commande'))) {
+														$tmpobject->date = dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]]['val'], 1);
+													}
+												}
+											}
+
+											$defaultref = $modForNumber->getNextValue(null, $tmpobject);
 										}
-										if (is_numeric($defaultref) && $defaultref <= 0) {
+										if (is_numeric($defaultref) && $defaultref <= 0) {	// If error
 											$defaultref = '';
 										}
 										$newval = $defaultref;

+ 25 - 6
htdocs/core/modules/import/import_xlsx.modules.php

@@ -367,7 +367,8 @@ class ImportXlsx extends ModeleImports
 		//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
 
 		//var_dump($array_match_file_to_database);
-		//var_dump($arrayrecord);
+		//var_dump($arrayrecord); exit;
+
 		$array_match_database_to_file = array_flip($array_match_file_to_database);
 		$sort_array_match_file_to_database = $array_match_file_to_database;
 		ksort($sort_array_match_file_to_database);
@@ -410,12 +411,15 @@ class ImportXlsx extends ModeleImports
 					//dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]);
 				}
 
-				// array of fields to column index
+				// Define array to convert fields ('c.ref', ...) into column index (1, ...)
 				$arrayfield = array();
 				foreach ($sort_array_match_file_to_database as $key => $val) {
-					$arrayfield[$val] = ($key - 1);
+					$arrayfield[$val] = ($key);
 				}
 
+				// $arrayrecord start at key 1
+				// $sort_array_match_file_to_database start at key 1
+
 				// Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom)
 				foreach ($sort_array_match_file_to_database as $key => $val) {
 					$fieldalias = preg_replace('/\..*$/i', '', $val);
@@ -619,7 +623,7 @@ class ImportXlsx extends ModeleImports
 										$this->thirpartyobject->get_codecompta('supplier');
 										$newval = $this->thirpartyobject->code_compta_fournisseur;
 										if (empty($newval)) {
-											$arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null"
+											$arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null"
 										}
 										//print 'code_compta_fournisseur='.$newval;
 									}
@@ -636,9 +640,24 @@ class ImportXlsx extends ModeleImports
 										if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
 											require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
 											$modForNumber = new $classModForNumber;
-											$defaultref = $modForNumber->getNextValue(null, null);
+
+											$tmpobject = null;
+											// Set the object with the date property when we can
+											if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) {
+												$pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject'];
+												require_once DOL_DOCUMENT_ROOT.$pathForObject;
+												$tmpclassobject = $objimport->array_import_convertvalue[0][$val]['classobject'];
+												$tmpobject = new $tmpclassobject($this->db);
+												foreach ($arrayfield as $tmpkey => $tmpval) {	// $arrayfield is array('c.ref'=>1, ...)
+													if (in_array($tmpkey, array('t.date', 'c.date_commande'))) {
+														$tmpobject->date = dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]]['val'], 1);
+													}
+												}
+											}
+
+											$defaultref = $modForNumber->getNextValue(null, $tmpobject);
 										}
-										if (is_numeric($defaultref) && $defaultref <= 0) {
+										if (is_numeric($defaultref) && $defaultref <= 0) {	// If error
 											$defaultref = '';
 										}
 										$newval = $defaultref;

+ 23 - 31
htdocs/core/modules/modCommande.class.php

@@ -296,18 +296,18 @@ class modCommande extends DolibarrModules
 		$this->import_entities_array[$r] = array();
 		$this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande', 'extra' => MAIN_DB_PREFIX.'commande_extrafields');
 		$this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
+		$import_sample = array();
 		$this->import_fields_array[$r] = array(
 			'c.ref'               => 'Ref*',
 			'c.ref_client'        => 'RefCustomer',
 			'c.fk_soc'            => 'ThirdPartyName*',
 			'c.fk_projet'         => 'ProjectId',
 			'c.date_creation'     => 'DateCreation',
-			'c.date_valid'        => 'DateValid',
-			'c.date_commande'     => 'DateOrder',
+			'c.date_valid'        => 'DateValidation',
+			'c.date_commande'     => 'OrderDate*',
 			'c.fk_user_modif'     => 'ModifiedById',
 			'c.fk_user_valid'     => 'ValidatedById',
-			'c.fk_statut'         => 'Status*',
-			'c.remise_percent'    => 'GlobalDiscount',
+			//'c.remise_percent'    => 'GlobalDiscount',
 			'c.total_tva'         => 'TotalTVA',
 			'c.total_ht'          => 'TotalHT',
 			'c.total_ttc'         => 'TotalTTC',
@@ -317,7 +317,8 @@ class modCommande extends DolibarrModules
 			'c.date_livraison'    => 'DeliveryDate',
 			'c.fk_cond_reglement' => 'Payment Condition',
 			'c.fk_mode_reglement' => 'Payment Mode',
-			'c.model_pdf'         => 'Model'
+			'c.model_pdf'         => 'Model',
+			'c.fk_statut'         => 'Status*'
 		);
 
 		if (!empty($conf->multicurrency->enabled)) {
@@ -327,29 +328,26 @@ class modCommande extends DolibarrModules
 			$this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
 			$this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
 		}
-
-		// Add extra fields
 		$import_extrafield_sample = array();
-		$sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande' AND entity IN (0, ".$conf->entity.")";
-		$resql = $this->db->query($sql);
-
-		if ($resql) {
-			while ($obj = $this->db->fetch_object($resql)) {
-				$fieldname = 'extra.'.$obj->name;
-				$fieldlabel = ucfirst($obj->label);
-				$this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
-				$import_extrafield_sample[$fieldname] = $fieldlabel;
-			}
-		}
-		// End add extra fields
+		$keyforselect = 'commande';
+		$keyforelement = 'order';
+		$keyforaliasextra = 'extra';
+		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
 
 		$this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande');
 		$this->import_regex_array[$r] = array(
 			'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
 		);
-
+		$this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
 		$this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
 		$this->import_convertvalue_array[$r] = array(
+			'c.ref' => array(
+				'rule'=>'getrefifauto',
+				'class'=>(empty($conf->global->COMMANDE_ADDON) ? 'mod_commande_marbre' : $conf->global->COMMANDE_ADDON),
+				'path'=>"/core/modules/commande/".(empty($conf->global->COMMANDE_ADDON) ? 'mod_commande_marbre' : $conf->global->COMMANDE_ADDON).'.php',
+				'classobject'=>'Commande',
+				'pathobject'=>'/commande/class/commande.class.php',
+			),
 			'c.fk_soc' => array(
 				'rule'    => 'fetchidfromref',
 				'file'    => '/societe/class/societe.class.php',
@@ -410,17 +408,11 @@ class modCommande extends DolibarrModules
 			$this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
 		}
 
-		// Add extra fields
-		$sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commandedet' AND entity IN (0, ".$conf->entity.")";
-		$resql = $this->db->query($sql);
-		if ($resql) {
-			while ($obj = $this->db->fetch_object($resql)) {
-				$fieldname = 'extra.'.$obj->name;
-				$fieldlabel = ucfirst($obj->label);
-				$this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
-			}
-		}
-		// End add extra fields
+		$import_extrafield_sample = array();
+		$keyforselect = 'commandedet';
+		$keyforelement = 'orderline';
+		$keyforaliasextra = 'extra';
+		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
 
 		$this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commandedet'];
 		$this->import_regex_array[$r] = [

+ 1 - 1
htdocs/core/modules/product_batch/mod_lot_advanced.php

@@ -128,7 +128,7 @@ class mod_lot_advanced extends ModeleNumRefBatch
 	/**
 	 * 	Return next free value
 	 *
-	 *  @param	Societe		$objsoc	    Object Societe
+	 *  @param	Societe		$objsoc	    Object thirdparty
 	 *  @param  Object		$object		Object we need next value for
 	 *  @return string      			Value if KO, <0 if KO
 	 */

+ 3 - 3
htdocs/core/modules/product_batch/mod_lot_free.php

@@ -93,11 +93,11 @@ class mod_lot_free extends ModeleNumRefBatch
 	/**
 	 * Return an example of result returned by getNextValue
 	 *
-	 * @param	product		$objproduct		Object product
-	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
+	 * @param	Societe		$objsoc	    Object thirdparty
+	 * @param   Object		$object		Object we need next value for
 	 * @return	string					Return next value
 	 */
-	public function getNextValue($objproduct = 0, $type = -1)
+	public function getNextValue($objsoc, $object)
 	{
 		global $langs;
 		return '';

+ 2 - 2
htdocs/core/modules/product_batch/mod_lot_standard.php

@@ -111,11 +111,11 @@ class mod_lot_standard extends ModeleNumRefBatch
 	/**
 	 * 	Return next free value
 	 *
-	 *  @param	Product		$objprod    Object product
+	 *  @param	Societe		$objsoc	    Object thirdparty
 	 *  @param  Object		$object		Object we need next value for
 	 *  @return string      			Value if KO, <0 if KO
 	 */
-	public function getNextValue($objprod, $object)
+	public function getNextValue($objsoc, $object)
 	{
 		global $db, $conf;
 

+ 2 - 2
htdocs/core/modules/product_batch/mod_sn_advanced.php

@@ -128,11 +128,11 @@ class mod_sn_advanced extends ModeleNumRefBatch
 	/**
 	 * 	Return next free value
 	 *
-	 *  @param	Product		$objprod    Object product
+	 *  @param	Societe		$objsoc	    Object thirdparty
 	 *  @param  Object		$object		Object we need next value for
 	 *  @return string      			Value if KO, <0 if KO
 	 */
-	public function getNextValue($objprod, $object)
+	public function getNextValue($objsoc, $object)
 	{
 		global $db, $conf;
 

+ 3 - 3
htdocs/core/modules/product_batch/mod_sn_free.php

@@ -92,11 +92,11 @@ class mod_sn_free extends ModeleNumRefBatch
 	/**
 	 * Return an example of result returned by getNextValue
 	 *
-	 * @param	product		$objproduct		Object product
-	 * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
+	 * @param	Societe		$objsoc	    Object thirdparty
+	 * @param   Object		$object		Object we need next value for
 	 * @return	string					Return next value
 	 */
-	public function getNextValue($objproduct = 0, $type = -1)
+	public function getNextValue($objsoc, $object)
 	{
 		global $langs;
 		return '';

+ 1 - 1
htdocs/core/modules/product_batch/mod_sn_standard.php

@@ -111,7 +111,7 @@ class mod_sn_standard extends ModeleNumRefBatch
 	/**
 	 * 	Return next free value
 	 *
-	 *  @param	Societe		$objsoc     Object product
+	 *  @param	Societe		$objsoc     Object thirdparty
 	 *  @param  Object		$object		Object we need next value for
 	 *  @return string      			Value if KO, <0 if KO
 	 */

+ 2 - 2
htdocs/core/modules/reception/mod_reception_beryl.php

@@ -96,10 +96,10 @@ class mod_reception_beryl extends ModelNumRefReception
 	 *	Return next value
 	 *
 	 *	@param	Societe		$objsoc     Third party object
-	 *	@param	Object		$shipment	Shipment object
+	 *	@param	Object		$reception	Reception object
 	 *	@return string      			Value if OK, 0 if KO
 	 */
-	public function getNextValue($objsoc, $shipment)
+	public function getNextValue($objsoc, $reception)
 	{
 		global $db, $conf;
 

+ 2 - 2
htdocs/core/modules/reception/modules_reception.php

@@ -110,10 +110,10 @@ abstract class ModelNumRefReception
 	 *	Returns next value assigned
 	 *
 	 *	@param	Societe		$objsoc     Third party object
-	 *	@param	Object		$shipment	Shipment object
+	 *	@param	Object		$reception	Reception object
 	 *	@return	string					Value
 	 */
-	public function getNextValue($objsoc, $shipment)
+	public function getNextValue($objsoc, $reception)
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 1 - 1
htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php

@@ -120,7 +120,7 @@ abstract class ModeleNumRefSuppliersInvoices
 	 * @param	string		$mode       'next' for next value or 'last' for last value
 	 * @return 	string      			Value if OK, 0 if KO
 	 */
-	public function getNextValue($objsoc, $object, $mode)
+	public function getNextValue($objsoc, $object, $mode = 'next')
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 4 - 2
htdocs/core/modules/supplier_order/modules_commandefournisseur.php

@@ -120,9 +120,11 @@ abstract class ModeleNumRefSuppliersOrders
 
 	/**  Returns next value assigned
 	 *
-	 *   @return     string      Valeur
+	 *  @param	Societe		$objsoc     Object third party
+	 *  @param  Object	    $object		Object
+	 *  @return string      			Valeur
 	 */
-	public function getNextValue()
+	public function getNextValue($objsoc = 0, $object = '')
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 3 - 3
htdocs/core/modules/supplier_proposal/mod_supplier_proposal_marbre.php

@@ -120,9 +120,9 @@ class mod_supplier_proposal_marbre extends ModeleNumRefSupplierProposal
 	/**
 	 *  Return next value
 	 *
-	 *  @param	Societe		$objsoc     Object third party
-	 * 	@param	Propal		$supplier_proposal		Object commercial proposal
-	 *  @return string      			Next value
+	 *  @param	Societe				$objsoc     			Object third party
+	 * 	@param	SupplierProposal	$supplier_proposal		Object commercial proposal
+	 *  @return string      								Next value
 	 */
 	public function getNextValue($objsoc, $supplier_proposal)
 	{

+ 3 - 3
htdocs/core/modules/supplier_proposal/mod_supplier_proposal_saphir.php

@@ -120,9 +120,9 @@ class mod_supplier_proposal_saphir extends ModeleNumRefSupplierProposal
 	/**
 	 *  Return next value
 	 *
-	 *  @param	Societe		$objsoc     		Object third party
-	 * 	@param	Propal		$supplier_proposal	Object supplier_proposal
-	 *  @return string      					Value if OK, 0 if KO
+	 *  @param	Societe				$objsoc     			Object third party
+	 * 	@param	SupplierProposal	$supplier_proposal		Object commercial proposal
+	 *  @return string      								Value if OK, 0 if KO
 	 */
 	public function getNextValue($objsoc, $supplier_proposal)
 	{

+ 4 - 4
htdocs/core/modules/supplier_proposal/modules_supplier_proposal.php

@@ -124,11 +124,11 @@ abstract class ModeleNumRefSupplierProposal
 	/**
 	 * 	Renvoi prochaine valeur attribuee
 	 *
-	 *	@param		Societe		$objsoc     Object third party
-	 *	@param		Propal		$propal		Object commercial proposal
-	 *	@return     string      Valeur
+	 *	@param	Societe				$objsoc     			Object third party
+	 * 	@param	SupplierProposal	$supplier_proposal		Object commercial proposal
+	 *	@return string      								Valeur
 	 */
-	public function getNextValue($objsoc, $propal)
+	public function getNextValue($objsoc, $supplier_proposal)
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 1 - 1
htdocs/core/modules/takepos/mod_takepos_ref_universal.php

@@ -119,7 +119,7 @@ class mod_takepos_ref_universal extends ModeleNumRefTakepos
 	 * @param   string		$mode       'next' for next value or 'last' for last value
 	 * @return  string      Value if KO, <0 if KO
 	 */
-	public function getNextValue($objsoc = 0, $invoice = null, $mode = 'next')
+	public function getNextValue($objsoc = null, $invoice = null, $mode = 'next')
 	{
 		global $db, $conf;
 

+ 5 - 2
htdocs/core/modules/takepos/modules_takepos.php

@@ -89,9 +89,12 @@ abstract class ModeleNumRefTakepos
 	/**
 	 * Renvoi prochaine valeur attribuee
 	 *
-	 * @return     string      Valeur
+	 * @param   Societe     $objsoc     Object thirdparty
+	 * @param   Facture		$invoice	Object invoice
+	 * @param   string		$mode       'next' for next value or 'last' for last value
+	 * @return  string      Value if KO, <0 if KO
 	 */
-	public function getNextValue()
+	public function getNextValue($objsoc = null, $invoice = null, $mode = 'next')
 	{
 		global $langs;
 		return $langs->trans('NotAvailable');

+ 4 - 4
htdocs/core/modules/ticket/modules_ticket.php

@@ -115,11 +115,11 @@ abstract class ModeleNumRefTicket
 	/**
 	 *  Renvoi prochaine valeur attribuee
 	 *
-	 *    @param  Societe $objsoc  Object third party
-	 *    @param  Project $project Object project
-	 *    @return string                    Valeur
+	 *    @param  Societe 	$objsoc  	Object third party
+	 *    @param  Ticket 	$ticket		Object ticket
+	 *    @return string                Valeur
 	 */
-	public function getNextValue($objsoc, $project)
+	public function getNextValue($objsoc, $ticket)
 	{
 		global $langs;
 		return $langs->trans("NotAvailable");

+ 1 - 1
htdocs/modulebuilder/template/class/myobject.class.php

@@ -122,7 +122,7 @@ class MyObject extends CommonObject
 		'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>1, 'visible'=>0, 'notnull'=>0, 'position'=>600),
 		'import_key'    => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
 		'model_pdf' 	=> array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'notnull'=>-1, 'position'=>1010),
-		'status'        => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled'), 'validate'=>1),
+		'status'        => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>2000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled'), 'validate'=>1),
 	);
 
 	/**

+ 23 - 14
htdocs/modulebuilder/template/core/modules/modMyModule.class.php

@@ -382,20 +382,29 @@ class modMyModule extends DolibarrModules
 		$r = 1;
 		/* BEGIN MODULEBUILDER IMPORT MYOBJECT */
 		/*
-		 $langs->load("mymodule@mymodule");
-		 $this->export_code[$r]=$this->rights_class.'_'.$r;
-		 $this->export_label[$r]='MyObjectLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
-		 $this->export_icon[$r]='myobject@mymodule';
-		 $keyforclass = 'MyObject'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobject@mymodule';
-		 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
-		 $keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule';
-		 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
-		 //$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
-		 $this->export_sql_start[$r]='SELECT DISTINCT ';
-		 $this->export_sql_end[$r]  =' FROM '.MAIN_DB_PREFIX.'myobject as t';
-		 $this->export_sql_end[$r] .=' WHERE 1 = 1';
-		 $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('myobject').')';
-		 $r++; */
+		$langs->load("mymodule@mymodule");
+		$this->import_code[$r]=$this->rights_class.'_'.$r;
+		$this->import_label[$r]='MyObjectLines';	// Translation key (used only if key ExportDataset_xxx_z not found)
+		$this->import_icon[$r]='myobject@mymodule';
+		$this->import_tables_array[$r] = array('t' => MAIN_DB_PREFIX.'mymodule_myobject', 'extra' => MAIN_DB_PREFIX.'mymodule_myobject_extrafields');
+		$this->import_tables_creator_array[$r] = array('t' => 'fk_user_author'); // Fields to store import user id
+		$import_sample = array();
+		$keyforclass = 'MyObject'; $keyforclassfile='/mymodule/class/myobject.class.php'; $keyforelement='myobject@mymodule';
+		include DOL_DOCUMENT_ROOT.'/core/commonfieldsinimport.inc.php';
+		$import_extrafield_sample = array();
+		$keyforselect='myobject'; $keyforaliasextra='extra'; $keyforelement='myobject@mymodule';
+		include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
+		$this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'mymodule_myobject');
+		$this->import_regex_array[$r] = array();
+		$this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
+		$this->import_updatekeys_array[$r] = array('t.ref' => 'Ref');
+		$this->import_convertvalue_array[$r] = array(
+			't.ref' => array('rule'=>'getrefifauto', 'class'=>(empty($conf->global->MYMODULE_MYOBJECT_ADDON) ? 'mod_myobject_standard' : $conf->global->MYMODULE_MYOBJECT_ADDON), 'path'=>"/core/modules/commande/".(empty($conf->global->MYMODULE_MYOBJECT_ADDON) ? 'mod_myobject_standard' : $conf->global->MYMODULE_MYOBJECT_ADDON).'.php'),
+			't.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
+			't.fk_user_valid' => array('rule' => 'fetchidfromref', 'file' => '/user/class/user.class.php', 'class' => 'User', 'method' => 'fetch', 'element' => 'user'),
+			't.fk_mode_reglement' => array('rule' => 'fetchidfromcodeorlabel', 'file' => '/compta/paiement/class/cpaiement.class.php', 'class' => 'Cpaiement', 'method' => 'fetch', 'element' => 'cpayment'),
+		);
+		$r++; */
 		/* END MODULEBUILDER IMPORT MYOBJECT */
 	}