Fix can close a salary if paid partially.

This commit is contained in:
Laurent Destailleur 2021-11-29 19:39:03 +01:00
parent b2e8d03dae
commit 5cebaae235
2 changed files with 13 additions and 12 deletions

View File

@ -263,7 +263,10 @@ if ($action == 'add' && empty($cancel)) {
$db->begin();
$ret = $object->create($user);
if ($ret < 0) $error++;
if ($ret < 0) {
var_dump($ret);
$error++;
}
if (!empty($auto_create_paiement) && !$error) {
// Create a line of payments
$paiement = new PaymentSalary($db);
@ -562,10 +565,12 @@ if ($action == 'create') {
print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
print '</tr>';
print '<tr><td colspan="2"><hr></td></tr>';
// Auto create payment
print '<tr><td>'.$langs->trans('AutomaticCreationPayment').'</td>';
print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
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
// Bank
@ -997,14 +1002,14 @@ if ($id) {
print '<div class="clearboth"></div>';
print dol_get_fiche_end();
if ($action == 'edit') {
print $form->buttonsSaveCancel();
print "</form>";
}
print dol_get_fiche_end();
$resteapayer = price2num($resteapayer, 'MT');
/*
* Action bar
@ -1023,17 +1028,13 @@ if ($id) {
}
// Emit payment
if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->salaries->write) {
if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->rights->salaries->write) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT."/salaries/paiement_salary.php?id=".$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment")."</a></div>";
}
// Classify 'paid'
if ($object->paye == 0
&& (
(round($resteapayer) <= 0 && $object->amount > 0)
|| (round($resteapayer) >= 0 && $object->amount < 0)
)
&& $user->rights->salaries->write) {
// If at least one payment was already done ($object->amount - $resteapayer > 0) or if amount is negative, we allow to classify as paid.
if ($object->paye == 0 && ((($object->amount - $resteapayer) > 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->rights->salaries->write) {
print "<div class=\"inline-block divButAction\"><a class=\"butAction\" href=\"".DOL_URL_ROOT."/salaries/card.php?id=".$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid")."</a></div>";
}

View File

@ -367,7 +367,7 @@ class Salary extends CommonObject
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
return -4;
}
if ($this->amount < 0 || $this->amount == '') {
if ($this->amount == '') {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -5;
}