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 ".MAIN_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 .=
", ".$conf->entity;
151 $sql .=
", '".$this->db->idate($now).
"'";
152 $sql .=
", ".$user->id;
155 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
156 $result = $this->
db->query($sql);
159 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"accounting_fiscalyear");
161 $result = $this->
update($user);
167 $this->error = $this->
db->lasterror();
168 $this->
db->rollback();
172 $this->error = $this->
db->lasterror().
" sql=".$sql;
173 $this->
db->rollback();
189 if (empty($this->date_start) && empty($this->date_end))
191 $this->error =
'ErrorBadParameter';
197 $sql =
"UPDATE ".MAIN_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->
statut ? $this->
statut : 0).
"'";
202 $sql .=
", fk_user_modif = ".$user->id;
203 $sql .=
" WHERE rowid = ".$this->id;
205 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
206 $result = $this->
db->query($sql);
212 $this->error = $this->
db->lasterror();
214 $this->
db->rollback();
227 $sql =
"SELECT rowid, label, date_start, date_end, statut";
228 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear";
229 $sql .=
" WHERE rowid = ".$id;
231 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
232 $result = $this->
db->query($sql);
235 $obj = $this->
db->fetch_object($result);
237 $this->
id = $obj->rowid;
238 $this->ref = $obj->rowid;
239 $this->date_start = $this->
db->jdate($obj->date_start);
240 $this->date_end = $this->
db->jdate($obj->date_end);
241 $this->label = $obj->label;
242 $this->
statut = $obj->statut;
246 $this->error = $this->
db->lasterror();
257 public function delete($id)
261 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"accounting_fiscalyear WHERE rowid = ".$id;
263 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
264 $result = $this->
db->query($sql);
270 $this->error = $this->
db->lasterror();
271 $this->
db->rollback();
284 public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
286 global $conf, $langs, $user;
288 if (empty($this->ref)) $this->ref = $this->id;
290 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
294 $url = DOL_URL_ROOT.
'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
296 if (!$user->rights->accounting->fiscalyear->write)
299 if ($option !==
'nolink')
302 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
303 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
304 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
307 if ($short)
return $url;
311 if ($user->rights->accounting->fiscalyear->write) {
312 $label =
'<u>'.$langs->trans(
"FiscalPeriod").
'</u>';
313 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->id;
314 if (isset($this->
statut)) {
315 $label .=
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
320 if (empty($notooltip) && $user->rights->accounting->fiscalyear->write)
322 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
324 $label = $langs->trans(
"FiscalYear");
325 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
327 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
328 $linkclose .=
' class="classfortooltip"';
331 $linkstart =
'<a href="'.$url.
'"';
332 $linkstart .= $linkclose.
'>';
335 if ($option ===
'nolink') {
340 $result .= $linkstart;
341 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
342 if ($withpicto != 2) $result .= $this->ref;
374 return $langs->trans($this->statuts[$status]);
375 } elseif ($mode == 1)
377 return $langs->trans($this->statuts_short[$status]);
378 } elseif ($mode == 2)
380 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts_short[$status]);
381 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts_short[$status]);
382 } elseif ($mode == 3)
384 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
385 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut8');
386 } elseif ($mode == 4)
388 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
389 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
390 } elseif ($mode == 5)
392 if ($status == 0 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
393 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
405 $sql =
'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,';
407 $sql .=
' FROM '.MAIN_DB_PREFIX.
'accounting_fiscalyear as fy';
408 $sql .=
' WHERE fy.rowid = '.$id;
410 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
411 $result = $this->
db->query($sql);
415 if ($this->
db->num_rows($result))
417 $obj = $this->
db->fetch_object($result);
418 $this->
id = $obj->rowid;
419 if ($obj->fk_user_author)
421 $cuser =
new User($this->
db);
422 $cuser->fetch($obj->fk_user_author);
423 $this->user_creation = $cuser;
425 if ($obj->fk_user_modif)
427 $muser =
new User($this->
db);
428 $muser->fetch($obj->fk_user_modif);
429 $this->user_modification = $muser;
431 $this->date_creation = $this->
db->jdate($obj->datec);
432 $this->date_modification = $this->
db->jdate($obj->tms);
434 $this->
db->free($result);
451 if (empty($datestart))
452 $datestart = $this->date_start;
454 $dateend = $this->date_end;
456 $sql =
"SELECT count(DISTINCT piece_num) as nb";
457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
458 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
459 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->
db->idate($dateend).
"'";
464 $obj = $this->
db->fetch_object(
$resql);
482 if (empty($datestart))
483 $datestart = $this->date_start;
485 $dateend = $this->date_end;
487 $sql =
"SELECT count(rowid) as nb";
488 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping ";
489 $sql .=
" WHERE entity IN (".getEntity(
'bookkeeping', 0).
")";
490 $sql .=
" AND doc_date >= '".$this->db->idate($datestart).
"' and doc_date <= '".$this->
db->idate($dateend).
"'";
495 $obj = $this->
db->fetch_object(
$resql);
update($user)
Update record.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Give a label from a status.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
$conf db
API class for accounts.
info($id)
Information on record.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Class to manage fiscal year.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
create($user)
Create object in database.
print $_SERVER["PHP_SELF"]
Edit parameters.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $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...
getAccountancyEntriesByFiscalYear($datestart= '', $dateend= '')
Return the number of entries by fiscal year.
fetch($id)
Load an object from database.
getAccountancyMovementsByFiscalYear($datestart= '', $dateend= '')
Return the number of movements by fiscal year.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)