26require 
'../../main.inc.php';
 
   28require_once DOL_DOCUMENT_ROOT.
'/core/lib/fiscalyear.lib.php';
 
   29require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
 
   32$langs->loadLangs(array(
"admin", 
"compta"));
 
   38$action = 
GETPOST(
'action', 
'aZ09');
 
   39$confirm = 
GETPOST(
'confirm', 
'alpha');
 
   40$cancel = 
GETPOST(
'cancel', 
'aZ09');
 
   41$contextpage = 
GETPOST(
'contextpage', 
'aZ') ? 
GETPOST(
'contextpage', 
'aZ') : str_replace(
'_', 
'', basename(dirname(__FILE__)).basename(__FILE__, 
'.php')); 
 
   42$backtopage = 
GETPOST(
'backtopage', 
'alpha');         
 
   43$backtopageforcancel = 
GETPOST(
'backtopageforcancel', 
'alpha'); 
 
   44$backtopagejsfields = 
GETPOST(
'backtopagejsfields', 
'alpha');
 
   45$dol_openinpopup = 
GETPOST(
'dol_openinpopup', 
'aZ09');
 
   47if (!empty($backtopagejsfields)) {
 
   48  $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
 
   49  $dol_openinpopup = $tmpbacktopagejsfields[0];
 
   59include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php'; 
 
   62static $tmpstatus2label = array(
 
   63    '0' => 
'OpenFiscalYear',
 
   64    '1' => 
'CloseFiscalYear' 
   69foreach ($tmpstatus2label as $key => $val) {
 
   70  $status2label[$key] = $langs->trans($val);
 
   76$permissiontoadd = $user->hasRight(
'accounting', 
'fiscalyear', 
'write');
 
   79if ($user->socid > 0) {
 
   82if (!$permissiontoadd) {
 
   92$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action); 
 
   97if ($action == 
'confirm_delete' && $confirm == 
"yes" && $permissiontoadd) {
 
   98  $result = $object->delete($id);
 
  100    header(
"Location: fiscalyear.php");
 
  105} elseif ($action == 
'add' && $permissiontoadd) {
 
  106  if (!
GETPOST(
'cancel', 
'alpha')) {
 
  109    $object->date_start = $date_start;
 
  110    $object->date_end = $date_end;
 
  111    $object->label = 
GETPOST(
'label', 
'alpha');
 
  112    $object->status = 
GETPOST(
'status', 
'int');
 
  115    if (empty($object->date_start) && empty($object->date_end)) {
 
  116      setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), 
null, 
'errors');
 
  119    if (empty($object->label)) {
 
  120      setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")), 
null, 
'errors');
 
  127      $id = $object->create($user);
 
  132        header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
 
  144    header(
"Location: ./fiscalyear.php");
 
  147} elseif ($action == 
'update' && $permissiontoadd) {
 
  149  if (!
GETPOST(
'cancel', 
'alpha')) {
 
  150    $result = $object->fetch($id);
 
  152    $object->date_start = 
GETPOST(
"fiscalyear") ? $date_start : 
'';
 
  153    $object->date_end = 
GETPOST(
"fiscalyearend") ? $date_end : 
'';
 
  154    $object->label = 
GETPOST(
'label', 
'alpha');
 
  155    $object->status = 
GETPOST(
'status', 
'int');
 
  157    $result = $object->update($user);
 
  160      header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
 
  166    header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
 
  169} elseif ($action == 
'reopen' && $permissiontoadd && 
getDolGlobalString(
'ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) {
 
  170  $result = $object->fetch($id);
 
  172  $object->status = 
GETPOST(
'status', 
'int');
 
  173  $result = $object->update($user);
 
  176    header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
 
  188$form = 
new Form($db);
 
  190$title = $langs->trans(
"Fiscalyear").
" - ".$langs->trans(
"Card");
 
  191if ($action == 
'create') {
 
  192  $title = $langs->trans(
"NewFiscalYear");
 
  195$help_url = 
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
 
  199if ($action == 
'create') {
 
  202  print 
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
 
  203  print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  204  print 
'<input type="hidden" name="action" value="add">';
 
  208  print 
'<table class="border centpercent">';
 
  211  print 
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Label").
'</td><td><input name="label" size="32" value="'.
GETPOST(
'label', 
'alpha').
'"></td></tr>';
 
  214  print 
'<tr><td class="fieldrequired">'.$langs->trans(
"DateStart").
'</td><td>';
 
  215  print $form->selectDate(($date_start ? $date_start : 
''), 
'fiscalyear');
 
  219  print 
'<tr><td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td><td>';
 
  220  print $form->selectDate(($date_end ? $date_end : - 1), 
'fiscalyearend');
 
  236  print $form->buttonsSaveCancel(
"Create");
 
  243if (($id || $ref) && $action == 
'edit') {
 
  244  print 
load_fiche_titre($langs->trans(
"Fiscalyear"), 
'', 
'object_'.$object->picto);
 
  246  print 
'<form method="POST" name="update" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
 
  247  print 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  248  print 
'<input type="hidden" name="action" value="update">';
 
  249  print 
'<input type="hidden" name="id" value="'.$object->id.
'">';
 
  251    print 
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
 
  253  if ($backtopageforcancel) {
 
  254    print 
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
 
  259  print 
'<table class="border centpercent tableforfieldedit">'.
"\n";
 
  263  print 
'<td class="titlefieldcreate titlefield">'.$langs->trans(
"Ref").
'</td><td>';
 
  268  print 
'<tr><td class="fieldrequired">'.$langs->trans(
"Label").
'</td><td>';
 
  269  print 
'<input name="label" class="flat" size="32" value="'.$object->label.
'">';
 
  273  print 
'<tr><td class="fieldrequired">'.$langs->trans(
"DateStart").
'</td><td>';
 
  274  print $form->selectDate($object->date_start ? $object->date_start : - 1, 
'fiscalyear');
 
  278  print 
'<tr><td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td><td>';
 
  279  print $form->selectDate($object->date_end ? $object->date_end : - 1, 
'fiscalyearend');
 
  283  print 
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
 
  284  print $object->getLibStatut(4);
 
  291  print $form->buttonsSaveCancel();
 
  297if ($object->id > 0 && (empty($action) || ($action != 
'edit' && $action != 
'create'))) {
 
  305  if ($action == 
'delete') {
 
  306    $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"DeleteFiscalYear"), $langs->trans(
"ConfirmDeleteFiscalYear"), 
"confirm_delete", 
'', 0, 1);
 
  314  $linkback = 
'<a href="'.DOL_URL_ROOT.
'/accountancy/admin/fiscalyear.php">'.$langs->trans(
"BackToList").
'</a>';
 
  316  print 
'<table class="border centpercent">';
 
  319  print 
'<tr><td class="titlefield">'.$langs->trans(
"Ref").
'</td><td width="50%">';
 
  326  print 
'<tr><td class="tdtop">';
 
  327  print $form->editfieldkey(
"Label", 
'label', $object->label, $object, 0, 
'alpha:32');
 
  328  print 
'</td><td colspan="2">';
 
  329  print $form->editfieldval(
"Label", 
'label', $object->label, $object, 0, 
'alpha:32');
 
  334  print $form->editfieldkey(
"DateStart", 
'date_start', $object->date_start, $object, 0, 
'datepicker');
 
  335  print 
'</td><td colspan="2">';
 
  336  print $form->editfieldval(
"DateStart", 
'date_start', $object->date_start, $object, 0, 
'datepicker');
 
  341  print $form->editfieldkey(
"DateEnd", 
'date_end', $object->date_end, $object, 0, 
'datepicker');
 
  342  print 
'</td><td colspan="2">';
 
  343  print $form->editfieldval(
"DateEnd", 
'date_end', $object->date_end, $object, 0, 
'datepicker');
 
  347  print 
'<tr><td>'.$langs->trans(
"Status").
'</td><td colspan="2">'.$object->getLibStatut(4).
'</td></tr>';
 
  356  if ($user->hasRight(
'accounting', 
'fiscalyear', 
'write')) {
 
  357    print 
'<div class="tabsAction">';
 
  359    if (
getDolGlobalString(
'ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) {
 
  360      print 
dolGetButtonAction($langs->trans(
"ReOpen"), 
'', 
'reopen', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken(), 
'reopen', $permissiontoadd);
 
  363    print 
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'&id='.$id.
'">'.$langs->trans(
'Modify').
'</a>';
 
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
 
Class to manage fiscal year.
 
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
 
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
 
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
 
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
 
dol_get_fiche_end($notab=0)
Return tab footer of a card.
 
dol_now($mode='auto')
Return date for now.
 
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.