'; // Do not force class=right, or it align also the content of the select box
- print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
+ print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1);
print '
'; // Do not force class=right, or it align also the content of the select box
- print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
+ print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
print '
';
print '';
}
diff --git a/htdocs/accountancy/admin/fiscalyear.php b/htdocs/accountancy/admin/fiscalyear.php
index 4338d7ad803..44c5309f531 100644
--- a/htdocs/accountancy/admin/fiscalyear.php
+++ b/htdocs/accountancy/admin/fiscalyear.php
@@ -52,7 +52,7 @@ $langs->loadLangs(array("admin", "compta"));
if ($user->socid > 0) {
accessforbidden();
}
-if (!$user->rights->accounting->fiscalyear->write) { // If we can read accounting records, we should be able to see fiscal year.
+if (empty($user->rights->accounting->fiscalyear->write)) { // If we can read accounting records, we should be able to see fiscal year.
accessforbidden();
}
diff --git a/htdocs/accountancy/admin/fiscalyear_info.php b/htdocs/accountancy/admin/fiscalyear_info.php
index d472350fab7..77ec988143a 100644
--- a/htdocs/accountancy/admin/fiscalyear_info.php
+++ b/htdocs/accountancy/admin/fiscalyear_info.php
@@ -33,7 +33,7 @@ $langs->loadLangs(array("admin", "compta"));
if ($user->socid > 0) {
accessforbidden();
}
-if (!$user->rights->accounting->fiscalyear->write) {
+if (empty($user->rights->accounting->fiscalyear->write)) {
accessforbidden();
}
diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php
index a842c294937..b3d6ac87780 100644
--- a/htdocs/accountancy/admin/productaccount.php
+++ b/htdocs/accountancy/admin/productaccount.php
@@ -41,7 +41,7 @@ $langs->loadLangs(array("companies", "compta", "accountancy", "products"));
if (empty($conf->accounting->enabled)) {
accessforbidden();
}
-if (!$user->rights->accounting->bind->write) {
+if (empty($user->rights->accounting->bind->write)) {
accessforbidden();
}
diff --git a/htdocs/accountancy/admin/subaccount.php b/htdocs/accountancy/admin/subaccount.php
index c3308393c27..26c02de3467 100644
--- a/htdocs/accountancy/admin/subaccount.php
+++ b/htdocs/accountancy/admin/subaccount.php
@@ -46,7 +46,7 @@ $search_type = GETPOST('search_type', 'int');
if ($user->socid > 0) {
accessforbidden();
}
-if (!$user->rights->accounting->chartofaccount) {
+if (empty($user->rights->accounting->chartofaccount)) {
accessforbidden();
}
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index ed3c69c18bc..50116b94b23 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -1,10 +1,10 @@
- * Copyright (C) 2013-2020 Alexandre Spangaro
- * Copyright (C) 2013-2014 Florian Henry
+ * Copyright (C) 2013-2021 Alexandre Spangaro
+ * Copyright (C) 2013-2021 Florian Henry
* Copyright (C) 2014 Juanjo Menent
* Copyright (C) 2015 Ari Elbaz (elarifr)
- * Copyright (C) 2018 Frédéric France
+ * Copyright (C) 2018 Frédéric France
*
* 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
@@ -738,10 +738,11 @@ class AccountingAccount extends CommonObject
* @param Facture $facture Facture
* @param FactureLigne $factureDet Facture Det
* @param array $accountingAccount array of Account account
+ * @param string $type Customer / Supplier
*
* @return array Accounting accounts suggested
*/
- public function getAccountingCodeToBind(Societe $buyer, $seller, Product $product, Facture $facture, FactureLigne $factureDet, $accountingAccount = array())
+ public function getAccountingCodeToBind(Societe $buyer, $seller, Product $product, Facture $facture, FactureLigne $factureDet, $accountingAccount = array(), $type = '')
{
global $conf;
global $hookmanager;
@@ -750,84 +751,116 @@ class AccountingAccount extends CommonObject
$hookmanager->initHooks(array('accoutancyBindingCalculation'));
// Execute hook accoutancyBindingCalculation
- $parameters = array('buyer' => $buyer, 'seller' => $seller, 'product' => $product, 'facture' => $facture, 'factureDet' => $factureDet ,'accountingAccount'=>$accountingAccount);
+ $parameters = array('buyer' => $buyer, 'seller' => $seller, 'product' => $product, 'facture' => $facture, 'factureDet' => $factureDet ,'accountingAccount'=>$accountingAccount, $type);
$reshook = $hookmanager->executeHooks('accoutancyBindingCalculation', $parameters); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) {
+ if ($type=='customer') {
+ $const_name = "SOLD";
+ } elseif ($type=='supplier') {
+ $const_name = "BUY";
+ }
+
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
$isBuyerInEEC = isInEEC($buyer);
$isSellerInEEC = isInEEC($seller);
- $code_sell_l = '';
- $code_sell_p = '';
- $code_sell_t = '';
+ $code_l = '';
+ $code_p = '';
+ $code_t = '';
$suggestedid = '';
// Level 1: Search suggested default account for product/service
$suggestedaccountingaccountbydefaultfor = '';
if ($factureDet->product_type == 1) {
if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
- $code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = '';
} else {
if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) { // European intravat sale, but with a VAT
- $code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) { // European intravat sale, without VAT intra community number
- $code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
- $code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_INTRA_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_INTRA_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eec';
} else { // Foreign sale
- $code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_EXPORT_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_SERVICE_' . $const_name . '_EXPORT_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'export';
}
}
} elseif ($factureDet->product_type == 0) {
if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
- $code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = '';
} else {
if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) { // European intravat sale, but with a VAT
- $code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) { // European intravat sale, without VAT intra community number
- $code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
- $code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_INTRA_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_INTRA_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'eec';
} else {
- $code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : '');
+ $code_l = (!empty($conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_EXPORT_ACCOUNT'}) ? $conf->global->{'ACCOUNTING_PRODUCT_' . $const_name . '_EXPORT_ACCOUNT'} : '');
$suggestedaccountingaccountbydefaultfor = 'export';
}
}
}
- if ($code_sell_l == -1) {
- $code_sell_l = '';
+ if ($code_l == -1) {
+ $code_l = '';
}
// Level 2: Search suggested account for product/service (similar code exists in page index.php to make automatic binding)
$suggestedaccountingaccountfor = '';
- if ((($buyer->country_code == $seller->country_code) || empty($buyer->country_code)) && !empty($product->accountancy_code_sell)) { // If buyer in same country than seller (if not defined, we assume it is same country)
- $code_sell_p = $product->accountancy_code_sell;
+ if ((($buyer->country_code == $seller->country_code) || empty($buyer->country_code))) {
+ // If buyer in same country than seller (if not defined, we assume it is same country)
+ if ($type=='customer' && !empty($product->accountancy_code_sell)) {
+ $code_p = $product->accountancy_code_sell;
+ } elseif ($type=='supplier' && !empty($product->accountancy_code_buy)) {
+ $code_p = $product->accountancy_code_sell;
+ }
$suggestedid = $accountingAccount['dom'];
$suggestedaccountingaccountfor = 'prodserv';
} else {
- if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0 && !empty($product->accountancy_code_sell)) { // European intravat sale, but with VAT
- $code_sell_p = $product->accountancy_code_sell;
+ if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) {
+ // European intravat sale, but with VAT
+ if ($type=='customer' && !empty($product->accountancy_code_sell)) {
+ $code_p = $product->accountancy_code_sell;
+ } elseif ($type=='supplier' && !empty($product->accountancy_code_buy)) {
+ $code_p = $product->accountancy_code_sell;
+ }
$suggestedid = $accountingAccount['dom'];
$suggestedaccountingaccountfor = 'eecwithvat';
- } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra) && !empty($product->accountancy_code_sell)) { // European intravat sale, without VAT intra community number
- $code_sell_p = $product->accountancy_code_sell;
+ } elseif ($isSellerInEEC && $isBuyerInEEC && empty($buyer->tva_intra)) {
+ // European intravat sale, without VAT intra community number
+ if ($type=='customer' && !empty($product->accountancy_code_sell)) {
+ $code_p = $product->accountancy_code_sell;
+ } elseif ($type=='supplier' && !empty($product->accountancy_code_buy)) {
+ $code_p = $product->accountancy_code_sell;
+ }
$suggestedid = $accountingAccount['dom']; // There is a doubt for this case. Is it an error on vat or we just forgot to fill vat number ?
$suggestedaccountingaccountfor = 'eecwithoutvatnumber';
- } elseif ($isSellerInEEC && $isBuyerInEEC && !empty($product->accountancy_code_sell_intra)) { // European intravat sale
- $code_sell_p = $product->accountancy_code_sell_intra;
+ } elseif ($isSellerInEEC && $isBuyerInEEC && !empty($product->accountancy_code_sell_intra)) {
+ // European intravat sale
+ if ($type=='customer' && !empty($product->accountancy_code_sell_intra)) {
+ $code_p = $product->accountancy_code_sell_intra;
+ } elseif ($type=='supplier' && !empty($product->accountancy_code_buy_intra)) {
+ $code_p = $product->accountancy_code_buy_intra;
+ }
$suggestedid = $accountingAccount['intra'];
$suggestedaccountingaccountfor = 'eec';
- } elseif (!empty($product->accountancy_code_sell_export)) { // Foreign sale
- $code_sell_p = $product->accountancy_code_sell_export;
+ } else {
+ // Foreign sale
+ // European intravat sale
+ if ($type=='customer' && !empty($product->accountancy_code_sell_export)) {
+ $code_p = $product->accountancy_code_sell_export;
+ } elseif ($type=='supplier' && !empty($product->accountancy_code_sell_export)) {
+ $code_p = $product->accountancy_code_sell_export;
+ }
$suggestedid = $accountingAccount['export'];
$suggestedaccountingaccountfor = 'export';
}
@@ -836,7 +869,7 @@ class AccountingAccount extends CommonObject
// Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding)
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
if (!empty($buyer->code_compta)) {
- $code_sell_t = $buyer->code_compta;
+ $code_t = $buyer->code_compta;
$suggestedid = $accountingAccount['thirdparty'];
$suggestedaccountingaccountfor = 'thridparty';
}
@@ -850,33 +883,33 @@ class AccountingAccount extends CommonObject
return -1;
}
- $code_sell_l = $accountdeposittoventilated->ref;
+ $code_l = $accountdeposittoventilated->ref;
$suggestedid = $accountdeposittoventilated->rowid;
$suggestedaccountingaccountfor = 'deposit';
}
- if (empty($suggestedid) && empty($code_sell_p) && !empty($code_sell_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
- if (empty($this->accountingaccount_codetotid_cache[$code_sell_l])) {
+ if (empty($suggestedid) && empty($code_p) && !empty($code_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
+ if (empty($this->accountingaccount_codetotid_cache[$code_l])) {
$tmpaccount = new self($this->db);
- $result = $tmpaccount->fetch(0, $code_sell_l, 1);
+ $result = $tmpaccount->fetch(0, $code_l, 1);
if ($result < 0) {
return -1;
}
if ($tmpaccount->id > 0) {
$suggestedid = $tmpaccount->id;
}
- $this->accountingaccount_codetotid_cache[$code_sell_l] = $tmpaccount->id;
+ $this->accountingaccount_codetotid_cache[$code_l] = $tmpaccount->id;
} else {
- $suggestedid = $this->accountingaccount_codetotid_cache[$code_sell_l];
+ $suggestedid = $this->accountingaccount_codetotid_cache[$code_l];
}
}
return array(
'suggestedaccountingaccountbydefaultfor' => $suggestedaccountingaccountbydefaultfor,
'suggestedaccountingaccountfor' => $suggestedaccountingaccountfor,
'suggestedid' => $suggestedid,
- 'code_sell_l' => $code_sell_l,
- 'code_sell_p' => $code_sell_p,
- 'code_sell_t' => $code_sell_t,
+ 'code_l' => $code_l,
+ 'code_p' => $code_p,
+ 'code_t' => $code_t,
);
} else {
if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php
index a7220d01a28..fdcc6f54ab3 100644
--- a/htdocs/accountancy/closure/index.php
+++ b/htdocs/accountancy/closure/index.php
@@ -63,7 +63,7 @@ if (empty($conf->accounting->enabled)) {
if ($user->socid > 0) {
accessforbidden();
}
-if (!$user->rights->accounting->fiscalyear->write) {
+if (empty($user->rights->accounting->fiscalyear->write)) {
accessforbidden();
}
diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php
index aa1abde5fa5..23958820b64 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -43,7 +43,7 @@ if (empty($conf->accounting->enabled)) {
if ($user->socid > 0) {
accessforbidden();
}
-if (!$user->rights->accounting->bind->write) {
+if (empty($user->rights->accounting->bind->write)) {
accessforbidden();
}
@@ -73,12 +73,23 @@ $action = GETPOST('action', 'aZ09');
$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
+// Security check
+if (empty($conf->accounting->enabled)) {
+ accessforbidden();
+}
+if ($user->socid > 0) {
+ accessforbidden();
+}
+if (empty($user->rights->accounting->mouvements->lire)) {
+ accessforbidden();
+}
+
/*
* Actions
*/
-if ($action == 'clean' || $action == 'validatehistory') {
+if (($action == 'clean' || $action == 'validatehistory') && $user->rights->accounting->bind->write) {
// Clean database
$db->begin();
$sql1 = "UPDATE ".MAIN_DB_PREFIX."facturedet as fd";
@@ -165,6 +176,7 @@ if ($action == 'validatehistory') {
}
dol_syslog('htdocs/accountancy/customer/index.php');
+
$result = $db->query($sql);
if (!$result) {
$error++;
@@ -209,7 +221,6 @@ if ($action == 'validatehistory') {
$product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
$product_static->accountancy_code_buy_export = $objp->code_buy_export;
$product_static->tva_tx = $objp->tva_tx_prod;
- $product_static->tva_tx = $objp->tva_tx_prod;
$facture_static->ref = $objp->ref;
$facture_static->id = $objp->facid;
@@ -223,7 +234,7 @@ if ($action == 'validatehistory') {
$facture_static_det->product_type = $objp->type_l;
$facture_static_det->desc = $objp->description;
- $accoutinAccountArray = array(
+ $accountingAccountArray = array(
'dom'=>$objp->aarowid,
'intra'=>$objp->aarowid_intra,
'export'=>$objp->aarowid_export,
@@ -232,7 +243,7 @@ if ($action == 'validatehistory') {
$code_sell_p_notset = '';
$code_sell_t_notset = '';
- $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accoutinAccountArray);
+ $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer');
if (!is_array($return) && $return<0) {
setEventMessage($accountingAccount->error, 'errors');
} else {
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 97a885f97b9..24a64bac872 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -2,7 +2,7 @@
/* Copyright (C) 2013-2014 Olivier Geffroy
* Copyright (C) 2013-2021 Alexandre Spangaro
* Copyright (C) 2014-2015 Ari Elbaz (elarifr)
- * Copyright (C) 2013-2014 Florian Henry
+ * Copyright (C) 2013-2021 Florian Henry
* Copyright (C) 2014 Juanjo Menent
* Copyright (C) 2016 Laurent Destailleur
*
@@ -192,10 +192,10 @@ if ($massaction == 'ventil' && $user->rights->accounting->bind->write) {
dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
if ($db->query($sql)) {
- $msg .= '