Merge pull request #24026 from frederic34/loanclean

Loanclean
This commit is contained in:
Laurent Destailleur 2023-02-24 17:55:33 +01:00 committed by GitHub
commit 4228147f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 31 deletions

View File

@ -76,7 +76,7 @@ if ($reshook < 0) {
} }
if (empty($reshook)) { if (empty($reshook)) {
// Classify paid // Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->loan->write) { if ($action == 'confirm_paid' && $confirm == 'yes' && $user->hasRight('loan', 'write')) {
$object->fetch($id); $object->fetch($id);
$result = $object->setPaid($user); $result = $object->setPaid($user);
if ($result > 0) { if ($result > 0) {
@ -87,7 +87,7 @@ if (empty($reshook)) {
} }
// Delete loan // Delete loan
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->write) { if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'write')) {
$object->fetch($id); $object->fetch($id);
$result = $object->delete($user); $result = $object->delete($user);
if ($result > 0) { if ($result > 0) {
@ -100,7 +100,7 @@ if (empty($reshook)) {
} }
// Add loan // Add loan
if ($action == 'add' && $user->rights->loan->write) { if ($action == 'add' && $user->hasRight('loan', 'write')) {
if (!$cancel) { if (!$cancel) {
$datestart = dol_mktime(12, 0, 0, GETPOST('startmonth', 'int'), GETPOST('startday', 'int'), GETPOST('startyear', 'int')); $datestart = dol_mktime(12, 0, 0, GETPOST('startmonth', 'int'), GETPOST('startday', 'int'), GETPOST('startyear', 'int'));
$dateend = dol_mktime(12, 0, 0, GETPOST('endmonth', 'int'), GETPOST('endday', 'int'), GETPOST('endyear', 'int')); $dateend = dol_mktime(12, 0, 0, GETPOST('endmonth', 'int'), GETPOST('endday', 'int'), GETPOST('endyear', 'int'));
@ -168,7 +168,7 @@ if (empty($reshook)) {
header("Location: list.php"); header("Location: list.php");
exit(); exit();
} }
} elseif ($action == 'update' && $user->rights->loan->write) { } elseif ($action == 'update' && $user->hasRight('loan', 'write')) {
// Update record // Update record
if (!$cancel) { if (!$cancel) {
$result = $object->fetch($id); $result = $object->fetch($id);
@ -225,7 +225,7 @@ if (empty($reshook)) {
} }
// Link to a project // Link to a project
if ($action == 'classin' && $user->rights->loan->write) { if ($action == 'classin' && $user->hasRight('loan', 'write')) {
$object->fetch($id); $object->fetch($id);
$result = $object->setProject($projectid); $result = $object->setProject($projectid);
if ($result < 0) { if ($result < 0) {
@ -233,7 +233,7 @@ if (empty($reshook)) {
} }
} }
if ($action == 'setlabel' && $user->rights->loan->write) { if ($action == 'setlabel' && $user->hasRight('loan', 'write')) {
$object->fetch($id); $object->fetch($id);
$result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY'); $result = $object->setValueFrom('label', GETPOST('label'), '', '', 'text', '', $user, 'LOAN_MODIFY');
if ($result < 0) { if ($result < 0) {
@ -350,22 +350,22 @@ if ($action == 'create') {
// Accountancy_account_capital // Accountancy_account_capital
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_account_capital') ?GETPOST('accountancy_account_capital') : $conf->global->LOAN_ACCOUNTING_ACCOUNT_CAPITAL, 'accountancy_account_capital', 1, '', 1, 1); print $formaccounting->select_account(GETPOST('accountancy_account_capital') ?GETPOST('accountancy_account_capital') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_CAPITAL'), 'accountancy_account_capital', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_insurance // Accountancy_account_insurance
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ?GETPOST('accountancy_account_insurance') : $conf->global->LOAN_ACCOUNTING_ACCOUNT_INSURANCE, 'accountancy_account_insurance', 1, '', 1, 1); print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ?GETPOST('accountancy_account_insurance') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INSURANCE'), 'accountancy_account_insurance', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_interest // Accountancy_account_interest
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_account_interest') ?GETPOST('accountancy_account_interest') : $conf->global->LOAN_ACCOUNTING_ACCOUNT_INTEREST, 'accountancy_account_interest', 1, '', 1, 1); print $formaccounting->select_account(GETPOST('accountancy_account_interest') ?GETPOST('accountancy_account_interest') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INTEREST'), 'accountancy_account_interest', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
} else // For external software } else {
{ // For external software
// Accountancy_account_capital // Accountancy_account_capital
print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">'; print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
@ -426,13 +426,13 @@ if ($id > 0) {
$morehtmlref = '<div class="refidno">'; $morehtmlref = '<div class="refidno">';
// Ref loan // Ref loan
$morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', 0, 1); $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', 0, 1);
$morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->rights->loan->write, 'string', '', null, null, '', 1); $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', null, null, '', 1);
// Project // Project
if (isModEnabled('project')) { if (isModEnabled('project')) {
$langs->loadLangs(array("projects")); $langs->loadLangs(array("projects"));
$morehtmlref .= '<br>'.$langs->trans('Project').' '; $morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->loan->write) { if ($user->hasRight('loan', 'write')) {
if ($action != 'classify') { 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 .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
} }
@ -441,11 +441,11 @@ if ($id > 0) {
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">'; $morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>'; $morehtmlref .= '</form>';
} else { } else {
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300'); $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
} }
} else { } else {
if (!empty($object->fk_project)) { if (!empty($object->fk_project)) {
@ -740,17 +740,17 @@ if ($id > 0) {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
// Edit // Edit
if (($object->paid == 0 || $object->paid == 2) && $user->rights->loan->write) { if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'write')) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>';
} }
// Emit payment // Emit payment
if (($object->paid == 0 || $object->paid == 2) && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) { if (($object->paid == 0 || $object->paid == 2) && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->hasRight('loan', 'write')) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>';
} }
// Classify 'paid' // Classify 'paid'
if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->rights->loan->write) { if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->hasRight('loan', 'write')) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr> /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015-2018 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2015-2023 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -66,6 +66,9 @@ class Loan extends CommonObject
public $account_capital; public $account_capital;
public $account_insurance; public $account_insurance;
public $account_interest; public $account_interest;
public $accountancy_account_capital;
public $accountancy_account_insurance;
public $accountancy_account_interest;
/** /**
* @var integer|string date_creation * @var integer|string date_creation
@ -641,7 +644,6 @@ class Loan extends CommonObject
$this->fk_bank = 1; $this->fk_bank = 1;
$this->label = 'SPECIMEN'; $this->label = 'SPECIMEN';
$this->specimen = 1; $this->specimen = 1;
$this->socid = 1;
$this->account_capital = 16; $this->account_capital = 16;
$this->account_insurance = 616; $this->account_insurance = 616;
$this->account_interest = 518; $this->account_interest = 518;

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2017 Florian HENRY <florian.henry@atm-consulting.fr> /* Copyright (C) 2017 Florian HENRY <florian.henry@atm-consulting.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@ -161,11 +161,11 @@ if (!empty($conf->project->enabled)) {
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">'; $morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>'; $morehtmlref .= '</form>';
} else { } else {
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300'); $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
} }
} }
} else { } else {