26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'payment_salary';
42 public $table_element =
'payment_salary';
47 public $picto =
'payment';
84 public $fk_user_author;
89 public $fk_user_modif;
94 public $fields = array();
105 $this->element =
'payment_salary';
106 $this->table_element =
'payment_salary';
116 public function update($user = null, $notrigger = 0)
118 global $conf, $langs;
123 $this->amount = trim($this->amount);
124 $this->label = trim($this->label);
128 if (empty($this->fk_user) || $this->fk_user < 0)
130 $this->error =
'ErrorBadParameter';
137 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET";
139 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
140 $sql .=
" fk_user=".$this->fk_user.
",";
141 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
142 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
143 $sql .=
" amount=".price2num($this->amount).
",";
144 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
145 $sql .=
" fk_typepayment=".$this->fk_typepayment.
"',";
146 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
147 $sql .=
" label='".$this->db->escape($this->label).
"',";
148 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
149 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
150 $sql .=
" note='".$this->db->escape($this->
note).
"',";
151 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
152 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
153 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif :
'null');
155 $sql .=
" WHERE rowid=".$this->id;
157 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
161 $this->error =
"Error ".$this->db->lasterror();
181 $result = $this->
call_trigger(
'PAYMENT_SALARY_MODIFY', $user);
182 if ($result < 0) $error++;
191 $this->
db->rollback();
204 public function fetch($id, $user = null)
211 $sql .=
" s.fk_user,";
214 $sql .=
" s.amount,";
215 $sql .=
" s.fk_projet as fk_project,";
216 $sql .=
" s.fk_typepayment,";
217 $sql .=
" s.num_payment,";
219 $sql .=
" s.datesp,";
220 $sql .=
" s.dateep,";
222 $sql .=
" s.fk_bank,";
223 $sql .=
" s.fk_user_author,";
224 $sql .=
" s.fk_user_modif,";
225 $sql .=
" b.fk_account,";
226 $sql .=
" b.fk_type,";
229 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as s";
230 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
231 $sql .=
" WHERE s.rowid = ".$id;
233 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
239 $obj = $this->
db->fetch_object(
$resql);
241 $this->
id = $obj->rowid;
242 $this->ref = $obj->rowid;
243 $this->tms = $this->
db->jdate($obj->tms);
244 $this->fk_user = $obj->fk_user;
245 $this->datep = $this->
db->jdate($obj->datep);
246 $this->datev = $this->
db->jdate($obj->datev);
247 $this->amount = $obj->amount;
248 $this->fk_project = $obj->fk_project;
249 $this->type_payement = $obj->fk_typepayment;
250 $this->num_payment = $obj->num_payment;
251 $this->label = $obj->label;
252 $this->datesp = $this->
db->jdate($obj->datesp);
253 $this->dateep = $this->
db->jdate($obj->dateep);
254 $this->
note = $obj->note;
255 $this->fk_bank = $obj->fk_bank;
256 $this->fk_user_author = $obj->fk_user_author;
257 $this->fk_user_modif = $obj->fk_user_modif;
258 $this->fk_account = $obj->fk_account;
259 $this->fk_type = $obj->fk_type;
260 $this->rappro = $obj->rappro;
270 $this->error =
"Error ".$this->db->lasterror();
282 public function delete($user)
284 global $conf, $langs;
289 $result = $this->
call_trigger(
'PAYMENT_SALARY_DELETE', $user);
290 if ($result < 0)
return -1;
296 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_salary_extrafields";
297 $sql .=
" WHERE fk_object=".$this->id;
302 $this->errors[] = $this->
db->lasterror();
307 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_salary";
308 $sql .=
" WHERE rowid=".$this->id;
310 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
314 $this->error =
"Error ".$this->db->lasterror();
343 $this->fk_user_author =
'';
344 $this->fk_user_modif =
'';
355 global $conf, $langs;
361 $this->amount =
price2num(trim($this->amount));
362 $this->label = trim($this->label);
364 $this->fk_bank = trim($this->fk_bank);
365 $this->fk_user_author = trim($this->fk_user_author);
366 $this->fk_user_modif = trim($this->fk_user_modif);
371 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
374 if ($this->fk_user < 0 || $this->fk_user ==
'')
376 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
379 if ($this->amount < 0 || $this->amount ==
'')
381 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
384 if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
386 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
389 if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
391 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
398 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_salary (fk_user";
402 $sql .=
", fk_projet";
404 $sql .=
", fk_typepayment";
405 $sql .=
", num_payment";
406 if ($this->
note) $sql .=
", note";
410 $sql .=
", fk_user_author";
416 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
417 $sql .=
", '".$this->db->idate($this->datep).
"'";
418 $sql .=
", '".$this->db->idate($this->datev).
"'";
419 $sql .=
", ".$this->amount;
420 $sql .=
", ".($this->fk_project > 0 ? $this->fk_project : 0);
421 $sql .=
", ".($this->salary > 0 ? $this->salary :
"null");
422 $sql .=
", ".$this->db->escape($this->type_payment);
423 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
424 if ($this->
note) $sql .=
", '".$this->db->escape($this->
note).
"'";
425 $sql .=
", '".$this->db->escape($this->label).
"'";
426 $sql .=
", '".$this->db->idate($this->datesp).
"'";
427 $sql .=
", '".$this->db->idate($this->dateep).
"'";
428 $sql .=
", '".$this->db->escape($user->id).
"'";
429 $sql .=
", '".$this->db->idate($now).
"'";
431 $sql .=
", ".$conf->entity;
434 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
435 $result = $this->
db->query($sql);
438 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_salary");
442 if (!empty($conf->banque->enabled) && !empty($this->amount))
445 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
448 $result = $acc->fetch($this->accountid);
465 $bank_line_id = $acc->addline(
481 if ($bank_line_id > 0)
485 $this->error = $acc->error;
492 $url = DOL_URL_ROOT.
'/salaries/card.php?id=';
494 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(SalaryPayment)",
"payment_salary");
497 $this->error = $acc->error;
502 $fuser =
new User($this->
db);
503 $fuser->fetch($this->fk_user);
506 $result = $acc->add_url_line(
509 DOL_URL_ROOT.
'/user/card.php?id=',
510 $fuser->getFullName($langs),
517 $this->error = $acc->error;
523 $result = $this->
call_trigger(
'PAYMENT_SALARY_CREATE', $user);
524 if ($result < 0) $error++;
533 $this->
db->rollback();
537 $this->error = $this->
db->error();
538 $this->
db->rollback();
553 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_salary SET fk_bank = '.$id_bank;
554 $sql .=
' WHERE rowid = '.$this->id;
555 $result = $this->
db->query($sql);
576 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
578 global $db, $conf, $langs, $hookmanager;
579 global $dolibarr_main_authentication, $dolibarr_main_demo;
582 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
586 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SalaryPayment").
'</u>';
587 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
588 if (!empty($this->label)) {
589 $labeltoshow = $this->label;
591 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg))
594 if ($reg[1] ==
'paiement') $reg[1] =
'Payment';
595 $labeltoshow = $langs->trans($reg[1]);
597 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
600 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
602 if ($option !=
'nolink')
605 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
606 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
607 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
611 if (empty($notooltip))
613 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
615 $label = $langs->trans(
"ShowMyObject");
616 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
618 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
619 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
627 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
629 $linkstart =
'<a href="'.$url.
'"';
630 $linkstart .= $linkclose.
'>';
633 $result .= $linkstart;
634 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
635 if ($withpicto != 2) $result .= $this->ref;
639 global $action, $hookmanager;
640 $hookmanager->initHooks(array(
'salarypayment'));
641 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
642 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
643 if ($reshook > 0) $result = $hookmanager->resPrint;
644 else $result .= $hookmanager->resPrint;
657 $sql =
'SELECT ps.rowid, ps.datec, ps.fk_user_author';
658 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_salary as ps';
659 $sql .=
' WHERE ps.rowid = '.$id;
661 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
662 $result = $this->
db->query($sql);
666 if ($this->
db->num_rows($result))
668 $obj = $this->
db->fetch_object($result);
669 $this->
id = $obj->rowid;
670 if ($obj->fk_user_author)
672 $cuser =
new User($this->
db);
673 $cuser->fetch($obj->fk_user_author);
674 $this->user_creation = $cuser;
676 $this->date_creation = $this->
db->jdate($obj->datec);
678 $this->
db->free($result);
709 $langs->load(
'compta');
create($user)
Create in database.
fetch($id, $user=null)
Load object in memory from database.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) ...
Class to manage salary payments.
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.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
update_fk_bank($id_bank)
Update link between payment salary and line generate into llx_bank.
$conf db
API class for accounts.
Class to manage bank accounts.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
__construct($db)
Constructor.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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...
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
info($id)
Information on record.
initAsSpecimen()
Initialise an instance with random values.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
update($user=null, $notrigger=0)
Update database.