*
* 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/fiscalyear_card.php
* \ingroup Advanced accountancy
* \brief Page to show a fiscal year
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/fiscalyear.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php';
$langs->load("admin");
$langs->load("compta");
// Security check
if ($user->societe_id > 0)
accessforbidden();
if (empty($user->rights->accounting->fiscalyear))
accessforbidden();
$error = 0;
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$id = GETPOST('id', 'int');
// List of statut
static $tmpstatut2label = array (
'0' => 'OpenFiscalYear',
'1' => 'CloseFiscalYear'
);
$statut2label = array (
''
);
foreach ( $tmpstatut2label as $key => $val )
$statut2label[$key] = $langs->trans($val);
$object = new Fiscalyear($db);
$date_start = dol_mktime(0, 0, 0, GETPOST('fiscalyearmonth', 'int'), GETPOST('fiscalyearday', 'int'), GETPOST('fiscalyearyear', 'int'));
$date_end = dol_mktime(0, 0, 0, GETPOST('fiscalyearendmonth', 'int'), GETPOST('fiscalyearendday', 'int'), GETPOST('fiscalyearendyear', 'int'));
/*
* Actions
*/
if ($action == 'confirm_delete' && $confirm == "yes") {
$result = $object->delete($id);
if ($result >= 0) {
header("Location: fiscalyear.php");
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
else if ($action == 'add') {
if (! GETPOST('cancel', 'alpha')) {
$error = 0;
$object->date_start = $date_start;
$object->date_end = $date_end;
$object->label = GETPOST('label', 'alpha');
$object->statut = GETPOST('statut', 'int');
$object->datec = dol_now();
if (empty($object->date_start) && empty($object->date_end)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
$error ++;
}
if (empty($object->label)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
$error ++;
}
if (! $error) {
$db->begin();
$id = $object->create($user);
if ($id > 0) {
$db->commit();
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit();
} else {
$db->rollback();
setEventMessages($object->error, $object->errors, 'errors');
$action = 'create';
}
} else {
$action = 'create';
}
} else {
header("Location: ./fiscalyear.php");
exit();
}
}
// Update record
else if ($action == 'update') {
if (! GETPOST('cancel', 'alpha')) {
$result = $object->fetch($id);
$object->date_start = empty($_POST["fiscalyear"]) ? '' : $date_start;
$object->date_end = empty($_POST["fiscalyearend"]) ? '' : $date_end;
$object->label = GETPOST('label', 'alpha');
$object->statut = GETPOST('statut', 'int');
$result = $object->update($user);
if ($result > 0) {
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit();
}
}
/*
* View
*/
$form = new Form($db);
$title = $langs->trans("Fiscalyear") . " - " . $langs->trans("Card");
$helpurl = "";
llxHeader("",$title,$helpurl);
if ($action == 'create')
{
print load_fiche_titre($langs->trans("NewFiscalYear"));
print '
';
} else if ($id) {
$result = $object->fetch($id);
if ($result > 0) {
$head = fiscalyear_prepare_head($object);
if ($action == 'edit') {
dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
print '';
dol_fiche_end();
} else {
/*
* Confirm delete
*/
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $id, $langs->trans("DeleteFiscalYear"), $langs->trans("ConfirmDeleteFiscalYear"), "confirm_delete");
}
dol_fiche_head($head, 'card', $langs->trans("Fiscalyear"), 0, 'cron');
print '';
$linkback = '' . $langs->trans("BackToList") . '';
// Ref
print '' . $langs->trans("Ref") . ' | ';
print $object->ref;
print ' | ';
print $linkback;
print ' |
';
// Label
print '';
print $form->editfieldkey("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
print ' | ';
print $form->editfieldval("Label", 'label', $object->label, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'alpha:32');
print " |
";
// Date start
print '';
print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
print ' | ';
print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
print ' |
';
// Date end
print '';
print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
print ' | ';
print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker');
print ' |
';
// Statut
print '' . $langs->trans("Status") . ' | ' . $object->getLibStatut(4) . ' |
';
print "
";
dol_fiche_end();
if (! empty($user->rights->accounting->fiscalyear))
{
/*
* Barre d'actions
*/
print '';
}
}
} else {
dol_print_error($db);
}
}
llxFooter();
$db->close();