NEW: Accountancy - Add category
This commit is contained in:
parent
4145874d34
commit
432cc44ab6
@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
<?php
|
||||
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -28,6 +28,7 @@ require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
|
||||
|
||||
$error = 0;
|
||||
|
||||
@ -61,6 +62,7 @@ if ($action == 'add') {
|
||||
$accounting->pcg_subtype = GETPOST('pcg_subtype');
|
||||
$accounting->account_number = GETPOST('account_number');
|
||||
$accounting->account_parent = GETPOST('account_parent', 'int');
|
||||
$accounting->account_category = GETPOST('account_category', 'int');
|
||||
$accounting->label = GETPOST('label', 'alpha');
|
||||
$accounting->active = 1;
|
||||
|
||||
@ -94,6 +96,7 @@ if ($action == 'add') {
|
||||
$accounting->pcg_subtype = GETPOST('pcg_subtype');
|
||||
$accounting->account_number = GETPOST('account_number');
|
||||
$accounting->account_parent = GETPOST('account_parent', 'int');
|
||||
$accounting->account_category = GETPOST('account_category', 'int');
|
||||
$accounting->label = GETPOST('label', 'alpha');
|
||||
|
||||
$result = $accounting->update($user);
|
||||
@ -131,7 +134,9 @@ llxheader('', $langs->trans('AccountAccounting'));
|
||||
|
||||
$form = new Form($db);
|
||||
$htmlacc = new FormVentilation($db);
|
||||
$formaccounting = new FormAccounting($db);
|
||||
|
||||
// Create mode
|
||||
if ($action == 'create') {
|
||||
print load_fiche_titre($langs->trans('NewAccount'));
|
||||
|
||||
@ -142,19 +147,34 @@ if ($action == 'create') {
|
||||
dol_fiche_head();
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
|
||||
// Account number
|
||||
print '<tr><td width="25%"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
|
||||
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
|
||||
print '<td><input name="label" size="70" value="' . $accounting->label . '"</td></tr>';
|
||||
|
||||
// Account parent
|
||||
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Category
|
||||
print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
|
||||
print '<td>';
|
||||
$formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Chart of accounts type
|
||||
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type');
|
||||
print '</td></tr>';
|
||||
|
||||
// Chart of acounts subtype
|
||||
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
|
||||
@ -180,6 +200,7 @@ if ($action == 'create') {
|
||||
|
||||
$head = accounting_prepare_head($accounting);
|
||||
|
||||
// Edit mode
|
||||
if ($action == 'update') {
|
||||
$soc = new Societe($db);
|
||||
if ($object->socid) {
|
||||
@ -195,18 +216,33 @@ if ($action == 'create') {
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Account number
|
||||
print '<tr><td width="25%"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
|
||||
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
|
||||
print '<td><input name="label" size="70" value="' . $accounting->label . '"</td></tr>';
|
||||
|
||||
// Account parent
|
||||
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Category
|
||||
print '<tr><td>'.$langs->trans("AccountingCategory").'</td>';
|
||||
print '<td>';
|
||||
$formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Chart of accounts type
|
||||
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type');
|
||||
print '</td></tr>';
|
||||
|
||||
// Chart of accounts subtype
|
||||
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
|
||||
print '<td>';
|
||||
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
|
||||
@ -224,6 +260,8 @@ if ($action == 'create') {
|
||||
|
||||
print '</form>';
|
||||
} else {
|
||||
|
||||
// View mode
|
||||
$linkback = '<a href="../admin/account.php">' . $langs->trans("BackToChartofaccounts") . '</a>';
|
||||
|
||||
dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
|
||||
@ -234,23 +272,31 @@ if ($action == 'create') {
|
||||
print '<tr><td width="25%">' . $langs->trans("AccountNumber") . '</td>';
|
||||
print '<td>' . $accounting->account_number . '</td>';
|
||||
print '<td align="right" width="25%">' . $linkback . '</td></tr>';
|
||||
|
||||
|
||||
// Label
|
||||
print '<tr><td>' . $langs->trans("Label") . '</td>';
|
||||
print '<td colspan="2">' . $accounting->label . '</td></tr>';
|
||||
|
||||
|
||||
// Account parent
|
||||
$accp = new AccountingAccount($db);
|
||||
if (! empty($accounting->account_parent)) {
|
||||
$accp->fetch($accounting->account_parent, '');
|
||||
}
|
||||
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
|
||||
print '<td colspan="2">' . $accp->account_number . ' - ' . $accp->label . '</td></tr>';
|
||||
|
||||
|
||||
// Category
|
||||
print "<tr><td>".$langs->trans("AccountingCategory")."</td><td colspan='2'>".$accounting->accounting_category_label."</td>";
|
||||
|
||||
// Chart of accounts type
|
||||
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
|
||||
print '<td colspan="2">' . $accounting->pcg_type . '</td></tr>';
|
||||
|
||||
|
||||
// Chart of accounts subtype
|
||||
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
|
||||
print '<td colspan="2">' . $accounting->pcg_subtype . '</td></tr>';
|
||||
|
||||
|
||||
// Active
|
||||
print '<tr><td>' . $langs->trans("Activated") . '</td>';
|
||||
print '<td colspan="2">';
|
||||
|
||||
@ -267,7 +313,7 @@ if ($action == 'create') {
|
||||
dol_fiche_end();
|
||||
|
||||
/*
|
||||
* Barre d'actions
|
||||
* Actions buttons
|
||||
*/
|
||||
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
|
||||
* Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
|
||||
@ -41,6 +41,7 @@ class AccountingAccount extends CommonObject
|
||||
var $pcg_subtype;
|
||||
var $account_number;
|
||||
var $account_parent;
|
||||
var $account_category;
|
||||
var $label;
|
||||
var $fk_user_author;
|
||||
var $fk_user_modif;
|
||||
@ -67,12 +68,14 @@ class AccountingAccount extends CommonObject
|
||||
global $conf;
|
||||
|
||||
if ($rowid || $account_number) {
|
||||
$sql = "SELECT rowid, datec, tms, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, fk_user_author, fk_user_modif, active";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account WHERE";
|
||||
$sql = "SELECT a.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 .= ", ac.label as category_label";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, ".MAIN_DB_PREFIX."c_accounting_category as ac";
|
||||
$sql .= " WHERE a.fk_accounting_category = ac.rowid";
|
||||
if ($rowid) {
|
||||
$sql .= " rowid = '" . $rowid . "'";
|
||||
$sql .= " AND rowid = '" . $rowid . "'";
|
||||
} elseif ($account_number) {
|
||||
$sql .= " account_number = '" . $account_number . "'";
|
||||
$sql .= " AND account_number = '" . $account_number . "'";
|
||||
}
|
||||
if (! empty($limittocurentchart)) {
|
||||
$sql .= ' AND fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
|
||||
@ -93,6 +96,8 @@ class AccountingAccount extends CommonObject
|
||||
$this->account_number = $obj->account_number;
|
||||
$this->account_parent = $obj->account_parent;
|
||||
$this->label = $obj->label;
|
||||
$this->fk_accounting_category = $obj->fk_accounting_category;
|
||||
$this->accounting_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;
|
||||
@ -153,6 +158,7 @@ class AccountingAccount extends CommonObject
|
||||
$sql .= ", account_number";
|
||||
$sql .= ", account_parent";
|
||||
$sql .= ", label";
|
||||
$sql .= ", fk_accounting_account";
|
||||
$sql .= ", fk_user_author";
|
||||
$sql .= ", active";
|
||||
|
||||
@ -166,6 +172,7 @@ class AccountingAccount extends CommonObject
|
||||
$sql .= ", " . (! isset($this->account_number) ? 'NULL' : "'" . $this->account_number . "'");
|
||||
$sql .= ", " . (! isset($this->account_parent) ? 'NULL' : "'" . $this->db->escape($this->account_parent) . "'");
|
||||
$sql .= ", " . (! isset($this->label) ? 'NULL' : "'" . $this->db->escape($this->label) . "'");
|
||||
$sql .= ", " . (! isset($this->account_category) ? 'NULL' : "'" . $this->db->escape($this->account_category) . "'");
|
||||
$sql .= ", " . $user->id;
|
||||
$sql .= ", " . (! isset($this->active) ? 'NULL' : "'" . $this->db->escape($this->active) . "'");
|
||||
|
||||
@ -226,6 +233,7 @@ class AccountingAccount extends CommonObject
|
||||
$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 . "'";
|
||||
|
||||
|
||||
116
htdocs/core/class/html.formaccounting.class.php
Normal file
116
htdocs/core/class/html.formaccounting.class.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/* Copyright (C) 2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/class/html.formaccounting.class.php
|
||||
* \ingroup core
|
||||
* \brief File of class with all html predefined components
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage generation of HTML components for accounting management
|
||||
*/
|
||||
class FormAccounting
|
||||
{
|
||||
var $db;
|
||||
var $error;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of accounting category.
|
||||
* Use mysoc->country_id or mysoc->country_code so they must be defined.
|
||||
*
|
||||
* @param string $selected Preselected type
|
||||
* @param string $htmlname Name of field in form
|
||||
* @param int $useempty Set to 1 if we want an empty value
|
||||
* @param int $maxlen Max length of text in combo box
|
||||
* @param int $help Add or not the admin help picto
|
||||
* @return void
|
||||
*/
|
||||
function select_accounting_category($selected='',$htmlname='actioncode', $useempty=0, $maxlen=64, $help=1)
|
||||
{
|
||||
global $db,$langs,$user,$mysoc;
|
||||
|
||||
if (empty($mysoc->country_id) && empty($mysoc->country_code))
|
||||
{
|
||||
dol_print_error('','Call to select_accounting_account with mysoc country not yet defined');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (! empty($mysoc->country_id))
|
||||
{
|
||||
$sql = "SELECT c.rowid, c.label as type, c.range";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category as c";
|
||||
$sql.= " WHERE c.active = 1";
|
||||
$sql.= " AND c.fk_country = ".$mysoc->country_id;
|
||||
$sql.= " ORDER BY c.label ASC";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT c.rowid, c.label as type, c.range";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_accountancy_category, ".MAIN_DB_PREFIX."c_country as co";
|
||||
$sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid";
|
||||
$sql.= " AND co.code = '".$mysoc->country_code."'";
|
||||
$sql.= " ORDER BY c.label ASC";
|
||||
}
|
||||
|
||||
dol_syslog("Form::select_accounting_category", LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
print '<select class="flat" name="'.$htmlname.'">';
|
||||
$i = 0;
|
||||
|
||||
if ($useempty) print '<option value="0"> </option>';
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<option value="'.$obj->id.'"';
|
||||
if ($obj->id == $selected) print ' selected';
|
||||
print '>'.dol_trunc($obj->type,$maxlen);
|
||||
print ' ('.$obj->range.')';
|
||||
$i++;
|
||||
}
|
||||
print '</select>';
|
||||
if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ErrorNoAccountingCategoryForThisCountry",$mysoc->country_code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db,$db->lasterror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,3 +323,5 @@ ALTER TABLE llx_expensereport_det ADD COLUMN multicurrency_total_ttc double(24,8
|
||||
ALTER TABLE llx_product_lang ADD COLUMN import_key varchar(14) DEFAULT NULL;
|
||||
|
||||
ALTER TABLE llx_actioncomm MODIFY COLUMN elementtype varchar(255) DEFAULT NULL;
|
||||
|
||||
ALTER TABLE llx_accounting_account ADD COLUMN fk_accounting_category integer DEFAULT 0 after label;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
-- ============================================================================
|
||||
-- Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
-- Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
|
||||
-- Copyright (C) 2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
--
|
||||
-- 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
|
||||
@ -20,17 +21,18 @@
|
||||
|
||||
create table llx_accounting_account
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL,
|
||||
datec datetime,
|
||||
tms timestamp,
|
||||
fk_pcg_version varchar(32) NOT NULL,
|
||||
pcg_type varchar(20) NOT NULL,
|
||||
pcg_subtype varchar(20) NOT NULL,
|
||||
account_number varchar(32) NOT NULL,
|
||||
account_parent varchar(32),
|
||||
label varchar(255) NOT NULL,
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
active tinyint DEFAULT 1 NOT NULL
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL,
|
||||
datec datetime,
|
||||
tms timestamp,
|
||||
fk_pcg_version varchar(32) NOT NULL,
|
||||
pcg_type varchar(20) NOT NULL,
|
||||
pcg_subtype varchar(20) NOT NULL,
|
||||
account_number varchar(32) NOT NULL,
|
||||
account_parent varchar(32),
|
||||
label varchar(255) NOT NULL,
|
||||
fk_accounting_category integer DEFAULT 0,
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_modif integer DEFAULT NULL,
|
||||
active tinyint DEFAULT 1 NOT NULL
|
||||
)ENGINE=innodb;
|
||||
|
||||
@ -105,6 +105,7 @@ Labelcompte=Label account
|
||||
Sens=Sens
|
||||
Codejournal=Journal
|
||||
NumPiece=Piece number
|
||||
AccountingCategory=Accounting category
|
||||
|
||||
DelBookKeeping=Delete the records of the general ledger
|
||||
|
||||
@ -179,4 +180,7 @@ OptionModeProductSellDesc=Show all products with no accounting account defined f
|
||||
OptionModeProductBuyDesc=Show all products with no accounting account defined for purchases.
|
||||
|
||||
## Dictionary
|
||||
Range=Range of accounting account
|
||||
Range=Range of accounting account
|
||||
|
||||
## Error
|
||||
ErrorNoAccountingCategoryForThisCountry=No accounting category are available for this country
|
||||
Loading…
Reference in New Issue
Block a user