26 require_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;
102 public $statuts = array();
103 public $statuts_short = array();
117 $this->statuts_short = array(0 =>
'Opened', 1 =>
'Closed');
118 $this->statuts = array(0 =>
'Opened', 1 =>
'Closed');
137 $sql =
"INSERT INTO ".$this->db->prefix().
"accounting_fiscalyear (";
139 $sql .=
", date_start";
140 $sql .=
", date_end";
144 $sql .=
", fk_user_author";
145 $sql .=
") VALUES (";
146 $sql .=
" '".$this->db->escape($this->label).
"'";
147 $sql .=
", '".$this->db->idate($this->date_start).
"'";
148 $sql .=
", ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
150 $sql .=
", ".((int) $conf->entity);
151 $sql .=
", '".$this->db->idate($now).
"'";
152 $sql .=
", ".((int) $user->id);
155 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
156 $result = $this->
db->query($sql);
158 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"accounting_fiscalyear");
160 $result = $this->
update($user);
165 $this->error = $this->
db->lasterror();
166 $this->
db->rollback();
170 $this->error = $this->
db->lasterror().
" sql=".$sql;
171 $this->
db->rollback();
187 if (empty($this->date_start) && empty($this->date_end)) {
188 $this->error =
'ErrorBadParameter';
194 $sql =
"UPDATE ".$this->db->prefix().
"accounting_fiscalyear";
195 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
196 $sql .=
", date_start = '".$this->db->idate($this->date_start).
"'";
197 $sql .=
", date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
198 $sql .=
", statut = '".$this->db->escape($this->statut ? $this->statut : 0).
"'";
199 $sql .=
", fk_user_modif = ".((int) $user->id);
200 $sql .=
" WHERE rowid = ".((int) $this->
id);
202 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
203 $result = $this->
db->query($sql);
208 $this->error = $this->
db->lasterror();
210 $this->
db->rollback();
223 $sql =
"SELECT rowid, label, date_start, date_end, statut";
224 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear";
225 $sql .=
" WHERE rowid = ".((int) $id);
227 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
228 $result = $this->
db->query($sql);
230 $obj = $this->
db->fetch_object($result);
232 $this->
id = $obj->rowid;
233 $this->
ref = $obj->rowid;
234 $this->date_start = $this->
db->jdate($obj->date_start);
235 $this->date_end = $this->
db->jdate($obj->date_end);
236 $this->label = $obj->label;
237 $this->statut = $obj->statut;
241 $this->error = $this->
db->lasterror();
252 public function delete($id)
256 $sql =
"DELETE FROM ".$this->db->prefix().
"accounting_fiscalyear WHERE rowid = ".((int) $id);
258 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
259 $result = $this->
db->query($sql);
264 $this->error = $this->
db->lasterror();
265 $this->
db->rollback();
278 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
280 global $conf, $langs, $user;
282 if (empty($this->
ref)) {
283 $this->
ref = $this->id;
286 if (!empty($conf->dol_no_mouse_hover)) {
292 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
294 if (empty($user->rights->accounting->fiscalyear->write)) {
298 if ($option !==
'nolink') {
300 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
301 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
302 $add_save_lastsearch_values = 1;
304 if ($add_save_lastsearch_values) {
305 $url .=
'&save_lastsearch_values=1';
315 if ($user->rights->accounting->fiscalyear->write) {
316 $label =
'<u>'.$langs->trans(
"FiscalPeriod").
'</u>';
317 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->id;
318 if (isset($this->statut)) {
319 $label .=
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
324 if (empty($notooltip) && $user->rights->accounting->fiscalyear->write) {
325 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
326 $label = $langs->trans(
"FiscalYear");
327 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
329 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
330 $linkclose .=
' class="classfortooltip"';
333 $linkstart =
'<a href="'.$url.
'"';
334 $linkstart .= $linkclose.
'>';
337 if ($option ===
'nolink') {
342 $result .= $linkstart;
344 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
346 if ($withpicto != 2) {
347 $result .= $this->ref;
362 return $this->
LibStatut($this->statut, $mode);
379 return $langs->trans($this->statuts[$status]);
380 } elseif ($mode == 1) {
381 return $langs->trans($this->statuts_short[$status]);
382 } elseif ($mode == 2) {
384 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts_short[$status]);
385 } elseif ($status == 1) {
386 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts_short[$status]);
388 } elseif ($mode == 3) {
389 if ($status == 0 && !empty($this->statuts_short[$status])) {
390 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
391 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
392 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8');
394 } elseif ($mode == 4) {
395 if ($status == 0 && !empty($this->statuts_short[$status])) {
396 return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
397 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
398 return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
400 } elseif ($mode == 5) {
401 if ($status == 0 && !empty($this->statuts_short[$status])) {
402 return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
403 } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
404 return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
417 $sql =
"SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,";
418 $sql .=
" fy.tms as datem";
419 $sql .=
" FROM ".$this->db->prefix().
"accounting_fiscalyear as fy";
420 $sql .=
" WHERE fy.rowid = ".((int) $id);
422 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
423 $result = $this->
db->query($sql);
426 if ($this->
db->num_rows($result)) {
427 $obj = $this->
db->fetch_object($result);
428 $this->
id = $obj->rowid;
429 $this->user_creation_id = $obj->fk_user_author;
430 $this->user_modification_id = $obj->fk_user_modif;
431 $this->date_creation = $this->
db->jdate($obj->datec);
432 $this->date_modification = $this->
db->jdate($obj->datem);
434 $this->
db->free($result);
451 if (empty($datestart)) {
452 $datestart = $this->date_start;
454 if (empty($dateend)) {
455 $dateend = $this->date_end;
458 $sql =
"SELECT count(DISTINCT piece_num) as nb";
459 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
460 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
461 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->
db->idate($dateend).
"'";
465 $obj = $this->
db->fetch_object(
$resql);
485 if (empty($datestart)) {
486 $datestart = $this->date_start;
488 if (empty($dateend)) {
489 $dateend = $this->date_end;
492 $sql =
"SELECT count(rowid) as nb";
493 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping ";
494 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
495 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->
db->idate($dateend).
"'";
499 $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.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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_now($mode='auto')
Return date for now.
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.
$conf db
API class for accounts.