From a231074012902f16fdd6b19f6e18491828f7c859 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 9 Apr 2018 11:31:24 +0200 Subject: [PATCH] Save search criteria when using "back to" on accounting account Change type of foreign key to be an integer to avoid CAST in requests --- htdocs/accountancy/admin/account.php | 15 +++++++-------- htdocs/accountancy/admin/card.php | 11 +++++++---- .../class/accountingaccount.class.php | 18 ++++++++++++------ htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 5 +++++ .../tables/llx_accounting_account.key.sql | 1 + .../mysql/tables/llx_accounting_account.sql | 2 +- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 2dd71e8e2e6..7d73202eb79 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2016-2017 Laurent Destailleur + * Copyright (C) 2016-2018 Laurent Destailleur * * 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 @@ -176,11 +176,10 @@ $sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.pcg_subtype, aa.acco $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"; -// Dirty hack wainting that foreign key account_parent is an integer to be compared correctly with rowid -if ($db->type == 'pgsql') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = CAST(aa.account_parent AS INTEGER)"; -else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = CAST(aa.account_parent AS UNSIGNED)"; +if ($db->type == 'pgsql') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent"; +else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent"; $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_accountparent))) $sql .= natural_search("aa.account_parent", $search_accountparent); @@ -256,7 +255,7 @@ if ($resql) else dol_print_error($db); print ""; print ajax_combobox("chartofaccounts"); - print ''; + print ''; print '
'; print '
'; @@ -275,7 +274,7 @@ if ($resql) if (! empty($arrayfields['aa.pcg_type']['checked'])) print ''; if (! empty($arrayfields['aa.pcg_subtype']['checked'])) print ''; if (! empty($arrayfields['aa.active']['checked'])) print ' '; - print ''; + print ''; $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpicto; print ''; @@ -309,7 +308,7 @@ if ($resql) if (! empty($arrayfields['aa.account_number']['checked'])) { print ""; - print $accountstatic->getNomUrl(1); + print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1); print "\n"; if (! $i) $totalarray['nbfield']++; } diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 82ba00a882c..61166f88d07 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -188,12 +188,10 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount) } } + /* * View */ -$title = $langs->trans('AccountAccounting') ." - ". $langs->trans('Card'); -$helpurl = ''; -llxheader('', $title, $helpurl); $form = new Form($db); $formaccounting = new FormAccounting($db); @@ -201,6 +199,11 @@ $formaccounting = new FormAccounting($db); $accountsystem = new AccountancySystem($db); $accountsystem->fetch($conf->global->CHARTOFACCOUNTS); +$title = $langs->trans('AccountAccounting') ." - ". $langs->trans('Card'); +$helpurl = ''; +llxheader('', $title, $helpurl); + + // Create mode if ($action == 'create') { print load_fiche_titre($langs->trans('NewAccountingAccount')); @@ -330,7 +333,7 @@ else if ($id > 0 || $ref) { print ''; } else { // View mode - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), -1, 'billr'); diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 6b7e925832b..0b0d42b0075 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -384,14 +384,15 @@ class AccountingAccount extends CommonObject /** * Return clicable name (with picto eventually) * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $withlabel 0=No label, 1=Include label of account - * @param int $nourl 1=Disable url - * @param string $moretitle Add more text to title tooltip - * @param int $notooltip 1=Disable tooltip + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $withlabel 0=No label, 1=Include label of account + * @param int $nourl 1=Disable url + * @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 * @return string String with URL */ - function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0) + function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0, $save_lastsearch_value=-1) { global $langs, $conf, $user; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; @@ -402,6 +403,11 @@ class AccountingAccount extends CommonObject $url = DOL_URL_ROOT . '/accountancy/admin/card.php?id=' . $this->id; + // 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 = 'billr'; $label=''; diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 2024a6b68e2..880bd4e7ca2 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -406,3 +406,8 @@ create table llx_asset_type_extrafields ALTER TABLE llx_asset_type_extrafields ADD INDEX idx_asset_type_extrafields (fk_object); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (7,'INV', 'Inventory journal', 8, 1); + +UPDATE llx_accounting_account set account_parent = 0 WHERE account_parent = '' OR account_parent IS NULL; +ALTER TABLE llx_accounting_account MODIFY COLUMN account_parent integer DEFAULT 0; +ALTER TABLE llx_accounting_account ADD INDEX idx_accounting_account_account_parent (account_parent); + diff --git a/htdocs/install/mysql/tables/llx_accounting_account.key.sql b/htdocs/install/mysql/tables/llx_accounting_account.key.sql index 19a6c95447a..cf62da87daa 100644 --- a/htdocs/install/mysql/tables/llx_accounting_account.key.sql +++ b/htdocs/install/mysql/tables/llx_accounting_account.key.sql @@ -19,6 +19,7 @@ ALTER TABLE llx_accounting_account ADD INDEX idx_accounting_account_fk_pcg_version (fk_pcg_version); +ALTER TABLE llx_accounting_account ADD INDEX idx_accounting_account_account_parent (account_parent); ALTER TABLE llx_accounting_account ADD UNIQUE INDEX uk_accounting_account (account_number, entity, fk_pcg_version); diff --git a/htdocs/install/mysql/tables/llx_accounting_account.sql b/htdocs/install/mysql/tables/llx_accounting_account.sql index aa82664f931..79215115cfb 100644 --- a/htdocs/install/mysql/tables/llx_accounting_account.sql +++ b/htdocs/install/mysql/tables/llx_accounting_account.sql @@ -29,7 +29,7 @@ create table llx_accounting_account pcg_type varchar(20) NOT NULL, -- First part of Key for predefined groups pcg_subtype varchar(20) NOT NULL, -- Second part of Key for predefined groups account_number varchar(32) NOT NULL, - account_parent varchar(32) DEFAULT '0', -- Hierarchic parent. TODO Move this as integer, it is a foreign key of llx_accounting_account.rowid + account_parent integer DEFAULT 0, -- Hierarchic parent. label varchar(255) NOT NULL, fk_accounting_category integer DEFAULT 0, -- ID of personalized group for report fk_user_author integer DEFAULT NULL,