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