26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'fiscalyear';
41 public $picto =
'calendar';
46 public $table_element =
'accounting_fiscalyear';
51 public $table_element_line =
'';
56 public $fk_element =
'';
62 public $ismultientitymanaged = 1;
113 const STATUS_OPEN = 0;
114 const STATUS_CLOSED = 1;
126 $this->labelStatusShort = array(self::STATUS_OPEN =>
'Opened', self::STATUS_CLOSED =>
'Closed');
127 $this->labelStatus = array(self::STATUS_OPEN =>
'Opened', self::STATUS_CLOSED =>
'Closed');
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");
169 $result = $this->
update($user);
174 $this->error = $this->db->lasterror();
175 $this->db->rollback();
179 $this->error = $this->db->lasterror().
" sql=".$sql;
180 $this->db->rollback();
194 if (empty($this->date_start) && empty($this->date_end)) {
195 $this->error =
'ErrorBadParameter';
201 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
202 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
203 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
204 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
205 $sql .=
", statut = '".$this->db->escape($this->
status ? $this->
status : 0).
"'";
206 $sql .=
", fk_user_modif = ".((int) $user->id);
207 $sql .=
" WHERE rowid = ".((int) $this->
id);
209 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
210 $result = $this->db->query($sql);
215 $this->error = $this->db->lasterror();
217 $this->db->rollback();
230 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
231 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
232 $sql .=
" WHERE rowid = ".((int) $id);
234 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
235 $result = $this->db->query($sql);
237 $obj = $this->db->fetch_object($result);
239 $this->
id = $obj->rowid;
240 $this->
ref = $obj->rowid;
241 $this->date_start = $this->db->jdate($obj->date_start);
242 $this->date_end = $this->db->jdate($obj->date_end);
243 $this->label = $obj->label;
244 $this->
statut = $obj->status;
245 $this->
status = $obj->status;
249 $this->error = $this->db->lasterror();
260 public function delete($id)
264 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear WHERE rowid = ".((int) $id);
266 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
267 $result = $this->db->query($sql);
272 $this->error = $this->db->lasterror();
273 $this->db->rollback();
289 $langs->load(
'compta');
292 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
293 if (isset($this->
status)) {
294 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
296 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
297 if (isset($this->date_start)) {
298 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
300 if (isset($this->date_start)) {
301 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
315 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
317 global $conf, $langs, $user;
319 if (empty($this->
ref)) {
320 $this->
ref = $this->id;
323 if (!empty($conf->dol_no_mouse_hover)) {
327 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
333 'objecttype' => $this->element,
337 $classfortooltip =
'classfortooltip';
340 $classfortooltip =
'classforajaxtooltip';
341 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
342 $label =
'ToComplete';
346 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
348 if ($option !==
'nolink') {
350 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
351 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
352 $add_save_lastsearch_values = 1;
354 if ($add_save_lastsearch_values) {
355 $url .=
'&save_lastsearch_values=1';
360 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
362 $label = $langs->trans(
"FiscalYear");
363 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
365 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
366 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
369 $linkstart =
'<a href="'.$url.
'"';
370 $linkstart .= $linkclose.
'>';
373 if ($option ===
'nolink') {
378 $result .= $linkstart;
380 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
382 if ($withpicto != 2) {
383 $result .= $this->ref;
412 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
415 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Draft');
416 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Enabled');
417 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Enabled');
418 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Disabled');
421 $statusType =
'status4';
423 if ($status == self::STATUS_CLOSED) {
424 $statusType =
'status6';
427 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
438 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
439 $sql .=
" fy.tms as datem";
440 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
441 $sql .=
" WHERE fy.rowid = ".((int) $id);
443 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
444 $result = $this->db->query($sql);
447 if ($this->db->num_rows($result)) {
448 $obj = $this->db->fetch_object($result);
450 $this->
id = $obj->rowid;
452 $this->user_creation_id = $obj->fk_user_author;
453 $this->user_modification_id = $obj->fk_user_modif;
454 $this->date_creation = $this->db->jdate($obj->datec);
455 $this->date_modification = $this->db->jdate($obj->datem);
457 $this->db->free($result);
474 if (empty($datestart)) {
475 $datestart = $this->date_start;
477 if (empty($dateend)) {
478 $dateend = $this->date_end;
481 $sql =
"SELECT count(DISTINCT piece_num) as nb";
482 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
483 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
484 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
486 $resql = $this->db->query($sql);
488 $obj = $this->db->fetch_object($resql);
508 if (empty($datestart)) {
509 $datestart = $this->date_start;
511 if (empty($dateend)) {
512 $dateend = $this->date_end;
515 $sql =
"SELECT count(rowid) as nb";
516 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
517 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
518 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
520 $resql = $this->db->query($sql);
522 $obj = $this->db->fetch_object($resql);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
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 a 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)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut