dolibarr/htdocs/accountancy/admin/card.php

403 lines
13 KiB
PHP
Raw Normal View History

2016-03-28 13:51:19 +02:00
<?php
2014-08-27 07:03:42 +02:00
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
2014-08-27 07:03:42 +02:00
*
* 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/accountancy/admin/card.php
* \ingroup Advanced accountancy
* \brief Card of accounting account
2014-08-27 07:03:42 +02:00
*/
2015-06-12 13:21:21 +02:00
2016-10-07 12:10:16 +02:00
require '../../main.inc.php';
2016-02-01 15:07:12 +01:00
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/accountancysystem.class.php';
2016-03-28 13:51:19 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
2014-08-27 07:03:42 +02:00
2016-02-01 15:07:12 +01:00
$error = 0;
2015-06-12 13:21:21 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2018-04-18 06:20:34 +02:00
$langs->loadLangs(array("bills","accountancy"));
2014-08-27 07:03:42 +02:00
$mesg = '';
2017-05-16 13:27:32 +02:00
$action = GETPOST('action','aZ09');
2017-09-15 10:52:53 +02:00
$backtopage = GETPOST('backtopage','alpha');
2014-08-27 07:03:42 +02:00
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
2014-08-27 07:03:42 +02:00
$rowid = GETPOST('rowid', 'int');
2017-09-15 10:50:50 +02:00
$cancel = GETPOST('cancel','alpha');
2014-08-27 07:03:42 +02:00
// Security check
2015-06-12 13:21:21 +02:00
2016-03-28 21:03:47 +02:00
$object = new AccountingAccount($db);
2014-08-27 07:03:42 +02:00
2016-10-07 12:10:16 +02:00
/*
* Action
*/
2017-09-15 10:50:50 +02:00
if (GETPOST('cancel','alpha'))
2016-10-14 13:05:01 +02:00
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/accountancy/admin/account.php',1);
header("Location: ".$urltogo);
exit;
}
if ($action == 'add' && $user->rights->accounting->chartofaccount)
{
if (! $cancel) {
2014-09-06 09:50:42 +02:00
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
2017-09-06 19:56:01 +02:00
2014-09-06 09:50:42 +02:00
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
$result = $db->query($sql);
$obj = $db->fetch_object($result);
// Clean code
// To manage zero or not at the end of the accounting account
if($conf->global->ACCOUNTING_MANAGE_ZERO == 1)
{
$account_number = GETPOST('account_number');
}
else
{
$account_number = clean_account(GETPOST('account_number'));
}
if (GETPOST('account_parent') <= 0) {
2016-08-11 06:12:04 +02:00
$account_parent = 0;
} else {
$account_parent = GETPOST('account_parent','int');
}
2016-03-28 21:03:47 +02:00
$object->fk_pcg_version = $obj->pcg_version;
$object->pcg_type = GETPOST('pcg_type');
$object->pcg_subtype = GETPOST('pcg_subtype');
2016-03-30 06:49:10 +02:00
$object->account_number = $account_number;
$object->account_parent = $account_parent;
2016-03-28 21:03:47 +02:00
$object->account_category = GETPOST('account_category');
$object->label = GETPOST('label', 'alpha');
$object->active = 1;
2016-03-28 21:03:47 +02:00
$res = $object->create($user);
2016-05-08 11:33:46 +02:00
if ($res == - 3) {
$error = 1;
$action = "create";
2016-10-07 12:10:16 +02:00
setEventMessages($object->error, $object->errors, 'errors');
2016-05-08 11:33:46 +02:00
}
2016-10-07 12:10:16 +02:00
elseif ($res == - 4) {
2016-05-08 11:33:46 +02:00
$error = 2;
$action = "create";
2016-10-07 12:10:16 +02:00
setEventMessages($object->error, $object->errors, 'errors');
}
elseif ($res < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
$action = "create";
}
if (! $error)
{
2016-10-14 13:05:01 +02:00
setEventMessages("RecordCreatedSuccessfully",null,'mesgs');
$urltogo=$backtopage?$backtopage:dol_buildpath('/accountancy/admin/account.php',1);
header("Location: ".$urltogo);
2016-10-07 12:10:16 +02:00
exit;
2014-08-27 07:03:42 +02:00
}
}
} else if ($action == 'edit' && $user->rights->accounting->chartofaccount) {
if (! $cancel) {
2016-03-28 21:03:47 +02:00
$result = $object->fetch($id);
2014-08-27 07:03:42 +02:00
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
2014-08-28 06:30:01 +02:00
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
2014-08-27 07:03:42 +02:00
$result2 = $db->query($sql);
$obj = $db->fetch_object($result2);
// Clean code
// To manage zero or not at the end of the accounting account
if($conf->global->ACCOUNTING_MANAGE_ZERO == 1)
{
$account_number = GETPOST('account_number');
}
else
{
$account_number = clean_account(GETPOST('account_number'));
}
if (GETPOST('account_parent') <= 0) {
$account_parent = 0;
} else {
$account_parent = GETPOST('account_parent','int');
}
2016-03-28 21:03:47 +02:00
$object->fk_pcg_version = $obj->pcg_version;
$object->pcg_type = GETPOST('pcg_type');
$object->pcg_subtype = GETPOST('pcg_subtype');
$object->account_number = $account_number;
2016-04-03 10:51:56 +02:00
$object->account_parent = $account_parent;
2016-03-28 21:03:47 +02:00
$object->account_category = GETPOST('account_category');
$object->label = GETPOST('label', 'alpha');
2016-03-28 21:03:47 +02:00
$result = $object->update($user);
2014-08-27 07:03:42 +02:00
if ($result > 0) {
$urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id);
header("Location: " . $urltogo);
2014-08-27 07:03:42 +02:00
exit();
} else {
$mesg = $object->error;
}
} else {
$urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id);
header("Location: " . $urltogo);
2014-08-27 07:03:42 +02:00
exit();
}
} else if ($action == 'delete' && $user->rights->accounting->chartofaccount) {
2016-03-28 21:03:47 +02:00
$result = $object->fetch($id);
2017-09-06 19:56:01 +02:00
2016-03-28 21:03:47 +02:00
if (! empty($object->id)) {
$result = $object->delete($user);
2017-09-06 19:56:01 +02:00
2014-08-27 07:03:42 +02:00
if ($result > 0) {
2016-05-08 11:33:46 +02:00
header("Location: account.php");
exit;
2014-08-27 07:03:42 +02:00
}
}
2017-09-06 19:56:01 +02:00
2014-08-27 07:03:42 +02:00
if ($result < 0) {
2016-03-28 21:03:47 +02:00
setEventMessages($object->error, $object->errors, 'errors');
2014-08-27 07:03:42 +02:00
}
}
2014-08-27 07:03:42 +02:00
/*
* View
*/
$form = new Form($db);
2016-03-28 13:51:19 +02:00
$formaccounting = new FormAccounting($db);
2014-08-27 07:03:42 +02:00
$accountsystem = new AccountancySystem($db);
$accountsystem->fetch($conf->global->CHARTOFACCOUNTS);
$title = $langs->trans('AccountAccounting') ." - ". $langs->trans('Card');
$helpurl = '';
llxheader('', $title, $helpurl);
2016-03-28 13:51:19 +02:00
// Create mode
2016-02-01 15:07:12 +01:00
if ($action == 'create') {
2016-10-11 10:24:02 +02:00
print load_fiche_titre($langs->trans('NewAccountingAccount'));
2014-08-27 07:03:42 +02:00
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="add">';
dol_fiche_head();
2014-08-27 07:03:42 +02:00
print '<table class="border" width="100%">';
2016-03-28 13:51:19 +02:00
// Chart of account
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("Chartofaccounts") . '</span></td>';
print '<td>';
print $accountsystem->ref;
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Account number
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"></td></tr>';
2016-03-28 13:51:19 +02:00
// Label
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
print '<td><input name="label" size="70" value="' . $object->label . '"></td></tr>';
2016-03-28 13:51:19 +02:00
// Account parent
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td>';
print $formaccounting->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200');
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Category
print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
print '<td>';
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1);
2016-03-28 13:51:19 +02:00
print '</td></tr>';
// Chart of accounts type
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Chart of acounts subtype
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2014-08-27 07:03:42 +02:00
print '</table>';
dol_fiche_end();
print '<div class="center">';
2014-11-25 20:13:43 +01:00
print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
print '</div>';
2014-08-27 07:03:42 +02:00
print '</form>';
}
else if ($id > 0 || $ref) {
$result = $object->fetch($id, $ref, 1);
2016-03-28 21:03:47 +02:00
if ($result > 0) {
2014-08-27 07:03:42 +02:00
dol_htmloutput_mesg($mesg);
2016-03-28 21:03:47 +02:00
$head = accounting_prepare_head($object);
2016-03-28 13:51:19 +02:00
// Edit mode
2017-09-06 19:56:01 +02:00
if ($action == 'update')
2016-04-09 15:38:15 +02:00
{
2014-08-27 07:03:42 +02:00
dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
2014-08-27 07:03:42 +02:00
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="edit">';
print '<input type="hidden" name="id" value="' . $id . '">';
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
2014-08-27 07:03:42 +02:00
print '<table class="border" width="100%">';
2016-03-28 13:51:19 +02:00
// Account number
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
2016-03-28 21:03:47 +02:00
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"</td></tr>';
2016-03-28 13:51:19 +02:00
// Label
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
2016-03-28 21:03:47 +02:00
print '<td><input name="label" size="70" value="' . $object->label . '"</td></tr>';
2016-03-28 13:51:19 +02:00
// Account parent
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td>';
print $formaccounting->select_account($object->account_parent, 'account_parent', 1);
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Category
print '<tr><td>'.$langs->trans("AccountingCategory").'</td>';
2016-03-28 13:51:19 +02:00
print '<td>';
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Chart of accounts type
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2016-03-28 13:51:19 +02:00
// Chart of accounts subtype
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
2014-08-27 07:03:42 +02:00
print '</td></tr>';
2014-08-27 07:03:42 +02:00
print '</table>';
dol_fiche_end();
print '<div class="center">';
2014-11-25 20:13:43 +01:00
print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
2014-08-27 07:03:42 +02:00
print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
2014-11-25 20:13:43 +01:00
print '</div>';
2014-08-27 07:03:42 +02:00
print '</form>';
2016-02-01 15:07:12 +01:00
} else {
2016-03-28 13:51:19 +02:00
// View mode
$linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/account.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), -1, 'billr');
dol_banner_tab($object, 'ref', $linkback, 1, 'account_number', 'ref');
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
2016-03-28 13:51:19 +02:00
// Label
print '<tr><td class="titlefield">' . $langs->trans("Label") . '</td>';
2016-03-28 21:03:47 +02:00
print '<td colspan="2">' . $object->label . '</td></tr>';
2016-03-28 13:51:19 +02:00
// Account parent
2014-08-27 07:03:42 +02:00
$accp = new AccountingAccount($db);
2016-03-28 21:03:47 +02:00
if (! empty($object->account_parent)) {
$accp->fetch($object->account_parent, '');
2014-08-27 07:03:42 +02:00
}
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td colspan="2">' . $accp->account_number . ' - ' . $accp->label . '</td></tr>';
2016-03-28 13:51:19 +02:00
// Category
2016-03-28 21:03:47 +02:00
print "<tr><td>".$langs->trans("AccountingCategory")."</td><td colspan='2'>".$object->account_category_label."</td>";
2016-03-28 13:51:19 +02:00
// Chart of accounts type
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
2016-03-28 21:03:47 +02:00
print '<td colspan="2">' . $object->pcg_type . '</td></tr>';
2016-03-28 13:51:19 +02:00
// Chart of accounts subtype
2014-08-27 07:03:42 +02:00
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
2016-03-28 21:03:47 +02:00
print '<td colspan="2">' . $object->pcg_subtype . '</td></tr>';
2016-03-28 13:51:19 +02:00
2014-08-27 07:03:42 +02:00
print '</table>';
print '</div>';
dol_fiche_end();
2014-08-27 07:03:42 +02:00
/*
2016-03-28 13:51:19 +02:00
* Actions buttons
2014-09-03 07:22:59 +02:00
*/
2014-08-27 07:03:42 +02:00
print '<div class="tabsAction">';
if (! empty($user->rights->accounting->chartofaccount)) {
2014-08-27 07:03:42 +02:00
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
} else {
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Modify') . '</a>';
}
if (! empty($user->rights->accounting->chartofaccount)) {
2014-08-27 07:03:42 +02:00
print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
} else {
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Delete') . '</a>';
}
2014-08-27 07:03:42 +02:00
print '</div>';
}
2016-02-01 15:07:12 +01:00
} else {
dol_print_error($db, $object->error, $object->errors);
2014-08-27 07:03:42 +02:00
}
}
llxFooter();
2018-05-26 23:52:52 +02:00
$db->close();