From c06aedc54da2dadd3d01e8dd3c5200ea847ed8c3 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 15 Feb 2017 20:55:52 +0100 Subject: [PATCH 1/4] [FP17] : Add data in llx_accountancy_journal --- htdocs/install/mysql/data/llx_accounting.sql | 8 +++++++- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 6 ++++++ htdocs/install/mysql/tables/llx_accounting_journal.sql | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/data/llx_accounting.sql b/htdocs/install/mysql/data/llx_accounting.sql index 149d7fea394..dc7aeb27bef 100644 --- a/htdocs/install/mysql/data/llx_accounting.sql +++ b/htdocs/install/mysql/data/llx_accounting.sql @@ -5,7 +5,7 @@ -- Copyright (C) 2004 Guillaume Delecourt -- Copyright (C) 2005-2009 Regis Houssin -- Copyright (C) 2007 Patrick Raguin --- Copyright (C) 2011-2016 Alexandre Spangaro +-- Copyright (C) 2011-2017 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 @@ -29,7 +29,13 @@ delete from llx_accounting_account; delete from llx_accounting_system; +delete from llx_accounting_journal; +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (1,'VT', 'Journal des ventes', 1, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (2,'AC', 'Journal des achats', 2, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (3,'BQ', 'Journal de banque', 3, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 4, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (5,'AN', 'Journal des à-nouveaux', 9, 1); -- -- Descriptif des plans comptables FR PCG99-ABREGE -- diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index aa755daa09a..0d47261503c 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -98,3 +98,9 @@ CREATE TABLE llx_product_attribute_combination entity INT DEFAULT 1 NOT NULL ); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (1,'VT', 'Journal des ventes', 1, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (2,'AC', 'Journal des achats', 2, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (3,'BQ', 'Journal de banque', 3, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 4, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (5,'AN', 'Journal des à-nouveaux', 9, 1); + diff --git a/htdocs/install/mysql/tables/llx_accounting_journal.sql b/htdocs/install/mysql/tables/llx_accounting_journal.sql index bc514f0ed9b..f3ee2a2e010 100644 --- a/htdocs/install/mysql/tables/llx_accounting_journal.sql +++ b/htdocs/install/mysql/tables/llx_accounting_journal.sql @@ -1,5 +1,5 @@ -- ============================================================================ --- Copyright (C) 2016 Alexandre Spangaro +-- Copyright (C) 2016-2017 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 @@ -22,6 +22,6 @@ create table llx_accounting_journal rowid integer AUTO_INCREMENT PRIMARY KEY, code varchar(32) NOT NULL, label varchar(128) NOT NULL, - nature smallint DEFAULT 0 NOT NULL, -- type of journals (Sale / purchase / bank / various operations) + nature smallint DEFAULT 0 NOT NULL, -- type of journals (1:Sale / 2:purchase / 3:bank / 4:various operations / 9: has-new) active smallint DEFAULT 0 )ENGINE=innodb; From 1401e9267b5ec5a9554e2cb08f1d22b15847c9d3 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 21 Feb 2017 07:09:58 +0100 Subject: [PATCH 2/4] [FP17] Modify menu for multijournal --- htdocs/core/menus/standard/eldy.lib.php | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index e16e6601940..5f2a5f5def6 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -993,6 +993,37 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('',$langs->trans("Journalization"),1,$user->rights->accounting->comptarapport->lire); + // Multi journal + $sql = "SELECT rowid, code, label, nature"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + // $sql.= " WHERE entity = ".$conf->entity; + $sql.= " ORDER BY code"; + + $resql = $db->query($sql); + if ($resql) + { + $numr = $db->num_rows($resql); + $i = 0; + + if ($numr > 0) + while ($i < $numr) + { + $objp = $db->fetch_object($resql); + + if ($objp->nature == 1) $nature="sells"; + if ($objp->nature == 2) $nature="purchases"; + if ($objp->nature == 3) $nature="bank"; + if ($objp->nature == 4) $nature="various"; + if ($objp->nature == 9) $nature="hasnew"; + + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&code_journal='.$objp->code,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire); + $i++; + } + } + else dol_print_error($db); + $db->free($resql); + + /* $sql = "SELECT rowid, label, accountancy_journal"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE entity = ".$conf->entity; @@ -1020,6 +1051,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/journal/sellsjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal",$langs->trans("SellsJournal"),2,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/journal/purchasesjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal",$langs->trans("PurchasesJournal"),2,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/journal/expensereportsjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal",$langs->trans("ExpenseReportsJournal"),2,$user->rights->accounting->comptarapport->lire); + */ } // General Ledger From fc2b9a858b0e518b4088698c08b30faddbdd665c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 28 Mar 2017 06:35:03 +0200 Subject: [PATCH 3/4] New : [FP17] Add multijournals in accountancy admin --- htdocs/accountancy/admin/journals.php | 170 ++++++ htdocs/accountancy/admin/journals_card.php | 296 ++++++++++ .../class/accountingjournal.class.php | 525 ++++++++++++++++++ htdocs/core/lib/accounting.lib.php | 4 +- htdocs/install/mysql/data/llx_accounting.sql | 2 +- .../install/mysql/migration/5.0.0-6.0.0.sql | 3 +- .../mysql/tables/llx_accounting_journal.sql | 2 +- htdocs/langs/en_US/accountancy.lang | 8 + 8 files changed, 1004 insertions(+), 6 deletions(-) create mode 100644 htdocs/accountancy/admin/journals.php create mode 100644 htdocs/accountancy/admin/journals_card.php create mode 100644 htdocs/accountancy/class/accountingjournal.class.php diff --git a/htdocs/accountancy/admin/journals.php b/htdocs/accountancy/admin/journals.php new file mode 100644 index 00000000000..72f81dc90ba --- /dev/null +++ b/htdocs/accountancy/admin/journals.php @@ -0,0 +1,170 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * \file htdocs/accountancy/admin/journals.php + * \ingroup Advanced accountancy + * \brief Setup page to configure journals + */ +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; + +$action = GETPOST('action'); + +// Load variable for pagination +$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if ($page == -1) { $page = 0; } +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortfield) $sortfield="j.rowid"; // Set here default search field +if (! $sortorder) $sortorder="ASC"; + +$langs->load("admin"); +$langs->load("compta"); +$langs->load("accountancy"); + +// Security check +if ($user->societe_id > 0) + accessforbidden(); +if (! $user->rights->accounting->fiscalyear) // If we can read accounting records, we shoul be able to see fiscal year. + accessforbidden(); + +$error = 0; + +// List of status +/* +static $tmptype2label = array ( + '0' => 'AccountingJournalTypeVariousOperation', + '1' => 'AccountingJournalTypeSale', + '2' => 'AccountingJournalTypePurchase', + '3' => 'AccountingJournalTypeBank', + '9' => 'AccountingJournalTypeHasNew' +); +$type2label = array ( + '' +); +foreach ( $tmptype2label as $key => $val ) + $type2label[$key] = $langs->trans($val); +*/ + +$errors = array (); + +$object = new AccountingJournal($db); + + +/* + * Actions + */ + + + +/* + * View + */ +$title = $langs->trans('AccountingJournals'); +$helpurl = ""; +llxHeader('', $title, $helpurl); + +$max = 100; +$form = new Form($db); + +$linkback = '' . $langs->trans("BackToModuleList") . ''; +print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup'); + +$head = admin_accounting_prepare_head(null); + +dol_fiche_head($head, 'journal', $langs->trans("Configuration"), 0, 'cron'); + +$sql = "SELECT j.rowid, j.code, j.label, j.nature, j.active"; +$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_journal as j"; +// $sql .= " WHERE j.entity = " . $conf->entity; +$sql.=$db->order($sortfield,$sortorder); + +// Count total nb of records +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); +} + +$sql.= $db->plimit($limit+1, $offset); + +$result = $db->query($sql); +if ($result) { + $var = false; + $num = $db->num_rows($result); + + $i = 0; + + // $title = $langs->trans('AccountingJournals'); + // print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 1); + + // Load attribute_label + print ''; + print ''; + // print ''; + print ''; + print ''; + print ''; + print ''; + + if ($num) { + $accountingjournalstatic = new AccountingJournal($db); + + while ( $i < $num && $i < $max ) { + $obj = $db->fetch_object($result); + $accountingjournalstatic->id = $obj->rowid; + print ''; + print ''; + print ''; + print ''; + print ''; + $var = ! $var; + $i ++; + } + } else { + print ''; + } + print '
' . $langs->trans("Ref") . '' . $langs->trans("Code") . '' . $langs->trans("Label") . '' . $langs->trans("Nature") . '
' . img_object($langs->trans("ShowJournal"), "technic") . ' ' . $obj->code . '' . $obj->label . '' . $accountingjournalstatic->LibType($obj->nature, 0) . '
' . $langs->trans("None") . '
'; +} else { + dol_print_error($db); +} + +dol_fiche_end(); + +// Buttons +print '
'; +if (! empty($user->rights->accounting->fiscalyear)) +{ + print '' . $langs->trans("NewAccountingJournal") . ''; +} +else +{ + print '' . $langs->trans("NewAccountingJournal") . ''; +} +print '
'; + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/admin/journals_card.php b/htdocs/accountancy/admin/journals_card.php new file mode 100644 index 00000000000..c9c45f9a4e5 --- /dev/null +++ b/htdocs/accountancy/admin/journals_card.php @@ -0,0 +1,296 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/accountancy/admin/journals_card.php + * \ingroup Advanced accountancy + * \brief Page to show an accounting journal + */ +require '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; + +$langs->load("admin"); +$langs->load("compta"); +$langs->load("accountancy"); + +// Security check +if ($user->societe_id > 0) + accessforbidden(); +if (empty($user->rights->accounting->fiscalyear)) + accessforbidden(); + +$error = 0; + +$action = GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); +$id = GETPOST('id', 'int'); + +// List of status +static $tmptype2label = array ( + '0' => 'AccountingJournalTypeVariousOperation', + '1' => 'AccountingJournalTypeSale', + '2' => 'AccountingJournalTypePurchase', + '3' => 'AccountingJournalTypeBank', + '9' => 'AccountingJournalTypeHasNew' +); +$type2label = array ( + '' +); +foreach ( $tmptype2label as $key => $val ) + $type2label[$key] = $langs->trans($val); + +$object = new AccountingJournal($db); + +/* + * Actions + */ + +if ($action == 'confirm_delete' && $confirm == "yes") { + $result = $object->delete($id); + if ($result >= 0) { + header("Location: journals.php"); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +else if ($action == 'add') { + if (! GETPOST('cancel', 'alpha')) { + $error = 0; + + $object->code = GETPOST('code', 'alpha'); + $object->label = GETPOST('label', 'alpha'); + $object->nature = GETPOST('nature', 'int'); + + if (empty($object->code)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Code")), null, 'errors'); + $error ++; + } + if (empty($object->label)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + $error ++; + } + + if (! $error) { + $db->begin(); + + $id = $object->create($user); + + if ($id > 0) { + $db->commit(); + + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit(); + } else { + $db->rollback(); + + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } else { + $action = 'create'; + } + } else { + header("Location: ./journals.php"); + exit(); + } +} + +// Update record +else if ($action == 'update') { + if (! GETPOST('cancel', 'alpha')) { + $result = $object->fetch($id); + + $object->code = GETPOST('code', 'alpha'); + $object->label = GETPOST('label', 'alpha'); + $object->nature = GETPOST('nature', 'int'); + + $result = $object->update($user); + + if ($result > 0) { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit(); + } +} + + + +/* + * View + */ + +$title = $langs->trans("Journal") . " - " . $langs->trans("Card"); +$helpurl = ""; +llxHeader("",$title,$helpurl); + +$form = new Form($db); + +if ($action == 'create') +{ + print load_fiche_titre($langs->trans("NewAccountingJournal")); + + print '
'; + print ''; + print ''; + + dol_fiche_head(); + + print ''; + + // Code + print ''; + + + // Label + print ''; + + // Nature + print ''; + print ''; + print ''; + + print '
' . $langs->trans("Code") . '
' . $langs->trans("Label") . '
' . $langs->trans("Status") . ''; + print $form->selectarray('nature', $type2label, GETPOST('nature')); + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print '
'; +} else if ($id) { + $result = $object->fetch($id); + if ($result > 0) { + $head = fiscalyear_prepare_head($object); + + if ($action == 'edit') { + dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + + print '
' . "\n"; + print ''; + print ''; + print ''; + + print ''; + + // Ref + print ""; + print ''; + + // Label + print ''; + + // Date start + print ''; + + // Date end + print ''; + + // Nature + print ''; + + print '
' . $langs->trans("Ref") . ''; + print $object->ref; + print '
' . $langs->trans("Label") . ''; + print ''; + print '
' . $langs->trans("DateStart") . ''; + print $form->select_date($object->date_start ? $object->date_start : - 1, 'fiscalyear'); + print '
' . $langs->trans("DateEnd") . ''; + print $form->select_date($object->date_end ? $object->date_end : - 1, 'fiscalyearend'); + print '
' . $langs->trans("Type") . ''; + // print $form->selectarray('statut', $statut2label, $object->statut); + print $object->getLibStatut(4); + print '
'; + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print '
'; + + dol_fiche_end(); + } else { + /* + * Confirm delete + */ + if ($action == 'delete') { + print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete"); + } + + dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + + print ''; + + $linkback = '' . $langs->trans("BackToList") . ''; + + // Ref + print ''; + + // Label + print '"; + + // Nature + print ''; + + print "
' . $langs->trans("Ref") . ''; + print $object->ref; + print ''; + print $linkback; + print '
'; + print $form->editfieldkey("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32'); + print ''; + print $form->editfieldval("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32'); + print "
' . $langs->trans("Type") . '' . $object->getLibType(0) . '
"; + + dol_fiche_end(); + + if (! empty($user->rights->accounting->fiscalyear)) + { + /* + * Barre d'actions + */ + print '
'; + + print '' . $langs->trans('Modify') . ''; + + // print '' . $langs->trans('Delete') . ''; + + print '
'; + } + } + } else { + dol_print_error($db); + } +} + +llxFooter(); +$db->close(); diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php new file mode 100644 index 00000000000..7b34c4171d8 --- /dev/null +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -0,0 +1,525 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/accountancy/class/accountingjournal.class.php + * \ingroup Advanced accountancy + * \brief File of class to manage accounting journals + */ + +/** + * Class to manage accounting accounts + */ +class AccountingJournal extends CommonObject +{ + var $db; + var $error; + var $errors; + var $id; + var $rowid; + var $datec; // Creation date + var $fk_pcg_version; + var $pcg_type; + var $pcg_subtype; + var $account_number; + var $account_parent; + var $account_category; + var $label; + var $fk_user_author; + var $fk_user_modif; + var $active; // duplicate with status + var $status; + + /** + * Constructor + * + * @param DoliDB $db Database handle + */ + function __construct($db) { + $this->db = $db; + } + + /** + * Load record in memory + * + * @param int $rowid Id + * @param string $account_number Account number + * @param int $limittocurrentchart 1=Do not load record if it is into another accounting system + * @return int <0 if KO, Id of record if OK and found + */ + function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) { + 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 .= ", 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"; + $sql .= " WHERE"; + if ($rowid) { + $sql .= " a.rowid = '" . $rowid . "'"; + } elseif ($account_number) { + $sql .= " a.account_number = '" . $account_number . "'"; + } + if (! empty($limittocurrentchart)) { + $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; + } + + dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $obj = $this->db->fetch_object($result); + + if ($obj) { + $this->id = $obj->rowid; + $this->rowid = $obj->rowid; + $this->datec = $obj->datec; + $this->tms = $obj->tms; + $this->fk_pcg_version = $obj->fk_pcg_version; + $this->pcg_type = $obj->pcg_type; + $this->pcg_subtype = $obj->pcg_subtype; + $this->account_number = $obj->account_number; + $this->account_parent = $obj->account_parent; + $this->label = $obj->label; + $this->account_category = $obj->fk_accounting_category; + $this->account_category_label = $obj->category_label; + $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_modif = $obj->fk_user_modif; + $this->active = $obj->active; + $this->status = $obj->active; + + return $this->id; + } else { + return 0; + } + } else { + $this->error = "Error " . $this->db->lasterror(); + $this->errors[] = "Error " . $this->db->lasterror(); + } + } + return - 1; + } + + /** + * Insert new accounting account in chart of accounts + * + * @param User $user Use making action + * @param int $notrigger Disable triggers + * @return int <0 if KO, >0 if OK + */ + function create($user, $notrigger = 0) { + global $conf; + $error = 0; + $now = dol_now(); + + // Clean parameters + if (isset($this->fk_pcg_version)) + $this->fk_pcg_version = trim($this->fk_pcg_version); + if (isset($this->pcg_type)) + $this->pcg_type = trim($this->pcg_type); + if (isset($this->pcg_subtype)) + $this->pcg_subtype = trim($this->pcg_subtype); + if (isset($this->account_number)) + $this->account_number = trim($this->account_number); + if (isset($this->account_parent)) + $this->account_parent = trim($this->account_parent); + if (isset($this->label)) + $this->label = trim($this->label); + if (isset($this->account_category)) + $this->account_category = trim($this->account_category); + if (isset($this->fk_user_author)) + $this->fk_user_author = trim($this->fk_user_author); + if (isset($this->active)) + $this->active = trim($this->active); + + if (empty($this->pcg_type) || $this->pcg_type == '-1') + { + $this->pcg_type = 'XXXXXX'; + } + if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') + { + $this->pcg_subtype = 'XXXXXX'; + } + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; + $sql .= "datec"; + $sql .= ", entity"; + $sql .= ", fk_pcg_version"; + $sql .= ", pcg_type"; + $sql .= ", pcg_subtype"; + $sql .= ", account_number"; + $sql .= ", account_parent"; + $sql .= ", label"; + $sql .= ", fk_accounting_category"; + $sql .= ", fk_user_author"; + $sql .= ", active"; + $sql .= ") VALUES ("; + $sql .= " '" . $this->db->idate($now) . "'"; + $sql .= ", " . $conf->entity; + $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'"); + $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'"); + $sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->pcg_subtype . "'"); + $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->account_number . "'"); + $sql .= ", " . (empty($this->account_parent) ? 'NULL' : "'" . $this->db->escape($this->account_parent) . "'"); + $sql .= ", " . (empty($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'"); + $sql .= ", " . (empty($this->account_category) ? 'NULL' : "'" . $this->db->escape($this->account_category) . "'"); + $sql .= ", " . $user->id; + $sql .= ", " . (! isset($this->active) ? 'NULL' : $this->db->escape($this->active)); + $sql .= ")"; + + $this->db->begin(); + + dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = "Error " . $this->db->lasterror(); + } + + if (! $error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account"); + + // if (! $notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + // // Call triggers + // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + // $interface=new Interfaces($this->db); + // $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + // if ($result < 0) { $error++; $this->errors=$interface->errors; } + // // End call triggers + // } + } + + // Commit or rollback + if ($error) { + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + $this->db->rollback(); + return - 1 * $error; + } else { + $this->db->commit(); + return $this->id; + } + } + + /** + * Update record + * + * @param User $user Use making update + * @return int <0 if KO, >0 if OK + */ + function update($user) + { + // Check parameters + if (empty($this->pcg_type) || $this->pcg_type == '-1') + { + $this->pcg_type = 'XXXXXX'; + } + if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') + { + $this->pcg_subtype = 'XXXXXX'; + } + + $this->db->begin(); + + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); + $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); + $sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null"); + $sql .= " , account_number = '" . $this->account_number . "'"; + $sql .= " , account_parent = '" . $this->account_parent . "'"; + $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null"); + $sql .= " , fk_accounting_category = '" . $this->account_category . "'"; + $sql .= " , fk_user_modif = " . $user->id; + $sql .= " , active = '" . $this->active . "'"; + $sql .= " WHERE rowid = " . $this->id; + + dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $this->db->commit(); + return 1; + } else { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return - 1; + } + } + + /** + * Check usage of accounting code + * + * @return int <0 if KO, >0 if OK + */ + function checkUsage() { + global $langs; + + $sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet"; + $sql .= " WHERE fk_code_ventilation=" . $this->id . ")"; + $sql .= "UNION"; + $sql .= "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det"; + $sql .= " WHERE fk_code_ventilation=" . $this->id . ")"; + + dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + + if ($resql) { + $num = $this->db->num_rows($resql); + if ($num > 0) { + $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse'); + return 0; + } else { + return 1; + } + } else { + $this->error = $this->db->lasterror(); + return - 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $notrigger 0=triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger = 0) { + $error = 0; + + $result = $this->checkUsage(); + + if ($result > 0) { + + $this->db->begin(); + + // if (! $error) { + // if (! $notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + // // Call triggers + // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + // $interface=new Interfaces($this->db); + // $result=$interface->run_triggers('ACCOUNTANCY_ACCOUNT_DELETE',$this,$user,$langs,$conf); + // if ($result < 0) { $error++; $this->errors=$interface->errors; } + // // End call triggers + // } + // } + + if (! $error) { + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account"; + $sql .= " WHERE rowid=" . $this->id; + + dol_syslog(get_class($this) . "::delete sql=" . $sql); + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = "Error " . $this->db->lasterror(); + } + } + + // Commit or rollback + if ($error) { + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + $this->db->rollback(); + return - 1 * $error; + } else { + $this->db->commit(); + return 1; + } + } else { + return - 1; + } + } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @return string Chaine avec URL + */ + function getNomUrl($withpicto = 0) { + global $langs; + + $result = ''; + + $link = ''; + $linkend = ''; + + $picto = 'billr'; + + $label = $langs->trans("Show") . ': ' . $this->account_number . ' - ' . $this->label; + + if ($withpicto) + $result .= ($link . img_object($label, $picto) . $linkend); + if ($withpicto && $withpicto != 2) + $result .= ' '; + if ($withpicto != 2) + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $result .= $link . length_accountg($this->account_number) . ' - ' . $this->label . $linkend; + return $result; + } + + /** + * Information on record + * + * @param int $id of record + * @return void + */ + function info($id) { + $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a'; + $sql .= ' WHERE a.rowid = ' . $id; + + dol_syslog(get_class($this) . '::info sql=' . $sql); + $result = $this->db->query($sql); + + if ($result) { + if ($this->db->num_rows($result)) { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_modif) { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->tms); + } + $this->db->free($result); + } else { + dol_print_error($this->db); + } + } + + /** + * Account desactivate + * + * @param int $id Id + * @return int <0 if KO, >0 if OK + */ + function account_desactivate($id) { + $result = $this->checkUsage(); + + if ($result > 0) { + $this->db->begin(); + + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql .= "SET active = '0'"; + $sql .= " WHERE rowid = " . $this->db->escape($id); + + dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) { + $this->db->commit(); + return 1; + } else { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return - 1; + } + } else { + return - 1; + } + } + + /** + * Account activate + * + * @param int $id Id + * @return int <0 if KO, >0 if OK + */ + function account_activate($id) { + $this->db->begin(); + + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql .= "SET active = '1'"; + $sql .= " WHERE rowid = " . $this->db->escape($id); + + dol_syslog(get_class($this) . "::activate sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $this->db->commit(); + return 1; + } else { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return - 1; + } + } + + + /** + * Retourne le libelle du statut d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court + * @return string Label of type + */ + function getLibType($mode=0) + { + return $this->LibType($this->nature,$mode); + } + + /** + * Return type of an accounting journal + * + * @param int $nature Id type + * @param int $mode 0=libelle long, 1=libelle court + * @return string Label of type + */ + function LibType($nature,$mode=0) + { + global $langs; + + $langs->load("accountancy"); + + if ($mode == 0) + { + $prefix=''; + if ($nature == 9) return $langs->trans('AccountingJournalTypeHasNew'); + if ($nature == 3) return $langs->trans('AccountingJournalTypeBank'); + if ($nature == 2) return $langs->trans('AccountingJournalTypePurchase'); + if ($nature == 1) return $langs->trans('AccountingJournalTypeSale'); + if ($nature == 0) return $langs->trans('AccountingJournalTypeVariousOperation'); + } + if ($mode == 1) + { + if ($nature == 9) return $langs->trans('AccountingJournalTypeHasNew'); + if ($nature == 3) return $langs->trans('AccountingJournalTypeBank'); + if ($nature == 2) return $langs->trans('AccountingJournalTypePurchase'); + if ($nature == 1) return $langs->trans('AccountingJournalTypeSale'); + if ($nature == 0) return $langs->trans('AccountingJournalTypeVariousOperation'); + } + } +} diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 8ec0713b01a..205acb9ba80 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -41,7 +41,7 @@ function admin_accounting_prepare_head(AccountingAccount $object=null) $head[$h][2] = 'general'; $h ++; - $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journal.php'; + $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journals.php'; $head[$h][1] = $langs->trans("Journaux"); $head[$h][2] = 'journal'; $h ++; diff --git a/htdocs/install/mysql/data/llx_accounting.sql b/htdocs/install/mysql/data/llx_accounting.sql index 1db22e7408d..5f0e8dd5416 100644 --- a/htdocs/install/mysql/data/llx_accounting.sql +++ b/htdocs/install/mysql/data/llx_accounting.sql @@ -34,7 +34,7 @@ delete from llx_accounting_journal; INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (1,'VT', 'Journal des ventes', 1, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (2,'AC', 'Journal des achats', 2, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (3,'BQ', 'Journal de banque', 3, 1); -INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 4, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 0, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (5,'AN', 'Journal des à-nouveaux', 9, 1); -- -- Descriptif des plans comptables FR PCG99-ABREGE diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 18683f71638..1ce53af43fe 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -101,7 +101,7 @@ CREATE TABLE llx_product_attribute_combination INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (1,'VT', 'Journal des ventes', 1, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (2,'AC', 'Journal des achats', 2, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (3,'BQ', 'Journal de banque', 3, 1); -INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 4, 1); +INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 0, 1); INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (5,'AN', 'Journal des à-nouveaux', 9, 1); ALTER TABLE llx_paiementfourn ADD COLUMN model_pdf varchar(255); @@ -150,4 +150,3 @@ create table llx_payment_various fk_user_author integer, fk_user_modif integer )ENGINE=innodb; ->>>>>>> uptream/develop diff --git a/htdocs/install/mysql/tables/llx_accounting_journal.sql b/htdocs/install/mysql/tables/llx_accounting_journal.sql index f3ee2a2e010..d9c6ea76e3e 100644 --- a/htdocs/install/mysql/tables/llx_accounting_journal.sql +++ b/htdocs/install/mysql/tables/llx_accounting_journal.sql @@ -22,6 +22,6 @@ create table llx_accounting_journal rowid integer AUTO_INCREMENT PRIMARY KEY, code varchar(32) NOT NULL, label varchar(128) NOT NULL, - nature smallint DEFAULT 0 NOT NULL, -- type of journals (1:Sale / 2:purchase / 3:bank / 4:various operations / 9: has-new) + nature smallint DEFAULT 0 NOT NULL, -- type of journals (0:various operations / 1:sale / 2:purchase / 3:bank / 9: has-new) active smallint DEFAULT 0 )ENGINE=innodb; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index d8313e2a11b..f35b61055ad 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -198,6 +198,14 @@ ChangeBinding=Change the binding ApplyMassCategories=Apply mass categories AddAccountFromBookKeepingWithNoCategories=Add acccount already used with no categories CategoryDeleted=Category for the accounting account has been removed +AccountingJournals=Accounting journals +NewAccountingJournal=New accounting journal +ShowAccoutingJournal=Show accounting journal +AccountingJournalTypeVariousOperation=Various operation +AccountingJournalTypeSale=Sale +AccountingJournalTypePurchase=Purchase +AccountingJournalTypeBank=Bank +AccountingJournalTypeHasNew=Has-new ## Export Exports=Exports From 06c2f049270d69f00f1917590593d6e3f63656b1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 29 Mar 2017 06:32:26 +0200 Subject: [PATCH 4/4] Finish work on multijournal admin part Need harmonization on rights --- htdocs/accountancy/admin/journals_card.php | 54 ++-- .../class/accountingjournal.class.php | 273 ++++++------------ htdocs/core/lib/accounting.lib.php | 29 ++ htdocs/langs/en_US/accountancy.lang | 4 + 4 files changed, 140 insertions(+), 220 deletions(-) diff --git a/htdocs/accountancy/admin/journals_card.php b/htdocs/accountancy/admin/journals_card.php index c9c45f9a4e5..9e04d75ce9f 100644 --- a/htdocs/accountancy/admin/journals_card.php +++ b/htdocs/accountancy/admin/journals_card.php @@ -122,6 +122,15 @@ else if ($action == 'update') { $object->label = GETPOST('label', 'alpha'); $object->nature = GETPOST('nature', 'int'); + if (empty($object->code)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Code")), null, 'errors'); + $error ++; + } + if (empty($object->label)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + $error ++; + } + $result = $object->update($user); if ($result > 0) { @@ -161,15 +170,15 @@ if ($action == 'create') print ''; // Code - print ''; + print ''; // Label - print ''; + print ''; // Nature print ''; - print ''; + print ''; print ''; @@ -188,10 +197,10 @@ if ($action == 'create') } else if ($id) { $result = $object->fetch($id); if ($result > 0) { - $head = fiscalyear_prepare_head($object); + $head = accounting_journal_prepare_head($object); if ($action == 'edit') { - dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + dol_fiche_head($head, 'card', $langs->trans("AccountingJournal"), 0, 'cron'); print '' . "\n"; print ''; @@ -200,10 +209,10 @@ if ($action == 'create') print '
' . $langs->trans("Code") . '
' . $langs->trans("Code") . '
' . $langs->trans("Label") . '
' . $langs->trans("Label") . '
' . $langs->trans("Status") . '' . $langs->trans("Type") . ''; print $form->selectarray('nature', $type2label, GETPOST('nature')); print '
'; - // Ref + // Code print ""; - print ''; // Label @@ -211,20 +220,9 @@ if ($action == 'create') print ''; print ''; - // Date start - print ''; - - // Date end - print ''; - // Nature print ''; print '
' . $langs->trans("Ref") . ''; - print $object->ref; + print '' . $langs->trans("Code") . ''; + print ''; print '
' . $langs->trans("DateStart") . ''; - print $form->select_date($object->date_start ? $object->date_start : - 1, 'fiscalyear'); - print '
' . $langs->trans("DateEnd") . ''; - print $form->select_date($object->date_end ? $object->date_end : - 1, 'fiscalyearend'); - print '
' . $langs->trans("Type") . ''; - // print $form->selectarray('statut', $statut2label, $object->statut); - print $object->getLibStatut(4); + print $form->selectarray('nature', $type2label, $object->nature); print '
'; @@ -246,15 +244,15 @@ if ($action == 'create') print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete"); } - dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron'); + dol_fiche_head($head, 'card', $langs->trans("AccountingJournal"), 0, 'cron'); print ''; - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; // Ref - print ''; @@ -267,7 +265,7 @@ if ($action == 'create') print ""; // Nature - print ''; + print ''; print "
' . $langs->trans("Ref") . ''; - print $object->ref; + print '
' . $langs->trans("Code") . ''; + print $object->code; print ''; print $linkback; print '
' . $langs->trans("Type") . '' . $object->getLibType(0) . '
' . $langs->trans("Type") . '' . $object->getLibType(0) . '
"; @@ -281,9 +279,9 @@ if ($action == 'create') print ''; } } diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 7b34c4171d8..d7cc61d6418 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -26,24 +26,18 @@ */ class AccountingJournal extends CommonObject { - var $db; - var $error; - var $errors; - var $id; + public $element='accounting_journal'; + public $table_element='accounting_journal'; + public $fk_element = ''; + protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + var $rowid; - var $datec; // Creation date - var $fk_pcg_version; - var $pcg_type; - var $pcg_subtype; - var $account_number; - var $account_parent; - var $account_category; + + var $code; var $label; - var $fk_user_author; - var $fk_user_modif; - var $active; // duplicate with status - var $status; - + var $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 9: has-new + var $active; + /** * Constructor * @@ -54,133 +48,75 @@ class AccountingJournal extends CommonObject } /** - * Load record in memory - * - * @param int $rowid Id - * @param string $account_number Account number - * @param int $limittocurrentchart 1=Do not load record if it is into another accounting system - * @return int <0 if KO, Id of record if OK and found - */ - function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) { - 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 .= ", 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"; - $sql .= " WHERE"; - if ($rowid) { - $sql .= " a.rowid = '" . $rowid . "'"; - } elseif ($account_number) { - $sql .= " a.account_number = '" . $account_number . "'"; - } - if (! empty($limittocurrentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - } + * Load an object from database + * + * @param int $id Id of record to load + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + $sql = "SELECT rowid, code, label, nature, active"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + $sql.= " WHERE rowid = ".$id; - dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $obj = $this->db->fetch_object($result); - - if ($obj) { - $this->id = $obj->rowid; - $this->rowid = $obj->rowid; - $this->datec = $obj->datec; - $this->tms = $obj->tms; - $this->fk_pcg_version = $obj->fk_pcg_version; - $this->pcg_type = $obj->pcg_type; - $this->pcg_subtype = $obj->pcg_subtype; - $this->account_number = $obj->account_number; - $this->account_parent = $obj->account_parent; - $this->label = $obj->label; - $this->account_category = $obj->fk_accounting_category; - $this->account_category_label = $obj->category_label; - $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_modif = $obj->fk_user_modif; - $this->active = $obj->active; - $this->status = $obj->active; - - return $this->id; - } else { - return 0; - } - } else { - $this->error = "Error " . $this->db->lasterror(); - $this->errors[] = "Error " . $this->db->lasterror(); - } + dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ( $result ) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + + $this->code = $obj->code; + $this->ref = $obj->code; + $this->label = $obj->label; + $this->nature = $obj->nature; + $this->active = $obj->active; + + return 1; + } + else + { + $this->error=$this->db->lasterror(); + return -1; } - return - 1; } /** - * Insert new accounting account in chart of accounts + * Insert journal in database * - * @param User $user Use making action - * @param int $notrigger Disable triggers - * @return int <0 if KO, >0 if OK + * @param User $user Use making action + * @param int $notrigger Disable triggers + * @return int <0 if KO, >0 if OK */ - function create($user, $notrigger = 0) { + function create($user, $notrigger = 0) + { global $conf; $error = 0; $now = dol_now(); // Clean parameters - if (isset($this->fk_pcg_version)) - $this->fk_pcg_version = trim($this->fk_pcg_version); - if (isset($this->pcg_type)) - $this->pcg_type = trim($this->pcg_type); - if (isset($this->pcg_subtype)) - $this->pcg_subtype = trim($this->pcg_subtype); - if (isset($this->account_number)) - $this->account_number = trim($this->account_number); - if (isset($this->account_parent)) - $this->account_parent = trim($this->account_parent); + if (isset($this->code)) + $this->code = trim($this->code); if (isset($this->label)) $this->label = trim($this->label); - if (isset($this->account_category)) - $this->account_category = trim($this->account_category); - if (isset($this->fk_user_author)) - $this->fk_user_author = trim($this->fk_user_author); - if (isset($this->active)) - $this->active = trim($this->active); - - if (empty($this->pcg_type) || $this->pcg_type == '-1') - { - $this->pcg_type = 'XXXXXX'; - } - if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') - { - $this->pcg_subtype = 'XXXXXX'; - } + // Check parameters - // Put here code to add control on parameters values - + if (empty($this->nature) || $this->nature == '-1') + { + $this->nature = '0'; + } + // Insert request - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; - $sql .= "datec"; - $sql .= ", entity"; - $sql .= ", fk_pcg_version"; - $sql .= ", pcg_type"; - $sql .= ", pcg_subtype"; - $sql .= ", account_number"; - $sql .= ", account_parent"; + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_journal("; + $sql .= "code"; $sql .= ", label"; - $sql .= ", fk_accounting_category"; - $sql .= ", fk_user_author"; + $sql .= ", nature"; $sql .= ", active"; $sql .= ") VALUES ("; - $sql .= " '" . $this->db->idate($now) . "'"; - $sql .= ", " . $conf->entity; - $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'"); - $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'"); - $sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->pcg_subtype . "'"); - $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->account_number . "'"); - $sql .= ", " . (empty($this->account_parent) ? 'NULL' : "'" . $this->db->escape($this->account_parent) . "'"); + $sql .= " " . (empty($this->code) ? 'NULL' : "'" . $this->db->escape($this->code) . "'"); $sql .= ", " . (empty($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'"); - $sql .= ", " . (empty($this->account_category) ? 'NULL' : "'" . $this->db->escape($this->account_category) . "'"); - $sql .= ", " . $user->id; + $sql .= ", " . (empty($this->nature) ? '0' : "'" . $this->db->escape($this->nature) . "'"); $sql .= ", " . (! isset($this->active) ? 'NULL' : $this->db->escape($this->active)); $sql .= ")"; @@ -194,7 +130,7 @@ class AccountingJournal extends CommonObject } if (! $error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_journal"); // if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -232,26 +168,17 @@ class AccountingJournal extends CommonObject function update($user) { // Check parameters - if (empty($this->pcg_type) || $this->pcg_type == '-1') + if (empty($this->nature) || $this->nature == '-1') { - $this->pcg_type = 'XXXXXX'; + $this->nature = '0'; } - if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') - { - $this->pcg_subtype = 'XXXXXX'; - } - + $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; - $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); - $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); - $sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null"); - $sql .= " , account_number = '" . $this->account_number . "'"; - $sql .= " , account_parent = '" . $this->account_parent . "'"; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; + $sql .= " SET code = " . ($this->code ? "'" . $this->db->escape($this->code) . "'" : "null"); $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "null"); - $sql .= " , fk_accounting_category = '" . $this->account_category . "'"; - $sql .= " , fk_user_modif = " . $user->id; + $sql .= " , nature = " . ($this->nature ? "'" . $this->db->escape($this->nature) . "'" : "0"); $sql .= " , active = '" . $this->active . "'"; $sql .= " WHERE rowid = " . $this->id; @@ -268,7 +195,7 @@ class AccountingJournal extends CommonObject } /** - * Check usage of accounting code + * Check usage of accounting journal * * @return int <0 if KO, >0 if OK */ @@ -287,7 +214,7 @@ class AccountingJournal extends CommonObject if ($resql) { $num = $this->db->num_rows($resql); if ($num > 0) { - $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse'); + $this->error = $langs->trans('ErrorAccountingJournalIsAlreadyUse'); return 0; } else { return 1; @@ -329,7 +256,7 @@ class AccountingJournal extends CommonObject // } if (! $error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account"; + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_journal"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql); @@ -360,85 +287,47 @@ class AccountingJournal extends CommonObject /** * Return clicable name (with picto eventually) * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @return string Chaine avec URL + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @return string Chaine avec URL */ function getNomUrl($withpicto = 0) { global $langs; $result = ''; - $link = ''; + $link = ''; $linkend = ''; $picto = 'billr'; - $label = $langs->trans("Show") . ': ' . $this->account_number . ' - ' . $this->label; + $label = $langs->trans("Show") . ': ' . $this->code . ' - ' . $this->label; if ($withpicto) $result .= ($link . img_object($label, $picto) . $linkend); if ($withpicto && $withpicto != 2) $result .= ' '; if ($withpicto != 2) - require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - $result .= $link . length_accountg($this->account_number) . ' - ' . $this->label . $linkend; + $result .= $link . $this->code . ' - ' . $this->label . $linkend; return $result; } /** - * Information on record - * - * @param int $id of record - * @return void - */ - function info($id) { - $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a'; - $sql .= ' WHERE a.rowid = ' . $id; - - dol_syslog(get_class($this) . '::info sql=' . $sql); - $result = $this->db->query($sql); - - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - if ($obj->fk_user_author) { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; - } - if ($obj->fk_user_modif) { - $muser = new User($this->db); - $muser->fetch($obj->fk_user_modif); - $this->user_modification = $muser; - } - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->tms); - } - $this->db->free($result); - } else { - dol_print_error($this->db); - } - } - - /** - * Account desactivate + * Deactivate journal * * @param int $id Id * @return int <0 if KO, >0 if OK */ - function account_desactivate($id) { + function journal_deactivate($id) { $result = $this->checkUsage(); if ($result > 0) { $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; $sql .= "SET active = '0'"; $sql .= " WHERE rowid = " . $this->db->escape($id); - dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::deactivate sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -455,15 +344,15 @@ class AccountingJournal extends CommonObject } /** - * Account activate + * Activate journal * * @param int $id Id * @return int <0 if KO, >0 if OK */ - function account_activate($id) { + function journal_activate($id) { $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_journal "; $sql .= "SET active = '1'"; $sql .= " WHERE rowid = " . $this->db->escape($id); diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 205acb9ba80..56fdc8e6de9 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -91,6 +91,35 @@ function accounting_prepare_head(AccountingAccount $object) return $head; } +/** + * Prepare array with list of tabs + * + * @param AccountingAccount $object Accounting account + * @return array Array of tabs to show + */ +function accounting_journal_prepare_head(AccountingJournal $object) +{ + global $langs, $conf; + + $h = 0; + $head = array (); + + $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journals_card.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h ++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_journal'); + + complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_journal', 'remove'); + + return $head; +} + /** * Return accounting account without zero on the right * diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index f35b61055ad..42c5c519d2c 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -199,13 +199,17 @@ ApplyMassCategories=Apply mass categories AddAccountFromBookKeepingWithNoCategories=Add acccount already used with no categories CategoryDeleted=Category for the accounting account has been removed AccountingJournals=Accounting journals +AccountingJournal=Accounting journal NewAccountingJournal=New accounting journal ShowAccoutingJournal=Show accounting journal +Code=Code +Nature=Nature AccountingJournalTypeVariousOperation=Various operation AccountingJournalTypeSale=Sale AccountingJournalTypePurchase=Purchase AccountingJournalTypeBank=Bank AccountingJournalTypeHasNew=Has-new +ErrorAccountingJournalIsAlreadyUse=This journal is already use ## Export Exports=Exports