Merge branch '7.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/compta/tva/index.php
	htdocs/install/mysql/data/llx_accounting_category.sql
This commit is contained in:
Laurent Destailleur 2018-03-15 15:11:18 +01:00
commit c4ca4a5a16
5 changed files with 77 additions and 71 deletions

View File

@ -152,7 +152,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
{
if ($value == 'formula' && empty($_POST['formula'])) continue;
if ($value == 'range_account' && empty($_POST['range_account'])) continue;
if ($value == 'country') continue; // country_id required but not country
if ($value == 'country' || $value == 'country_id') continue;
if (! isset($_POST[$value]) || $_POST[$value]=='')
{
$ok=0;
@ -175,16 +175,12 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
$ok=0;
setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
}
/*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
{
$ok = 0;
$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
}*/
}
if (isset($_POST["country"]) && ($_POST["country"] <= 0))
if (! is_numeric(GETPOST('position','alpha')))
{
$ok=0;
setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
$langs->load("errors");
$ok=0;
setEventMessages($langs->transnoentities('ErrorFieldMustBeANumeric', $langs->transnoentities("Position")), null, 'errors');
}
// Clean some parameters
@ -193,7 +189,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
// Si verif ok et action add, on ajoute la ligne
if ($ok && GETPOST('actionadd'))
if ($ok && GETPOST('actionadd','alpha'))
{
if ($tabrowid[$id])
{
@ -214,15 +210,13 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
// Add new entry
$sql = "INSERT INTO ".$tabname[$id]." (";
// List of fields
if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
$sql.= $tabrowid[$id].",";
if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert)) $sql.= $tabrowid[$id].",";
$sql.= $tabfieldinsert[$id];
$sql.=",active)";
$sql.= " VALUES(";
// List of values
if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
$sql.= $newid.",";
if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert)) $sql.= $newid.",";
$i=0;
foreach ($listfieldinsert as $f => $value)
{
@ -306,7 +300,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." = '".$this->db->escape($rowid)."'";
dol_syslog("delete", LOG_DEBUG);
$result = $db->query($sql);
@ -330,10 +324,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." = '".$this->db->escape($rowid)."'";
}
elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
$sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code = '".$this->db->escape($code)."'";
}
$result = $db->query($sql);
@ -350,10 +344,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." = '".$this->db->escape($rowid)."'";
}
elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
$sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code = '".$this->db->escape($code)."'";
}
$result = $db->query($sql);
@ -370,10 +364,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." = '".$this->db->escape($rowid)."'";
}
elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$code."'";
$sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code = '".$this->db->escape($code)."'";
}
$result = $db->query($sql);
@ -390,10 +384,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." = '".$this->db->escape($rowid)."'";
}
elseif ($code) {
$sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$code."'";
$sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code = '".$this->db->escape($code)."'";
}
$result = $db->query($sql);
@ -440,7 +434,7 @@ if ($id)
{
if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
else $sql.=" WHERE ";
$sql.= " c.rowid = ".$search_country_id;
$sql.= " (a.fk_country = ".$search_country_id." OR a.fk_country = 0)";
}
if ($sortfield)

View File

@ -579,31 +579,25 @@ class AccountancyCategory // extends CommonObject
*
* @return array Result in table
*/
public function getCatsCpts() {
public function getCatsCpts()
{
global $mysoc;
$sql = "";
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
if (empty($mysoc->country_id)) {
dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
exit();
}
if (! empty($mysoc->country_id)) {
$sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat";
$sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid ";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
$sql .= " WHERE c.active = 1";
$sql .= " AND c.fk_country = " . $mysoc->country_id . ")";
$sql .= " AND cat.rowid = t.fk_accounting_category";
$sql .= " ORDER BY cat.position ASC";
} else {
$sql = "SELECT c.rowid, c.code, c.label, c.category_type ";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co";
$sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid";
$sql .= " AND co.code = '" . $mysoc->country_code . "'";
$sql .= " ORDER BY c.position ASC";
}
$sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens ";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat";
$sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid ";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
$sql .= " WHERE c.active = 1";
$sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
$sql .= " AND cat.rowid = t.fk_accounting_category";
$sql .= " ORDER BY cat.position ASC";
$resql = $this->db->query($sql);
if ($resql) {
@ -684,7 +678,7 @@ class AccountancyCategory // extends CommonObject
}
/**
* Return list of personalized groups
* Return list of personalized groups that are active
*
* @param int $categorytype -1=All, 0=Only non computed groups, 1=Only computed groups
* @return array Array of groups
@ -693,26 +687,17 @@ class AccountancyCategory // extends CommonObject
{
global $db, $langs, $user, $mysoc;
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
if (empty($mysoc->country_id)) {
dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
exit();
}
if (! empty($mysoc->country_id)) {
$sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
$sql .= " WHERE c.active = 1 ";
if ($categorytype >= 0) $sql.=" AND c.category_type = 1";
$sql .= " AND c.fk_country = " . $mysoc->country_id;
$sql .= " ORDER BY c.position ASC";
} else { // Note: this should not happen
$sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co";
$sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid";
if ($categorytype >= 0) $sql.=" AND c.category_type = 1";
$sql .= " AND co.code = '" . $mysoc->country_code . "'";
$sql .= " ORDER BY c.position ASC";
}
$sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
$sql .= " WHERE c.active = 1 ";
if ($categorytype >= 0) $sql.=" AND c.category_type = 1";
$sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
$sql .= " ORDER BY c.position ASC";
$resql = $this->db->query($sql);
if ($resql) {
@ -769,14 +754,14 @@ class AccountancyCategory // extends CommonObject
$sql = "SELECT t.rowid, t.account_number, t.label as account_label";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
$sql .= " WHERE t.fk_accounting_category = ".$cat_id;
$sql .= " ORDER BY t.account_number ";
$sql .= " ORDER BY t.account_number";
}
else
{
$sql = "SELECT t.rowid, t.account_number, t.label as account_label";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
$sql .= " WHERE ".$predefinedgroupwhere;
$sql .= " ORDER BY t.account_number ";
$sql .= " ORDER BY t.account_number";
}
//echo $sql;

View File

@ -218,7 +218,7 @@ if ($date_endyear) $param.='&date_endyear='.$date_startyear;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print_liste_field_titre("PredefinedGroups", $_SERVER["PHP_SELF"], 's.nom, s.rowid','',$param,'',$sortfield,$sortorder,'width200 ');
print_liste_field_titre("PredefinedGroups", $_SERVER["PHP_SELF"], 'f.thirdparty_code,f.rowid','',$param,'',$sortfield,$sortorder,'width200 ');
print_liste_field_titre('');
if ($modecompta == 'BOOKKEEPING')
{

View File

@ -254,9 +254,33 @@ else if ($modecompta=="RECETTES-DEPENSES")
else if ($modecompta=="BOOKKEEPING")
{
//All categories
$cats = $AccCat->getCats();
if ($catsCalcule < 0) dol_print_error($db, $AccCat->error, $AccCat->errors);
// Get array of all report groups that are active
$cats = $AccCat->getCats(); // WARNING: Computed groups must be after group they include
/*
$sql = 'SELECT DISTINCT t.numero_compte as nb FROM '.MAIN_DB_PREFIX.'accounting_bookkeeping as t, '.MAIN_DB_PREFIX.'accounting_account as aa';
$sql.= " WHERE t.numero_compte = aa.account_number AND aa.fk_accounting_category = 0";
if (! empty($date_start) && ! empty($date_end))
$sql.= " AND t.doc_date >= '".$db->idate($date_start)."' AND t.doc_date <= '".$db->idate($date_end)."'";
if (! empty($month)) {
$sql .= " AND MONTH(t.doc_date) = " . $month;
}
$resql = $db->query($sql);
if ($resql)
{
$num_rows = $db->num_rows($resql);
if ($num_rows) {
print '<div class="warning">Warning: There is '.$num_rows.' accounts in your ledger table that are not set into a reporting group</div>';
$i = 0;
//while ($i < $num) {
// $obj = $db->fetch_object($resql);
// $i++;
//}
}
}
else dol_print_error($db);
*/
$j=1;
$sommes = array();
@ -365,7 +389,7 @@ else if ($modecompta=="BOOKKEEPING")
$totCat['M'][$k] = 0;
}
// Get cpts of category/group
// Set $cpts of with array of accounts in the category/group
$cpts = $AccCat->getCptsCat($cat['rowid']);
print "<tr>";
@ -373,7 +397,10 @@ else if ($modecompta=="BOOKKEEPING")
// Column group
print '<td class="width200">';
print $cat['code'];
print '</td><td>';
print '</td>';
// Label of group
print '<td>';
print $cat['label'];
if (count($cpts) > 0) // Show example of 5 first accounting accounts
{

View File

@ -17,8 +17,8 @@
--
-- Group of accounting account for French reports. This is a minimal default setup.
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'INCOME', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 1, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'EXPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 1, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'VENTES+DEPENSES', '30', 1, 1);
-- Group of accounting accounts for report. This is a minimal default setup.
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'INCOMES', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 0, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'EXPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 0, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'INCOMES+EXPENSES', '30', 0, 1);