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