dolibarr  x.y.z
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  * Copyright (C) 2014-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
5  * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
6  * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
7  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 // Load Dolibarr environment
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39 if (isModEnabled('project')) {
40  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
41  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
42 }
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips"));
46 if (isModEnabled('project')) {
47  $langs->load("projects");
48 }
49 
50 $id = GETPOSTINT('id');
51 $ref = GETPOST('ref', 'alpha');
52 $action = GETPOST('action', 'aZ09');
53 $cancel = GETPOST('cancel', 'aZ09');
54 $backtopage = GETPOST('backtopage', 'alpha');
55 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
56 $confirm = GETPOST('confirm');
57 
58 $label = GETPOST('label', 'alphanohtml');
59 $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
60 $accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0;
61 if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
62  $auto_create_paiement = GETPOST("auto_create_paiement", "int");
63 } else {
64  $auto_create_paiement = empty($conf->global->CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT);
65 }
66 
67 $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
68 $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
69 $datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int'));
70 $dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int'));
71 $fk_user = GETPOSTINT('userid');
72 
73 $object = new Salary($db);
74 $extrafields = new ExtraFields($db);
75 
76 $childids = $user->getAllChildIds(1);
77 
78 // fetch optionals attributes and labels
79 $extrafields->fetch_name_optionals_label($object->table_element);
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $hookmanager->initHooks(array('salarycard', 'globalcard'));
83 
84 if ($id > 0 || !empty($ref)) {
85  $object->fetch($id, $ref);
86 
87  // Check current user can read this salary
88  $canread = 0;
89  if (!empty($user->rights->salaries->readall)) {
90  $canread = 1;
91  }
92  if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
93  $canread = 1;
94  }
95  if (!$canread) {
97  }
98 }
99 
100 // Security check
101 $socid = GETPOSTINT('socid');
102 if ($user->socid) {
103  $socid = $user->socid;
104 }
105 
106 restrictedArea($user, 'salaries', $object->id, 'salary', '');
107 
108 $permissiontoread = $user->rights->salaries->read;
109 $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
110 $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
111 
112 
113 /*
114  * Actions
115  */
116 
117 $parameters = array();
118 // Note that $action and $object may be modified by some hooks
119 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
120 if ($reshook < 0) {
121  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
122 }
123 
124 if (empty($reshook)) {
125  $error = 0;
126 
127  $backurlforlist = DOL_URL_ROOT.'/salaries/list.php';
128 
129  if (empty($backtopage) || ($cancel && empty($id))) {
130  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
131  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
132  $backtopage = $backurlforlist;
133  } else {
134  $backtopage = DOL_URL_ROOT.'/salaries/card.php?id='.($id > 0 ? $id : '__ID__');
135  }
136  }
137  }
138 
139  if ($cancel) {
140  //var_dump($cancel);
141  //var_dump($backtopage);exit;
142  if (!empty($backtopageforcancel)) {
143  header("Location: ".$backtopageforcancel);
144  exit;
145  } elseif (!empty($backtopage)) {
146  header("Location: ".$backtopage);
147  exit;
148  }
149  $action = '';
150  }
151 }
152 
153 // Link to a project
154 if ($action == 'classin' && $user->rights->banque->modifier) {
155  $object->fetch($id);
156  $object->setProject($projectid);
157 }
158 
159 // set label
160 if ($action == 'setlabel' && $user->rights->salaries->write) {
161  $object->fetch($id);
162  $object->label = $label;
163  $object->update($user);
164 }
165 
166 // Classify paid
167 if ($action == 'confirm_paid' && $user->rights->salaries->write && $confirm == 'yes') {
168  $object->fetch($id);
169  $result = $object->set_paid($user);
170 }
171 
172 if ($action == 'setfk_user' && $user->rights->salaries->write) {
173  $result = $object->fetch($id);
174  if ($result > 0) {
175  $object->fk_user = $fk_user;
176  $object->update($user);
177  } else {
178  dol_print_error($db);
179  exit;
180  }
181 }
182 
183 if ($action == 'reopen' && $user->rights->salaries->write) {
184  $result = $object->fetch($id);
185  if ($object->paye) {
186  $result = $object->set_unpaid($user);
187  if ($result > 0) {
188  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
189  exit();
190  } else {
191  setEventMessages($object->error, $object->errors, 'errors');
192  }
193  }
194 }
195 
196 // payment mode
197 if ($action == 'setmode' && $user->rights->salaries->write) {
198  $object->fetch($id);
199  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
200  if ($result < 0)
201  setEventMessages($object->error, $object->errors, 'errors');
202 }
203 
204 // bank account
205 if ($action == 'setbankaccount' && $user->rights->salaries->write) {
206  $object->fetch($id);
207  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
208  if ($result < 0) {
209  setEventMessages($object->error, $object->errors, 'errors');
210  }
211 }
212 
213 if ($action == 'add' && empty($cancel)) {
214  $error = 0;
215 
216  if (empty($datev)) $datev = $datep;
217 
218  $type_payment = GETPOST("paymenttype", 'alpha');
219  $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2);
220 
221  $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
222  $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", "int") : 0;
223  $object->datev = $datev;
224  $object->datep = $datep;
225  $object->amount = $amount;
226  $object->label = GETPOST("label", 'alphanohtml');
227  $object->datesp = $datesp;
228  $object->dateep = $dateep;
229  $object->note = GETPOST("note", 'restricthtml');
230  $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
231  $object->fk_user_author = $user->id;
232  $object->fk_project = $projectid;
233 
234  // Set user current salary as ref salary for the payment
235  $fuser = new User($db);
236  $fuser->fetch(GETPOST("fk_user", "int"));
237  $object->salary = $fuser->salary;
238 
239  // Fill array 'array_options' with data from add form
240  $ret = $extrafields->setOptionalsFromPost(null, $object);
241  if ($ret < 0) {
242  $error++;
243  }
244 
245  if (!empty($auto_create_paiement) && empty($datep)) {
246  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors');
247  $error++;
248  }
249  if (empty($datesp) || empty($dateep)) {
250  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
251  $error++;
252  }
253  if (empty($object->fk_user) || $object->fk_user < 0) {
254  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Employee")), null, 'errors');
255  $error++;
256  }
257  if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) {
258  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
259  $error++;
260  }
261  if (empty($object->amount)) {
262  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
263  $error++;
264  }
265  if (isModEnabled("banque") && !empty($auto_create_paiement) && !$object->accountid > 0) {
266  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
267  $error++;
268  }
269 
270  if (!$error) {
271  $db->begin();
272 
273  $ret = $object->create($user);
274  if ($ret < 0) {
275  setEventMessages($object->error, $object->errors, 'errors');
276  $error++;
277  }
278  if (!empty($auto_create_paiement) && !$error) {
279  // Create a line of payments
280  $paiement = new PaymentSalary($db);
281  $paiement->chid = $object->id;
282  $paiement->datepaye = $datep;
283  $paiement->datev = $datev;
284  $paiement->amounts = array($object->id=>$amount); // Tableau de montant
285  $paiement->paiementtype = $type_payment;
286  $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
287  $paiement->note = GETPOST("note", 'restricthtml');
288 
289  if (!$error) {
290  $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary'));
291  if ($paymentid < 0) {
292  $error++;
293  setEventMessages($paiement->error, null, 'errors');
294  $action = 'create';
295  }
296  }
297 
298  if (!$error) {
299  $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', '');
300  if (!($result > 0)) {
301  $error++;
302  setEventMessages($paiement->error, null, 'errors');
303  }
304  }
305  }
306 
307  if (empty($error)) {
308  $db->commit();
309 
310  if (GETPOST('saveandnew', 'alpha')) {
311  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
312  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'));
313  exit;
314  } else {
315  header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
316  exit;
317  }
318  } else {
319  $db->rollback();
320  }
321  }
322 
323  $action = 'create';
324 }
325 
326 if ($action == 'confirm_delete') {
327  $result = $object->fetch($id);
328  $totalpaid = $object->getSommePaiement();
329 
330  if (empty($totalpaid)) {
331  $db->begin();
332 
333  $ret = $object->delete($user);
334  if ($ret > 0) {
335  $db->commit();
336  header("Location: ".DOL_URL_ROOT.'/salaries/list.php');
337  exit;
338  } else {
339  $db->rollback();
340  setEventMessages($object->error, $object->errors, 'errors');
341  }
342  } else {
343  setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
344  }
345 }
346 
347 
348 if ($action == 'update' && !GETPOST("cancel") && $user->rights->salaries->write) {
349  $amount = price2num(GETPOST('amount'), 'MT', 2);
350 
351  if (empty($amount)) {
352  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
353  $action = 'edit';
354  } elseif (!is_numeric($amount)) {
355  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
356  $action = 'create';
357  } else {
358  $result = $object->fetch($id);
359 
360  $object->amount = price2num($amount);
361  $object->datesp = price2num($datesp);
362  $object->dateep = price2num($dateep);
363 
364  $result = $object->update($user);
365  if ($result <= 0) {
366  setEventMessages($object->error, $object->errors, 'errors');
367  }
368  }
369 }
370 
371 if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
372 
373 if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->salaries->write)) {
374  $db->begin();
375 
376  $originalId = $id;
377 
378  $object->fetch($id);
379 
380  if ($object->id > 0) {
381  $object->paye = 0;
382  $object->id = $object->ref = null;
383 
384  if (GETPOST('clone_label', 'alphanohtml')) {
385  $object->label = GETPOST('clone_label', 'alphanohtml');
386  } else {
387  $object->label = $langs->trans("CopyOf").' '.$object->label;
388  }
389 
390  $newdatestart = dol_mktime(0, 0, 0, GETPOST('clone_date_startmonth', 'int'), GETPOST('clone_date_startday', 'int'), GETPOST('clone_date_startyear', 'int'));
391  $newdateend = dol_mktime(0, 0, 0, GETPOST('clone_date_endmonth', 'int'), GETPOST('clone_date_endday', 'int'), GETPOST('clone_date_endyear', 'int'));
392 
393  if ($newdatestart) $object->datesp = $newdatestart;
394  if ($newdateend) $object->dateep = $newdateend;
395 
396  $id = $object->create($user);
397  if ($id > 0) {
398  $db->commit();
399  $db->close();
400 
401  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
402  exit;
403  } else {
404  $id = $originalId;
405  $db->rollback();
406 
407  setEventMessages($object->error, $object->errors, 'errors');
408  }
409  } else {
410  $db->rollback();
411  dol_print_error($db, $object->error);
412  }
413 }
414 
415 // Action to update one extrafield
416 if ($action == "update_extras" && !empty($user->rights->salaries->read)) {
417  $object->fetch(GETPOST('id', 'int'));
418 
419  $attributekey = GETPOST('attribute', 'alpha');
420  $attributekeylong = 'options_'.$attributekey;
421 
422  if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
423  // This is properties of a date
424  $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'));
425  //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
426  } else {
427  $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
428  }
429 
430  $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
431  if ($result > 0) {
432  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
433  $action = 'view';
434  } else {
435  setEventMessages($object->error, $object->errors, 'errors');
436  $action = 'edit_extras';
437  }
438 }
439 
440 /*
441  * View
442  */
443 
444 $form = new Form($db);
445 $formfile = new FormFile($db);
446 if (isModEnabled('project')) $formproject = new FormProjets($db);
447 
448 $title = $langs->trans('Salary')." - ".$object->ref;
449 $help_url = "";
450 
451 llxHeader('', $title, $help_url);
452 
453 
454 if ($id > 0) {
455  $result = $object->fetch($id);
456  if ($result <= 0) {
457  dol_print_error($db);
458  exit;
459  }
460 }
461 
462 // Create
463 if ($action == 'create' && $permissiontoadd) {
464  $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
465  $pastmonth = strftime("%m", dol_now()) - 1;
466  $pastmonthyear = $year_current;
467  if ($pastmonth == 0) {
468  $pastmonth = 12;
469  $pastmonthyear--;
470  }
471 
472  $datespmonth = GETPOST('datespmonth', 'int');
473  $datespday = GETPOST('datespday', 'int');
474  $datespyear = GETPOST('datespyear', 'int');
475  $dateepmonth = GETPOST('dateepmonth', 'int');
476  $dateepday = GETPOST('dateepday', 'int');
477  $dateepyear = GETPOST('dateepyear', 'int');
478  $datesp = dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
479  $dateep = dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
480 
481  if (empty($datesp) || empty($dateep)) { // We define date_start and date_end
482  $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false); $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false);
483  }
484 
485  print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
486  print '<input type="hidden" name="token" value="'.newToken().'">';
487  print '<input type="hidden" name="action" value="add">';
488  if ($backtopage) {
489  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
490  }
491  if ($backtopageforcancel) {
492  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
493  }
494 
495  print load_fiche_titre($langs->trans("NewSalary"), '', 'salary');
496 
497  if (!empty($conf->use_javascript_ajax)) {
498  print "\n".'<script type="text/javascript">';
499  print '
500  $(document).ready(function () {
501  let onAutoCreatePaiementChange = function () {
502  if($("#auto_create_paiement").is(":checked")) {
503  $("#label_fk_account").find("span").addClass("fieldrequired");
504  $("#label_type_payment").find("span").addClass("fieldrequired");
505  $(".hide_if_no_auto_create_payment").show();
506  } else {
507  $("#label_fk_account").find("span").removeClass("fieldrequired");
508  $("#label_type_payment").find("span").removeClass("fieldrequired");
509  $(".hide_if_no_auto_create_payment").hide();
510  }
511  };
512  $("#radiopayment").click(function() {
513  $("#label").val($(this).data("label"));
514  });
515  $("#radiorefund").click(function() {
516  $("#label").val($(this).data("label"));
517  });
518  $("#auto_create_paiement").click(function () {
519  onAutoCreatePaiementChange();
520  });
521  onAutoCreatePaiementChange();
522  });
523  ';
524  print '</script>'."\n";
525  }
526 
527  print dol_get_fiche_head('');
528 
529  print '<table class="border centpercent">';
530 
531  // Employee
532  print '<tr><td class="titlefieldcreate">';
533  print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).'</td><td>';
534  $noactive = 0; // We keep active and unactive users
535  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);
536  print '</td></tr>';
537 
538  // Label
539  print '<tr><td>';
540  print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
541  print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST("label") ?GETPOST("label") : $langs->trans("Salary")).'">';
542  print '</td></tr>';
543 
544  // Date start period
545  print '<tr><td>';
546  print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).'</td><td>';
547  print $form->selectDate($datesp, "datesp", '', '', '', 'add');
548  print '</td></tr>';
549 
550  // Date end period
551  print '<tr><td>';
552  print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).'</td><td>';
553  print $form->selectDate($dateep, "dateep", '', '', '', 'add');
554  print '</td></tr>';
555 
556  // Amount
557  print '<tr><td>';
558  print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
559  print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST("amount").'">&nbsp;';
560  print '<button class="dpInvisibleButtons datenow" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans('UpdateAmountWithLastSalary').'</a>';
561  print '</td>';
562  print '</tr>';
563 
564  // Project
565  if (isModEnabled('project')) {
566  $formproject = new FormProjets($db);
567 
568  print '<tr><td>'.$langs->trans("Project").'</td><td>';
569  print img_picto('', 'project', 'class="pictofixedwidth"');
570  print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
571  print '</td></tr>';
572  }
573 
574  // Comments
575  print '<tr>';
576  print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
577  print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
578  print '</tr>';
579 
580 
581  print '<tr><td colspan="2"><hr></td></tr>';
582 
583 
584  // Auto create payment
585  print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
586  print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_paiement) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n"; // Date payment
587 
588  // Bank
589  if (isModEnabled("banque")) {
590  print '<tr><td id="label_fk_account">';
591  print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
592  print img_picto('', 'bank_account', 'class="paddingrighonly"');
593  $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant
594  print '</td></tr>';
595  }
596 
597  // Type payment
598  print '<tr><td id="label_type_payment">';
599  print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).'</td><td>';
600  $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '');
601  print '</td></tr>';
602 
603  // Date payment
604  print '<tr class="hide_if_no_auto_create_payment"><td>';
605  print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
606  print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1);
607  print '</td></tr>';
608 
609  // Date value for bank
610  print '<tr class="hide_if_no_auto_create_payment"><td>';
611  print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
612  print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
613  print '</td></tr>';
614 
615  // Number
616  if (isModEnabled("banque")) {
617  // Number
618  print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans('Numero');
619  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
620  print '</label></td>';
621  print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
622  }
623 
624  // Bouton Save payment
625  /*
626  print '<tr class="hide_if_no_auto_create_payment"><td>';
627  print $langs->trans("ClosePaidSalaryAutomatically");
628  print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>';
629  */
630 
631  // Other attributes
632  $parameters = array();
633  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
634  print $hookmanager->resPrint;
635  if (empty($reshook)) {
636  print $object->showOptionals($extrafields, 'create');
637  }
638 
639  print '</table>';
640 
641  print dol_get_fiche_end();
642 
643  print '<div class="center">';
644 
645  print '<div class="hide_if_no_auto_create_payment paddingbottom">';
646  print '<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans("ClosePaidSalaryAutomatically");
647  print '</div>';
648 
649  print '</div>';
650 
651  $addition_button = array(
652  'name' => 'saveandnew',
653  'label_key' => 'SaveAndNew',
654  );
655  print $form->buttonsSaveCancel("Save", "Cancel", $addition_button);
656 
657  print '</form>';
658  print '<script>';
659  print '$( document ).ready(function() {';
660  print '$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
661  console.log("We click on link to autofill salary amount");
662  var fk_user = $("#fk_user").val()
663  var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
664  if (fk_user != -1) {
665  $.get(
666  url,
667  function( data ) {
668  if(data!=null) {
669  console.log("Data returned: "+data);
670  item = JSON.parse(data);
671  if(item[0].key == "Amount") {
672  value = item[0].value;
673  if (value != null) {
674  $("#amount").val(item[0].value);
675  } else {
676  console.error("Error: Ajax url "+url+" has returned a null value.");
677  }
678  } else {
679  console.error("Error: Ajax url "+url+" has returned the wrong key.");
680  }
681  } else {
682  console.error("Error: Ajax url "+url+" has returned an empty page.");
683  }
684  }
685  );
686 
687  } else {
688  alert("'.dol_escape_js($langs->transnoentitiesnoconv("FillFieldFirst")).'");
689  }
690  });
691 
692  })';
693  print '</script>';
694 }
695 
696 
697 // View mode
698 if ($id > 0) {
699  $head = salaries_prepare_head($object);
700  $formconfirm = '';
701 
702  if ($action === 'clone') {
703  $formquestion = array(
704  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
705  );
706 
707  //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
708  $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1);
709  $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1);
710 
711  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 250);
712  }
713 
714  if ($action == 'paid') {
715  $text = $langs->trans('ConfirmPaySalary');
716  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2);
717  }
718 
719  if ($action == 'delete') {
720  $text = $langs->trans('ConfirmDeleteSalary');
721  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2);
722  }
723 
724  if ($action == 'edit') {
725  print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
726  print '<input type="hidden" name="token" value="'.newToken().'">';
727  }
728 
729  // Call Hook formConfirm
730  $parameters = array('formConfirm' => $formconfirm);
731  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
732  if (empty($reshook)) {
733  $formconfirm .= $hookmanager->resPrint;
734  } elseif ($reshook > 0) {
735  $formconfirm = $hookmanager->resPrint;
736  }
737 
738  // Print form confirm
739  print $formconfirm;
740 
741 
742  print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary');
743 
744  $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
745 
746  $morehtmlref = '<div class="refidno">';
747 
748  // Label
749  if ($action != 'editlabel') {
750  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
751  $morehtmlref .= $object->label;
752  } else {
753  $morehtmlref .= $langs->trans('Label').' :&nbsp;';
754  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
755  $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
756  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
757  $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
758  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
759  $morehtmlref .= '</form>';
760  }
761 
762  // Employee
763  if ($action != 'editfk_user') {
764  if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
765  $userstatic = new User($db);
766  $result = $userstatic->fetch($object->fk_user);
767  if ($result > 0) {
768  $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
769  }
770  } else {
771  $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
772 
773  if (!empty($object->fk_user)) {
774  $userstatic = new User($db);
775  $result = $userstatic->fetch($object->fk_user);
776  if ($result > 0) {
777  $morehtmlref .= $userstatic->getNomUrl(-1);
778  } else {
779  dol_print_error($db);
780  exit();
781  }
782  }
783  }
784  } else {
785  $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
786  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
787  $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
788  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
789  $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
790  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
791  $morehtmlref .= '</form>';
792  }
793 
794  $usercancreate = $permissiontoadd;
795 
796  // Project
797  if (isModEnabled('project')) {
798  $langs->load("projects");
799  $morehtmlref .= '<br>';
800  if ($usercancreate) {
801  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
802  if ($action != 'classify') {
803  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
804  }
805  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, '');
806  } else {
807  if (!empty($object->fk_project)) {
808  $proj = new Project($db);
809  $proj->fetch($object->fk_project);
810  $morehtmlref .= $proj->getNomUrl(1);
811  if ($proj->title) {
812  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
813  }
814  }
815  }
816  }
817 
818  $morehtmlref .= '</div>';
819 
820  $totalpaid = $object->getSommePaiement();
821  $object->totalpaid = $totalpaid;
822 
823  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
824 
825  print '<div class="fichecenter">';
826  print '<div class="fichehalfleft">';
827  print '<div class="underbanner clearboth"></div>';
828 
829  print '<table class="border centpercent tableforfield">';
830 
831  if ($action == 'edit') {
832  print '<tr><td class="titlefield">'.$langs->trans("DateStartPeriod")."</td><td>";
833  print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
834  print "</td></tr>";
835  } else {
836  print "<tr>";
837  print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
838  print dol_print_date($object->datesp, 'day');
839  print '</td></tr>';
840  }
841 
842  if ($action == 'edit') {
843  print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
844  print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
845  print "</td></tr>";
846  } else {
847  print "<tr>";
848  print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
849  print dol_print_date($object->dateep, 'day');
850  print '</td></tr>';
851  }
852 
853  /*print "<tr>";
854  print '<td>'.$langs->trans("DatePayment").'</td><td>';
855  print dol_print_date($object->datep, 'day');
856  print '</td></tr>';
857 
858  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
859  print dol_print_date($object->datev, 'day');
860  print '</td></tr>';*/
861 
862  if ($action == 'edit') {
863  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
864  } else {
865  print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
866  }
867 
868  // Default mode of payment
869  print '<tr><td>';
870  print '<table class="nobordernopadding" width="100%"><tr><td>';
871  print $langs->trans('DefaultPaymentMode');
872  print '</td>';
873  if ($action != 'editmode')
874  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>';
875  print '</tr></table>';
876  print '</td><td>';
877 
878  if ($action == 'editmode') {
879  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
880  } else {
881  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
882  }
883  print '</td></tr>';
884 
885  // Default Bank Account
886  if (isModEnabled("banque")) {
887  print '<tr><td class="nowrap">';
888  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
889  print $langs->trans('DefaultBankAccount');
890  print '<td>';
891  if ($action != 'editbankaccount' && $user->rights->salaries->write) {
892  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>';
893  }
894  print '</tr></table>';
895  print '</td><td>';
896  if ($action == 'editbankaccount') {
897  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
898  } else {
899  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
900  }
901  print '</td>';
902  print '</tr>';
903  }
904 
905  // Other attributes
906  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
907 
908  print '</table>';
909 
910  print '</div>';
911 
912  print '<div class="fichehalfright">';
913 
914  $nbcols = 3;
915  if (isModEnabled("banque")) {
916  $nbcols++;
917  }
918 
919  /*
920  * Payments
921  */
922  $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
923  $sql .= " c.code as type_code,c.libelle as paiement_type,";
924  $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';
925  $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
926  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
927  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
928  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
929  $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
930  $sql .= " WHERE p.fk_salary = ".((int) $id);
931  $sql .= " AND p.fk_salary = salaire.rowid";
932  $sql .= " AND salaire.entity IN (".getEntity('tax').")";
933  $sql .= " ORDER BY dp DESC";
934 
935  //print $sql;
936  $resql = $db->query($sql);
937  if ($resql) {
938  $totalpaid = 0;
939 
940  $num = $db->num_rows($resql);
941  $i = 0; $total = 0;
942 
943  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
944  print '<table class="noborder paymenttable">';
945  print '<tr class="liste_titre">';
946  print '<td>'.$langs->trans("RefPayment").'</td>';
947  print '<td>'.$langs->trans("Date").'</td>';
948  print '<td>'.$langs->trans("Type").'</td>';
949  if (isModEnabled("banque")) {
950  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
951  }
952  print '<td class="right">'.$langs->trans("Amount").'</td>';
953  print '</tr>';
954 
955  if ($num > 0) {
956  $bankaccountstatic = new Account($db);
957  while ($i < $num) {
958  $objp = $db->fetch_object($resql);
959 
960  print '<tr class="oddeven">';
961  // Date
962  print '<td>';
963  print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
964  // Date
965  print '<td>'.dol_print_date($db->jdate($objp->dp), 'dayhour', 'tzuserrel')."</td>\n";
966  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
967  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
968  if (isModEnabled("banque")) {
969  $bankaccountstatic->id = $objp->baid;
970  $bankaccountstatic->ref = $objp->baref;
971  $bankaccountstatic->label = $objp->baref;
972  $bankaccountstatic->number = $objp->banumber;
973  $bankaccountstatic->currency_code = $objp->bacurrency_code;
974 
975  if (isModEnabled('accounting')) {
976  $bankaccountstatic->account_number = $objp->account_number;
977 
978  $accountingjournal = new AccountingJournal($db);
979  $accountingjournal->fetch($objp->fk_accountancy_journal);
980  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
981  }
982 
983  print '<td class="right">';
984  if ($bankaccountstatic->id)
985  print $bankaccountstatic->getNomUrl(1, 'transactions');
986  print '</td>';
987  }
988  print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
989  print "</tr>";
990  $totalpaid += $objp->amount;
991  $i++;
992  }
993  } else {
994  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
995  print '<td></td><td></td><td></td><td></td>';
996  print '</tr>';
997  }
998 
999  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowrap amountcard">'.price($totalpaid)."</td></tr>\n";
1000  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowrap amountcard">'.price($object->amount)."</td></tr>\n";
1001 
1002  $resteapayer = $object->amount - $totalpaid;
1003  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
1004 
1005  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
1006  print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
1007 
1008  print "</table>";
1009  print '</div>';
1010 
1011  $db->free($resql);
1012  } else {
1013  dol_print_error($db);
1014  }
1015 
1016  print '</div>';
1017  print '</div>';
1018 
1019  print '<div class="clearboth"></div>';
1020 
1021  print dol_get_fiche_end();
1022 
1023  if ($action == 'edit') {
1024  print $form->buttonsSaveCancel();
1025  print "</form>";
1026  }
1027 
1028  $resteapayer = price2num($resteapayer, 'MT');
1029 
1030 
1031  /*
1032  * Action bar
1033  */
1034 
1035  print '<div class="tabsAction">'."\n";
1036  if ($action != 'edit') {
1037  // Reopen
1038  if ($object->paye && $user->rights->salaries->write) {
1039  print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
1040  }
1041 
1042  // Edit
1043  if ($object->paye == 0 && $user->rights->salaries->write) {
1044  print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
1045  }
1046 
1047  // Emit payment
1048  if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->rights->salaries->write) {
1049  print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
1050  }
1051 
1052  // Classify 'paid'
1053  // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
1054  if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->rights->salaries->write) {
1055  print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
1056  }
1057 
1058  // Clone
1059  if ($user->rights->salaries->write) {
1060  print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
1061  }
1062 
1063  if (!empty($user->rights->salaries->delete) && empty($totalpaid)) {
1064  print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
1065  } else {
1066  print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1067  }
1068  }
1069  print "</div>";
1070 
1071 
1072 
1073  // Select mail models is same action as presend
1074  if (GETPOST('modelselected')) {
1075  $action = 'presend';
1076  }
1077 
1078  if ($action != 'presend') {
1079  print '<div class="fichecenter"><div class="fichehalfleft">';
1080  print '<a name="builddoc"></a>'; // ancre
1081 
1082  $includedocgeneration = 1;
1083 
1084  // Documents
1085  if ($includedocgeneration) {
1086  $objref = dol_sanitizeFileName($object->ref);
1087  $relativepath = $objref.'/'.$objref.'.pdf';
1088  $filedir = $conf->salaries->dir_output.'/'.$objref;
1089  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1090  //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1091  $genallowed = 0; // If you can read, you can build the PDF to read content
1092  $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1093  print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1094  }
1095 
1096  // Show links to link elements
1097  /*
1098  $linktoelem = $form->showLinkToObjectBlock($object, null, array('salaries'));
1099  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1100  */
1101 
1102  print '</div><div class="fichehalfright">';
1103 
1104  $MAXEVENT = 10;
1105 
1106  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1107 
1108  // List of actions on element
1109  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1110  $formactions = new FormActions($db);
1111  //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1112 
1113  print '</div></div>';
1114  }
1115 
1116  //Select mail models is same action as presend
1117  if (GETPOST('modelselected')) {
1118  $action = 'presend';
1119  }
1120 
1121  // Presend form
1122  $modelmail = 'salary';
1123  $defaulttopic = 'InformationMessage';
1124  $diroutput = $conf->salaries->dir_output;
1125  $trackid = 'salary'.$object->id;
1126 
1127  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1128 }
1129 
1130 // End of page
1131 llxFooter();
1132 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage payments of salaries.
Class to manage projects.
Class to manage salary payments.
Class to manage Dolibarr users.
Definition: user.class.php:45
$parameters
Actions.
Definition: card.php:79
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.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:575
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
$formconfirm
if ($action == 'delbookkeepingyear') {
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.