Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display import menu in std but std import is not compatible #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not Released

- FIX : Remove std import menu, keep discount rule import menu - *30/03/2022* - 2.17.2
- FIX : CSRF token protection - *17/03/2022* - 2.17.1
- FIX : css and js files doesn't need to be PHP file (need module reload) - *05/02/2022* - 2.17.0
- NEW : Add project category filter for rules *28/12/2021* - 2.16.0
Expand Down
15 changes: 12 additions & 3 deletions class/importrule.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class ImportRule{
*/
public $nbErrors;

/**
* @var string csv separator char
*/
public $csvSeparator = ';';

/**
* @var string csv category separator char
*/
public $csvCatSeparator = ',';

/**
* @var int number imported lines
Expand Down Expand Up @@ -76,7 +85,7 @@ function idrGetDiscountFromCSV($filePath, $srcEncoding = 'latin1', $importKey='e
$csvFile = fopen($filePath, 'r');

$this->db->begin();
for ($i = 1; $csvValues = fgetcsv($csvFile, '64000', ";", '"'); $i++) {
for ($i = 1; $csvValues = fgetcsv($csvFile, '64000', $this->csvSeparator, '"'); $i++) {
$csvValues = array_map(
function ($val) use ($srcEncoding) {
if ($srcEncoding === 'UTF-8') return trim($val);
Expand Down Expand Up @@ -358,7 +367,7 @@ function setProduct($ref_product, $catProducts, $langs, $lineNumber, &$objDiscou
}else{
if ($this->validate->isNotEmptyString($catProducts)){
// Test des catégories
$TCactProducts = explode(",",$catProducts);
$TCactProducts = explode($this->csvCatSeparator,$catProducts);

foreach ($TCactProducts as $catproduct){
// in the were param we can't pass $cat->MAP_ID[$cat::TYPE_PRODUCT] instead of 0 ...
Expand Down Expand Up @@ -454,7 +463,7 @@ function setCompany($ref_company, $catCompanies, $langs, $lineNumber, &$objDisco
}else{
if ($this->validate->isNotEmptyString($catCompanies)){
// Test des catégories
$TCactCompanies = explode(",",$catCompanies);
$TCactCompanies = explode($this->csvCatSeparator,$catCompanies);

foreach ($TCactCompanies as $catcompany){
if (!$this->isCatInType($catcompany,"label",2)){
Expand Down
110 changes: 55 additions & 55 deletions core/modules/moddiscountrules.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct($db)

// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'

$this->version = '2.17.1';
$this->version = '2.17.2';

// Key used in llx_const table to save module status enabled/disabled (where discountrules is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
Expand Down Expand Up @@ -382,60 +382,60 @@ public function __construct($db)
// Imports profiles provided by this module
$r = 1;
/* BEGIN MODULEBUILDER IMPORT MYOBJECT */

$this->import_code[$r] = $this->rights_class.'_'.$r;
$this->import_label[$r] = "discountrules"; // Translation key
$this->import_icon[$r] = 'discountrules@discountrules';
// for example csv file
$this->import_fields_array[$r] = array(
"label" => "label",
"fk_project" => "refProject",
"fk_product" => "refProduct",
"fk_company" => "refCompany",
"fk_country" => "refCountry",
"priority_rank" =>"priorityRank",
"fk_c_typent" => "cTypeEnt",



"all_category_product" =>"allCategoryProduct",
"all_category_company" =>"allCategoryCompany",

"reduction" => "reduction",
"from_quantity" => "fromQuantity",
"product_price" => "productPrice",
"product_reduction_amount" => "productReductionAmount",
"date_from" =>"dateFrom",
"date_to" =>"dateTo",
"activation" =>"activation",


);

//@todo exemple à remplir
$this->import_examplevalues_array[$r] = array(
"label" => "ligne Exemple",

"fk_project" => "PJ2201-0001",
"fk_product" => "PRODUIT_IMPORT_01",
"fk_company" => "KEVIN",
"fk_country" => "code pays. ex : US",
"priority_rank" =>"vide ou 0 si pas de priorité sinon numérique entre 1 et 5",
"fk_c_typent" => "cTypeEnt",


"all_category_product" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02",
"all_category_company" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02",

"from_quantity" => "numérique",
"product_price" => "numérique",
"product_reduction_amount" => "5",
"reduction" => "10",
"date_from" =>"date au format jj/mm/yyyy",
"date_to" =>"date au format jj/mm/yyyy",
"activation" =>"vide/0 pour désactiver 1 pour activer",

);
//
// $this->import_code[$r] = $this->rights_class.'_'.$r;
// $this->import_label[$r] = "discountrules"; // Translation key
// $this->import_icon[$r] = 'discountrules@discountrules';
// // for example csv file
// $this->import_fields_array[$r] = array(
// "label" => "label",
// "fk_project" => "refProject",
// "fk_product" => "refProduct",
// "fk_company" => "refCompany",
// "fk_country" => "refCountry",
// "priority_rank" =>"priorityRank",
// "fk_c_typent" => "cTypeEnt",
//
//
//
// "all_category_product" =>"allCategoryProduct",
// "all_category_company" =>"allCategoryCompany",
//
// "reduction" => "reduction",
// "from_quantity" => "fromQuantity",
// "product_price" => "productPrice",
// "product_reduction_amount" => "productReductionAmount",
// "date_from" =>"dateFrom",
// "date_to" =>"dateTo",
// "activation" =>"activation",
//
//
// );
//
// //@todo exemple à remplir
// $this->import_examplevalues_array[$r] = array(
// "label" => "ligne Exemple",
//
// "fk_project" => "PJ2201-0001",
// "fk_product" => "PRODUIT_IMPORT_01",
// "fk_company" => "KEVIN",
// "fk_country" => "code pays. ex : US",
// "priority_rank" =>"vide ou 0 si pas de priorité sinon numérique entre 1 et 5",
// "fk_c_typent" => "cTypeEnt",
//
//
// "all_category_product" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02",
// "all_category_company" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02",
//
// "from_quantity" => "numérique",
// "product_price" => "numérique",
// "product_reduction_amount" => "5",
// "reduction" => "10",
// "date_from" =>"date au format jj/mm/yyyy",
// "date_to" =>"date au format jj/mm/yyyy",
// "activation" =>"vide/0 pour désactiver 1 pour activer",
//
// );
/* END MODULEBUILDER IMPORT MYOBJECT */


Expand Down
10 changes: 5 additions & 5 deletions discount_rules_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

$startLine = GETPOSTISSET('startLine','int') ? GETPOST('startLine','int') : 2;
$endline = GETPOSTISSET('endline','int') ? GETPOST('endline','int') : '';
$importRule = new ImportRule($db);

/*
* ACTION
Expand All @@ -75,7 +76,6 @@

$filePath = $_FILES['CSVFile']['tmp_name'];

$importRule = new ImportRule($db);
$importLogs = $importRule->idrGetDiscountFromCSV(
$filePath,
GETPOST('srcEncoding', 'alpha'),
Expand Down Expand Up @@ -248,7 +248,7 @@ function _showImportForm($form,$startline,$endline) {

function _showHelp() {

global $langs;
global $langs, $importRule;

$key="csv";
$param="&datatoimport=discountrules_1";
Expand All @@ -257,7 +257,7 @@ function _showHelp() {
<legend><?php print $langs->trans("help"); ?></legend>

<h4 class="center">
<?php print img_picto('', 'download', 'class="paddingright opacitymedium"').'<a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$key.$param.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a>'; ?>
<?php print img_picto('', 'download', 'class="paddingright opacitymedium"').'<a href="'.dol_buildpath('/discountrules/import_demo/Exemple_de_fichier_import_discountrules_sep_point_vigule.csv',1).'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a>'; ?>
</h4>
<hr/>

Expand All @@ -273,8 +273,8 @@ function _showHelp() {
<li><strong><?php print $langs->trans("EncodeCharsSubTitle"); ?> </strong>
<br><?php print $langs->trans("EncodeCharsSubTitle-2"); ?>
</li>
<li><?php print $langs->trans("FieldSeparatorsubTitle"); ?> </li>
<li><?php print $langs->trans("catSeparatorsubTitle"); ?> </li>
<li><?php print $langs->trans("FieldSeparatorsubTitle", $importRule->csvSeparator); ?> </li>
<li><?php print $langs->trans("catSeparatorsubTitle", $importRule->csvCatSeparator); ?> </li>
<li><?php print $langs->trans("StringSeparatorsubTitle"); ?></li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Libellé (label);Référence projet (fk_project);Référence produit (fk_product);Référence client (fk_company);Référence pays (fk_country);Priorité (priority_rank);Type de tiers (fk_c_typent);Catégorie de produit (all_category_product);Catégorie de client (all_category_company);Remise en pourcentage (reduction);À partir de la quantité (from_quantity);Prix HT à appliquer (product_price);Montant de remise fixe (product_reduction_amount);Date de début d'application de la règle (date_from);Date de fin d'application de la règle (date_to);activation (activation)
ligne Exemple;PJ2201-0001;PRODUIT_IMPORT_01;KEVIN;code pays. ex : US;vide ou 0 si pas de priorité sinon numérique entre 1 et 5;cTypeEnt;vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01/TCP02;vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01/TCP02;10;numérique;numérique;5;date au format jj/mm/yyyy;date au format jj/mm/yyyy;vide/0 pour désactiver 1 pour activer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Libellé (label),Référence projet (fk_project),Référence produit (fk_product),Référence client (fk_company),Référence pays (fk_country),Priorité (priority_rank),Type de tiers (fk_c_typent),Catégorie de produit (all_category_product),Catégorie de client (all_category_company),Remise en pourcentage (reduction),À partir de la quantité (from_quantity),Prix HT à appliquer (product_price),Montant de remise fixe (product_reduction_amount),Date de début d'application de la règle (date_from),Date de fin d'application de la règle (date_to),activation (activation)
ligne Exemple,PJ2201-0001,PRODUIT_IMPORT_01,KEVIN,code pays. ex : US,vide ou 0 si pas de priorité sinon numérique entre 1 et 5,cTypeEnt,vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01/TCP02,vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01/TCP02,10,numérique,numérique,5,date au format jj/mm/yyyy,date au format jj/mm/yyyy,vide/0 pour désactiver 1 pour activer
4 changes: 2 additions & 2 deletions langs/fr_FR/importdiscountrules.lang
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Numbersub-2=sans unité (175)
Numbersub-3=sans séparateur de milliers (30000)
EncodeCharsSubTitle=Encodage du jeu de caractères
EncodeCharsSubTitle-2=À sélectionner dans la liste déroulante. Choisir le bon encodage évite les erreurs sur les caractères accentués.<br> Si le logiciel qui génère le fichier CSV vous le permet, choisissez l’encodage <span class="character">UTF-8</span> lors de l’export en CSV.
FieldSeparatorsubTitle=<b>Séparateur de champs</b> :point-virgule (<span class="character">;</span>)
catSeparatorsubTitle=<b>Séparateur de catégories </b> :virgule (<span class="character">,</span>)
FieldSeparatorsubTitle=<b>Séparateur de champs</b> :point-virgule (<span class="character">%s</span>)
catSeparatorsubTitle=<b>Séparateur de catégories </b> :virgule (<span class="character">%s</span>)
StringSeparatorsubTitle=<b>Séparateur de chaînes de caractères</b> : double-quote (<span class="character">"</span>)
EOLsubTitle=<b>Fin de ligne</b> : type Windows (CRLF)

Expand Down