diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 313981cc482..4b1f4220c88 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -19,7 +19,6 @@ * * $Id$ * $Source$ - * */ /** @@ -269,7 +268,7 @@ if ($_socid > 0) print ''.$langs->trans("Type").''.$objsoc->typent.''.$langs->trans("Staff").''.$objsoc->effectif.''; print ''; - print '
'; + print '
'; print $langs->trans("CustomerRelativeDiscount"); print ''; print ''.img_edit($langs->trans("Modify")).''; @@ -278,7 +277,7 @@ if ($_socid > 0) print '
'; - print '
'; + print '
'; print $langs->trans("CustomerAbsoluteDiscount"); print ''; print ''.img_edit($langs->trans("Modify")).''; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index a34c20ec378..7ff401138c1 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -248,33 +248,47 @@ class Facture { $error = 0; + $this->db->begin(); + 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)) { - $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; + } + else + { + $remise = $this->remise_exceptionnelle[1]; + $reliquat=0; + } - $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; + $result_insert = $this->addline($this->id, + addslashes("Remise exceptionnelle"), + (0 - $remise), + 1, + '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 ($result_insert < 0) + { + $error++; + } - if (! $this->db->query( $sql)) - { - $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 .= " (fk_soc, datec, amount_ht, fk_user) "; $sql .= " VALUES "; @@ -288,32 +302,20 @@ class Facture { $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"; - $sql .= " SET fk_facture = ".$this->id; - $sql .= " WHERE rowid =".$this->remise_exceptionnelle[0]; - $sql .= " AND fk_soc =". $this->socidp; - - if (! $this->db->query( $sql) ) - { - $error++; - } - } + if (! $error) + { + $this->db->commit(); + } + else + { + $this->db->rollback(); } return $error; - } /**