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