FIX Blocking situation when a payment was deleted in bank.

FIX Missing or bad permissions
This commit is contained in:
Laurent Destailleur 2022-02-28 19:45:53 +01:00
parent 8866d447c7
commit ca236c556a
6 changed files with 97 additions and 21 deletions

View File

@ -734,7 +734,7 @@ if (empty($reshook)) {
}
if (!$error) {
// On verifie si la facture a des paiements
// We check if invoice has payments
$sql = 'SELECT pf.amount';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
$sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
@ -984,7 +984,7 @@ if (empty($reshook)) {
$db->rollback();
}
}
} elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) {
} elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercanissuepayment) {
// Delete payment
$object->fetch($id);
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) {

View File

@ -75,6 +75,12 @@ $hookmanager->initHooks(array('paiementcard', 'globalcard'));
$formquestion = array();
$usercanissuepayment = !empty($user->rights->facture->paiement);
$fieldid = 'rowid';
$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
$result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $fieldid, $isdraft);
/*
* Actions
@ -87,7 +93,7 @@ if ($reshook < 0) {
}
if (empty($reshook)) {
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
if (($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $usercanissuepayment) {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -202,7 +208,7 @@ if (empty($reshook)) {
/*
* Action confirm_paiement
*/
if ($action == 'confirm_paiement' && $confirm == 'yes') {
if ($action == 'confirm_paiement' && $confirm == 'yes' && $usercanissuepayment) {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -486,7 +492,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<td><span class="fieldrequired">'.$langs->trans('AccountToDebit').'</span></td>';
}
print '<td>';
$form->select_comptes($accountid, 'accountid', 0, '', 2);
print $form->select_comptes($accountid, 'accountid', 0, '', 2, '', 0, '', 1);
print '</td>';
} else {
print '<td>&nbsp;</td>';

View File

@ -64,6 +64,8 @@ if ($socid && $socid != $object->thirdparty->id) {
accessforbidden();
}
$error = 0;
/*
* Actions
@ -191,6 +193,39 @@ if ($action == 'setdatep' && !empty($_POST['datepday'])) {
setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
}
}
if ($action == 'createbankpayment' && !empty($user->rights->facture->paiement)) {
$db->begin();
// Create the record into bank for the amount of payment $object
if (!$error) {
$label = '(CustomerInvoicePayment)';
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
$label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
}
$bankaccountid = GETPOST('accountid', 'int');
if ($bankaccountid > 0) {
$object->paiementcode = $object->type_code;
$object->amounts = $object->getAmountsArray();
$result = $object->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
} else {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
$error++;
}
}
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
/*
@ -315,7 +350,37 @@ if (!empty($conf->banque->enabled)) {
print $bankline->getNomUrl(1, 0, 'showconciliatedandaccounted');
} else {
$langs->load("admin");
print '<span class="opacitymedium">'.$langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name")).'</span>';
print '<span class="opacitymedium">';
print $langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name"));
print '</span>';
if (!empty($user->rights->facture->paiement)) {
// Try to guess $bankaccountidofinvoices that is ID of bank account defined on invoice.
// Return null if not found, return 0 if it has different value for at least 2 invoices, return the value if same on all invoices where a bank is defined.
$amountofpayments = $object->getAmountsArray();
$bankaccountidofinvoices = null;
foreach ($amountofpayments as $idinvoice => $amountofpayment) {
$tmpinvoice = new Facture($db);
$tmpinvoice->fetch($idinvoice);
if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
if (is_null($bankaccountidofinvoices)) {
$bankaccountidofinvoices = $tmpinvoice->fk_account;
} elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
$bankaccountidofinvoices = 0;
}
}
}
print '<form method="POST" name="createbankpayment">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="createbankpayment">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print ' '.$langs->trans("ToCreateRelatedRecordIntoBank").': ';
print $form->select_comptes($bankaccountidofinvoices, 'accountid', 0, '', 2, '', 0, '', 1);
//print '<span class="opacitymedium">';
print '<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans("ClickHere").'">';
//print '</span>';
print '</form>';
}
}
print '</td>';
print '</tr>';

View File

@ -951,6 +951,7 @@ class Paiement extends CommonObject
*
* @param string $filter Filter
* @return int|array <0 if KO or array of invoice id
* @see getAmountsArray()
*/
public function getBillsArray($filter = '')
{
@ -984,6 +985,7 @@ class Paiement extends CommonObject
* Return list of amounts of payments.
*
* @return int|array Array of amount of payments
* @see getBillsArray()
*/
public function getAmountsArray()
{

View File

@ -182,3 +182,4 @@ IfYouDontReconcileDisableProperty=If you don't make the bank reconciliations on
NoBankAccountDefined=No bank account defined
NoRecordFoundIBankcAccount=No record found in bank account. Commonly, this occurs when a record has been deleted manually from the list of transaction in the bank account (for example during a reconciliation of the bank account). Another reason is that the payment was recorded when the module "%s" was disabled.
AlreadyOneBankAccount=Already one bank account defined
ToCreateRelatedRecordIntoBank=To create missing related bank record

View File

@ -41,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage third parties objects (customers, suppliers, prospects...)
*/
@ -2573,7 +2574,7 @@ class Societe extends CommonObject
$name .= ' ('.$this->name_alias.')';
}
$result = ''; $label = '';
$result = ''; $label = ''; $label2 = '';
$linkstart = ''; $linkend = '';
if (!empty($this->logo) && class_exists('Form')) {
@ -2641,47 +2642,48 @@ class Societe extends CommonObject
}
$label .= '<br>'.implode('&nbsp;', $phonelist);
}
if (!empty($this->address)) {
$label .= '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs); // Address + country
$label2 .= '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs); // Address + country
} elseif (!empty($this->country_code)) {
$label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
$label2 .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
}
if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) {
$label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.dol_escape_htmltag($this->tva_intra);
$label2 .= '<br><b>'.$langs->trans('VATIntra').':</b> '.dol_escape_htmltag($this->tva_intra);
}
if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1;
$label2 .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2;
$label2 .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3;
$label2 .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4;
$label2 .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5;
$label2 .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5;
}
if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) {
$label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6;
$label2 .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6;
}
}
if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
$label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
$label2 .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
}
if (!empty($this->code_fournisseur) && $this->fournisseur) {
$label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
$label2 .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
}
if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
$label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
$label2 .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
}
if (!empty($conf->accounting->enabled) && $this->fournisseur) {
$label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
$label2 .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
}
$label .= '</div>';
$label .= ($label2 ? '<br>'.$label2 : '').'</div>';
// Add type of canvas
$linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : '');