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