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");
168 $triggerres = $this->call_trigger(
'FISCALYEAR_CREATE', $user);
169 if ($triggerres < 0) {
170 $this->db->rollback();
178 $this->error = $this->db->lasterror().
" sql=".$sql;
179 $this->db->rollback();
193 if (empty($this->date_start) && empty($this->date_end)) {
194 $this->error =
'ErrorBadParameter';
200 if ($checkresult < 0) {
206 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
207 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
208 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
209 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
210 $sql .=
", statut = '".$this->db->escape($this->
status ? (
string) $this->
status :
'0').
"'";
211 $sql .=
", fk_user_modif = ".((int) $user->id);
212 $sql .=
" WHERE rowid = ".((int) $this->
id);
214 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
215 $result = $this->db->query($sql);
218 $triggerres = $this->call_trigger(
'FISCALYEAR_MODIFY', $user);
219 if ($triggerres < 0) {
220 $this->db->rollback();
228 $this->error = $this->db->lasterror();
230 $this->db->rollback();
242 public function fetch($idorref, $label =
'')
244 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
245 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
247 $sql .=
" WHERE label = '".$this->db->escape($label).
"'";
249 $sql .=
" WHERE rowid = ".((int) $idorref);
252 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
253 $result = $this->db->query($sql);
255 $obj = $this->db->fetch_object($result);
257 $this->
id = $obj->rowid;
258 $this->
ref = $obj->rowid;
259 $this->label = $obj->label;
260 $this->date_start = $this->db->jdate($obj->date_start);
261 $this->date_end = $this->db->jdate($obj->date_end);
262 $this->statut = $obj->status;
263 $this->
status = $obj->status;
267 $this->error = $this->db->lasterror();
278 public function delete($user)
282 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear";
283 $sql .=
" WHERE rowid = ".((int) $this->
id);
285 $result = $this->db->query($sql);
288 $triggerres = $this->call_trigger(
'FISCALYEAR_DELETE', $user);
289 if ($triggerres < 0) {
290 $this->db->rollback();
298 $this->error = $this->db->lasterror();
299 $this->db->rollback();
314 $entity = (!empty($this->entity) ? $this->entity :
$conf->entity);
317 $sql =
"SELECT label";
318 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
319 $sql .=
" WHERE entity = " . ((int) $entity);
320 $sql .=
" AND date_start <= '" . $this->db->idate($this->date_end) .
"'";
321 $sql .=
" AND date_end >= '" . $this->db->idate($this->date_start) .
"'";
324 if (!empty($this->
id)) {
325 $sql .=
" AND rowid != " . ((int) $this->
id);
328 dol_syslog(get_class($this) .
"::checkOverlap", LOG_DEBUG);
330 $result = $this->db->query($sql);
332 if ($this->db->num_rows($result) > 0) {
333 $obj = $this->db->fetch_object($result);
334 $this->error =
'ErrorFiscalYearOverlapWithFiscalYear';
335 $this->errors[] = $obj->label;
340 $this->error = $this->db->lasterror();
355 $langs->load(
'compta');
358 $datas[
'picto'] = img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
359 if (isset($this->
status)) {
360 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
362 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
363 if (isset($this->date_start)) {
364 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
366 if (isset($this->date_start)) {
367 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
381 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
383 global
$conf, $langs, $user;
385 if (empty($this->
ref)) {
386 $this->
ref = (string) $this->
id;
389 if (!empty(
$conf->dol_no_mouse_hover)) {
393 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
399 'objecttype' => $this->element,
403 $classfortooltip =
'classfortooltip';
406 $classfortooltip =
'classforajaxtooltip';
407 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
408 $label =
'ToComplete';
412 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
414 if ($option !==
'nolink') {
416 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
417 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
418 $add_save_lastsearch_values = 1;
420 if ($add_save_lastsearch_values) {
421 $url .=
'&save_lastsearch_values=1';
426 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
428 $label = $langs->trans(
"FiscalPeriod");
429 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
431 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
432 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
435 $linkstart =
'<a href="'.$url.
'"';
436 $linkstart .= $linkclose.
'>';
439 if ($option ===
'nolink') {
444 $result .= $linkstart;
446 $result .= img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
448 if ($withpicto != 2) {
449 $result .= $this->ref;
478 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
481 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpened');
482 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosed');
483 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'FiscalYearOpenedShort');
484 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'FiscalYearClosedShort');
487 $statusType =
'status4';
489 if ($status == self::STATUS_CLOSED) {
490 $statusType =
'status6';
493 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
504 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
505 $sql .=
" fy.tms as datem";
506 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
507 $sql .=
" WHERE fy.rowid = ".((int) $id);
509 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
510 $result = $this->db->query($sql);
513 if ($this->db->num_rows($result)) {
514 $obj = $this->db->fetch_object($result);
516 $this->
id = $obj->rowid;
518 $this->user_creation_id = $obj->fk_user_author;
519 $this->user_modification_id = $obj->fk_user_modif;
520 $this->date_creation = $this->db->jdate($obj->datec);
521 $this->date_modification = $this->db->jdate($obj->datem);
523 $this->db->free($result);
525 dol_print_error($this->db);
538 if (empty($datestart)) {
539 $datestart = $this->date_start;
541 if (empty($dateend)) {
542 $dateend = $this->date_end;
545 $sql =
"SELECT count(DISTINCT piece_num) as nb";
546 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
547 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
548 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
551 $resql = $this->db->query($sql);
553 $obj = $this->db->fetch_object($resql);
554 $nb = (int) $obj->nb;
556 dol_print_error($this->db);
571 if (empty($datestart)) {
572 $datestart = $this->date_start;
574 if (empty($dateend)) {
575 $dateend = $this->date_end;
578 $sql =
"SELECT count(rowid) as nb";
579 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
580 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
581 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
584 $resql = $this->db->query($sql);
586 $obj = $this->db->fetch_object($resql);
587 $nb = (int) $obj->nb;
589 dol_print_error($this->db);
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.