dolibarr  17.0.4
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"), '', '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  var fk_user = $("#fk_user").val()
662  var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
663  console.log("We click on link to autofill salary amount url="+url);
664  if (fk_user != -1) {
665  $.get(
666  url,
667  function( data ) {
668  console.log("Data returned: "+data);
669  if (data != null) {
670  if (typeof data == "object") {
671  console.log("data is already type object, no need to parse it");
672  item = data;
673  } else {
674  console.log("data is type "+(typeof data));
675  item = JSON.parse(data);
676  }
677  if (item[0].key == "Amount") {
678  value = item[0].value;
679  console.log("amount returned = "+value);
680  if (value != null) {
681  $("#amount").val(item[0].value);
682  } else {
683  console.error("Error: Ajax url "+url+" has returned a null value.");
684  }
685  } else {
686  console.error("Error: Ajax url "+url+" has returned the wrong key.");
687  }
688  } else {
689  console.error("Error: Ajax url "+url+" has returned an empty page.");
690  }
691  }
692  );
693 
694  } else {
695  alert("'.dol_escape_js($langs->transnoentitiesnoconv("FillFieldFirst")).'");
696  }
697  });
698 
699  })';
700  print '</script>';
701 }
702 
703 
704 // View mode
705 if ($id > 0) {
706  $head = salaries_prepare_head($object);
707  $formconfirm = '';
708 
709  if ($action === 'clone') {
710  $formquestion = array(
711  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
712  );
713 
714  //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
715  $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1);
716  $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1);
717 
718  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 250);
719  }
720 
721  if ($action == 'paid') {
722  $text = $langs->trans('ConfirmPaySalary');
723  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2);
724  }
725 
726  if ($action == 'delete') {
727  $text = $langs->trans('ConfirmDeleteSalary');
728  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2);
729  }
730 
731  if ($action == 'edit') {
732  print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
733  print '<input type="hidden" name="token" value="'.newToken().'">';
734  }
735 
736  // Call Hook formConfirm
737  $parameters = array('formConfirm' => $formconfirm);
738  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
739  if (empty($reshook)) {
740  $formconfirm .= $hookmanager->resPrint;
741  } elseif ($reshook > 0) {
742  $formconfirm = $hookmanager->resPrint;
743  }
744 
745  // Print form confirm
746  print $formconfirm;
747 
748 
749  print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary');
750 
751  $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
752 
753  $morehtmlref = '<div class="refidno">';
754 
755  // Label
756  if ($action != 'editlabel') {
757  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
758  $morehtmlref .= $object->label;
759  } else {
760  $morehtmlref .= $langs->trans('Label').' :&nbsp;';
761  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
762  $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
763  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
764  $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
765  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
766  $morehtmlref .= '</form>';
767  }
768 
769  // Employee
770  if ($action != 'editfk_user') {
771  if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
772  $userstatic = new User($db);
773  $result = $userstatic->fetch($object->fk_user);
774  if ($result > 0) {
775  $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
776  }
777  } else {
778  $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
779 
780  if (!empty($object->fk_user)) {
781  $userstatic = new User($db);
782  $result = $userstatic->fetch($object->fk_user);
783  if ($result > 0) {
784  $morehtmlref .= $userstatic->getNomUrl(-1);
785  } else {
786  dol_print_error($db);
787  exit();
788  }
789  }
790  }
791  } else {
792  $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
793  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
794  $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
795  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
796  $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
797  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
798  $morehtmlref .= '</form>';
799  }
800 
801  $usercancreate = $permissiontoadd;
802 
803  // Project
804  if (isModEnabled('project')) {
805  $langs->load("projects");
806  $morehtmlref .= '<br>';
807  if ($usercancreate) {
808  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
809  if ($action != 'classify') {
810  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
811  }
812  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
813  } else {
814  if (!empty($object->fk_project)) {
815  $proj = new Project($db);
816  $proj->fetch($object->fk_project);
817  $morehtmlref .= $proj->getNomUrl(1);
818  if ($proj->title) {
819  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
820  }
821  }
822  }
823  }
824 
825  $morehtmlref .= '</div>';
826 
827  $totalpaid = $object->getSommePaiement();
828  $object->totalpaid = $totalpaid;
829 
830  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
831 
832  print '<div class="fichecenter">';
833  print '<div class="fichehalfleft">';
834  print '<div class="underbanner clearboth"></div>';
835 
836  print '<table class="border centpercent tableforfield">';
837 
838  if ($action == 'edit') {
839  print '<tr><td class="titlefield">'.$langs->trans("DateStartPeriod")."</td><td>";
840  print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
841  print "</td></tr>";
842  } else {
843  print "<tr>";
844  print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
845  print dol_print_date($object->datesp, 'day');
846  print '</td></tr>';
847  }
848 
849  if ($action == 'edit') {
850  print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
851  print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
852  print "</td></tr>";
853  } else {
854  print "<tr>";
855  print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
856  print dol_print_date($object->dateep, 'day');
857  print '</td></tr>';
858  }
859 
860  /*print "<tr>";
861  print '<td>'.$langs->trans("DatePayment").'</td><td>';
862  print dol_print_date($object->datep, 'day');
863  print '</td></tr>';
864 
865  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
866  print dol_print_date($object->datev, 'day');
867  print '</td></tr>';*/
868 
869  if ($action == 'edit') {
870  print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
871  } else {
872  print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
873  }
874 
875  // Default mode of payment
876  print '<tr><td>';
877  print '<table class="nobordernopadding" width="100%"><tr><td>';
878  print $langs->trans('DefaultPaymentMode');
879  print '</td>';
880  if ($action != 'editmode')
881  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>';
882  print '</tr></table>';
883  print '</td><td>';
884 
885  if ($action == 'editmode') {
886  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
887  } else {
888  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
889  }
890  print '</td></tr>';
891 
892  // Default Bank Account
893  if (isModEnabled("banque")) {
894  print '<tr><td class="nowrap">';
895  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
896  print $langs->trans('DefaultBankAccount');
897  print '<td>';
898  if ($action != 'editbankaccount' && $user->rights->salaries->write) {
899  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>';
900  }
901  print '</tr></table>';
902  print '</td><td>';
903  if ($action == 'editbankaccount') {
904  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
905  } else {
906  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
907  }
908  print '</td>';
909  print '</tr>';
910  }
911 
912  // Other attributes
913  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
914 
915  print '</table>';
916 
917  print '</div>';
918 
919  print '<div class="fichehalfright">';
920 
921  $nbcols = 3;
922  if (isModEnabled("banque")) {
923  $nbcols++;
924  }
925 
926  /*
927  * Payments
928  */
929  $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
930  $sql .= " c.code as type_code,c.libelle as paiement_type,";
931  $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';
932  $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
933  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
934  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
935  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
936  $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
937  $sql .= " WHERE p.fk_salary = ".((int) $id);
938  $sql .= " AND p.fk_salary = salaire.rowid";
939  $sql .= " AND salaire.entity IN (".getEntity('tax').")";
940  $sql .= " ORDER BY dp DESC";
941 
942  //print $sql;
943  $resql = $db->query($sql);
944  if ($resql) {
945  $totalpaid = 0;
946 
947  $num = $db->num_rows($resql);
948  $i = 0; $total = 0;
949 
950  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
951  print '<table class="noborder paymenttable">';
952  print '<tr class="liste_titre">';
953  print '<td>'.$langs->trans("RefPayment").'</td>';
954  print '<td>'.$langs->trans("Date").'</td>';
955  print '<td>'.$langs->trans("Type").'</td>';
956  if (isModEnabled("banque")) {
957  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
958  }
959  print '<td class="right">'.$langs->trans("Amount").'</td>';
960  print '</tr>';
961 
962  if ($num > 0) {
963  $bankaccountstatic = new Account($db);
964  while ($i < $num) {
965  $objp = $db->fetch_object($resql);
966 
967  print '<tr class="oddeven"><td>';
968  print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
969  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
970  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
971  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
972  if (isModEnabled("banque")) {
973  $bankaccountstatic->id = $objp->baid;
974  $bankaccountstatic->ref = $objp->baref;
975  $bankaccountstatic->label = $objp->baref;
976  $bankaccountstatic->number = $objp->banumber;
977  $bankaccountstatic->currency_code = $objp->bacurrency_code;
978 
979  if (isModEnabled('accounting')) {
980  $bankaccountstatic->account_number = $objp->account_number;
981 
982  $accountingjournal = new AccountingJournal($db);
983  $accountingjournal->fetch($objp->fk_accountancy_journal);
984  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
985  }
986 
987  print '<td class="right">';
988  if ($bankaccountstatic->id)
989  print $bankaccountstatic->getNomUrl(1, 'transactions');
990  print '</td>';
991  }
992  print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
993  print "</tr>";
994  $totalpaid += $objp->amount;
995  $i++;
996  }
997  } else {
998  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
999  print '<td></td><td></td><td></td><td></td>';
1000  print '</tr>';
1001  }
1002 
1003  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right nowrap amountcard\">".price($totalpaid)."</td></tr>\n";
1004  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right nowrap amountcard\">".price($object->amount)."</td></tr>\n";
1005 
1006  $resteapayer = $object->amount - $totalpaid;
1007  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
1008 
1009  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
1010  print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
1011 
1012  print "</table>";
1013  print '</div>';
1014 
1015  $db->free($resql);
1016  } else {
1017  dol_print_error($db);
1018  }
1019 
1020  print '</div>';
1021  print '</div>';
1022 
1023  print '<div class="clearboth"></div>';
1024 
1025  print dol_get_fiche_end();
1026 
1027  if ($action == 'edit') {
1028  print $form->buttonsSaveCancel();
1029  print "</form>";
1030  }
1031 
1032  $resteapayer = price2num($resteapayer, 'MT');
1033 
1034 
1035  /*
1036  * Action bar
1037  */
1038 
1039  print '<div class="tabsAction">'."\n";
1040  if ($action != 'edit') {
1041  // Reopen
1042  if ($object->paye && $user->rights->salaries->write) {
1043  print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
1044  }
1045 
1046  // Edit
1047  if ($object->paye == 0 && $user->rights->salaries->write) {
1048  print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
1049  }
1050 
1051  // Emit payment
1052  if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->rights->salaries->write) {
1053  print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
1054  }
1055 
1056  // Classify 'paid'
1057  // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
1058  if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->rights->salaries->write) {
1059  print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
1060  }
1061 
1062  // Clone
1063  if ($user->rights->salaries->write) {
1064  print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
1065  }
1066 
1067  if (!empty($user->rights->salaries->delete) && empty($totalpaid)) {
1068  print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
1069  } else {
1070  print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1071  }
1072  }
1073  print "</div>";
1074 
1075 
1076 
1077  // Select mail models is same action as presend
1078  if (GETPOST('modelselected')) {
1079  $action = 'presend';
1080  }
1081 
1082  if ($action != 'presend') {
1083  print '<div class="fichecenter"><div class="fichehalfleft">';
1084  print '<a name="builddoc"></a>'; // ancre
1085 
1086  $includedocgeneration = 1;
1087 
1088  // Documents
1089  if ($includedocgeneration) {
1090  $objref = dol_sanitizeFileName($object->ref);
1091  $relativepath = $objref.'/'.$objref.'.pdf';
1092  $filedir = $conf->salaries->dir_output.'/'.$objref;
1093  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1094  //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1095  $genallowed = 0; // If you can read, you can build the PDF to read content
1096  $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1097  print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1098  }
1099 
1100  // Show links to link elements
1101  /*
1102  $linktoelem = $form->showLinkToObjectBlock($object, null, array('salaries'));
1103  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1104  */
1105 
1106  print '</div><div class="fichehalfright">';
1107 
1108  $MAXEVENT = 10;
1109 
1110  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1111 
1112  // List of actions on element
1113  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1114  $formactions = new FormActions($db);
1115  //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1116 
1117  print '</div></div>';
1118  }
1119 
1120  //Select mail models is same action as presend
1121  if (GETPOST('modelselected')) {
1122  $action = 'presend';
1123  }
1124 
1125  // Presend form
1126  $modelmail = 'salary';
1127  $defaulttopic = 'InformationMessage';
1128  $diroutput = $conf->salaries->dir_output;
1129  $trackid = 'salary'.$object->id;
1130 
1131  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1132 }
1133 
1134 // End of page
1135 llxFooter();
1136 $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:47
$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.