diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index fcbd00fe945..52071b672fe 100644
--- a/htdocs/commande/list.php
+++ b/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 '';
}
+ // Import key
+ if (!empty($arrayfields['c.import_key']['checked'])) {
+ print '
';
+ print ' | ';
+ }
// Status
if (!empty($arrayfields['c.fk_statut']['checked'])) {
print '';
@@ -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 ' | '.$obj->import_key.' | ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
// Status
if (!empty($arrayfields['c.fk_statut']['checked'])) {
print ''.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).' | ';
diff --git a/htdocs/core/commonfieldsinimport.inc.php b/htdocs/core/commonfieldsinimport.inc.php
new file mode 100644
index 00000000000..60716b8b109
--- /dev/null
+++ b/htdocs/core/commonfieldsinimport.inc.php
@@ -0,0 +1,63 @@
+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
diff --git a/htdocs/core/extrafieldsinexport.inc.php b/htdocs/core/extrafieldsinexport.inc.php
index fc2210eabd8..4962e353741 100644
--- a/htdocs/core/extrafieldsinexport.inc.php
+++ b/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)
diff --git a/htdocs/core/extrafieldsinimport.inc.php b/htdocs/core/extrafieldsinimport.inc.php
new file mode 100644
index 00000000000..bbfcd7b9fdb
--- /dev/null
+++ b/htdocs/core/extrafieldsinimport.inc.php
@@ -0,0 +1,75 @@
+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
diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php
index c101001af4c..17b5a9bb16a 100644
--- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php
+++ b/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;
diff --git a/htdocs/core/modules/facture/mod_facture_mars.php b/htdocs/core/modules/facture/mod_facture_mars.php
index c7a69a82caa..ef34b145e52 100644
--- a/htdocs/core/modules/facture/mod_facture_mars.php
+++ b/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')
{
diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php
index 621bb8e6d2d..7a572615a21 100644
--- a/htdocs/core/modules/facture/mod_facture_mercure.php
+++ b/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;
}
diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php
index 55f6dd816d1..9660be93266 100644
--- a/htdocs/core/modules/facture/mod_facture_terre.php
+++ b/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;
}
/**
diff --git a/htdocs/core/modules/facture/modules_facture.php b/htdocs/core/modules/facture/modules_facture.php
index e188f66b1ad..480c532cc1f 100644
--- a/htdocs/core/modules/facture/modules_facture.php
+++ b/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");
diff --git a/htdocs/core/modules/fichinter/modules_fichinter.php b/htdocs/core/modules/fichinter/modules_fichinter.php
index 8cf79227d4f..185ef4cf73b 100644
--- a/htdocs/core/modules/fichinter/modules_fichinter.php
+++ b/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");
diff --git a/htdocs/core/modules/holiday/mod_holiday_immaculate.php b/htdocs/core/modules/holiday/mod_holiday_immaculate.php
index 84d6638a27e..a1647a67953 100644
--- a/htdocs/core/modules/holiday/mod_holiday_immaculate.php
+++ b/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;
}
diff --git a/htdocs/core/modules/holiday/modules_holiday.php b/htdocs/core/modules/holiday/modules_holiday.php
index 65b08f4bba8..7b6e13ea992 100644
--- a/htdocs/core/modules/holiday/modules_holiday.php
+++ b/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");
diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php
index 947dd3d18d3..e45630df298 100644
--- a/htdocs/core/modules/import/import_csv.modules.php
+++ b/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;
diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php
index 3747e8f6847..9fa5cbf2c44 100644
--- a/htdocs/core/modules/import/import_xlsx.modules.php
+++ b/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;
diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php
index b5c07d5221e..af3d033e670 100644
--- a/htdocs/core/modules/modCommande.class.php
+++ b/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] = [
diff --git a/htdocs/core/modules/product_batch/mod_lot_advanced.php b/htdocs/core/modules/product_batch/mod_lot_advanced.php
index d44a261a16b..d56178697f5 100644
--- a/htdocs/core/modules/product_batch/mod_lot_advanced.php
+++ b/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
*/
diff --git a/htdocs/core/modules/product_batch/mod_lot_free.php b/htdocs/core/modules/product_batch/mod_lot_free.php
index def14bd37b3..d6b24945ab0 100644
--- a/htdocs/core/modules/product_batch/mod_lot_free.php
+++ b/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 '';
diff --git a/htdocs/core/modules/product_batch/mod_lot_standard.php b/htdocs/core/modules/product_batch/mod_lot_standard.php
index 59de1965a6e..fc8d1389a00 100644
--- a/htdocs/core/modules/product_batch/mod_lot_standard.php
+++ b/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;
diff --git a/htdocs/core/modules/product_batch/mod_sn_advanced.php b/htdocs/core/modules/product_batch/mod_sn_advanced.php
index abe094220d2..6ee931d51a9 100644
--- a/htdocs/core/modules/product_batch/mod_sn_advanced.php
+++ b/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;
diff --git a/htdocs/core/modules/product_batch/mod_sn_free.php b/htdocs/core/modules/product_batch/mod_sn_free.php
index 67d39ec085a..f6b2417d34b 100644
--- a/htdocs/core/modules/product_batch/mod_sn_free.php
+++ b/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 '';
diff --git a/htdocs/core/modules/product_batch/mod_sn_standard.php b/htdocs/core/modules/product_batch/mod_sn_standard.php
index 845044c39f3..d6c109cff81 100644
--- a/htdocs/core/modules/product_batch/mod_sn_standard.php
+++ b/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
*/
diff --git a/htdocs/core/modules/reception/mod_reception_beryl.php b/htdocs/core/modules/reception/mod_reception_beryl.php
index bbfc0daee45..6570f2c864a 100644
--- a/htdocs/core/modules/reception/mod_reception_beryl.php
+++ b/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;
diff --git a/htdocs/core/modules/reception/modules_reception.php b/htdocs/core/modules/reception/modules_reception.php
index 145a04fbd31..f519974382b 100644
--- a/htdocs/core/modules/reception/modules_reception.php
+++ b/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");
diff --git a/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php b/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php
index acb3ad8fa2a..546596ab640 100644
--- a/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php
+++ b/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");
diff --git a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php b/htdocs/core/modules/supplier_order/modules_commandefournisseur.php
index 6fe3cb8883d..51c4e5f07d3 100644
--- a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php
+++ b/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");
diff --git a/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_marbre.php b/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_marbre.php
index b225899cef2..2e618b3ece3 100644
--- a/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_marbre.php
+++ b/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)
{
diff --git a/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_saphir.php b/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_saphir.php
index e7db54062cb..57cba16c01b 100644
--- a/htdocs/core/modules/supplier_proposal/mod_supplier_proposal_saphir.php
+++ b/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)
{
diff --git a/htdocs/core/modules/supplier_proposal/modules_supplier_proposal.php b/htdocs/core/modules/supplier_proposal/modules_supplier_proposal.php
index 0b6f0b3725d..5a3d9e2280a 100644
--- a/htdocs/core/modules/supplier_proposal/modules_supplier_proposal.php
+++ b/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");
diff --git a/htdocs/core/modules/takepos/mod_takepos_ref_universal.php b/htdocs/core/modules/takepos/mod_takepos_ref_universal.php
index b3d26b39511..7e46c10a341 100644
--- a/htdocs/core/modules/takepos/mod_takepos_ref_universal.php
+++ b/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;
diff --git a/htdocs/core/modules/takepos/modules_takepos.php b/htdocs/core/modules/takepos/modules_takepos.php
index b9fae565647..24fa70b7f28 100644
--- a/htdocs/core/modules/takepos/modules_takepos.php
+++ b/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');
diff --git a/htdocs/core/modules/ticket/modules_ticket.php b/htdocs/core/modules/ticket/modules_ticket.php
index 1d2bc944022..c8561382436 100644
--- a/htdocs/core/modules/ticket/modules_ticket.php
+++ b/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");
diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php
index d6e59e4b2bd..288fd88eae6 100644
--- a/htdocs/modulebuilder/template/class/myobject.class.php
+++ b/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),
);
/**
diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php
index 874d964ad6e..898dd2692e4 100644
--- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php
+++ b/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 */
}