From c3518426bde70dacda369a99579f9f0600e04366 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 3 Jan 2020 22:05:49 +0100 Subject: [PATCH] NEW Accountancy - Add possibility to manage an short alternative label - use to simplify --- htdocs/accountancy/admin/account.php | 26 +++++++++++--- htdocs/accountancy/admin/card.php | 18 ++++++++-- .../class/accountingaccount.class.php | 35 ++++++++++++++----- .../core/class/html.formaccounting.class.php | 17 ++++++--- .../install/mysql/migration/11.0.0-12.0.0.sql | 1 + .../mysql/tables/llx_accounting_account.sql | 3 +- 6 files changed, 80 insertions(+), 20 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 9c4536e94c4..4caad5cfa94 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2020 Alexandre Spangaro * Copyright (C) 2016-2018 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -41,6 +41,7 @@ $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'acc $search_account = GETPOST('search_account', 'alpha'); $search_label = GETPOST('search_label', 'alpha'); +$search_labelshort = GETPOST('search_labelshort', 'alpha'); $search_accountparent = GETPOST('search_accountparent', 'alpha'); $search_pcgtype = GETPOST('search_pcgtype', 'alpha'); $search_pcgsubtype = GETPOST('search_pcgsubtype', 'alpha'); @@ -64,6 +65,7 @@ if (!$sortorder) $sortorder = "ASC"; $arrayfields = array( 'aa.account_number'=>array('label'=>$langs->trans("AccountNumber"), 'checked'=>1), 'aa.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1), + 'aa.labelshort'=>array('label'=>$langs->trans("LabelToShow"), 'checked'=>1), 'aa.account_parent'=>array('label'=>$langs->trans("Accountparent"), 'checked'=>1), 'aa.pcg_type'=>array('label'=>$langs->trans("Pcgtype"), 'checked'=>1, 'help'=>'PcgtypeDesc'), 'aa.pcg_subtype'=>array('label'=>$langs->trans("Pcgsubtype"), 'checked'=>0, 'help'=>'PcgtypeDesc'), @@ -95,7 +97,8 @@ if (empty($reshook)) { $search_account = ""; $search_label = ""; - $search_accountparent = ""; + $search_labelshort = ""; + $search_accountparent = ""; $search_pcgtype = ""; $search_pcgsubtype = ""; $search_array_options = array(); @@ -190,7 +193,7 @@ if ($action == 'delete') { $pcgver = $conf->global->CHARTOFACCOUNTS; -$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.pcg_subtype, aa.account_number, aa.account_parent , aa.label, aa.active, "; +$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.pcg_subtype, aa.account_number, aa.account_parent , aa.label, aa.labelshort, aa.active, "; $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".$conf->entity; @@ -200,6 +203,7 @@ $sql .= " WHERE asy.rowid = ".$pcgver; //print $sql; if (strlen(trim($search_account))) $sql .= natural_search("aa.account_number", $search_account); if (strlen(trim($search_label))) $sql .= natural_search("aa.label", $search_label); +if (strlen(trim($search_labelshort))) $sql .= natural_search("aa.labelshort", $search_labelshort); if (strlen(trim($search_accountparent))) $sql .= natural_search("aa.account_parent", $search_accountparent); if (strlen(trim($search_pcgtype))) $sql .= natural_search("aa.pcg_type", $search_pcgtype); if (strlen(trim($search_pcgsubtype))) $sql .= natural_search("aa.pcg_subtype", $search_pcgsubtype); @@ -232,6 +236,7 @@ if ($resql) if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; if ($search_account) $param .= '&search_account='.urlencode($search_account); if ($search_label) $param .= '&search_label='.urlencode($search_label); + if ($search_labelshort) $param.= '&search_labelshort='.urlencode($search_labelshort); if ($search_accountparent) $param .= '&search_accountparent='.urlencode($search_accountparent); if ($search_pcgtype) $param .= '&search_pcgtype='.urlencode($search_pcgtype); if ($search_pcgsubtype) $param .= '&search_pcgsubtype='.urlencode($search_pcgsubtype); @@ -316,8 +321,9 @@ if ($resql) print ''; if (!empty($arrayfields['aa.account_number']['checked'])) print ''; if (!empty($arrayfields['aa.label']['checked'])) print ''; + if (!empty($arrayfields['aa.labelshort']['checked'])) print ''; if (!empty($arrayfields['aa.account_parent']['checked'])) print ''; - if (!empty($arrayfields['aa.pcg_type']['checked'])) print ''; + if (!empty($arrayfields['aa.pcg_type']['checked'])) print ''; if (!empty($arrayfields['aa.pcg_subtype']['checked'])) print ''; if (!empty($arrayfields['aa.active']['checked'])) print ' '; print ''; @@ -329,8 +335,9 @@ if ($resql) print ''; if (!empty($arrayfields['aa.account_number']['checked'])) print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['aa.label']['checked'])) print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder); + if (!empty($arrayfields['aa.labelshort']['checked'])) print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['aa.account_parent']['checked'])) print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left '); - if (!empty($arrayfields['aa.pcg_type']['checked'])) print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help']); + if (!empty($arrayfields['aa.pcg_type']['checked'])) print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help']); if (!empty($arrayfields['aa.pcg_subtype']['checked'])) print_liste_field_titre($arrayfields['aa.pcg_subtype']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_subtype', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_subtype']['help']); if (!empty($arrayfields['aa.active']['checked'])) print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); @@ -368,6 +375,15 @@ if ($resql) if (!$i) $totalarray['nbfield']++; } + // Account label to show (label short) + if (! empty($arrayfields['aa.labelshort']['checked'])) + { + print ""; + print $obj->labelshort; + print "\n"; + if (! $i) $totalarray['nbfield']++; + } + // Account parent if (!empty($arrayfields['aa.account_parent']['checked'])) { diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 33ff1e409e9..f2bc1907c7c 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2018 Alexandre Spangaro + * Copyright (C) 2013-2020 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -97,6 +97,7 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount) $object->account_parent = $account_parent; $object->account_category = GETPOST('account_category', 'alpha'); $object->label = GETPOST('label', 'alpha'); + $object->labelshort = GETPOST('labelshort', 'alpha'); $object->active = 1; $res = $object->create($user); @@ -162,6 +163,7 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount) $object->account_parent = $account_parent; $object->account_category = GETPOST('account_category', 'alpha'); $object->label = GETPOST('label', 'alpha'); + $object->labelshort = GETPOST('labelshort', 'alpha'); $result = $object->update($user); @@ -236,6 +238,10 @@ if ($action == 'create') { print ''.$langs->trans("Label").''; print ''; + // Label short + print '' . $langs->trans("LabelToShow") . ''; + print ''; + // Account parent print ''.$langs->trans("Accountparent").''; print ''; @@ -254,7 +260,7 @@ if ($action == 'create') { print ''; print ''; - // Chart of acounts subtype + // Chart of accounts subtype print ''.$langs->trans("Pcgsubtype").''; print ''; print ''; @@ -301,6 +307,10 @@ elseif ($id > 0 || $ref) { print ''.$langs->trans("Label").''; print ''; + // Label short + print '' . $langs->trans("LabelToShow") . ''; + print ''; + // Account parent print ''.$langs->trans("Accountparent").''; print ''; @@ -354,6 +364,10 @@ elseif ($id > 0 || $ref) { print ''.$langs->trans("Label").''; print ''.$object->label.''; + // Label to show + print '' . $langs->trans("LabelToShow") . ''; + print '' . $object->labelshort . ''; + // Account parent $accp = new AccountingAccount($db); if (!empty($object->account_parent)) { diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index b244d8be123..d1525b56833 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2020 Alexandre Spangaro * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) @@ -120,7 +120,12 @@ class AccountingAccount extends CommonObject */ public $label; - /** + /** + * @var string Label short of account + */ + public $labelshort; + + /** * @var int ID */ public $fk_user_author; @@ -162,7 +167,7 @@ class AccountingAccount extends CommonObject global $conf; if ($rowid || $account_number) { - $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; + $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; $sql .= ", ca.label as category_label"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; @@ -196,6 +201,7 @@ class AccountingAccount extends CommonObject $this->account_number = $obj->account_number; $this->account_parent = $obj->account_parent; $this->label = $obj->label; + $this->labelshort = $obj->labelshort; $this->account_category = $obj->fk_accounting_category; $this->account_category_label = $obj->category_label; $this->fk_user_author = $obj->fk_user_author; @@ -239,6 +245,8 @@ class AccountingAccount extends CommonObject $this->account_number = trim($this->account_number); if (isset($this->label)) $this->label = trim($this->label); + if (isset($this->labelshort)) + $this->labelshort = trim($this->labelshort); if (empty($this->pcg_type) || $this->pcg_type == '-1') { @@ -261,6 +269,7 @@ class AccountingAccount extends CommonObject $sql .= ", account_number"; $sql .= ", account_parent"; $sql .= ", label"; + $sql .= ", labelshort"; $sql .= ", fk_accounting_category"; $sql .= ", fk_user_author"; $sql .= ", active"; @@ -273,6 +282,7 @@ class AccountingAccount extends CommonObject $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'"); $sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->account_parent); $sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'"); + $sql .= ", " . (empty($this->labelshort) ? "''" : "'" . $this->db->escape($this->labelshort) . "'"); $sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category); $sql .= ", " . $user->id; $sql .= ", " . (int) $this->active; @@ -344,6 +354,7 @@ class AccountingAccount extends CommonObject $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'"; $sql .= " , account_parent = " . (int) $this->account_parent; $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''"); + $sql .= " , labelshort = " . ($this->labelshort ? "'" . $this->db->escape($this->labelshort) . "'" : "''"); $sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category); $sql .= " , fk_user_modif = " . $user->id; $sql .= " , active = " . (int) $this->active; @@ -461,10 +472,11 @@ class AccountingAccount extends CommonObject * @param string $moretitle Add more text to title tooltip * @param int $notooltip 1=Disable tooltip * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $withcompletelabel 0=Short label (field short label), 1=Complete label (field label) * @return string String with URL */ - public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1) - { + public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0) + { global $langs, $conf, $user; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; @@ -482,11 +494,18 @@ class AccountingAccount extends CommonObject $picto = 'billr'; $label=''; + if (empty($this->labelshort) || $withcompletelabel == 1) + { + $labeltoshow = $this->label; + } else { + $labeltoshow = $this->labelshort; + } + $label = '' . $langs->trans("ShowAccountingAccount") . ''; if (! empty($this->account_number)) $label .= '
'.$langs->trans('AccountAccounting') . ': ' . length_accountg($this->account_number); - if (! empty($this->label)) - $label .= '
'.$langs->trans('Label') . ': ' . $this->label; + if (! empty($labeltoshow)) + $label .= '
'.$langs->trans('Label') . ': ' . $labeltoshow; if ($moretitle) $label.=' - '.$moretitle; $linkclose=''; @@ -513,7 +532,7 @@ class AccountingAccount extends CommonObject } $label_link = length_accountg($this->account_number); - if ($withlabel) $label_link .= ' - ' . $this->label; + if ($withlabel) $label_link .= ' - ' . $labeltoshow; if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result .= ' '; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index c26a9cd7108..204aeea32f7 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2013-2014 Olivier Geffroy * Copyright (C) 2015 Ari Elbaz (elarifr) * Copyright (C) 2016 Marcos GarcĂ­a - * Copyright (C) 2016-2017 Alexandre Spangaro + * Copyright (C) 2016-2020 Alexandre Spangaro * * 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 @@ -292,7 +292,7 @@ class FormAccounting extends Form { $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT; - $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; + $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.labelshort, aa.rowid, aa.fk_pcg_version"; $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 .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS; @@ -312,8 +312,17 @@ class FormAccounting extends Form $selected = 0; while ($obj = $this->db->fetch_object($resql)) { - $label = length_accountg($obj->account_number).' - '.$obj->label; - $label = dol_trunc($label, $trunclength); + if (empty($obj->labelshort)) + { + $labeltoshow = $obj->label; + } + else + { + $labeltoshow = $obj->labelshort; + } + + $label = length_accountg($obj->account_number) . ' - ' . $labeltoshow; + $label = dol_trunc($label, $trunclength); $select_value_in = $obj->rowid; $select_value_out = $obj->rowid; diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index b0ecc2b9639..775c6e15a29 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -52,6 +52,7 @@ create table llx_object_lang ALTER TABLE llx_object_lang ADD UNIQUE INDEX uk_object_lang (fk_object, type_object, property, lang); +ALTER TABLE llx_accounting_account ADD COLUMN labelshort varchar(255) DEFAULT NULL after label; diff --git a/htdocs/install/mysql/tables/llx_accounting_account.sql b/htdocs/install/mysql/tables/llx_accounting_account.sql index e06faab0f00..3dbe025dbd3 100644 --- a/htdocs/install/mysql/tables/llx_accounting_account.sql +++ b/htdocs/install/mysql/tables/llx_accounting_account.sql @@ -1,7 +1,7 @@ -- ============================================================================ -- Copyright (C) 2004-2006 Laurent Destailleur -- Copyright (C) 2014 Juanjo Menent --- Copyright (C) 2016 Alexandre Spangaro +-- Copyright (C) 2016-2020 Alexandre Spangaro -- -- 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 @@ -31,6 +31,7 @@ create table llx_accounting_account account_number varchar(32) NOT NULL, account_parent integer DEFAULT 0, -- Hierarchic parent. label varchar(255) NOT NULL, + labelshort varchar(255) DEFAULT NULL, fk_accounting_category integer DEFAULT 0, -- ID of personalized group for report fk_user_author integer DEFAULT NULL, fk_user_modif integer DEFAULT NULL,