From 35dc1e7d4f0f96e834552e1033bb77cf0991f8e4 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 18 Feb 2021 11:04:37 +0100 Subject: [PATCH 1/5] with new phpoffice col start at 1 not 0 --- htdocs/core/modules/import/import_xlsx.modules.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 6c0bcc0f4b1..9d3c4e2b94e 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -173,7 +173,7 @@ class ImportXlsx extends ModeleImports $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT); - $col = 0; + $col = 1; foreach ($headerlinefields as $field) { $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, 1, $outputlangs->transnoentities($field)); // set autowidth @@ -195,7 +195,7 @@ class ImportXlsx extends ModeleImports public function write_record_example($outputlangs, $contentlinevalues) { // phpcs:enable - $col = 0; + $col = 1; $row = 2; foreach ($contentlinevalues as $cell) { $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($col, $row, $cell); @@ -289,7 +289,7 @@ class ImportXlsx extends ModeleImports $xlsx = new Xlsx(); $info = $xlsx->listWorksheetinfo($this->file); $countcolumns = $info[0]['totalColumns']; - for ($col = 0; $col < $countcolumns; $col++) { + for ($col = 1; $col <= $countcolumns; $col++) { $this->headers[$col] = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, 1)->getValue(); } return 0; @@ -314,7 +314,7 @@ class ImportXlsx extends ModeleImports $xlsx = new Xlsx(); $info = $xlsx->listWorksheetinfo($this->file); $countcolumns = $info[0]['totalColumns']; - for ($col = 0; $col < $countcolumns; $col++) { + for ($col = 1; $col <= $countcolumns; $col++) { $val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue(); $array[$col]['val'] = $val; $array[$col]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it null From de2d5c7188de18c458545c7edb830b418ebc4d9e Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 18 Feb 2021 12:24:24 +0100 Subject: [PATCH 2/5] fix sample xls file --- htdocs/core/modules/modProduct.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index f92d9b30890..27446890043 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -749,13 +749,13 @@ class modProduct extends DolibarrModules $this->import_convertvalue_array[$r] = array( 'pr.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product') ); - $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"PRODUCT_REF or id:123456", + $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"ref:PRODUCT_REF or id:123456", 'pr.price_base_type'=>"HT (for excl tax) or TTC (for inc tax)", 'pr.price_level'=>"1", 'pr.price'=>"100", 'pr.price_ttc'=>"110", 'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110", 'pr.tva_tx'=>'20', 'pr.recuperableonly'=>'0', - 'pr.date_price'=>'2013-04-10'); + 'pr.date_price'=>'2020-12-31'); } if (!empty($conf->global->MAIN_MULTILANGS)) From 58a1904c155b4892fc06bf91e403df68f8b7d593 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 18 Feb 2021 12:48:06 +0100 Subject: [PATCH 3/5] fix column count --- .../modules/import/import_xlsx.modules.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 9d3c4e2b94e..ebe0486d97c 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -372,7 +372,7 @@ class ImportXlsx extends ModeleImports //var_dump($sort_array_match_file_to_database); - if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) { + if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1]['val']))) { //print 'W'; $this->warnings[$warning]['lib'] = $langs->trans('EmptyLine'); $this->warnings[$warning]['type'] = 'EMPTY'; @@ -401,7 +401,7 @@ class ImportXlsx extends ModeleImports else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field } else dol_print_error($this->db); } else { - //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); + dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); } // array of fields to column index @@ -420,7 +420,7 @@ class ImportXlsx extends ModeleImports if ($key <= $maxfields) { // Set $newval with value to insert and set $listvalues with sql request part for insert $newval = ''; - if ($arrayrecord[($key - 1)]['type'] > 0) $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value + if ($arrayrecord[($key)]['type'] > 0) $newval = $arrayrecord[($key)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value // Make some tests on $newval @@ -572,21 +572,21 @@ class ImportXlsx extends ModeleImports $newval = $this->thirpartyobject->code_client; //print 'code_client='.$newval; } - if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" + if (empty($newval)) $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null" } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsuppliercodeifauto') { if (strtolower($newval) == 'auto') { $newval = $this->thirpartyobject->get_codefournisseur(0, 1); $newval = $this->thirpartyobject->code_fournisseur; //print 'code_fournisseur='.$newval; } - if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" + if (empty($newval)) $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null" } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getcustomeraccountancycodeifauto') { if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('customer'); $newval = $this->thirpartyobject->code_compta; //print 'code_compta='.$newval; } - if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" + if (empty($newval)) $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null" } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getsupplieraccountancycodeifauto') { if (strtolower($newval) == 'auto') { $this->thirpartyobject->get_codecompta('supplier'); @@ -594,7 +594,7 @@ class ImportXlsx extends ModeleImports if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" //print 'code_compta_fournisseur='.$newval; } - if (empty($newval)) $arrayrecord[($key - 1)]['type'] = -1; // If we get empty value, we will use "null" + if (empty($newval)) $arrayrecord[($key)]['type'] = -1; // If we get empty value, we will use "null" } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'getrefifauto') { $defaultref = ''; // TODO provide the $modTask (module of generation of ref) as parameter of import_insert function @@ -624,7 +624,7 @@ class ImportXlsx extends ModeleImports $errorforthistable++; $error++; } else { - $newval = $arrayrecord[($key - 1)]['val']; //We get new value computed. + $newval = $arrayrecord[($key)]['val']; //We get new value computed. } } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') { $newval = price2num($newval); @@ -695,8 +695,8 @@ class ImportXlsx extends ModeleImports $listfields[] = $fieldname; // Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert - if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) $listvalues[] = ($newval == '0' ? $newval : "null"); - elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) $listvalues[] = "''"; + if (empty($newval) && $arrayrecord[($key)]['type'] < 0) $listvalues[] = ($newval == '0' ? $newval : "null"); + elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) $listvalues[] = "''"; else $listvalues[] = "'" . $this->db->escape($newval) . "'"; } $i++; From 6fe9b589ed4eac1d979628ab958e7652af3de735 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 18 Feb 2021 12:50:15 +0100 Subject: [PATCH 4/5] fix sample product import files --- htdocs/core/modules/modProduct.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index 27446890043..78f638b1821 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -547,7 +547,7 @@ class modProduct extends DolibarrModules // field order as per structure of table llx_product $import_sample = array( - 'p.ref' => "PREF123456", + 'p.ref' => "ref:PREF123456", 'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'), 'p.label' => "Product name in default language", 'p.description' => "Product description in default language", @@ -687,7 +687,7 @@ class modProduct extends DolibarrModules ); $this->import_examplevalues_array[$r] = array( - 'sp.fk_product' => "PRODUCT_REF or id:123456", + 'sp.fk_product' => "ref:PRODUCT_REF or id:123456", 'sp.fk_soc' => "My Supplier", 'sp.ref_fourn' => "XYZ-F123456", 'sp.quantity' => "5", From fd0615b3fcf5bd7dc08383510b1132d2c9571468 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 19 Feb 2021 17:56:04 +0100 Subject: [PATCH 5/5] Too verbose --- htdocs/core/modules/import/import_xlsx.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index ebe0486d97c..5b2e339a588 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -401,7 +401,7 @@ class ImportXlsx extends ModeleImports else $tablewithentity_cache[$tablename] = 0; // table does not contains entity field } else dol_print_error($this->db); } else { - dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); + //dol_syslog("Table ".$tablename." check for entity into cache is ".$tablewithentity_cache[$tablename]); } // array of fields to column index