';
+
+}
+
llxFooter();
$db->close();
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 427eba96854..673ce2f2d24 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
@@ -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');
$code=GETPOST('code','alpha');
$allowed=$user->admin;
@@ -181,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 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]);
+$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";
@@ -259,8 +260,8 @@ $tabfield[8] = "code,libelle,country_id,country".(! empty($conf->global->SOCIETE
$tabfield[9] = "code,label,unicode";
$tabfield[10]= "country_id,country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,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";
@@ -335,8 +336,8 @@ $tabfieldinsert[8] = "code,libelle,fk_country".(! empty($conf->global->SOCIETE_S
$tabfieldinsert[9] = "code_iso,label,unicode";
$tabfieldinsert[10]= "fk_pays,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,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";
@@ -733,7 +734,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]);
}
if ($i) $sql.=",";
if ($listfieldvalue[$i] == 'sortorder') // For column name 'sortorder', we use the field name 'position'
@@ -785,7 +786,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]);
}
if ($i) $sql.=",";
$sql.= $field."=";
@@ -798,6 +799,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$i++;
}
$sql.= " WHERE ".$rowidcol." = '".$rowid."'";
+ $sql.= " AND entity = '".getEntity($tabname[$id])."'";
dol_syslog("actionmodify", LOG_DEBUG);
//print $sql;
@@ -820,7 +822,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 != '' ? " AND entity = " . (int) $entity : '');
dol_syslog("delete", LOG_DEBUG);
$result = $db->query($sql);
@@ -844,10 +846,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 != '' ? " AND entity = " . (int) $entity : '');
}
elseif ($code) {
- $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($code)."'";
+ $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
}
$result = $db->query($sql);
@@ -864,10 +866,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 != '' ? " AND entity = " . (int) $entity : '');
}
elseif ($code) {
- $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($code)."'";
+ $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
}
$result = $db->query($sql);
@@ -884,10 +886,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 != '' ? " AND entity = " . (int) $entity : '');
}
elseif ($code) {
- $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($code)."'";
+ $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
}
$result = $db->query($sql);
@@ -904,10 +906,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 != '' ? " AND entity = " . (int) $entity : '');
}
elseif ($code) {
- $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($code)."'";
+ $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($code)."'".($entity != '' ? " AND entity = " . (int) $entity : '');
}
$result = $db->query($sql);
@@ -959,6 +961,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;
$paramwithsearch = $param;
if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
@@ -1016,6 +1019,7 @@ if ($id)
if ($tabname[$id])
{
$alabelisused=0;
+ $withentity=null;
$fieldlist=explode(',',$tabfield[$id]);
@@ -1026,6 +1030,11 @@ if ($id)
print '
';
foreach ($fieldlist as $field => $value)
{
+ if ($fieldlist[$field] == 'entity') {
+ $withentity = getEntity($tabname[$id]);
+ continue;
+ }
+
// Determine le nom du champ par rapport aux noms possibles
// dans les dictionnaires de donnees
$valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
@@ -1119,6 +1128,8 @@ if ($id)
if ($id == 4) print '
';
@@ -1197,7 +1208,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; }
@@ -1239,6 +1252,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
@@ -1349,12 +1364,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 '';
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index a13e626fe20..54fddba3494 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1559,10 +1559,10 @@ 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_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_payment_term as cr ON c.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term') . ')';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON c.fk_mode_reglement = p.id AND p.entity IN (' . 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';
$sql.= " WHERE c.entity IN (".getEntity('commande').")";
if ($id) $sql.= " AND c.rowid=".$id;
diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php
index eb14db2d3ac..44badfa51d8 100644
--- a/htdocs/compta/bank/annuel.php
+++ b/htdocs/compta/bank/annuel.php
@@ -149,7 +149,7 @@ dol_fiche_head($head, 'annual', $langs->trans("FinancialAccount"), -1, 'account'
$title=$langs->trans("FinancialAccount")." : ".$object->label;
$link=($year_start?"".img_previous('', 'class="valignbottom"')." ".$langs->trans("Year")." ".img_next('', 'class="valignbottom"')."":"");
-$linkback = ''.$langs->trans("BackToList").'';
+$linkback = ''.$langs->trans("BackToList").'';
if (!empty($id))
@@ -203,7 +203,7 @@ print '';
$var=true;
for ($mois = 1 ; $mois < 13 ; $mois++)
{
-
+
print '
';
if (! $i) $totalarray['nbfield']++;
if (! $i) $totalarray['totalbalancefield']=$totalarray['nbfield'];
diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php
index ec61c39ee84..95e73183154 100644
--- a/htdocs/compta/bank/releve.php
+++ b/htdocs/compta/bank/releve.php
@@ -328,7 +328,7 @@ if (empty($numref))
$head=bank_prepare_head($object);
dol_fiche_head($head,'statement',$langs->trans("FinancialAccount"),0,'account');
- $linkback = ''.$langs->trans("BackToList").'';
+ $linkback = ''.$langs->trans("BackToList").'';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
@@ -340,7 +340,7 @@ if (empty($numref))
if ($object->canBeConciliated() > 0) {
// If not cash account and can be reconciliate
if ($user->rights->banque->consolidate) {
- print ''.$langs->trans("Conciliate").'';
+ print ''.$langs->trans("Conciliate").'';
} else {
print ''.$langs->trans("Conciliate").'';
}
diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php
index 0e2d3b35f38..cc0d58945e0 100644
--- a/htdocs/compta/bank/treso.php
+++ b/htdocs/compta/bank/treso.php
@@ -93,14 +93,14 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$head=bank_prepare_head($object);
dol_fiche_head($head, 'cash', $langs->trans("FinancialAccount"), -1, 'account');
- $linkback = ''.$langs->trans("BackToList").'';
+ $linkback = ''.$langs->trans("BackToList").'';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
dol_fiche_end();
-
+
print ' ';
-
+
$solde = $object->solde(0);
// Show next coming entries
@@ -120,13 +120,13 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$var=true;
// Current balance
-
+
print '
';
print '
'.$langs->trans("CurrentBalance").'
';
print '
'.price($solde).'
';
print '
';
-
+
print '
';
print '
'.$langs->trans("RemainderToPay").'
';
print '
';
@@ -295,7 +295,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
// We discard lines with a remainder to pay to 0
if (price2num($total_ttc) != 0)
{
-
+
// Show line
print '
';
diff --git a/htdocs/compta/bank/various_payment/index.php b/htdocs/compta/bank/various_payment/index.php
index 48f37d24235..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";
+$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 e048de2deb7..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";
+ $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";
+ $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";
+ $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 940ada5e04b..3918983894e 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -716,9 +716,13 @@ if (empty($reshook))
if ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_SITUATION)
{
// 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';
+
+ $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 c.entity IN (' . getEntity('c_paiement').')';
+ $sql.= ' ORDER BY p.datep, p.tms';
$resql = $db->query($sql);
if (! $resql) dol_print_error($db);
@@ -3798,6 +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 IN (' . getEntity('c_paiement').')';
$sql .= ' ORDER BY p.datep, p.tms';
$result = $db->query($sql);
@@ -4324,7 +4329,7 @@ else if ($id > 0 || ! empty($ref))
// Delete
if ($user->rights->facture->supprimer)
{
- if (! $object->is_erasable()) {
+ if ($object->is_erasable() <= 0) {
print '
';
diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index e28d19b95b2..a1f76807ab6 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -378,7 +378,59 @@ class Invoices extends DolibarrApi
}
/**
- * Validate an order
+ * Sets an invoice as draft
+ *
+ * @param int $id Order ID
+ * @param int $idwarehouse Warehouse ID
+ *
+ * @url POST {id}/settodraft
+ *
+ * @return array
+ *
+ * @throws 200
+ * @throws 304
+ * @throws 401
+ * @throws 404
+ * @throws 500
+ *
+ */
+ function settodraft($id, $idwarehouse=-1)
+ {
+ if(! DolibarrApiAccess::$user->rights->facture->creer) {
+ throw new RestException(401);
+ }
+ $result = $this->invoice->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Invoice not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->invoice->set_draft(DolibarrApiAccess::$user, $idwarehouse);
+ if ($result == 0) {
+ throw new RestException(304, 'Nothing done.');
+ }
+ if ($result < 0) {
+ throw new RestException(500, 'Error : '.$this->invoice->error);
+ }
+
+ $result = $this->invoice->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Invoice not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ return $this->_cleanObjectDatas($this->invoice);
+ }
+
+
+ /**
+ * Validate an invoice
*
* @param int $id Order ID
* @param int $idwarehouse Warehouse ID
@@ -411,20 +463,82 @@ class Invoices extends DolibarrApi
$result = $this->invoice->validate(DolibarrApiAccess::$user, '', $idwarehouse, $notrigger);
if ($result == 0) {
- throw new RestException(500, 'Error nothing done. May be object is already validated');
+ throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
throw new RestException(500, 'Error when validating Invoice: '.$this->invoice->error);
}
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'Invoice validated (Ref='.$this->invoice->ref.')'
- )
- );
+
+ $result = $this->invoice->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Invoice not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ return $this->_cleanObjectDatas($this->invoice);
+
+
}
+ /**
+ * Sets an invoice as paid
+ *
+ * @param int $id Order ID
+ * @param string $close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas escompte par exemple)
+ * @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple)
+ *
+ * @url POST {id}/settopaid
+ *
+ * @return array An invoice object
+ *
+ * @throws 200
+ * @throws 304
+ * @throws 401
+ * @throws 404
+ * @throws 500
+ */
+ function settopaid($id, $close_code='', $close_note='')
+ {
+ if(! DolibarrApiAccess::$user->rights->facture->creer) {
+ throw new RestException(401);
+ }
+ $result = $this->invoice->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Invoice not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->invoice->set_paid(DolibarrApiAccess::$user, $close_code, $close_note);
+ if ($result == 0) {
+ throw new RestException(304, 'Error nothing done. May be object is already validated');
+ }
+ if ($result < 0) {
+ throw new RestException(500, 'Error : '.$this->invoice->error);
+ }
+
+
+ $result = $this->invoice->fetch($id);
+ if( ! $result ) {
+ throw new RestException(404, 'Invoice not found');
+ }
+
+ if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ return $this->_cleanObjectDatas($this->invoice);
+
+
+ }
+
+
/**
* Clean sensible object datas
*
diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php
index 7c6e0567c24..0a9fa2872eb 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';
- $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 IN (' . getEntity('c_payment_term').')';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN (' . 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 b7603400c61..d853ea03138 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1076,18 +1076,19 @@ class Facture extends CommonInvoice
}
/**
- * Return clicable link of object (with eventually picto)
+ * Return clicable link of object (with eventually picto)
*
- * @param int $withpicto Add picto into link
- * @param string $option Where point the link
- * @param int $max Maxlength of ref
- * @param int $short 1=Return just URL
- * @param string $moretitle Add more text to title tooltip
- * @param int $notooltip 1=Disable tooltip
- * @param int $addlinktonotes 1=Add link to notes
- * @return string String with URL
+ * @param int $withpicto Add picto into link
+ * @param string $option Where point the link
+ * @param int $max Maxlength of ref
+ * @param int $short 1=Return just URL
+ * @param string $moretitle Add more text to title tooltip
+ * @param int $notooltip 1=Disable tooltip
+ * @param int $addlinktonotes 1=Add link to notes
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @return string String with URL
*/
- function getNomUrl($withpicto=0,$option='',$max=0,$short=0,$moretitle='',$notooltip=0,$addlinktonotes=0)
+ function getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $addlinktonotes=0, $save_lastsearch_value=-1)
{
global $langs, $conf, $user, $form;
@@ -1100,6 +1101,14 @@ class Facture extends CommonInvoice
if ($short) return $url;
+ if ($option !== 'nolink')
+ {
+ // Add param to save lastsearch_values or not
+ $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
+ if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
+ if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
+ }
+
$picto='bill';
if ($this->type == self::TYPE_REPLACEMENT) $picto.='r'; // Replacement invoice
if ($this->type == self::TYPE_CREDIT_NOTE) $picto.='a'; // Credit note
@@ -1197,8 +1206,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 IN (' . getEntity('c_payment_term').')';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN (' . 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;
@@ -1737,20 +1746,24 @@ class Facture extends CommonInvoice
* @param User $user User making the deletion.
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @param int $idwarehouse Id warehouse to use for stock change.
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, 0=Refused, >0 if OK
*/
function delete($user, $notrigger=0, $idwarehouse=-1)
{
global $langs,$conf;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- if (empty($rowid)) $rowid=$this->id;
+ $rowid=$this->id;
- dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
+ dol_syslog(get_class($this)."::delete rowid=".$rowid.", ref=".$this->ref.", thirdparty=".$this->thirdparty->name, LOG_DEBUG);
- // TODO Test if there is at least one payment. If yes, refuse to delete.
+ // Test to avoid invoice deletion (allowed if draft)
+ $test = $this->is_erasable();
+
+ if ($test <= 0) return $test;
$error=0;
+
$this->db->begin();
if (! $error && ! $notrigger)
@@ -2072,7 +2085,7 @@ class Facture extends CommonInvoice
* @param string $force_number Reference to force on invoice
* @param int $idwarehouse Id of warehouse to use for stock decrease if option to decreasenon stock is on (0=no decrease)
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK
*/
function validate($user, $force_number='', $idwarehouse=0, $notrigger=0)
{
@@ -3167,6 +3180,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 IN (' . getEntity('c_paiement').')';
if ($filtertype) $sql.=" AND t.code='PRE'";
dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG);
@@ -3213,6 +3227,8 @@ class Facture extends CommonInvoice
if (! empty($conf->global->FACTURE_ADDON))
{
+ dol_syslog("Call getNextNumRef with FACTURE_ADDON = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->nom.", type=".$soc->typent_code, LOG_DEBUG);
+
$mybool=false;
$file = $conf->global->FACTURE_ADDON.".php";
@@ -3356,40 +3372,49 @@ class Facture extends CommonInvoice
/**
* Return if an invoice can be deleted
* Rule is:
- * If hidden option INVOICE_CAN_ALWAYS_BE_REMOVED is on, we can
- * If invoice has a definitive ref, is last, without payment and not dipatched into accountancy -> yes end of rule
* If invoice is draft and ha a temporary ref -> yes
+ * If hidden option INVOICE_CAN_ALWAYS_BE_REMOVED is on, we can. If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on, we can't.
+ * If invoice has a definitive ref, is last, without payment and not dipatched into accountancy -> yes end of rule
*
- * @return int <0 if KO, 0=no, 1=yes
+ * @return int <0 if KO, 0=no, >0=yes
*/
function is_erasable()
{
global $conf;
- if (! empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) return 1;
+ // we check if invoice is a temporary number (PROVxxxx)
+ $tmppart = substr($this->ref, 1, 4);
+
+ if ($this->statut == self::STATUS_DRAFT && $tmppart === 'PROV') // If draft invoice and ref not yet defined
+ {
+ return 1;
+ }
+
+ if (! empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) return 2;
if (! empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED)) return 0;
- // on verifie si la facture est en numerotation provisoire
- $facref = substr($this->ref, 1, 4);
+ // TODO Test if there is at least one payment. If yes, refuse to delete.
+ // ...
// If not a draft invoice and not temporary invoice
- if ($facref != 'PROV')
+ if ($tmppart !== 'PROV')
{
+ // We need to have this->thirdparty defined, in case of numbering rule use tags that depend on thirdparty (like {t} tag).
+ if (empty($this->thirdparty)) $this->fetch_thirdparty();
+
$maxfacnumber = $this->getNextNumRef($this->thirdparty,'last');
$ventilExportCompta = $this->getVentilExportCompta();
+
// If there is no invoice into the reset range and not already dispatched, we can delete
- if ($maxfacnumber == '' && $ventilExportCompta == 0) return 1;
+ if ($maxfacnumber == '' && $ventilExportCompta == 0) return 3;
// If invoice to delete is last one and not already dispatched, we can delete
- if ($maxfacnumber == $this->ref && $ventilExportCompta == 0) return 1;
+ if ($maxfacnumber == $this->ref && $ventilExportCompta == 0) return 4;
+
if ($this->situation_cycle_ref) {
$last = $this->is_last_in_cycle();
return $last;
}
}
- else if ($this->statut == self::STATUS_DRAFT && $facref == 'PROV') // Si facture brouillon et provisoire
- {
- return 1;
- }
return 0;
}
@@ -3649,7 +3674,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', 1);
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 a34705c8476..bc13b0d5876 100644
--- a/htdocs/compta/facture/class/paymentterm.class.php
+++ b/htdocs/compta/facture/class/paymentterm.class.php
@@ -91,6 +91,7 @@ class PaymentTerm // extends CommonObject
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_payment_term(";
$sql.= "rowid,";
+ $sql.= "entity,";
$sql.= "code,";
$sql.= "sortorder,";
$sql.= "active,";
@@ -101,6 +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'):"'".$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)."'").",";
@@ -165,6 +167,7 @@ class PaymentTerm // extends CommonObject
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
+ $sql.= " t.entity";
$sql.= " t.code,";
$sql.= " t.sortorder,";
@@ -178,6 +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');
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql);
@@ -227,6 +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');
dol_syslog(get_class($this)."::getDefaultId", LOG_DEBUG);
$resql=$this->db->query($sql);
@@ -255,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
@@ -276,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").",";
@@ -286,37 +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")."";
- $sql.= " WHERE rowid=".$this->id;
+ $sql.= " WHERE rowid = " . $this->id;
+ $sql.= " AND entity = " . getEntity('c_payment_term');
$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;
@@ -326,7 +333,7 @@ class PaymentTerm // extends CommonObject
$this->db->commit();
return 1;
}
- }
+ }
/**
@@ -342,7 +349,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');
$this->db->begin();
diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php
index 93b23834e9f..5ac71ef03ca 100644
--- a/htdocs/compta/facture/contact.php
+++ b/htdocs/compta/facture/contact.php
@@ -139,13 +139,13 @@ if ($id > 0 || ! empty($ref))
$head = facture_prepare_head($object);
$totalpaye = $object->getSommePaiement();
-
+
dol_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill');
// Invoice content
-
- $linkback = '' . $langs->trans("BackToList") . '';
-
+
+ $linkback = '' . $langs->trans("BackToList") . '';
+
$morehtmlref='
';
@@ -507,16 +507,16 @@ if ($object->id > 0)
// TODO Replace this by an include with same code to show already done payment visible in invoice card
print '
';
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 7a494113090..866529fd5dd 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');
+ $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',1);
$paiement->num_paiement = GETPOST('num_paiement');
$paiement->note = GETPOST('comment');
@@ -526,21 +526,19 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
* 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 = '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.= ' WHERE f.entity IN ('.getEntity('facture', $conf->entity).')';
$sql.= ' AND (f.fk_soc = '.$facture->socid;
-
+ // Can pay invoices of all child of parent company
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.')';
}
-
+ // Can pay invoices of all child of myself
+ if(!empty($conf->global->FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES)){
+ $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->id.')';
+ }
$sql.= ') AND f.paye = 0';
$sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
if ($facture->type != 2)
@@ -831,7 +829,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 IN (' . getEntity('facture').')';
+ $sql.= ' AND c.entity IN (' . 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 370fbdfdd05..4c7fafe4429 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');
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 808d2cbb00b..3458e6bc82a 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)
@@ -481,10 +481,10 @@ class RemiseCheque extends CommonObject
/**
- * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
- *
- * @param User $user Objet user
- * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
+ * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
+ *
+ * @param User $user Objet user
+ * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
*/
function load_board($user)
{
@@ -533,6 +533,45 @@ class RemiseCheque extends CommonObject
}
+ /**
+ * Charge indicateurs this->nb de tableau de bord
+ *
+ * @return int <0 if ko, >0 if ok
+ */
+ 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";
+ $sql.= " WHERE b.fk_account = ba.rowid";
+ $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;
+ }
+ $this->db->free($resql);
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ $this->error=$this->db->error();
+ return -1;
+ }
+ }
+
+
/**
* Build document
*
@@ -716,7 +755,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 +766,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 +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');
+ $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/compta/paiement/cheque/list.php b/htdocs/compta/paiement/cheque/list.php
index d08b6c734cc..76c52215281 100644
--- a/htdocs/compta/paiement/cheque/list.php
+++ b/htdocs/compta/paiement/cheque/list.php
@@ -203,7 +203,7 @@ if ($resql)
// Bank
print '
';
// Date start period
diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php
index f7c722e3e1d..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";
+$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 0ab82a7cae3..a8f795115c4 100644
--- a/htdocs/compta/sociales/card.php
+++ b/htdocs/compta/sociales/card.php
@@ -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');
$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 83fe7d8b6b6..dc089c13e30 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';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id AND p.entity IN (' . 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 1d553831f99..6c7cda1f07e 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');
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 879e9b69ee7..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";
+ $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 0d4d827e694..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";
+$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/contact/agenda.php b/htdocs/contact/agenda.php
index 04c62107e83..a4412082ead 100644
--- a/htdocs/contact/agenda.php
+++ b/htdocs/contact/agenda.php
@@ -210,7 +210,7 @@ else
dol_fiche_head($head, 'agenda', $title, -1, 'contact');
- $linkback = ''.$langs->trans("BackToList").'';
+ $linkback = ''.$langs->trans("BackToList").'';
$morehtmlref='
';
// Ref supplier
@@ -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';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (' . 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/contact.php b/htdocs/fourn/facture/contact.php
index 0f56c5f7bae..ffc58195e26 100644
--- a/htdocs/fourn/facture/contact.php
+++ b/htdocs/fourn/facture/contact.php
@@ -135,12 +135,12 @@ if ($id > 0 || ! empty($ref))
$object->fetch_thirdparty();
$alreadypaid=$object->getSommePaiement();
-
+
$head = facturefourn_prepare_head($object);
dol_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), -1, 'bill');
- $linkback = '' . $langs->trans("BackToList") . '';
+ $linkback = '' . $langs->trans("BackToList") . '';
$morehtmlref='
';
// Ref supplier
@@ -186,7 +186,7 @@ if ($id > 0 || ! empty($ref))
$object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
-
+
print '
';
// Ref supplier
@@ -128,7 +128,7 @@ if ($object->id > 0)
$object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
- dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
+ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '
';
print '';
diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php
index d6fd80e47fe..000bf0b9743 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';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id AND c.entity IN (' . 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';
@@ -913,7 +913,7 @@ if (empty($action))
print '