27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'salary';
43 public $table_element =
'salary';
48 public $picto =
'salary';
85 public $fk_user_author;
90 public $fk_user_modif;
102 const STATUS_UNPAID = 0;
103 const STATUS_PAID = 1;
114 $this->element =
'salary';
115 $this->table_element =
'salary';
125 public function update($user =
null, $notrigger = 0)
127 global $conf, $langs;
132 $this->amount = trim($this->amount);
133 $this->label = trim($this->label);
134 $this->note = trim($this->note);
137 if (empty($this->fk_user) || $this->fk_user < 0) {
138 $this->error =
'ErrorBadParameter';
145 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
146 $sql .=
" tms='".$this->db->idate(
dol_now()).
"',";
147 $sql .=
" fk_user=".((int) $this->fk_user).
",";
150 $sql .=
" amount=".price2num($this->amount).
",";
151 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
152 $sql .=
" fk_typepayment=".((int) $this->type_payment).
",";
153 $sql .=
" label='".$this->db->escape($this->label).
"',";
154 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
155 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
156 $sql .=
" note='".$this->db->escape($this->note).
"',";
157 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
158 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
159 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (
int) $user->id);
160 $sql .=
" WHERE rowid=".((int) $this->
id);
162 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
165 $this->error =
"Error ".$this->db->lasterror();
182 if ($result < 0) $error++;
190 $this->
db->rollback();
203 public function fetch($id, $user =
null)
210 $sql .=
" s.fk_user,";
213 $sql .=
" s.amount,";
214 $sql .=
" s.fk_projet as fk_project,";
215 $sql .=
" s.fk_typepayment,";
217 $sql .=
" s.datesp,";
218 $sql .=
" s.dateep,";
221 $sql .=
" s.fk_bank,";
222 $sql .=
" s.fk_user_author,";
223 $sql .=
" s.fk_user_modif,";
224 $sql .=
" s.fk_account";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
227 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
228 $sql .=
" WHERE s.rowid = ".((int) $id);
230 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
234 $obj = $this->
db->fetch_object(
$resql);
236 $this->
id = $obj->rowid;
237 $this->
ref = $obj->rowid;
238 $this->tms = $this->
db->jdate($obj->tms);
239 $this->fk_user = $obj->fk_user;
240 $this->datep = $this->
db->jdate($obj->datep);
241 $this->datev = $this->
db->jdate($obj->datev);
242 $this->amount = $obj->amount;
243 $this->fk_project = $obj->fk_project;
244 $this->type_payment = $obj->fk_typepayment;
245 $this->label = $obj->label;
246 $this->datesp = $this->
db->jdate($obj->datesp);
247 $this->dateep = $this->
db->jdate($obj->dateep);
248 $this->note = $obj->note;
249 $this->paye = $obj->paye;
250 $this->fk_bank = $obj->fk_bank;
251 $this->fk_user_author = $obj->fk_user_author;
252 $this->fk_user_modif = $obj->fk_user_modif;
253 $this->fk_account = $this->accountid = $obj->fk_account;
263 $this->error =
"Error ".$this->db->lasterror();
275 public function delete($user)
277 global $conf, $langs;
283 if ($result < 0)
return -1;
300 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"salary";
301 $sql .=
" WHERE rowid=".((int) $this->
id);
303 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
306 $this->error =
"Error ".$this->db->lasterror();
335 $this->fk_user_author =
'';
336 $this->fk_user_modif =
'';
347 global $conf, $langs;
353 $this->amount =
price2num(trim($this->amount));
354 $this->label = trim($this->label);
355 $this->note = trim($this->note);
356 $this->fk_bank = trim($this->fk_bank);
357 $this->fk_user_author = trim($this->fk_user_author);
358 $this->fk_user_modif = trim($this->fk_user_modif);
359 $this->accountid = trim($this->accountid);
360 $this->paye = trim($this->paye);
364 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
367 if ($this->fk_user < 0 || $this->fk_user ==
'') {
368 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
371 if ($this->amount ==
'') {
372 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
389 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"salary (fk_user";
393 $sql .=
", fk_projet";
395 $sql .=
", fk_typepayment";
396 $sql .=
", fk_account";
397 if ($this->note) $sql .=
", note";
401 $sql .=
", fk_user_author";
407 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
410 $sql .=
", ".((double) $this->amount);
411 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
412 $sql .=
", ".($this->salary > 0 ? ((double) $this->salary) :
"null");
413 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
414 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
415 if ($this->note) $sql .=
", '".$this->db->escape($this->note).
"'";
416 $sql .=
", '".$this->db->escape($this->label).
"'";
417 $sql .=
", '".$this->db->idate($this->datesp).
"'";
418 $sql .=
", '".$this->db->idate($this->dateep).
"'";
419 $sql .=
", '".$this->db->escape($user->id).
"'";
420 $sql .=
", '".$this->db->idate($now).
"'";
422 $sql .=
", ".((int) $conf->entity);
425 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
426 $result = $this->
db->query($sql);
428 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"salary");
443 if ($result < 0) $error++;
451 $this->
db->rollback();
455 $this->error = $this->
db->error();
456 $this->
db->rollback();
471 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'salary SET fk_bank = '.((int) $id_bank);
472 $sql .=
" WHERE rowid = ".((int) $this->
id);
473 $result = $this->
db->query($sql);
493 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
495 global $db, $conf, $langs, $hookmanager;
496 global $dolibarr_main_authentication, $dolibarr_main_demo;
499 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
503 $label =
'<u>'.$langs->trans(
"Salary").
'</u>';
505 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
507 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
509 if ($this->datesp && $this->dateep) {
512 if (isset($this->amount)) {
513 $label .=
'<br><b>'.$langs->trans(
'Amount').
':</b> '.
price($this->amount);
516 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
518 if ($option !=
'nolink') {
520 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
521 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
522 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
526 if (empty($notooltip)) {
527 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
528 $label = $langs->trans(
"ShowMyObject");
529 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
531 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
532 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
540 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
542 $linkstart =
'<a href="'.$url.
'"';
543 $linkstart .= $linkclose.
'>';
546 $result .= $linkstart;
547 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright pictofixedwidth"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip pictofixedwidth"'), 0, 0, $notooltip ? 0 : 1);
548 if ($withpicto != 2) $result .= $this->ref;
552 global $action, $hookmanager;
553 $hookmanager->initHooks(array(
'salarypayment'));
554 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
555 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
556 if ($reshook > 0) $result = $hookmanager->resPrint;
557 else $result .= $hookmanager->resPrint;
569 $table =
'payment_salary';
570 $field =
'fk_salary';
572 $sql =
'SELECT sum(amount) as amount';
573 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
574 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
576 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
582 $obj = $this->
db->fetch_object(
$resql);
583 if ($obj) $amount = $obj->amount ? $obj->amount : 0;
600 $sql =
'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
601 $sql .=
' FROM '.MAIN_DB_PREFIX.
'salary as ps';
602 $sql .=
' WHERE ps.rowid = '.((int) $id);
604 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
605 $result = $this->
db->query($sql);
608 if ($this->
db->num_rows($result)) {
609 $obj = $this->
db->fetch_object($result);
610 $this->
id = $obj->rowid;
612 $this->user_creation_id = $obj->fk_user_author;
613 $this->user_modification_id = $obj->fk_user_modif;
614 $this->date_creation = $this->
db->jdate($obj->datec);
615 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
617 $this->
db->free($result);
633 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
635 $sql .=
" WHERE rowid = ".((int) $this->
id);
636 $return = $this->
db->query($sql);
637 if ($return)
return 1;
651 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
653 $sql .=
" WHERE rowid = ".((int) $this->
id);
654 $return = $this->
db->query($sql);
655 if ($return)
return 1;
669 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
681 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
687 $langs->loadLangs(array(
"customers",
"bills"));
690 $this->labelStatus = array();
691 $this->labelStatusShort = array();
693 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
696 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
697 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
698 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
699 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
700 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
701 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
704 $statusType =
'status1';
705 if ($status == 0 && $alreadypaid <> 0) $statusType =
'status3';
706 if ($status == 1) $statusType =
'status6';
708 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage salary payments.
fetch($id, $user=null)
Load object in memory from database.
initAsSpecimen()
Initialise an instance with random values.
update($user=null, $notrigger=0)
Update database.
update_fk_bank($id_bank)
Update link between payment salary and line generate into llx_bank.
LibStatut($status, $mode=0, $alreadypaid=-1)
Renvoi le libelle d'un statut donne.
set_paid($user)
Tag social contribution as payed completely.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
set_unpaid($user)
Remove tag payed on social contribution.
create($user)
Create in database.
getLibStatut($mode=0, $alreadypaid=-1)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
$paye
1 if salary paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
info($id)
Information on record.
__construct($db)
Constructor.
getSommePaiement()
Return amount of payments already done.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.