32require
'../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/salaries/class/salary.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/salaries.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
42if (isModEnabled(
'project')) {
43 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
48$langs->loadLangs(array(
"compta",
"banks",
"bills",
"users",
"salaries",
"hrm",
"trips"));
49if (isModEnabled(
'project')) {
50 $langs->load(
"projects");
55$action =
GETPOST(
'action',
'aZ09');
56$cancel =
GETPOST(
'cancel',
'alpha');
57$backtopage =
GETPOST(
'backtopage',
'alpha');
58$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
61$label =
GETPOST(
'label',
'alphanohtml');
62$projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') :
GETPOST(
'fk_project',
'int'));
63$accountid =
GETPOST(
'accountid',
'int') > 0 ?
GETPOST(
'accountid',
'int') : 0;
64if (GETPOSTISSET(
'auto_create_paiement') || $action ===
'add') {
65 $auto_create_paiement =
GETPOST(
"auto_create_paiement",
"int");
79$childids = $user->getAllChildIds(1);
82$extrafields->fetch_name_optionals_label($object->table_element);
85$hookmanager->initHooks(array(
'salarycard',
'globalcard'));
87if ($id > 0 || !empty($ref)) {
88 $object->fetch($id, $ref);
92 if ($user->hasRight(
'salaries',
'readall')) {
95 if ($user->hasRight(
'salaries',
'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
106 $socid = $user->socid;
111$permissiontoread = $user->hasRight(
'salaries',
'read');
112$permissiontoadd = $user->hasRight(
'salaries',
'write');
113$permissiontodelete = $user->hasRight(
'salaries',
'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
115$upload_dir = $conf->salaries->multidir_output[$conf->entity];
122$parameters = array();
124$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
129if (empty($reshook)) {
132 $backurlforlist = DOL_URL_ROOT.
'/salaries/list.php';
134 if (empty($backtopage) || ($cancel && empty($id))) {
135 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
136 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
137 $backtopage = $backurlforlist;
139 $backtopage = DOL_URL_ROOT.
'/salaries/card.php?id='.($id > 0 ? $id :
'__ID__');
147 if (!empty($backtopageforcancel)) {
148 header(
"Location: ".$backtopageforcancel);
150 } elseif (!empty($backtopage)) {
151 header(
"Location: ".$backtopage);
158 $triggersendname =
'COMPANY_SENTBYMAIL';
160 $mode =
'emailfromthirdparty';
161 $trackid =
'sal'.$object->id;
162 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
166 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
170if ($action ==
'classin' && $permissiontoadd) {
172 $object->setProject($projectid);
176if ($action ==
'setlabel' && $permissiontoadd) {
178 $object->label = $label;
179 $object->update($user);
183if ($action ==
'confirm_paid' && $permissiontoadd && $confirm ==
'yes') {
185 $result = $object->setPaid($user);
188if ($action ==
'setfk_user' && $permissiontoadd) {
189 $result = $object->fetch($id);
191 $object->fk_user = $fk_user;
192 $object->update($user);
199if ($action ==
'reopen' && $permissiontoadd) {
200 $result = $object->fetch($id);
202 $result = $object->set_unpaid($user);
204 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$id);
213if ($action ==
'setmode' && $permissiontoadd) {
215 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
222if ($action ==
'setbankaccount' && $permissiontoadd) {
224 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
230if ($action ==
'add' && empty($cancel)) {
237 $type_payment =
GETPOST(
"paymenttype",
'alpha');
240 $object->accountid =
GETPOST(
"accountid",
'int') > 0 ?
GETPOST(
"accountid",
"int") : 0;
241 $object->fk_user =
GETPOST(
"fk_user",
'int') > 0 ?
GETPOST(
"fk_user",
"int") : 0;
242 $object->datev = $datev;
243 $object->datep = $datep;
244 $object->amount = $amount;
245 $object->label =
GETPOST(
"label",
'alphanohtml');
246 $object->datesp = $datesp;
247 $object->dateep = $dateep;
248 $object->note =
GETPOST(
"note",
'restricthtml');
249 $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
250 $object->fk_user_author = $user->id;
251 $object->fk_project = $projectid;
254 $fuser =
new User($db);
255 $fuser->fetch(
GETPOST(
"fk_user",
"int"));
256 $object->salary = $fuser->salary;
259 $ret = $extrafields->setOptionalsFromPost(
null, $object);
264 if (!empty($auto_create_paiement) && empty($datep)) {
265 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DATE_PAIEMENT")),
null,
'errors');
268 if (empty($datesp) || empty($dateep)) {
269 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
272 if (empty($object->fk_user) || $object->fk_user < 0) {
273 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Employee")),
null,
'errors');
276 if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) {
277 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PaymentMode")),
null,
'errors');
280 if (empty($object->amount)) {
281 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
284 if (isModEnabled(
"banque") && !empty($auto_create_paiement) && !$object->accountid > 0) {
285 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
292 $ret = $object->create($user);
297 if (!empty($auto_create_paiement) && !$error) {
300 $paiement->fk_salary = $object->id;
301 $paiement->chid = $object->id;
302 $paiement->datep = $datep;
303 $paiement->datev = $datev;
304 $paiement->amounts = array($object->id=>$amount);
305 $paiement->fk_typepayment = $type_payment;
306 $paiement->num_payment =
GETPOST(
"num_payment",
'alphanohtml');
307 $paiement->note_private =
GETPOST(
"note",
'restricthtml');
310 $paymentid = $paiement->create($user, (
int)
GETPOST(
'closepaidsalary'));
311 if ($paymentid < 0) {
319 $result = $paiement->addPaymentToBank($user,
'payment_salary',
'(SalaryPayment)',
GETPOST(
'accountid',
'int'),
'',
'');
320 if (!($result > 0)) {
330 if (
GETPOST(
'saveandnew',
'alpha')) {
332 header(
"Location: card.php?action=create&fk_project=" . urlencode($projectid) .
"&accountid=" . urlencode($accountid) .
'&paymenttype=' . urlencode(
GETPOST(
'paymenttype',
'aZ09')) .
'&datepday=' .
GETPOST(
"datepday",
'int') .
'&datepmonth=' .
GETPOST(
"datepmonth",
'int') .
'&datepyear=' .
GETPOST(
"datepyear",
'int'));
335 header(
"Location: " . $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id);
346if ($action ==
'confirm_delete') {
347 $result = $object->fetch($id);
348 $totalpaid = $object->getSommePaiement();
350 if (empty($totalpaid)) {
353 $ret = $object->delete($user);
356 header(
"Location: ".DOL_URL_ROOT.
'/salaries/list.php');
368if ($action ==
'update' && !
GETPOST(
"cancel") && $permissiontoadd) {
371 if (empty($amount)) {
372 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount")),
null,
'errors');
374 } elseif (!is_numeric($amount)) {
375 setEventMessages($langs->trans(
"ErrorFieldMustBeANumeric", $langs->transnoentities(
"Amount")),
null,
'errors');
378 $result = $object->fetch($id);
384 $result = $object->update($user);
391if ($action ==
'confirm_clone' && $confirm !=
'yes') {
395if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
402 if ($object->id > 0) {
404 $object->id = $object->ref =
null;
406 if (
GETPOST(
'amount',
'alphanohtml')) {
410 if (
GETPOST(
'clone_label',
'alphanohtml')) {
411 $object->label =
GETPOST(
'clone_label',
'alphanohtml');
413 $object->label = $langs->trans(
"CopyOf").
' '.$object->label;
416 $newdatestart =
dol_mktime(0, 0, 0,
GETPOST(
'clone_date_startmonth',
'int'),
GETPOST(
'clone_date_startday',
'int'),
GETPOST(
'clone_date_startyear',
'int'));
420 $object->datesp = $newdatestart;
423 $object->dateep = $newdateend;
426 $id = $object->create($user);
431 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
446if ($action ==
"update_extras" && $permissiontoadd) {
447 $object->fetch(
GETPOST(
'id',
'int'));
449 $attributekey =
GETPOST(
'attribute',
'alpha');
450 $attributekeylong =
'options_'.$attributekey;
452 if (GETPOSTISSET($attributekeylong.
'day') && GETPOSTISSET($attributekeylong.
'month') && GETPOSTISSET($attributekeylong.
'year')) {
454 $object->array_options[
'options_'.$attributekey] =
dol_mktime(
GETPOST($attributekeylong.
'hour',
'int'),
GETPOST($attributekeylong.
'min',
'int'),
GETPOST($attributekeylong.
'sec',
'int'),
GETPOST($attributekeylong.
'month',
'int'),
GETPOST($attributekeylong.
'day',
'int'),
GETPOST($attributekeylong.
'year',
'int'));
457 $object->array_options[
'options_'.$attributekey] =
GETPOST($attributekeylong,
'alpha');
460 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
466 $action =
'edit_extras';
474$form =
new Form($db);
476if (isModEnabled(
'project')) {
480$title = $langs->trans(
'Salary').
" - ".$object->ref;
481if ($action ==
'create') {
482 $title = $langs->trans(
"NewSalary");
489 $result = $object->fetch($id);
497if ($action ==
'create' && $permissiontoadd) {
499 $pastmonth = strftime(
"%m",
dol_now()) - 1;
500 $pastmonthyear = $year_current;
501 if ($pastmonth == 0) {
506 $datespmonth =
GETPOST(
'datespmonth',
'int');
507 $datespday =
GETPOST(
'datespday',
'int');
508 $datespyear =
GETPOST(
'datespyear',
'int');
509 $dateepmonth =
GETPOST(
'dateepmonth',
'int');
510 $dateepday =
GETPOST(
'dateepday',
'int');
511 $dateepyear =
GETPOST(
'dateepyear',
'int');
512 $datesp =
dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
513 $dateep =
dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
515 if (empty($datesp) || empty($dateep)) {
520 print
'<form name="salary" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
521 print
'<input type="hidden" name="token" value="'.newToken().
'">';
522 print
'<input type="hidden" name="action" value="add">';
524 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
526 if ($backtopageforcancel) {
527 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
532 if (!empty($conf->use_javascript_ajax)) {
533 print
"\n".
'<script type="text/javascript">';
535 $(document).ready(function () {
536 let onAutoCreatePaiementChange = function () {
537 if($("#auto_create_paiement").is(":checked")) {
538 $("#label_fk_account").find("span").addClass("fieldrequired");
539 $("#label_type_payment").find("span").addClass("fieldrequired");
540 $(".hide_if_no_auto_create_payment").show();
542 $("#label_fk_account").find("span").removeClass("fieldrequired");
543 $("#label_type_payment").find("span").removeClass("fieldrequired");
544 $(".hide_if_no_auto_create_payment").hide();
547 $("#radiopayment").click(function() {
548 $("#label").val($(this).data("label"));
550 $("#radiorefund").click(function() {
551 $("#label").val($(this).data("label"));
553 $("#auto_create_paiement").click(function () {
554 onAutoCreatePaiementChange();
556 onAutoCreatePaiementChange();
559 print
'</script>'.
"\n";
564 print
'<table class="border centpercent">';
567 print
'<tr><td class="titlefieldcreate">';
568 print $form->editfieldkey(
'Employee',
'fk_user',
'', $object, 0,
'string',
'', 1).
'</td><td>';
570 print
img_picto(
'',
'user',
'class="paddingrighonly"').$form->select_dolusers(
GETPOST(
'fk_user',
'int'),
'fk_user', 1,
'', 0,
'',
'', 0, 0, 0,
'AND employee=1', 0,
'',
'maxwidth300', $noactive);
575 print $form->editfieldkey(
'Label',
'label',
'', $object, 0,
'string',
'', 1).
'</td><td>';
576 print
'<input name="label" id="label" class="minwidth300" value="'.(GETPOST(
"label") ?
GETPOST(
"label") : $langs->trans(
"Salary")).
'">';
581 print $form->editfieldkey(
'DateStartPeriod',
'datesp',
'', $object, 0,
'string',
'', 1).
'</td><td>';
582 print $form->selectDate($datesp,
"datesp",
'',
'',
'',
'add');
587 print $form->editfieldkey(
'DateEndPeriod',
'dateep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
588 print $form->selectDate($dateep,
"dateep",
'',
'',
'',
'add');
593 print $form->editfieldkey(
'Amount',
'amount',
'', $object, 0,
'string',
'', 1).
'</td><td>';
594 print
'<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST(
"amount").
'"> ';
595 print
' <button class="dpInvisibleButtons datenowlink" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans(
'UpdateAmountWithLastSalary').
'</a>';
600 if (isModEnabled(
'project')) {
603 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
604 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
605 print $formproject->select_projects(-1, $projectid,
'fk_project', 0, 0, 1, 1, 0, 0, 0,
'', 1);
611 print
'<td class="tdtop">'.$langs->trans(
"Comments").
'</td>';
612 print
'<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.
'">'.
GETPOST(
'note',
'restricthtml').
'</textarea></td>';
616 print
'<tr><td colspan="2"><hr></td></tr>';
620 print
'<tr><td><label for="auto_create_paiement">'.$langs->trans(
'AutomaticCreationPayment').
'</label></td>';
621 print
'<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_paiement) ?
'' :
'checked="checked"') .
' value="1"></td></tr>'.
"\n";
624 if (isModEnabled(
"banque")) {
625 print
'<tr><td id="label_fk_account">';
626 print $form->editfieldkey(
'BankAccount',
'selectaccountid',
'', $object, 0,
'string',
'', 1).
'</td><td>';
627 print
img_picto(
'',
'bank_account',
'class="paddingrighonly"');
628 $form->select_comptes($accountid,
"accountid", 0,
'', 1);
633 print
'<tr><td id="label_type_payment">';
634 print $form->editfieldkey(
'PaymentMode',
'selectpaymenttype',
'', $object, 0,
'string',
'', 1).
'</td><td>';
635 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
636 print $form->select_types_paiements(
GETPOST(
"paymenttype",
'aZ09'),
"paymenttype",
'');
640 print
'<tr class="hide_if_no_auto_create_payment"><td>';
641 print $form->editfieldkey(
'DatePayment',
'datep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
642 print $form->selectDate((empty($datep) ?
'' : $datep),
"datep", 0, 0, 0,
'add', 1, 1);
646 print
'<tr class="hide_if_no_auto_create_payment"><td>';
647 print $form->editfieldkey(
'DateValue',
'datev',
'', $object, 0).
'</td><td>';
648 print $form->selectDate((empty($datev) ? -1 : $datev),
"datev",
'',
'',
'',
'add', 1, 1);
652 if (isModEnabled(
"banque")) {
654 print
'<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans(
'Numero');
655 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
656 print
'</label></td>';
657 print
'<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST(
"num_payment").
'"></td></tr>'.
"\n";
668 $parameters = array();
669 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
670 print $hookmanager->resPrint;
671 if (empty($reshook)) {
672 print $object->showOptionals($extrafields,
'create');
679 print
'<div class="center">';
681 print
'<div class="hide_if_no_auto_create_payment paddingbottom">';
682 print
'<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans(
"ClosePaidSalaryAutomatically");
687 $addition_button = array(
688 'name' =>
'saveandnew',
689 'label_key' =>
'SaveAndNew',
691 print $form->buttonsSaveCancel(
"Save",
"Cancel", $addition_button);
695 print
'$( document ).ready(function() {';
696 print
'$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
697 var fk_user = $("#fk_user").val()
698 var url = "'.DOL_URL_ROOT.
'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
699 console.log("We click on link to autofill salary amount url="+url);
705 console.log("Data returned: "+data);
707 if (typeof data == "object") {
708 console.log("data is already type object, no need to parse it");
711 console.log("data is type "+(typeof data));
712 item = JSON.parse(data);
714 if (item[0].key == "Amount") {
715 value = item[0].value;
716 console.log("amount returned = "+value);
718 $("#amount").val(item[0].value);
720 console.error("Error: Ajax url "+url+" has returned a null value.");
723 console.error("Error: Ajax url "+url+" has returned the wrong key.");
726 console.error("Error: Ajax url "+url+" has returned an empty page.");
732 alert("'.
dol_escape_js($langs->transnoentitiesnoconv(
"FillFieldFirst")).
'");
742 $head = salaries_prepare_head($object);
745 if ($action ===
'clone') {
746 $formquestion = array(
747 array(
'type' =>
'text',
'name' =>
'clone_label',
'label' => $langs->trans(
"Label"),
'value' => $langs->trans(
"CopyOf").
' '.$object->label),
751 $formquestion[] = array(
'type' =>
'date',
'name' =>
'clone_date_start',
'label' => $langs->trans(
"DateStart"),
'value' => -1);
752 $formquestion[] = array(
'type' =>
'date',
'name' =>
'clone_date_end',
'label' => $langs->trans(
"DateEnd"),
'value' => -1);
753 $formquestion[] = array(
'type' =>
'text',
'name' =>
'amount',
'label' => $langs->trans(
"Amount"),
'value' =>
price($object->amount),
'morecss' =>
'width100 right');
755 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneSalary', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 280);
758 $formconfirm .=
"<script>
759 $('#clone_date_end').after($('<button id=\"fill_end_of_month\" class=\"dpInvisibleButtons\" style=\"color: var(--colortextlink);font-size: 0.8em;opacity: 0.7;margin-left:4px;\" type=\"button\">".$langs->trans(
'FillEndOfMonth').
"</button>'));
760 $('#fill_end_of_month').click(function(){
761 var clone_date_startmonth = +$('#clone_date_startmonth').val();
762 var clone_date_startyear = +$('#clone_date_startyear').val();
763 var end_date = new Date(clone_date_startyear, clone_date_startmonth, 0);
764 end_date.setMonth(clone_date_startmonth - 1);
765 $('#clone_date_end').val(formatDate(end_date,'".$langs->trans(
"FormatDateShortJavaInput").
"'));
766 $('#clone_date_endday').val(end_date.getDate());
767 $('#clone_date_endmonth').val(end_date.getMonth() + 1);
768 $('#clone_date_endyear').val(end_date.getFullYear());
773 if ($action ==
'paid') {
774 $text = $langs->trans(
'ConfirmPaySalary');
775 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
'PaySalary'), $text,
"confirm_paid",
'',
'', 2);
778 if ($action ==
'delete') {
779 $text = $langs->trans(
'ConfirmDeleteSalary');
780 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'DeleteSalary'), $text,
'confirm_delete',
'',
'', 2);
783 if ($action ==
'edit') {
784 print
"<form name=\"charge\" action=\"".$_SERVER[
"PHP_SELF"].
"?id=$object->id&action=update\" method=\"post\">";
785 print
'<input type="hidden" name="token" value="'.newToken().
'">';
789 $parameters = array(
'formConfirm' => $formconfirm);
790 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
791 if (empty($reshook)) {
792 $formconfirm .= $hookmanager->resPrint;
793 } elseif ($reshook > 0) {
794 $formconfirm = $hookmanager->resPrint;
801 print
dol_get_fiche_head($head,
'card', $langs->trans(
"SalaryPayment"), -1,
'salary', 0,
'',
'', 0,
'', 1);
803 $linkback =
'<a href="'.DOL_URL_ROOT.
'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
805 $morehtmlref =
'<div class="refidno">';
808 if ($action !=
'editlabel') {
809 $morehtmlref .= $form->editfieldkey(
"Label",
'label', $object->label, $object, $permissiontoadd,
'string',
'', 0, 1);
810 $morehtmlref .= $object->label;
812 $morehtmlref .= $langs->trans(
'Label').
' : ';
813 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
814 $morehtmlref .=
'<input type="hidden" name="action" value="setlabel">';
815 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
816 $morehtmlref .=
'<input type="text" name="label" value="'.$object->label.
'"/>';
817 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
818 $morehtmlref .=
'</form>';
822 if ($action !=
'editfk_user') {
823 if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
824 $userstatic =
new User($db);
825 $result = $userstatic->fetch($object->fk_user);
827 $morehtmlref .=
'<br>' .$langs->trans(
'Employee').
' : '.$userstatic->getNomUrl(-1);
830 $morehtmlref .=
'<br>' . $form->editfieldkey(
"Employee",
'fk_user', $object->label, $object, $permissiontoadd,
'string',
'', 0, 1);
832 if (!empty($object->fk_user)) {
833 $userstatic =
new User($db);
834 $result = $userstatic->fetch($object->fk_user);
836 $morehtmlref .= $userstatic->getNomUrl(-1);
844 $morehtmlref .=
'<br>'.$langs->trans(
'Employee').
' : ';
845 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
846 $morehtmlref .=
'<input type="hidden" name="action" value="setfk_user">';
847 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
848 $morehtmlref .= $form->select_dolusers($object->fk_user,
'userid', 1);
849 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
850 $morehtmlref .=
'</form>';
853 $usercancreate = $permissiontoadd;
856 if (isModEnabled(
'project')) {
857 $langs->load(
"projects");
858 $morehtmlref .=
'<br>';
859 if ($usercancreate) {
860 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
861 if ($action !=
'classify') {
862 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
864 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, -1, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
866 if (!empty($object->fk_project)) {
868 $proj->fetch($object->fk_project);
869 $morehtmlref .= $proj->getNomUrl(1);
871 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
877 $morehtmlref .=
'</div>';
879 $totalpaid = $object->getSommePaiement();
880 $object->alreadypaid = $totalpaid;
881 $object->totalpaid = $totalpaid;
883 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'',
'');
885 print
'<div class="fichecenter">';
886 print
'<div class="fichehalfleft">';
887 print
'<div class="underbanner clearboth"></div>';
889 print
'<table class="border centpercent tableforfield">';
891 if ($action ==
'edit') {
892 print
'<tr><td class="titlefield">'.$langs->trans(
"DateStartPeriod").
"</td><td>";
893 print $form->selectDate($object->datesp,
'datesp', 0, 0, 0,
'datesp', 1);
897 print
'<td class="titlefield">' . $langs->trans(
"DateStartPeriod") .
'</td><td>';
902 if ($action ==
'edit') {
903 print
'<tr><td>'.$langs->trans(
"DateEndPeriod").
"</td><td>";
904 print $form->selectDate($object->dateep,
'dateep', 0, 0, 0,
'dateep', 1);
908 print
'<td>' . $langs->trans(
"DateEndPeriod") .
'</td><td>';
922 if ($action ==
'edit') {
923 print
'<tr><td class="fieldrequired">' . $langs->trans(
"Amount") .
'</td><td><input name="amount" size="10" value="' .
price($object->amount) .
'"></td></tr>';
925 print
'<tr><td>' . $langs->trans(
"Amount") .
'</td><td><span class="amount">' .
price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) .
'</span></td></tr>';
930 print
'<table class="nobordernopadding" width="100%"><tr><td>';
931 print $langs->trans(
'DefaultPaymentMode');
933 if ($action !=
'editmode') {
934 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
936 print
'</tr></table>';
939 if ($action ==
'editmode') {
940 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->type_payment,
'mode_reglement_id');
942 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->type_payment,
'none');
947 if (isModEnabled(
"banque")) {
948 print
'<tr><td class="nowrap">';
949 print
'<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
950 print $langs->trans(
'DefaultBankAccount');
952 if ($action !=
'editbankaccount' && $permissiontoadd) {
953 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
955 print
'</tr></table>';
957 if ($action ==
'editbankaccount') {
958 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
960 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
967 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
973 print
'<div class="fichehalfright">';
976 if (isModEnabled(
"banque")) {
983 $sql =
"SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
984 $sql .=
" c.code as type_code,c.libelle as paiement_type,";
985 $sql .=
' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
986 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
987 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
988 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
989 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
990 $sql .=
", ".MAIN_DB_PREFIX.
"salary as salaire";
991 $sql .=
" WHERE p.fk_salary = ".((int) $id);
992 $sql .=
" AND p.fk_salary = salaire.rowid";
993 $sql .=
" AND salaire.entity IN (".getEntity(
'tax').
")";
994 $sql .=
" ORDER BY dp DESC";
996 $resql = $db->query($sql);
1000 $num = $db->num_rows($resql);
1004 print
'<div class="div-table-responsive-no-min">';
1005 print
'<table class="noborder paymenttable">';
1006 print
'<tr class="liste_titre">';
1007 print
'<td>'.$langs->trans(
"RefPayment").
'</td>';
1008 print
'<td>'.$langs->trans(
"Date").
'</td>';
1009 print
'<td>'.$langs->trans(
"Type").
'</td>';
1010 if (isModEnabled(
"banque")) {
1011 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1013 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
1019 $bankaccountstatic =
new Account($db);
1021 $objp = $db->fetch_object($resql);
1023 $paymentsalarytemp->id = $objp->rowid;
1024 $paymentsalarytemp->ref = $objp->rowid;
1025 $paymentsalarytemp->num_payment = $objp->num_payment;
1026 $paymentsalarytemp->datep = $objp->dp;
1028 print
'<tr class="oddeven"><td>';
1029 print $paymentsalarytemp->getNomUrl(1);
1031 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'dayhour',
'tzuserrel').
"</td>\n";
1032 $labeltype = $langs->trans(
"PaymentType".$objp->type_code) !=
"PaymentType".$objp->type_code ? $langs->trans(
"PaymentType".$objp->type_code) : $objp->paiement_type;
1033 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
1034 if (isModEnabled(
"banque")) {
1035 $bankaccountstatic->id = $objp->baid;
1036 $bankaccountstatic->ref = $objp->baref;
1037 $bankaccountstatic->label = $objp->baref;
1038 $bankaccountstatic->number = $objp->banumber;
1039 $bankaccountstatic->currency_code = $objp->bacurrency_code;
1041 if (isModEnabled(
'accounting')) {
1042 $bankaccountstatic->account_number = $objp->account_number;
1045 $accountingjournal->fetch($objp->fk_accountancy_journal);
1046 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
1049 print
'<td class="right">';
1050 if ($bankaccountstatic->id) {
1051 print $bankaccountstatic->getNomUrl(1,
'transactions');
1055 print
'<td class="right nowrap amountcard">'.price($objp->amount).
"</td>\n";
1057 $totalpaid += $objp->amount;
1061 print
'<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td>';
1062 print
'<td></td><td></td><td></td><td></td>';
1066 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
' :</td><td class="right nowrap amountcard">'.
price($totalpaid).
"</td></tr>\n";
1067 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
' :</td><td class="right nowrap amountcard">'.
price($object->amount).
"</td></tr>\n";
1069 $resteapayer = $object->amount - $totalpaid;
1070 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
1072 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
" :</td>";
1073 print
'<td class="right nowrap'.($resteapayer ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayer).
"</td></tr>\n";
1086 print
'<div class="clearboth"></div>';
1090 if ($action ==
'edit') {
1091 print $form->buttonsSaveCancel();
1095 $resteapayer =
price2num($resteapayer,
'MT');
1102 print
'<div class="tabsAction">'.
"\n";
1103 if ($action !=
'edit') {
1105 $parameters = array();
1106 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1107 if (empty($reshook)) {
1108 if (empty($user->socid)) {
1109 $canSendMail =
true;
1111 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
'PHP_SELF'] .
'?id=' . $object->id .
'&action=presend&token='.newToken().
'&mode=init#formmailbeforetitle',
'', $canSendMail);
1116 if ($object->paye && $permissiontoadd) {
1117 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.newToken().
'&id='.$object->id,
'');
1121 if ($object->paye == 0 && $permissiontoadd) {
1122 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'&id='.$object->id,
'');
1126 if ($object->paye == 0 && ((
price2num($object->amount) < 0 && $resteapayer < 0) || (
price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
1127 print
dolGetButtonAction(
'', $langs->trans(
'DoPayment'),
'default', DOL_URL_ROOT.
'/salaries/paiement_salary.php?action=create&token='.newToken().
'&id='. $object->id,
'');
1132 if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $permissiontoadd) {
1133 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyPaid'),
'default', $_SERVER[
"PHP_SELF"].
'?action=paid&token='.newToken().
'&id='.$object->id,
'');
1137 print
dolGetButtonAction(
'', $langs->trans(
'MakeTransferRequest'),
'default', DOL_URL_ROOT.
'/salaries/virement_request.php?id='.$object->id,
'');
1140 if ($permissiontoadd) {
1141 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.newToken().
'&id='.$object->id,
'');
1144 if ($permissiontodelete && empty($totalpaid)) {
1145 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&id='.$object->id,
'');
1147 print
dolGetButtonAction($langs->trans(
'DisabledBecausePayments'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
1155 if (
GETPOST(
'modelselected')) {
1156 $action =
'presend';
1159 if ($action !=
'presend') {
1160 print
'<div class="fichecenter"><div class="fichehalfleft">';
1161 print
'<a name="builddoc"></a>';
1163 $includedocgeneration = 1;
1166 if ($includedocgeneration) {
1168 $relativepath = $objref.
'/'.$objref.
'.pdf';
1169 $filedir = $conf->salaries->dir_output.
'/'.$objref;
1170 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
1173 $delallowed = $permissiontoadd;
1174 print $formfile->showdocuments(
'salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
1183 print
'</div><div class="fichehalfright">';
1187 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode',
dol_buildpath(
'/mymodule/myobject_agenda.php', 1).
'?id='.$object->id);
1190 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
1194 print
'</div></div>';
1198 if (
GETPOST(
'modelselected')) {
1199 $action =
'presend';
1203 $modelmail =
'salary';
1204 $defaulttopic =
'InformationMessage';
1205 $diroutput = $conf->salaries->dir_output;
1206 $trackid =
'salary'.$object->id;
1208 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
1211 $parameters = array();
1212 $reshook = $hookmanager->executeHooks(
'salaryCardTabAddMore', $parameters, $object, $action);
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting journals.
Class to manage payments of salaries.
Class to manage projects.
Class to manage salary payments.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
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_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.