Fix: Protection pour qu'une remise soit appliquée qu'une fois. Si on a 2 brouillons sur la meme remise, le deuxieme qui valide a une erreur de remise non disponible

This commit is contained in:
Laurent Destailleur 2006-08-20 04:13:46 +00:00
parent a9521fdf89
commit 2e0a010daf
2 changed files with 51 additions and 15 deletions

View File

@ -150,7 +150,7 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($fac->socidp); $soc->fetch($fac->socidp);
$result = $fac->set_valid($fac->id, $user, $soc); $result = $fac->set_valid($fac->id, $user, $soc);
if ($result) if ($result >= 0)
{ {
if ($_REQUEST['lang_id']) if ($_REQUEST['lang_id'])
{ {
@ -159,6 +159,10 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
} }
facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs);
} }
else
{
$msg='<div class="error">'.$fac->error.'</div>';
}
} }
// Repasse la facture en mode brouillon // Repasse la facture en mode brouillon

View File

@ -887,7 +887,7 @@ class Facture extends CommonObject
{ {
dolibarr_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest); dolibarr_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest);
if (rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
dolibarr_syslog("Renommage ok"); dolibarr_syslog("Renommage ok");
// Suppression ancien fichier PDF dans nouveau rep // Suppression ancien fichier PDF dans nouveau rep
@ -904,25 +904,59 @@ class Facture extends CommonObject
{ {
if (($this->lignes[$i]->info_bits & 2) == 2) if (($this->lignes[$i]->info_bits & 2) == 2)
{ {
// Ligne de remis // Ligne de remise
dolibarr_syslog("Facture.class::set_valid top remises de ligne ".$this->lignes[$i]->fk_remise_except." comme utilisee"); dolibarr_syslog("Facture.class::set_valid: recherche si remise ".$this->lignes[$i]->fk_remise_except." toujours dispo");
// On recherche si ligne de remise pas deja attribuée
$sql = 'SELECT fk_facture';
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' WHERE fk_facture IS NULL AND rowid ='.$this->lignes[$i]->fk_remise_except;
$sql.= ' FOR UPDATE';
$resql=$this->db->query($sql);
if ($resql)
{
$num=$this->db->num_rows($resql);
if ($num >= 1)
{
dolibarr_syslog("Facture.class::set_valid: top ligne de remise ".$this->lignes[$i]->fk_remise_except." pour ligne de facture ".$this->lignes[$i]->rowid);
// On met à jour ligne de remise comme utilisée // On met à jour ligne de remise comme utilisée
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql.= ' SET fk_facture = '.$this->lignes[$i]->rowid; $sql.= ' SET fk_facture = '.$this->lignes[$i]->rowid;
$sql.= ' WHERE rowid ='.$this->lignes[$i]->fk_remise_except; $sql.= ' WHERE fk_facture IS NULL AND rowid ='.$this->lignes[$i]->fk_remise_except;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if ($resql)
{
}
else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->error().' sql='.$sql;
dolibarr_syslog("Facture.class::set_valid Error ".$this->error); dolibarr_syslog("Facture.class::set_valid: Error ".$this->error);
$error++; $error++;
break;
}
}
else
{
$error++;
$this->error=$langs->trans("InvoiceDiscountNotAvailable");
dolibarr_syslog("Facture.class::set_valid: Error ".$this->error);
break;
}
}
else
{
$this->error=$this->db->error().' sql='.$sql;
dolibarr_syslog("Facture.class::set_valid: Error ".$this->error);
$error++;
break;
} }
} }
} }
// On vérifie si la facture était une provisoire // On vérifie si la facture était une provisoire
if ($facref == 'PROV') if (! $error && $facref == 'PROV')
{ {
/* /*
* Pour chaque produit, on met a jour indicateur nbvente * Pour chaque produit, on met a jour indicateur nbvente
@ -948,12 +982,12 @@ class Facture extends CommonObject
else else
{ {
$error++; $error++;
$this->error=$this->db->error().' sql='.$sql;
} }
} }
if ($error == 0) if (! $error)
{ {
// Classe la société rattachée comme client // Classe la société rattachée comme client
$soc=new Societe($this->db); $soc=new Societe($this->db);
$soc->id = $this->socidp; $soc->id = $this->socidp;
@ -970,12 +1004,10 @@ class Facture extends CommonObject
// Fin appel triggers // Fin appel triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }