Ajout protection pour empecher suppression d'un paiement qui a gnr une criture qui a t rapproche
This commit is contained in:
parent
ba3e94a2c5
commit
a4ce5d1fd0
@ -78,23 +78,39 @@ class Account
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Efface une entree dans la table ".MAIN_DB_PREFIX."bank
|
||||
/**
|
||||
* \brief Efface une entree dans la table ".MAIN_DB_PREFIX."bank
|
||||
* \param rowid Id de l'ecriture a effacer
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
function deleteline($rowid)
|
||||
{
|
||||
$nbko=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=$rowid";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$rowid;
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=$rowid";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$rowid;
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=$rowid";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$rowid;
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
$this->db->commit();
|
||||
if (! $nbko)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -$nbko;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -333,17 +333,23 @@ if ($result)
|
||||
foreach($links as $key=>$val)
|
||||
{
|
||||
if ($key) print '<br>';
|
||||
print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
||||
if ($links[$key]['type']=='payment') {
|
||||
print '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$links[$key]['url_id'].'">';
|
||||
print img_object($langs->trans('ShowPayment'),'payment').' ';
|
||||
print $langs->trans("Payment");
|
||||
print '</a>';
|
||||
}
|
||||
else if ($links[$key]['type']=='company') {
|
||||
print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$links[$key]['url_id'].'">';
|
||||
print img_object($langs->trans('ShowCustomer'),'company').' ';
|
||||
print $links[$key]['label'];
|
||||
print '</a>';
|
||||
}
|
||||
else {
|
||||
print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
|
||||
print $links[$key]['label'];
|
||||
print '</a>';
|
||||
}
|
||||
else print $links[$key]['label'];
|
||||
print '</a>';
|
||||
}
|
||||
print '</td><td> </td></tr>';
|
||||
}
|
||||
|
||||
@ -38,48 +38,53 @@ $langs->load('bills');
|
||||
$langs->load('banks');
|
||||
$langs->load('companies');
|
||||
|
||||
$mesg='';
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->fetch($_GET['id']);
|
||||
$bank_line_id = $paiement->bank_line;
|
||||
$deleted = $paiement->delete();
|
||||
if ($deleted)
|
||||
$result = $paiement->delete();
|
||||
if ($result > 0)
|
||||
{
|
||||
// Supprimer l'écriture bancaire
|
||||
if (!empty($bank_line_id))
|
||||
{
|
||||
$acc = new Account($db);
|
||||
$acc->deleteline($bank_line_id);
|
||||
Header('Location: liste.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
print 'bank_line_id='.$bank_line_id;
|
||||
exit;
|
||||
}
|
||||
$db->commit();
|
||||
Header("Location: liste.php");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
print 'deleted='.$deleted;
|
||||
exit;
|
||||
$mesg='<div class="error">'.$paiement->error.'</div>';
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer)
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$paiement = new Paiement($db);
|
||||
$paiement->id = $_GET['id'];
|
||||
if ( $paiement->valide() == 0 )
|
||||
{
|
||||
$db->commit();
|
||||
Header('Location: fiche.php?id='.$paiement->id);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg='<div class="error">'.$paiement->error.'</div>';
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Visualisation de la fiche
|
||||
*/
|
||||
@ -123,27 +128,39 @@ if ($_GET['action'] == 'valide')
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
|
||||
if ($mesg) print $mesg.'<br>';
|
||||
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td>'.$paiement->id.'</td></tr>';
|
||||
if ($paiement->bank_account)
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
||||
if ($conf->banque->enabled)
|
||||
{
|
||||
// Si compte renseigné, on affiche libelle
|
||||
$bank=new Account($db);
|
||||
$bank->fetch($paiement->bank_account);
|
||||
|
||||
print '<tr>';
|
||||
print '<td valign="top" width="140">'.$langs->trans('BankAccount').'</td>';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$bank->id.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$bank->label.'</a></td></tr>';
|
||||
if ($paiement->bank_account)
|
||||
{
|
||||
// Si compte renseigné, on affiche libelle
|
||||
$bank=new Account($db);
|
||||
$bank->fetch($paiement->bank_account);
|
||||
|
||||
$bankline=new AccountLine($db);
|
||||
$bankline->fetch($paiement->bank_line);
|
||||
|
||||
print '<tr>';
|
||||
print '<td valign="top" width="140">'.$langs->trans('BankAccount').'</td>';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$bank->id.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$bank->label.'</a></td>';
|
||||
print '<td>'.$langs->trans("BankLineConciliated").'</td><td>'.yn($bankline->rappro).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
}
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Date').'</td><td>'.dolibarr_print_date($paiement->date).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Type').'</td><td>'.$paiement->type_libelle.'</td></tr>';
|
||||
print '<tr><td valign="top" width="140">'.$langs->trans('Date').'</td><td colspan="3">'.dolibarr_print_date($paiement->date).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Type').'</td><td colspan="3">'.$paiement->type_libelle.'</td></tr>';
|
||||
if ($paiement->numero)
|
||||
{
|
||||
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td>'.$paiement->numero.'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->numero.'</td></tr>';
|
||||
}
|
||||
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td>'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td>'.nl2br($paiement->note).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($paiement->note).'</td></tr>';
|
||||
print '</table>';
|
||||
|
||||
|
||||
|
||||
@ -147,7 +147,10 @@ if ($resql)
|
||||
|
||||
print '<td align="center">'.dolibarr_print_date($objp->dp).'</td>';
|
||||
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement.'</td>';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.$objp->label.'</a></td>';
|
||||
print '<td>';
|
||||
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.'</a>';
|
||||
else print ' ';
|
||||
print '</td>';
|
||||
print '<td align="right">'.price($objp->amount).'</td>';
|
||||
print '<td align="center">';
|
||||
|
||||
|
||||
@ -71,8 +71,9 @@ class Facture
|
||||
function Facture($DB, $soc_idp='', $facid='')
|
||||
{
|
||||
$this->db = $DB ;
|
||||
|
||||
$this->id = $facid;
|
||||
$this->socidp = $soc_idp;
|
||||
$this->products = array(); // Tableau de lignes de factures
|
||||
|
||||
$this->amount = 0;
|
||||
$this->remise = 0;
|
||||
@ -81,9 +82,10 @@ class Facture
|
||||
$this->total = 0;
|
||||
$this->propalid = 0;
|
||||
$this->projetid = 0;
|
||||
$this->id = $facid;
|
||||
$this->prefixe_facture = ''; // utilisé dans le module de numérotation saturne
|
||||
$this->remise_exceptionnelle = 0;
|
||||
|
||||
$this->products = array(); // Tableau de lignes de factures
|
||||
}
|
||||
|
||||
/**
|
||||
@ -716,9 +718,11 @@ class Facture
|
||||
*/
|
||||
function set_unpayed($rowid)
|
||||
{
|
||||
dolibarr_syslog("Facture.class.php::set_unpayed rowid=".$rowid);
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture set paye=0 WHERE rowid = '.$rowid ;
|
||||
$resql = $this->db->query( $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Tag la facture comme payer partiellement
|
||||
* \param rowid id de la facture à modifier
|
||||
|
||||
@ -76,4 +76,5 @@ LineRecord=Transaction
|
||||
AddBankRecord=Add transaction
|
||||
AddBankRecordLong=Add transaction manually
|
||||
ConciliatedBy=Conciliated by
|
||||
DateConciliating=Conciliate date
|
||||
DateConciliating=Conciliate date
|
||||
BankLineConciliated=Transaction conciliated
|
||||
@ -76,4 +76,5 @@ LineRecord=Ecriture
|
||||
AddBankRecord=Ajouter écriture
|
||||
AddBankRecordLong=Saisie d'une écriture manuelle hors facture
|
||||
ConciliatedBy=Rapproché par
|
||||
DateConciliating=Date rapprochement
|
||||
DateConciliating=Date rapprochement
|
||||
BankLineConciliated=Ecriture rapprochée
|
||||
@ -209,40 +209,98 @@ class Paiement
|
||||
$form->select($name, $sql, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Supprime un paiement ainsi que les lignes qu'il a généré dans comptes
|
||||
* Si le paiement porte sur un écriture compte qui est rapprochée, on refuse
|
||||
* Si le paiement porte sur au moins une facture à "payée", on refuse
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
function delete()
|
||||
{
|
||||
$bank_line_id = $this->bank_line;
|
||||
|
||||
$this->db->begin();
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture WHERE fk_paiement = '.$this->id;
|
||||
|
||||
// Vérifier si paiement porte pas sur une facture à l'état payée
|
||||
// Si c'est le cas, on refuse la suppression
|
||||
$billsarray=$this->getBillsArray('paye=1');
|
||||
if (is_array($billsarray))
|
||||
{
|
||||
if (sizeof($billsarray))
|
||||
{
|
||||
$this->error="Impossible de supprimer un paiement portant sur au moins une facture à l'état payé";
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Vérifier si paiement ne porte pas sur ecriture bancaire rapprochée
|
||||
// Si c'est le cas, on refuse le paiement
|
||||
if ($bank_line_id)
|
||||
{
|
||||
$accline = new AccountLine($this->db,$bank_line_id);
|
||||
$accline->fetch($bank_line_id);
|
||||
if ($accline->rappro)
|
||||
{
|
||||
$this->error="Impossible de supprimer un paiement qui a généré une écriture qui a été rapprochée";
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
// Efface la ligne de paiement (dans paiement_facture et paiement)
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
|
||||
$sql.= ' WHERE fk_paiement = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement WHERE rowid = '.$this->id;
|
||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
|
||||
$sql.= ' WHERE rowid = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
if (! $result)
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
|
||||
// Supprimer l'écriture bancaire si paiement lié à écriture
|
||||
if ($bank_line_id)
|
||||
{
|
||||
$acc = new Account($this->db);
|
||||
$result=$acc->deleteline($bank_line_id);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$acc->error;
|
||||
$this->db->rollback();
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error;
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mise a jour du lien entre le paiement et la ligne générée dans llx_bank
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Mise a jour du lien entre le paiement et la ligne générée dans llx_bank
|
||||
* \param id_bank Id compte bancaire
|
||||
*/
|
||||
function update_fk_bank($id_bank)
|
||||
{
|
||||
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank.' where rowid = '.$this->id;
|
||||
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank;
|
||||
$sql.= ' WHERE rowid = '.$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -255,9 +313,10 @@ class Paiement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Valide le paiement
|
||||
*/
|
||||
/**
|
||||
* \brief Valide le paiement
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
function valide()
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id;
|
||||
@ -273,12 +332,11 @@ class Paiement
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Information sur l'objet
|
||||
* \param id id du paiement dont il faut afficher les infos
|
||||
*/
|
||||
|
||||
function info($id)
|
||||
/*
|
||||
* \brief Information sur l'objet
|
||||
* \param id id du paiement dont il faut afficher les infos
|
||||
*/
|
||||
function info($id)
|
||||
{
|
||||
$sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec, fk_user_creat, fk_user_modif';
|
||||
$sql .= ', '.$this->db->pdate('tms').' as tms';
|
||||
@ -313,5 +371,41 @@ class Paiement
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retourne la liste des factures sur lesquels porte le paiement
|
||||
* \param filter Critere de filtre
|
||||
* \return array Tableau des id de factures
|
||||
*/
|
||||
function getBillsArray($filter='')
|
||||
{
|
||||
$sql = 'SELECT fk_facture';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f';
|
||||
$sql.= ' WHERE pf.fk_facture = f.rowid AND fk_paiement = '.$this->id;
|
||||
if ($filter) $sql.= ' AND '.$filter;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$i=0;
|
||||
$num=$this->db->num_rows($resql);
|
||||
$billsarray=array();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$billsarray[$i]=$obj->fk_facture;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $billsarray;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dolibarr_syslog('Paiement::getBillsArray Error '.$this->error.' - sql='.$sql);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user