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 $triggermodname = 'SALARY_MODIFY';
471
472 $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
473 if ($result > 0) {
474 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
475 $action = 'view';
476 } else {
477 setEventMessages($object->error, $object->errors, 'errors');
478 $action = 'edit_extras';
479 }
480}
481
482
483/*
484 * View
485 */
486
487$form = new Form($db);
488$formfile = new FormFile($db);
489if (isModEnabled('project')) {
490 $formproject = new FormProjets($db);
491}
492
493$title = $langs->trans('Salary')." - ".$object->ref;
494if ($action == 'create') {
495 $title = $langs->trans("NewSalary");
496}
497$help_url = "";
498llxHeader('', $title, $help_url);
499
500
501if ($id > 0) {
502 $result = $object->fetch($id);
503 if ($result <= 0) {
504 dol_print_error($db);
505 exit;
506 }
507}
508
509// Create
510if ($action == 'create' && $permissiontoadd) {
511 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
512 $pastmonth = (int) dol_print_date(dol_now(), "%m") - 1;
513 $pastmonthyear = $year_current;
514 if ($pastmonth == 0) {
515 $pastmonth = 12;
516 $pastmonthyear--;
517 }
518
519 $datespmonth = GETPOSTINT('datespmonth');
520 $datespday = GETPOSTINT('datespday');
521 $datespyear = GETPOSTINT('datespyear');
522 $dateepmonth = GETPOSTINT('dateepmonth');
523 $dateepday = GETPOSTINT('dateepday');
524 $dateepyear = GETPOSTINT('dateepyear');
525 $datesp = dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
526 $dateep = dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
527
528 if (empty($datesp) || empty($dateep)) { // We define date_start and date_end
529 $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false);
530 $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false);
531 }
532
533 print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
534 print '<input type="hidden" name="token" value="'.newToken().'">';
535 print '<input type="hidden" name="action" value="add">';
536 if ($backtopage) {
537 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
538 }
539 if ($backtopageforcancel) {
540 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
541 }
542
543 print load_fiche_titre($langs->trans("NewSalary"), '', 'salary');
544
545 if (!empty($conf->use_javascript_ajax)) {
546 print "\n".'<script type="text/javascript">';
547 print '
548 $(document).ready(function () {
549 let onAutoCreatePaiementChange = function () {
550 if($("#auto_create_paiement").is(":checked")) {
551 $("#label_fk_account").find("span").addClass("fieldrequired");
552 $("#label_type_payment").find("span").addClass("fieldrequired");
553 $(".hide_if_no_auto_create_payment").show();
554 } else {
555 $("#label_fk_account").find("span").removeClass("fieldrequired");
556 $("#label_type_payment").find("span").removeClass("fieldrequired");
557 $(".hide_if_no_auto_create_payment").hide();
558 }
559 };
560 $("#radiopayment").click(function() {
561 $("#label").val($(this).data("label"));
562 });
563 $("#radiorefund").click(function() {
564 $("#label").val($(this).data("label"));
565 });
566 $("#auto_create_paiement").click(function () {
567 onAutoCreatePaiementChange();
568 });
569 onAutoCreatePaiementChange();
570 });
571 ';
572 print '</script>'."\n";
573 }
574
575 print dol_get_fiche_head();
576
577 print '<table class="border centpercent">';
578
579 // Employee
580 print '<tr><td class="titlefieldcreate">';
581 print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).'</td><td>';
582 $noactive = 0; // We keep active and unactive users
583 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(GETPOSTINT('fk_user'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'employee:=:1', 0, '', 'maxwidth300', $noactive);
584 print '</td></tr>';
585
586 // Label
587 print '<tr><td>';
588 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
589 print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST("label") ? GETPOST("label") : $langs->trans("Salary")).'">';
590 print '</td></tr>';
591
592 // Date start period
593 print '<tr><td>';
594 print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).'</td><td>';
595 print $form->selectDate($datesp, "datesp", 0, 0, 0, 'add');
596 print '</td></tr>';
597
598 // Date end period
599 print '<tr><td>';
600 print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).'</td><td>';
601 print $form->selectDate($dateep, "dateep", 0, 0, 0, 'add');
602 print '</td></tr>';
603
604 // Amount
605 print '<tr><td>';
606 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
607 print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST("amount").'"> &nbsp;';
608 print ' <button class="dpInvisibleButtons datenowlink" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans('UpdateAmountWithLastSalary').'</a>';
609 print '</td>';
610 print '</tr>';
611
612 // Project
613 if (isModEnabled('project')) {
614 $formproject = new FormProjets($db);
615
616 print '<tr><td>'.$langs->trans("Project").'</td><td>';
617 print img_picto('', 'project', 'class="pictofixedwidth"');
618 print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
619 print '</td></tr>';
620 }
621
622 // Comments
623 print '<tr>';
624 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
625 print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
626 print '</tr>';
627
628
629 print '<tr><td colspan="2"><hr></td></tr>';
630
631
632 // Auto create payment
633 print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
634 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
635
636 // Bank
637 if (isModEnabled("bank")) {
638 print '<tr><td id="label_fk_account">';
639 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
640 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
641 $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant
642 print '</td></tr>';
643 }
644
645 // Type payment
646 print '<tr><td id="label_type_payment">';
647 print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).'</td><td>';
648 print img_picto('', 'bank', 'class="pictofixedwidth"');
649 print $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '');
650 print '</td></tr>';
651
652 // Date payment
653 print '<tr class="hide_if_no_auto_create_payment"><td>';
654 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
655 print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1);
656 print '</td></tr>';
657
658 // Date value for bank
659 print '<tr class="hide_if_no_auto_create_payment"><td>';
660 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
661 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
662 print '</td></tr>';
663
664 // Number
665 if (isModEnabled("bank")) {
666 // Number
667 print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans('Numero');
668 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
669 print '</label></td>';
670 print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
671 }
672
673 // Bouton Save payment
674 /*
675 print '<tr class="hide_if_no_auto_create_payment"><td>';
676 print $langs->trans("ClosePaidSalaryAutomatically");
677 print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>';
678 */
679
680 // Other attributes
681 $parameters = array();
682 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
683 print $hookmanager->resPrint;
684 if (empty($reshook)) {
685 print $object->showOptionals($extrafields, 'create');
686 }
687
688 print '</table>';
689
690 print dol_get_fiche_end();
691
692 print '<div class="center">';
693
694 print '<div class="hide_if_no_auto_create_payment paddingbottom">';
695 print '<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans("ClosePaidSalaryAutomatically");
696 print '</div>';
697
698 print '</div>';
699
700 $addition_button = array(
701 'name' => 'saveandnew',
702 'label_key' => 'SaveAndNew',
703 );
704 print $form->buttonsSaveCancel("Save", "Cancel", $addition_button);
705
706 print '</form>';
707 print '<script>';
708 print '$( document ).ready(function() {';
709 print '$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
710 var fk_user = $("#fk_user").val()
711 var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
712 console.log("We click on link to autofill salary amount url="+url);
713
714 if (fk_user != -1) {
715 $.get(
716 url,
717 function( data ) {
718 console.log("Data returned: "+data);
719 if (data != null) {
720 if (typeof data == "object") {
721 console.log("data is already type object, no need to parse it");
722 item = data;
723 } else {
724 console.log("data is type "+(typeof data));
725 item = JSON.parse(data);
726 }
727 if (item[0].key == "Amount") {
728 value = item[0].value;
729 console.log("amount returned = "+value);
730 if (value != null) {
731 $("#amount").val(item[0].value);
732 } else {
733 console.error("Error: Ajax url "+url+" has returned a null value.");
734 }
735 } else {
736 console.error("Error: Ajax url "+url+" has returned the wrong key.");
737 }
738 } else {
739 console.error("Error: Ajax url "+url+" has returned an empty page.");
740 }
741 }
742 );
743
744 } else {
745 alert("'.dol_escape_js($langs->transnoentitiesnoconv("FillFieldFirst")).'");
746 }
747 });
748
749 })';
750 print '</script>';
751}
752
753// View mode
754if ($id > 0) {
755 $head = salaries_prepare_head($object);
756 $formconfirm = '';
757
758 if ($action === 'clone') {
759 $formquestion = array(
760 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
761 );
762
763 //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
764 $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1);
765 $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1);
766 $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100 right');
767
768 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280);
769
770 //Add fill with end of month button
771 $formconfirm .= "<script>
772 $('#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>'));
773 $('#fill_end_of_month').click(function(){
774 var clone_date_startmonth = +$('#clone_date_startmonth').val();
775 var clone_date_startyear = +$('#clone_date_startyear').val();
776 var end_date;
777 if (clone_date_startmonth && clone_date_startyear) {
778 end_date = new Date(clone_date_startyear, clone_date_startmonth , 0);
779 } else {
780 var currentDate = new Date();
781 var currentDay = currentDate.getDate();
782 if (currentDay <= 15) {
783 end_date = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
784 } else {
785 end_date = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
786 }
787 }
788 $('#clone_date_end').val(formatDate(end_date,'".$langs->trans("FormatDateShortJavaInput")."'));
789 $('#clone_date_endday').val(end_date.getDate());
790 $('#clone_date_endmonth').val(end_date.getMonth() + 1);
791 $('#clone_date_endyear').val(end_date.getFullYear());
792 });
793 </script>";
794 }
795
796 if ($action == 'paid') {
797 $text = $langs->trans('ConfirmPaySalary');
798 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2);
799 }
800
801 if ($action == 'delete') {
802 $text = $langs->trans('ConfirmDeleteSalary');
803 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2);
804 }
805
806 if ($action == 'edit') {
807 print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
808 print '<input type="hidden" name="token" value="'.newToken().'">';
809 }
810
811 // Call Hook formConfirm
812 $parameters = array('formConfirm' => $formconfirm);
813 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
814 if (empty($reshook)) {
815 $formconfirm .= $hookmanager->resPrint;
816 } elseif ($reshook > 0) {
817 $formconfirm = $hookmanager->resPrint;
818 }
819
820 // Print form confirm
821 print $formconfirm;
822
823
824 print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary', 0, '', '', 0, '', 1);
825
826 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
827
828 $morehtmlref = '<div class="refidno">';
829
830 // Label
831 if ($action != 'editlabel') {
832 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
833 $morehtmlref .= $object->label;
834 } else {
835 $morehtmlref .= $langs->trans('Label').' :&nbsp;';
836 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
837 $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
838 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
839 $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
840 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
841 $morehtmlref .= '</form>';
842 }
843
844 // Employee
845 if ($action != 'editfk_user') {
846 if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
847 $userstatic = new User($db);
848 $result = $userstatic->fetch($object->fk_user);
849 if ($result > 0) {
850 $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
851 }
852 } else {
853 $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
854
855 if (!empty($object->fk_user)) {
856 $userstatic = new User($db);
857 $result = $userstatic->fetch($object->fk_user);
858 if ($result > 0) {
859 $morehtmlref .= $userstatic->getNomUrl(-1);
860 } else {
861 dol_print_error($db);
862 exit();
863 }
864 }
865 }
866 } else {
867 $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
868 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
869 $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
870 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
871 $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
872 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
873 $morehtmlref .= '</form>';
874 }
875
876 $usercancreate = $permissiontoadd;
877
878 // Project
879 if (isModEnabled('project')) {
880 $langs->load("projects");
881 $morehtmlref .= '<br>';
882 if ($usercancreate) {
883 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
884 if ($action != 'classify') {
885 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
886 }
887 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
888 } else {
889 if (!empty($object->fk_project)) {
890 $proj = new Project($db);
891 $proj->fetch($object->fk_project);
892 $morehtmlref .= $proj->getNomUrl(1);
893 if ($proj->title) {
894 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
895 }
896 }
897 }
898 }
899
900 $morehtmlref .= '</div>';
901
902 $totalpaid = $object->getSommePaiement();
903 $object->alreadypaid = $totalpaid;
904 $object->totalpaid = $totalpaid;
905
906 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
907
908 print '<div class="fichecenter">';
909 print '<div class="fichehalfleft">';
910 print '<div class="underbanner clearboth"></div>';
911
912 print '<table class="border centpercent tableforfield">';
913
914 if ($action == 'edit') {
915 print '<tr><td class="titlefieldmiddle">'.$langs->trans("DateStartPeriod")."</td><td>";
916 print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
917 print "</td></tr>";
918 } else {
919 print "<tr>";
920 print '<td class="titlefieldmiddle">' . $langs->trans("DateStartPeriod") . '</td><td>';
921 print dol_print_date($object->datesp, 'day');
922 print '</td></tr>';
923 }
924
925 if ($action == 'edit') {
926 print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
927 print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
928 print "</td></tr>";
929 } else {
930 print "<tr>";
931 print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
932 print dol_print_date($object->dateep, 'day');
933 print '</td></tr>';
934 }
935
936 /*print "<tr>";
937 print '<td>'.$langs->trans("DatePayment").'</td><td>';
938 print dol_print_date($object->datep, 'day');
939 print '</td></tr>';
940
941 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
942 print dol_print_date($object->datev, 'day');
943 print '</td></tr>';*/
944
945 if ($action == 'edit') {
946 print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
947 } else {
948 print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
949 }
950
951 // Default mode of payment
952 print '<tr><td>';
953 print '<table class="nobordernopadding" width="100%"><tr><td>';
954 print $langs->trans('DefaultPaymentMode');
955 print '</td>';
956 if ($action != 'editmode') {
957 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>';
958 }
959 print '</tr></table>';
960 print '</td><td>';
961
962 if ($action == 'editmode') {
963 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
964 } else {
965 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
966 }
967 print '</td></tr>';
968
969 // Default Bank Account
970 if (isModEnabled("bank")) {
971 print '<tr><td class="nowrap">';
972 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
973 print $langs->trans('DefaultBankAccount');
974 print '<td>';
975 if ($action != 'editbankaccount' && $permissiontoadd) {
976 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>';
977 }
978 print '</tr></table>';
979 print '</td><td>';
980 if ($action == 'editbankaccount') {
981 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
982 } else {
983 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
984 }
985 print '</td>';
986 print '</tr>';
987 }
988
989 // Other attributes
990 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
991
992 print '</table>';
993
994 print '</div>';
995
996 print '<div class="fichehalfright">';
997
998 $nbcols = 3;
999 if (isModEnabled("bank")) {
1000 $nbcols++;
1001 }
1002
1003 /*
1004 * Payments
1005 */
1006 $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
1007 $sql .= " c.code as type_code,c.libelle as paiement_type,";
1008 $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';
1009 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
1010 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1011 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1012 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1013 $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
1014 $sql .= " WHERE p.fk_salary = ".((int) $id);
1015 $sql .= " AND p.fk_salary = salaire.rowid";
1016 $sql .= " AND salaire.entity IN (".getEntity('tax').")";
1017 $sql .= " ORDER BY dp DESC";
1018 //print $sql;
1019 $resql = $db->query($sql);
1020 if ($resql) {
1021 $totalpaid = 0;
1022
1023 $num = $db->num_rows($resql);
1024 $i = 0;
1025 $total = 0;
1026
1027 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
1028 print '<table class="noborder paymenttable">';
1029 print '<tr class="liste_titre">';
1030 print '<td>'.$langs->trans("RefPayment").'</td>';
1031 print '<td>'.$langs->trans("Date").'</td>';
1032 print '<td>'.$langs->trans("Type").'</td>';
1033 if (isModEnabled("bank")) {
1034 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
1035 }
1036 print '<td class="right">'.$langs->trans("Amount").'</td>';
1037 print '</tr>';
1038
1039 $paymentsalarytemp = new PaymentSalary($db);
1040
1041 if ($num > 0) {
1042 $bankaccountstatic = new Account($db);
1043 while ($i < $num) {
1044 $objp = $db->fetch_object($resql);
1045
1046 $paymentsalarytemp->id = $objp->rowid;
1047 $paymentsalarytemp->ref = $objp->rowid;
1048 $paymentsalarytemp->num_payment = $objp->num_payment;
1049 $paymentsalarytemp->datep = $objp->dp;
1050
1051 print '<tr class="oddeven"><td>';
1052 print $paymentsalarytemp->getNomUrl(1);
1053 print '</td>';
1054 print '<td>'.dol_print_date($db->jdate($objp->dp), 'dayhour', 'tzuserrel')."</td>\n";
1055 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
1056 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
1057 if (isModEnabled("bank")) {
1058 $bankaccountstatic->id = $objp->baid;
1059 $bankaccountstatic->ref = $objp->baref;
1060 $bankaccountstatic->label = $objp->baref;
1061 $bankaccountstatic->number = $objp->banumber;
1062 $bankaccountstatic->currency_code = $objp->bacurrency_code;
1063
1064 if (isModEnabled('accounting')) {
1065 $bankaccountstatic->account_number = $objp->account_number;
1066
1067 $accountingjournal = new AccountingJournal($db);
1068 $accountingjournal->fetch($objp->fk_accountancy_journal);
1069 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
1070 }
1071
1072 print '<td class="right">';
1073 if ($bankaccountstatic->id) {
1074 print $bankaccountstatic->getNomUrl(1, 'transactions');
1075 }
1076 print '</td>';
1077 }
1078 print '<td class="right nowrap amountcard">'.price($objp->amount)."</td>\n";
1079 print "</tr>";
1080 $totalpaid += $objp->amount;
1081 $i++;
1082 }
1083 } else {
1084 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1085 print '<td></td><td></td><td></td><td></td>';
1086 print '</tr>';
1087 }
1088
1089 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowrap amountcard">'.price($totalpaid)."</td></tr>\n";
1090 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowrap amountcard">'.price($object->amount)."</td></tr>\n";
1091
1092 $resteapayer = (float) $object->amount - $totalpaid;
1093 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
1094
1095 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
1096 print '<td class="right nowrap'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
1097
1098 print "</table>";
1099 print '</div>';
1100
1101 $db->free($resql);
1102 } else {
1103 dol_print_error($db);
1104 }
1105
1106 print '</div>';
1107 print '</div>';
1108
1109 print '<div class="clearboth"></div>';
1110
1111 print dol_get_fiche_end();
1112
1113 if ($action == 'edit') {
1114 print $form->buttonsSaveCancel();
1115 print "</form>";
1116 }
1117
1118 $resteapayer = price2num($resteapayer, 'MT');
1119
1120
1121 /*
1122 * Action bar
1123 */
1124
1125 print '<div class="tabsAction">'."\n";
1126 if ($action != 'edit') {
1127 // Dynamic send mail button
1128 $parameters = array();
1129 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1130 if (empty($reshook)) {
1131 if (empty($user->socid)) {
1132 $canSendMail = true;
1133
1134 print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=presend&token='.newToken().'&mode=init#formmailbeforetitle', '', $canSendMail);
1135 }
1136 }
1137
1138 // Reopen
1139 if ($object->status == $object::STATUS_PAID && $permissiontoadd) {
1140 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
1141 }
1142
1143 // Edit
1144 if ($object->status == $object::STATUS_UNPAID && $permissiontoadd) {
1145 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
1146 }
1147
1148 // Emit payment
1149 if ($object->status == $object::STATUS_UNPAID && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
1150 print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
1151 }
1152
1153 // Classify 'paid'
1154 // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
1155 if ($object->status == $object::STATUS_UNPAID && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $permissiontoadd) {
1156 print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
1157 }
1158
1159 // Transfer request
1160 if ($object->status == $object::STATUS_UNPAID && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
1161 print dolGetButtonAction('', $langs->trans('MakeTransferRequest'), 'default', DOL_URL_ROOT . '/salaries/virement_request.php?id=' . $object->id, '');
1162 }
1163
1164 // Clone
1165 if ($permissiontoadd) {
1166 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
1167 }
1168
1169 if ($permissiontodelete && empty($totalpaid)) {
1170 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
1171 } else {
1172 print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1173 }
1174 }
1175 print "</div>";
1176
1177
1178
1179 // Select mail models is same action as presend
1180 if (GETPOST('modelselected')) {
1181 $action = 'presend';
1182 }
1183
1184 if ($action != 'presend') {
1185 print '<div class="fichecenter"><div class="fichehalfleft">';
1186 print '<a name="builddoc"></a>'; // ancre
1187
1188 $includedocgeneration = 1;
1189
1190 // Documents
1191 if ($includedocgeneration) {
1192 $objref = dol_sanitizeFileName($object->ref);
1193 $relativepath = $objref.'/'.$objref.'.pdf';
1194 $filedir = $conf->salaries->dir_output.'/'.$objref;
1195 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1196 //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1197 $genallowed = 0; // If you can read, you can build the PDF to read content
1198 $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1199 print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1200 }
1201
1202 // Show links to link elements
1203 /*
1204 $tmparray = $form->showLinkToObjectBlock($object, array(), array('salaries'), 1);
1205 $linktoelem = $tmparray['linktoelem'];
1206 $htmltoenteralink = $tmparray['htmltoenteralink'];
1207 print $htmltoenteralink;
1208
1209 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1210 */
1211
1212 print '</div><div class="fichehalfright">';
1213
1214 $MAXEVENT = 10;
1215
1216 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1217
1218 // List of actions on element
1219 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1220 $formactions = new FormActions($db);
1221 //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1222
1223 print '</div></div>';
1224 }
1225
1226 // Select mail models is same action as presend
1227 if (GETPOST('modelselected')) {
1228 $action = 'presend';
1229 }
1230
1231 // Presend form
1232 $modelmail = 'salary';
1233 $defaulttopic = 'InformationMessage';
1234 $diroutput = $conf->salaries->dir_output;
1235 $trackid = 'salary'.$object->id;
1236
1237 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1238
1239 // Hook to add more things on page
1240 $parameters = array();
1241 $reshook = $hookmanager->executeHooks('salaryCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1242}
1243
1244// End of page
1245llxFooter();
1246$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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
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.