27require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/fiscalyear.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
40$langs->loadLangs(array(
"admin",
"compta"));
46$action =
GETPOST(
'action',
'aZ09');
47$confirm =
GETPOST(
'confirm',
'alpha');
48$cancel =
GETPOST(
'cancel',
'alpha');
49$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') : str_replace(
'_',
'', basename(dirname(__FILE__)).basename(__FILE__,
'.php'));
50$backtopage =
GETPOST(
'backtopage',
'alpha');
51$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
52$dol_openinpopup =
GETPOST(
'dol_openinpopup',
'aZ09');
60include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
65$permissiontoadd = $user->hasRight(
'accounting',
'fiscalyear',
'write');
66$permissiontodelete = $user->hasRight(
'accounting',
'fiscalyear',
'write');
69if ($user->socid > 0) {
72if (!$permissiontoadd) {
82$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
84 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
88 if ($action ==
'confirm_delete' && $confirm ==
"yes") {
91 $result =
$object->delete($user);
93 header(
"Location: fiscalyear.php");
98 } elseif ($action ==
'add') {
99 if (!
GETPOST(
'cancel',
'alpha')) {
109 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
113 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
125 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
131 if ($id == -5 && !empty(
$object->errors[0])) {
132 setEventMessages($langs->trans(
$object->error,
$object->errors[0]),
null,
'errors');
142 header(
"Location: ".DOL_URL_ROOT.
'/accountancy/admin/fiscalyear.php');
145 } elseif ($action ==
'update') {
147 if (!
GETPOST(
'cancel',
'alpha')) {
155 $result =
$object->update($user);
158 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
162 if ($result == -5 && !empty(
$object->errors[0])) {
163 setEventMessages($langs->trans(
$object->error,
$object->errors[0]),
null,
'errors');
169 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
172 } elseif ($action ==
'reopen') {
178 $result =
$object->update($user);
181 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
195$form =
new Form($db);
197$title = $langs->trans(
"Fiscalyear").
" - ".$langs->trans(
"Card");
198if ($action ==
'create') {
199 $title = $langs->trans(
"NewFiscalYear");
202$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
204llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-fiscalyear_card');
212 $sql =
"SELECT MAX(date_end) as date_end FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear";
213 $sql .=
" WHERE entity = ".((int)
$conf->entity);
214 $resql = $db->query($sql);
216 $obj = $db->fetch_object($resql);
217 if ($obj && !empty($obj->date_end)) {
218 $lastend = $db->jdate($obj->date_end);
228 $startmonth = max(1, min(12,
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)));
230 $startyear = ($startmonth > $now[
'mon']) ? $now[
'year'] - 1 : $now[
'year'];
231 $defaultstart =
dol_mktime(12, 0, 0, $startmonth, 1, $startyear);
240 $defaultlabel = ($ys == $ye) ? (
string) $ys : $ys.
'-'.$ye;
243if ($action ==
'create') {
246 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
247 print
'<input type="hidden" name="token" value="'.newToken().
'">';
248 print
'<input type="hidden" name="action" value="add">';
252 print
'<table class="border centpercent tableforfieldcreate">';
255 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Label").
'</td><td>';
256 print
'<input name="label" id="label" size="32" value="'.dol_escape_htmltag(
GETPOST(
'label',
'alpha') ?
GETPOST(
'label',
'alpha') : $defaultlabel).
'">';
260 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DateStart").
'</td><td>';
265 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td><td>';
266 print $form->selectDate($date_end ? $date_end : ($defaultend ? $defaultend : -1),
'fiscalyearend');
278 print
'</table>'.
"\n";
282 $labelposted =
GETPOST(
'label',
'alpha') ? 1 : 0;
284 jQuery(document).ready(function() {
285 // The label is "touched" only if the user typed it (or it was posted back after an error)
286 var labelTouched = '.((int) $labelposted).
';
287 jQuery("#label").on("input", function() { labelTouched = true; });
289 function readDate(prefix) {
290 var d = parseInt(jQuery("#" + prefix + "day").val());
291 var m = parseInt(jQuery("#" + prefix + "month").val());
292 var y = parseInt(jQuery("#" + prefix + "year").val());
293 if (!d || !m || !y) return null;
294 return new Date(y, m - 1, d);
297 function updateLabel() {
298 if (labelTouched) return;
299 var start = readDate("fiscalyear");
300 var end = readDate("fiscalyearend");
301 if (!start || !end) return;
302 var ys = start.getFullYear(), ye = end.getFullYear();
303 jQuery("#label").val(ys === ye ? ys : ys + "-" + ye);
306 function updateEndFromStart() {
307 var start = readDate("fiscalyear");
309 var end = new Date(start.getFullYear() + 1, start.getMonth(), start.getDate() - 1);
310 jQuery("#fiscalyearendday").val(end.getDate());
311 jQuery("#fiscalyearendmonth").val(end.getMonth() + 1);
312 jQuery("#fiscalyearendyear").val(end.getFullYear());
313 jQuery("#fiscalyearend").datepicker("setDate", end);
317 jQuery("#fiscalyear").on("change", function() { setTimeout(updateEndFromStart, 100); });
318 jQuery("#fiscalyearend").on("change", function() { setTimeout(updateLabel, 100); });
322 print $form->buttonsSaveCancel(
"Create");
330if (($id || $ref) && $action ==
'edit') {
331 print
load_fiche_titre($langs->trans(
"Fiscalyear"),
'',
'object_'.$object->picto);
333 print
'<form method="POST" name="update" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
334 print
'<input type="hidden" name="token" value="'.newToken().
'">';
335 print
'<input type="hidden" name="action" value="update">';
336 print
'<input type="hidden" name="status" value="' .
$object->status .
'">';
337 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
339 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
341 if ($backtopageforcancel) {
342 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
347 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
351 print
'<td class="titlefieldcreate titlefield">'.$langs->trans(
"Ref").
'</td><td>';
356 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Label").
'</td><td>';
357 print
'<input name="label" class="flat" size="32" value="'.dolPrintHTMLForAttribute(
$object->label).
'">';
361 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DateStart").
'</td><td>';
362 print $form->selectDate(
$object->date_start ?
$object->date_start : -1,
'fiscalyear');
366 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td><td>';
367 print $form->selectDate(
$object->date_end ?
$object->date_end : -1,
'fiscalyearend');
371 print
'<tr><td>'.$langs->trans(
"Status").
'</td><td>';
372 print
$object->getLibStatut(4);
379 print $form->buttonsSaveCancel();
385if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
390 $morehtmlref =
'<div class="refidno">';
391 $morehtmlref .=
'</div>';
396 if ($action ==
'delete') {
397 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$object->id, $langs->trans(
"DeleteFiscalYear"), $langs->trans(
"ConfirmDeleteFiscalYear"),
"confirm_delete",
'', 0, 1);
405 $linkback =
'<a href="'.DOL_URL_ROOT.
'/accountancy/admin/fiscalyear.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
407 dol_banner_tab($object,
'label', $linkback, 1,
'label',
'label', $morehtmlref);
409 print
'<div class="fichecenter">';
410 print
'<div class="fichehalfleft">';
411 print
'<div class="underbanner clearboth"></div>';
412 print
'<table class="border centpercent tableforfield">'.
"\n";
416 print
'<td class="titlefield">'.$langs->trans(
"Id").
'</td><td>';
421 print
'<tr><td class="tdtop">';
422 print $form->editfieldkey(
"Label",
'label',
$object->label, $object, 0,
'alpha:32');
424 print $form->editfieldval(
"Label",
'label',
$object->label, $object, 0,
'alpha:32');
429 print $form->editfieldkey(
"DateStart",
'date_start', (
string)
$object->date_start, $object, 0,
'datepicker');
431 print $form->editfieldval(
"DateStart",
'date_start',
$object->date_start, $object, 0,
'datepicker');
436 print $form->editfieldkey(
"DateEnd",
'date_end', (
string)
$object->date_end, $object, 0,
'datepicker');
438 print $form->editfieldval(
"DateEnd",
'date_end',
$object->date_end, $object, 0,
'datepicker');
446 print
'<div class="clearboth"></div>';
454 if ($user->hasRight(
'accounting',
'fiscalyear',
'write')) {
455 print
'<div class="tabsAction">';
458 print dolGetButtonAction($langs->trans(
"ReOpen"),
'',
'reopen', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken(),
'reopen', (
int) $permissiontoadd);
461 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'&id='.
$id.
'">'.$langs->trans(
'Modify').
'</a>';
463 print dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'delete', (
int) $permissiontodelete);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage fiscal year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
fiscalyear_prepare_head(Fiscalyear $object)
Prepare array with list of tabs.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_set_focus($selector, $nooutput=0)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.