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;
122 $this->labelStatusShort = array(self::STATUS_OPEN =>
'Opened', self::STATUS_CLOSED =>
'Closed');
123 $this->labelStatus = array(self::STATUS_OPEN =>
'Opened', self::STATUS_CLOSED =>
'Closed');
142 $sql =
"INSERT INTO ".$this->db->prefix().
"accounting_fiscalyear (";
144 $sql .=
", date_start";
145 $sql .=
", date_end";
149 $sql .=
", fk_user_author";
150 $sql .=
") VALUES (";
151 $sql .=
" '".$this->db->escape($this->label).
"'";
152 $sql .=
", '".$this->db->idate($this->date_start).
"'";
153 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
155 $sql .=
", ".((int)
$conf->entity);
156 $sql .=
", '".$this->db->idate($now).
"'";
157 $sql .=
", ".((int) $user->id);
160 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
161 $result = $this->db->query($sql);
163 $this->
id = $this->db->last_insert_id($this->db->prefix().
"accounting_fiscalyear");
165 $result = $this->
update($user);
170 $this->error = $this->db->lasterror();
171 $this->db->rollback();
175 $this->error = $this->db->lasterror().
" sql=".$sql;
176 $this->db->rollback();
190 if (empty($this->date_start) && empty($this->date_end)) {
191 $this->error =
'ErrorBadParameter';
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 ? $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();
226 $sql =
"SELECT rowid, label, date_start, date_end, statut as status";
227 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
228 $sql .=
" WHERE rowid = ".((int) $id);
230 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
231 $result = $this->db->query($sql);
233 $obj = $this->db->fetch_object($result);
235 $this->
id = $obj->rowid;
236 $this->
ref = $obj->rowid;
237 $this->date_start = $this->db->jdate($obj->date_start);
238 $this->date_end = $this->db->jdate($obj->date_end);
239 $this->label = $obj->label;
240 $this->statut = $obj->status;
241 $this->
status = $obj->status;
245 $this->error = $this->db->lasterror();
256 public function delete($user)
260 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear";
261 $sql .=
" WHERE rowid = ".((int) $this->
id);
263 $result = $this->db->query($sql);
268 $this->error = $this->db->lasterror();
269 $this->db->rollback();
284 $langs->load(
'compta');
287 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <b><u>'.$langs->trans(
"FiscalPeriod").
'</u></b>';
288 if (isset($this->
status)) {
289 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
291 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
292 if (isset($this->date_start)) {
293 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->date_start,
'day');
295 if (isset($this->date_start)) {
296 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->date_end,
'day');
310 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
312 global
$conf, $langs, $user;
314 if (empty($this->
ref)) {
315 $this->
ref = (string) $this->
id;
318 if (!empty(
$conf->dol_no_mouse_hover)) {
322 if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
328 'objecttype' => $this->element,
332 $classfortooltip =
'classfortooltip';
335 $classfortooltip =
'classforajaxtooltip';
336 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
337 $label =
'ToComplete';
341 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
343 if ($option !==
'nolink') {
345 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
346 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
347 $add_save_lastsearch_values = 1;
349 if ($add_save_lastsearch_values) {
350 $url .=
'&save_lastsearch_values=1';
355 if (empty($notooltip) && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
357 $label = $langs->trans(
"FiscalPeriod");
358 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
360 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
361 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
364 $linkstart =
'<a href="'.$url.
'"';
365 $linkstart .= $linkclose.
'>';
368 if ($option ===
'nolink') {
373 $result .= $linkstart;
375 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
377 if ($withpicto != 2) {
378 $result .= $this->ref;
407 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
410 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Draft');
411 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Enabled');
412 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Enabled');
413 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Disabled');
416 $statusType =
'status4';
418 if ($status == self::STATUS_CLOSED) {
419 $statusType =
'status6';
422 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
433 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
434 $sql .=
" fy.tms as datem";
435 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
436 $sql .=
" WHERE fy.rowid = ".((int) $id);
438 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
439 $result = $this->db->query($sql);
442 if ($this->db->num_rows($result)) {
443 $obj = $this->db->fetch_object($result);
445 $this->
id = $obj->rowid;
447 $this->user_creation_id = $obj->fk_user_author;
448 $this->user_modification_id = $obj->fk_user_modif;
449 $this->date_creation = $this->db->jdate($obj->datec);
450 $this->date_modification = $this->db->jdate($obj->datem);
452 $this->db->free($result);
469 if (empty($datestart)) {
470 $datestart = $this->date_start;
472 if (empty($dateend)) {
473 $dateend = $this->date_end;
476 $sql =
"SELECT count(DISTINCT piece_num) as nb";
477 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
478 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
479 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
482 $resql = $this->db->query($sql);
484 $obj = $this->db->fetch_object($resql);
485 $nb = (int) $obj->nb;
504 if (empty($datestart)) {
505 $datestart = $this->date_start;
507 if (empty($dateend)) {
508 $dateend = $this->date_end;
511 $sql =
"SELECT count(rowid) as nb";
512 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
513 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
514 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->db->idate($dateend).
"'";
517 $resql = $this->db->query($sql);
519 $obj = $this->db->fetch_object($resql);
520 $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.
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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...