diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index ba028915b92..c8a12cef083 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -370,7 +370,7 @@ class BookKeeping extends CommonObject $sql .= ", ".(!empty($this->subledger_account) ? ("'".$this->db->escape($this->subledger_account)."'") : "NULL"); $sql .= ", ".(!empty($this->subledger_label) ? ("'".$this->db->escape($this->subledger_label)."'") : "NULL"); $sql .= ", '".$this->db->escape($this->numero_compte)."'"; - $sql .= ", ".(!empty($this->label_operation) ? ("'".$this->db->escape($this->label_operation)."'") : "NULL"); + $sql .= ", ".(!empty($this->label_compte) ? ("'".$this->db->escape($this->label_compte)."'") : "NULL"); $sql .= ", '".$this->db->escape($this->label_operation)."'"; $sql .= ", ".$this->debit; $sql .= ", ".$this->credit; diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 2d6a598398c..ebeeac5c5b9 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -425,7 +425,7 @@ class Documents extends DolibarrApi throw new RestException(500, 'Error while fetching object: '.$object->error); } - $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, 'product'); } elseif ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') { diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 07ff1c64dbb..e7af582d121 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -291,7 +291,7 @@ $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos' //llxHeader('',$langs->trans('Proposal'),$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, '; $sql .= " typent.code as typent_code,"; $sql .= " ava.rowid as availability,"; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 1531dfd622e..7cbff15f1da 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -282,7 +282,7 @@ $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_P // llxHeader('',$title,$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index da5bab5b47e..0a7732bf21c 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -416,7 +416,7 @@ $formcompany = new FormCompany($db); $thirdpartystatic = new Societe($db); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql .= ' f.fk_user_author,'; diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 0be6659f7b4..03c128e841f 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -44,12 +44,12 @@ $nbofyear = 4; $year = GETPOST('year', 'int'); if (empty($year)) { - $year_current = strftime("%Y", dol_now()); - $month_current = strftime("%m", dol_now()); + $year_current = dol_print_date(dol_now(), "%Y"); + $month_current = dol_print_date(dol_now(), "%m"); $year_start = $year_current - ($nbofyear - 1); } else { $year_current = $year; - $month_current = strftime("%m", dol_now()); + $month_current = dol_print_date(dol_now(), "%m"); $year_start = $year - ($nbofyear - 1); } $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); @@ -58,12 +58,12 @@ $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); // We define date_start and date_end if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q = GETPOST("q") ?GETPOST("q") : 0; + $q = GETPOST("q") ? GETPOST("q") : 0; if ($q == 0) { // We define date_start and date_end $year_end = $year_start + ($nbofyear - 1); - $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); + $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1); if (!GETPOST('month')) { if (!GETPOST("year") && $month_start > $month_current) @@ -86,8 +86,10 @@ $userid = GETPOST('userid', 'int'); $socid = GETPOST('socid', 'int'); $tmps = dol_getdate($date_start); +$mothn_start = $tmps['mon']; $year_start = $tmps['year']; $tmpe = dol_getdate($date_end); +$month_end = $tmpe['mon']; $year_end = $tmpe['year']; $nbofyear = ($year_end - $year_start) + 1; @@ -306,7 +308,7 @@ $now = dol_now(); $casenow = dol_print_date($now, "%Y-%m"); // Loop on each month -$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0; +$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOST('date_startmonth', 'int') - 1) : (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1)); for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { $mois_modulo = $mois; // ajout @@ -338,68 +340,75 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. { if ($modecompta == 'CREANCES-DETTES') { - // Valeur CA du mois w/o VAT + // Value turnover of month w/o VAT print ''; - if ($cum_ht[$case]) - { - $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. - print ''.price($cum_ht[$case], 1).''; - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } + if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { + if ($cum_ht[$case]) { + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + print ''.price($cum_ht[$case], 1).''; + } else { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } + } } print ""; } - // Valeur CA du mois + // Value turnover of month print ''; - if ($cum[$case]) - { - $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. - if ($modecompta != 'BOOKKEEPING') print ''; - print price($cum[$case], 1); - if ($modecompta != 'BOOKKEEPING') print ''; - } else { - if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } + if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { + if ($cum[$case]) { + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + if ($modecompta != 'BOOKKEEPING') print ''; + print price($cum[$case], 1); + if ($modecompta != 'BOOKKEEPING') print ''; + } else { + if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } + } } print ""; - // Pourcentage du mois - if ($annee_decalage > $minyear && $case <= $casenow) - { - if ($cum[$caseprev] && $cum[$case]) + // Percentage of month + print ''; + //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end); + if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { + if ($annee_decalage > $minyear && $case <= $casenow) { - $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100); - //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; - print ''.($percent >= 0 ? "+$percent" : "$percent").'%'; + if ($cum[$caseprev] && $cum[$case]) + { + $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100); + //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; + print ($percent >= 0 ? "+$percent" : "$percent").'%'; + } + if ($cum[$caseprev] && !$cum[$case]) + { + print '-100%'; + } + if (!$cum[$caseprev] && $cum[$case]) + { + //print '+Inf%'; + print '-'; + } + if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) + { + print '+0%'; + } + if (!isset($cum[$caseprev]) && !$cum[$case]) + { + print '-'; + } + } else { + if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print ' '; } } - if ($cum[$caseprev] && !$cum[$case]) - { - print '-100%'; - } - if (!$cum[$caseprev] && $cum[$case]) - { - //print '+Inf%'; - print '-'; - } - if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) - { - print '+0%'; - } - if (!isset($cum[$caseprev]) && !$cum[$case]) - { - print '-'; - } - } else { - print ''; - if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print ' '; } - print ''; } + print ''; if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ' '; } - $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); - $total[$annee] += $cum[$case]; + if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) { + $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); + $total[$annee] += $cum[$case]; + } } print ''; @@ -470,34 +479,37 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) } */ -// Affiche total +// Show total print ''.$langs->trans("Total").''; for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') { // Montant total HT - if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) - { - print ''.($total_ht[$annee] ?price($total_ht[$annee]) : "0").""; + if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { + print ''; + print ($total_ht[$annee] ?price($total_ht[$annee]) : "0"); + print ""; } else { print ' '; } } - // Montant total - if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) - { - print ''.($total[$annee] ?price($total[$annee]) : "0").""; + // Total amount + if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { + print ''; + print ($total[$annee] ?price($total[$annee]) : "0"); + print ""; } else { print ' '; } // Pourcentage total - if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) - { + if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) { if ($total[$annee - 1] && $total[$annee]) { $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100); - print ''.($percent >= 0 ? "+$percent" : "$percent").'%'; + print ''; + print ($percent >= 0 ? "+$percent" : "$percent").'%'; + print ''; } if ($total[$annee - 1] && !$total[$annee]) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8db917882ec..68941b92387 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5652,7 +5652,7 @@ function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart = ' $arrayforoldpath = array('cheque', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment'); if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[] = 'product'; if (!empty($level) && in_array($modulepart, $arrayforoldpath)) { - // This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided. + // This part should be removed once all code is using "get_exdir" to forge path, with parameter $object and $modulepart provided. if (empty($alpha)) $num = preg_replace('/([^0-9])/i', '', $num); else $num = preg_replace('/^.*\-/i', '', $num); $num = substr("000".$num, -$level); diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 28c0673ef17..20bb6f298cb 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -211,8 +211,9 @@ $helpurl = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Ex llxHeader('', $langs->trans('ListOfSendings'), $helpurl); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; -$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, l.date_delivery as date_reception, e.fk_statut, e.billed, e.tracking_number,"; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; +$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number,"; +$sql .= " l.date_delivery as date_reception,"; $sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, "; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; @@ -242,11 +243,12 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user_author = u.rowid'; - +if ($search_user > 0) { // Get link to order to get the order id in eesource.fk_source + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'"; +} // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -if ($search_user > 0) -{ +if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; } @@ -274,6 +276,11 @@ if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_tracking) $sql .= natural_search("e.tracking_number", $search_tracking); if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale; +if ($search_user > 0) +{ + // The contact on a shipment is also the contact of the order. + $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = eesource.fk_source AND ec.fk_socpeople = ".$db->escape($search_user); +} if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp); if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv); if ($search_company) $sql .= natural_search('s.nom', $search_company); diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 14a9a9e6f19..52b8c1d2cd3 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -535,7 +535,7 @@ $help_url = ''; // llxHeader('',$title,$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 26ec6377cc3..6354190ab80 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -558,4 +558,3 @@ INSERT INTO llx_c_socialnetworks (entity, code, label, url, icon, active) VALUES ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); ALTER TABLE llx_projet ADD COLUMN fk_opp_status_end integer DEFAULT NULL; - diff --git a/htdocs/install/mysql/tables/llx_mrp_production.sql b/htdocs/install/mysql/tables/llx_mrp_production.sql index bd0cd722f1a..36129a54aea 100644 --- a/htdocs/install/mysql/tables/llx_mrp_production.sql +++ b/htdocs/install/mysql/tables/llx_mrp_production.sql @@ -16,7 +16,7 @@ CREATE TABLE llx_mrp_production( rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL, - fk_mo integer NOT NULL, + fk_mo integer NOT NULL, position integer NOT NULL DEFAULT 0, fk_product integer NOT NULL, fk_warehouse integer, diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 5634905da6e..a7a7e12db14 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -59,6 +59,7 @@ ErrorDirNotFound=Directory %s not found (Bad path, wrong permissions or a ErrorFunctionNotAvailableInPHP=Function %s is required for this feature but is not available in this version/setup of PHP. ErrorDirAlreadyExists=A directory with this name already exists. ErrorFileAlreadyExists=A file with this name already exists. +ErrorDestinationAlreadyExists=Another file with the name %s already exists. ErrorPartialFile=File not received completely by server. ErrorNoTmpDir=Temporary directy %s does not exists. ErrorUploadBlockedByAddon=Upload blocked by a PHP/Apache plugin. diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 274782a14ea..121909eb28a 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -106,7 +106,7 @@ class Mo extends CommonObject 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61, 'notnull'=>-1,), 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62, 'notnull'=>-1,), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>500, 'notnull'=>1,), - 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>-1,), + 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>1,), 'date_valid' => array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-2, 'position'=>502,), 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid',), 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1,), @@ -1352,7 +1352,7 @@ class Mo extends CommonObject */ public static function replaceThirdparty($db, $origin_id, $dest_id) { - $tables = array('mrp_production'); + $tables = array('mrp_mo'); return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } diff --git a/htdocs/supplier_proposal/list.php b/htdocs/supplier_proposal/list.php index d74f2fbdec3..421ac40b447 100644 --- a/htdocs/supplier_proposal/list.php +++ b/htdocs/supplier_proposal/list.php @@ -249,7 +249,7 @@ $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur'; //llxHeader('',$langs->trans('CommRequest'),$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,";