Amélioration sécurité sur l'édition d'un facture validée

This commit is contained in:
Regis Houssin 2006-07-16 12:26:36 +00:00
parent 5bf8ab56b4
commit 74847f56de
2 changed files with 44 additions and 39 deletions

View File

@ -161,25 +161,17 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
} }
} }
// Repasse la facture en mode brouillon
if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->global->FACTURE_ENABLE_EDITDELETE) if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->global->FACTURE_ENABLE_EDITDELETE)
{ {
/*
* Repasse la facture en mode brouillon
*/
$fac = new Facture($db); $fac = new Facture($db);
$fac->fetch($_GET['facid']); $fac->fetch($_GET['facid']);
// On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées
$ventilExportCompta = 0 ; $ventilExportCompta = $fac->getVentilExportCompta();
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
{
if ($fac->lignes[$i]->export_compta <> 0 && $fac->lignes[$i]->code_ventilation <> 0)
{
$ventilExportCompta++;
}
}
if ($ventilExportCompta == 0) // On vérifie si aucun paiement n'a été effectué
if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0)
{ {
$fac->reopen($user); $fac->reopen($user);
} }
@ -2111,14 +2103,7 @@ else
if ($fac->statut == 1) if ($fac->statut == 1)
{ {
// On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées
$ventilExportCompta = 0 ; $ventilExportCompta = $fac->getVentilExportCompta();
for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
{
if ($fac->lignes[$i]->export_compta <> 0 && $fac->lignes[$i]->code_ventilation <> 0)
{
$ventilExportCompta++;
}
}
if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier
&& ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0)) && ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0))

View File

@ -1834,6 +1834,34 @@ class Facture extends CommonObject
} }
/**
* \brief Renvoi si les lignes de facture sont ventilées et/ou exportées en compta
* \param user Utilisateur créant la demande
* \return int <0 si ko, 0=non, 1=oui
*/
function getVentilExportCompta()
{
// On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées
$ventilExportCompta = 0 ;
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
if ($this->lignes[$i]->export_compta <> 0 && $this->lignes[$i]->code_ventilation <> 0)
{
$ventilExportCompta++;
}
}
if ($ventilExportCompta <> 0)
{
return 1;
}
else
{
return 0;
}
}
/** /**
* \brief Renvoi si une facture peut etre supprimée complètement * \brief Renvoi si une facture peut etre supprimée complètement
* La règle est la suivante: * La règle est la suivante:
@ -1863,15 +1891,7 @@ class Facture extends CommonObject
$maxfacnumber = $db->fetch_row($resql); $maxfacnumber = $db->fetch_row($resql);
} }
// On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées $ventilExportCompta = $this->getVentilExportCompta();
$ventilExportCompta = 0 ;
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
if ($this->lignes[$i]->export_compta <> 0 && $this->lignes[$i]->code_ventilation <> 0)
{
$ventilExportCompta++;
}
}
// Si derniere facture et si non ventilée, on peut supprimer // Si derniere facture et si non ventilée, on peut supprimer
if ($maxfacnumber[0] == $this->ref && $ventilExportCompta == 0) if ($maxfacnumber[0] == $this->ref && $ventilExportCompta == 0)