diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 7990893036a..577107a3586 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -176,6 +176,7 @@ class modFacture extends DolibarrModules $this->export_permission[$r]=array(array("facture","facture","export")); $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','c.code'=>'CountryCode','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>"DateDue",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"NotePrivate",'f.note_public'=>"NotePublic",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalVAT",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.product_type'=>"TypeOfLineServiceOrProduct",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel'); $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','c.code'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.date_lim_reglement'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'f.note_public'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.product_type'=>'invoice_line','fd.fk_product'=>'product','p.ref'=>'product','p.label'=>'product'); + $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; @@ -193,6 +194,7 @@ class modFacture extends DolibarrModules $this->export_permission[$r]=array(array("facture","facture","export")); $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','c.code'=>'CountryCode','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>"DateDue",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"NotePrivate",'f.note_public'=>"NotePublic",'p.rowid'=>'PaymentId','pf.amount'=>'AmountPayment','p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber'); $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','c.code'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.date_lim_reglement'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'f.note_public'=>"invoice",'p.rowid'=>'payment','pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment'); + $this->export_dependencies_array[$r]=array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index bc4b9ee1265..013e41e2fea 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -24,8 +24,7 @@ /** - * \class Export - * \brief Class to manage exports + * Class to manage exports */ class Export { @@ -36,7 +35,8 @@ class Export var $array_export_label=array(); // Tableau de "libelle de lots" var $array_export_sql=array(); // Tableau des "requetes sql" var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter - //var $array_export_alias=array(); // Tableau des listes de champ+alias a exporter + var $array_export_entities=array(); // Tableau des listes de champ+alias a exporter + var $array_export_dependencies=array(); // array of list of entities that must take care of the DISTINCT if a field is added into export var $array_export_special=array(); // Tableau des operations speciales sur champ // To store export modules @@ -162,6 +162,8 @@ class Export $this->array_export_fields[$i]=$module->export_fields_array[$r]; // Tableau des entites a exporter (cle=champ, valeur=entite) $this->array_export_entities[$i]=$module->export_entities_array[$r]; + // Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records) + $this->array_export_dependencies[$i]=$module->export_dependencies_array[$r]; // Tableau des operations speciales sur champ $this->array_export_special[$i]=$module->export_special_array[$r]; diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 0670724d264..3fca99ee8fc 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -64,12 +64,13 @@ $entitytolang=array( // Translation code ); $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array(); -$datatoexport=isset($_GET["datatoexport"])? $_GET["datatoexport"] : (isset($_POST["datatoexport"])?$_POST["datatoexport"]:''); -$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:''); -$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1); -$export_name=isset($_POST["export_name"])? $_POST["export_name"] : ''; -$hexa=isset($_POST["hexa"])? $_POST["hexa"] : ''; -$exportmodelid=isset($_POST["exportmodelid"])? $_POST["exportmodelid"] : ''; +$datatoexport=GETPOST("datatoexport"); +$action=GETPOST("action"); +$step=GETPOST("step")?GETPOST("step"):1; +$export_name=GETPOST("export_name"); +$hexa=GETPOST("hexa"); +$exportmodelid=GETPOST("exportmodelid"); +$field=GETPOST("field"); $objexport=new Export($db); $objexport->load_arrays($user,$datatoexport); @@ -87,12 +88,15 @@ $sqlusedforexport=''; if ($action=='selectfield') { - if ($_GET["field"]=='all') + $fieldsarray=$objexport->array_export_fields[0]; + $fieldsentitiesarray=$objexport->array_export_entities[0]; + $fieldsdependenciesarray=$objexport->array_export_dependencies[0]; + + if ($field=='all') { - $fieldsarray=$objexport->array_export_fields[0]; foreach($fieldsarray as $key=>$val) { - if (! empty($array_selected[$key])) continue; // If already selected, select next + if (! empty($array_selected[$key])) continue; // If already selected, check next $array_selected[$key]=count($array_selected)+1; //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; @@ -100,7 +104,13 @@ if ($action=='selectfield') } else { - $array_selected[$_GET["field"]]=count($array_selected)+1; + $array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected" + // We check if there is a dependency + if (! empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]])) + { + // TODO Show warning "risk of duplicate record filtered" + + } //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; }