FIX: Accountancy - Add control on required fields when we create an account
This commit is contained in:
parent
74ba7e68da
commit
5606542220
@ -32,7 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
|
|||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array("bills", "accountancy"));
|
$langs->loadLangs(array("bills", "accountancy", "compta"));
|
||||||
|
|
||||||
$mesg = '';
|
$mesg = '';
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
@ -41,7 +41,9 @@ $id = GETPOST('id', 'int');
|
|||||||
$ref = GETPOST('ref', 'alpha');
|
$ref = GETPOST('ref', 'alpha');
|
||||||
$rowid = GETPOST('rowid', 'int');
|
$rowid = GETPOST('rowid', 'int');
|
||||||
$cancel = GETPOST('cancel', 'alpha');
|
$cancel = GETPOST('cancel', 'alpha');
|
||||||
$accountingaccount = GETPOST('accountingaccount', 'alpha');
|
|
||||||
|
$account_number = GETPOST('account_number', 'string');
|
||||||
|
$label = GETPOST('label', 'alpha');
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
if ($user->socid > 0) accessforbidden();
|
if ($user->socid > 0) accessforbidden();
|
||||||
@ -65,104 +67,118 @@ if (GETPOST('cancel', 'alpha'))
|
|||||||
if ($action == 'add' && $user->rights->accounting->chartofaccount)
|
if ($action == 'add' && $user->rights->accounting->chartofaccount)
|
||||||
{
|
{
|
||||||
if (!$cancel) {
|
if (!$cancel) {
|
||||||
$sql = 'SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$conf->global->CHARTOFACCOUNTS;
|
if (!$account_number)
|
||||||
|
|
||||||
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', 'string');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors');
|
||||||
|
$action = 'create';
|
||||||
|
} elseif (!$label)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
|
||||||
|
$action = 'create';
|
||||||
} else {
|
} else {
|
||||||
$account_number = clean_account(GETPOST('account_number', 'string'));
|
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
|
||||||
}
|
|
||||||
|
|
||||||
if (GETPOST('account_parent', 'int') <= 0)
|
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
|
||||||
{
|
$result = $db->query($sql);
|
||||||
$account_parent = 0;
|
$obj = $db->fetch_object($result);
|
||||||
} else {
|
|
||||||
$account_parent = GETPOST('account_parent', 'int');
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->fk_pcg_version = $obj->pcg_version;
|
// Clean code
|
||||||
$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 = GETPOST('label', 'alpha');
|
|
||||||
$object->labelshort = GETPOST('labelshort', 'alpha');
|
|
||||||
$object->active = 1;
|
|
||||||
|
|
||||||
$res = $object->create($user);
|
// To manage zero or not at the end of the accounting account
|
||||||
if ($res == - 3) {
|
if ($conf->global->ACCOUNTING_MANAGE_ZERO == 1) {
|
||||||
$error = 1;
|
$account_number = $account_number;
|
||||||
$action = "create";
|
} else {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
$account_number = clean_account($account_number);
|
||||||
} elseif ($res == - 4) {
|
}
|
||||||
$error = 2;
|
|
||||||
$action = "create";
|
if (GETPOST('account_parent', 'int') <= 0) {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
$account_parent = 0;
|
||||||
} elseif ($res < 0)
|
} else {
|
||||||
{
|
$account_parent = GETPOST('account_parent', 'int');
|
||||||
$error++;
|
}
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
|
||||||
$action = "create";
|
$object->fk_pcg_version = $obj->pcg_version;
|
||||||
}
|
$object->pcg_type = GETPOST('pcg_type', 'alpha');
|
||||||
if (!$error)
|
$object->account_number = $account_number;
|
||||||
{
|
$object->account_parent = $account_parent;
|
||||||
setEventMessages("RecordCreatedSuccessfully", null, 'mesgs');
|
$object->account_category = GETPOST('account_category', 'alpha');
|
||||||
$urltogo = $backtopage ? $backtopage : dol_buildpath('/accountancy/admin/account.php', 1);
|
$object->label = $label;
|
||||||
header("Location: ".$urltogo);
|
$object->labelshort = GETPOST('labelshort', 'alpha');
|
||||||
exit;
|
$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');
|
||||||
|
$urltogo = $backtopage ? $backtopage : dol_buildpath('/accountancy/admin/account.php', 1);
|
||||||
|
header("Location: " . $urltogo);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($action == 'edit' && $user->rights->accounting->chartofaccount) {
|
} elseif ($action == 'edit' && $user->rights->accounting->chartofaccount) {
|
||||||
if (!$cancel) {
|
if (!$cancel) {
|
||||||
$result = $object->fetch($id);
|
if (!$account_number)
|
||||||
|
|
||||||
$sql = 'SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$conf->global->CHARTOFACCOUNTS;
|
|
||||||
|
|
||||||
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
|
|
||||||
if ($conf->global->ACCOUNTING_MANAGE_ZERO == 1)
|
|
||||||
{
|
{
|
||||||
$account_number = GETPOST('account_number', 'string');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors');
|
||||||
} else {
|
$action = 'update';
|
||||||
$account_number = clean_account(GETPOST('account_number', 'string'));
|
} elseif (!$label)
|
||||||
}
|
|
||||||
|
|
||||||
if (GETPOST('account_parent', 'int') <= 0)
|
|
||||||
{
|
{
|
||||||
$account_parent = 0;
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
|
||||||
|
$action = 'update';
|
||||||
} else {
|
} else {
|
||||||
$account_parent = GETPOST('account_parent', 'int');
|
$result = $object->fetch($id);
|
||||||
}
|
|
||||||
|
|
||||||
$object->fk_pcg_version = $obj->pcg_version;
|
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
|
||||||
$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 = GETPOST('label', 'alpha');
|
|
||||||
$object->labelshort = GETPOST('labelshort', 'alpha');
|
|
||||||
|
|
||||||
$result = $object->update($user);
|
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
|
||||||
|
$result2 = $db->query($sql);
|
||||||
|
$obj = $db->fetch_object($result2);
|
||||||
|
|
||||||
if ($result > 0) {
|
// Clean code
|
||||||
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"]."?id=".$id);
|
|
||||||
header("Location: ".$urltogo);
|
// To manage zero or not at the end of the accounting account
|
||||||
exit();
|
if ($conf->global->ACCOUNTING_MANAGE_ZERO == 1) {
|
||||||
} else {
|
$account_number = $account_number;
|
||||||
$mesg = $object->error;
|
} 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);
|
||||||
|
|
||||||
|
if ($result > 0) {
|
||||||
|
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"] . "?id=" . $id);
|
||||||
|
header("Location: " . $urltogo);
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
$mesg = $object->error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"]."?id=".$id);
|
$urltogo = $backtopage ? $backtopage : ($_SERVER["PHP_SELF"]."?id=".$id);
|
||||||
@ -222,7 +238,7 @@ if ($action == 'create') {
|
|||||||
|
|
||||||
// Account number
|
// Account number
|
||||||
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("AccountNumber").'</span></td>';
|
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("AccountNumber").'</span></td>';
|
||||||
print '<td><input name="account_number" size="30" value="'.$accountingaccount.'"></td></tr>';
|
print '<td><input name="account_number" size="30" value="'.$account_number.'"></td></tr>';
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td>';
|
print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td>';
|
||||||
|
|||||||
@ -323,7 +323,7 @@ if ($action != 'export_csv')
|
|||||||
$root_account_number = $tmparrayforrootaccount['account_number'];
|
$root_account_number = $tmparrayforrootaccount['account_number'];
|
||||||
|
|
||||||
if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) {
|
if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) {
|
||||||
$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=update&token=' . newToken() . '&id=' . $accountingaccountstatic->id . '">' . img_edit() . '</a>';
|
$link = '<a class="editfielda reposition" href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=update&token=' . newToken() . '&id=' . $accountingaccountstatic->id . '">' . img_edit() . '</a>';
|
||||||
} elseif (empty($tmparrayforrootaccount['label'])) {
|
} elseif (empty($tmparrayforrootaccount['label'])) {
|
||||||
$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>';
|
$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user