2016-03-28 13:51:19 +02:00
|
|
|
<?php
|
2018-12-02 11:01:11 +01:00
|
|
|
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
|
2020-01-03 22:05:49 +01:00
|
|
|
* Copyright (C) 2013-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
2018-12-02 11:01:11 +01:00
|
|
|
* 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
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-08-27 07:03:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2018-12-02 11:01:11 +01:00
|
|
|
* \file htdocs/accountancy/admin/card.php
|
2019-05-13 22:25:15 +02:00
|
|
|
* \ingroup Accountancy (Double entries)
|
2018-12-02 11:01:11 +01:00
|
|
|
* \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';
|
2019-11-13 19:35:02 +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';
|
|
|
|
|
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
|
2021-01-07 06:59:40 +01:00
|
|
|
$langs->loadLangs(array("bills", "accountancy", "compta"));
|
2014-08-27 07:03:42 +02:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
|
|
|
$backtopage = GETPOST('backtopage', 'alpha');
|
2014-08-27 07:03:42 +02:00
|
|
|
$id = GETPOST('id', 'int');
|
2018-01-11 17:06:06 +01:00
|
|
|
$ref = GETPOST('ref', 'alpha');
|
2014-08-27 07:03:42 +02:00
|
|
|
$rowid = GETPOST('rowid', 'int');
|
2019-01-27 11:55:16 +01:00
|
|
|
$cancel = GETPOST('cancel', 'alpha');
|
2021-01-07 06:59:40 +01:00
|
|
|
|
2023-02-13 14:35:02 +01:00
|
|
|
$account_number = GETPOST('account_number', 'alphanohtml');
|
2021-01-07 06:59:40 +01:00
|
|
|
$label = GETPOST('label', 'alpha');
|
2014-08-27 07:03:42 +02:00
|
|
|
|
|
|
|
|
// Security check
|
2021-02-22 21:36:42 +01:00
|
|
|
if ($user->socid > 0) {
|
|
|
|
|
accessforbidden();
|
|
|
|
|
}
|
2021-10-22 22:08:13 +02:00
|
|
|
if (empty($user->rights->accounting->chartofaccount)) {
|
2021-02-22 21:36:42 +01:00
|
|
|
accessforbidden();
|
|
|
|
|
}
|
2016-09-29 12:11:57 +02:00
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-22 21:36:42 +01:00
|
|
|
if (GETPOST('cancel', 'alpha')) {
|
2021-09-18 19:34:46 +02:00
|
|
|
$urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.'/accountancy/admin/account.php';
|
2016-10-14 13:05:01 +02:00
|
|
|
header("Location: ".$urltogo);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2021-02-22 21:36:42 +01:00
|
|
|
if ($action == 'add' && $user->rights->accounting->chartofaccount) {
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!$cancel) {
|
2021-02-22 21:36:42 +01:00
|
|
|
if (!$account_number) {
|
2021-01-07 06:59:40 +01:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors');
|
|
|
|
|
$action = 'create';
|
2021-02-22 21:36:42 +01:00
|
|
|
} elseif (!$label) {
|
2021-01-07 06:59:40 +01:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
|
|
|
|
|
$action = 'create';
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2021-09-30 15:24:57 +02:00
|
|
|
$sql = "SELECT pcg_version FROM " . MAIN_DB_PREFIX . "accounting_system WHERE rowid = ".((int) $conf->global->CHARTOFACCOUNTS);
|
2021-01-07 06:59:40 +01: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 = $account_number;
|
|
|
|
|
} else {
|
|
|
|
|
$account_number = clean_account($account_number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GETPOST('account_parent', 'int') <= 0) {
|
|
|
|
|
$account_parent = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$account_parent = GETPOST('account_parent', 'int');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$object->fk_pcg_version = $obj->pcg_version;
|
|
|
|
|
$object->pcg_type = GETPOST('pcg_type', 'alpha');
|
|
|
|
|
$object->account_number = $account_number;
|
|
|
|
|
$object->account_parent = $account_parent;
|
|
|
|
|
$object->account_category = GETPOST('account_category', 'alpha');
|
|
|
|
|
$object->label = $label;
|
|
|
|
|
$object->labelshort = GETPOST('labelshort', 'alpha');
|
|
|
|
|
$object->active = 1;
|
|
|
|
|
|
|
|
|
|
$res = $object->create($user);
|
|
|
|
|
if ($res == -3) {
|
|
|
|
|
$error = 1;
|
|
|
|
|
$action = "create";
|
|
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
|
|
|
} elseif ($res == -4) {
|
|
|
|
|
$error = 2;
|
|
|
|
|
$action = "create";
|
|
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
|
|
|
} elseif ($res < 0) {
|
|
|
|
|
$error++;
|
|
|
|
|
setEventMessages($object->error, $object->errors, 'errors');
|
|
|
|
|
$action = "create";
|
|
|
|
|
}
|
|
|
|
|
if (!$error) {
|
|
|
|
|
setEventMessages("RecordCreatedSuccessfully", null, 'mesgs');
|
2021-09-18 19:34:46 +02:00
|
|
|
$urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.'/accountancy/admin/account.php';
|
2021-01-07 06:59:40 +01:00
|
|
|
header("Location: " . $urltogo);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-27 10:49:34 +01:00
|
|
|
} elseif ($action == 'edit' && $user->rights->accounting->chartofaccount) {
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!$cancel) {
|
2021-02-22 21:36:42 +01:00
|
|
|
if (!$account_number) {
|
2021-01-07 06:59:40 +01:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors');
|
|
|
|
|
$action = 'update';
|
2021-02-22 21:36:42 +01:00
|
|
|
} elseif (!$label) {
|
2021-01-07 06:59:40 +01:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
|
|
|
|
|
$action = 'update';
|
2014-08-27 07:03:42 +02:00
|
|
|
} else {
|
2021-01-07 06:59:40 +01:00
|
|
|
$result = $object->fetch($id);
|
|
|
|
|
|
2021-09-30 15:24:57 +02:00
|
|
|
$sql = "SELECT pcg_version FROM ".MAIN_DB_PREFIX."accounting_system WHERE rowid=".((int) $conf->global->CHARTOFACCOUNTS);
|
2021-01-07 06:59:40 +01:00
|
|
|
|
|
|
|
|
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
|
|
|
|
|
$result2 = $db->query($sql);
|
|
|
|
|
$obj = $db->fetch_object($result2);
|
|
|
|
|
|
|
|
|
|
// Clean code
|
|
|
|
|
|
|
|
|
|
// To manage zero or not at the end of the accounting account
|
2021-04-13 09:46:50 +02:00
|
|
|
if (isset($conf->global->ACCOUNTING_MANAGE_ZERO) && $conf->global->ACCOUNTING_MANAGE_ZERO == 1) {
|
2021-01-07 06:59:40 +01:00
|
|
|
$account_number = $account_number;
|
|
|
|
|
} else {
|
|
|
|
|
$account_number = clean_account($account_number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GETPOST('account_parent', 'int') <= 0) {
|
|
|
|
|
$account_parent = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$account_parent = GETPOST('account_parent', 'int');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$object->fk_pcg_version = $obj->pcg_version;
|
|
|
|
|
$object->pcg_type = GETPOST('pcg_type', 'alpha');
|
|
|
|
|
$object->account_number = $account_number;
|
|
|
|
|
$object->account_parent = $account_parent;
|
|
|
|
|
$object->account_category = GETPOST('account_category', 'alpha');
|
|
|
|
|
$object->label = $label;
|
|
|
|
|
$object->labelshort = GETPOST('labelshort', 'alpha');
|
|
|
|
|
|
|
|
|
|
$result = $object->update($user);
|
2022-06-28 20:11:18 +02:00
|
|
|
|
2021-01-07 06:59:40 +01:00
|
|
|
if ($result > 0) {
|
|
|
|
|
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"] . "?id=" . $id);
|
|
|
|
|
header("Location: " . $urltogo);
|
|
|
|
|
exit();
|
2022-06-28 20:11:18 +02:00
|
|
|
} elseif ($result == -2) {
|
|
|
|
|
setEventMessages($langs->trans("ErrorAccountNumberAlreadyExists", $object->account_number), null, 'errors');
|
2021-01-07 06:59:40 +01:00
|
|
|
} else {
|
2021-04-13 09:46:50 +02:00
|
|
|
setEventMessages($object->error, null, 'errors');
|
2021-01-07 06:59:40 +01:00
|
|
|
}
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2020-10-31 14:32:18 +01:00
|
|
|
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"]."?id=".$id);
|
|
|
|
|
header("Location: ".$urltogo);
|
2014-08-27 07:03:42 +02:00
|
|
|
exit();
|
|
|
|
|
}
|
2019-01-27 10:49:34 +01:00
|
|
|
} elseif ($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
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!empty($object->id)) {
|
2016-03-28 21:03:47 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 11:31:24 +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
|
|
|
|
2017-03-03 17:59:49 +01:00
|
|
|
$accountsystem = new AccountancySystem($db);
|
|
|
|
|
$accountsystem->fetch($conf->global->CHARTOFACCOUNTS);
|
|
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
$title = $langs->trans('AccountAccounting')." - ".$langs->trans('Card');
|
2021-03-18 21:49:29 +01:00
|
|
|
|
|
|
|
|
$help_url = 'EN:Category:Accounting';
|
|
|
|
|
|
|
|
|
|
llxheader('', $title, $help_url);
|
2018-04-09 11:31:24 +02:00
|
|
|
|
|
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Create mode
|
2022-07-11 00:05:50 +02:00
|
|
|
if ($action == 'create') {
|
2016-10-11 10:24:02 +02:00
|
|
|
print load_fiche_titre($langs->trans('NewAccountingAccount'));
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
|
2019-12-18 23:12:31 +01:00
|
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<input type="hidden" name="action" value="add">';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2020-10-22 16:34:12 +02:00
|
|
|
print dol_get_fiche_head();
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="border centpercent">';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2017-03-03 17:59:49 +01:00
|
|
|
// Chart of account
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Chartofaccounts").'</span></td>';
|
2017-03-03 17:59:49 +01:00
|
|
|
print '<td>';
|
|
|
|
|
print $accountsystem->ref;
|
|
|
|
|
print '</td></tr>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Account number
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("AccountNumber").'</span></td>';
|
2021-01-07 06:59:40 +01:00
|
|
|
print '<td><input name="account_number" size="30" value="'.$account_number.'"></td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
|
|
|
|
// Label
|
2019-11-13 19:35:02 +01:00
|
|
|
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
|
|
|
|
2020-01-03 22:05:49 +01:00
|
|
|
// Label short
|
2020-04-10 10:59:32 +02:00
|
|
|
print '<tr><td>'.$langs->trans("LabelToShow").'</td>';
|
|
|
|
|
print '<td><input name="labelshort" size="70" value="'.$object->labelshort.'"></td></tr>';
|
2020-01-03 22:05:49 +01:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Account parent
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td>'.$langs->trans("Accountparent").'</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2017-05-25 06:57:28 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
// Chart of accounts type
|
2021-04-13 09:46:50 +02:00
|
|
|
print '<tr><td>';
|
|
|
|
|
print $form->textwithpicto($langs->trans("Pcgtype"), $langs->transnoentitiesnoconv("PcgtypeDesc"));
|
|
|
|
|
print '</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2021-05-19 11:12:34 +02:00
|
|
|
print '<input type="text" name="pcg_type" list="pcg_type_datalist" value="'.dol_escape_htmltag(GETPOSTISSET('pcg_type') ? GETPOST('pcg_type', 'alpha') : $object->pcg_type).'">';
|
2021-05-28 08:42:38 +02:00
|
|
|
// autosuggest from existing account types if found
|
2021-05-19 11:12:34 +02:00
|
|
|
print '<datalist id="pcg_type_datalist">';
|
2021-09-30 15:24:57 +02:00
|
|
|
$sql = "SELECT DISTINCT pcg_type FROM " . MAIN_DB_PREFIX . "accounting_account";
|
2021-08-27 22:42:04 +02:00
|
|
|
$sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
|
2021-08-17 20:02:19 +02:00
|
|
|
$sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
|
2021-05-28 08:42:38 +02:00
|
|
|
$sql .= ' LIMIT 50000'; // just as a sanity check
|
2021-08-17 20:02:19 +02:00
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
if ($resql) {
|
|
|
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
|
|
|
print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
|
|
|
|
|
}
|
2021-05-19 11:12:34 +02:00
|
|
|
}
|
|
|
|
|
print '</datalist>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2020-12-30 12:07:42 +01:00
|
|
|
// Category
|
2021-04-13 09:46:50 +02:00
|
|
|
print '<tr><td>';
|
|
|
|
|
print $form->textwithpicto($langs->trans("AccountingCategory"), $langs->transnoentitiesnoconv("AccountingAccountGroupsDesc"));
|
|
|
|
|
print '</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2020-12-30 12:07:42 +01:00
|
|
|
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1);
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</table>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2020-10-27 18:19:31 +01:00
|
|
|
print dol_get_fiche_end();
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2015-05-20 07:03:17 +02:00
|
|
|
print '<div class="center">';
|
2020-11-19 20:23:38 +01:00
|
|
|
print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
|
2014-11-25 20:13:43 +01:00
|
|
|
print ' ';
|
2020-11-23 15:12:52 +01:00
|
|
|
print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
|
2014-11-25 20:13:43 +01:00
|
|
|
print '</div>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</form>';
|
2020-05-21 15:05:19 +02:00
|
|
|
} elseif ($id > 0 || $ref) {
|
2018-01-11 17:06:06 +01:00
|
|
|
$result = $object->fetch($id, $ref, 1);
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2016-03-28 21:03:47 +02:00
|
|
|
if ($result > 0) {
|
|
|
|
|
$head = accounting_prepare_head($object);
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Edit mode
|
2021-02-22 21:36:42 +01:00
|
|
|
if ($action == 'update') {
|
2022-05-07 06:43:23 +02:00
|
|
|
print dol_get_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'accounting_account');
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
|
2019-12-18 23:12:31 +01:00
|
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<input type="hidden" name="action" value="edit">';
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<input type="hidden" name="id" value="'.$id.'">';
|
|
|
|
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="border centpercent">';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Account number
|
2019-11-13 19:35:02 +01:00
|
|
|
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>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Label
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td>';
|
|
|
|
|
print '<td><input name="label" size="70" value="'.$object->label.'"</td></tr>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2020-01-03 22:05:49 +01:00
|
|
|
// Label short
|
2020-04-10 10:59:32 +02:00
|
|
|
print '<tr><td>'.$langs->trans("LabelToShow").'</td>';
|
|
|
|
|
print '<td><input name="labelshort" size="70" value="'.$object->labelshort.'"</td></tr>';
|
2020-01-03 22:05:49 +01:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Account parent
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td>'.$langs->trans("Accountparent").'</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2017-05-25 06:57:28 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
// Chart of accounts type
|
2021-04-13 09:46:50 +02:00
|
|
|
print '<tr><td>';
|
|
|
|
|
print $form->textwithpicto($langs->trans("Pcgtype"), $langs->transnoentitiesnoconv("PcgtypeDesc"));
|
|
|
|
|
print '</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2021-08-17 20:02:19 +02:00
|
|
|
print '<input type="text" name="pcg_type" list="pcg_type_datalist" value="'.dol_escape_htmltag(GETPOSTISSET('pcg_type') ? GETPOST('pcg_type', 'alpha') : $object->pcg_type).'">';
|
|
|
|
|
// autosuggest from existing account types if found
|
|
|
|
|
print '<datalist id="pcg_type_datalist">';
|
|
|
|
|
$sql = 'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX . 'accounting_account';
|
2021-08-27 22:42:04 +02:00
|
|
|
$sql .= " WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) . "'";
|
2021-08-17 20:02:19 +02:00
|
|
|
$sql .= ' AND entity in ('.getEntity('accounting_account', 0).')'; // Always limit to current entity. No sharing in accountancy.
|
|
|
|
|
$sql .= ' LIMIT 50000'; // just as a sanity check
|
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
if ($resql) {
|
|
|
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
|
|
|
print '<option value="' . dol_escape_htmltag($obj->pcg_type) . '">';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
print '</datalist>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2020-12-30 12:07:42 +01:00
|
|
|
// Category
|
2021-04-13 09:46:50 +02:00
|
|
|
print '<tr><td>';
|
|
|
|
|
print $form->textwithpicto($langs->trans("AccountingCategory"), $langs->transnoentitiesnoconv("AccountingAccountGroupsDesc"));
|
|
|
|
|
print '</td>';
|
2014-08-27 07:03:42 +02:00
|
|
|
print '<td>';
|
2020-12-30 12:07:42 +01:00
|
|
|
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</table>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2020-10-27 18:19:31 +01:00
|
|
|
print dol_get_fiche_end();
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2021-08-20 14:41:30 +02:00
|
|
|
print $form->buttonsSaveCancel();
|
2017-05-25 05:40:41 +02:00
|
|
|
|
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
|
2019-11-13 19:35:02 +01:00
|
|
|
$linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/account.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2022-05-07 06:43:23 +02:00
|
|
|
print dol_get_fiche_head($head, 'card', $langs->trans('AccountAccounting'), -1, 'accounting_account');
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2018-01-11 17:06:06 +01:00
|
|
|
dol_banner_tab($object, 'ref', $linkback, 1, 'account_number', 'ref');
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2018-01-11 17:06:06 +01:00
|
|
|
|
|
|
|
|
print '<div class="fichecenter">';
|
|
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
|
|
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="border centpercent">';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
|
|
|
|
// Label
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("Label").'</td>';
|
|
|
|
|
print '<td colspan="2">'.$object->label.'</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2020-01-03 22:05:49 +01:00
|
|
|
// Label to show
|
2020-04-10 10:59:32 +02:00
|
|
|
print '<tr><td class="titlefield">'.$langs->trans("LabelToShow").'</td>';
|
|
|
|
|
print '<td colspan="2">'.$object->labelshort.'</td></tr>';
|
2020-01-03 22:05:49 +01:00
|
|
|
|
2016-03-28 13:51:19 +02:00
|
|
|
// Account parent
|
2014-08-27 07:03:42 +02:00
|
|
|
$accp = new AccountingAccount($db);
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!empty($object->account_parent)) {
|
2016-03-28 21:03:47 +02:00
|
|
|
$accp->fetch($object->account_parent, '');
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
2019-11-13 19:35:02 +01: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
|
|
|
|
2021-04-13 09:46:50 +02:00
|
|
|
// Group of accounting account
|
|
|
|
|
print '<tr><td>';
|
|
|
|
|
print $form->textwithpicto($langs->trans("Pcgtype"), $langs->transnoentitiesnoconv("PcgtypeDesc"));
|
|
|
|
|
print '</td>';
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<td colspan="2">'.$object->pcg_type.'</td></tr>';
|
2016-03-28 13:51:19 +02:00
|
|
|
|
2021-04-13 09:46:50 +02:00
|
|
|
// Custom group of accounting account
|
|
|
|
|
print "<tr><td>";
|
|
|
|
|
print $form->textwithpicto($langs->trans("AccountingCategory"), $langs->transnoentitiesnoconv("AccountingAccountGroupsDesc"));
|
|
|
|
|
print "</td><td colspan='2'>".$object->account_category_label."</td>";
|
|
|
|
|
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</table>';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2018-01-11 17:06:06 +01:00
|
|
|
print '</div>';
|
|
|
|
|
|
2020-10-27 18:19:31 +01:00
|
|
|
print dol_get_fiche_end();
|
2017-05-25 05:40:41 +02:00
|
|
|
|
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">';
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!empty($user->rights->accounting->chartofaccount)) {
|
2021-12-18 23:02:31 +01:00
|
|
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=update&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Modify').'</a>';
|
2014-08-27 07:03:42 +02:00
|
|
|
} else {
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2019-11-13 19:35:02 +01:00
|
|
|
if (!empty($user->rights->accounting->chartofaccount)) {
|
2021-12-18 23:02:31 +01:00
|
|
|
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Delete').'</a>';
|
2014-08-27 07:03:42 +02:00
|
|
|
} else {
|
2019-11-13 19:35:02 +01:00
|
|
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
2017-05-25 05:40:41 +02:00
|
|
|
|
2014-08-27 07:03:42 +02:00
|
|
|
print '</div>';
|
|
|
|
|
}
|
2016-02-01 15:07:12 +01:00
|
|
|
} else {
|
2018-01-11 17:06:06 +01:00
|
|
|
dol_print_error($db, $object->error, $object->errors);
|
2014-08-27 07:03:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-28 14:02:33 +02:00
|
|
|
// End of page
|
2015-12-11 12:29:19 +01:00
|
|
|
llxFooter();
|
2018-05-26 23:52:52 +02:00
|
|
|
$db->close();
|