mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Fix We must refuse to delete a various payment if payment was dispatched
in accountancy.
This commit is contained in:
@@ -682,4 +682,40 @@ class PaymentVarious extends CommonObject
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a various payment linked to a bank line id was dispatched into bookkeeping
|
||||
*
|
||||
* @return int <0 if KO, 0=no, 1=yes
|
||||
*/
|
||||
public function getVentilExportCompta()
|
||||
{
|
||||
$banklineid = $this->fk_bank;
|
||||
|
||||
$alreadydispatched = 0;
|
||||
|
||||
$type = 'bank';
|
||||
|
||||
$sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$banklineid;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
$alreadydispatched = $obj->nb;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($alreadydispatched)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,6 +427,8 @@ if ($action == 'create')
|
||||
|
||||
if ($id)
|
||||
{
|
||||
$alreadyaccounted = $object->getVentilExportCompta();
|
||||
|
||||
$head=various_payment_prepare_head($object);
|
||||
|
||||
dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
|
||||
@@ -510,9 +512,9 @@ if ($id)
|
||||
|
||||
// Subledger account
|
||||
print '<tr><td class="nowrap">';
|
||||
print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, $user->rights->banque->modifier, 'string', '', 0);
|
||||
print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
|
||||
print '</td><td>';
|
||||
print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, $user->rights->banque->modifier, 'string', '', 0);
|
||||
print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
|
||||
print '</td></tr>';
|
||||
|
||||
if (!empty($conf->banque->enabled))
|
||||
@@ -557,8 +559,12 @@ if ($id)
|
||||
{
|
||||
if (!empty($user->rights->banque->modifier))
|
||||
{
|
||||
if ($alreadyaccounted) {
|
||||
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
|
||||
} else {
|
||||
print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a></div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
|
||||
|
||||
@@ -1561,7 +1561,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
|
||||
}
|
||||
|
||||
// Add if object was dispatched "into accountancy"
|
||||
if (!empty($conf->accounting->enabled) && in_array($object->element, array('bank', 'facture', 'invoice', 'invoice_supplier', 'expensereport')))
|
||||
if (!empty($conf->accounting->enabled) && in_array($object->element, array('bank', 'facture', 'invoice', 'invoice_supplier', 'expensereport', 'payment_various')))
|
||||
{
|
||||
if (method_exists($object, 'getVentilExportCompta'))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user