dolibarr 22.0.5
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-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-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';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
42require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44if (isModEnabled('project')) {
45 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
47}
48
57// Load translation files required by the page
58$langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips"));
59if (isModEnabled('project')) {
60 $langs->load("projects");
61}
62
63$id = GETPOSTINT('id');
64$ref = GETPOST('ref', 'alpha');
65$action = GETPOST('action', 'aZ09');
66$cancel = GETPOST('cancel', 'alpha');
67$backtopage = GETPOST('backtopage', 'alpha');
68$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
69$confirm = GETPOST('confirm');
70
71$label = GETPOST('label', 'alphanohtml');
72$projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project');
73$accountid = GETPOSTINT('accountid') > 0 ? GETPOSTINT('accountid') : 0;
74if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
75 $auto_create_paiement = GETPOSTINT("auto_create_paiement");
76} else {
77 $auto_create_paiement = !getDolGlobalString('CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT');
78}
79
80$datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
81$datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
82$datesp = dol_mktime(12, 0, 0, GETPOSTINT("datespmonth"), GETPOSTINT("datespday"), GETPOSTINT("datespyear"));
83$dateep = dol_mktime(12, 0, 0, GETPOSTINT("dateepmonth"), GETPOSTINT("dateepday"), GETPOSTINT("dateepyear"));
84$fk_user = GETPOSTINT('userid');
85
86$object = new Salary($db);
87$extrafields = new ExtraFields($db);
88
89$childids = $user->getAllChildIds(1);
90
91// fetch optionals attributes and labels
92$extrafields->fetch_name_optionals_label($object->table_element);
93
94// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
95$hookmanager->initHooks(array('salarycard', 'globalcard'));
96
97if ($id > 0) {
98 $object->fetch($id);
99
100 // Check current user can read this salary
101 $canread = 0;
102 if ($user->hasRight('salaries', 'readall')) {
103 $canread = 1;
104 }
105 if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
106 $canread = 1;
107 }
108 if (!$canread) {
110 }
111}
112
113// Security check
114$socid = GETPOSTINT('socid');
115if ($user->socid) {
116 $socid = $user->socid;
117}
118
119restrictedArea($user, 'salaries', $object->id, 'salary', '');
120
121$permissiontoread = $user->hasRight('salaries', 'read');
122$permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
123$permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
124$permissiontoeditextra = $permissiontoadd;
125if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
126 // For action 'update_extras', is there a specific permission set for the attribute to update
127 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
128}
129
130$upload_dir = $conf->salaries->multidir_output[$conf->entity];
131
132$error = 0;
133
134/*
135 * Actions
136 */
137
138$parameters = array();
139// Note that $action and $object may be modified by some hooks
140$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
141if ($reshook < 0) {
142 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
143}
144
145if (empty($reshook)) {
146 $error = 0;
147
148 $backurlforlist = DOL_URL_ROOT.'/salaries/list.php';
149
150 if (empty($backtopage) || ($cancel && empty($id))) {
151 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
152 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
153 $backtopage = $backurlforlist;
154 } else {
155 $backtopage = DOL_URL_ROOT.'/salaries/card.php?id='.($id > 0 ? $id : '__ID__');
156 }
157 }
158 }
159
160 if ($cancel) {
161 //var_dump($cancel);
162 //var_dump($backtopage);exit;
163 if (!empty($backtopageforcancel)) {
164 header("Location: ".$backtopageforcancel);
165 exit;
166 } elseif (!empty($backtopage)) {
167 header("Location: ".$backtopage);
168 exit;
169 }
170 $action = '';
171 }
172
173 // Actions to send emails
174 $triggersendname = 'COMPANY_SENTBYMAIL';
175 $paramname = 'id';
176 $mode = 'emailfromthirdparty';
177 $trackid = 'sal'.$object->id;
178 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
179
180 //var_dump($upload_dir);var_dump($permissiontoadd);var_dump($action);exit;
181 // Actions to build doc
182 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
183}
184
185// Link to a project
186if ($action == 'classin' && $permissiontoadd) {
187 $object->fetch($id);
188 $object->setProject($projectid);
189}
190
191// set label
192if ($action == 'setlabel' && $permissiontoadd) {
193 $object->fetch($id);
194 $object->label = $label;
195 $object->update($user);
196}
197
198// Classify paid
199if ($action == 'confirm_paid' && $permissiontoadd && $confirm == 'yes') {
200 $object->fetch($id);
201 $result = $object->setPaid($user);
202}
203
204if ($action == 'setfk_user' && $permissiontoadd) {
205 $result = $object->fetch($id);
206 if ($result > 0) {
207 $object->fk_user = $fk_user;
208 $object->update($user);
209 } else {
210 dol_print_error($db);
211 exit;
212 }
213}
214
215if ($action == 'reopen' && $permissiontoadd) {
216 $result = $object->fetch($id);
217 if ($object->paye) {
218 $result = $object->set_unpaid($user);
219 if ($result > 0) {
220 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
221 exit();
222 } else {
223 setEventMessages($object->error, $object->errors, 'errors');
224 }
225 }
226}
227
228// payment mode
229if ($action == 'setmode' && $permissiontoadd) {
230 $object->fetch($id);
231 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
232 if ($result < 0) {
233 setEventMessages($object->error, $object->errors, 'errors');
234 }
235}
236
237// bank account
238if ($action == 'setbankaccount' && $permissiontoadd) {
239 $object->fetch($id);
240 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
241 if ($result < 0) {
242 setEventMessages($object->error, $object->errors, 'errors');
243 }
244}
245
246if ($action == 'add' && empty($cancel) && $permissiontoadd) {
247 $error = 0;
248
249 if (empty($datev)) {
250 $datev = $datep;
251 }
252
253 $type_payment = GETPOSTINT("paymenttype");
254 $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2);
255
256 $object->accountid = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
257 $object->fk_user = GETPOSTINT("fk_user") > 0 ? GETPOSTINT("fk_user") : 0;
258 $object->datev = $datev;
259 $object->datep = $datep;
260 $object->amount = $amount;
261 $object->label = GETPOST("label", 'alphanohtml');
262 $object->datesp = $datesp;
263 $object->dateep = $dateep;
264 $object->note = GETPOST("note", 'restricthtml');
265 $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
266 $object->fk_user_author = $user->id;
267 $object->fk_project = $projectid;
268
269 // Set user current salary as ref salary for the payment
270 $fuser = new User($db);
271 $fuser->fetch(GETPOSTINT("fk_user"));
272 $object->salary = $fuser->salary;
273
274 // Fill array 'array_options' with data from add form
275 $ret = $extrafields->setOptionalsFromPost(null, $object);
276 if ($ret < 0) {
277 $error++;
278 }
279
280 if (!empty($auto_create_paiement) && empty($datep)) {
281 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors');
282 $error++;
283 }
284 if (empty($datesp) || empty($dateep)) {
285 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
286 $error++;
287 }
288 if (empty($object->fk_user) || $object->fk_user < 0) {
289 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Employee")), null, 'errors');
290 $error++;
291 }
292 if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) {
293 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
294 $error++;
295 }
296 if (empty($object->amount)) {
297 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
298 $error++;
299 }
300 if (isModEnabled("bank") && !empty($auto_create_paiement) && !$object->accountid > 0) {
301 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
302 $error++;
303 }
304
305 if (!$error) {
306 $db->begin();
307
308 $ret = $object->create($user);
309 if ($ret < 0) {
310 setEventMessages($object->error, $object->errors, 'errors');
311 $error++;
312 }
313 if (!empty($auto_create_paiement) && !$error) {
314 // Create a line of payments
315 $paiement = new PaymentSalary($db);
316 $paiement->fk_salary = $object->id;
317 $paiement->chid = $object->id; // deprecated
318 $paiement->datep = $datep;
319 $paiement->datev = $datev;
320 $paiement->amounts = array($object->id => $amount); // Tableau de montant
321 $paiement->fk_typepayment = $type_payment;
322 $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
323 $paiement->note_private = GETPOST("note", 'restricthtml');
324
325 if (!$error) {
326 $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary'));
327 if ($paymentid < 0) {
328 $error++;
329 setEventMessages($paiement->error, null, 'errors');
330 $action = 'create';
331 }
332 }
333
334 if (!$error) {
335 $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOSTINT('accountid'), '', '');
336 if (!($result > 0)) {
337 $error++;
338 setEventMessages($paiement->error, null, 'errors');
339 }
340 }
341 }
342
343 if (empty($error)) {
344 $db->commit();
345
346 if (GETPOST('saveandnew', 'alpha')) {
347 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
348 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"));
349 exit;
350 } else {
351 header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
352 exit;
353 }
354 } else {
355 $db->rollback();
356 }
357 }
358
359 $action = 'create';
360}
361
362if ($action == 'confirm_delete' && $permissiontodelete) {
363 $result = $object->fetch($id);
364 $totalpaid = $object->getSommePaiement();
365
366 if (empty($totalpaid)) {
367 $db->begin();
368
369 $ret = $object->delete($user);
370 if ($ret > 0) {
371 $db->commit();
372 header("Location: ".DOL_URL_ROOT.'/salaries/list.php');
373 exit;
374 } else {
375 $db->rollback();
376 setEventMessages($object->error, $object->errors, 'errors');
377 }
378 } else {
379 setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
380 }
381}
382
383
384if ($action == 'update' && !GETPOST("cancel") && $permissiontoadd) {
385 $amount = price2num(GETPOST('amount'), 'MT', 2);
386
387 if (empty($amount)) {
388 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
389 $action = 'edit';
390 } elseif (!is_numeric($amount)) {
391 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
392 $action = 'create';
393 } else {
394 $result = $object->fetch($id);
395
396 $object->amount = price2num($amount);
397 $object->datesp = price2num($datesp);
398 $object->dateep = price2num($dateep);
399
400 $result = $object->update($user);
401 if ($result <= 0) {
402 setEventMessages($object->error, $object->errors, 'errors');
403 }
404 }
405}
406
407if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
408 $action = '';
409}
410
411if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
412 $db->begin();
413
414 $originalId = $id;
415
416 $object->fetch($id);
417
418 if ($object->id > 0) {
419 $object->paye = 0;
420 $object->id = 0;
421 $object->ref = '';
422
423 if (GETPOST('amount', 'alphanohtml')) {
424 $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
425 }
426
427 if (GETPOST('clone_label', 'alphanohtml')) {
428 $object->label = GETPOST('clone_label', 'alphanohtml');
429 } else {
430 $object->label = $langs->trans("CopyOf").' '.$object->label;
431 }
432
433 $newdatestart = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_startmonth'), GETPOSTINT('clone_date_startday'), GETPOSTINT('clone_date_startyear'));
434 $newdateend = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_endmonth'), GETPOSTINT('clone_date_endday'), GETPOSTINT('clone_date_endyear'));
435
436 if ($newdatestart) {
437 $object->datesp = $newdatestart;
438 }
439 if ($newdateend) {
440 $object->dateep = $newdateend;
441 }
442
443 $id = $object->create($user);
444 if ($id > 0) {
445 $db->commit();
446 $db->close();
447
448 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
449 exit;
450 } else {
451 $id = $originalId;
452 $db->rollback();
453
454 setEventMessages($object->error, $object->errors, 'errors');
455 }
456 } else {
457 $db->rollback();
458 dol_print_error($db, $object->error);
459 }
460}
461
462
463// Action to update one extrafield
464if ($action == 'update_extras' && $permissiontoeditextra) {
465 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
466
467 $attribute = GETPOST('attribute', 'aZ09');
468
469 // Fill array 'array_options' with data from update form
470 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute);
471 if ($ret < 0) {
472 setEventMessages($extrafields->error, $object->errors, 'errors');
473 $error++;
474 }
475
476 if (!$error) {
477 $result = $object->updateExtraField($attribute, 'SALARY_MODIFY');
478 if ($result < 0) {
479 setEventMessages($object->error, $object->errors, 'errors');
480 $error++;
481 }
482 }
483
484 if ($error) {
485 $action = 'edit_extras';
486 }
487}
488
489
490/*
491 * View
492 */
493
494$form = new Form($db);
495$formfile = new FormFile($db);
496if (isModEnabled('project')) {
497 $formproject = new FormProjets($db);
498}
499
500$title = $langs->trans('Salary')." - ".$object->ref;
501if ($action == 'create') {
502 $title = $langs->trans("NewSalary");
503}
504$help_url = "";
505llxHeader('', $title, $help_url);
506
507
508if ($id > 0) {
509 $result = $object->fetch($id);
510 if ($result <= 0) {
511 dol_print_error($db);
512 exit;
513 }
514}
515
516// Create
517if ($action == 'create' && $permissiontoadd) {
518 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
519 $pastmonth = (int) dol_print_date(dol_now(), "%m") - 1;
520 $pastmonthyear = $year_current;
521 if ($pastmonth == 0) {
522 $pastmonth = 12;
523 $pastmonthyear--;
524 }
525
526 $datespmonth = GETPOSTINT('datespmonth');
527 $datespday = GETPOSTINT('datespday');
528 $datespyear = GETPOSTINT('datespyear');
529 $dateepmonth = GETPOSTINT('dateepmonth');
530 $dateepday = GETPOSTINT('dateepday');
531 $dateepyear = GETPOSTINT('dateepyear');
532 $datesp = dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
533 $dateep = dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
534
535 if (empty($datesp) || empty($dateep)) { // We define date_start and date_end
536 $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false);
537 $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false);
538 }
539
540 print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
541 print '<input type="hidden" name="token" value="'.newToken().'">';
542 print '<input type="hidden" name="action" value="add">';
543 if ($backtopage) {
544 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
545 }
546 if ($backtopageforcancel) {
547 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
548 }
549
550 print load_fiche_titre($langs->trans("NewSalary"), '', 'salary');
551
552 if (!empty($conf->use_javascript_ajax)) {
553 print "\n".'<script type="text/javascript">';
554 print '
555 $(document).ready(function () {
556 let onAutoCreatePaiementChange = function () {
557 if($("#auto_create_paiement").is(":checked")) {
558 $("#label_fk_account").find("span").addClass("fieldrequired");
559 $("#label_type_payment").find("span").addClass("fieldrequired");
560 $(".hide_if_no_auto_create_payment").show();
561 } else {
562 $("#label_fk_account").find("span").removeClass("fieldrequired");
563 $("#label_type_payment").find("span").removeClass("fieldrequired");
564 $(".hide_if_no_auto_create_payment").hide();
565 }
566 };
567 $("#radiopayment").click(function() {
568 $("#label").val($(this).data("label"));
569 });
570 $("#radiorefund").click(function() {
571 $("#label").val($(this).data("label"));
572 });
573 $("#auto_create_paiement").click(function () {
574 onAutoCreatePaiementChange();
575 });
576 onAutoCreatePaiementChange();
577 });
578 ';
579 print '</script>'."\n";
580 }
581
582 print dol_get_fiche_head();
583
584 print '<table class="border centpercent">';
585
586 // Employee
587 print '<tr><td class="titlefieldcreate">';
588 print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).'</td><td>';
589 $noactive = 0; // We keep active and unactive users
590 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);
591 print '</td></tr>';
592
593 // Label
594 print '<tr><td>';
595 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
596 print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST("label") ? GETPOST("label") : $langs->trans("Salary")).'">';
597 print '</td></tr>';
598
599 // Date start period
600 print '<tr><td>';
601 print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).'</td><td>';
602 print $form->selectDate($datesp, "datesp", 0, 0, 0, 'add');
603 print '</td></tr>';
604
605 // Date end period
606 print '<tr><td>';
607 print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).'</td><td>';
608 print $form->selectDate($dateep, "dateep", 0, 0, 0, 'add');
609 print '</td></tr>';
610
611 // Amount
612 print '<tr><td>';
613 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
614 print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST("amount").'"> &nbsp;';
615 print ' <button class="dpInvisibleButtons datenowlink" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans('UpdateAmountWithLastSalary').'</a>';
616 print '</td>';
617 print '</tr>';
618
619 // Project
620 if (isModEnabled('project')) {
621 $formproject = new FormProjets($db);
622
623 print '<tr><td>'.$langs->trans("Project").'</td><td>';
624 print img_picto('', 'project', 'class="pictofixedwidth"');
625 print $formproject->select_projects(-1, (string) $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
626 print '</td></tr>';
627 }
628
629 // Comments
630 print '<tr>';
631 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
632 print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
633 print '</tr>';
634
635
636 print '<tr><td colspan="2"><hr></td></tr>';
637
638
639 // Auto create payment
640 print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
641 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
642
643 // Bank
644 if (isModEnabled("bank")) {
645 print '<tr><td id="label_fk_account">';
646 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
647 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
648 $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant
649 print '</td></tr>';
650 }
651
652 // Type payment
653 print '<tr><td id="label_type_payment">';
654 print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).'</td><td>';
655 print img_picto('', 'bank', 'class="pictofixedwidth"');
656 print $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '');
657 print '</td></tr>';
658
659 // Date payment
660 print '<tr class="hide_if_no_auto_create_payment"><td>';
661 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
662 print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1);
663 print '</td></tr>';
664
665 // Date value for bank
666 print '<tr class="hide_if_no_auto_create_payment"><td>';
667 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
668 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
669 print '</td></tr>';
670
671 // Number
672 if (isModEnabled("bank")) {
673 // Number
674 print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans('Numero');
675 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
676 print '</label></td>';
677 print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
678 }
679
680 // Bouton Save payment
681 /*
682 print '<tr class="hide_if_no_auto_create_payment"><td>';
683 print $langs->trans("ClosePaidSalaryAutomatically");
684 print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>';
685 */
686
687 // Other attributes
688 $parameters = array();
689 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
690 print $hookmanager->resPrint;
691 if (empty($reshook)) {
692 print $object->showOptionals($extrafields, 'create');
693 }
694
695 print '</table>';
696
697 print dol_get_fiche_end();
698
699 print '<div class="center">';
700
701 print '<div class="hide_if_no_auto_create_payment paddingbottom">';
702 print '<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans("ClosePaidSalaryAutomatically");
703 print '</div>';
704
705 print '</div>';
706
707 $addition_button = array(
708 'name' => 'saveandnew',
709 'label_key' => 'SaveAndNew',
710 );
711 print $form->buttonsSaveCancel("Save", "Cancel", $addition_button);
712
713 print '</form>';
714 print '<script>';
715 print '$( document ).ready(function() {';
716 print '$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
717 var fk_user = $("#fk_user").val()
718 var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
719 console.log("We click on link to autofill salary amount url="+url);
720
721 if (fk_user != -1) {
722 $.get(
723 url,
724 function( data ) {
725 console.log("Data returned: "+data);
726 if (data != null) {
727 if (typeof data == "object") {
728 console.log("data is already type object, no need to parse it");
729 item = data;
730 } else {
731 console.log("data is type "+(typeof data));
732 item = JSON.parse(data);
733 }
734 if (item[0].key == "Amount") {
735 value = item[0].value;
736 console.log("amount returned = "+value);
737 if (value != null) {
738 $("#amount").val(item[0].value);
739 } else {
740 console.error("Error: Ajax url "+url+" has returned a null value.");
741 }
742 } else {
743 console.error("Error: Ajax url "+url+" has returned the wrong key.");
744 }
745 } else {
746 console.error("Error: Ajax url "+url+" has returned an empty page.");
747 }
748 }
749 );
750
751 } else {
752 alert("'.dol_escape_js($langs->transnoentitiesnoconv("FillFieldFirst")).'");
753 }
754 });
755
756 })';
757 print '</script>';
758}
759
760// View mode
761if ($id > 0) {
762 $head = salaries_prepare_head($object);
763 $formconfirm = '';
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($_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($_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($_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=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;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="'.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="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
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" 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>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
910 }
911 } else {
912 $morehtmlref .= '<br>' . $form->editfieldkey("Employee", '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>'.$langs->trans('Employee').' :&nbsp;';
927 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
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" 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="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
945 }
946 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -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 $object->alreadypaid = $totalpaid;
963 $object->totalpaid = $totalpaid;
964
965 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
966
967 print '<div class="fichecenter">';
968 print '<div class="fichehalfleft">';
969 print '<div class="underbanner clearboth"></div>';
970
971 print '<table class="border centpercent tableforfield">';
972
973 if ($action == 'edit') {
974 print '<tr><td class="titlefieldmiddle">'.$langs->trans("DateStartPeriod")."</td><td>";
975 print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
976 print "</td></tr>";
977 } else {
978 print "<tr>";
979 print '<td class="titlefieldmiddle">' . $langs->trans("DateStartPeriod") . '</td><td>';
980 print dol_print_date($object->datesp, 'day');
981 print '</td></tr>';
982 }
983
984 if ($action == 'edit') {
985 print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
986 print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
987 print "</td></tr>";
988 } else {
989 print "<tr>";
990 print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
991 print dol_print_date($object->dateep, 'day');
992 print '</td></tr>';
993 }
994
995 /*print "<tr>";
996 print '<td>'.$langs->trans("DatePayment").'</td><td>';
997 print dol_print_date($object->datep, 'day');
998 print '</td></tr>';
999
1000 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
1001 print dol_print_date($object->datev, 'day');
1002 print '</td></tr>';*/
1003
1004 if ($action == 'edit') {
1005 print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
1006 } else {
1007 print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
1008 }
1009
1010 // Default mode of payment
1011 print '<tr><td>';
1012 print '<table class="nobordernopadding" width="100%"><tr><td>';
1013 print $langs->trans('DefaultPaymentMode');
1014 print '</td>';
1015 if ($action != 'editmode') {
1016 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>';
1017 }
1018 print '</tr></table>';
1019 print '</td><td>';
1020
1021 if ($action == 'editmode') {
1022 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->type_payment, 'mode_reglement_id');
1023 } else {
1024 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->type_payment, 'none');
1025 }
1026 print '</td></tr>';
1027
1028 // Default Bank Account
1029 if (isModEnabled("bank")) {
1030 print '<tr><td class="nowrap">';
1031 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1032 print $langs->trans('DefaultBankAccount');
1033 print '<td>';
1034 if ($action != 'editbankaccount' && $permissiontoadd) {
1035 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>';
1036 }
1037 print '</tr></table>';
1038 print '</td><td>';
1039 if ($action == 'editbankaccount') {
1040 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
1041 } else {
1042 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
1043 }
1044 print '</td>';
1045 print '</tr>';
1046 }
1047
1048 // Other attributes
1049 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1050
1051 print '</table>';
1052
1053 print '</div>';
1054
1055 print '<div class="fichehalfright">';
1056
1057 $nbcols = 3;
1058 if (isModEnabled("bank")) {
1059 $nbcols++;
1060 }
1061
1062 /*
1063 * Payments
1064 */
1065 $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
1066 $sql .= " c.code as type_code,c.libelle as paiement_type,";
1067 $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';
1068 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
1069 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1070 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1071 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1072 $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
1073 $sql .= " WHERE p.fk_salary = ".((int) $id);
1074 $sql .= " AND p.fk_salary = salaire.rowid";
1075 $sql .= " AND salaire.entity IN (".getEntity('tax').")";
1076 $sql .= " ORDER BY dp DESC";
1077 //print $sql;
1078 $resql = $db->query($sql);
1079 if ($resql) {
1080 $totalpaid = 0;
1081
1082 $num = $db->num_rows($resql);
1083 $i = 0;
1084 $total = 0;
1085
1086 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
1087 print '<table class="noborder paymenttable">';
1088 print '<tr class="liste_titre">';
1089 print '<td>'.$langs->trans("RefPayment").'</td>';
1090 print '<td>'.$langs->trans("Date").'</td>';
1091 print '<td>'.$langs->trans("Type").'</td>';
1092 if (isModEnabled("bank")) {
1093 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
1094 }
1095 print '<td class="right">'.$langs->trans("Amount").'</td>';
1096 print '</tr>';
1097
1098 $paymentsalarytemp = new PaymentSalary($db);
1099
1100 if ($num > 0) {
1101 $bankaccountstatic = new Account($db);
1102 while ($i < $num) {
1103 $objp = $db->fetch_object($resql);
1104
1105 $paymentsalarytemp->id = $objp->rowid;
1106 $paymentsalarytemp->ref = $objp->rowid;
1107 $paymentsalarytemp->num_payment = $objp->num_payment;
1108 $paymentsalarytemp->datep = $objp->dp;
1109
1110 print '<tr class="oddeven"><td>';
1111 print $paymentsalarytemp->getNomUrl(1);
1112 print '</td>';
1113 print '<td>'.dol_print_date($db->jdate($objp->dp), 'dayhour', 'tzuserrel')."</td>\n";
1114 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
1115 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
1116 if (isModEnabled("bank")) {
1117 $bankaccountstatic->id = $objp->baid;
1118 $bankaccountstatic->ref = $objp->baref;
1119 $bankaccountstatic->label = $objp->baref;
1120 $bankaccountstatic->number = $objp->banumber;
1121 $bankaccountstatic->currency_code = $objp->bacurrency_code;
1122
1123 if (isModEnabled('accounting')) {
1124 $bankaccountstatic->account_number = $objp->account_number;
1125
1126 $accountingjournal = new AccountingJournal($db);
1127 $accountingjournal->fetch($objp->fk_accountancy_journal);
1128 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
1129 }
1130
1131 print '<td class="right">';
1132 if ($bankaccountstatic->id) {
1133 print $bankaccountstatic->getNomUrl(1, 'transactions');
1134 }
1135 print '</td>';
1136 }
1137 print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
1138 print "</tr>";
1139 $totalpaid += $objp->amount;
1140 $i++;
1141 }
1142 } else {
1143 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1144 print '<td></td><td></td><td></td><td></td>';
1145 print '</tr>';
1146 }
1147
1148 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowrap amountcard">'.price($totalpaid)."</td></tr>\n";
1149 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowrap amountcard">'.price($object->amount)."</td></tr>\n";
1150
1151 $resteapayer = (float) $object->amount - $totalpaid;
1152 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
1153
1154 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
1155 print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
1156
1157 print "</table>";
1158 print '</div>';
1159
1160 $db->free($resql);
1161 } else {
1162 dol_print_error($db);
1163 }
1164
1165 print '</div>';
1166 print '</div>';
1167
1168 print '<div class="clearboth"></div>';
1169
1170 print dol_get_fiche_end();
1171
1172 if ($action == 'edit') {
1173 print $form->buttonsSaveCancel();
1174 print "</form>";
1175 }
1176
1177 $resteapayer = price2num($resteapayer, 'MT');
1178
1179
1180 /*
1181 * Action bar
1182 */
1183
1184 print '<div class="tabsAction">'."\n";
1185 if ($action != 'edit') {
1186 // Dynamic send mail button
1187 $parameters = array();
1188 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1189 if (empty($reshook)) {
1190 if (empty($user->socid)) {
1191 $canSendMail = true;
1192
1193 print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=presend&token='.newToken().'&mode=init#formmailbeforetitle', '', $canSendMail);
1194 }
1195 }
1196
1197 // Reopen
1198 if ($object->status == $object::STATUS_PAID && $permissiontoadd) {
1199 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
1200 }
1201
1202 // Edit
1203 if ($object->status == $object::STATUS_UNPAID && $permissiontoadd) {
1204 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
1205 }
1206
1207 // Transfer request
1208 if ($object->status == $object::STATUS_UNPAID && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
1209 print dolGetButtonAction('', $langs->trans('MakeTransferRequest'), 'default', DOL_URL_ROOT . '/salaries/virement_request.php?id=' . $object->id, '');
1210 }
1211
1212 // Emit payment
1213 if ($object->status == $object::STATUS_UNPAID && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
1214 print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
1215 }
1216
1217 // Classify 'paid'
1218 // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
1219 if ($object->status == $object::STATUS_UNPAID && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $permissiontoadd) {
1220 print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
1221 }
1222
1223 // Clone
1224 if ($permissiontoadd) {
1225 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
1226 }
1227
1228 if ($permissiontodelete && empty($totalpaid)) {
1229 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
1230 } else {
1231 print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1232 }
1233 }
1234 print "</div>";
1235
1236
1237
1238 // Select mail models is same action as presend
1239 if (GETPOST('modelselected')) {
1240 $action = 'presend';
1241 }
1242
1243 if ($action != 'presend') {
1244 print '<div class="fichecenter"><div class="fichehalfleft">';
1245 print '<a name="builddoc"></a>'; // ancre
1246
1247 $includedocgeneration = 1;
1248
1249 // Documents
1250 if ($includedocgeneration) {
1251 $objref = dol_sanitizeFileName($object->ref);
1252 $relativepath = $objref.'/'.$objref.'.pdf';
1253 $filedir = $conf->salaries->dir_output.'/'.$objref;
1254 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1255 //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1256 $genallowed = 0; // If you can read, you can build the PDF to read content
1257 $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1258 print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1259 }
1260
1261 // Show links to link elements
1262 /*
1263 $tmparray = $form->showLinkToObjectBlock($object, array(), array('salaries'), 1);
1264 $linktoelem = $tmparray['linktoelem'];
1265 $htmltoenteralink = $tmparray['htmltoenteralink'];
1266 print $htmltoenteralink;
1267
1268 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1269 */
1270
1271 print '</div><div class="fichehalfright">';
1272
1273 $MAXEVENT = 10;
1274
1275 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1276
1277 // List of actions on element
1278 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1279 $formactions = new FormActions($db);
1280 //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1281
1282 print '</div></div>';
1283 }
1284
1285 // Select mail models is same action as presend
1286 if (GETPOST('modelselected')) {
1287 $action = 'presend';
1288 }
1289
1290 // Presend form
1291 $modelmail = 'salary';
1292 $defaulttopic = 'InformationMessage';
1293 $diroutput = $conf->salaries->dir_output;
1294 $trackid = 'salary'.$object->id;
1295
1296 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1297
1298 // Hook to add more things on page
1299 $parameters = array();
1300 $reshook = $hookmanager->executeHooks('salaryCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1301}
1302
1303// End of page
1304llxFooter();
1305$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
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.
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.
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.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.