Clean code

This commit is contained in:
Laurent Destailleur 2021-04-13 11:30:23 +02:00
parent 9e491ad30c
commit 3439bc4a0f
4 changed files with 438 additions and 436 deletions

View File

@ -55,7 +55,7 @@ $accountingcategory = new AccountancyCategory($db);
* Actions * Actions
*/ */
// si ajout de comptes // If we add account
if (!empty($selectcpt)) { if (!empty($selectcpt)) {
$cpts = array(); $cpts = array();
foreach ($selectcpt as $selectedoption) { foreach ($selectcpt as $selectedoption) {
@ -72,6 +72,7 @@ if (!empty($selectcpt)) {
setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs'); setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs');
} }
} }
if ($action == 'delete') { if ($action == 'delete') {
if ($cpt_id) { if ($cpt_id) {
if ($accountingcategory->deleteCptCat($cpt_id)) { if ($accountingcategory->deleteCptCat($cpt_id)) {
@ -93,8 +94,9 @@ $formaccounting = new FormAccounting($db);
llxheader('', $langs->trans('AccountingCategory')); llxheader('', $langs->trans('AccountingCategory'));
$linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$titlepicto = 'setup';
print load_fiche_titre($langs->trans('AccountingCategory'), $linkback); print load_fiche_titre($langs->trans('AccountingCategory'), $linkback, $titlepicto);
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n"; print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';

View File

@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array("errors", "admin", "companies", "resource", "holiday", "accountancy", "hrm")); $langs->loadLangs(array("errors", "admin", "companies", "resource", "holiday", "accountancy", "hrm"));
@ -52,7 +53,6 @@ $actl[1] = img_picto($langs->trans("Activated"), 'switch_on');
$listoffset = GETPOST('listoffset', 'alpha'); $listoffset = GETPOST('listoffset', 'alpha');
$listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000; $listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000;
$active = 1;
$sortfield = GETPOST("sortfield", 'aZ09comma'); $sortfield = GETPOST("sortfield", 'aZ09comma');
$sortorder = GETPOST("sortorder", 'aZ09comma'); $sortorder = GETPOST("sortorder", 'aZ09comma');
@ -124,11 +124,7 @@ $tabfieldcheck[32] = array();
// Complete all arrays with entries found into modules // Complete all arrays with entries found into modules
complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck); complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
$accountingcategory = new AccountancyCategory($db);
// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
$elementList = array();
$sourceList = array();
/* /*
@ -428,7 +424,7 @@ llxHeader('', $langs->trans('DictionaryAccountancyCategory'));
$titre = $langs->trans($tablib[$id]); $titre = $langs->trans($tablib[$id]);
$linkback = ''; $linkback = '';
$titlepicto = 'title_accountancy'; $titlepicto = 'setup';
print load_fiche_titre($titre, $linkback, $titlepicto); print load_fiche_titre($titre, $linkback, $titlepicto);
@ -438,43 +434,38 @@ print '<span class="opacitymedium">'.$langs->trans("AccountingAccountGroupsDesc"
if ($action == 'delete') { if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id.($search_country_id > 0 ? '&search_country_id='.$search_country_id : ''), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1); print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id.($search_country_id > 0 ? '&search_country_id='.$search_country_id : ''), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
} }
//var_dump($elementList);
/* // Complete requete recherche valeurs avec critere de tri
* Show a dictionary $sql = $tabsql[$id];
*/
if ($id) {
// Complete requete recherche valeurs avec critere de tri
$sql = $tabsql[$id];
if ($search_country_id > 0) { if ($search_country_id > 0) {
if (preg_match('/ WHERE /', $sql)) { if (preg_match('/ WHERE /', $sql)) {
$sql .= " AND "; $sql .= " AND ";
} else { } else {
$sql .= " WHERE "; $sql .= " WHERE ";
} }
$sql .= " (a.fk_country = ".$search_country_id." OR a.fk_country = 0)"; $sql .= " (a.fk_country = ".$search_country_id." OR a.fk_country = 0)";
} }
// If sort order is "country", we use country_code instead // If sort order is "country", we use country_code instead
if ($sortfield == 'country') { if ($sortfield == 'country') {
$sortfield = 'country_code'; $sortfield = 'country_code';
} }
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($listlimit + 1, $offset); $sql .= $db->plimit($listlimit + 1, $offset);
//print $sql; //print $sql;
$fieldlist = explode(',', $tabfield[$id]); $fieldlist = explode(',', $tabfield[$id]);
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'; print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">'; print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
// Form to add a new line // Form to add a new line
if ($tabname[$id]) { if ($tabname[$id]) {
$fieldlist = explode(',', $tabfield[$id]); $fieldlist = explode(',', $tabfield[$id]);
// Line for title // Line for title
@ -577,12 +568,13 @@ if ($id) {
} }
print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
} }
// List of available record in database // List of available record in database
dol_syslog("htdocs/admin/dict", LOG_DEBUG); dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) { $resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -842,6 +834,16 @@ if ($id) {
print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">'; print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">';
print $langs->trans("ListOfAccounts"); print $langs->trans("ListOfAccounts");
print '</a>'; print '</a>';
// Count number of accounts into group
$nbofaccountintogroup = 0;
$listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
$nbofaccountintogroup = count($listofaccountintogroup);
//if ($nbofaccountintogroup > 0) {
print ' <span class="opacitymedium">('.$langs->trans("NAccounts", $nbofaccountintogroup).')</span>';
//} else {
// print ' <span class="opacitymedium">(0)</span>';
//}
} }
print '</td>'; print '</td>';
} }
@ -849,16 +851,15 @@ if ($id) {
$i++; $i++;
} }
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
}
print '</table>';
print '</div>';
print '</form>';
} }
print '</table>';
print '</div>';
print '</form>';
print '<br>'; print '<br>';
// End of page // End of page
@ -879,9 +880,6 @@ function fieldListAccountingCategories($fieldlist, $obj = '', $tabname = '', $co
{ {
global $conf, $langs, $db; global $conf, $langs, $db;
global $form, $mysoc; global $form, $mysoc;
global $region_id;
global $elementList, $sourceList, $localtax_typeList;
global $bc;
$formadmin = new FormAdmin($db); $formadmin = new FormAdmin($db);
$formcompany = new FormCompany($db); $formcompany = new FormCompany($db);

View File

@ -418,7 +418,7 @@ class AccountancyCategory // extends CommonObject
/** /**
* Function to select all accounting accounts from an accounting category * Function to select into ->lines_display all accounting accounts for a given custom accounting group
* *
* @param int $id Id * @param int $id Id
* @return int <0 if KO, 0 if not found, >0 if OK * @return int <0 if KO, 0 if not found, >0 if OK
@ -453,23 +453,23 @@ class AccountancyCategory // extends CommonObject
} }
/** /**
* Function to select accounting category of an accounting account present in chart of accounts * Function to fill ->lines_cptbk with accounting account used (into bookkeeping) and not yet into a custom group
*
* @param int $id Id category
* *
* @param int $id Id of custom group
* @return int <0 if KO, 0 if not found, >0 if OK * @return int <0 if KO, 0 if not found, >0 if OK
*/ */
/*
public function getCptBK($id) public function getCptBK($id)
{ {
global $conf; global $conf;
$sql = "SELECT t.numero_compte, t.label_operation, t.doc_ref"; $sql = "SELECT DISTINCT t.numero_compte, t.label_operation, t.doc_ref";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t";
$sql .= " WHERE t.numero_compte NOT IN ("; $sql .= " WHERE t.numero_compte NOT IN ("; // account not into a custom group
$sql .= " SELECT t.account_number"; $sql .= " SELECT t.account_number";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
$sql .= " WHERE t.fk_accounting_category = ".$id." AND t.entity = ".$conf->entity.")"; $sql .= " WHERE t.fk_accounting_category = ".((int) $id)." AND t.entity = ".$conf->entity.")";
$sql .= " AND t.numero_compte IN ("; $sql .= " AND t.numero_compte IN ("; // account into current chart of account
$sql .= " SELECT DISTINCT aa.account_number"; $sql .= " SELECT DISTINCT aa.account_number";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
@ -479,7 +479,7 @@ class AccountancyCategory // extends CommonObject
$sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref"; $sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref";
$sql .= " ORDER BY t.numero_compte"; $sql .= " ORDER BY t.numero_compte";
$this->lines_CptBk = array(); $this->lines_cptbk = array();
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -500,12 +500,12 @@ class AccountancyCategory // extends CommonObject
return -1; return -1;
} }
} }
*/
/** /**
* Function to select accounting category of an accounting account present in chart of accounts * Function to fill ->lines_cptbk with accounting account (defined in chart of account) and not yet into a custom group
* *
* @param int $id Id of category to know which account to exclude * @param int $id Id of category to know which account to exclude
*
* @return int <0 if KO, 0 if not found, >0 if OK * @return int <0 if KO, 0 if not found, >0 if OK
*/ */
public function getAccountsWithNoCategory($id) public function getAccountsWithNoCategory($id)
@ -515,14 +515,14 @@ class AccountancyCategory // extends CommonObject
$sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte"; $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
$sql .= " WHERE (aa.fk_accounting_category != ".$id." OR aa.fk_accounting_category IS NULL)"; $sql .= " WHERE (aa.fk_accounting_category <> ".((int) $id)." OR aa.fk_accounting_category IS NULL)";
$sql .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS; $sql .= " AND asy.rowid = ".((int) $conf->global->CHARTOFACCOUNTS);
$sql .= " AND aa.active = 1"; $sql .= " AND aa.active = 1";
$sql .= " AND aa.entity = ".$conf->entity; $sql .= " AND aa.entity = ".$conf->entity;
$sql .= " GROUP BY aa.account_number, aa.label"; $sql .= " GROUP BY aa.account_number, aa.label";
$sql .= " ORDER BY aa.account_number, aa.label"; $sql .= " ORDER BY aa.account_number, aa.label";
$this->lines_CptBk = array(); $this->lines_cptbk = array();
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -656,7 +656,7 @@ class AccountancyCategory // extends CommonObject
} }
/** /**
* Function to know all category from accounting account * Function to know all custom groupd from an accounting account
* *
* @return array|integer Result in table (array), -1 if KO * @return array|integer Result in table (array), -1 if KO
*/ */
@ -785,7 +785,7 @@ class AccountancyCategory // extends CommonObject
} }
/** /**
* Return list of personalized groups that are active * Return list of custom groups that are active
* *
* @param int $categorytype -1=All, 0=Only non computed groups, 1=Only computed groups * @param int $categorytype -1=All, 0=Only non computed groups, 1=Only computed groups
* @return array|int Array of groups or -1 if error * @return array|int Array of groups or -1 if error
@ -843,11 +843,11 @@ class AccountancyCategory // extends CommonObject
/** /**
* Get all accounting account of a group. * Get all accounting account of a custom group (or a list of custom groups).
* You must choose between first parameter (personalized group) or the second (free criteria filter) * You must choose between first parameter (personalized group) or the second (free criteria filter)
* *
* @param int $cat_id Id if personalized accounting group/category * @param int $cat_id Id if personalized accounting group/category
* @param string $predefinedgroupwhere Sql criteria filter to select accounting accounts * @param string $predefinedgroupwhere Sql criteria filter to select accounting accounts. This value must not come from an input of a user.
* @return array|int Array of accounting accounts or -1 if error * @return array|int Array of accounting accounts or -1 if error
*/ */
public function getCptsCat($cat_id, $predefinedgroupwhere = '') public function getCptsCat($cat_id, $predefinedgroupwhere = '')

View File

@ -426,3 +426,5 @@ DateExport=Date export
WarningReportNotReliable=Warning, this report is not based on the Ledger, so does not contains transaction modified manually in the Ledger. If your journalization is up to date, the bookkeeping view is more accurate. WarningReportNotReliable=Warning, this report is not based on the Ledger, so does not contains transaction modified manually in the Ledger. If your journalization is up to date, the bookkeeping view is more accurate.
ExpenseReportJournal=Expense Report Journal ExpenseReportJournal=Expense Report Journal
InventoryJournal=Inventory Journal InventoryJournal=Inventory Journal
NAccounts=%s accounts