26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'fiscalyear';
41 public $picto =
'technic';
46 public $table_element =
'accounting_fiscalyear';
51 public $table_element_line =
'';
56 public $fk_element =
'';
62 public $ismultientitymanaged = 1;
112 public $statuts = array();
113 public $statuts_short = array();
115 const STATUS_OPEN = 0;
116 const STATUS_CLOSED = 1;
130 $this->statuts_short = array(0 =>
'Opened', 1 =>
'Closed');
131 $this->statuts = array(0 =>
'Opened', 1 =>
'Closed');
150 $sql =
"INSERT INTO ".$this->db->prefix().
"accounting_fiscalyear (";
152 $sql .=
", date_start";
153 $sql .=
", date_end";
157 $sql .=
", fk_user_author";
158 $sql .=
") VALUES (";
159 $sql .=
" '".$this->db->escape($this->label).
"'";
160 $sql .=
", '".$this->db->idate($this->date_start).
"'";
161 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
163 $sql .=
", ".((int) $conf->entity);
164 $sql .=
", '".$this->db->idate($now).
"'";
165 $sql .=
", ".((int) $user->id);
168 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
169 $result = $this->db->query($sql);
171 $this->
id = $this->db->last_insert_id($this->db->prefix().
"accounting_fiscalyear");
173 $result = $this->
update($user);
178 $this->error = $this->db->lasterror();
179 $this->db->rollback();
183 $this->error = $this->db->lasterror().
" sql=".$sql;
184 $this->db->rollback();
200 if (empty($this->date_start) && empty($this->date_end)) {
201 $this->error =
'ErrorBadParameter';
207 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
208 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
209 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
210 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
211 $sql .=
", statut = '".$this->db->escape($this->
statut ? $this->
statut : 0).
"'";
212 $sql .=
", fk_user_modif = ".((int) $user->id);
213 $sql .=
" WHERE rowid = ".((int) $this->
id);
215 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
216 $result = $this->db->query($sql);
221 $this->error = $this->db->lasterror();
223 $this->db->rollback();
236 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
237 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
238 $sql .=
" WHERE rowid = ".((int) $id);
240 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
241 $result = $this->db->query($sql);
243 $obj = $this->db->fetch_object($result);
245 $this->
id = $obj->rowid;
246 $this->
ref = $obj->rowid;
247 $this->date_start = $this->db->jdate($obj->date_start);
248 $this->date_end = $this->db->jdate($obj->date_end);
249 $this->label = $obj->label;
250 $this->
statut = $obj->status;
251 $this->status = $obj->status;
255 $this->error = $this->db->lasterror();
266 public function delete($id)
270 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear WHERE rowid = ".((int) $id);
272 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
273 $result = $this->db->query($sql);
278 $this->error = $this->db->lasterror();
279 $this->db->rollback();
295 $langs->load(
'compta');
298 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
299 if (isset($this->status)) {
300 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
302 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
303 if (isset($this->date_start)) {
304 $datas[
'date_start'] .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
306 if (isset($this->date_start)) {
307 $datas[
'date_end'] .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
321 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
323 global $conf, $langs, $user;
325 if (empty($this->
ref)) {
326 $this->
ref = $this->id;
329 if (!empty($conf->dol_no_mouse_hover)) {
333 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
339 'objecttype' => $this->element,
343 $classfortooltip =
'classfortooltip';
346 $classfortooltip =
'classforajaxtooltip';
347 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
348 $label =
'ToComplete';
352 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
354 if ($option !==
'nolink') {
356 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
357 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
358 $add_save_lastsearch_values = 1;
360 if ($add_save_lastsearch_values) {
361 $url .=
'&save_lastsearch_values=1';
366 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
367 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
368 $label = $langs->trans(
"FiscalYear");
369 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
371 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
372 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
375 $linkstart =
'<a href="'.$url.
'"';
376 $linkstart .= $linkclose.
'>';
379 if ($option ===
'nolink') {
384 $result .= $linkstart;
386 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
388 if ($withpicto != 2) {
389 $result .= $this->ref;
404 return $this->
LibStatut($this->status, $mode);
421 return $langs->trans($this->statuts[$status]);
422 } elseif ($mode == 1) {
423 return $langs->trans($this->statuts_short[$status]);
424 } elseif ($mode == 2) {
426 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts_short[$status]);
427 } elseif ($status == 1) {
428 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts_short[$status]);
430 } elseif ($mode == 3) {
431 if ($status == 0 && !empty($this->statuts_short[$status])) {
432 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
433 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
434 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8');
436 } elseif ($mode == 4) {
437 if ($status == 0 && !empty($this->statuts_short[$status])) {
438 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
439 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
440 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
442 } elseif ($mode == 5) {
443 if ($status == 0 && !empty($this->statuts_short[$status])) {
444 return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
445 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
446 return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
460 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
461 $sql .=
" fy.tms as datem";
462 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
463 $sql .=
" WHERE fy.rowid = ".((int) $id);
465 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
466 $result = $this->db->query($sql);
469 if ($this->db->num_rows($result)) {
470 $obj = $this->db->fetch_object($result);
471 $this->
id = $obj->rowid;
472 $this->user_creation_id = $obj->fk_user_author;
473 $this->user_modification_id = $obj->fk_user_modif;
474 $this->date_creation = $this->db->jdate($obj->datec);
475 $this->date_modification = $this->db->jdate($obj->datem);
477 $this->db->free($result);
494 if (empty($datestart)) {
495 $datestart = $this->date_start;
497 if (empty($dateend)) {
498 $dateend = $this->date_end;
501 $sql =
"SELECT count(DISTINCT piece_num) as nb";
502 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
503 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
504 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
506 $resql = $this->db->query($sql);
508 $obj = $this->db->fetch_object($resql);
528 if (empty($datestart)) {
529 $datestart = $this->date_start;
531 if (empty($dateend)) {
532 $dateend = $this->date_end;
535 $sql =
"SELECT count(rowid) as nb";
536 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
537 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
538 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
540 $resql = $this->db->query($sql);
542 $obj = $this->db->fetch_object($resql);
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 clicable link of object (with eventually picto)
LibStatut($status, $mode=0)
Give a label from a status.
print $langs trans("Ref").' m m m statut
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.