Qual: Mise en transaction de la mise a jour de la remise.
This commit is contained in:
parent
ef3642a795
commit
3f96249762
@ -19,7 +19,6 @@
|
|||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,7 +268,7 @@ if ($_socid > 0)
|
|||||||
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$objsoc->typent.'</td><td>'.$langs->trans("Staff").'</td><td>'.$objsoc->effectif.'</td></tr>';
|
print '<tr><td>'.$langs->trans("Type").'</td><td>'.$objsoc->typent.'</td><td>'.$langs->trans("Staff").'</td><td>'.$objsoc->effectif.'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td nowrap>';
|
print '<tr><td nowrap>';
|
||||||
print '<table width="100%" class="nobordernopadding"><tr><td>';
|
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
|
||||||
print $langs->trans("CustomerRelativeDiscount");
|
print $langs->trans("CustomerRelativeDiscount");
|
||||||
print '<td><td align="right">';
|
print '<td><td align="right">';
|
||||||
print '<a href="remise.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
|
print '<a href="remise.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
|
||||||
@ -278,7 +277,7 @@ if ($_socid > 0)
|
|||||||
|
|
||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
|
|
||||||
print '<table width="100%" class="nobordernopadding"><tr><td>';
|
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
|
||||||
print $langs->trans("CustomerAbsoluteDiscount");
|
print $langs->trans("CustomerAbsoluteDiscount");
|
||||||
print '<td><td align="right">';
|
print '<td><td align="right">';
|
||||||
print '<a href="remx.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
|
print '<a href="remx.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
|
||||||
|
|||||||
@ -248,33 +248,47 @@ class Facture
|
|||||||
{
|
{
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
if ($this->remise_exceptionnelle[1] > 0)
|
if ($this->remise_exceptionnelle[1] > 0)
|
||||||
{
|
{
|
||||||
|
// Calcul valeur de remise a appliquer (remise) et reliquat
|
||||||
if ($this->remise_exceptionnelle[1] > ($this->total_ht * 0.9))
|
if ($this->remise_exceptionnelle[1] > ($this->total_ht * 0.9))
|
||||||
{
|
{
|
||||||
|
|
||||||
$remise = floor($this->total_ht * 0.9);
|
$remise = floor($this->total_ht * 0.9);
|
||||||
|
|
||||||
$result_insert = $this->addline($this->id,
|
|
||||||
addslashes("Remise exceptionnelle"),
|
|
||||||
(0 - $remise),
|
|
||||||
1,
|
|
||||||
'19.6');
|
|
||||||
|
|
||||||
$reliquat = $this->remise_exceptionnelle[1] - $remise;
|
$reliquat = $this->remise_exceptionnelle[1] - $remise;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$remise = $this->remise_exceptionnelle[1];
|
||||||
|
$reliquat=0;
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
|
$result_insert = $this->addline($this->id,
|
||||||
$sql .= " SET fk_facture = ".$this->id;
|
addslashes("Remise exceptionnelle"),
|
||||||
$sql .= " ,amount_ht = '".ereg_replace(",",".",$remise)."'";
|
(0 - $remise),
|
||||||
$sql .= " WHERE rowid =".$this->remise_exceptionnelle[0];
|
1,
|
||||||
$sql .= " AND fk_soc =". $this->socidp;
|
'0'); // Une remise est un négatif sur le TTC, on ne doit pas appliquer de TVA,
|
||||||
|
// sinon on impute une TVA négative.
|
||||||
|
|
||||||
if (! $this->db->query( $sql))
|
if ($result_insert < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
|
||||||
|
$sql .= " SET fk_facture = ".$this->id;
|
||||||
|
$sql .= " ,amount_ht = '".ereg_replace(",",".",$remise)."'";
|
||||||
|
$sql .= " WHERE rowid =".$this->remise_exceptionnelle[0];
|
||||||
|
$sql .= " AND fk_soc =". $this->socidp;
|
||||||
|
|
||||||
|
if (! $this->db->query( $sql))
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reliquat > 0)
|
||||||
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
|
||||||
$sql .= " (fk_soc, datec, amount_ht, fk_user) ";
|
$sql .= " (fk_soc, datec, amount_ht, fk_user) ";
|
||||||
$sql .= " VALUES ";
|
$sql .= " VALUES ";
|
||||||
@ -288,32 +302,20 @@ class Facture
|
|||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$remise = $this->remise_exceptionnelle[1];
|
|
||||||
|
|
||||||
$result_insert = $this->addline($this->id,
|
}
|
||||||
addslashes("Remise exceptionnelle"),
|
|
||||||
(0 - $remise),
|
|
||||||
1,
|
|
||||||
'19.6');
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
|
if (! $error)
|
||||||
$sql .= " SET fk_facture = ".$this->id;
|
{
|
||||||
$sql .= " WHERE rowid =".$this->remise_exceptionnelle[0];
|
$this->db->commit();
|
||||||
$sql .= " AND fk_soc =". $this->socidp;
|
}
|
||||||
|
else
|
||||||
if (! $this->db->query( $sql) )
|
{
|
||||||
{
|
$this->db->rollback();
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error;
|
return $error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user