27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'fiscalyear';
42 public $picto =
'calendar';
47 public $table_element =
'accounting_fiscalyear';
52 public $table_element_line =
'';
57 public $fk_element =
'';
108 const STATUS_OPEN = 0;
109 const STATUS_CLOSED = 1;
121 $this->ismultientitymanaged = 1;
140 if ($checkresult < 0) {
146 $sql =
"INSERT INTO ".$this->db->prefix().
"accounting_fiscalyear (";
148 $sql .=
", date_start";
149 $sql .=
", date_end";
153 $sql .=
", fk_user_author";
154 $sql .=
") VALUES (";
155 $sql .=
" '".$this->db->escape($this->label).
"'";
156 $sql .=
", '".$this->db->idate($this->date_start).
"'";
157 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
159 $sql .=
", ".((int)
$conf->entity);
160 $sql .=
", '".$this->db->idate($now).
"'";
161 $sql .=
", ".((int) $user->id);
164 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
165 $result = $this->db->query($sql);
167 $this->
id = $this->db->last_insert_id($this->db->prefix().
"accounting_fiscalyear");
171 $this->error = $this->db->lasterror().
" sql=".$sql;
172 $this->db->rollback();
186 if (empty($this->date_start) && empty($this->date_end)) {
187 $this->error =
'ErrorBadParameter';
193 if ($checkresult < 0) {
199 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
200 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
201 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
202 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
203 $sql .=
", statut = '".$this->db->escape($this->
status ? (
string) $this->
status :
'0').
"'";
204 $sql .=
", fk_user_modif = ".((int) $user->id);
205 $sql .=
" WHERE rowid = ".((int) $this->
id);
207 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
208 $result = $this->db->query($sql);
213 $this->error = $this->db->lasterror();
215 $this->db->rollback();
228 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
229 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
230 $sql .=
" WHERE rowid = ".((int) $id);
232 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
233 $result = $this->db->query($sql);
235 $obj = $this->db->fetch_object($result);
237 $this->
id = $obj->rowid;
238 $this->
ref = $obj->rowid;
239 $this->date_start = $this->db->jdate($obj->date_start);
240 $this->date_end = $this->db->jdate($obj->date_end);
241 $this->label = $obj->label;
242 $this->statut = $obj->status;
243 $this->
status = $obj->status;
247 $this->error = $this->db->lasterror();
258 public function delete($user)
262 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear";
263 $sql .=
" WHERE rowid = ".((int) $this->
id);
265 $result = $this->db->query($sql);
270 $this->error = $this->db->lasterror();
271 $this->db->rollback();
286 $entity = (!empty($this->entity) ? $this->entity :
$conf->entity);
289 $sql =
"SELECT label";
290 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
291 $sql .=
" WHERE entity = " . ((int) $entity);
292 $sql .=
" AND date_start <= '" . $this->db->idate($this->date_end) .
"'";
293 $sql .=
" AND date_end >= '" . $this->db->idate($this->date_start) .
"'";
296 if (!empty($this->
id)) {
297 $sql .=
" AND rowid != " . ((int) $this->
id);
300 dol_syslog(get_class($this) .
"::checkOverlap", LOG_DEBUG);
302 $result = $this->db->query($sql);
304 if ($this->db->num_rows($result) > 0) {
305 $obj = $this->db->fetch_object($result);
306 $this->error =
'ErrorFiscalYearOverlapWithFiscalYear';
307 $this->errors[] = $obj->label;
312 $this->error = $this->db->lasterror();
327 $langs->load(
'compta');
330 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
331 if (isset($this->
status)) {
332 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
334 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
335 if (isset($this->date_start)) {
336 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
338 if (isset($this->date_start)) {
339 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
353 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
355 global
$conf, $langs, $user;
357 if (empty($this->
ref)) {
358 $this->
ref = (string) $this->
id;
361 if (!empty(
$conf->dol_no_mouse_hover)) {
365 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
371 'objecttype' => $this->element,
375 $classfortooltip =
'classfortooltip';
378 $classfortooltip =
'classforajaxtooltip';
379 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
380 $label =
'ToComplete';
384 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
386 if ($option !==
'nolink') {
388 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
389 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
390 $add_save_lastsearch_values = 1;
392 if ($add_save_lastsearch_values) {
393 $url .=
'&save_lastsearch_values=1';
398 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
400 $label = $langs->trans(
"FiscalPeriod");
401 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
403 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
404 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
407 $linkstart =
'<a href="'.$url.
'"';
408 $linkstart .= $linkclose.
'>';
411 if ($option ===
'nolink') {
416 $result .= $linkstart;
418 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
420 if ($withpicto != 2) {
421 $result .= $this->ref;
450 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
453 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpened');
454 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosed');
455 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpenedShort');
456 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosedShort');
459 $statusType =
'status4';
461 if ($status == self::STATUS_CLOSED) {
462 $statusType =
'status6';
465 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
476 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
477 $sql .=
" fy.tms as datem";
478 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
479 $sql .=
" WHERE fy.rowid = ".((int) $id);
481 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
482 $result = $this->db->query($sql);
485 if ($this->db->num_rows($result)) {
486 $obj = $this->db->fetch_object($result);
488 $this->
id = $obj->rowid;
490 $this->user_creation_id = $obj->fk_user_author;
491 $this->user_modification_id = $obj->fk_user_modif;
492 $this->date_creation = $this->db->jdate($obj->datec);
493 $this->date_modification = $this->db->jdate($obj->datem);
495 $this->db->free($result);
512 if (empty($datestart)) {
513 $datestart = $this->date_start;
515 if (empty($dateend)) {
516 $dateend = $this->date_end;
519 $sql =
"SELECT count(DISTINCT piece_num) as nb";
520 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
521 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
522 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
525 $resql = $this->db->query($sql);
527 $obj = $this->db->fetch_object($resql);
528 $nb = (int) $obj->nb;
547 if (empty($datestart)) {
548 $datestart = $this->date_start;
550 if (empty($dateend)) {
551 $dateend = $this->date_end;
554 $sql =
"SELECT count(rowid) as nb";
555 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
556 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
557 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
560 $resql = $this->db->query($sql);
562 $obj = $this->db->fetch_object($resql);
563 $nb = (int) $obj->nb;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage Dolibarr database access.
Class to manage fiscal year.
fetch($id)
Load an object from database.
getTooltipContentArray($params)
getTooltipContentArray
create($user)
Create object in database.
getAccountancyEntriesByFiscalYear($datestart='', $dateend='')
Return the number of entries by fiscal year.
getAccountancyMovementsByFiscalYear($datestart='', $dateend='')
Return the number of movements by fiscal year.
update($user)
Update record.
__construct(DoliDB $db)
Constructor.
info($id)
Information on record.
getLibStatut($mode=0)
Give a label from a status.
getNomUrl($withpicto=0, $notooltip=0, $save_lastsearch_value=-1)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0)
Give a label from a status.
checkOverlap()
Check if fiscal year dates overlap with existing fiscal years.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...