|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-/* Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
|
|
+/* Copyright (C) 2011-2023 Alexandre Spangaro <aspangaro@easya.solutions>
|
|
|
* Copyright (C) 2014-2020 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
|
|
* Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
|
|
@@ -108,9 +108,9 @@ if ($user->socid) {
|
|
|
|
|
|
restrictedArea($user, 'salaries', $object->id, 'salary', '');
|
|
|
|
|
|
-$permissiontoread = $user->rights->salaries->read;
|
|
|
-$permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
|
|
|
-$permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
|
|
|
+$permissiontoread = $user->hasRight('salaries', 'read');
|
|
|
+$permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
|
|
|
+$permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
|
|
|
|
|
|
$upload_dir = $conf->salaries->multidir_output[$conf->entity];
|
|
|
|
|
@@ -167,25 +167,25 @@ if (empty($reshook)) {
|
|
|
}
|
|
|
|
|
|
// Link to a project
|
|
|
-if ($action == 'classin' && $user->hasRight('banque', 'modifier')) {
|
|
|
+if ($action == 'classin' && $permissiontoadd) {
|
|
|
$object->fetch($id);
|
|
|
$object->setProject($projectid);
|
|
|
}
|
|
|
|
|
|
// set label
|
|
|
-if ($action == 'setlabel' && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'setlabel' && $permissiontoadd) {
|
|
|
$object->fetch($id);
|
|
|
$object->label = $label;
|
|
|
$object->update($user);
|
|
|
}
|
|
|
|
|
|
// Classify paid
|
|
|
-if ($action == 'confirm_paid' && $user->hasRight('salaries', 'write') && $confirm == 'yes') {
|
|
|
+if ($action == 'confirm_paid' && $permissiontoadd && $confirm == 'yes') {
|
|
|
$object->fetch($id);
|
|
|
$result = $object->setPaid($user);
|
|
|
}
|
|
|
|
|
|
-if ($action == 'setfk_user' && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'setfk_user' && $permissiontoadd) {
|
|
|
$result = $object->fetch($id);
|
|
|
if ($result > 0) {
|
|
|
$object->fk_user = $fk_user;
|
|
@@ -196,7 +196,7 @@ if ($action == 'setfk_user' && $user->hasRight('salaries', 'write')) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-if ($action == 'reopen' && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'reopen' && $permissiontoadd) {
|
|
|
$result = $object->fetch($id);
|
|
|
if ($object->paye) {
|
|
|
$result = $object->set_unpaid($user);
|
|
@@ -210,7 +210,7 @@ if ($action == 'reopen' && $user->hasRight('salaries', 'write')) {
|
|
|
}
|
|
|
|
|
|
// payment mode
|
|
|
-if ($action == 'setmode' && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'setmode' && $permissiontoadd) {
|
|
|
$object->fetch($id);
|
|
|
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
|
|
|
if ($result < 0)
|
|
@@ -218,7 +218,7 @@ if ($action == 'setmode' && $user->hasRight('salaries', 'write')) {
|
|
|
}
|
|
|
|
|
|
// bank account
|
|
|
-if ($action == 'setbankaccount' && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'setbankaccount' && $permissiontoadd) {
|
|
|
$object->fetch($id);
|
|
|
$result = $object->setBankAccount(GETPOST('fk_account', 'int'));
|
|
|
if ($result < 0) {
|
|
@@ -361,7 +361,7 @@ if ($action == 'confirm_delete') {
|
|
|
}
|
|
|
|
|
|
|
|
|
-if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('salaries', 'write')) {
|
|
|
+if ($action == 'update' && !GETPOST("cancel") && $permissiontoadd) {
|
|
|
$amount = price2num(GETPOST('amount'), 'MT', 2);
|
|
|
|
|
|
if (empty($amount)) {
|
|
@@ -388,7 +388,7 @@ if ($action == 'confirm_clone' && $confirm != 'yes') {
|
|
|
$action = '';
|
|
|
}
|
|
|
|
|
|
-if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->hasRight('salaries', 'write'))) {
|
|
|
+if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
|
|
|
$db->begin();
|
|
|
|
|
|
$originalId = $id;
|
|
@@ -435,7 +435,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->hasRight('salarie
|
|
|
}
|
|
|
|
|
|
// Action to update one extrafield
|
|
|
-if ($action == "update_extras" && $user->hasRight('salaries', 'read')) {
|
|
|
+if ($action == "update_extras" && $permissiontoadd) {
|
|
|
$object->fetch(GETPOST('id', 'int'));
|
|
|
|
|
|
$attributekey = GETPOST('attribute', 'alpha');
|
|
@@ -468,6 +468,9 @@ $formfile = new FormFile($db);
|
|
|
if (isModEnabled('project')) $formproject = new FormProjets($db);
|
|
|
|
|
|
$title = $langs->trans('Salary')." - ".$object->ref;
|
|
|
+if ($action == 'create') {
|
|
|
+ $title = $langs->trans("NewSalary");
|
|
|
+}
|
|
|
$help_url = "";
|
|
|
llxHeader('', $title, $help_url);
|
|
|
|
|
@@ -792,7 +795,7 @@ if ($id > 0) {
|
|
|
|
|
|
// Label
|
|
|
if ($action != 'editlabel') {
|
|
|
- $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
|
|
|
+ $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
|
|
|
$morehtmlref .= $object->label;
|
|
|
} else {
|
|
|
$morehtmlref .= $langs->trans('Label').' : ';
|
|
@@ -813,7 +816,7 @@ if ($id > 0) {
|
|
|
$morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
|
|
|
}
|
|
|
} else {
|
|
|
- $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
|
|
|
+ $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $permissiontoadd, 'string', '', 0, 1);
|
|
|
|
|
|
if (!empty($object->fk_user)) {
|
|
|
$userstatic = new User($db);
|
|
@@ -847,7 +850,7 @@ if ($id > 0) {
|
|
|
if ($action != 'classify') {
|
|
|
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
|
|
|
}
|
|
|
- $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, null, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
|
|
|
+ $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
|
|
|
} else {
|
|
|
if (!empty($object->fk_project)) {
|
|
|
$proj = new Project($db);
|
|
@@ -933,7 +936,7 @@ if ($id > 0) {
|
|
|
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
|
|
|
print $langs->trans('DefaultBankAccount');
|
|
|
print '<td>';
|
|
|
- if ($action != 'editbankaccount' && $user->hasRight('salaries', 'write')) {
|
|
|
+ if ($action != 'editbankaccount' && $permissiontoadd) {
|
|
|
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>';
|
|
|
}
|
|
|
print '</tr></table>';
|
|
@@ -1087,35 +1090,35 @@ if ($id > 0) {
|
|
|
}
|
|
|
|
|
|
// Reopen
|
|
|
- if ($object->paye && $user->hasRight('salaries', 'write')) {
|
|
|
+ if ($object->paye && $permissiontoadd) {
|
|
|
print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
|
|
|
}
|
|
|
|
|
|
// Edit
|
|
|
- if ($object->paye == 0 && $user->hasRight('salaries', 'write')) {
|
|
|
+ if ($object->paye == 0 && $permissiontoadd) {
|
|
|
print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
|
|
|
}
|
|
|
|
|
|
// Emit payment
|
|
|
- if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->hasRight('salaries', 'write')) {
|
|
|
+ if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $permissiontoadd) {
|
|
|
print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
|
|
|
}
|
|
|
|
|
|
// Classify 'paid'
|
|
|
// If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
|
|
|
- if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->hasRight('salaries', 'write')) {
|
|
|
+ if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $permissiontoadd) {
|
|
|
print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
|
|
|
}
|
|
|
|
|
|
- //transfer request
|
|
|
+ // Transfer request
|
|
|
print dolGetButtonAction('', $langs->trans('MakeTransferRequest'), 'default', DOL_URL_ROOT.'/salaries/virement_request.php?id='.$object->id, '');
|
|
|
|
|
|
// Clone
|
|
|
- if ($user->hasRight('salaries', 'write')) {
|
|
|
+ if ($permissiontoadd) {
|
|
|
print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
|
|
|
}
|
|
|
|
|
|
- if ($user->hasRight('salaries', 'delete') && empty($totalpaid)) {
|
|
|
+ if ($permissiontodelete && empty($totalpaid)) {
|
|
|
print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
|
|
|
} else {
|
|
|
print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
|