From 1dec4c432008cd4d49aa2d7a148eb78523c6f2a5 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Thu, 14 Jun 2018 10:37:40 +0200 Subject: [PATCH 1/6] FIX: supplier order: product supplier ref not saved on addline --- htdocs/fourn/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index efa8be0f951..9783fc9911e 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -409,7 +409,7 @@ if (empty($reshook)) $localtax2_tx, $idprod, $productsupplier->product_fourn_price_id, - $productsupplier->fourn_ref, + $productsupplier->ref_supplier, $remise_percent, 'HT', $pu_ttc, From f9a86ba43f0f56f163f7994dda9ab0e8db884a01 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 14 Jun 2018 14:01:05 +0200 Subject: [PATCH 2/6] Fix: MEMBER_MODIFY trigger not called if i change only extrafields --- htdocs/adherents/class/adherent.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 507695b0ffd..8736500757f 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -599,14 +599,14 @@ class Adherent extends CommonObject $error++; } } + } - if (! $error && ! $notrigger) - { - // Call trigger - $result=$this->call_trigger('MEMBER_MODIFY',$user); - if ($result < 0) { $error++; } - // End call triggers - } + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('MEMBER_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) From cb3704b67eb44aec8907ff4d6bed3ee138b2c252 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Fri, 15 Jun 2018 11:02:46 +0200 Subject: [PATCH 3/6] Fix can't add an attribute simply --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9dcd4c67035..1cf2f33980e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2010,7 +2010,7 @@ class Societe extends CommonObject $hookmanager=new HookManager($this->db); } $hookmanager->initHooks(array('societedao')); - $parameters=array('id'=>$this->id); + $parameters=array('id'=>$this->id, 'linkclose'=>$linkclose); $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) $linkclose = $hookmanager->resPrint; } From 3c80ce501bf9962d7dc4ec2c40ab43b0d5ccb5b5 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Fri, 15 Jun 2018 16:05:50 +0200 Subject: [PATCH 4/6] Fix missing hook on usercard (addMoreActionsButtons) --- htdocs/user/card.php | 127 ++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 3779e3ed6fa..9d9b73bad09 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1619,85 +1619,90 @@ else print '
'; - if (! empty($object->email)) + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { - $langs->load("mails"); - print ''; - } - else - { - $langs->load("mails"); - print ''; - } - - if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) - { - if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) + if (! empty($object->email)) { - print ''; + $langs->load("mails"); + print ''; } else { - print ''; + $langs->load("mails"); + print ''; } - } - elseif ($caneditpassword && ! $object->ldap_sid && - (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) - { - print ''; - } - // Si on a un gestionnaire de generation de mot de passe actif - if ($conf->global->USER_PASSWORD_GENERATED != 'none') - { - if ($object->statut == 0) + if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { - print ''; + if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) + { + print ''; + } + else + { + print ''; + } } - elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid && + elseif ($caneditpassword && ! $object->ldap_sid && + (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) + { + print ''; + } + + // Si on a un gestionnaire de generation de mot de passe actif + if ($conf->global->USER_PASSWORD_GENERATED != 'none') + { + if ($object->statut == 0) + { + print ''; + } + elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid && + ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) + { + print ''; + } + + if ($object->statut == 0) + { + print ''; + } + else if (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid && + ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) + { + if ($object->email) print ''; + else print ''; + } + } + + // Activer + if ($user->id <> $id && $candisableuser && $object->statut == 0 && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { - print ''; + print ''; } - - if ($object->statut == 0) - { - print ''; - } - else if (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid && + // Desactiver + if ($user->id <> $id && $candisableuser && $object->statut == 1 && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { - if ($object->email) print ''; - else print ''; + print ''; } - } - - // Activer - if ($user->id <> $id && $candisableuser && $object->statut == 0 && - ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) - { - print ''; - } - // Desactiver - if ($user->id <> $id && $candisableuser && $object->statut == 1 && - ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) - { - print ''; - } - // Delete - if ($user->id <> $id && $candisableuser && - ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) - { - if ($user->admin || ! $object->admin) // If user edited is admin, delete is possible on for an admin + // Delete + if ($user->id <> $id && $candisableuser && + ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $conf->entity == 1))) { - print ''; - } - else - { - print ''; + if ($user->admin || ! $object->admin) // If user edited is admin, delete is possible on for an admin + { + print ''; + } + else + { + print ''; + } } } - + print "
\n"; From 95ee3325fc448a913b570a44d3cf64f0e26a7524 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jun 2018 11:11:07 +0200 Subject: [PATCH 5/6] Part of fix of #8972 --- htdocs/compta/facture/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 67de173dff7..055a100848a 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -12,7 +12,7 @@ * Copyright (C) 2013 Jean-Francois FERRY * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2013 Cédric Salvador - * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 2014-2018 Ferran Marcet * Copyright (C) 2015-2016 Marcos García * * This program is free software; you can redistribute it and/or modify @@ -4408,7 +4408,7 @@ else if ($id > 0 || ! empty($ref)) print ''; } // For deposit invoice - if ($object->type == Facture::TYPE_DEPOSIT && $user->rights->facture->creer && empty($discount->id)) + if ($object->type == Facture::TYPE_DEPOSIT && $user->rights->facture->creer && $object->statut > 0 && empty($discount->id)) { print ''; } From 102f9aa84ffa09da522d826ee5d12e12044a5b59 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jun 2018 13:14:35 +0200 Subject: [PATCH 6/6] FIX Problems in accountancy module when using multicompany module. --- htdocs/accountancy/customer/index.php | 61 ++++++++++------------ htdocs/accountancy/customer/lines.php | 2 +- htdocs/accountancy/customer/list.php | 6 +-- htdocs/accountancy/expensereport/index.php | 59 ++++++++++----------- htdocs/accountancy/expensereport/list.php | 2 +- htdocs/accountancy/supplier/index.php | 59 ++++++++++----------- htdocs/accountancy/supplier/lines.php | 3 +- htdocs/accountancy/supplier/list.php | 2 +- 8 files changed, 89 insertions(+), 105 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index aedaeda0e5b..28657e352b4 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -70,38 +70,53 @@ $year_current = $year_start; $action = GETPOST('action','aZ09'); - /* * Actions */ +if ($action == 'clean' || $action == 'validatehistory') +{ + // Clean database + $db->begin(); + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; + $sql1 .= " SET fk_code_ventilation = 0"; + $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN'; + $sql1 .= ' (SELECT accnt.rowid '; + $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; + $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; + $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ' AND accnt.entity = '.$conf->entity.')'; + $sql1 .= ' AND fd.fk_facture IN (SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture WHERE entity = '.$conf->entity.')'; + $sql1 .= ' AND fk_code_ventilation <> 0'; + + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); + $resql1 = $db->query($sql1); + if (! $resql1) { + $error ++; + $db->rollback(); + setEventMessage($db->lasterror(), 'errors'); + } else { + $db->commit(); + } + // End clean database +} + if ($action == 'validatehistory') { $error = 0; $db->begin(); - // First clean corrupted data - $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sqlclean .= " SET fk_code_ventilation = 0"; - $sqlclean .= ' WHERE fd.fk_code_ventilation NOT IN '; - $sqlclean .= ' (SELECT accnt.rowid '; - $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; - $sqlclean .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; - $sqlclean .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - $resql = $db->query($sqlclean); - // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind if ($db->type == 'pgsql') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet"; $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; $sql1 .= " SET fk_code_ventilation = accnt.rowid"; - $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } @@ -131,26 +146,6 @@ $textnextyear = ' begin(); -$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; -$sql1 .= " SET fk_code_ventilation = 0"; -$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; -$sql1 .= ' (SELECT accnt.rowid '; -$sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; -$sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; -$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; -dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); -$resql1 = $db->query($sql1); -if (! $resql1) { - $error ++; - $db->rollback(); - setEventMessage($db->lasterror(), 'errors'); -} else { - $db->commit(); -} -// End clean database - print $langs->trans("DescVentilCustomer") . '
'; print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index e696b4774d1..a475461f973 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -180,7 +180,7 @@ $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, $sql .= " fd.situation_percent, co.label as country, s.tva_intra"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_product"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; +$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays "; diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 4d9d7532d7e..3719fd85650 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -219,9 +219,9 @@ $sql.=$hookmanager->resPrint; $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f"; $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture"; $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; -$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'"; -$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.fk_pcg_version = '" . $chartaccountcode."'"; -$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.fk_pcg_version = '" . $chartaccountcode."'"; +$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity; +$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.fk_pcg_version = '" . $chartaccountcode."' AND aa2.entity = " . $conf->entity; +$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.fk_pcg_version = '" . $chartaccountcode."' AND aa3.entity = " . $conf->entity; $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; $sql.= " AND l.product_type <= 2"; // Add search filter like diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index cec7fbdced4..fd3c342b0c7 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -72,33 +72,48 @@ $action = GETPOST('action','aZ09'); * Actions */ +if ($action == 'clean' || $action == 'validatehistory') +{ + // Clean database + $db->begin(); + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; + $sql1 .= " SET fk_code_ventilation = 0"; + $sql1 .= ' WHERE erd.fk_code_ventilation NOT IN'; + $sql1 .= ' (SELECT accnt.rowid '; + $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; + $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; + $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ' AND accnt.entity = '.$conf->entity.')'; + $sql1 .= ' AND erd.fk_expensereport IN (SELECT rowid FROM ' . MAIN_DB_PREFIX . 'expensereport WHERE entity = '.$conf->entity.')'; + $sql1 .= ' AND fk_code_ventilation <> 0'; + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); + $resql1 = $db->query($sql1); + if (! $resql1) { + $error ++; + $db->rollback(); + setEventMessage($db->lasterror(), 'errors'); + } else { + $db->commit(); + } + // End clean database +} + if ($action == 'validatehistory') { $error = 0; $db->begin(); - // First clean corrupted data - $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; - $sqlclean .= " SET fk_code_ventilation = 0"; - $sqlclean .= ' WHERE erd.fk_code_ventilation NOT IN '; - $sqlclean .= ' (SELECT accnt.rowid '; - $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; - $sqlclean .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; - $sqlclean .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - $resql = $db->query($sqlclean); - // Now make the binding if ($db->type == 'pgsql') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det"; $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "c_type_fees as t, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE " . MAIN_DB_PREFIX . "expensereport_det.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE " . MAIN_DB_PREFIX . "expensereport_det.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND t.accountancy_code = accnt.account_number"; $sql1 .= " AND " . MAIN_DB_PREFIX . "expensereport_det.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd, " . MAIN_DB_PREFIX . "c_type_fees as t, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; $sql1 .= " SET erd.fk_code_ventilation = accnt.rowid"; - $sql1 .= " WHERE erd.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE erd.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND t.accountancy_code=accnt.account_number"; $sql1 .= " AND erd.fk_code_ventilation = 0"; } @@ -128,26 +143,6 @@ $textnextyear = ' 
begin(); -$sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; -$sql1 .= " SET fk_code_ventilation = 0"; -$sql1 .= ' WHERE erd.fk_code_ventilation NOT IN '; -$sql1 .= ' (SELECT accnt.rowid '; -$sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; -$sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; -$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; -dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); -$resql1 = $db->query($sql1); -if (! $resql1) { - $error ++; - $db->rollback(); - setEventMessage($db->lasterror(), 'errors'); -} else { - $db->commit(); -} -// End clean database - print $langs->trans("DescVentilExpenseReport") . '
'; print $langs->trans("DescVentilExpenseReportMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php index 2a24aa2f656..d4d67655314 100644 --- a/htdocs/accountancy/expensereport/list.php +++ b/htdocs/accountancy/expensereport/list.php @@ -200,7 +200,7 @@ $sql.= " aa.rowid as aarowid"; $sql.= " FROM " . MAIN_DB_PREFIX . "expensereport as er"; $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport_det as erd ON er.rowid = erd.fk_expensereport"; $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees"; -$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'"; +$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity; $sql.= " WHERE er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <= 0"; // Add search filter like if (strlen(trim($search_expensereport))) { diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index e9935fc8d78..0c0bcf256ed 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -73,33 +73,48 @@ $action = GETPOST('action','aZ09'); * Actions */ +if ($action == 'clean' || $action == 'validatehistory') +{ + // Clean database + $db->begin(); + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; + $sql1 .= " SET fk_code_ventilation = 0"; + $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN'; + $sql1 .= ' (SELECT accnt.rowid '; + $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; + $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; + $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ' AND accnt.entity = '.$conf->entity.')'; + $sql1 .= ' AND fd.fk_facture_fourn IN (SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture_fourn WHERE entity = '.$conf->entity.')'; + $sql1 .= ' AND fk_code_ventilation <> 0'; + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); + $resql1 = $db->query($sql1); + if (! $resql1) { + $error ++; + $db->rollback(); + setEventMessage($db->lasterror(), 'errors'); + } else { + $db->commit(); + } + // End clean database +} + if ($action == 'validatehistory') { $error = 0; $db->begin(); - // First clean corrupted data - $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sqlclean .= " SET fk_code_ventilation = 0"; - $sqlclean .= ' WHERE fd.fk_code_ventilation NOT IN '; - $sqlclean .= ' (SELECT accnt.rowid '; - $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; - $sqlclean .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; - $sqlclean .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - $resql = $db->query($sqlclean); - // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind if ($db->type == 'pgsql') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det"; $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number"; $sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; $sql1 .= " SET fk_code_ventilation = accnt.rowid"; - $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } @@ -129,26 +144,6 @@ $textnextyear = ' 
begin(); -$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; -$sql1 .= " SET fk_code_ventilation = 0"; -$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; -$sql1 .= ' (SELECT accnt.rowid '; -$sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; -$sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; -$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; -dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); -$resql1 = $db->query($sql1); -if (! $resql1) { - $error ++; - $db->rollback(); - setEventMessage($db->lasterror(), 'errors'); -} else { - $db->commit(); -} -// End clean database - print $langs->trans("DescVentilSupplier") . '
'; print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php index 6ad8731a415..b12d4da70bc 100644 --- a/htdocs/accountancy/supplier/lines.php +++ b/htdocs/accountancy/supplier/lines.php @@ -179,12 +179,11 @@ $sql.= " aa.label, aa.account_number, "; $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, co.label as country, s.tva_intra"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as l"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = l.fk_code_ventilation"; +$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = l.fk_code_ventilation"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays "; $sql.= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 "; -$sql.= " AND aa.rowid = l.fk_code_ventilation"; if ($search_lineid) { $sql .= natural_search("l.rowid", $search_lineid, 1); } diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index c19e1d2716c..ab03b2f433e 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -220,7 +220,7 @@ $sql.=$hookmanager->resPrint; $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn"; $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; -$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."'"; +$sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity; $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; $sql.= " AND l.product_type <= 2"; // Add search filter like