From 44dba391c11a2a579771a2ee627e6fd13db4e50d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 10:24:16 +0200 Subject: [PATCH 01/24] New: add dictionnary sharing (multicompany) --- htdocs/admin/dict.php | 24 +++++------ htdocs/core/lib/functions.lib.php | 40 ++++++++++++------- .../install/mysql/migration/5.0.0-6.0.0.sql | 10 ++++- .../mysql/tables/llx_c_paiement.key.sql | 5 ++- .../install/mysql/tables/llx_c_paiement.sql | 11 +++-- .../mysql/tables/llx_c_payment_term.key.sql | 20 ++++++++++ .../mysql/tables/llx_c_payment_term.sql | 26 ++++++------ 7 files changed, 89 insertions(+), 47 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_c_payment_term.key.sql diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 22e7bf7087f..838f76aa296 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -1,16 +1,16 @@ - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2010-2016 Juanjo Menent - * Copyright (C) 2011-2015 Philippe Grand - * Copyright (C) 2011 Remy Younes - * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2011-2016 Alexandre Spangaro - * Copyright (C) 2015 Ferran Marcet - * Copyright (C) 2016 Raphaël Doursenaud +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2010-2016 Juanjo Menent + * Copyright (C) 2011-2015 Philippe Grand + * Copyright (C) 2011 Remy Younes + * Copyright (C) 2012-2015 Marcos García + * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2011-2016 Alexandre Spangaro + * Copyright (C) 2015 Ferran Marcet + * Copyright (C) 2016 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5113c9f1d96..454607d7dd1 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -102,18 +102,21 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) /** * Get list of entity id to use. * - * @param string $element Current element - * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', - * 'product', 'productprice', 'stock', - * 'propal', 'supplier_proposal', 'facture', 'facture_fourn', - * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', - * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', - * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', - * 'email_template', 'event', - * @param int $shared 1=Return id of current entity + shared entities (default), 0=Return id of current entity only + * @param string $element Current element + * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', + * 'product', 'productprice', 'stock', + * 'propal', 'supplier_proposal', 'facture', 'facture_fourn', + * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', + * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', + * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', + * 'email_template', 'event', + * @param int $shared 0=Return id of current entity only, + * 1=Return id of current entity + shared entities (default), + * 2=Return id of current entity OR $forceentity value (eg. dictionnary share) + * @param int $forceentity Entity id * @return mixed Entity id(s) to use */ -function getEntity($element=false, $shared=1) +function getEntity($element=false, $shared=1, $forceentity=null) { global $conf, $mc; @@ -124,14 +127,23 @@ function getEntity($element=false, $shared=1) if (is_object($mc)) { - return $mc->getEntity($element, $shared); + return $mc->getEntity($element, $shared, $forceentity); } else { $out=''; - $addzero = array('user', 'usergroup', 'email_template', 'default_values'); - if (in_array($element, $addzero)) $out.= '0,'; - $out.= $conf->entity; + + if ($shared == 2) + { + $out.= $forceentity; + } + else + { + $addzero = array('user', 'usergroup', 'email_template', 'default_values'); + if (in_array($element, $addzero)) $out.= '0,'; + $out.= $conf->entity; + } + return $out; } } diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 317fb6b7ff2..db67c58e51a 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -380,4 +380,12 @@ create table llx_loan_schedule fk_user_modif integer )ENGINE=innodb; -ALTER TABLE llx_tva ADD COLUMN datec date AFTER tms; \ No newline at end of file +ALTER TABLE llx_tva ADD COLUMN datec date AFTER tms; + +ALTER TABLE llx_c_paiement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER id; +ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement; +ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(entity, code); + +ALTER TABLE llx_c_payment_term ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; +ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(entity, code); + diff --git a/htdocs/install/mysql/tables/llx_c_paiement.key.sql b/htdocs/install/mysql/tables/llx_c_paiement.key.sql index 0d6686a774c..8c944e0c34d 100644 --- a/htdocs/install/mysql/tables/llx_c_paiement.key.sql +++ b/htdocs/install/mysql/tables/llx_c_paiement.key.sql @@ -1,5 +1,6 @@ -- ======================================================================== --- Copyright (C) 2012 Florian Henry +-- Copyright (C) 2012 Florian Henry +-- Copyright (C) 2017 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -16,4 +17,4 @@ -- -- ======================================================================== -ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(code); +ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(entity, code); diff --git a/htdocs/install/mysql/tables/llx_c_paiement.sql b/htdocs/install/mysql/tables/llx_c_paiement.sql index 1759af781f8..85e3cfb404d 100644 --- a/htdocs/install/mysql/tables/llx_c_paiement.sql +++ b/htdocs/install/mysql/tables/llx_c_paiement.sql @@ -1,7 +1,8 @@ -- ======================================================================== --- Copyright (C) 2001-2004 Rodolphe Quiedeville --- Copyright (C) 2004-2014 Laurent Destailleur --- Copyright (C) 2014 Alexandre Spangaro +-- Copyright (C) 2001-2004 Rodolphe Quiedeville +-- Copyright (C) 2004-2014 Laurent Destailleur +-- Copyright (C) 2014 Alexandre Spangaro +-- Copyright (C) 2017 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,6 +22,7 @@ create table llx_c_paiement ( id integer PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, -- multi company id code varchar(6) NOT NULL, libelle varchar(62), type smallint, -- 0: input money, 1: output money, 2: input and output, 3: other @@ -28,6 +30,3 @@ create table llx_c_paiement accountancy_code varchar(32) NULL, module varchar(32) NULL )ENGINE=innodb; - - - diff --git a/htdocs/install/mysql/tables/llx_c_payment_term.key.sql b/htdocs/install/mysql/tables/llx_c_payment_term.key.sql new file mode 100644 index 00000000000..e5977adf3cd --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_payment_term.key.sql @@ -0,0 +1,20 @@ +-- ======================================================================== +-- Copyright (C) 2012 Florian Henry +-- Copyright (C) 2017 Regis Houssin +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(entity, code); diff --git a/htdocs/install/mysql/tables/llx_c_payment_term.sql b/htdocs/install/mysql/tables/llx_c_payment_term.sql index a2d79af2502..6c55a6742b2 100644 --- a/htdocs/install/mysql/tables/llx_c_payment_term.sql +++ b/htdocs/install/mysql/tables/llx_c_payment_term.sql @@ -1,6 +1,7 @@ -- ============================================================================ --- Copyright (C) 2002-2003 Rodolphe Quiedeville --- Copyright (C) 2016 Laurent Destailleur +-- Copyright (C) 2002-2003 Rodolphe Quiedeville +-- Copyright (C) 2016 Laurent Destailleur +-- Copyright (C) 2017 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -19,14 +20,15 @@ create table llx_c_payment_term ( - rowid integer PRIMARY KEY, - code varchar(16), - sortorder smallint, - active tinyint DEFAULT 1, - libelle varchar(255), - libelle_facture text, - type_cdr tinyint, -- Type of change date reckoning. 1=Payment at end of current month, 2=the Nth of next month - nbjour smallint, - decalage smallint, - module varchar(32) NULL + rowid integer PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, -- multi company id + code varchar(16), + sortorder smallint, + active tinyint DEFAULT 1, + libelle varchar(255), + libelle_facture text, + type_cdr tinyint, -- Type of change date reckoning. 1=Payment at end of current month, 2=the Nth of next month + nbjour smallint, + decalage smallint, + module varchar(32) NULL )ENGINE=innodb; From ade915af5f0485bf2d2a468af55df11fd50f09b7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 15:32:08 +0200 Subject: [PATCH 02/24] New: add dictionnary sharing (multicompany) --- htdocs/admin/dict.php | 85 +++++++++++++------ htdocs/core/lib/admin.lib.php | 20 ++--- htdocs/core/lib/functions.lib.php | 17 +--- .../install/mysql/migration/5.0.0-6.0.0.sql | 6 +- .../mysql/tables/llx_c_paiement.key.sql | 2 +- .../install/mysql/tables/llx_c_paiement.sql | 2 +- .../mysql/tables/llx_c_payment_term.key.sql | 2 +- .../mysql/tables/llx_c_payment_term.sql | 2 +- 8 files changed, 83 insertions(+), 53 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 86652fd7614..1f27fdd9dad 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -54,6 +54,7 @@ $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $confirm=GETPOST('confirm','alpha'); $id=GETPOST('id','int'); $rowid=GETPOST('rowid','alpha'); +$entity=GETPOST('entity','int'); $allowed=$user->admin; if ($id == 7 && ! empty($user->rights->accounting->chartofaccount)) $allowed=1; // Tax page allowed to manager of chart account @@ -72,7 +73,7 @@ $active = 1; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if (empty($page) || $page == -1) { $page = 0 ; } $offset = $listlimit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; @@ -176,8 +177,8 @@ $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as $tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c"; $tabsql[10]= "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid"; $tabsql[11]= "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t"; -$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder FROM ".MAIN_DB_PREFIX.'c_payment_term AS c'; -$tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement AS c"; +$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = " . getEntity($tabname[12], 2); +$tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = " . getEntity($tabname[13], 2); $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1"; $tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format"; $tabsql[16]= "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel"; @@ -250,8 +251,8 @@ $tabfield[8] = "code,libelle,country_id,country".(! empty($conf->global->SOCIETE $tabfield[9] = "code,label,unicode"; $tabfield[10]= "country_id,country,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note"; $tabfield[11]= "element,source,code,libelle,position"; -$tabfield[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder"; -$tabfield[13]= "code,libelle,type,accountancy_code"; +$tabfield[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity"; +$tabfield[13]= "code,libelle,type,accountancy_code,entity"; $tabfield[14]= "code,libelle,price,organization,country_id,country"; $tabfield[15]= "code,libelle,width,height,unit"; $tabfield[16]= "code,libelle,sortorder"; @@ -324,8 +325,8 @@ $tabfieldinsert[8] = "code,libelle,fk_country".(! empty($conf->global->SOCIETE_S $tabfieldinsert[9] = "code_iso,label,unicode"; $tabfieldinsert[10]= "fk_pays,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note"; $tabfieldinsert[11]= "element,source,code,libelle,position"; -$tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder"; -$tabfieldinsert[13]= "code,libelle,type,accountancy_code"; +$tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity"; +$tabfieldinsert[13]= "code,libelle,type,accountancy_code,entity"; $tabfieldinsert[14]= "code,libelle,price,organization,fk_pays"; $tabfieldinsert[15]= "code,label,width,height,unit"; $tabfieldinsert[16]= "code,label,sortorder"; @@ -703,7 +704,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); } else if ($value == 'entity') { - $_POST[$listfieldvalue[$i]] = $conf->entity; + $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id], 2); } if ($i) $sql.=","; if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = '' @@ -751,7 +752,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); } else if ($field == 'entity') { - $_POST[$listfieldvalue[$i]] = $conf->entity; + $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id], 2); } if ($i) $sql.=","; $sql.= $field."="; @@ -760,6 +761,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $i++; } $sql.= " WHERE ".$rowidcol." = '".$rowid."'"; + $sql.= " AND entity = '".getEntity($tabname[$id], 2)."'"; dol_syslog("actionmodify", LOG_DEBUG); //print $sql; @@ -782,7 +784,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } - $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'"; + $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); dol_syslog("delete", LOG_DEBUG); $result = $db->query($sql); @@ -806,10 +808,10 @@ if ($action == $acts[0]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'"; + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($_GET["code"])."'"; + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); } $result = $db->query($sql); @@ -826,10 +828,10 @@ if ($action == $acts[1]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'"; + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($_GET["code"])."'"; + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); } $result = $db->query($sql); @@ -846,10 +848,10 @@ if ($action == 'activate_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'"; + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($_GET["code"])."'"; + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); } $result = $db->query($sql); @@ -866,10 +868,10 @@ if ($action == 'disable_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'"; + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($_GET["code"])."'"; + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); } $result = $db->query($sql); @@ -921,6 +923,7 @@ print "
\n"; $param = '&id='.$id; if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id; if ($search_code != '') $param.= '&search_code='.urlencode($search_country_id); +if ($entity >=0 ) $param.= '&entity='.$entity; $paramwithsearch = $param; if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; @@ -930,7 +933,7 @@ if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha'); // Confirmation de la suppression de la ligne if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'rowid='.$rowid.'&code='.urlencode($_GET["code"]).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); + print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'rowid='.$rowid.'&code='.urlencode(GETPOST('code')).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); } //var_dump($elementList); @@ -977,6 +980,7 @@ if ($id) if ($tabname[$id]) { $alabelisused=0; + $withentity=false; $fieldlist=explode(',',$tabfield[$id]); @@ -986,6 +990,11 @@ if ($id) print ''; foreach ($fieldlist as $field => $value) { + if ($fieldlist[$field] == 'entity') { + $withentity = getEntity($tabname[$id], 2); + continue; + } + // Determine le nom du champ par rapport aux noms possibles // dans les dictionnaires de donnees $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut @@ -1076,6 +1085,8 @@ if ($id) if ($id == 4) print ''; print ''; print ''; + if (! empty($withentity)) + print ''; print ''; print ''; print ''; @@ -1156,7 +1167,9 @@ if ($id) $filterfound=0; foreach ($fieldlist as $field => $value) { - $showfield=1; // By defaut + if ($fieldlist[$field] == 'entity') continue; + + $showfield=1; // By default if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } @@ -1198,6 +1211,8 @@ if ($id) print ''; foreach ($fieldlist as $field => $value) { + if ($fieldlist[$field] == 'entity') continue; + // Determine le nom du champ par rapport aux noms possibles // dans les dictionnaires de donnees $showfield=1; // By defaut @@ -1305,12 +1320,16 @@ if ($id) $error=$hookmanager->error; $errors=$hookmanager->errors; // Show fields - if (empty($reshook)) fieldList($fieldlist, $obj, $tabname[$id], 'edit'); + if (empty($reshook)) { + $withentity = fieldList($fieldlist, $obj, $tabname[$id], 'edit'); + } print ''; print '
'; print ''; print ''; + if (! empty($withentity)) + print ''; print ''; print ''; print ''; @@ -1325,11 +1344,19 @@ if ($id) if (empty($reshook)) { + $withentity=false; + foreach ($fieldlist as $field => $value) { - $showfield=1; + $showfield=1; $align="left"; - $valuetoshow=$obj->{$fieldlist[$field]}; + $valuetoshow=$obj->{$fieldlist[$field]}; + + if ($fieldlist[$field] == 'entity') { + $withentity = $valuetoshow; + continue; + } + if ($value == 'element') { $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow; @@ -1521,7 +1548,8 @@ if ($id) // If rowidcol not defined if (empty($rowidcol) || in_array($id, array(6,7,8,13,17,19,27))) $rowidcol='rowid'; $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((! empty($obj->{$rowidcol}) || $obj->{$rowidcol} == '0')?$obj->{$rowidcol}:(! empty($obj->code)?urlencode($obj->code):'')).'&code='.(! empty($obj->code)?urlencode($obj->code):''); - if ($param) $url .= '&'.$param; + if (! empty($param)) $url .= '&'.$param; + if (! empty($withentity)) $url .= '&entity='.$withentity; $url.='&'; // Favorite @@ -1664,8 +1692,15 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') $formcompany = new FormCompany($db); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); + $withentity=false; + foreach ($fieldlist as $field => $value) { + if ($fieldlist[$field] == 'entity') { + $withentity = $obj->{$fieldlist[$field]}; + continue; + } + if (in_array($fieldlist[$field], array('code', 'libelle', 'type')) && $tabname == MAIN_DB_PREFIX."c_actioncomm" && in_array($obj->type, array('system','systemauto'))) { $hidden = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''); @@ -1856,5 +1891,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') print ''; } } + + return $withentity; } diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 6a0336aab38..98515f0271e 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -813,7 +813,7 @@ function activateModule($value,$withdeps=1) } $result=$objMod->init(); // Enable module - if ($result <= 0) + if ($result <= 0) { $ret['errors'][]=$objMod->error; } @@ -825,7 +825,7 @@ function activateModule($value,$withdeps=1) { // Activation of modules this module depends on // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>"modModule1", 'FR'=>'modModule2') - foreach ($objMod->depend as $key => $modulestring) + foreach ($objMod->depends as $key => $modulestring) { if ((! is_numeric($key)) && $key != 'always' && $key != $mysoc->country_code) { @@ -848,19 +848,19 @@ function activateModule($value,$withdeps=1) break; } } - + if ($activate) { $ret['nbmodules']+=$resarray['nbmodules']; $ret['nbperms']+=$resarray['nbperms']; } - else + else { $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring); } } } - + if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith)) { // Desactivation des modules qui entrent en conflit @@ -879,12 +879,12 @@ function activateModule($value,$withdeps=1) } } - if (! count($ret['errors'])) + if (! count($ret['errors'])) { $ret['nbmodules']++; $ret['nbperms']+=count($objMod->rights); } - + return $ret; } @@ -1221,7 +1221,7 @@ function form_constantes($tableau, $strictw3c=0, $helptext='') if ($result) { $obj = $db->fetch_object($result); // Take first result of select - + // For avoid warning in strict mode if (empty($obj)) { @@ -1360,7 +1360,7 @@ function showModulesExludedForExternal($modules) //if (empty($conf->global->$moduleconst)) continue; if (! in_array($modulename,$listofmodules)) continue; //var_dump($modulename.'eee'.$langs->trans('Module'.$module->numero.'Name')); - + if ($i > 0) $text.=', '; else $text.=' '; $i++; @@ -1391,7 +1391,7 @@ function addDocumentModel($name, $type, $label='', $description='') $sql.= ($label?"'".$db->escape($label)."'":'null').", "; $sql.= (! empty($description)?"'".$db->escape($description)."'":"null"); $sql.= ")"; - + dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG); $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index de1cfafce0d..688624dc838 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -112,7 +112,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * 'email_template', 'event', * @param int $shared 0=Return id of current entity only, * 1=Return id of current entity + shared entities (default), - * 2=Return id of current entity OR $forceentity value (eg. dictionnary share) + * 2=Return id of current entity OR master entity 1 value (eg. dictionnary share) * @param int $forceentity Entity id * @return mixed Entity id(s) to use */ @@ -132,18 +132,9 @@ function getEntity($element=false, $shared=1, $forceentity=null) else { $out=''; - - if ($shared == 2) - { - $out.= $forceentity; - } - else - { - $addzero = array('user', 'usergroup', 'email_template', 'default_values'); - if (in_array($element, $addzero)) $out.= '0,'; - $out.= $conf->entity; - } - + $addzero = array('user', 'usergroup', 'email_template', 'default_values'); + if (in_array($element, $addzero)) $out.= '0,'; + $out.= $conf->entity; return $out; } } diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index ccc54b09026..996d218bf12 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -395,9 +395,11 @@ ALTER TABLE llx_usergroup_rights DROP INDEX fk_usergroup; ALTER TABLE llx_usergroup_rights ADD UNIQUE INDEX uk_usergroup_rights (entity, fk_usergroup, fk_id); ALTER TABLE llx_usergroup_rights ADD CONSTRAINT fk_usergroup_rights_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid); +ALTER TABLE llx_c_paiement DROP PRIMARY KEY ALTER TABLE llx_c_paiement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER id; ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement; -ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(entity, code); +ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(id, entity, code); +ALTER TABLE llx_c_payment_term DROP PRIMARY KEY ALTER TABLE llx_c_payment_term ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; -ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(entity, code); +ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(rowid, entity, code); diff --git a/htdocs/install/mysql/tables/llx_c_paiement.key.sql b/htdocs/install/mysql/tables/llx_c_paiement.key.sql index 8c944e0c34d..ad1930fba2e 100644 --- a/htdocs/install/mysql/tables/llx_c_paiement.key.sql +++ b/htdocs/install/mysql/tables/llx_c_paiement.key.sql @@ -17,4 +17,4 @@ -- -- ======================================================================== -ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(entity, code); +ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(id, entity, code); diff --git a/htdocs/install/mysql/tables/llx_c_paiement.sql b/htdocs/install/mysql/tables/llx_c_paiement.sql index 85e3cfb404d..60b4824748e 100644 --- a/htdocs/install/mysql/tables/llx_c_paiement.sql +++ b/htdocs/install/mysql/tables/llx_c_paiement.sql @@ -21,7 +21,7 @@ create table llx_c_paiement ( - id integer PRIMARY KEY, + id integer, entity integer DEFAULT 1 NOT NULL, -- multi company id code varchar(6) NOT NULL, libelle varchar(62), diff --git a/htdocs/install/mysql/tables/llx_c_payment_term.key.sql b/htdocs/install/mysql/tables/llx_c_payment_term.key.sql index e5977adf3cd..1bd86401945 100644 --- a/htdocs/install/mysql/tables/llx_c_payment_term.key.sql +++ b/htdocs/install/mysql/tables/llx_c_payment_term.key.sql @@ -17,4 +17,4 @@ -- -- ======================================================================== -ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(entity, code); +ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(rowid, entity, code); diff --git a/htdocs/install/mysql/tables/llx_c_payment_term.sql b/htdocs/install/mysql/tables/llx_c_payment_term.sql index 6c55a6742b2..4ecfdea6134 100644 --- a/htdocs/install/mysql/tables/llx_c_payment_term.sql +++ b/htdocs/install/mysql/tables/llx_c_payment_term.sql @@ -20,7 +20,7 @@ create table llx_c_payment_term ( - rowid integer PRIMARY KEY, + rowid integer, entity integer DEFAULT 1 NOT NULL, -- multi company id code varchar(16), sortorder smallint, From 3bddbd3bdf78b2de8562c44e59ee814caf227d4c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 18:20:27 +0200 Subject: [PATCH 03/24] Fix: better test --- htdocs/admin/dict.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 1f27fdd9dad..e873e570930 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -784,7 +784,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } - $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); dol_syslog("delete", LOG_DEBUG); $result = $db->query($sql); @@ -808,10 +808,10 @@ if ($action == $acts[0]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } $result = $db->query($sql); @@ -828,10 +828,10 @@ if ($action == $acts[1]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } $result = $db->query($sql); @@ -848,10 +848,10 @@ if ($action == 'activate_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } $result = $db->query($sql); @@ -868,10 +868,10 @@ if ($action == 'disable_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity >= 0 ? " AND entity = " . $entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); } $result = $db->query($sql); @@ -923,7 +923,7 @@ print "
\n"; $param = '&id='.$id; if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id; if ($search_code != '') $param.= '&search_code='.urlencode($search_country_id); -if ($entity >=0 ) $param.= '&entity='.$entity; +if ($entity != '') $param.= '&entity=' . (int)$entity; $paramwithsearch = $param; if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; From 73557151d295727c4c133b60e161d5a6e4b09d66 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 18:27:32 +0200 Subject: [PATCH 04/24] Fix: better test if entity equal 0 --- htdocs/admin/dict.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index e873e570930..8cb30d6dd6e 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -980,7 +980,7 @@ if ($id) if ($tabname[$id]) { $alabelisused=0; - $withentity=false; + $withentity=null; $fieldlist=explode(',',$tabfield[$id]); @@ -1085,7 +1085,7 @@ if ($id) if ($id == 4) print ''; print ''; print ''; - if (! empty($withentity)) + if (! is_null($withentity)) print ''; print ''; print ''; @@ -1328,7 +1328,7 @@ if ($id) print '
'; print ''; print ''; - if (! empty($withentity)) + if (! is_null($withentity)) print ''; print ''; print ''; @@ -1344,7 +1344,7 @@ if ($id) if (empty($reshook)) { - $withentity=false; + $withentity=null; foreach ($fieldlist as $field => $value) { @@ -1549,7 +1549,7 @@ if ($id) if (empty($rowidcol) || in_array($id, array(6,7,8,13,17,19,27))) $rowidcol='rowid'; $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((! empty($obj->{$rowidcol}) || $obj->{$rowidcol} == '0')?$obj->{$rowidcol}:(! empty($obj->code)?urlencode($obj->code):'')).'&code='.(! empty($obj->code)?urlencode($obj->code):''); if (! empty($param)) $url .= '&'.$param; - if (! empty($withentity)) $url .= '&entity='.$withentity; + if (! is_null($withentity)) $url .= '&entity='.$withentity; $url.='&'; // Favorite @@ -1692,7 +1692,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') $formcompany = new FormCompany($db); if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); - $withentity=false; + $withentity=null; foreach ($fieldlist as $field => $value) { From 0546f288232236ac71e7a432374d57f1dc118104 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 18:38:24 +0200 Subject: [PATCH 05/24] Fix: Travis error --- htdocs/admin/dict.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 8cb30d6dd6e..4f8b40e2259 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -784,7 +784,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } - $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "DELETE FROM ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : ''); dol_syslog("delete", LOG_DEBUG); $result = $db->query($sql); @@ -808,10 +808,10 @@ if ($action == $acts[0]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } $result = $db->query($sql); @@ -828,10 +828,10 @@ if ($action == $acts[1]) else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } $result = $db->query($sql); @@ -848,10 +848,10 @@ if ($action == 'activate_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } $result = $db->query($sql); @@ -868,10 +868,10 @@ if ($action == 'disable_favorite') else { $rowidcol="rowid"; } if ($rowid) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int)$entity: ''); + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag(GETPOST('code'))."'".($entity != '' ? " AND entity = " . (int) $entity : ''); } $result = $db->query($sql); @@ -923,7 +923,7 @@ print "
\n"; $param = '&id='.$id; if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id; if ($search_code != '') $param.= '&search_code='.urlencode($search_country_id); -if ($entity != '') $param.= '&entity=' . (int)$entity; +if ($entity != '') $param.= '&entity=' . (int) $entity; $paramwithsearch = $param; if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; From 4c70908ea2c9ec96893fb63b2bbc8a221e81c303 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 8 Jun 2017 18:52:01 +0200 Subject: [PATCH 06/24] Fix: entity field in combobox --- htdocs/core/class/html.form.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7a69172889e..01d28ecde24 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2743,7 +2743,8 @@ class Form $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; - $sql.= " WHERE active > 0"; + $sql.= " WHERE entity = " . getEntity('c_payment_term', 2); + $sql.= " AND active > 0"; $sql.= " ORDER BY sortorder"; $resql = $this->db->query($sql); @@ -2958,6 +2959,7 @@ class Form $sql = "SELECT id, code, libelle as label, type, active"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; //if ($active >= 0) $sql.= " WHERE active = ".$active; + $sql.= " WHERE entity = " . getEntity('c_paiement', 2); $resql = $this->db->query($sql); if ($resql) From fa58f0f3e84886dd8960acc715124334f65bf46c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 09:25:15 +0200 Subject: [PATCH 07/24] Fix: add entity filter --- dev/initdata/import-thirdparties.php | 44 ++-- htdocs/adherents/subscription.php | 2 +- htdocs/cashdesk/validation_verif.php | 22 +- htdocs/comm/propal/class/propal.class.php | 26 +-- htdocs/commande/class/commande.class.php | 18 +- htdocs/compta/bank/bankentries.php | 46 ++-- htdocs/compta/bank/class/account.class.php | 55 ++--- htdocs/compta/bank/various_payment/index.php | 10 +- htdocs/compta/charges/index.php | 26 +-- htdocs/compta/facture/card.php | 10 +- .../facture/class/facture-rec.class.php | 156 +++++++------- htdocs/compta/facture/class/facture.class.php | 7 +- .../facture/class/paymentterm.class.php | 11 +- htdocs/compta/paiement.php | 67 +++--- htdocs/compta/paiement/avalider.php | 5 +- .../cheque/class/remisecheque.class.php | 18 +- .../compta/paiement/class/paiement.class.php | 53 ++--- htdocs/compta/paiement/list.php | 22 +- htdocs/compta/resultat/clientfourn.php | 22 +- htdocs/compta/resultat/index.php | 26 +-- htdocs/compta/salaries/index.php | 16 +- htdocs/compta/sociales/card.php | 41 ++-- .../sociales/class/chargesociales.class.php | 12 +- .../class/paymentsocialcontribution.class.php | 7 +- htdocs/compta/sociales/payments.php | 12 +- htdocs/compta/tva/reglement.php | 12 +- htdocs/core/class/commoninvoice.class.php | 31 +-- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/class/translate.class.php | 61 +++--- htdocs/core/lib/functions.lib.php | 5 +- .../modules/facture/doc/pdf_crabe.modules.php | 38 ++-- htdocs/core/modules/modFacture.class.php | 26 +-- htdocs/core/modules/modSalaries.class.php | 10 +- htdocs/core/modules/modSociete.class.php | 4 +- .../modules/rapport/pdf_paiement.class.php | 3 +- .../rapport/pdf_paiement_fourn.class.php | 3 +- .../pdf/pdf_canelle.modules.php | 2 +- htdocs/don/card.php | 1 + htdocs/don/class/don.class.php | 6 +- htdocs/don/class/paymentdonation.class.php | 11 +- htdocs/expensereport/card.php | 197 +++++++++--------- .../class/expensereport.class.php | 97 ++++----- .../class/paymentexpensereport.class.php | 9 +- .../class/fournisseur.commande.class.php | 68 +++--- .../fourn/class/fournisseur.facture.class.php | 10 +- htdocs/fourn/class/paiementfourn.class.php | 33 +-- htdocs/fourn/facture/card.php | 2 +- htdocs/fourn/facture/paiement.php | 74 +++---- htdocs/loan/card.php | 1 + htdocs/loan/class/loanschedule.class.php | 1 + htdocs/loan/class/paymentloan.class.php | 1 + .../class/supplier_proposal.class.php | 80 +++---- 52 files changed, 780 insertions(+), 742 deletions(-) diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php index 08ad248ecc0..05fd0689102 100755 --- a/dev/initdata/import-thirdparties.php +++ b/dev/initdata/import-thirdparties.php @@ -21,7 +21,7 @@ /** * \file dev/initdata/import-thirdparties.php - * \brief Script example to insert thirdparties from a csv file. + * \brief Script example to insert thirdparties from a csv file. * To purge data, you can have a look at purge-data.php */ @@ -123,15 +123,15 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) if ($endlinenb && $i > $endlinenb) continue; $nboflines++; - + $object = new Societe($db); $object->state = $fields[6]; $object->client = $fields[7]; $object->fournisseur = $fields[8]; - + $object->name = $fields[13]?trim($fields[13]):$fields[0]; $object->name_alias = $fields[0]!=$fields[13]?trim($fields[0]):''; - + $object->address = trim($fields[14]); $object->zip = trim($fields[15]); $object->town = trim($fields[16]); @@ -149,7 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $condpayment = trim($fields[36]); if ($condpayment == 'A la commande') $condpayment = 'A réception de commande'; if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture'; - $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid'); + $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', getEntity('c_payment_term', 2)); if (empty($object->cond_reglement_id)) { print " - Error cant find payment mode for ".$condpayment."\n"; @@ -166,7 +166,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) // Set price level $object->price_level = 1; if ($labeltype == 'Revendeur') $object->price_level = 2; - + print "Process line nb ".$i.", name ".$object->name; @@ -182,7 +182,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) print " - Error in create result code = ".$ret." - ".$object->errorsToString(); $errorrecord++; } - else + else { print " - Creation OK with name ".$object->name." - id = ".$ret; } @@ -198,7 +198,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) if (! $errorrecord && $fields[3]) { $salesrep=new User($db); - + $tmp=explode(' ',$fields[3],2); $salesrep->firstname = trim($tmp[0]); $salesrep->lastname = trim($tmp[1]); @@ -206,7 +206,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) else $salesrep->login=strtolower($salesrep->firstname); $salesrep->login=preg_replace('/ /','',$salesrep->login); $salesrep->fetch(0,$salesrep->login); - + $result = $object->add_commercial($user, $salesrep->id); if ($result < 0) { @@ -217,14 +217,14 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) { print " - create link sale representative OK"; } - } - + } + dol_syslog("Add invoice contacts"); // Insert an invoice contact if there is an invoice email != standard email if (! $errorrecord && $fields[27] && $fields[26] != $fields[27]) { $ret1=$ret2=0; - + $contact = new Contact($db); $contact->lastname = $object->name; $contact->address=$object->address; @@ -233,7 +233,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $contact->country_id=$object->country_id; $contact->email=$fields[27]; $contact->socid=$object->id; - + $ret1=$contact->create($user); if ($ret1 > 0) { @@ -244,18 +244,18 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString(); $errorrecord++; } - else + else { print " - create contact OK"; } } - + dol_syslog("Add delivery contacts"); // Insert a delivery contact if (! $errorrecord && $fields[47]) { $ret1=$ret2=0; - + $contact2 = new Contact($db); $contact2->lastname = 'Service livraison - '.$fields[47]; $contact2->address = $fields[48]; @@ -264,10 +264,10 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid'); $contact2->note_public=$fields[54]; $contact2->socid=$object->id; - + // Extrafields $contact2->array_options['options_anazoneliv']=price2num($fields[53]); - + $ret1=$contact2->create($user); if ($ret1 > 0) { @@ -278,16 +278,16 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString(); $errorrecord++; } - else + else { print " - create contact OK"; } } - + print "\n"; - - if ($errorrecord) + + if ($errorrecord) { fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n"); $error++; // $errorrecord will be reset diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 21de6e305b5..30853e2dedf 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -442,7 +442,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && ! $paiement = new Paiement($db); $paiement->datepaye = $paymentdate; $paiement->amounts = $amounts; - $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement'); + $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',getEntity('c_paiement', 2)); $paiement->num_paiement = $num_chq; $paiement->note = $label; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 5e4ed9b028e..c28df626bc5 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -45,14 +45,14 @@ switch ($action) case 'valide_achat': $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; - + $company=new Societe($db); $company->fetch($thirdpartyid); $invoice=new Facture($db); $invoice->date=dol_now(); $invoice->type= Facture::TYPE_STANDARD; - + // To use a specific numbering module for POS, reset $conf->global->FACTURE_ADDON and other vars here // and restore values just after $sav_FACTURE_ADDON=''; @@ -68,7 +68,7 @@ switch ($action) // To force rule only for POS with mercure //... } - + $num=$invoice->getNextNumRef($company); // Restore save values @@ -76,7 +76,7 @@ switch ($action) { $conf->global->FACTURE_ADDON = $sav_FACTURE_ADDON; } - + $obj_facturation->numInvoice($num); $obj_facturation->getSetPaymentMode($_POST['hdnChoix']); @@ -137,7 +137,7 @@ switch ($action) $cond_reglement_id = 0; break; case 'ESP': - $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement'); + $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',getEntity('c_paiement', 2)); $cond_reglement_id = 0; $note .= $langs->trans("Cash")."\n"; $note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n"; @@ -146,11 +146,11 @@ switch ($action) $note .= '--------------------------------------'."\n\n"; break; case 'CB': - $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement'); + $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',getEntity('c_paiement', 2)); $cond_reglement_id = 0; break; case 'CHQ': - $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement'); + $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',getEntity('c_paiement', 2)); $cond_reglement_id = 0; break; } @@ -192,10 +192,10 @@ switch ($action) $invoiceline->remise_percent=$tab_liste[$i]['remise_percent']; $invoiceline->price=$tab_liste[$i]['price']; $invoiceline->subprice=$tab_liste[$i]['price']; - + $invoiceline->tva_tx=empty($vat_rate)?0:$vat_rate; // works even if vat_rate is '' $invoiceline->info_bits=empty($vat_npr)?0:$vat_npr; - + $invoiceline->total_ht=$tab_liste[$i]['total_ht']; $invoiceline->total_ttc=$tab_liste[$i]['total_ttc']; $invoiceline->total_tva=$tab_liste[$i]['total_vat']; @@ -224,7 +224,7 @@ switch ($action) { $warehouseidtodecrease=(isset($_SESSION["CASHDESK_ID_WAREHOUSE"])?$_SESSION["CASHDESK_ID_WAREHOUSE"]:0); if (! empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) $warehouseidtodecrease=0; // If a particular stock is defined, we disable choice - + $resultvalid=$invoice->validate($user, $obj_facturation->numInvoice(), 0); if ($warehouseidtodecrease > 0) @@ -264,7 +264,7 @@ switch ($action) { $warehouseidtodecrease=(isset($_SESSION["CASHDESK_ID_WAREHOUSE"])?$_SESSION["CASHDESK_ID_WAREHOUSE"]:0); if (! empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) $warehouseidtodecrease=0; // If a particular stock is defined, we disable choice - + $resultvalid=$invoice->validate($user, $obj_facturation->numInvoice(), 0); if ($warehouseidtodecrease > 0) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index fb1ac46cd91..dfebeae6893 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -254,7 +254,7 @@ class Propal extends CommonObject $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; $vat_src_code = ''; // May be defined into tva_tx - + $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr); $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr); @@ -433,7 +433,7 @@ class Propal extends CommonObject // Check parameters if ($type < 0) return -1; - + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -1270,8 +1270,8 @@ class Propal extends CommonObject $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."propal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; @@ -1392,17 +1392,17 @@ class Propal extends CommonObject return -1; } } - + /** * Load array lines - * + * * @param int $only_product Return only physical products * @return int <0 if KO, >0 if OK */ function fetch_lines($only_product=0) { $this->lines=array(); - + $sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,'; $sql.= ' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,'; $sql.= ' d.fk_unit,'; @@ -1422,7 +1422,7 @@ class Propal extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $num = $this->db->num_rows($result); - + $i = 0; while ($i < $num) { @@ -1489,9 +1489,9 @@ class Propal extends CommonObject //print "xx $i ".$this->lines[$i]->fk_product; $i++; } - + $this->db->free($result); - + return 1; } else @@ -2779,7 +2779,7 @@ class Propal extends CommonObject function availability($availability_id, $notrigger=0) { global $user; - + if ($this->statut >= self::STATUS_DRAFT) { $error=0; @@ -3352,9 +3352,9 @@ class Propal extends CommonObject function getLinesArray() { // TODO Duplicate with fetch_lines ? Wich one to keep ? - + $this->lines = array(); - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.vat_src_code, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 93df2f1aa0b..eafb406ba58 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -706,10 +706,10 @@ class Commande extends CommonOrder // Clean parameters $this->brouillon = 1; // set command as draft - + // $date_commande is deprecated $date = ($this->date_commande ? $this->date_commande : $this->date); - + // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate) if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date); else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); @@ -1468,7 +1468,7 @@ class Commande extends CommonOrder $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; $vat_src_code = ''; // May be defined into tva_tx - + $localtax1_tx=get_localtax($tva_tx,1,$this->thirdparty,$mysoc,$tva_npr); $localtax2_tx=get_localtax($tva_tx,2,$this->thirdparty,$mysoc,$tva_npr); @@ -1559,8 +1559,8 @@ class Commande extends CommonOrder $sql.= ', ca.code as availability_code, ca.label as availability_label'; $sql.= ', dr.code as demand_reason_code'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id)'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2) . ')'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id AND cr.entity = ' . getEntity('c_paiement', 2) . ')'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_input_reason = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; @@ -1798,7 +1798,7 @@ class Commande extends CommonOrder $line->product_type = $objp->product_type; $line->qty = $objp->qty; - $line->vat_src_code = $objp->vat_src_code; + $line->vat_src_code = $objp->vat_src_code; $line->tva_tx = $objp->tva_tx; $line->localtax1_tx = $objp->localtax1_tx; $line->localtax2_tx = $objp->localtax2_tx; @@ -3106,7 +3106,7 @@ class Commande extends CommonOrder $error = 0; dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG); - + $this->db->begin(); if (! $error && ! $notrigger) @@ -3381,7 +3381,7 @@ class Commande extends CommonOrder global $conf, $langs, $user; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $result=''; if (! empty($conf->expedition->enabled) && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; @@ -3418,7 +3418,7 @@ class Commande extends CommonOrder $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; diff --git a/htdocs/compta/bank/bankentries.php b/htdocs/compta/bank/bankentries.php index 5f6d5156b72..1f9f089270f 100644 --- a/htdocs/compta/bank/bankentries.php +++ b/htdocs/compta/bank/bankentries.php @@ -407,7 +407,7 @@ if ($id > 0 || ! empty($ref)) dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); dol_fiche_end(); - + /* * Buttons actions */ @@ -521,10 +521,10 @@ if (($id > 0 || ! empty($ref)) && ((string) $page == '')) $offset = $limit * $page; if ($page < 0) $page = 0; } -if ($page >= $nbtotalofpages) +if ($page >= $nbtotalofpages) { // If we made a search and result has low page than the page number we were on - $page = ($nbtotalofpages -1); + $page = ($nbtotalofpages -1); $offset = $limit * $page; if ($page < 0) $page = 0; } @@ -598,7 +598,7 @@ if ($resql) print ''; print ' '.$langs->trans("or").' '; print ''; - + // Show last bank statements $nbmax=15; // We accept to show last 15 receipts (so we can have more than one year) $liste=""; @@ -703,8 +703,8 @@ if ($resql) $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; - - if ($moreforfilter) + + if ($moreforfilter) { print '
'; print $moreforfilter; @@ -718,7 +718,7 @@ if ($resql) print ''."\n"; print ''; - if (! empty($arrayfields['b.rowid']['checked'])) + if (! empty($arrayfields['b.rowid']['checked'])) { print ''; // Ref - if (! empty($arrayfields['b.rowid']['checked'])) + if (! empty($arrayfields['b.rowid']['checked'])) { print '\n"; if (! $i) $totalarray['nbfield']++; } // Date value - if (! empty($arrayfields['b.datev']['checked'])) + if (! empty($arrayfields['b.datev']['checked'])) { print '\n"; @@ -1081,7 +1081,7 @@ if ($resql) } // Third party - if (! empty($arrayfields['bu.label']['checked'])) + if (! empty($arrayfields['bu.label']['checked'])) { print "'; - if (! $i) $totalarray['nbfield']++; - + if (! $i) $totalarray['nbfield']++; + // Action column print ''; - + // Ref print ''; - + // Ref supplier print ''; - + // Date if ($objp->df > 0 ) { @@ -470,13 +470,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie { print ''; } - + // Multicurrency - if (!empty($conf->multicurrency->enabled)) + if (!empty($conf->multicurrency->enabled)) { // Currency print '\n"; - + print ''; print ''; - + print ''; - + print ''; - + print ''; - + print '"; - + // Multicurrency - if (!empty($conf->multicurrency->enabled)) + if (!empty($conf->multicurrency->enabled)) { print '"; } - + print "\n"; $total+=$objp->total_ht; $total_ttc+=$objp->total_ttc; @@ -549,7 +549,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print "\n"; } print "
'; print ''; @@ -840,19 +840,19 @@ if ($resql) $sign = 1; $totalarray=array(); - while ($i < min($num,$limit)) + while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); // If we are in a situation where we need/can show balance, we calculate the start of balance if (! $balancecalculated && ! empty($arrayfields['balance']['checked']) && $mode_balance_ok) { - if (! $account) + if (! $account) { dol_print_error('', 'account is not defined but $mode_balance_ok is true'); exit; } - + //Loop on each record $sign = 1; $i = 0; @@ -875,7 +875,7 @@ if ($resql) } } else dol_print_error($db); - + $balancecalculated=true; } @@ -896,7 +896,7 @@ if ($resql) print '
'; print "rowid.'">'.img_object($langs->trans("ShowPayment").': '.$objp->rowid, 'account', 'class="classfortooltip"').' '.$objp->rowid."   "; @@ -908,14 +908,14 @@ if ($resql) if (! empty($arrayfields['description']['checked'])) { print ""; - + //print "rowid."&account=".$objp->fk_account."\">"; $reg=array(); preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthee on tente recherche de traduction if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]); else print dol_trunc($objp->label,40); //print " "; - + // Add links after description $links = $bankaccountstatic->get_url($objp->rowid); $cachebankaccount=array(); @@ -1040,14 +1040,14 @@ if ($resql) } // Date ope - if (! empty($arrayfields['b.dateo']['checked'])) + if (! empty($arrayfields['b.dateo']['checked'])) { print ''.dol_print_date($db->jdate($objp->do),"day")."'; print ''.dol_print_date($db->jdate($objp->dv),"day").""; @@ -1063,10 +1063,10 @@ if ($resql) } // Payment type - if (! empty($arrayfields['type']['checked'])) + if (! empty($arrayfields['type']['checked'])) { print ''; - $labeltype=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$langs->getLabelFromKey($db,$objp->fk_type,'c_paiement','code','libelle'); + $labeltype=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$langs->getLabelFromKey($db,$objp->fk_type,'c_paiement','code','libelle','',getEntity('c_paiement', 2)); if ($labeltype == 'SOLD') print ' '; //$langs->trans("InitialBankBalance"); else print $labeltype; print ""; if ($objp->url_id) @@ -1106,7 +1106,7 @@ if ($resql) } // Bank account - if (! empty($arrayfields['ba.ref']['checked'])) + if (! empty($arrayfields['ba.ref']['checked'])) { print ''; print $bankaccount->getNomUrl(1); @@ -1174,7 +1174,7 @@ if ($resql) print ''.$objp->num_releve.''; } else if ($action == 'reconcile') - { + { print 'rowid])?' checked':'').'>'; } } @@ -1229,8 +1229,8 @@ if ($resql) } } print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 43b6dace19c..5330eca86a4 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -39,7 +39,7 @@ class Account extends CommonObject public $element = 'bank_account'; public $table_element = 'bank_account'; public $picto = 'account'; - + /** * @var int Use id instead of rowid * @deprecated @@ -411,8 +411,9 @@ class Account extends CommonObject if (is_numeric($oper)) // Clean oper to have a code instead of a rowid { - $sql ="SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; - $sql.=" WHERE id=".$oper; + $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; + $sql.= " WHERE id=".$oper; + $sql.= " AND entity = " . getEntity('c_payement_term', 2) . ")"; $resql=$this->db->query($sql); if ($resql) { @@ -538,7 +539,7 @@ class Account extends CommonObject $now=dol_now(); $this->db->begin(); - + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account ("; $sql.= "datec"; $sql.= ", ref"; @@ -619,14 +620,14 @@ class Account extends CommonObject $result=$this->insertExtraFields(); if ($result < 0) $error++; } - + if (! $error && ! $notrigger) { // Call trigger $result=$this->call_trigger('BANKACCOUNT_CREATE',$user); if ($result < 0) $error++; // End call triggers - } + } } else { @@ -670,9 +671,9 @@ class Account extends CommonObject global $langs,$conf, $hookmanager; $error=0; - + $this->db->begin(); - + // Clean parameters $this->state_id = ($this->state_id?$this->state_id:$this->state_id); $this->country_id = ($this->country_id?$this->country_id:$this->country_id); @@ -739,7 +740,7 @@ class Account extends CommonObject if ($result < 0) $error++; } } - + if (! $error && ! $notrigger) { // Call trigger @@ -754,7 +755,7 @@ class Account extends CommonObject $this->error=$this->db->lasterror(); dol_print_error($this->db); } - + if (! $error) { $this->db->commit(); @@ -906,7 +907,7 @@ class Account extends CommonObject $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_update = $this->db->jdate($obj->date_update); - + // Retreive all extrafield for thirdparty // fetch optionals attributes and labels require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); @@ -983,15 +984,15 @@ class Account extends CommonObject global $conf; $error=0; - + $this->db->begin(); - + // Delete link between tag and bank account if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; $sql.= " WHERE fk_account = ".$this->id; - + $resql = $this->db->query($sql); if (!$resql) { @@ -999,15 +1000,15 @@ class Account extends CommonObject $this->error = "Error ".$this->db->lasterror(); } } - + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE rowid = ".$this->rowid; - + dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) + if ($result) { // Remove extrafields if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used @@ -1020,13 +1021,13 @@ class Account extends CommonObject } } } - else + else { $error++; $this->error = "Error ".$this->db->lasterror(); - } + } } - + if (! $error) { $this->db->commit(); @@ -1433,7 +1434,7 @@ class Account extends CommonObject * - DeskCode * * Some countries show less or more bank account properties to the user - * + * * @param int $includeibanbic 1=Return also key for IBAN and BIC * @return array * @see useDetailedBBAN @@ -1554,7 +1555,7 @@ class AccountLine extends CommonObject var $element='bank'; var $table_element='bank'; var $picto = 'generic'; - + var $id; var $ref; var $datec; @@ -1842,7 +1843,7 @@ class AccountLine extends CommonObject function update_conciliation(User $user, $cat) { global $conf; - + $this->db->begin(); // Check statement field @@ -1854,7 +1855,7 @@ class AccountLine extends CommonObject return -1; } } - + $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET"; $sql.= " rappro = 1"; $sql.= ", num_releve = '".$this->db->escape($this->num_releve)."'"; @@ -2042,7 +2043,7 @@ class AccountLine extends CommonObject return $result; } - + /** * Return label of status (activity, closed) * @@ -2053,7 +2054,7 @@ class AccountLine extends CommonObject { return $this->LibStatut($this->status,$mode); } - + /** * Renvoi le libelle d'un statut donne * @@ -2097,6 +2098,6 @@ class AccountLine extends CommonObject if ($statut==1) return $langs->trans("InActivity").' '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"'); }*/ } - + } diff --git a/htdocs/compta/bank/various_payment/index.php b/htdocs/compta/bank/various_payment/index.php index 39c6d27be4f..5cea33d5baa 100644 --- a/htdocs/compta/bank/various_payment/index.php +++ b/htdocs/compta/bank/various_payment/index.php @@ -92,7 +92,7 @@ $sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,"; $sql.= " pst.code as payment_code"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE v.entity = ".$conf->entity; @@ -142,9 +142,9 @@ if ($result) print ''; print ''; print ''; - + print_barre_liste($langs->trans("VariousPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit); - + print '
'; print ''."\n"; @@ -188,13 +188,13 @@ if ($result) $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; print ''; - + print "\n"; while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); - + print ''; $variousstatic->id=$obj->rowid; diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index d494f778df0..715d1c96627 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -92,7 +92,7 @@ print ''; print ''; print ''; -if ($mode != 'sconly') +if ($mode != 'sconly') { $center=($year?''.img_previous($langs->trans("Previous"), 'class="valignbottom"')." ".$langs->trans("Year").' '.$year.' '.img_next($langs->trans("Next"), 'class="valignbottom"')."":""); print_barre_liste($title,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$center,$num,$totalnboflines, 'title_accountancy', 0, '', '', $limit, 1); @@ -139,7 +139,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement', 2); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE cs.fk_type = c.id"; @@ -260,7 +260,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."tva as pv"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pv.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE pv.entity = ".$conf->entity; if ($year > 0) { @@ -294,7 +294,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $total = $total + $obj->amount; - + print ''; print ''."\n"; @@ -309,12 +309,12 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) // Date print '\n"; - + // Type payment print ''; - + // Account if (! empty($conf->banque->enabled)) { @@ -333,7 +333,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) else print ' '; print ''; } - + // Paid print '"; print "\n"; @@ -424,7 +424,7 @@ while($j<$numlt) $total = $total + $obj->amount; - + print ''; print ''."\n"; @@ -465,7 +465,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $sal = new PaymentSalary($db); print "
"; - + print_fiche_titre($langs->trans("SalariesPayments").($year?' ('.$langs->trans("Year").' '.$year.')':''), '', ''); $sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, s.fk_bank, u.salary as current_salary,"; @@ -474,7 +474,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement', 2); $sql.= " , ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE s.entity IN (".getEntity('user').")"; $sql.= " AND u.rowid = s.fk_user"; @@ -508,7 +508,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $total = $total + $obj->amount; - + print ''; print ''."\n"; @@ -527,7 +527,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) print ''; - + // Account if (! empty($conf->banque->enabled)) { @@ -546,7 +546,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) else print ' '; print ''; } - + // Paid print '"; print "\n"; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e9be0a0b962..319369fa304 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -649,9 +649,12 @@ if (empty($reshook)) { // If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT - $sql = 'SELECT SUM(pf.amount) as total_paiements - FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p - WHERE pf.fk_facture = '.$object->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid ORDER BY p.datep, p.tms'; + $sql = 'SELECT SUM(pf.amount) as total_paiements'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p'; + $sql.= ' WHERE pf.fk_facture = '.$object->id; + $sql.= ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; + $sql.= ' AND p.entity = ' . getEntity('c_paiement', 2); + $sql.= ' ORDER BY p.datep, p.tms'; $resql = $db->query($sql); $res = $db->fetch_object($resql); @@ -3693,6 +3696,7 @@ else if ($id > 0 || ! empty($ref)) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; + $sql .= ' AND c.entity = ' . getEntity('c_paiement', 2); $sql .= ' ORDER BY p.datep, p.tms'; $result = $db->query($sql); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 6bc88e47490..6e7f2580859 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -43,7 +43,7 @@ class FactureRec extends CommonInvoice public $table_element_line='facturedet_rec'; public $fk_element='fk_facture'; public $picto='bill'; - + var $entity; var $number; var $date; @@ -58,7 +58,7 @@ class FactureRec extends CommonInvoice var $date_when; var $nb_gen_done; var $nb_gen_max; - + var $rang; var $special_code; @@ -91,20 +91,20 @@ class FactureRec extends CommonInvoice // Clean parameters $this->titre=trim($this->titre); $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice; - + // No frequency defined then no next date to execution - if (empty($this->frequency)) + if (empty($this->frequency)) { $this->frequency=0; $this->date_when=NULL; } - - + + $this->frequency=abs($this->frequency); $this->nb_gen_done=0; $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max; $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate; - + $this->db->begin(); // Charge facture modele @@ -197,7 +197,7 @@ class FactureRec extends CommonInvoice $error++; } } - + // Add object linked if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) { @@ -210,7 +210,7 @@ class FactureRec extends CommonInvoice $error++; } } - } + } if ($error) { @@ -259,8 +259,8 @@ class FactureRec extends CommonInvoice $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; //$sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'"; if ($rowid) $sql.= ' WHERE f.rowid='.$rowid; elseif ($ref) $sql.= " WHERE f.titre='".$this->db->escape($ref)."'"; @@ -268,7 +268,7 @@ class FactureRec extends CommonInvoice if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'"; */ - + $result = $this->db->query($sql); if ($result) { @@ -361,8 +361,8 @@ class FactureRec extends CommonInvoice { return $this->fetch_lines(); } - - + + /** * Recupere les lignes de factures predefinies dans this->lines * @@ -386,7 +386,7 @@ class FactureRec extends CommonInvoice $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' WHERE l.fk_facture = '.$this->id; $sql.= ' ORDER BY l.rang'; - + dol_syslog('FactureRec::fetch_lines', LOG_DEBUG); $result = $this->db->query($sql); if ($result) @@ -431,7 +431,7 @@ class FactureRec extends CommonInvoice $line->special_code = $objp->special_code; $line->fk_unit = $objp->fk_unit; $line->fk_contract_line = $objp->fk_contract_line; - + // Ne plus utiliser $line->price = $objp->price; $line->remise = $objp->remise; @@ -463,12 +463,12 @@ class FactureRec extends CommonInvoice function delete($user, $notrigger=0, $idwarehouse=-1) { $rowid=$this->id; - + dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG); - + $error=0; $this->db->begin(); - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid; dol_syslog($sql); if ($this->db->query($sql)) @@ -486,7 +486,7 @@ class FactureRec extends CommonInvoice $this->error=$this->db->lasterror(); $error=-2; } - + if (! $error) { $this->db->commit(); @@ -525,7 +525,7 @@ class FactureRec extends CommonInvoice function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null) { global $mysoc; - + $facid=$this->id; dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG); @@ -578,7 +578,7 @@ class FactureRec extends CommonInvoice $total_ttc = $tabprice[2]; $total_localtax1=$tabprice[9]; $total_localtax2=$tabprice[10]; - + $product_type=$type; if ($fk_product) { @@ -679,12 +679,12 @@ class FactureRec extends CommonInvoice function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null) { global $mysoc; - + $facid=$this->id; - + dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; - + // Check parameters if ($type < 0) return -1; @@ -709,7 +709,7 @@ class FactureRec extends CommonInvoice $txtva=price2num($txtva); $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); - + if ($price_base_type=='HT') { $pu=$pu_ht; @@ -718,7 +718,7 @@ class FactureRec extends CommonInvoice { $pu=$pu_ttc; } - + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -730,7 +730,7 @@ class FactureRec extends CommonInvoice $total_ttc = $tabprice[2]; $total_localtax1=$tabprice[9]; $total_localtax2=$tabprice[10]; - + $product_type=$type; if ($fk_product) { @@ -738,7 +738,7 @@ class FactureRec extends CommonInvoice $result=$product->fetch($fk_product); $product_type=$product->type; } - + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET "; $sql.= "fk_facture = '".$facid."'"; $sql.= ", label=".(! empty($label)?"'".$this->db->escape($label)."'":"null"); @@ -778,12 +778,12 @@ class FactureRec extends CommonInvoice return -1; } } - } - - + } + + /** - * Return the next date of - * + * Return the next date of + * * @return timestamp false if KO, timestamp if OK */ function getNextDate() @@ -791,27 +791,27 @@ class FactureRec extends CommonInvoice if (empty($this->date_when)) return false; return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency); } - + /** * Create all recurrents invoices (for all entities if multicompany is used). * A result may also be provided into this->output. - * - * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found. - * - * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) + * + * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found. + * + * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) */ function createRecurringInvoices() { global $conf, $langs, $db, $user; - + $langs->load("bills"); - + $nb_create=0; - + $now = dol_now(); $tmparray=dol_getdate($now); $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day - + dol_syslog("createRecurringInvoices"); $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec'; $sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency @@ -819,30 +819,30 @@ class FactureRec extends CommonInvoice $sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)'; $sql.= $db->order('entity', 'ASC'); //print $sql;exit; - + $resql = $db->query($sql); if ($resql) { $i=0; $num = $db->num_rows($resql); - + if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n"; else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound"); - + $saventity = $conf->entity; - + while ($i < $num) // Loop on each template invoice { $line = $db->fetch_object($resql); $db->begin(); - + $facturerec = new FactureRec($db); $facturerec->fetch($line->rowid); - + // Set entity context $conf->entity = $facturerec->entity; - + dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity); $error=0; @@ -850,12 +850,12 @@ class FactureRec extends CommonInvoice $facture = new Facture($db); $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice - + $facture->type = self::TYPE_STANDARD; $facture->brouillon = 1; $facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later. $facture->socid = $facturerec->socid; - + $invoiceidgenerated = $facture->create($user); if ($invoiceidgenerated <= 0) { @@ -888,16 +888,16 @@ class FactureRec extends CommonInvoice $i++; } - + $conf->entity = $saventity; // Restore entity context } else dol_print_error($db); - + $this->output=trim($this->output); - + return $error?$error:0; } - + /** * Return clicable name (with picto eventually) * @@ -914,13 +914,13 @@ class FactureRec extends CommonInvoice $result=''; $label=$langs->trans("ShowInvoice").': '.$this->ref; - + $url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id; - + if ($short) return $url; - + $picto='bill'; - + $link = ''; $linkend=''; @@ -952,7 +952,7 @@ class FactureRec extends CommonInvoice // Load array of products prodids $num_prods = 0; $prodids = array(); - + $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " WHERE entity IN (".getEntity('product').")"; @@ -1065,7 +1065,7 @@ class FactureRec extends CommonInvoice $this->lines[$xnbp]=$line; $xnbp++; } - + $this->usenewprice = 1; } @@ -1085,7 +1085,7 @@ class FactureRec extends CommonInvoice return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } - + /** * Update frequency and unit * @@ -1109,12 +1109,12 @@ class FactureRec extends CommonInvoice $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null'); - if (!empty($unit)) + if (!empty($unit)) { $sql.= ', unit_frequency = \''.$this->db->escape($unit).'\''; } $sql.= ' WHERE rowid = '.$this->id; - + dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG); if ($this->db->query($sql)) { @@ -1128,7 +1128,7 @@ class FactureRec extends CommonInvoice return -1; } } - + /** * Update the next date of execution * @@ -1161,7 +1161,7 @@ class FactureRec extends CommonInvoice return -1; } } - + /** * Update the maximum period * @@ -1175,9 +1175,9 @@ class FactureRec extends CommonInvoice dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR); return -1; } - + if (empty($nb)) $nb=0; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= ' SET nb_gen_max = '.$nb; $sql.= ' WHERE rowid = '.$this->id; @@ -1194,7 +1194,7 @@ class FactureRec extends CommonInvoice return -1; } } - + /** * Update the auto validate invoice * @@ -1208,7 +1208,7 @@ class FactureRec extends CommonInvoice dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR); return -1; } - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= ' SET auto_validate = '.$validate; $sql.= ' WHERE rowid = '.$this->id; @@ -1235,7 +1235,7 @@ class FactureRec extends CommonInvoice */ class FactureLigneRec extends CommonInvoiceLine { - + /** * Delete line in database * @@ -1244,11 +1244,11 @@ class FactureLigneRec extends CommonInvoiceLine function delete() { global $conf,$langs,$user; - + $error=0; - + $this->db->begin(); - + // Call trigger /*$result=$this->call_trigger('LINEBILLREC_DELETE',$user); if ($result < 0) @@ -1257,8 +1257,8 @@ class FactureLigneRec extends CommonInvoiceLine return -1; }*/ // End call triggers - - + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); if ($this->db->query($sql) ) @@ -1273,5 +1273,5 @@ class FactureLigneRec extends CommonInvoiceLine return -1; } } - + } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 880832f80e1..b7042404262 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1153,8 +1153,8 @@ class Facture extends CommonInvoice $sql.= ', f.fk_incoterms, f.location_incoterms'; $sql.= ", i.libelle as libelle_incoterms"; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON f.fk_incoterms = i.rowid'; $sql.= ' WHERE f.entity = '.$conf->entity; if ($rowid) $sql.= " AND f.rowid=".$rowid; @@ -3112,6 +3112,7 @@ class Facture extends CommonInvoice //$sql.= ' WHERE pf.'.$field.' = 1'; $sql.= ' AND pf.'.$field2.' = p.rowid'; $sql.= ' AND p.fk_paiement = t.id'; + $sql.= ' AND t.entity = ' . getEntity('c_paiement', 2); if ($filtertype) $sql.=" AND t.code='PRE'"; dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG); @@ -3594,7 +3595,7 @@ class Facture extends CommonInvoice if (! $error) { // Force payment mode of invoice to withdraw - $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement'); + $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', getEntity('c_paiement', 2)); if ($payment_mode_id > 0) { $result=$this->setPaymentMethods($payment_mode_id); diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index 2899e3fae56..3f0c2bcf732 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -93,6 +93,7 @@ class PaymentTerm // extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_payment_term("; $sql.= "rowid,"; + $sql.= "entity,"; $sql.= "code,"; $sql.= "sortorder,"; $sql.= "active,"; @@ -106,6 +107,7 @@ class PaymentTerm // extends CommonObject $sql.= ") VALUES ("; $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->rowid."'").","; + $sql.= " ".(! isset($this->entity)?getEntity('c_payment_term', 2):"'".$this->entity."'").","; $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; $sql.= " ".(! isset($this->sortorder)?'NULL':"'".$this->sortorder."'").","; $sql.= " ".(! isset($this->active)?'NULL':"'".$this->active."'").","; @@ -172,6 +174,7 @@ class PaymentTerm // extends CommonObject global $langs; $sql = "SELECT"; $sql.= " t.rowid,"; + $sql.= " t.entity"; $sql.= " t.code,"; $sql.= " t.sortorder,"; @@ -185,6 +188,7 @@ class PaymentTerm // extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; $sql.= " WHERE t.rowid = ".$id; + $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -234,6 +238,7 @@ class PaymentTerm // extends CommonObject $sql.= " t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; $sql.= " WHERE t.code = 'RECEP'"; + $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); dol_syslog(get_class($this)."::getDefaultId", LOG_DEBUG); $resql=$this->db->query($sql); @@ -296,7 +301,8 @@ class PaymentTerm // extends CommonObject $sql.= " decalage=".(isset($this->decalage)?$this->decalage:"null").""; - $sql.= " WHERE rowid=".$this->id; + $sql.= " WHERE rowid = " . $this->id; + $sql.= " AND entity = " . getEntity('c_payment_term', 2); $this->db->begin(); @@ -352,7 +358,8 @@ class PaymentTerm // extends CommonObject $error=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_payment_term"; - $sql.= " WHERE rowid=".$this->id; + $sql.= " WHERE rowid = " . $this->id; + $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); $this->db->begin(); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index cdc5eb2e545..023f94c5eef 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -99,7 +99,7 @@ if (empty($reshook)) $atleastonepaymentnotnull = 0; // Generate payment array and check if there is payment higher than invoice and payment date before invoice date - $tmpinvoice=new Facture($db); + $tmpinvoice=new Facture($db); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') @@ -188,7 +188,7 @@ if (empty($reshook)) setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors'); $error++; } - + // Check if payments in both currency if ($totalpayment > 0 && $multicurrency_totalpayment > 0) { @@ -228,7 +228,7 @@ if (empty($reshook)) $newvalue = price2num($value,'MT'); $amounts[$key] = -$newvalue; } - + foreach ($multicurrency_amounts as $key => $value) // How payment is dispatch { $newvalue = price2num($value,'MT'); @@ -251,7 +251,7 @@ if (empty($reshook)) $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement'); + $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',getEntity('c_paiement', 2)); $paiement->num_paiement = GETPOST('num_paiement'); $paiement->note = GETPOST('comment'); @@ -389,7 +389,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie { subJson[n["name"]] = n["value"]; }); - + return subJson; } function callForResult(imgId) @@ -516,31 +516,31 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print ''; - + print '
'.dol_print_date($db->jdate($obj->dm),'day').''.dol_print_date($db->jdate($obj->dm),'day')."'; if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' '; print $obj->num_payment.''.price($obj->amount)."
'.dol_print_date($db->jdate($obj->dm),'day').'
'.dol_print_date($db->jdate($obj->dateep),'day').''; if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' '; print $obj->num_payment.''.price($obj->amount)."
'.$langs->trans('Comments').''; print '
'; dol_fiche_end(); - + /* * List of unpaid invoices */ - + $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type, '; $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; } - + $sql.= ' WHERE f.entity = '.$conf->entity; $sql.= ' AND (f.fk_soc = '.$facture->socid; - + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; } - + $sql.= ') AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) @@ -577,7 +577,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie //print '
'; print '
'; print ''; - + print ''; print ''; print ''; @@ -602,7 +602,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie while ($i < $num) { $objp = $db->fetch_object($resql); - + $soc = new Societe($db); $soc->fetch($objp->socid); @@ -614,9 +614,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $deposits=$invoice->getSumDepositsUsed(); $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); - + // Multicurrency Price - if (!empty($conf->multicurrency->enabled)) + if (!empty($conf->multicurrency->enabled)) { $multicurrency_payment = $invoice->getSommePaiement(1); $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1); @@ -624,7 +624,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT'); $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT'); } - + print ''; print '\n"; - + // Currency if (!empty($conf->multicurrency->enabled)) print '\n"; - + // Multicurrency Price - if (!empty($conf->multicurrency->enabled)) + if (!empty($conf->multicurrency->enabled)) { print ''; - + // Multicurrency Price print ''; - + // Multicurrency Price print ''; } - + // Price print ''; - + // Received or paid back print '"; // Multicurrency Price - if (! empty($conf->multicurrency->enabled)) + if (! empty($conf->multicurrency->enabled)) { print ''; print '\n"; print '\n"; diff --git a/htdocs/compta/paiement/avalider.php b/htdocs/compta/paiement/avalider.php index 0fe627cf7ac..be0e96bb4c1 100644 --- a/htdocs/compta/paiement/avalider.php +++ b/htdocs/compta/paiement/avalider.php @@ -71,7 +71,8 @@ if ($socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid"; } $sql.= " WHERE p.fk_paiement = c.id"; -$sql.= " AND p.entity = ".$conf->entity; +$sql.= " AND p.entity = " . $conf->entity; +$sql.= " AND c.entity = " . getEntity('c_paiement', 2); if ($socid) { $sql.= " AND f.fk_soc = ".$socid; @@ -111,7 +112,7 @@ if ($resql) while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - + print ''; print ''; print '\n"; diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 20afa14e0ca..45d64cf547e 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -36,7 +36,7 @@ class RemiseCheque extends CommonObject public $element='chequereceipt'; public $table_element='bordereau_cheque'; public $picto = 'payment'; - + var $num; var $intitule; //! Numero d'erreur Plage 1024-1279 @@ -345,7 +345,7 @@ class RemiseCheque extends CommonObject $this->errno = 0; $this->db->begin(); - + $numref = $this->getNextNumRef(); if ($this->errno == 0 && $numref) @@ -716,7 +716,7 @@ class RemiseCheque extends CommonObject * * @param int $bank_id Id of bank transaction line concerned * @param date $rejection_date Date to use on the negative payment - * @return int Id of negative payment line created + * @return int Id of negative payment line created */ function rejectCheck($bank_id, $rejection_date) { @@ -727,19 +727,19 @@ class RemiseCheque extends CommonObject $bankline = new AccountLine($db); $bankline->fetch($bank_id); - + /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log. if ($bankline->rappro) { $this->error='ActionRefusedLineAlreadyConciliated'; return -1; }*/ - + $this->db->begin(); - + // Not conciliated, we can delete it - //$bankline->delete($user); // We delete - + //$bankline->delete($user); // We delete + $bankaccount = $payment->fk_account; // Get invoices list to reopen them @@ -753,7 +753,7 @@ class RemiseCheque extends CommonObject $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; - $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement'); + $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',getEntity('c_paiement', 2)); $rejectedPayment->num_paiement = $payment->numero; while($obj = $db->fetch_object($resql)) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 03a7759e52c..0c66873647a 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -38,7 +38,7 @@ class Paiement extends CommonObject public $element='payment'; public $table_element='paiement'; public $picto = 'payment'; - + var $facid; var $datepaye; /** @@ -65,7 +65,7 @@ class Paiement extends CommonObject // fk_paiement dans llx_paiement_facture est le rowid du paiement var $fk_paiement; // Type of paiment - + /** * Constructor * @@ -93,6 +93,7 @@ class Paiement extends CommonObject $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; $sql.= ' WHERE p.fk_paiement = c.id'; + $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); if ($id > 0) $sql.= ' AND p.rowid = '.$id; else if ($ref) @@ -153,14 +154,14 @@ class Paiement extends CommonObject $error = 0; $way = $this->getWay(); - + $now=dol_now(); - + // Clean parameters $totalamount = 0; $totalamount_converted = 0; $atleastonepaymentnotnull = 0; - + if ($way == 'dolibarr') { $amounts = &$this->amounts; @@ -171,22 +172,22 @@ class Paiement extends CommonObject $amounts = &$this->multicurrency_amounts; $amounts_to_update = &$this->amounts; } - + foreach ($amounts as $key => $value) // How payment is dispatch { $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way); $totalamount_converted += $value_converted; $amounts_to_update[$key] = price2num($value_converted, 'MT'); - + $newvalue = price2num($value,'MT'); $amounts[$key] = $newvalue; $totalamount += $newvalue; if (! empty($newvalue)) $atleastonepaymentnotnull++; } - + $totalamount = price2num($totalamount); $totalamount_converted = price2num($totalamount_converted); - + // Check parameters if (empty($totalamount) && empty($atleastonepaymentnotnull)) // We accept negative amounts for withdraw reject but not empty arrays { @@ -211,7 +212,7 @@ class Paiement extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_creat)"; $sql.= " VALUES (".$conf->entity.", '".$ref."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")"; - + dol_syslog(get_class($this)."::Create insert paiement", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -227,7 +228,7 @@ class Paiement extends CommonObject $amount = price2num($amount); $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)'; $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')'; - + dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -279,7 +280,7 @@ class Paiement extends CommonObject if ($invoice->type == Facture::TYPE_DEPOSIT) { $amount_ht = $amount_tva = $amount_ttc = array(); - + // Loop on each vat rate $i = 0; foreach ($invoice->lines as $line) @@ -292,20 +293,20 @@ class Paiement extends CommonObject $i ++; } } - + // Insert one discount by VAT rate category $discount = new DiscountAbsolute($this->db); $discount->description = '(DEPOSIT)'; $discount->fk_soc = $invoice->socid; $discount->fk_facture_source = $invoice->id; - + foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht[$tva_tx]); $discount->amount_tva = abs($amount_tva[$tva_tx]); $discount->amount_ttc = abs($amount_ttc[$tva_tx]); $discount->tva_tx = abs($tva_tx); - + $result = $discount->create($user); if ($result < 0) { @@ -313,14 +314,14 @@ class Paiement extends CommonObject break; } } - + if ($error) { setEventMessages($discount->error, $discount->errors, 'errors'); $error++; - } + } } - + // Set invoice to paid if (! $error) { @@ -520,13 +521,13 @@ class Paiement extends CommonObject $acc = new Account($this->db); $result=$acc->fetch($this->fk_account); - + $totalamount=$this->amount; if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility - + // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me) if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount=$this->multicurrency_amount; - + if ($mode == 'payment_supplier') $totalamount=-$totalamount; // Insert payment into llx_bank @@ -796,7 +797,7 @@ class Paiement extends CommonObject /** * Information sur l'objet - * + * * @param int $id id du paiement dont il faut afficher les infos * @return void */ @@ -962,13 +963,13 @@ class Paiement extends CommonObject /** * get the right way of payment - * + * * @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs */ function getWay() { global $conf; - + $way = 'dolibarr'; if (!empty($conf->multicurrency->enabled)) { @@ -981,10 +982,10 @@ class Paiement extends CommonObject } } } - + return $way; } - + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index efc9d5e10d2..450ff455e13 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -117,7 +117,8 @@ if (GETPOST("orphelins")) $sql.= " ".MAIN_DB_PREFIX."c_paiement as c)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql.= " WHERE p.fk_paiement = c.id"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity = " . $conf->entity; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " AND pf.fk_facture IS NULL"; // Add where from hooks $parameters=array(); @@ -148,7 +149,8 @@ else $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql.= " WHERE p.fk_paiement = c.id"; - $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.entity = " . $conf->entity; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); if (! $user->rights->societe->client->voir && ! $socid) { $sql.= " AND sc.fk_user = " .$user->id; @@ -177,7 +179,7 @@ else if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account; if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'"; if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num); - if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1); + if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1); if ($search_company) $sql .= natural_search('s.nom', $search_company); // Add where from hooks $parameters=array(); @@ -211,7 +213,7 @@ if ($resql) $param.=($search_amount?"&search_amount=".urlencode($search_amount):""); $param.=($search_payment_num?"&search_payment_num=".urlencode($search_payment_num):""); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); - + print ''; if ($optioncss != '') print ''; print ''; @@ -220,9 +222,9 @@ if ($resql) print ''; print ''; print ''; - + print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords,'title_accountancy.png', 0, '', '', $limit); - + print '
'; print '
'.$arraytitle.''.$langs->trans('Date').'
'; @@ -634,36 +634,36 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie // Date print ''.dol_print_date($db->jdate($objp->df),'day')."'.$objp->multicurrency_code."'; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc); print ''; - if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($sign * $multicurrency_payment); if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes); if ($multicurrency_deposits) print '+'.price($multicurrency_deposits); } print ''; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay); print ''.price($sign * $objp->total_ttc).''.price($sign * $paiement); if ($creditnotes) print '+'.price($creditnotes); @@ -696,14 +696,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print "'; - + // Add remind multicurrency amount $namef = 'multicurrency_amount_'.$objp->facid; $nameRemain = 'multicurrency_remain_'.$objp->facid; - + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { if ($action != 'add_paiement') @@ -723,7 +723,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } // Warning - print ''; + print ''; //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id])) || $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id]))) @@ -744,7 +744,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $totalrecudeposits+=$deposits; $i++; } - + if ($i > 1) { // Print total @@ -802,7 +802,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '
'; if (!empty($totalpayment)) $text=$langs->trans('ConfirmCustomerPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); - if (!empty($multicurrency_totalpayment)) + if (!empty($multicurrency_totalpayment)) { $text.='
'.$langs->trans('ConfirmCustomerPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency")); } @@ -835,7 +835,8 @@ if (! GETPOST('action','aZ09')) $sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c'; $sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id'; - $sql.= ' AND f.entity = '.$conf->entity; + $sql.= ' AND f.entity = ' . $conf->entity; + $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); if ($socid) { $sql.= ' AND f.fk_soc = '.$socid; @@ -864,7 +865,7 @@ if (! GETPOST('action','aZ09')) while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - + print '
'.$objp->facnumber."'.dol_print_date($db->jdate($objp->dp))."
'.img_object($langs->trans("ShowPayment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."
'."\n"; @@ -277,15 +279,15 @@ if ($resql) } print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"p.amount","",$param,'align="right"',$sortfield,$sortorder); //print_liste_field_titre($langs->trans("Invoices"),"","","",$param,'align="left"',$sortfield,$sortorder); - + $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - + if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; - + while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); @@ -314,7 +316,7 @@ if ($resql) // Type print ''; - + // Payment number print ''; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 62ee285d70b..632efaf5d43 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -234,7 +234,7 @@ if ($result) { while ($i < $num) { $objp = $db->fetch_object($result); - + print ''; print "\n"; @@ -278,7 +278,7 @@ if ($modecompta != 'CREANCES-DETTES') while ($i < $num) { $objp = $db->fetch_object($result); - + print ''; print "'; print ''; print ''; @@ -363,7 +363,7 @@ if ($result) { while ($i < $num) { $objp = $db->fetch_object($result); - + print ''; print "\n"; @@ -381,7 +381,7 @@ if ($result) { } } else - { + { print ''; print ''; print ''; @@ -581,7 +581,7 @@ if (! empty($conf->salaries->enabled)) $column = 'p.datep'; } - print ''; + print ''; $sql = "SELECT u.rowid, u.firstname, u.lastname, p.fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user"; @@ -595,7 +595,7 @@ if (! empty($conf->salaries->enabled)) if ($newsortfield == 'amount_ht') $newsortfield = 'amount'; if ($newsortfield == 'amount_ttc') $newsortfield = 'amount'; $sql.= $db->order($newsortfield, $sortorder); - + dol_syslog("get payment salaries"); $result=$db->query($sql); $subtotal_ht = 0; @@ -663,7 +663,7 @@ if (! empty($conf->expensereport->enabled)) $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; @@ -676,7 +676,7 @@ if (! empty($conf->expensereport->enabled)) { $sql.= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'"; } - + $sql.= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm"; $newsortfield = $sortfield; if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'p.ref'; @@ -744,9 +744,9 @@ if (! empty($conf->don->enabled)) $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE p.entity = ".getEntity('donation'); - $sql.= " AND fk_statut >= 2"; + $sql.= " AND fk_statut >= 2"; } if (! empty($date_start) && ! empty($date_end)) $sql.= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'"; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 45cbbfe3a46..f1851bcfa36 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -492,14 +492,14 @@ if (! empty($conf->salaries->enabled)) } else { $column = 'p.datep'; } - + $subtotal_ht = 0; $subtotal_ttc = 0; $sql = "SELECT p.label as nom, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " GROUP BY p.label, dm"; - + dol_syslog("get social salaries payments"); $result=$db->query($sql); if ($result) @@ -512,13 +512,13 @@ if (! empty($conf->salaries->enabled)) while ($i < $num) { $obj = $db->fetch_object($result); - + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount; - + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount; - + $i++; } } @@ -546,7 +546,7 @@ if (! empty($conf->expensereport->enabled)) $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; @@ -568,7 +568,7 @@ if (! empty($conf->expensereport->enabled)) { if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount_ht; - + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount_ttc; @@ -588,7 +588,7 @@ if (! empty($conf->don->enabled)) { $subtotal_ht = 0; $subtotal_ttc = 0; - + if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; @@ -599,7 +599,7 @@ if (! empty($conf->don->enabled)) $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE p.entity = ".getEntity('donation'); $sql.= " AND fk_statut >= 2"; } @@ -617,13 +617,13 @@ if (! empty($conf->don->enabled)) while ($i < $num) { $obj = $db->fetch_object($result); - + if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; $encaiss[$obj->dm] += $obj->amount; - + if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; $encaiss_ttc[$obj->dm] += $obj->amount; - + $i++; } } @@ -671,7 +671,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) { $mois_modulo = $mois; if($mois>12) {$mois_modulo = $mois-12;} - + print ''; print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php index e87fc932c50..8d053028887 100644 --- a/htdocs/compta/salaries/index.php +++ b/htdocs/compta/salaries/index.php @@ -98,7 +98,7 @@ $sql.= " s.rowid, s.fk_user, s.amount, s.salary, s.label, s.datep as datep, s.da $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,"; $sql.= " pst.code as payment_code"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,"; $sql.= " ".MAIN_DB_PREFIX."user as u"; @@ -151,9 +151,9 @@ if ($result) print ''; print ''; print ''; - + print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit); - + print '
'; print '
'.$langs->trans("PaymentTypeShort".$objp->paiement_code).''.$objp->num_paiement.'
 ".$langs->trans("Bills").' '.$objp->name."
 ".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; @@ -301,7 +301,7 @@ if ($modecompta != 'CREANCES-DETTES') } if ($total_ttc == 0) -{ +{ print '
 '.$langs->trans("None").'
 ".$langs->trans("Bills")." socid."\">".$objp->name."
 '.$langs->trans("None").'
'.$langs->trans("Salaries").'
'.$langs->trans("Salaries").'
".dol_print_date(dol_mktime(12,0,0,$mois_modulo,1,$annee),"%B")."
'."\n"; @@ -188,7 +188,7 @@ if ($result) $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; print ''; - + print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Employee"),$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder); @@ -199,13 +199,13 @@ if ($result) print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; - + print "\n"; while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); - + print ''; $userstatic->id=$obj->uid; @@ -238,11 +238,11 @@ if ($result) $accountstatic->id=$obj->bid; $accountstatic->ref=$obj->bref; $accountstatic->number=$obj->bnumber; - + if (! empty($conf->accounting->enabled)) { $accountstatic->account_number=$obj->account_number; - + $accountingjournal = new AccountingJournal($db); $accountingjournal->fetch($obj->fk_accountancy_journal); diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 630197cfc78..7d32da6f937 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -67,7 +67,7 @@ if ($action == 'reopen' && $user->rights->tax->charges->creer) { if ($object->paye) { $result = $object->set_unpaid($user); - if ($result > 0) + if ($result > 0) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); exit(); @@ -350,7 +350,7 @@ if ($action == 'create') print ''; } @@ -405,7 +405,7 @@ if ($id > 0) $head=tax_prepare_head($object); $totalpaye = $object->getSommePaiement(); - + // Clone confirmation if ($action === 'clone') { @@ -473,21 +473,21 @@ if ($id > 0) $morehtmlref.=''; } } - } + } $morehtmlref.=''; - + $linkback = '' . $langs->trans("BackToList") . ''; - + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); - + print '
'; print '
'; print '
'; - + print '
'.$langs->trans("Project").''; $numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1); - + print '
'; - + // Type print '"; print ""; @@ -581,6 +581,7 @@ if ($id > 0) $sql.= " AND p.fk_charge = cs.rowid"; $sql.= " AND cs.entity = ".$conf->entity; $sql.= " AND p.fk_typepaiement = c.id"; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " ORDER BY dp DESC"; //print $sql; @@ -588,7 +589,7 @@ if ($id > 0) if ($resql) { $totalpaye = 0; - + $num = $db->num_rows($resql); $i = 0; $total = 0; print '
'.$langs->trans("Type")."".$object->type_libelle."
'; @@ -598,14 +599,14 @@ if ($id > 0) print ''; print ''; print ''; - + $var=true; if ($num > 0) { while ($i < $num) { $objp = $db->fetch_object($resql); - + print "'; print '\n"; @@ -619,18 +620,18 @@ if ($id > 0) } else { - + print ''; } - + //if ($object->status == ChargeSociales::STATUS_DRAFT) //{ print "\n"; print "\n"; - + $resteapayer = $object->amount - $totalpaye; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - + print ""; print '\n"; //} @@ -640,12 +641,12 @@ if ($id > 0) else { dol_print_error($db); - } - + } + print ''; print ''; print ''; - + print '
'; dol_fiche_end(); diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index cf359d691ec..9d1205c1cb0 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -26,7 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -/** +/** * Classe permettant la gestion des paiements des charges * La tva collectee n'est calculee que sur les factures payees. */ @@ -36,7 +36,7 @@ class ChargeSociales extends CommonObject public $table='chargesociales'; public $table_element='chargesociales'; public $picto = 'bill'; - + /** * {@inheritdoc} */ @@ -83,7 +83,7 @@ class ChargeSociales extends CommonObject $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); if ($ref) $sql.= " WHERE cs.rowid = ".$ref; else $sql.= " WHERE cs.rowid = ".$id; @@ -110,7 +110,7 @@ class ChargeSociales extends CommonObject $this->paye = $obj->paye; $this->periode = $this->db->jdate($obj->periode); $this->import_key = $this->import_key; - + $this->db->free($resql); return 1; @@ -378,7 +378,7 @@ class ChargeSociales extends CommonObject if ($return) return 1; else return -1; } - + /** * Retourne le libelle du statut d'une charge (impaye, payee) * @@ -445,7 +445,7 @@ class ChargeSociales extends CommonObject if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3'); if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6'); } - + return "Error, mode/status not found"; } diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 1d553831f99..8a5c8f0eeef 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -78,7 +78,7 @@ class PaymentSocialContribution extends CommonObject $now=dol_now(); dol_syslog(get_class($this)."::create", LOG_DEBUG); - + // Validate parametres if (! $this->datepaye) { @@ -125,7 +125,7 @@ class PaymentSocialContribution extends CommonObject if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); - + // Insere tableau des montants / factures foreach ($this->amounts as $key => $amount) { @@ -137,7 +137,7 @@ class PaymentSocialContribution extends CommonObject // If we want to closed payed invoices if ($closepaidcontrib) { - + $contrib=new ChargeSociales($this->db); $contrib->fetch($contribid); $paiement = $contrib->getSommePaiement(); @@ -205,6 +205,7 @@ class PaymentSocialContribution extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; + $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php index 6c88305f72e..bd4b3efc8b7 100644 --- a/htdocs/compta/sociales/payments.php +++ b/htdocs/compta/sociales/payments.php @@ -88,7 +88,7 @@ print ''; print ''; print ''; -if ($mode != 'sconly') +if ($mode != 'sconly') { $center=($year?''.img_previous($langs->trans("Previous"), 'class="valignbottom"')." ".$langs->trans("Year").' '.$year.' '.img_next($langs->trans("Next"), 'class="valignbottom"')."":""); print_barre_liste($title,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$center,$num,$totalnboflines, 'title_accountancy', 0, '', '', $limit, 1); @@ -133,7 +133,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs,"; $sql.= " ".MAIN_DB_PREFIX."paiementcharge as pc"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE cs.fk_type = c.id AND pc.fk_charge = cs.rowid"; $sql.= " AND cs.entity = ".$conf->entity; if ($year > 0) @@ -260,7 +260,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $total = $total + $obj->amount; - + print ''; print ''."\n"; @@ -362,7 +362,7 @@ while($j<$numlt) $total = $total + $obj->amount; - + print ''; print ''."\n"; @@ -408,7 +408,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $sal = new PaymentSalary($db); print "
"; - + print_fiche_titre($langs->trans("SalariesPayments").($year?' ('.$langs->trans("Year").' '.$year.')':''), '', ''); $sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, u.salary as current_salary"; @@ -444,7 +444,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $total = $total + $obj->amount; - + print ''; print ''."\n"; diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 44c45a65dc7..12ed60d6d68 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -100,7 +100,7 @@ $bankstatic = new Account($db); $sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,"; $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE t.entity = ".$conf->entity; @@ -156,9 +156,9 @@ if ($result) print ''; print ''; print ''; - + print_barre_liste($langs->trans("VATPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$totalnboflines, 'title_accountancy', 0, '', '', $limit); - + print '
'; print '
'.$langs->trans("Type").''.$langs->trans("Amount").'
"; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."
'.$langs->trans("None").'
".$langs->trans("AlreadyPaid")." :".price($totalpaye)."
".$langs->trans("AmountExpected")." :".price($object->amount)."
".$langs->trans("RemainderToPay")." :'.price($resteapayer)."
'.dol_print_date($db->jdate($obj->dm),'day').'
'.dol_print_date($db->jdate($obj->dm),'day').'
'.dol_print_date($db->jdate($obj->dateep),'day').'
'; @@ -199,7 +199,7 @@ if ($result) print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"t.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; - + while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); @@ -252,7 +252,7 @@ if ($result) $i++; } - + $colspan=5; if (! empty($conf->banque->enabled)) $colspan++; print ''; @@ -261,7 +261,7 @@ if ($result) print "
'.$langs->trans("Total").'
"; print ''; - + print ''; $db->free($result); diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 4b6d70b1366..2be205fa5c9 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -51,7 +51,7 @@ abstract class CommonInvoice extends CommonObject const TYPE_DEPOSIT = 3; /** - * Proforma invoice. + * Proforma invoice. * @deprectad Remove this. A "proforma invoice" is an order with a look of invoice, not an invoice ! */ const TYPE_PROFORMA = 4; @@ -89,7 +89,7 @@ abstract class CommonInvoice extends CommonObject */ const STATUS_ABANDONED = 3; - + /** * Return remain amount to pay. Property ->id and ->total_ttc must be set. * This does not include open direct debit requests. @@ -141,7 +141,7 @@ abstract class CommonInvoice extends CommonObject return -1; } } - + /** * Return amount (with tax) of all deposits invoices used by invoice. * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended). @@ -154,11 +154,11 @@ abstract class CommonInvoice extends CommonObject if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { // TODO - return 0; + return 0; } - + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; - + $discountstatic=new DiscountAbsolute($this->db); $result=$discountstatic->getSumDepositsUsed($this, $multicurrency); if ($result >= 0) @@ -185,9 +185,9 @@ abstract class CommonInvoice extends CommonObject // TODO return 0; } - + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; - + $discountstatic=new DiscountAbsolute($this->db); $result=$discountstatic->getSumCreditNotesUsed($this, $multicurrency); if ($result >= 0) @@ -200,7 +200,7 @@ abstract class CommonInvoice extends CommonObject return -1; } } - + /** * Renvoie tableau des ids de facture avoir issus de la facture * @@ -418,7 +418,7 @@ abstract class CommonInvoice extends CommonObject if ($status == 0) return ''.$langs->trans('Bill'.$prefix.'StatusDraft').' '.img_picto($langs->trans('BillStatusDraft'),'statut0'); if (($status == 3 || $status == 2) && $alreadypaid <= 0) return ''.$langs->trans('Bill'.$prefix.'StatusCanceled').' '.img_picto($langs->trans('BillStatusCanceled'),'statut5'); if (($status == 3 || $status == 2) && $alreadypaid > 0) return ''.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' '.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7'); - if ($alreadypaid <= 0) + if ($alreadypaid <= 0) { if ($type == self::TYPE_CREDIT_NOTE) return ''.$langs->trans('Bill'.$prefix.'StatusNotRefunded').' '.img_picto($langs->trans('StatusNotRefunded'),'statut1'); return ''.$langs->trans('Bill'.$prefix.'StatusNotPaid').' '.img_picto($langs->trans('BillStatusNotPaid'),'statut1'); @@ -450,8 +450,9 @@ abstract class CommonInvoice extends CommonObject $sqltemp = 'SELECT c.type_cdr,c.nbjour,c.decalage'; $sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; - if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement; - else $sqltemp.= " WHERE c.code='".$this->db->escape($cond_reglement)."'"; + $sqltemp.= " WHERE c.entity = " . getEntity('c_payment_term', 2); + if (is_numeric($cond_reglement)) $sqltemp.= " AND c.rowid=".$cond_reglement; + else $sqltemp.= " AND c.code='".$this->db->escape($cond_reglement)."'"; dol_syslog(get_class($this).'::calculate_date_lim_reglement', LOG_DEBUG); $resqltemp=$this->db->query($sqltemp); @@ -497,13 +498,13 @@ abstract class CommonInvoice extends CommonObject } elseif($cdr_type == 2 && !empty($cdr_nbjour)) // Application de la règle, le N du mois courant ou suivant { - + $date_piece = dol_mktime(0,0,0,date('m', $this->date),date('d', $this->date),date('Y', $this->date)); // Sans les heures minutes et secondes $date_lim_current = dol_mktime(0,0,0,date('m', $this->date),$cdr_nbjour,date('Y', $this->date)); // Sans les heures minutes et secondes $date_lim_next = strtotime(date('Y-m-d', $date_lim_current).' +1month'); - + $diff = $date_piece - $date_lim_current; - + if($diff < 0) $datelim = $date_lim_current; else $datelim = $date_lim_next; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 01d28ecde24..6b265584948 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2958,8 +2958,8 @@ class Form $sql = "SELECT id, code, libelle as label, type, active"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; - //if ($active >= 0) $sql.= " WHERE active = ".$active; $sql.= " WHERE entity = " . getEntity('c_paiement', 2); + //if ($active >= 0) $sql.= " AND active = ".$active; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 169aec16307..008049d3d13 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -151,7 +151,7 @@ class Translate $this->load($domain); } } - + /** * Load translation key-value for a particular file, into a memory array. * If data for file already loaded, do nothing. @@ -177,7 +177,7 @@ class Translate global $conf,$db; //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); - + // Check parameters if (empty($domain)) { @@ -185,8 +185,8 @@ class Translate return -1; } if ($this->defaultlang == 'none_NONE') return 0; // Special language code to not translate keys - - + + // Load $this->tab_translate[] from database if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. @@ -278,14 +278,14 @@ class Translate * and split the rest until a line feed. * This is more efficient than fgets + explode + trim by a factor of ~2. */ - while ($line = fscanf($fp, "%[^= ]%*[ =]%[^\n]")) + while ($line = fscanf($fp, "%[^= ]%*[ =]%[^\n]")) { - if (isset($line[1])) + if (isset($line[1])) { list($key, $value) = $line; //if ($domain == 'orders') print "Domain=$domain, found a string for $tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."
"; //if ($key == 'Order') print "Domain=$domain, found a string for key=$key=$tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."
"; - if (empty($this->tab_translate[$key])) + if (empty($this->tab_translate[$key])) { // If translation was already found, we must not continue, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite entries) $value = preg_replace('/\\n/', "\n", $value); // Parse and render carriage returns if ($key == 'DIRECTION') { // This is to declare direction of language @@ -375,8 +375,8 @@ class Translate if (! empty($tmparray2[1])) $this->tab_translate[$tmparray2[0]]=$tmparray2[1]; } } - } - + } + // Check to be sure that SeparatorDecimal differs from SeparatorThousand if (! empty($this->tab_translate["SeparatorDecimal"]) && ! empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"]=''; @@ -401,7 +401,7 @@ class Translate global $conf; $domain='database'; - + // Check parameters if (empty($db)) return 0; // Database handler can't be used @@ -418,7 +418,7 @@ class Translate } $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only. - + $fileread=0; $langofdir=(empty($forcelangdir)?$this->defaultlang:$forcelangdir); @@ -467,24 +467,24 @@ class Translate if (! $found && ! empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) { // Overwrite translation with database read - $sql="SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; + $sql="SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; $resql=$db->query($sql); - + if ($resql) { $num = $db->num_rows($resql); if ($num) { if ($usecachekey) $tabtranslatedomain=array(); // To save lang content in cache - + $i = 0; while ($i < $num) // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents { $obj=$db->fetch_object($resql); - + $key=$obj->transkey; $value=$obj->transvalue; - + //print "Domain=$domain, found a string for $tab[0] with value $tab[1]
"; if (empty($this->tab_translate[$key])) // If translation was already found, we must not continue, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite entries) { @@ -493,12 +493,12 @@ class Translate $this->tab_translate[$key]=$value; if ($usecachekey) $tabtranslatedomain[$key]=$value; // To save lang content in cache } - + $i++; } - + $fileread=1; - + // TODO Move cache write out of loop on dirs // To save lang content for usecachekey into cache if ($usecachekey && count($tabtranslatedomain)) @@ -524,9 +524,9 @@ class Translate return 1; } - - - + + + /** * Return translated value of key for special keys ("Currency...", "Civility...", ...). * Search in lang file, then into database. Key must be any complete entry into lang file: CurrencyEUR, ... @@ -559,7 +559,7 @@ class Translate } elseif (preg_match('/^PaymentTypeShort([0-9A-Z]+)$/i',$key,$reg)) { - $newstr=$this->getLabelFromKey($db,$reg[1],'c_paiement','code','libelle'); + $newstr=$this->getLabelFromKey($db,$reg[1],'c_paiement','code','libelle','',getEntity('c_paiement', 2)); } elseif (preg_match('/^OppStatusShort([0-9A-Z]+)$/i',$key,$reg)) { @@ -611,8 +611,8 @@ class Translate $str=preg_replace('/'.preg_quote($tmparray2[0]).'/',$tmparray2[1],$str); } } - - if (! preg_match('/^Format/',$key)) + + if (! preg_match('/^Format/',$key)) { //print $str; $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings. @@ -690,9 +690,9 @@ class Translate $tmparray2=explode(':',$tmp); $str=preg_replace('/'.preg_quote($tmparray2[0]).'/',$tmparray2[1],$str); } - } + } - if (! preg_match('/^Format/',$key)) + if (! preg_match('/^Format/',$key)) { //print $str; $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings. @@ -867,10 +867,11 @@ class Translate * @param string $fieldkey Field for key * @param string $fieldlabel Field for label * @param string $keyforselect Use another value than the translation key for the where into select + * @param int $entity Field for filter by entity * @return string Label in UTF8 (but without entities) * @see dol_getIdFromCode */ - function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel,$keyforselect='') + function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel,$keyforselect='',$entity=null) { // If key empty if ($key == '') return ''; @@ -893,6 +894,8 @@ class Translate $sql = "SELECT ".$fieldlabel." as label"; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " WHERE ".$fieldkey." = '".($keyforselect?$keyforselect:$key)."'"; + if (! is_null($entity)) + $sql.= " AND entity = " . (int) $entity; dol_syslog(get_class($this).'::getLabelFromKey', LOG_DEBUG); $resql = $db->query($sql); if ($resql) @@ -930,7 +933,7 @@ class Translate } /** - * Return a currency code into its symbol. + * Return a currency code into its symbol. * If mb_convert_encoding is not available, return currency code. * * @param string $currency_code Currency code diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 688624dc838..204e55778af 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5652,10 +5652,11 @@ function dol_osencode($str) * @param string $tablename Table name without prefix * @param string $fieldkey Field for code * @param string $fieldid Field for id + * @param int $entity Field for filter by entity * @return int <0 if KO, Id of code if OK * @see $langs->getLabelFromKey */ -function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id') +function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$entity=null) { global $cache_codes; @@ -5671,6 +5672,8 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id') $sql = "SELECT ".$fieldid." as valuetoget"; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'"; + if (! is_null($entity)) + $sql.= " AND entity = " . (int) $entity; dol_syslog('dol_getIdFromCode', LOG_DEBUG); $resql = $db->query($sql); if ($resql) diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 693dd2e412f..2d0e09f57dc 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -255,16 +255,16 @@ class pdf_crabe extends ModelePDFFactures // Set nblignes with the new facture lines content after hook $nblignes = count($object->lines); $nbpayments = count($object->getListOfPayments()); - + // Create pdf instance $pdf=pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $pdf->SetAutoPageBreak(1,0); - + $heightforinfotot = 50+(4*$nbpayments); // Height reserved to output the info and total part and payment part $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) - + if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); @@ -509,7 +509,7 @@ class pdf_crabe extends ModelePDFFactures $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); $pdf->SetXY($this->posxqty, $curY); // Enough for 6 chars - + if ($this->situationinvoice) { $pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R'); @@ -769,7 +769,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetFont('','', $default_font_size - 4); - + // Loop on each deposits and credit notes included $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source,"; @@ -818,11 +818,11 @@ class pdf_crabe extends ModelePDFFactures $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount,"; $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1"; $sql.= " ORDER BY p.datep"; - + $resql=$this->db->query($sql); if ($resql) { @@ -1052,7 +1052,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetFillColor(255,255,255); $pdf->SetXY($col1x, $tab2_top + 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); - + $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); $pdf->SetXY($col2x, $tab2_top + 0); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1); @@ -1071,7 +1071,7 @@ class pdf_crabe extends ModelePDFFactures else { // FIXME amount of vat not supported with multicurrency - + //Local tax 1 before VAT //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on') //{ @@ -1397,7 +1397,7 @@ class pdf_crabe extends ModelePDFFactures if (empty($hidetop)) { $pdf->SetXY($this->posxqty-1, $tab_top+1); - + if($this->situationinvoice) { $pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); @@ -1411,14 +1411,14 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); } } - + if ($this->situationinvoice) { $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height); - + if (empty($hidetop)) { - + $pdf->SetXY($this->posxprogress, $tab_top+1); - + if($conf->global->PRODUCT_USE_UNITS) { $pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C'); @@ -1431,9 +1431,9 @@ class pdf_crabe extends ModelePDFFactures { $pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C'); } - + } - + } if($conf->global->PRODUCT_USE_UNITS) { @@ -1554,7 +1554,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref); - if ($object->statut == Facture::STATUS_DRAFT) + if ($object->statut == Facture::STATUS_DRAFT) { $pdf->SetTextColor(128,0,0); $textref.=' - '.$outputlangs->trans("NotValidated"); @@ -1616,7 +1616,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetTextColor(0,0,60); $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R'); } - + if ($object->type != 2) { $posy+=3; @@ -1647,7 +1647,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell($w, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R'); } } - + $posy+=1; // Show list of linked objects diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 3af85a1944d..71849018554 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -71,7 +71,7 @@ class modFacture extends DolibarrModules $this->warnings_activation = array('FR'=>'WarningNoteModuleInvoiceForFrenchLaw'); // Warning to show when we activate module. array('always'='text') or array('FR'='text') $this->warnings_activation = array(); $this->warnings_activation_ext = array('FR'=>'WarningInstallationMayBecomeNotCompliantWithLaw'); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text') - + // Config pages $this->config_page_url = array("facture.php"); @@ -99,7 +99,7 @@ class modFacture extends DolibarrModules $this->const[$r][3] = ""; $this->const[$r][4] = 0; $r++; - + /*$this->const[$r][0] = "FACTURE_DRAFT_WATERMARK"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "__(Draft)__"; @@ -107,7 +107,7 @@ class modFacture extends DolibarrModules $this->const[$r][4] = 0; $r++;*/ - + // Boxes //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php')); $this->boxes = array( @@ -116,16 +116,16 @@ class modFacture extends DolibarrModules 2=>array('file'=>'box_graph_invoices_permonth.php','enabledbydefaulton'=>'Home') ); - // Cronjobs + // Cronjobs $this->cronjobs = array( - 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24), + 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24), // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600) - ); - // List of cron jobs entries to add - // Example: + ); + // List of cron jobs entries to add + // Example: // $this->cronjobs=array( - // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600), - // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600) + // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600), + // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600) // ); // Permissions @@ -206,8 +206,8 @@ class modFacture extends DolibarrModules // Menus //------- $this->menu = 1; // This module add menu entries. They are coded into menu manager. - - + + // Exports //-------- $r=1; @@ -267,7 +267,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement AND pt.entity = ' . getEntity('c_paiement', 2); $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; diff --git a/htdocs/core/modules/modSalaries.class.php b/htdocs/core/modules/modSalaries.class.php index bf37a7e73d8..a0f479e79fe 100644 --- a/htdocs/core/modules/modSalaries.class.php +++ b/htdocs/core/modules/modSalaries.class.php @@ -111,7 +111,7 @@ class modSalaries extends DolibarrModules $this->rights[$r][3] = 0; $this->rights[$r][4] = 'write'; $this->rights[$r][5] = ''; - + $r++; $this->rights[$r][0] = 513; $this->rights[$r][1] = 'Create/modify payment of salaries'; @@ -119,7 +119,7 @@ class modSalaries extends DolibarrModules $this->rights[$r][3] = 0; $this->rights[$r][4] = 'write'; $this->rights[$r][5] = ''; - + $r++; $this->rights[$r][0] = 514; $this->rights[$r][1] = 'Delete contracts/salaries'; @@ -140,8 +140,8 @@ class modSalaries extends DolibarrModules // Menus //------- $this->menu = 1; // This module add menu entries. They are coded into menu manager. - - + + // Exports //-------- $r=0; @@ -157,7 +157,7 @@ class modSalaries extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('user').')'; } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index c4c93537444..641597de539 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -284,8 +284,8 @@ class modSociete extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid AND payterm.entity = ' . getEntity('c_payment_term', 2); + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id AND paymode.entity = ' . getEntity('c_paiement', 2); $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe').')'; if (is_object($user) && empty($user->rights->societe->client->voir)) { $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' '; diff --git a/htdocs/core/modules/rapport/pdf_paiement.class.php b/htdocs/core/modules/rapport/pdf_paiement.class.php index 11ee8a32d7d..406e07b094d 100644 --- a/htdocs/core/modules/rapport/pdf_paiement.class.php +++ b/htdocs/core/modules/rapport/pdf_paiement.class.php @@ -180,6 +180,7 @@ class pdf_paiement $sql.= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid "; $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND p.fk_paiement = c.id "; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'"; if (! $user->rights->societe->client->voir && ! $socid) { @@ -199,7 +200,7 @@ class pdf_paiement while ($i < $num) { $objp = $this->db->fetch_object($result); - + $lines[$i][0] = $objp->facnumber; $lines[$i][1] = dol_print_date($this->db->jdate($objp->dp),"day",false,$outputlangs,true); diff --git a/htdocs/core/modules/rapport/pdf_paiement_fourn.class.php b/htdocs/core/modules/rapport/pdf_paiement_fourn.class.php index f20e912e1ed..f220c51b59d 100644 --- a/htdocs/core/modules/rapport/pdf_paiement_fourn.class.php +++ b/htdocs/core/modules/rapport/pdf_paiement_fourn.class.php @@ -178,6 +178,7 @@ class pdf_paiement_fourn $sql.= " AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid "; $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND p.fk_paiement = c.id "; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'"; if (! $user->rights->societe->client->voir && ! $socid) { @@ -197,7 +198,7 @@ class pdf_paiement_fourn while ($i < $num) { $objp = $this->db->fetch_object($result); - + $lines[$i][0] = $objp->ref; $lines[$i][1] = dol_print_date($this->db->jdate($objp->dp),"day",false,$outputlangs,true); diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 1e7e6f4bcad..20f77c68a0e 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -914,7 +914,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,"; $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement', 2); $sql.= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".$object->id; $sql.= " ORDER BY p.datep"; $resql=$this->db->query($sql); diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 8e1bd00d893..e671f06845b 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -683,6 +683,7 @@ if (! empty($id) && $action != 'edit') $sql.= " AND p.fk_donation = d.rowid"; $sql.= " AND d.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " ORDER BY dp"; //print $sql; diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 695314bb526..2c92e52be7c 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -39,7 +39,7 @@ class Don extends CommonObject public $fk_element = 'fk_donation'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe var $picto = 'generic'; - + var $date; var $amount; var $societe; @@ -163,7 +163,7 @@ class Don extends CommonObject global $conf, $user,$langs; $now = dol_now(); - + // Charge tableau des id de societe socids $socids = array(); @@ -611,7 +611,7 @@ class Don extends CommonObject $sql.= " c.code as country_code, c.label as country"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment AND cp.entity = " . getEntity('c_paiement', 2); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid"; if (! empty($id)) { diff --git a/htdocs/don/class/paymentdonation.class.php b/htdocs/don/class/paymentdonation.class.php index 9d478c4d7f5..5752878fecf 100644 --- a/htdocs/don/class/paymentdonation.class.php +++ b/htdocs/don/class/paymentdonation.class.php @@ -32,7 +32,7 @@ class PaymentDonation extends CommonObject public $element='payment_donation'; //!< Id that identify managed objects public $table_element='payment_donation'; //!< Name of table without prefix where object is stored public $picto = 'payment'; - + public $rowid; public $fk_donation; @@ -175,6 +175,7 @@ class PaymentDonation extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_donation as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -443,7 +444,7 @@ class PaymentDonation extends CommonObject { return ''; } - + /** * Renvoi le libelle d'un statut donne * @@ -454,11 +455,11 @@ class PaymentDonation extends CommonObject function LibStatut($statut,$mode=0) { global $langs; - + return ''; } - - + + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index dff27139581..181b8d90b1d 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -125,7 +125,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if ($cancel) + if ($cancel) { $action=''; $fk_projet=''; @@ -158,7 +158,7 @@ if (empty($reshook)) { // Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails $orig = clone $object; - + $result=$object->createFromClone(GETPOST('fk_user_author','int')); if ($result > 0) { @@ -174,7 +174,7 @@ if (empty($reshook)) } } } - + if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer) { $object = new ExpenseReport($db); @@ -190,20 +190,20 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == 'add' && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); - + $object->date_debut = $date_start; $object->date_fin = $date_end; - + $object->fk_user_author = GETPOST('fk_user_author','int'); if (! ($object->fk_user_author > 0)) $object->fk_user_author = $user->id; - + $fuser=new User($db); $fuser->fetch($object->fk_user_author); - + $object->fk_statut = 1; $object->fk_c_paiement = GETPOST('fk_c_paiement','int'); $object->fk_user_validator = GETPOST('fk_user_validator','int'); @@ -215,20 +215,20 @@ if (empty($reshook)) $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) $error++; } - + if ($object->periode_existe($fuser,$object->date_debut,$object->date_fin)) { $error++; setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors'); $action='create'; } - + if (! $error) { $db->begin(); - + $id = $object->create($user); - + if ($id > 0) { $db->commit(); @@ -243,25 +243,25 @@ if (empty($reshook)) } } } - + if ($action == 'update' && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + $object->date_debut = $date_start; $object->date_fin = $date_end; - + if($object->fk_statut < 3) { $object->fk_user_validator = GETPOST('fk_user_validator','int'); } - + $object->fk_c_paiement = GETPOST('fk_c_paiement','int'); $object->note_public = GETPOST('note_public'); $object->note_private = GETPOST('note_private'); $object->fk_user_modif = $user->id; - + $result = $object->update($user); if ($result > 0) { @@ -273,14 +273,14 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error++; - + if (! $error) { // Actions on extra fields (by external module or standard code) @@ -296,17 +296,17 @@ if (empty($reshook)) } else if ($reshook < 0) $error++; } - + if ($error) $action = 'edit_extras'; } - + if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setValidate($user); - + if ($result > 0) { // Define output language @@ -322,51 +322,51 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0 && $object->fk_user_validator > 0) { $langs->load("mails"); - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - + if ($emailTo && $emailFrom) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportWaitingForApproval"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link); - + // Rebuild pdf /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); - + if($resultPDF): // ATTACHMENT array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf"); array_push($mimetype,"application/pdf"); */ - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -411,13 +411,13 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->set_save_from_refuse($user); - + if ($result > 0) { // Define output language @@ -433,11 +433,11 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { // Send mail @@ -446,7 +446,7 @@ if (empty($reshook)) $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_author); @@ -455,10 +455,10 @@ if (empty($reshook)) if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportWaitingForReApproval"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $dateRefusEx = explode(" ",$object->date_refuse); @@ -481,7 +481,7 @@ if (empty($reshook)) // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -526,15 +526,15 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + // Approve if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->setApproved($user); - + if ($result > 0) { // Define output language @@ -550,11 +550,11 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { // Send mail @@ -576,19 +576,19 @@ if (empty($reshook)) if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportApproved"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - + // Rebuilt pdf /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + if($resultPDF { // ATTACHMENT @@ -600,7 +600,7 @@ if (empty($reshook)) */ $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -673,7 +673,7 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } @@ -686,28 +686,28 @@ if (empty($reshook)) $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_refuse); $emailFrom = $expediteur->email; - + if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportRefused"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_refuse'], $link); - + // Rebuilt pdf /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + if($resultPDF { // ATTACHMENT @@ -796,7 +796,7 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } @@ -814,23 +814,23 @@ if (empty($reshook)) $expediteur = new User($db); $expediteur->fetch($object->fk_user_cancel); $emailFrom = $expediteur->email; - + if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportCanceled"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_cancel'], $link); - + // Rebuilt pdf /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + if($resultPDF { // ATTACHMENT @@ -840,10 +840,10 @@ if (empty($reshook)) array_push($mimetype,"application/pdf"); } */ - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -881,7 +881,7 @@ if (empty($reshook)) { setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); $action=''; - } + } } else { @@ -918,7 +918,7 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } @@ -961,7 +961,7 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } @@ -983,7 +983,7 @@ if (empty($reshook)) if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); - + // SUBJECT $subject = $langs->transnoentities("ExpenseReportPaid"); @@ -1154,7 +1154,7 @@ if (empty($reshook)) { $object = new ExpenseReport($db); $object->fetch($id); - + $object_ligne = new ExpenseReportLine($db); $object_ligne->fetch(GETPOST("rowid")); $total_ht = $object_ligne->total_ht; @@ -1178,11 +1178,11 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + $object->update_totaux_del($object_ligne->total_ht,$object_ligne->total_tva); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); exit; @@ -1244,13 +1244,13 @@ if (empty($reshook)) } $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + $result = $object->recalculer($id); - + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } @@ -1296,7 +1296,7 @@ if ($action == 'create') print ''; print ''; - + // Date start print ''; print ''; @@ -1304,7 +1304,7 @@ if ($action == 'create') $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1); print ''; print ''; - + // Date end print ''; print ''; @@ -1312,7 +1312,7 @@ if ($action == 'create') $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1); print ''; print ''; - + print ''; print ''; print ''; print ''; - + // Payment mode if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) { @@ -1400,7 +1400,7 @@ else $result = $object->fetch($id, $ref); $res = $object->fetch_optionals($object->id, $extralabels); - + if ($result > 0) { if (! in_array($object->fk_user_author, $user->getAllChildIds(1))) @@ -1698,7 +1698,7 @@ else $userfee=new User($db); $result = $userfee->fetch($object->fk_user_validator); if ($result > 0) print $userfee->getNomUrl(-1); - if (empty($userfee->email) || ! isValidEmail($userfee->email)) + if (empty($userfee->email) || ! isValidEmail($userfee->email)) { $langs->load("errors"); print img_warning($langs->trans("ErrorBadEMail", $userfee->email)); @@ -1851,6 +1851,7 @@ else $sql.= " AND p.fk_expensereport = e.rowid"; $sql.= " AND e.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " ORDER BY dp"; $resql = $db->query($sql); @@ -1902,9 +1903,9 @@ else { print ''; print ''; - + $remaintopay = $object->total_ttc - $totalpaid; - + print ''; print ''; } @@ -1984,7 +1985,7 @@ else if ($action != 'editline' || $objp->rowid != GETPOST('rowid')) { print ''; - + print ''; @@ -2006,7 +2007,7 @@ else print ''; print ''; print ''; - + if ($action != 'editline') { print ''; @@ -2034,7 +2035,7 @@ else if ($action == 'editline' && $objp->rowid == GETPOST('rowid')) { print ''; - + print ''; // Select date @@ -2049,7 +2050,7 @@ else $formproject->select_projects(-1, $objp->fk_projet,'fk_projet', 0, 0, 1, 1); print ''; } - + // Select type print ''; - + print ''; } // Fin si c'est payé/validé print '
'.$langs->trans("DateStart").'
'.$langs->trans("DateEnd").'
'.$langs->trans("User").''; @@ -1341,7 +1341,7 @@ if ($action == 'create') } print '
'.$langs->trans("AlreadyPaid").':'.price($totalpaid).'
'.$langs->trans("AmountExpected").':'.price($object->total_ttc).'
'.$langs->trans("RemainderToPay").':'.price($remaintopay).'
'; print img_picto($langs->trans("Document"), "object_generic"); print ' '.$piece_comptable.''.vatrate($objp->vatrate,true).''.price($objp->value_unit).''.$objp->qty.''.price($objp->total_ht).'
'; select_type_fees_id($objp->type_fees_code,'fk_c_type_fees'); @@ -2168,13 +2169,13 @@ else } print '
'; print ''; - + print ''; } else @@ -2290,7 +2291,7 @@ if ($action != 'create' && $action != 'edit') // If status is Appoved // -------------------- - + if ($user->rights->expensereport->approve && $object->fk_statut == 5) { print ''; @@ -2309,7 +2310,7 @@ if ($action != 'create' && $action != 'edit') print ''; } } - + // If bank module is not used if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5) { @@ -2319,26 +2320,26 @@ if ($action != 'create' && $action != 'edit') print '"; } } - + if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->fk_statut == 5) { // Cancel print ''; } - + // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled. if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->fk_statut == 6) { // Cancel print ''; } - + // Clone if ($user->rights->expensereport->creer) { print ''; } - - /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ + + /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->fk_statut <= 4) { // Delete @@ -2389,7 +2390,7 @@ if ($action != 'create' && $action != 'edit' && ($id || $ref)) $object->fetch_thirdparty(); $result = $object->add_object_linked('fichinter', GETPOST('LinkedFichinter')); } - + // Show links to link elements $linktoelements=array(); if (! empty($conf->global->EXPENSES_LINK_TO_INTERVENTION)) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index ffef31cad8b..05be397fde3 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -37,9 +37,9 @@ class ExpenseReport extends CommonObject var $picto = 'trip'; var $lignes=array(); - + public $date_debut; - + public $date_fin; var $fk_user_validator; @@ -65,7 +65,7 @@ class ExpenseReport extends CommonObject // Update var $date_modif; var $fk_user_modif; - + // Refus var $date_refuse; var $detail_refuse; @@ -128,17 +128,17 @@ class ExpenseReport extends CommonObject $now = dol_now(); $error = 0; - + // Check parameters - if (empty($this->date_debut) || empty($this->date_fin)) + if (empty($this->date_debut) || empty($this->date_fin)) { $this->error='ErrorFieldRequired'; return -1; } - + $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. if (empty($fuserid)) $fuserid = $user->id; - + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; @@ -208,7 +208,7 @@ class ExpenseReport extends CommonObject $result=$this->update_price(); if ($result > 0) { - + if (!$notrigger) { // Call trigger @@ -262,19 +262,19 @@ class ExpenseReport extends CommonObject function createFromClone($fk_user_author) { global $user,$hookmanager; - + $error=0; - + if (empty($fk_user_author)) $fk_user_author = $user->id; - + $this->context['createfromclone'] = 'createfromclone'; - + $this->db->begin(); - + // get extrafields so they will be clone //foreach($this->lines as $line) //$line->fetch_optionals($line->rowid); - + // Load source object $objFrom = clone $this; @@ -325,8 +325,8 @@ class ExpenseReport extends CommonObject return -1; } } - - + + /** * update * @@ -341,7 +341,7 @@ class ExpenseReport extends CommonObject $error = 0; $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql.= " total_ht = ".$this->total_ht; $sql.= " , total_ttc = ".$this->total_ttc; @@ -417,7 +417,8 @@ class ExpenseReport extends CommonObject $sql.= " d.fk_user_valid, d.fk_user_approve,"; $sql.= " d.fk_statut as status, d.fk_c_paiement,"; $sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id AND dp.entity = " . getEntity('c_paiement', 2); if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'"; else $sql.= " WHERE d.rowid = ".$id; $sql.= $restrict; @@ -455,7 +456,7 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $obj->fk_user_refuse; $this->fk_user_cancel = $obj->fk_user_cancel; $this->fk_user_approve = $obj->fk_user_approve; - + $user_author = new User($this->db); if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author); @@ -512,7 +513,7 @@ class ExpenseReport extends CommonObject { $error = 0; $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport"; $sql.= " SET fk_statut = 6, paid=1"; $sql.= " WHERE rowid = ".$id." AND fk_statut = 5"; @@ -533,7 +534,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -670,7 +671,7 @@ class ExpenseReport extends CommonObject $auser->fetch($obj->fk_user_approve); $this->user_approve = $auser; } - + } $this->db->free($resql); } @@ -704,8 +705,8 @@ class ExpenseReport extends CommonObject $this->date_fin = $now; $this->date_approve = $now; - $type_fees_id = 2; // TF_TRIP - + $type_fees_id = 2; // TF_TRIP + $this->status = 5; $this->fk_statut = 5; @@ -1078,14 +1079,14 @@ class ExpenseReport extends CommonObject { $now = dol_now(); $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."'"; if ($update_number_int) { $sql.= ", ref_number_int = ".$ref_number_int; } $sql.= ' WHERE rowid = '.$this->id; - + $resql=$this->db->query($sql); if ($resql) { @@ -1099,7 +1100,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1123,7 +1124,7 @@ class ExpenseReport extends CommonObject { dol_syslog(get_class($this)."::setValidate expensereport already with validated status", LOG_WARNING); } - + return 0; } @@ -1183,13 +1184,13 @@ class ExpenseReport extends CommonObject { $now=dol_now(); $error = 0; - + // date approval $this->date_approve = $this->db->idate($now); if ($this->fk_statut != 5) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = 5, fk_user_approve = ".$fuser->id.","; $sql.= " date_approve='".$this->db->idate($this->date_approve)."'"; @@ -1206,7 +1207,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1230,7 +1231,7 @@ class ExpenseReport extends CommonObject { dol_syslog(get_class($this)."::setApproved expensereport already with approve status", LOG_WARNING); } - + return 0; } @@ -1245,7 +1246,7 @@ class ExpenseReport extends CommonObject { $now = dol_now(); $error = 0; - + // date de refus if ($this->fk_statut != 99) { @@ -1261,7 +1262,7 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $fuser->id; $this->detail_refuse = $details; $this->date_refuse = $now; - + if (!$notrigger) { // Call trigger @@ -1272,7 +1273,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1308,11 +1309,11 @@ class ExpenseReport extends CommonObject function set_unpaid($fuser, $notrigger = 0) { $error = 0; - + if ($this->fk_c_deplacement_statuts != 5) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET fk_statut = 5"; $sql.= ' WHERE rowid = '.$this->id; @@ -1331,7 +1332,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1372,7 +1373,7 @@ class ExpenseReport extends CommonObject if ($this->fk_statut != 4) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET fk_statut = 4, fk_user_cancel = ".$fuser->id; $sql.= ", date_cancel='".$this->db->idate($this->date_cancel)."'"; @@ -1393,7 +1394,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1433,7 +1434,7 @@ class ExpenseReport extends CommonObject $sql = 'SELECT MAX(de.ref_number_int) as max'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de'; - + $result = $this->db->query($sql); if($this->db->num_rows($result) > 0): @@ -1758,7 +1759,7 @@ class ExpenseReport extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; $sql.= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; //print $sql; - + dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql); $result = $this->db->query($sql); if($result) @@ -1895,7 +1896,7 @@ class ExpenseReport extends CommonObject $now=dol_now(); $userchildids = $user->getAllChildIds(1); - + $sql = "SELECT ex.rowid, ex.date_valid"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; if ($option == 'toapprove') $sql.= " WHERE ex.fk_statut = 2"; @@ -1927,7 +1928,7 @@ class ExpenseReport extends CommonObject while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - + if ($option == 'toapprove') { if ($this->db->jdate($obj->date_valid) < ($now - $conf->expensereport->approve->warning_delay)) { @@ -1951,7 +1952,7 @@ class ExpenseReport extends CommonObject return -1; } } - + /** * Return if an expense report is late or not * @@ -1961,11 +1962,11 @@ class ExpenseReport extends CommonObject public function hasDelay($option) { global $conf; - + //Only valid members if ($option == 'toapprove' && $this->status != 2) return false; if ($option == 'topay' && $this->status != 5) return false; - + $now = dol_now(); if ($option == 'toapprove') { @@ -1973,7 +1974,7 @@ class ExpenseReport extends CommonObject } else return ($this->datevalid?$this->datevalid:$this->date_valid) < ($now - $conf->expensereport->payment->warning_delay); - } + } } diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index edd80a0bff5..51321460760 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -168,6 +168,7 @@ class PaymentExpenseReport extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_expensereport as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -447,7 +448,7 @@ class PaymentExpenseReport extends CommonObject function LibStatut($statut,$mode=0) { global $langs; - + return ''; } @@ -506,7 +507,7 @@ class PaymentExpenseReport extends CommonObject $total=$this->total; if ($mode == 'payment_expensereport') $amount=$total; - + // Insert payment into llx_bank $bank_line_id = $acc->addline( $this->datepaid, @@ -543,7 +544,7 @@ class PaymentExpenseReport extends CommonObject dol_print_error($this->db); } } - + // Add link 'user' in bank_url between user and bank transaction if (! $error) { @@ -561,7 +562,7 @@ class PaymentExpenseReport extends CommonObject $er->user->getFullName($langs), 'user' ); - if ($result <= 0) + if ($result <= 0) { $this->error=$this->db->lasterror(); dol_syslog(get_class($this).'::addPaymentToBank '.$this->error); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 159f76249df..84b346028c1 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -45,7 +45,7 @@ class CommandeFournisseur extends CommonOrder public $fk_element = 'fk_commande'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='order'; - + /** * {@inheritdoc} */ @@ -132,9 +132,9 @@ class CommandeFournisseur extends CommonOrder * Draft status */ const STATUS_DRAFT = 0; - - - + + + /** * Constructor * @@ -190,8 +190,8 @@ class CommandeFournisseur extends CommonOrder $sql.= ', c.fk_incoterms, c.location_incoterms'; $sql.= ', i.libelle as libelle_incoterms'; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term', 2) . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement', 2) . ")"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_input_method"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; $sql.= " WHERE c.entity = ".$conf->entity; @@ -318,7 +318,7 @@ class CommandeFournisseur extends CommonOrder $line->subprice = $objp->subprice; $line->pu_ht = $objp->subprice; $line->remise_percent = $objp->remise_percent; - + $line->vat_src_code = $objp->vat_src_code; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -615,7 +615,7 @@ class CommandeFournisseur extends CommonOrder $picto='order'; $url = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$this->id; - + $linkclose=''; if (empty($notooltip)) { @@ -627,7 +627,7 @@ class CommandeFournisseur extends CommonOrder $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; @@ -1378,7 +1378,7 @@ class CommandeFournisseur extends CommonOrder } $desc=trim($desc); $ref_supplier=''; // Ref of supplier price when we add line - + // Check parameters if ($qty < 1 && ! $fk_product) { @@ -1402,7 +1402,7 @@ class CommandeFournisseur extends CommonOrder { $product_type = $prod->type; $label = $prod->label; - + // We use 'none' instead of $fourn_ref, because fourn_ref may not exists anymore. So we will take the first supplier price ok. // If we want a dedicated supplier price, we must provide $fk_prod_fourn_price. $result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->fk_soc); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref/$this->fk_soc @@ -1414,7 +1414,7 @@ class CommandeFournisseur extends CommonOrder if ($remise_percent == 0 && $prod->remise_percent !=0) $remise_percent =$prod->remise_percent; - + } if ($result == 0) // If result == 0, we failed to found the supplier reference price { @@ -1422,7 +1422,7 @@ class CommandeFournisseur extends CommonOrder $this->error = "Ref " . $prod->ref . " " . $langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price"); - //$pu = $prod->fourn_pu; // We do not overwrite unit price + //$pu = $prod->fourn_pu; // We do not overwrite unit price //$ref = $prod->ref_fourn; // We do not overwrite ref supplier price return -1; } @@ -1468,7 +1468,7 @@ class CommandeFournisseur extends CommonOrder $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx,$pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -1487,7 +1487,7 @@ class CommandeFournisseur extends CommonOrder $localtax2_type=$localtaxes_type[2]; $subprice = price2num($pu,'MU'); - + $rangmax = $this->line_max(); $rang = $rangmax + 1; @@ -1513,7 +1513,7 @@ class CommandeFournisseur extends CommonOrder $this->line->subprice=$pu_ht; $this->line->rang=$this->rang; $this->line->info_bits=$info_bits; - + $this->line->vat_src_code=$vat_src_code; $this->line->total_ht=$total_ht; $this->line->total_tva=$total_tva; @@ -2001,7 +2001,7 @@ class CommandeFournisseur extends CommonOrder $old_statut = $this->statut; $this->statut = $statut; $this->actionmsg2 = $comment; - + // Call trigger $result=$this->call_trigger('ORDER_SUPPLIER_RECEIVE',$user); if ($result < 0) $error++; @@ -2334,7 +2334,7 @@ class CommandeFournisseur extends CommonOrder $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -2678,14 +2678,14 @@ class CommandeFournisseur extends CommonOrder if ($db->num_rows($query)) { $obj = $db->fetch_object($query); - + $string = $langs->trans($obj->code); if ($string == $obj->code) { $string = $obj->label != '-' ? $obj->label : ''; } return $string; - } + } } else dol_print_error($db); } @@ -2819,7 +2819,7 @@ class CommandeFournisseur extends CommonOrder return $text; } - + /** * Calc status regarding to dispatched stock * @@ -2828,7 +2828,7 @@ class CommandeFournisseur extends CommonOrder * @param string $comment Comment * @return int <0 if KO, 0 if not applicable, >0 if OK */ - public function calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='') + public function calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='') { global $conf, $langs; @@ -2845,14 +2845,14 @@ class CommandeFournisseur extends CommonOrder $filter['t.status']=1; } $ret=$supplierorderdispatch->fetchAll('','',0,0,$filter); - if ($ret<0) + if ($ret<0) { $this->error=$supplierorderdispatch->error; $this->errors=$supplierorderdispatch->errors; return $ret; - } - else + } + else { - if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) + if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) { //Build array with quantity deliverd by product foreach($supplierorderdispatch->lines as $line) { @@ -2861,12 +2861,12 @@ class CommandeFournisseur extends CommonOrder foreach($this->lines as $line) { $qtywished[$line->fk_product]+=$line->qty; } - + $date_liv = dol_now(); - + //Compare array $diff_array=array_diff_assoc($qtydelivered,$qtywished); - + if (count($diff_array)==0) //No diff => mean everythings is received { if ($closeopenorder) @@ -2888,8 +2888,8 @@ class CommandeFournisseur extends CommonOrder } return 4; } - } - else + } + else { //Diff => received partially $ret = $this->Livraison($user, $date_liv, 'par', $comment); // GETPOST("type") is 'tot', 'par', 'nev', 'can' @@ -3014,12 +3014,12 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->date_start = $this->db->jdate($objp->date_start); $this->date_end = $this->db->jdate($objp->date_end); $this->fk_unit = $objp->fk_unit; - + $this->multicurrency_subprice = $objp->multicurrency_subprice; $this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_tva = $objp->multicurrency_total_tva; $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->db->free($result); return 1; } @@ -3208,7 +3208,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ", subprice='".price2num($this->subprice)."'"; //$sql.= ",remise='".price2num($remise)."'"; $sql.= ", remise_percent='".price2num($this->remise_percent)."'"; - + $sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'"; $sql.= ", tva_tx='".price2num($this->tva_tx)."'"; $sql.= ", localtax1_tx='".price2num($this->total_localtax1)."'"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 5c8a41a0466..5ae4be6692d 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -130,7 +130,7 @@ class FactureFournisseur extends CommonInvoice public $multicurrency_total_ttc; //! id of source invoice if replacement invoice or credit note public $fk_facture_source; - + /** * Standard invoice */ @@ -517,8 +517,8 @@ class FactureFournisseur extends CommonInvoice $sql.= ' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (t.fk_mode_reglement = p.id)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term', 2) . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (t.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement', 2) . ")"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON t.fk_incoterms = i.rowid'; if ($id) $sql.= " WHERE t.rowid=".$id; if ($ref) $sql.= " WHERE t.ref='".$this->db->escape($ref)."'"; @@ -883,7 +883,7 @@ class FactureFournisseur extends CommonInvoice } // Fin appel triggers } - + if (! $error) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';'; @@ -902,7 +902,7 @@ class FactureFournisseur extends CommonInvoice $error++; } } - + if (! $error) { // Delete linked object diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 12fccab91d8..eb685f113ba 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -37,7 +37,7 @@ class PaiementFourn extends Paiement public $element='payment_supplier'; public $table_element='paiementfourn'; public $picto = 'payment'; - + var $statut; //Status of payment. 0 = unvalidated; 1 = validated // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...) // fk_paiement dans llx_paiement_facture est le rowid du paiement @@ -75,13 +75,14 @@ class PaiementFourn extends Paiement function fetch($id, $ref='', $fk_bank='') { $error=0; - + $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank,'; $sql.= ' c.code as paiement_code, c.libelle as paiement_type,'; $sql.= ' p.num_paiement, p.note, b.fk_account'; $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiementfourn as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; $sql.= ' WHERE p.fk_paiement = c.id'; + $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); if ($id > 0) $sql.= ' AND p.rowid = '.$id; else if ($ref) @@ -141,9 +142,9 @@ class PaiementFourn extends Paiement // Clean parameters $totalamount = 0; $totalamount_converted = 0; - + dol_syslog(get_class($this)."::create", LOG_DEBUG); - + if ($way == 'dolibarr') { $amounts = &$this->amounts; @@ -154,13 +155,13 @@ class PaiementFourn extends Paiement $amounts = &$this->multicurrency_amounts; $amounts_to_update = &$this->amounts; } - + foreach ($amounts as $key => $value) { $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way, 'facture_fourn'); $totalamount_converted += $value_converted; $amounts_to_update[$key] = price2num($value_converted, 'MT'); - + $newvalue = price2num($value,'MT'); $amounts[$key] = $newvalue; $totalamount += $newvalue; @@ -174,7 +175,7 @@ class PaiementFourn extends Paiement { $ref = $this->getNextNumRef(''); $now=dol_now(); - + if ($way == 'dolibarr') { $total = $totalamount; @@ -185,7 +186,7 @@ class PaiementFourn extends Paiement $total = $totalamount_converted; // Maybe use price2num with MT for the converted value $mtotal = $totalamount; } - + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn ('; $sql.= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)'; $sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',"; @@ -289,7 +290,7 @@ class PaiementFourn extends Paiement function delete($notrigger=0) { global $conf, $user, $langs; - + $bank_line_id = $this->bank_line; $this->db->begin(); @@ -358,7 +359,7 @@ class PaiementFourn extends Paiement return -4; } } - + if (! $notrigger) { // Appel des triggers @@ -370,7 +371,7 @@ class PaiementFourn extends Paiement } // Fin appel triggers } - + $this->db->commit(); return 1; } @@ -555,7 +556,7 @@ class PaiementFourn extends Paiement if ($withpicto != 2) $result.=$link.$text.$linkend; return $result; } - + /** * Initialise an instance with random values. * Used to build previews or test instances. @@ -579,7 +580,7 @@ class PaiementFourn extends Paiement $this->facid = 1; $this->datepaye = $nownotime; } - + /** * Return next reference of supplier invoice not already used (or last reference) * according to numbering module defined into constant SUPPLIER_PAYMENT_ADDON @@ -711,13 +712,13 @@ class PaiementFourn extends Paiement /** * get the right way of payment - * + * * @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs */ function getWay() { global $conf; - + $way = 'dolibarr'; if (!empty($conf->multicurrency->enabled)) { @@ -730,7 +731,7 @@ class PaiementFourn extends Paiement } } } - + return $way; } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 0ec657ccdfe..7b97b70d71d 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2321,7 +2321,7 @@ else $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement', 2); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; $sql.= ' ORDER BY p.datep, p.tms'; diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index f51246d8eea..a6b395b030a 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -214,7 +214,7 @@ if (empty($reshook)) setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors'); $error++; } - + // Check if payments in both currency if ($totalpayment > 0 && $multicurrency_totalpayment > 0) { @@ -341,7 +341,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie { $obj = $db->fetch_object($resql); $total = $obj->total; - + print load_fiche_titre($langs->trans('DoPayment')); print '
'; @@ -353,7 +353,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; dol_fiche_head(null); - + print ''; print '
'.$langs->trans('Company').''; @@ -384,7 +384,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '
'; dol_fiche_end(); - + $parameters=array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('paymentsupplierinvoices',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; @@ -447,19 +447,19 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie while ($i < $num) { $objp = $db->fetch_object($resql); - + print '
'; $invoicesupplierstatic->ref=$objp->ref; $invoicesupplierstatic->id=$objp->facid; print $invoicesupplierstatic->getNomUrl(1); print ''.$objp->ref_supplier.'!!!'.$objp->multicurrency_code."'; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { @@ -485,14 +485,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; - if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) - { + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) + { print price($objp->multicurrency_am); } print ''; - if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) { print price($objp->multicurrency_total_ttc - $objp->multicurrency_am); } @@ -500,20 +500,20 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } print ''.price($objp->total_ttc).''.price($objp->am).''.price($objp->total_ttc - $objp->am).''; $namef = 'amount_'.$objp->facid; if (!empty($conf->use_javascript_ajax)) print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->total_ttc - $objp->am)."'"); print ''; print "'; if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) @@ -525,7 +525,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } print "
\n"; - + print "
"; } $db->free($resql); @@ -574,7 +574,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '
'; if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',price($totalpayment),$langs->trans("Currency".$conf->currency)); - if (!empty($multicurrency_totalpayment)) + if (!empty($multicurrency_totalpayment)) { $text.='
'.$langs->trans('ConfirmSupplierPayment',price($multicurrency_totalpayment),$langs->trans("paymentInInvoiceCurrency")); } @@ -589,7 +589,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; } } - else dol_print_error($db); + else dol_print_error($db); } /* @@ -617,7 +617,7 @@ if (empty($action)) $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement', 2); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; @@ -635,14 +635,14 @@ if (empty($action)) $sql.= " GROUP BY p.rowid, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, c.code, c.libelle, ba.rowid, ba.label"; if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= $db->order($sortfield,$sortorder); - + $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } - + $sql.= $db->plimit($limit+1, $offset); $resql = $db->query($sql); @@ -667,9 +667,9 @@ if (empty($action)) $tmpkey=preg_replace('/search_options_/','',$key); if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - + $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); - + print_barre_liste($langs->trans('SupplierPayments'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit); print '
'; @@ -680,24 +680,24 @@ if (empty($action)) print ''; print ''; print ''; - + $moreforfilter=''; - + $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; - + if ($moreforfilter) { print '
'; print $moreforfilter; print '
'; } - + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - + print '
'; print ''."\n"; @@ -739,11 +739,11 @@ if (empty($action)) //print_liste_field_titre($langs->trans('Invoice'),$_SERVER["PHP_SELF"],'ref_supplier','',$param,'',$sortfield,$sortorder); print_liste_field_titre(''); print "\n"; - + while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - + print ''; // Ref payment @@ -764,7 +764,7 @@ if (empty($action)) // Payment number print ''; - + print ''; - print ''; - + $perm_libelle=($conf->global->MAIN_USE_ADVANCED_PERMS && ($langs->trans("PermissionAdvanced".$obj->id)!=("PermissionAdvanced".$obj->id))?$langs->trans("PermissionAdvanced".$obj->id):(($langs->trans("Permission".$obj->id)!=("Permission".$obj->id))?$langs->trans("Permission".$obj->id):$obj->libelle)); print ''; From cfe667a3cee4991ef5208918de756350d0a25e19 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 14:29:04 +0200 Subject: [PATCH 14/24] Fix: show all logs --- .travis.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index a040342b2e6..c7f63c2ef33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -275,26 +275,26 @@ script: set +e cd htdocs/install php upgrade.php 3.5.0 3.6.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade350360.log - php upgrade2.php 3.5.0 3.6.0 > $TRAVIS_BUILD_DIR/upgrade350360-2.log - php step5.php 3.5.0 3.6.0 > $TRAVIS_BUILD_DIR/upgrade350360-3.log + php upgrade2.php 3.5.0 3.6.0 >> $TRAVIS_BUILD_DIR/upgrade350360-2.log + php step5.php 3.5.0 3.6.0 >> $TRAVIS_BUILD_DIR/upgrade350360-3.log php upgrade.php 3.6.0 3.7.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade360370.log - php upgrade2.php 3.6.0 3.7.0 > $TRAVIS_BUILD_DIR/upgrade360370-2.log - php step5.php 3.6.0 3.7.0 > $TRAVIS_BUILD_DIR/upgrade360370-3.log + php upgrade2.php 3.6.0 3.7.0 >> $TRAVIS_BUILD_DIR/upgrade360370-2.log + php step5.php 3.6.0 3.7.0 >> $TRAVIS_BUILD_DIR/upgrade360370-3.log php upgrade.php 3.7.0 3.8.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade370380.log - php upgrade2.php 3.7.0 3.8.0 > $TRAVIS_BUILD_DIR/upgrade370380-2.log - php step5.php 3.7.0 3.8.0 > $TRAVIS_BUILD_DIR/upgrade370380-3.log + php upgrade2.php 3.7.0 3.8.0 >> $TRAVIS_BUILD_DIR/upgrade370380-2.log + php step5.php 3.7.0 3.8.0 >> $TRAVIS_BUILD_DIR/upgrade370380-3.log php upgrade.php 3.8.0 3.9.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade380390.log - php upgrade2.php 3.8.0 3.9.0 > $TRAVIS_BUILD_DIR/upgrade380390-2.log - php step5.php 3.8.0 3.9.0 > $TRAVIS_BUILD_DIR/upgrade380390-3.log + php upgrade2.php 3.8.0 3.9.0 >> $TRAVIS_BUILD_DIR/upgrade380390-2.log + php step5.php 3.8.0 3.9.0 >> $TRAVIS_BUILD_DIR/upgrade380390-3.log php upgrade.php 3.9.0 4.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade390400.log - php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade390400-2.log - php step5.php 3.9.0 4.0.0 > $TRAVIS_BUILD_DIR/upgrade390400-3.log + php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade390400-2.log + php step5.php 3.9.0 4.0.0 >> $TRAVIS_BUILD_DIR/upgrade390400-3.log php upgrade.php 4.0.0 5.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade400500.log - php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade400500-2.log - php step5.php 4.0.0 5.0.0 > $TRAVIS_BUILD_DIR/upgrade400500-3.log + php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade400500-2.log + php step5.php 4.0.0 5.0.0 >> $TRAVIS_BUILD_DIR/upgrade400500-3.log php upgrade.php 5.0.0 6.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade500600.log - php upgrade2.php 5.0.0 6.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade500600-2.log - php step5.php 5.0.0 6.0.0 > $TRAVIS_BUILD_DIR/upgrade500600-3.log + php upgrade2.php 5.0.0 6.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade500600-2.log + php step5.php 5.0.0 6.0.0 >> $TRAVIS_BUILD_DIR/upgrade500600-3.log cd - set +e echo From d4edca585726314e6dab230a53c232b90d486ccc Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 14:30:02 +0200 Subject: [PATCH 15/24] Revert "Fix: show all logs" This reverts commit cfe667a3cee4991ef5208918de756350d0a25e19. --- .travis.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7f63c2ef33..a040342b2e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -275,26 +275,26 @@ script: set +e cd htdocs/install php upgrade.php 3.5.0 3.6.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade350360.log - php upgrade2.php 3.5.0 3.6.0 >> $TRAVIS_BUILD_DIR/upgrade350360-2.log - php step5.php 3.5.0 3.6.0 >> $TRAVIS_BUILD_DIR/upgrade350360-3.log + php upgrade2.php 3.5.0 3.6.0 > $TRAVIS_BUILD_DIR/upgrade350360-2.log + php step5.php 3.5.0 3.6.0 > $TRAVIS_BUILD_DIR/upgrade350360-3.log php upgrade.php 3.6.0 3.7.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade360370.log - php upgrade2.php 3.6.0 3.7.0 >> $TRAVIS_BUILD_DIR/upgrade360370-2.log - php step5.php 3.6.0 3.7.0 >> $TRAVIS_BUILD_DIR/upgrade360370-3.log + php upgrade2.php 3.6.0 3.7.0 > $TRAVIS_BUILD_DIR/upgrade360370-2.log + php step5.php 3.6.0 3.7.0 > $TRAVIS_BUILD_DIR/upgrade360370-3.log php upgrade.php 3.7.0 3.8.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade370380.log - php upgrade2.php 3.7.0 3.8.0 >> $TRAVIS_BUILD_DIR/upgrade370380-2.log - php step5.php 3.7.0 3.8.0 >> $TRAVIS_BUILD_DIR/upgrade370380-3.log + php upgrade2.php 3.7.0 3.8.0 > $TRAVIS_BUILD_DIR/upgrade370380-2.log + php step5.php 3.7.0 3.8.0 > $TRAVIS_BUILD_DIR/upgrade370380-3.log php upgrade.php 3.8.0 3.9.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade380390.log - php upgrade2.php 3.8.0 3.9.0 >> $TRAVIS_BUILD_DIR/upgrade380390-2.log - php step5.php 3.8.0 3.9.0 >> $TRAVIS_BUILD_DIR/upgrade380390-3.log + php upgrade2.php 3.8.0 3.9.0 > $TRAVIS_BUILD_DIR/upgrade380390-2.log + php step5.php 3.8.0 3.9.0 > $TRAVIS_BUILD_DIR/upgrade380390-3.log php upgrade.php 3.9.0 4.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade390400.log - php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade390400-2.log - php step5.php 3.9.0 4.0.0 >> $TRAVIS_BUILD_DIR/upgrade390400-3.log + php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade390400-2.log + php step5.php 3.9.0 4.0.0 > $TRAVIS_BUILD_DIR/upgrade390400-3.log php upgrade.php 4.0.0 5.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade400500.log - php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade400500-2.log - php step5.php 4.0.0 5.0.0 >> $TRAVIS_BUILD_DIR/upgrade400500-3.log + php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade400500-2.log + php step5.php 4.0.0 5.0.0 > $TRAVIS_BUILD_DIR/upgrade400500-3.log php upgrade.php 5.0.0 6.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade500600.log - php upgrade2.php 5.0.0 6.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL >> $TRAVIS_BUILD_DIR/upgrade500600-2.log - php step5.php 5.0.0 6.0.0 >> $TRAVIS_BUILD_DIR/upgrade500600-3.log + php upgrade2.php 5.0.0 6.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade500600-2.log + php step5.php 5.0.0 6.0.0 > $TRAVIS_BUILD_DIR/upgrade500600-3.log cd - set +e echo From 2864d431482741c976e609fbd5cf4ba3b8a05239 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 14:31:19 +0200 Subject: [PATCH 16/24] Fix: missing all logs --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a040342b2e6..8da1b9fcd2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -299,8 +299,10 @@ script: set +e echo #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log + cat $TRAVIS_BUILD_DIR/upgrade500600.log cat $TRAVIS_BUILD_DIR/upgrade500600-2.log - cat /tmp/dolibarr_install.log + cat $TRAVIS_BUILD_DIR/upgrade500600-3.log + #cat /tmp/dolibarr_install.log - | echo "Unit testing" From fc08adff0f2a48a7798245abbaf0728ffc0e772c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 14:44:29 +0200 Subject: [PATCH 17/24] Fix: syntax error --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 996d218bf12..e990bb040e1 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -395,11 +395,11 @@ ALTER TABLE llx_usergroup_rights DROP INDEX fk_usergroup; ALTER TABLE llx_usergroup_rights ADD UNIQUE INDEX uk_usergroup_rights (entity, fk_usergroup, fk_id); ALTER TABLE llx_usergroup_rights ADD CONSTRAINT fk_usergroup_rights_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid); -ALTER TABLE llx_c_paiement DROP PRIMARY KEY +ALTER TABLE llx_c_paiement DROP PRIMARY KEY; ALTER TABLE llx_c_paiement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER id; ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement; ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(id, entity, code); -ALTER TABLE llx_c_payment_term DROP PRIMARY KEY +ALTER TABLE llx_c_payment_term DROP PRIMARY KEY; ALTER TABLE llx_c_payment_term ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(rowid, entity, code); From 735a24fb07aa47ac180b1b386686a7f053540e29 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 15:43:43 +0200 Subject: [PATCH 18/24] Fix: remove debug --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8da1b9fcd2b..6b47e5de600 100644 --- a/.travis.yml +++ b/.travis.yml @@ -299,9 +299,9 @@ script: set +e echo #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log - cat $TRAVIS_BUILD_DIR/upgrade500600.log - cat $TRAVIS_BUILD_DIR/upgrade500600-2.log - cat $TRAVIS_BUILD_DIR/upgrade500600-3.log + #cat $TRAVIS_BUILD_DIR/upgrade500600.log + #cat $TRAVIS_BUILD_DIR/upgrade500600-2.log + #cat $TRAVIS_BUILD_DIR/upgrade500600-3.log #cat /tmp/dolibarr_install.log - | From 6cac4b15d3e97be016608b1b16e749ab7fd11549 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 11 Jun 2017 06:54:40 +0200 Subject: [PATCH 19/24] Fix: Parameter must be an array or an object that implements Countable --- htdocs/core/lib/json.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 6b868663aa7..db343236e54 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -49,7 +49,7 @@ function dol_json_encode($elements) { dol_syslog('dol_json_encode() is deprecated. Please update your code to use native json_encode().', LOG_WARNING); - $num=count($elements); + $num = (is_null($elements) ? 0 : count($elements)); // for avoid phpunit error : "Parameter must be an array or an object that implements Countable" if (is_object($elements)) // Count number of properties for an object { $num=0; From c50b180e18b988d1bddfd113abc5fc624ab7e8d8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 19 Jun 2017 07:32:14 +0200 Subject: [PATCH 20/24] Fix: revert fix --- htdocs/install/inc.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index c799ab2c665..b9efc4eb8a4 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -453,11 +453,6 @@ function pFooter($nonext=0,$setuplang='',$jscheckfunction='', $withpleasewait=0) print '
'; if ($nonext == '2') { - if (!isset($_SERVER['REQUEST_URI'])) - { - $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 ); - if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; } - } print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"])?$_SERVER["REQUEST_URI"].'&ignoreerrors=1':'').'

'; } From cbd8cb8cb75690859cd182c1ce458d6da3f23707 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 15 Sep 2017 17:32:49 +0200 Subject: [PATCH 21/24] Fix: missing merge conflict --- .../facture/class/paymentterm.class.php | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index b08594fd09a..36ff6d73791 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -260,9 +260,10 @@ class PaymentTerm // extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user=null, $notrigger=0) - { - global $conf, $langs; + function update($user=null, $notrigger=0) + { + global $conf, $langs; + $error=0; // Clean parameters @@ -281,8 +282,8 @@ class PaymentTerm // extends CommonObject // Check parameters // Put here code to add control on parameters values - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_payment_term SET"; + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."c_payment_term SET"; $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; $sql.= " sortorder=".(isset($this->sortorder)?$this->sortorder:"null").","; $sql.= " active=".(isset($this->active)?$this->active:"null").","; @@ -291,44 +292,38 @@ class PaymentTerm // extends CommonObject $sql.= " type_cdr=".(isset($this->type_cdr)?$this->type_cdr:"null").","; $sql.= " nbjour=".(isset($this->nbjour)?$this->nbjour:"null").","; $sql.= " decalage=".(isset($this->decalage)?$this->decalage:"null").""; -<<<<<<< HEAD - - - $sql.= " WHERE rowid = " . $this->id; - $sql.= " AND entity = " . getEntity('c_payment_term', 2); -======= - $sql.= " WHERE rowid=".$this->id; ->>>>>>> branch 'develop' of https://github.com/Dolibarr/dolibarr.git + $sql.= " WHERE rowid = " . $this->id; + $sql.= " AND entity = " . getEntity('c_payment_term', 2); $this->db->begin(); dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $error) { if (! $notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } + // Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + // End call triggers + } } - // Commit or rollback + // Commit or rollback if ($error) { foreach($this->errors as $errmsg) { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); } $this->db->rollback(); return -1*$error; @@ -338,7 +333,7 @@ class PaymentTerm // extends CommonObject $this->db->commit(); return 1; } - } + } /** From 9823d6622c6b453b5caefb1d25fd66adeadac761 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 27 Sep 2017 17:40:02 +0200 Subject: [PATCH 22/24] Fix: use default $shared value --- dev/initdata/import-thirdparties.php | 2 +- htdocs/adherents/subscription.php | 2 +- htdocs/cashdesk/validation_verif.php | 6 +++--- htdocs/comm/propal/class/propal.class.php | 4 ++-- htdocs/commande/class/commande.class.php | 4 ++-- htdocs/compta/bank/bankentries.php | 2 +- htdocs/compta/bank/class/account.class.php | 2 +- htdocs/compta/bank/various_payment/index.php | 2 +- htdocs/compta/charges/index.php | 6 +++--- htdocs/compta/facture/card.php | 4 ++-- htdocs/compta/facture/class/facture-rec.class.php | 4 ++-- htdocs/compta/facture/class/facture.class.php | 8 ++++---- htdocs/compta/facture/class/paymentterm.class.php | 10 +++++----- htdocs/compta/paiement.php | 4 ++-- htdocs/compta/paiement/avalider.php | 2 +- .../paiement/cheque/class/remisecheque.class.php | 2 +- htdocs/compta/paiement/class/paiement.class.php | 2 +- htdocs/compta/paiement/list.php | 4 ++-- htdocs/compta/resultat/clientfourn.php | 4 ++-- htdocs/compta/resultat/index.php | 4 ++-- htdocs/compta/salaries/index.php | 2 +- htdocs/compta/sociales/card.php | 2 +- htdocs/compta/sociales/class/chargesociales.class.php | 2 +- .../sociales/class/paymentsocialcontribution.class.php | 2 +- htdocs/compta/sociales/payments.php | 2 +- htdocs/compta/tva/reglement.php | 2 +- htdocs/core/class/commoninvoice.class.php | 2 +- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/core/class/translate.class.php | 2 +- htdocs/core/lib/functions.lib.php | 3 +-- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 2 +- htdocs/core/modules/modFacture.class.php | 2 +- htdocs/core/modules/modSalaries.class.php | 2 +- htdocs/core/modules/modSociete.class.php | 4 ++-- .../supplier_invoice/pdf/pdf_canelle.modules.php | 2 +- htdocs/don/card.php | 2 +- htdocs/don/class/don.class.php | 2 +- htdocs/don/class/paymentdonation.class.php | 2 +- htdocs/expensereport/card.php | 2 +- htdocs/expensereport/class/expensereport.class.php | 2 +- .../expensereport/class/paymentexpensereport.class.php | 2 +- htdocs/fourn/class/fournisseur.commande.class.php | 4 ++-- htdocs/fourn/class/fournisseur.facture.class.php | 4 ++-- htdocs/fourn/class/paiementfourn.class.php | 2 +- htdocs/fourn/facture/card.php | 2 +- htdocs/fourn/facture/paiement.php | 2 +- htdocs/loan/card.php | 2 +- htdocs/loan/class/loanschedule.class.php | 2 +- htdocs/loan/class/paymentloan.class.php | 2 +- .../class/supplier_proposal.class.php | 4 ++-- 50 files changed, 74 insertions(+), 75 deletions(-) diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php index 05fd0689102..a5ccbf2c45d 100755 --- a/dev/initdata/import-thirdparties.php +++ b/dev/initdata/import-thirdparties.php @@ -149,7 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $condpayment = trim($fields[36]); if ($condpayment == 'A la commande') $condpayment = 'A réception de commande'; if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture'; - $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', getEntity('c_payment_term', 2)); + $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', getEntity('c_payment_term')); if (empty($object->cond_reglement_id)) { print " - Error cant find payment mode for ".$condpayment."\n"; diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index f192469e301..132d616e17b 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -461,7 +461,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && ! $paiement = new Paiement($db); $paiement->datepaye = $paymentdate; $paiement->amounts = $amounts; - $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',getEntity('c_paiement', 2)); + $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',getEntity('c_paiement')); $paiement->num_paiement = $num_chq; $paiement->note = $label; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 88c1e62a479..9937deab531 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -136,7 +136,7 @@ switch ($action) $cond_reglement_id = 0; break; case 'ESP': - $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',getEntity('c_paiement', 2)); + $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',getEntity('c_paiement')); $cond_reglement_id = 0; $note .= $langs->trans("Cash")."\n"; $note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n"; @@ -145,11 +145,11 @@ switch ($action) $note .= '--------------------------------------'."\n\n"; break; case 'CB': - $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',getEntity('c_paiement', 2)); + $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',getEntity('c_paiement')); $cond_reglement_id = 0; break; case 'CHQ': - $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',getEntity('c_paiement', 2)); + $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',getEntity('c_paiement')); $cond_reglement_id = 0; break; } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 316227cbe42..ca470b9d668 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1271,8 +1271,8 @@ class Propal extends CommonObject $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."propal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement'); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term'); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3104ec7f975..283c5e3d663 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1559,8 +1559,8 @@ class Commande extends CommonOrder $sql.= ', ca.code as availability_code, ca.label as availability_label'; $sql.= ', dr.code as demand_reason_code'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2) . ')'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2) . ')'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term') . ')'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement') . ')'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_input_reason = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; diff --git a/htdocs/compta/bank/bankentries.php b/htdocs/compta/bank/bankentries.php index acd8ab93aef..78ffe7f61ec 100644 --- a/htdocs/compta/bank/bankentries.php +++ b/htdocs/compta/bank/bankentries.php @@ -1161,7 +1161,7 @@ if ($resql) if (! empty($arrayfields['type']['checked'])) { print '
\n"; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 881616ebc45..576c477116c 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -414,7 +414,7 @@ class Account extends CommonObject { $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE id=".$oper; - $sql.= " AND entity = " . getEntity('c_paiement', 2) . ")"; + $sql.= " AND entity = " . getEntity('c_paiement') . ")"; $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/compta/bank/various_payment/index.php b/htdocs/compta/bank/various_payment/index.php index ef0d45751a9..db668b47eef 100644 --- a/htdocs/compta/bank/various_payment/index.php +++ b/htdocs/compta/bank/various_payment/index.php @@ -96,7 +96,7 @@ $sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,"; $sql.= " pst.code as payment_code"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement'); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE v.entity = ".$conf->entity; diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index c7d58a7070c..a504a730976 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -139,7 +139,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement'); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE cs.fk_type = c.id"; @@ -260,7 +260,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."tva as pv"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pv.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement'); $sql.= " WHERE pv.entity = ".$conf->entity; if ($year > 0) { @@ -474,7 +474,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement'); $sql.= " , ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE s.entity IN (".getEntity('user').")"; $sql.= " AND u.rowid = s.fk_user"; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 7fb0b86a39a..be4de99efb5 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -721,7 +721,7 @@ if (empty($reshook)) $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p'; $sql.= ' WHERE pf.fk_facture = '.$object->id; $sql.= ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; - $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND c.entity = ' . getEntity('c_paiement'); $sql.= ' ORDER BY p.datep, p.tms'; $resql = $db->query($sql); @@ -3802,7 +3802,7 @@ else if ($id > 0 || ! empty($ref)) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; - $sql .= ' AND c.entity = ' . getEntity('c_paiement', 2); + $sql .= ' AND c.entity = ' . getEntity('c_paiement'); $sql .= ' ORDER BY p.datep, p.tms'; $result = $db->query($sql); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index db7d4f09752..5ff3e0d065f 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -262,8 +262,8 @@ class FactureRec extends CommonInvoice $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; //$sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term', 2); - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term'); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement'); //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'"; if ($rowid) $sql.= ' WHERE f.rowid='.$rowid; elseif ($ref) $sql.= " WHERE f.titre='".$this->db->escape($ref)."'"; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d4a68b29ef6..485256d4529 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1197,8 +1197,8 @@ class Facture extends CommonInvoice $sql.= ', f.fk_incoterms, f.location_incoterms'; $sql.= ", i.libelle as libelle_incoterms"; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term', 2); - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity = ' . getEntity('c_payment_term'); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement'); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON f.fk_incoterms = i.rowid'; $sql.= ' WHERE f.entity = '.$conf->entity; if ($rowid) $sql.= " AND f.rowid=".$rowid; @@ -3167,7 +3167,7 @@ class Facture extends CommonInvoice //$sql.= ' WHERE pf.'.$field.' = 1'; $sql.= ' AND pf.'.$field2.' = p.rowid'; $sql.= ' AND p.fk_paiement = t.id'; - $sql.= ' AND t.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND t.entity = ' . getEntity('c_paiement'); if ($filtertype) $sql.=" AND t.code='PRE'"; dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG); @@ -3650,7 +3650,7 @@ class Facture extends CommonInvoice if (! $error) { // Force payment mode of invoice to withdraw - $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', getEntity('c_paiement', 2)); + $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', getEntity('c_paiement')); if ($payment_mode_id > 0) { $result=$this->setPaymentMethods($payment_mode_id); diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index 36ff6d73791..bc13b0d5876 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -102,7 +102,7 @@ class PaymentTerm // extends CommonObject $sql.= "decalage"; $sql.= ") VALUES ("; $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; - $sql.= " ".(! isset($this->entity)?getEntity('c_payment_term', 2):"'".$this->db->escape($this->entity)."'").","; + $sql.= " ".(! isset($this->entity)?getEntity('c_payment_term'):"'".$this->db->escape($this->entity)."'").","; $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; $sql.= " ".(! isset($this->sortorder)?'NULL':"'".$this->db->escape($this->sortorder)."'").","; $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").","; @@ -181,7 +181,7 @@ class PaymentTerm // extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; $sql.= " WHERE t.rowid = ".$id; - $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); + $sql.= " AND t.entity = " . getEntity('c_payment_term'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -231,7 +231,7 @@ class PaymentTerm // extends CommonObject $sql.= " t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; $sql.= " WHERE t.code = 'RECEP'"; - $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); + $sql.= " AND t.entity = " . getEntity('c_payment_term'); dol_syslog(get_class($this)."::getDefaultId", LOG_DEBUG); $resql=$this->db->query($sql); @@ -293,7 +293,7 @@ class PaymentTerm // extends CommonObject $sql.= " nbjour=".(isset($this->nbjour)?$this->nbjour:"null").","; $sql.= " decalage=".(isset($this->decalage)?$this->decalage:"null").""; $sql.= " WHERE rowid = " . $this->id; - $sql.= " AND entity = " . getEntity('c_payment_term', 2); + $sql.= " AND entity = " . getEntity('c_payment_term'); $this->db->begin(); @@ -350,7 +350,7 @@ class PaymentTerm // extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_payment_term"; $sql.= " WHERE rowid = " . $this->id; - $sql.= " AND t.entity = " . getEntity('c_payment_term', 2); + $sql.= " AND t.entity = " . getEntity('c_payment_term'); $this->db->begin(); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index e9d9dd6984f..b2ba863d096 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -251,7 +251,7 @@ if (empty($reshook)) $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',getEntity('c_paiement', 2)); + $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',getEntity('c_paiement')); $paiement->num_paiement = GETPOST('num_paiement'); $paiement->note = GETPOST('comment'); @@ -832,7 +832,7 @@ if (! GETPOST('action','aZ09')) $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c'; $sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id'; $sql.= ' AND f.entity = ' . $conf->entity; - $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND c.entity = ' . getEntity('c_paiement'); if ($socid) { $sql.= ' AND f.fk_soc = '.$socid; diff --git a/htdocs/compta/paiement/avalider.php b/htdocs/compta/paiement/avalider.php index b8ea972dc52..4c7fafe4429 100644 --- a/htdocs/compta/paiement/avalider.php +++ b/htdocs/compta/paiement/avalider.php @@ -72,7 +72,7 @@ if ($socid) } $sql.= " WHERE p.fk_paiement = c.id"; $sql.= " AND p.entity = " . $conf->entity; -$sql.= " AND c.entity = " . getEntity('c_paiement', 2); +$sql.= " AND c.entity = " . getEntity('c_paiement'); if ($socid) { $sql.= " AND f.fk_soc = ".$socid; diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 46e50fba56e..df6b8ead3b8 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -753,7 +753,7 @@ class RemiseCheque extends CommonObject $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; - $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',getEntity('c_paiement', 2)); + $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',getEntity('c_paiement')); $rejectedPayment->num_paiement = $payment->numero; while($obj = $db->fetch_object($resql)) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index f2b8cb26cdf..23dfafbeb8b 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -93,7 +93,7 @@ class Paiement extends CommonObject $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; $sql.= ' WHERE p.fk_paiement = c.id'; - $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND c.entity = ' . getEntity('c_paiement'); if ($id > 0) $sql.= ' AND p.rowid = '.$id; else if ($ref) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index f7938811057..b7b0b0489e2 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -120,7 +120,7 @@ if (GETPOST("orphelins")) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql.= " WHERE p.fk_paiement = c.id"; $sql.= " AND p.entity = " . $conf->entity; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); $sql.= " AND pf.fk_facture IS NULL"; // Add where from hooks $parameters=array(); @@ -152,7 +152,7 @@ else } $sql.= " WHERE p.fk_paiement = c.id"; $sql.= " AND p.entity = " . $conf->entity; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); if (! $user->rights->societe->client->voir && ! $socid) { $sql.= " AND sc.fk_user = " .$user->id; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 14d4ee994f4..eea830dfbc5 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -822,7 +822,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement'); $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; @@ -906,7 +906,7 @@ else $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement'); $sql.= " WHERE p.entity = ".getEntity('donation'); $sql.= " AND fk_statut >= 2"; } diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 983b3faa5e0..bd1d8effcc7 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -698,7 +698,7 @@ if (! empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement'); $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; @@ -761,7 +761,7 @@ if (! empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement'); $sql.= " WHERE p.entity = ".getEntity('donation'); $sql.= " AND fk_statut >= 2"; if (! empty($date_start) && ! empty($date_end)) diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php index 9a5c352b739..6928d3e38f6 100644 --- a/htdocs/compta/salaries/index.php +++ b/htdocs/compta/salaries/index.php @@ -105,7 +105,7 @@ $sql.= " s.rowid, s.fk_user, s.amount, s.salary, s.label, s.datep as datep, s.da $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,"; $sql.= " pst.code as payment_code"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement'); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,"; $sql.= " ".MAIN_DB_PREFIX."user as u"; diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 7d32da6f937..a8f795115c4 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -581,7 +581,7 @@ if ($id > 0) $sql.= " AND p.fk_charge = cs.rowid"; $sql.= " AND cs.entity = ".$conf->entity; $sql.= " AND p.fk_typepaiement = c.id"; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); $sql.= " ORDER BY dp DESC"; //print $sql; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 15774c04ed3..ab60f007e55 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -83,7 +83,7 @@ class ChargeSociales extends CommonObject $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement'); if ($ref) $sql.= " WHERE cs.rowid = ".$ref; else $sql.= " WHERE cs.rowid = ".$id; diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 8a5c8f0eeef..6c7cda1f07e 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -205,7 +205,7 @@ class PaymentSocialContribution extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; - $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); + $sql.= " AND pt.entity = " . getEntity('c_paiement'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php index 0f197b9495b..0bdff23007a 100644 --- a/htdocs/compta/sociales/payments.php +++ b/htdocs/compta/sociales/payments.php @@ -133,7 +133,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs,"; $sql.= " ".MAIN_DB_PREFIX."paiementcharge as pc"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement'); $sql.= " WHERE cs.fk_type = c.id AND pc.fk_charge = cs.rowid"; $sql.= " AND cs.entity = ".$conf->entity; if ($year > 0) diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 23b63afeb22..c22fb4ed30a 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -100,7 +100,7 @@ $bankstatic = new Account($db); $sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,"; $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement', 2); +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement'); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE t.entity = ".$conf->entity; diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index a9802db1205..dce39a950aa 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -450,7 +450,7 @@ abstract class CommonInvoice extends CommonObject $sqltemp = 'SELECT c.type_cdr,c.nbjour,c.decalage'; $sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; - $sqltemp.= " WHERE c.entity = " . getEntity('c_payment_term', 2); + $sqltemp.= " WHERE c.entity = " . getEntity('c_payment_term'); if (is_numeric($cond_reglement)) $sqltemp.= " AND c.rowid=".$cond_reglement; else $sqltemp.= " AND c.code='".$this->db->escape($cond_reglement)."'"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 12f88eef153..1df33c7bccf 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2737,7 +2737,7 @@ class Form $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; - $sql.= " WHERE entity = " . getEntity('c_payment_term', 2); + $sql.= " WHERE entity = " . getEntity('c_payment_term'); $sql.= " AND active > 0"; $sql.= " ORDER BY sortorder"; @@ -2952,7 +2952,7 @@ class Form $sql = "SELECT id, code, libelle as label, type, active"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; - $sql.= " WHERE entity = " . getEntity('c_paiement', 2); + $sql.= " WHERE entity = " . getEntity('c_paiement'); //if ($active >= 0) $sql.= " AND active = ".$active; $resql = $this->db->query($sql); diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 008049d3d13..66bde287ad1 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -559,7 +559,7 @@ class Translate } elseif (preg_match('/^PaymentTypeShort([0-9A-Z]+)$/i',$key,$reg)) { - $newstr=$this->getLabelFromKey($db,$reg[1],'c_paiement','code','libelle','',getEntity('c_paiement', 2)); + $newstr=$this->getLabelFromKey($db,$reg[1],'c_paiement','code','libelle','',getEntity('c_paiement')); } elseif (preg_match('/^OppStatusShort([0-9A-Z]+)$/i',$key,$reg)) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 566416016aa..7fe650f7c2c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -111,8 +111,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * 'contract', 'tax', 'expensereport', 'holiday', 'multicurrency', 'project', * 'email_template', 'event', * @param int $shared 0=Return id of current entity only, - * 1=Return id of current entity + shared entities (default), - * 2=Return id of current entity OR master entity 1 value (eg. dictionnary share) + * 1=Return id of current entity + shared entities (default) * @param int $forceentity Entity id * @return mixed Entity id(s) to use */ diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 0552e2fb4a6..3617a130c68 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -820,7 +820,7 @@ class pdf_crabe extends ModelePDFFactures $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement'); $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1"; $sql.= " ORDER BY p.datep"; diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 8655b8832ad..6e3c1660fb2 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -260,7 +260,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement AND pt.entity = ' . getEntity('c_paiement', 2); + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement AND pt.entity = ' . getEntity('c_paiement'); $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; diff --git a/htdocs/core/modules/modSalaries.class.php b/htdocs/core/modules/modSalaries.class.php index 729023456f8..6b84e549d10 100644 --- a/htdocs/core/modules/modSalaries.class.php +++ b/htdocs/core/modules/modSalaries.class.php @@ -165,7 +165,7 @@ class modSalaries extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id AND cp.entity = ' . getEntity('c_paiement'); $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('user').')'; } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 229db9763e5..c01bdca6985 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -284,8 +284,8 @@ class modSociete extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid AND payterm.entity = ' . getEntity('c_payment_term', 2); - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id AND paymode.entity = ' . getEntity('c_paiement', 2); + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid AND payterm.entity = ' . getEntity('c_payment_term'); + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id AND paymode.entity = ' . getEntity('c_paiement'); $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe').')'; if (is_object($user) && empty($user->rights->societe->client->voir)) { $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' '; diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index a11a517904a..53d47ebc608 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -933,7 +933,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity = " . getEntity('c_paiement'); $sql.= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".$object->id; $sql.= " ORDER BY p.datep"; $resql=$this->db->query($sql); diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 14ce9a86403..6998b7bdb52 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -638,7 +638,7 @@ if (! empty($id) && $action != 'edit') $sql.= " AND p.fk_donation = d.rowid"; $sql.= " AND d.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); $sql.= " ORDER BY dp"; //print $sql; diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index 2c92e52be7c..0a683fea355 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -611,7 +611,7 @@ class Don extends CommonObject $sql.= " c.code as country_code, c.label as country"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment AND cp.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment AND cp.entity = " . getEntity('c_paiement'); $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid"; if (! empty($id)) { diff --git a/htdocs/don/class/paymentdonation.class.php b/htdocs/don/class/paymentdonation.class.php index 5752878fecf..22fbcd6dab4 100644 --- a/htdocs/don/class/paymentdonation.class.php +++ b/htdocs/don/class/paymentdonation.class.php @@ -175,7 +175,7 @@ class PaymentDonation extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_donation as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; - $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); + $sql.= " AND pt.entity = " . getEntity('c_paiement'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index e337c1e1c72..8ba9f40c04d 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1865,7 +1865,7 @@ else $sql.= " AND p.fk_expensereport = e.rowid"; $sql.= ' AND e.entity IN ('.getEntity('expensereport').')'; $sql.= " AND p.fk_typepayment = c.id"; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); $sql.= " ORDER BY dp"; $resql = $db->query($sql); diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index c135d92a12c..3f2db4f984c 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -448,7 +448,7 @@ class ExpenseReport extends CommonObject $sql.= " d.fk_statut as status, d.fk_c_paiement,"; $sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id AND dp.entity = " . getEntity('c_paiement', 2); + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id AND dp.entity = " . getEntity('c_paiement'); if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'"; else $sql.= " WHERE d.rowid = ".$id; //$sql.= $restrict; diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index 3935021041a..b836f410245 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -168,7 +168,7 @@ class PaymentExpenseReport extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_expensereport as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; - $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); + $sql.= " AND pt.entity = " . getEntity('c_paiement'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 9335e4dcbb4..cf52c06ae55 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -190,8 +190,8 @@ class CommandeFournisseur extends CommonOrder $sql.= ', c.fk_incoterms, c.location_incoterms'; $sql.= ', i.libelle as libelle_incoterms'; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term', 2) . ")"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement', 2) . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term') . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement') . ")"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_input_method"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; $sql.= " WHERE c.entity = ".$conf->entity; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 5410d7aba65..76b9a70c7dc 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -517,8 +517,8 @@ class FactureFournisseur extends CommonInvoice $sql.= ' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term', 2) . ")"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (t.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement', 2) . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid AND cr.entity = " . getEntity('c_payment_term') . ")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (t.fk_mode_reglement = p.id AND p.entity = " . getEntity('c_paiement') . ")"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON t.fk_incoterms = i.rowid'; if ($id) $sql.= " WHERE t.rowid=".$id; if ($ref) $sql.= " WHERE t.ref='".$this->db->escape($ref)."'"; diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 6ae730732d9..f2d5460a864 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -82,7 +82,7 @@ class PaiementFourn extends Paiement $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiementfourn as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid '; $sql.= ' WHERE p.fk_paiement = c.id'; - $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND c.entity = ' . getEntity('c_paiement'); if ($id > 0) $sql.= ' AND p.rowid = '.$id; else if ($ref) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index bd883091059..28b57ea5931 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2358,7 +2358,7 @@ else $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement'); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; $sql.= ' ORDER BY p.datep, p.tms'; diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 21e10e6a8d5..5000494bcd3 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -745,7 +745,7 @@ if (empty($action)) $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id AND c.entity = ' . getEntity('c_paiement'); $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 57eb4eb62c6..2edf3c34547 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -642,7 +642,7 @@ if ($id > 0) $sql.= " AND p.fk_loan = l.rowid"; $sql.= " AND l.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; - $sql.= " AND c.entity = " . getEntity('c_paiement', 2); + $sql.= " AND c.entity = " . getEntity('c_paiement'); $sql.= " ORDER BY dp DESC"; //print $sql; diff --git a/htdocs/loan/class/loanschedule.class.php b/htdocs/loan/class/loanschedule.class.php index 90729dd3468..c5794b52daf 100644 --- a/htdocs/loan/class/loanschedule.class.php +++ b/htdocs/loan/class/loanschedule.class.php @@ -179,7 +179,7 @@ class LoanSchedule extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX.$this->table_element." as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; - $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); + $sql.= " AND pt.entity = " . getEntity('c_paiement'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index ec6672d898f..836acd082e1 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -178,7 +178,7 @@ class PaymentLoan extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_loan as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; - $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); + $sql.= " AND pt.entity = " . getEntity('c_paiement'); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index b6166124af0..1234e3c4468 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1116,8 +1116,8 @@ class SupplierProposal extends CommonObject $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement'); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term'); $sql.= " WHERE p.fk_statut = c.id"; $sql.= " AND p.entity = ".$conf->entity; if ($ref) $sql.= " AND p.ref='".$ref."'"; From a38668033d2ca3e5c5bba3557b7581428c584c18 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 27 Sep 2017 17:46:17 +0200 Subject: [PATCH 23/24] Fix: missing modification --- htdocs/admin/dict.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 32f895dc1ec..673ce2f2d24 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -182,8 +182,8 @@ $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as $tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c"; $tabsql[10]= "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid"; $tabsql[11]= "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t"; -$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = " . getEntity($tabname[12], 2); -$tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = " . getEntity($tabname[13], 2); +$tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = " . getEntity($tabname[12]); +$tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = " . getEntity($tabname[13]); $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1"; $tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format"; $tabsql[16]= "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel"; @@ -734,7 +734,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); } else if ($value == 'entity') { - $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id], 2); + $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id]); } if ($i) $sql.=","; if ($listfieldvalue[$i] == 'sortorder') // For column name 'sortorder', we use the field name 'position' @@ -786,7 +786,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); } else if ($field == 'entity') { - $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id], 2); + $_POST[$listfieldvalue[$i]] = getEntity($tabname[$id]); } if ($i) $sql.=","; $sql.= $field."="; @@ -799,7 +799,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) $i++; } $sql.= " WHERE ".$rowidcol." = '".$rowid."'"; - $sql.= " AND entity = '".getEntity($tabname[$id], 2)."'"; + $sql.= " AND entity = '".getEntity($tabname[$id])."'"; dol_syslog("actionmodify", LOG_DEBUG); //print $sql; @@ -1031,7 +1031,7 @@ if ($id) foreach ($fieldlist as $field => $value) { if ($fieldlist[$field] == 'entity') { - $withentity = getEntity($tabname[$id], 2); + $withentity = getEntity($tabname[$id]); continue; } From e65b21a3bf4fa6b6e6b220f29cf86000e9bc335c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 2 Oct 2017 11:59:17 +0200 Subject: [PATCH 24/24] Fix: change the parameter value of dol_getIdFromCode --- dev/initdata/import-thirdparties.php | 2 +- htdocs/adherents/subscription.php | 2 +- htdocs/cashdesk/validation_verif.php | 6 ++-- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/compta/paiement.php | 2 +- .../cheque/class/remisecheque.class.php | 32 +++++++++---------- htdocs/core/lib/functions.lib.php | 20 ++++++------ 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php index a5ccbf2c45d..0c32c7ea6a3 100755 --- a/dev/initdata/import-thirdparties.php +++ b/dev/initdata/import-thirdparties.php @@ -149,7 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $condpayment = trim($fields[36]); if ($condpayment == 'A la commande') $condpayment = 'A réception de commande'; if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture'; - $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', getEntity('c_payment_term')); + $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1); if (empty($object->cond_reglement_id)) { print " - Error cant find payment mode for ".$condpayment."\n"; diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 132d616e17b..71ff2b12cb9 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -461,7 +461,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && ! $paiement = new Paiement($db); $paiement->datepaye = $paymentdate; $paiement->amounts = $amounts; - $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',getEntity('c_paiement')); + $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',1); $paiement->num_paiement = $num_chq; $paiement->note = $label; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 9937deab531..399e2984ea8 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -136,7 +136,7 @@ switch ($action) $cond_reglement_id = 0; break; case 'ESP': - $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',1); $cond_reglement_id = 0; $note .= $langs->trans("Cash")."\n"; $note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n"; @@ -145,11 +145,11 @@ switch ($action) $note .= '--------------------------------------'."\n\n"; break; case 'CB': - $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',1); $cond_reglement_id = 0; break; case 'CHQ': - $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',1); $cond_reglement_id = 0; break; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ad56afe5d33..d1ad15ea2fe 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3660,7 +3660,7 @@ class Facture extends CommonInvoice if (! $error) { // Force payment mode of invoice to withdraw - $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', getEntity('c_paiement')); + $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', 1); if ($payment_mode_id > 0) { $result=$this->setPaymentMethods($payment_mode_id); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index b2ba863d096..fe379045de0 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -251,7 +251,7 @@ if (empty($reshook)) $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',getEntity('c_paiement')); + $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',1); $paiement->num_paiement = GETPOST('num_paiement'); $paiement->note = GETPOST('comment'); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 7aa0641f3bc..3458e6bc82a 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -478,8 +478,8 @@ class RemiseCheque extends CommonObject return ""; } } - - + + /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * @@ -489,9 +489,9 @@ class RemiseCheque extends CommonObject function load_board($user) { global $conf, $langs; - + if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe - + $sql = "SELECT b.rowid, b.datev as datefin"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; @@ -500,28 +500,28 @@ class RemiseCheque extends CommonObject $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; - + $resql=$this->db->query($sql); if ($resql) { $langs->load("banks"); $now=dol_now(); - + $response = new WorkboardResponse(); $response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24; $response->label=$langs->trans("BankChecksToReceipt"); $response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&mainmenu=bank'; $response->img=img_object('',"payment"); - + while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - + if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) { $response->nbtodolate++; } } - + return $response; } else @@ -531,8 +531,8 @@ class RemiseCheque extends CommonObject return -1; } } - - + + /** * Charge indicateurs this->nb de tableau de bord * @@ -541,9 +541,9 @@ class RemiseCheque extends CommonObject function load_state_board() { global $user; - + if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe - + $sql = "SELECT count(b.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; @@ -551,11 +551,11 @@ class RemiseCheque extends CommonObject $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.amount > 0"; - + $resql=$this->db->query($sql); if ($resql) { - + while ($obj=$this->db->fetch_object($resql)) { $this->nb["cheques"]=$obj->nb; @@ -792,7 +792,7 @@ class RemiseCheque extends CommonObject $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; - $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',getEntity('c_paiement')); + $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',1); $rejectedPayment->num_paiement = $payment->numero; while($obj = $db->fetch_object($resql)) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 28a98d6df7c..688e93362b7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5954,16 +5954,16 @@ function dol_osencode($str) * Return an id or code from a code or id. * Store also Code-Id into a cache to speed up next request on same key. * - * @param DoliDB $db Database handler - * @param string $key Code or Id to get Id or Code - * @param string $tablename Table name without prefix - * @param string $fieldkey Field for code - * @param string $fieldid Field for id - * @param int $entity Field for filter by entity - * @return int <0 if KO, Id of code if OK + * @param DoliDB $db Database handler + * @param string $key Code or Id to get Id or Code + * @param string $tablename Table name without prefix + * @param string $fieldkey Field for code + * @param string $fieldid Field for id + * @param int $entityfilter Filter by entity + * @return int <0 if KO, Id of code if OK * @see $langs->getLabelFromKey */ -function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$entity=null) +function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$entityfilter=0) { global $cache_codes; @@ -5979,8 +5979,8 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$e $sql = "SELECT ".$fieldid." as valuetoget"; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'"; - if (! is_null($entity)) - $sql.= " AND entity = " . (int) $entity; + if (! empty($entityfilter)) + $sql.= " AND entity IN (" . getEntity($tablename) . ")"; dol_syslog('dol_getIdFromCode', LOG_DEBUG); $resql = $db->query($sql); if ($resql)
'.$objp->num_paiement.''; if ($objp->bid) print ''.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).''; else print ' '; diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 557d48be680..f42303361ec 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -639,6 +639,7 @@ if ($id > 0) $sql.= " AND p.fk_loan = l.rowid"; $sql.= " AND l.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " AND c.entity = " . getEntity('c_paiement', 2); $sql.= " ORDER BY dp DESC"; //print $sql; diff --git a/htdocs/loan/class/loanschedule.class.php b/htdocs/loan/class/loanschedule.class.php index fb6df8fcb6c..90729dd3468 100644 --- a/htdocs/loan/class/loanschedule.class.php +++ b/htdocs/loan/class/loanschedule.class.php @@ -179,6 +179,7 @@ class LoanSchedule extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX.$this->table_element." as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index 52c822e54c1..ec6672d898f 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -178,6 +178,7 @@ class PaymentLoan extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_loan as t)"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + $sql.= " AND pt.entity = " . getEntity('c_paiement', 2); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index e3f873476ba..dbb0dad7149 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -50,7 +50,7 @@ class SupplierProposal extends CommonObject public $fk_element='fk_supplier_proposal'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='propal'; - + /** * {@inheritdoc} */ @@ -140,7 +140,7 @@ class SupplierProposal extends CommonObject var $multicurrency_total_ht; var $multicurrency_total_tva; var $multicurrency_total_ttc; - + /** * Draft status */ @@ -160,10 +160,10 @@ class SupplierProposal extends CommonObject /** * Billed or closed/processed quote */ - const STATUS_CLOSE = 4; - - - + const STATUS_CLOSE = 4; + + + /** * Constructor * @@ -407,7 +407,7 @@ class SupplierProposal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -419,7 +419,7 @@ class SupplierProposal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -487,7 +487,7 @@ class SupplierProposal extends CommonObject $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // Mise en option de la ligne if (empty($qty) && empty($special_code)) $this->line->special_code=3; @@ -583,7 +583,7 @@ class SupplierProposal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -595,7 +595,7 @@ class SupplierProposal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; if ($remise_percent > 0) @@ -662,7 +662,7 @@ class SupplierProposal extends CommonObject if (is_array($array_option) && count($array_option)>0) { $this->line->array_options=$array_option; } - + // Multicurrency $this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx); $this->line->multicurrency_total_ht = $multicurrency_total_ht; @@ -1116,8 +1116,8 @@ class SupplierProposal extends CommonObject $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement"; $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity = ' . getEntity('c_paiement', 2); + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2); $sql.= " WHERE p.fk_statut = c.id"; $sql.= " AND p.entity = ".$conf->entity; if ($ref) $sql.= " AND p.ref='".$ref."'"; @@ -1180,7 +1180,7 @@ class SupplierProposal extends CommonObject $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + if ($obj->fk_statut == 0) { $this->brouillon = 1; @@ -1271,7 +1271,7 @@ class SupplierProposal extends CommonObject $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; $line->fk_unit = $objp->fk_unit; - + $this->lines[$i] = $line; $i++; @@ -1653,7 +1653,7 @@ class SupplierProposal extends CommonObject { $trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED'; } - + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language @@ -1704,7 +1704,7 @@ class SupplierProposal extends CommonObject $productsupplier = new ProductFournisseur($this->db); dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG); - foreach ($this->lines as $product) + foreach ($this->lines as $product) { if ($product->subprice <= 0) continue; @@ -1721,7 +1721,7 @@ class SupplierProposal extends CommonObject $this->createPriceFournisseur($product, $user); } } - + return 1; } @@ -2149,7 +2149,7 @@ class SupplierProposal extends CommonObject $response->label = $label; $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut; $response->img = img_object('',"propal"); - + // This assignment in condition is not a bug. It allows walking the results. while ($obj=$this->db->fetch_object($resql)) { @@ -2187,7 +2187,7 @@ class SupplierProposal extends CommonObject global $user,$langs,$conf; // Load array of products prodids - $num_prods = 0; + $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; @@ -2250,7 +2250,7 @@ class SupplierProposal extends CommonObject $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -2375,10 +2375,10 @@ class SupplierProposal extends CommonObject global $langs, $conf, $user; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $url=''; $result=''; - + $label=''.$langs->trans("ShowSupplierProposal").''; if (! empty($this->ref)) $label.= '
'.$langs->trans('Ref').': '.$this->ref; @@ -2396,7 +2396,7 @@ class SupplierProposal extends CommonObject if ($option == 'document') { $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params; } - + $linkclose=''; if (empty($notooltip) && $user->rights->propal->lire) { @@ -2408,7 +2408,7 @@ class SupplierProposal extends CommonObject $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; @@ -2432,7 +2432,7 @@ class SupplierProposal extends CommonObject function getLinesArray() { // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; @@ -2486,7 +2486,7 @@ class SupplierProposal extends CommonObject $this->lines[$i]->rang = $obj->rang; $this->lines[$i]->ref_fourn = $obj->ref_produit_fourn; - + // Multicurrency $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency; $this->lines[$i]->multicurrency_code = $obj->multicurrency_code; @@ -2541,7 +2541,7 @@ class SupplierProposal extends CommonObject return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } - + /** * Function used to replace a thirdparty id with another one. * @@ -2555,10 +2555,10 @@ class SupplierProposal extends CommonObject $tables = array( 'supplier_proposal' ); - + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } - + } @@ -2669,7 +2669,7 @@ class SupplierProposalLine extends CommonObjectLine var $skip_update_total; // Skip update price total for special lines var $ref_fourn; - + // Multicurrency var $fk_multicurrency; var $multicurrency_code; @@ -2750,7 +2750,7 @@ class SupplierProposalLine extends CommonObjectLine $this->product_desc = $objp->product_desc; $this->ref_fourn = $objp->ref_produit_forun; - + // Multicurrency $this->fk_multicurrency = $objp->fk_multicurrency; $this->multicurrency_code = $objp->multicurrency_code; @@ -2798,11 +2798,11 @@ class SupplierProposalLine extends CommonObjectLine if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_unit)) $this->fk_unit=0; - + if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) + if ($this->pa_ht == 0) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -2869,7 +2869,7 @@ class SupplierProposalLine extends CommonObjectLine { $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet'); $this->id=$this->rowid; - + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { $result=$this->insertExtraFields(); @@ -2982,11 +2982,11 @@ class SupplierProposalLine extends CommonObjectLine if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_unit)) $this->fk_unit=0; - + if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) + if ($this->pa_ht == 0) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3031,13 +3031,13 @@ class SupplierProposalLine extends CommonObjectLine if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null"); $sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null'); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); From 58b3d86b498d18e99667a59a76ce1b5e98604cb0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 09:40:43 +0200 Subject: [PATCH 08/24] Fix: errors --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/bank/class/account.class.php | 2 +- htdocs/compta/facture/card.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index eafb406ba58..ab76fa34fd5 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1560,7 +1560,7 @@ class Commande extends CommonOrder $sql.= ', dr.code as demand_reason_code'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid AND cr.entity = ' . getEntity('c_payment_term', 2) . ')'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id AND cr.entity = ' . getEntity('c_paiement', 2) . ')'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id AND p.entity = ' . getEntity('c_paiement', 2) . ')'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_input_reason = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 5330eca86a4..b5a2177d798 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -413,7 +413,7 @@ class Account extends CommonObject { $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE id=".$oper; - $sql.= " AND entity = " . getEntity('c_payement_term', 2) . ")"; + $sql.= " AND entity = " . getEntity('c_paiement', 2) . ")"; $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 319369fa304..6f1454de1d3 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -653,7 +653,7 @@ if (empty($reshook)) $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p'; $sql.= ' WHERE pf.fk_facture = '.$object->id; $sql.= ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; - $sql.= ' AND p.entity = ' . getEntity('c_paiement', 2); + $sql.= ' AND c.entity = ' . getEntity('c_paiement', 2); $sql.= ' ORDER BY p.datep, p.tms'; $resql = $db->query($sql); From 4bd7bb86a79221131e7e95a90ca8064e8789adfb Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 10:13:24 +0200 Subject: [PATCH 09/24] Fix: try to add functions.lib.php to avoid phpunit error --- test/phpunit/PricesTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/phpunit/PricesTest.php b/test/phpunit/PricesTest.php index 3e09450b9cb..a171feb9d3c 100755 --- a/test/phpunit/PricesTest.php +++ b/test/phpunit/PricesTest.php @@ -28,6 +28,7 @@ global $conf,$user,$langs,$db; //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/core/lib/functions.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/price.lib.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; @@ -160,7 +161,7 @@ class PricesTest extends PHPUnit_Framework_TestCase print __METHOD__." result1=".join(', ',$result1)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) $this->assertEquals(array(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.56, 9.34795),$result1,'Test1 FR'); - + // qty=2, unit_price=0, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value), pu_ht_devise=100 $mysoc->country_code='FR'; $mysoc->country_id=1; @@ -168,7 +169,7 @@ class PricesTest extends PHPUnit_Framework_TestCase print __METHOD__." result1=".join(', ',$result1)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) $this->assertEquals(array(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20),$result1,'Test1 FR'); - + /* * Country Spain */ From 0a442365a7e1278d8f469d8ae08e20d91d99bc40 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 11:46:26 +0200 Subject: [PATCH 10/24] Revert "Fix: try to add functions.lib.php to avoid phpunit error" This reverts commit 4bd7bb86a79221131e7e95a90ca8064e8789adfb. --- test/phpunit/PricesTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/phpunit/PricesTest.php b/test/phpunit/PricesTest.php index a171feb9d3c..3e09450b9cb 100755 --- a/test/phpunit/PricesTest.php +++ b/test/phpunit/PricesTest.php @@ -28,7 +28,6 @@ global $conf,$user,$langs,$db; //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -require_once dirname(__FILE__).'/../../htdocs/core/lib/functions.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/price.lib.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; @@ -161,7 +160,7 @@ class PricesTest extends PHPUnit_Framework_TestCase print __METHOD__." result1=".join(', ',$result1)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) $this->assertEquals(array(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.56, 9.34795),$result1,'Test1 FR'); - + // qty=2, unit_price=0, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value), pu_ht_devise=100 $mysoc->country_code='FR'; $mysoc->country_id=1; @@ -169,7 +168,7 @@ class PricesTest extends PHPUnit_Framework_TestCase print __METHOD__." result1=".join(', ',$result1)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) $this->assertEquals(array(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20),$result1,'Test1 FR'); - + /* * Country Spain */ From 6dfb8e33c9354d0106752fe22edc1b344a73b27c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 12:12:25 +0200 Subject: [PATCH 11/24] Fix: try to debug --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf34c86bd58..a040342b2e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -299,7 +299,8 @@ script: set +e echo #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log - #cat /tmp/dolibarr_install.log + cat $TRAVIS_BUILD_DIR/upgrade500600-2.log + cat /tmp/dolibarr_install.log - | echo "Unit testing" From 1056473cdccc01a392057102c1cc024df73875ff Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 13:45:36 +0200 Subject: [PATCH 12/24] Try to fix travis error --- htdocs/install/inc.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 6da4125a56c..8045aada0b1 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -385,12 +385,12 @@ function pHeader($subtitle,$next,$action='set',$param='',$forcejqueryurl='',$css // We force the content charset header("Content-type: text/html; charset=".$conf->file->character_set_client); header("X-Content-Type-Options: nosniff"); - + print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; print ''."\n"; print ''."\n"; @@ -453,9 +453,14 @@ function pFooter($nonext=0,$setuplang='',$jscheckfunction='', $withpleasewait=0) print '
'; if ($nonext == '2') { - print $langs->trans("ErrorFoundDuringMigration", $_SERVER["REQUEST_URI"].'&ignoreerrors=1').'

'; + if (!isset($_SERVER['REQUEST_URI'])) + { + $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 ); + if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; } + } + print $langs->trans("ErrorFoundDuringMigration", $_SERVER["REQUEST_URI"].'&ignoreerrors=1').'

'; } - + print '"'; if ($jscheckfunction) print ' onClick="return '.$jscheckfunction.'();"'; print '>
'; From 460a6f0fb75c1eb96d273fa3279b2c3c8fa3ec97 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Jun 2017 14:15:29 +0200 Subject: [PATCH 13/24] Fix: phpunit : Unexpected 'print' (T_PRINT) --- htdocs/admin/perms.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/perms.php b/htdocs/admin/perms.php index 03b29abc109..eb348869b34 100644 --- a/htdocs/admin/perms.php +++ b/htdocs/admin/perms.php @@ -187,11 +187,11 @@ if ($result) print '
' + print ''; print img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName(); print ' '; print ''.$perm_libelle. ''; - $labeltype=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$langs->getLabelFromKey($db,$objp->fk_type,'c_paiement','code','libelle','',getEntity('c_paiement', 2)); + $labeltype=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$langs->getLabelFromKey($db,$objp->fk_type,'c_paiement','code','libelle','',getEntity('c_paiement')); if ($labeltype == 'SOLD') print ' '; //$langs->trans("InitialBankBalance"); else print $labeltype; print "