/[dolibarr]/dolibarr/htdocs/facture.class.php
ViewVC logotype

Diff of /dolibarr/htdocs/facture.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.107 by eldy, Sat Aug 20 14:36:32 2005 UTC revision 1.108 by eldy, Sat Aug 20 15:37:16 2005 UTC
# Line 248  class Facture Line 248  class Facture
248      {      {
249          $error = 0;          $error = 0;
250    
251            $this->db->begin();
252            
253          if ($this->remise_exceptionnelle[1] > 0)          if ($this->remise_exceptionnelle[1] > 0)
254          {          {
255                // Calcul valeur de remise a appliquer (remise) et reliquat
256              if ($this->remise_exceptionnelle[1] > ($this->total_ht * 0.9))              if ($this->remise_exceptionnelle[1] > ($this->total_ht * 0.9))
257              {              {
   
258                  $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');  
   
259                  $reliquat = $this->remise_exceptionnelle[1] - $remise;                  $reliquat = $this->remise_exceptionnelle[1] - $remise;
260                }
261                else
262                {
263                    $remise = $this->remise_exceptionnelle[1];
264                    $reliquat=0;
265                }
266    
267                  $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";              $result_insert = $this->addline($this->id,
268                  $sql .= " SET fk_facture = ".$this->id;              addslashes("Remise exceptionnelle"),
269                  $sql .= " ,amount_ht = '".ereg_replace(",",".",$remise)."'";              (0 - $remise),
270                  $sql .= " WHERE rowid =".$this->remise_exceptionnelle[0];              1,
271                  $sql .= " AND fk_soc =". $this->socidp;              '0');   // Une remise est un négatif sur le TTC, on ne doit pas appliquer de TVA,
272                        // sinon on impute une TVA négative.
273        
274                if ($result_insert < 0)
275                {
276                    $error++;
277                }
278    
279                  if (! $this->db->query( $sql))              $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
280                  {              $sql .= " SET fk_facture = ".$this->id;
281                      $error++;              $sql .= " ,amount_ht = '".ereg_replace(",",".",$remise)."'";
282                  }              $sql .= " WHERE rowid =".$this->remise_exceptionnelle[0];
283                $sql .= " AND fk_soc =". $this->socidp;
284    
285                if (! $this->db->query( $sql))
286                {
287                    $error++;
288                }
289    
290                if ($reliquat > 0)
291                {
292                  $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";                  $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
293                  $sql .= " (fk_soc, datec, amount_ht, fk_user) ";                  $sql .= " (fk_soc, datec, amount_ht, fk_user) ";
294                  $sql .= " VALUES ";                  $sql .= " VALUES ";
# Line 288  class Facture Line 302  class Facture
302                  {                  {
303                      $error++;                      $error++;
304                  }                  }
   
305              }              }
             else  
             {  
                 $remise = $this->remise_exceptionnelle[1];  
306    
307                  $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;  
308    
309                  if (! $this->db->query( $sql) )          if (! $error)
310                  {          {
311                      $error++;              $this->db->commit();
312                  }          }
313              }          else
314            {
315                $this->db->rollback();
316          }          }
317    
318          return $error;          return $error;
   
319      }      }
320    
321      /**      /**

Legend:
Removed from v.1.107  
changed lines
  Added in v.1.108

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26