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