* Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * 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/card.php * \ingroup Accounting Expert * \brief Card accounting account */ require '../../main.inc.php'; // Class 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'; $error=0; // Langs $langs->load("bills"); $langs->load("accountancy"); $mesg = ''; $action = GETPOST('action'); $id = GETPOST('id', 'int'); $rowid = GETPOST('rowid', 'int'); $cancel = GETPOST('cancel'); // Security check if (!$user->admin) accessforbidden(); $accounting = new AccountingAccount($db); // Action if ($action == 'add') { if (! $cancel) { $sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS; dol_syslog('accountancy/admin/card.php:: $sql=' . $sql); $result = $db->query($sql); $obj = $db->fetch_object($result); $accounting->fk_pcg_version = $obj->pcg_version; $accounting->pcg_type = GETPOST('pcg_type'); $accounting->pcg_subtype = GETPOST('pcg_subtype'); $accounting->account_number = GETPOST('account_number'); $accounting->account_parent = GETPOST('account_parent', 'int'); $accounting->label = GETPOST('label', 'alpha'); $accounting->active = 1; $res = $accounting->create($user); if ($res == 0) { } else { if ($res == - 3) { $error = 1; $action = "create"; } if ($res == - 4) { $error = 2; $action = "create"; } } } Header("Location: account.php"); } else if ($action == 'edit') { if (! GETPOST('cancel', 'alpha')) { $result = $accounting->fetch($id); $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); $accounting->fk_pcg_version = $obj->pcg_version; $accounting->pcg_type = GETPOST('pcg_type'); $accounting->pcg_subtype = GETPOST('pcg_subtype'); $accounting->account_number = GETPOST('account_number'); $accounting->account_parent = GETPOST('account_parent', 'int'); $accounting->label = GETPOST('label', 'alpha'); $result = $accounting->update($user); if ($result > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit(); } else { $mesg = $object->error; } } else { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit(); } } else if ($action == 'delete') { $result = $accounting->fetch($id); if (! empty($accounting->id)) { $result = $accounting->delete($user); if ($result > 0) { Header("Location: account.php"); } } if ($result < 0) { setEventMessage($accounting->error, 'errors'); } } /* * View */ llxheader('', $langs->trans('AccountAccounting')); $form = new Form($db); $htmlacc = new FormVentilation($db); if ($action == 'create') { print_fiche_titre($langs->trans('NewAccount')); print '
' . "\n"; print ''; print ''; dol_fiche_head(); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; print $htmlacc->select_account($accounting->account_parent, 'account_parent'); print '
' . $langs->trans("Pcgtype") . ''; print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } else if ($id) { $rowid = $id; $account = $accounting->fetch($rowid); if ($account > 0) { dol_htmloutput_mesg($mesg); $head = accounting_prepare_head($accounting); if ($action == 'update') { $soc = new Societe($db); if ($object->socid) { $soc->fetch($object->socid); } dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr'); print '
' . "\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; print $htmlacc->select_account($accounting->account_parent, 'account_parent'); print '
' . $langs->trans("Pcgtype") . ''; print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); print '
' . $langs->trans("Pcgsubtype") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } else { $linkback = '' . $langs->trans("BackToChartofaccounts") . ''; dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr'); print ''; // Account number print ''; print ''; print ''; print ''; print ''; $accp = new AccountingAccount($db); if (! empty($accounting->account_parent)) { $accp->fetch($accounting->account_parent, ''); } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans("AccountNumber") . '' . $accounting->account_number . '' . $linkback . '
' . $langs->trans("Label") . '' . $accounting->label . '
' . $langs->trans("Accountparent") . '' . $accp->account_number . ' - ' . $accp->label . '
' . $langs->trans("Pcgtype") . '' . $accounting->pcg_type . '
' . $langs->trans("Pcgsubtype") . '' . $accounting->pcg_subtype . '
' . $langs->trans("Activated") . ''; if (empty($accounting->active)) { print img_picto($langs->trans("Disabled"), 'switch_off'); } else { print img_picto($langs->trans("Activated"), 'switch_on'); } print '
'; dol_fiche_end(); /* * Barre d'actions */ print '
'; if ($user->admin) { print '' . $langs->trans('Modify') . ''; } else { print '' . $langs->trans('Modify') . ''; } if ($user->admin) { print '' . $langs->trans('Delete') . ''; } else { print '' . $langs->trans('Delete') . ''; } print '
'; } } else { dol_print_error($db); } } $db->close(); llxFooter();