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