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