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;
138 if ($checkresult < 0) {
144 $sql =
"INSERT INTO ".$this->db->prefix().
"accounting_fiscalyear (";
146 $sql .=
", date_start";
147 $sql .=
", date_end";
151 $sql .=
", fk_user_author";
152 $sql .=
") VALUES (";
153 $sql .=
" '".$this->db->escape($this->label).
"'";
154 $sql .=
", '".$this->db->idate($this->date_start).
"'";
155 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
157 $sql .=
", ".((int) $conf->entity);
158 $sql .=
", '".$this->db->idate($now).
"'";
159 $sql .=
", ".((int) $user->id);
162 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
163 $result = $this->db->query($sql);
165 $this->
id = $this->db->last_insert_id($this->db->prefix().
"accounting_fiscalyear");
169 $this->error = $this->db->lasterror().
" sql=".$sql;
170 $this->db->rollback();
184 if (empty($this->date_start) && empty($this->date_end)) {
185 $this->error =
'ErrorBadParameter';
191 if ($checkresult < 0) {
197 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
198 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
199 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
200 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
201 $sql .=
", statut = '".$this->db->escape($this->
status ? (
string) $this->
status :
'0').
"'";
202 $sql .=
", fk_user_modif = ".((int) $user->id);
203 $sql .=
" WHERE rowid = ".((int) $this->
id);
205 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
206 $result = $this->db->query($sql);
211 $this->error = $this->db->lasterror();
213 $this->db->rollback();
225 public function fetch($idorref, $label =
'')
227 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
228 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
230 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
232 $sql .=
" WHERE rowid = ".((int) $idorref);
235 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
236 $result = $this->db->query($sql);
238 $obj = $this->db->fetch_object($result);
240 $this->
id = $obj->rowid;
241 $this->
ref = $obj->rowid;
242 $this->label = $obj->label;
243 $this->date_start = $this->db->jdate($obj->date_start);
244 $this->date_end = $this->db->jdate($obj->date_end);
245 $this->statut = $obj->status;
246 $this->
status = $obj->status;
250 $this->error = $this->db->lasterror();
261 public function delete($user)
265 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear";
266 $sql .=
" WHERE rowid = ".((int) $this->
id);
268 $result = $this->db->query($sql);
273 $this->error = $this->db->lasterror();
274 $this->db->rollback();
289 $entity = (!empty($this->entity) ? $this->entity : $conf->entity);
292 $sql =
"SELECT label";
293 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
294 $sql .=
" WHERE entity = " . ((int) $entity);
295 $sql .=
" AND date_start <= '" . $this->db->idate($this->date_end) .
"'";
296 $sql .=
" AND date_end >= '" . $this->db->idate($this->date_start) .
"'";
299 if (!empty($this->
id)) {
300 $sql .=
" AND rowid != " . ((int) $this->
id);
303 dol_syslog(get_class($this) .
"::checkOverlap", LOG_DEBUG);
305 $result = $this->db->query($sql);
307 if ($this->db->num_rows($result) > 0) {
308 $obj = $this->db->fetch_object($result);
309 $this->error =
'ErrorFiscalYearOverlapWithFiscalYear';
310 $this->errors[] = $obj->label;
315 $this->error = $this->db->lasterror();
330 $langs->load(
'compta');
333 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
334 if (isset($this->
status)) {
335 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
337 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
338 if (isset($this->date_start)) {
339 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
341 if (isset($this->date_start)) {
342 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
356 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
358 global $conf, $langs, $user;
360 if (empty($this->
ref)) {
361 $this->
ref = (string) $this->
id;
364 if (!empty($conf->dol_no_mouse_hover)) {
368 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
374 'objecttype' => $this->element,
378 $classfortooltip =
'classfortooltip';
381 $classfortooltip =
'classforajaxtooltip';
382 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
383 $label =
'ToComplete';
387 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
389 if ($option !==
'nolink') {
391 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
392 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
393 $add_save_lastsearch_values = 1;
395 if ($add_save_lastsearch_values) {
396 $url .=
'&save_lastsearch_values=1';
401 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
403 $label = $langs->trans(
"FiscalPeriod");
404 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
406 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
407 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
410 $linkstart =
'<a href="'.$url.
'"';
411 $linkstart .= $linkclose.
'>';
414 if ($option ===
'nolink') {
419 $result .= $linkstart;
421 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
423 if ($withpicto != 2) {
424 $result .= $this->ref;
453 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
456 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpened');
457 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosed');
458 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpenedShort');
459 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosedShort');
462 $statusType =
'status4';
464 if ($status == self::STATUS_CLOSED) {
465 $statusType =
'status6';
468 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
479 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
480 $sql .=
" fy.tms as datem";
481 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
482 $sql .=
" WHERE fy.rowid = ".((int) $id);
484 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
485 $result = $this->db->query($sql);
488 if ($this->db->num_rows($result)) {
489 $obj = $this->db->fetch_object($result);
491 $this->
id = $obj->rowid;
493 $this->user_creation_id = $obj->fk_user_author;
494 $this->user_modification_id = $obj->fk_user_modif;
495 $this->date_creation = $this->db->jdate($obj->datec);
496 $this->date_modification = $this->db->jdate($obj->datem);
498 $this->db->free($result);
513 if (empty($datestart)) {
514 $datestart = $this->date_start;
516 if (empty($dateend)) {
517 $dateend = $this->date_end;
520 $sql =
"SELECT count(DISTINCT piece_num) as nb";
521 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
522 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
523 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
526 $resql = $this->db->query($sql);
528 $obj = $this->db->fetch_object($resql);
529 $nb = (int) $obj->nb;
546 if (empty($datestart)) {
547 $datestart = $this->date_start;
549 if (empty($dateend)) {
550 $dateend = $this->date_end;
553 $sql =
"SELECT count(rowid) as nb";
554 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
555 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
556 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
559 $resql = $this->db->query($sql);
561 $obj = $this->db->fetch_object($resql);
562 $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.
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.
fetch($idorref, $label='')
Load an object from database.
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...
dol_now($mode='gmt')
Return date for now.
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)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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).
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.