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

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

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

revision 1.61 by eldy, Tue Oct 18 20:03:30 2005 UTC revision 1.62 by eldy, Fri Nov 4 20:24:40 2005 UTC
# Line 55  class Propal Line 55  class Propal
55      var $note;      var $note;
56      var $price;      var $price;
57      var $status;      var $status;
58        var $fin_validite;
59            
60      var $labelstatut=array();      var $labelstatut=array();
61      var $labelstatut_short=array();      var $labelstatut_short=array();
# Line 138  class Propal Line 139  class Propal
139              $remise_percent=price2num($remise_percent);              $remise_percent=price2num($remise_percent);
140              $qty=price2num($qty);              $qty=price2num($qty);
141                            
142              $prod = new Product($this->db, $idproduct);              if ($idproduct)
             if ($prod->fetch($idproduct) > 0)  
143              {              {
144                  $price = price2num($prod->price);                  $prod = new Product($this->db, $idproduct);
145                  $subprice = price2num($prod->price);                  if ($prod->fetch($idproduct) > 0)
       
                 if ($remise_percent > 0)  
                 {  
                     $remise = round(($prod->price * $remise_percent / 100), 2);  
                     $price = $prod->price - $remise;  
                 }  
       
                 $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";  
                 $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$prod->tva_tx."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')";  
       
                 if ($this->db->query($sql) )  
146                  {                  {
147                      $this->update_price();                      $txtva = $prod->tva_tx;
148                      return 1;                      $price = price2num($prod->price);
149                        $subprice = price2num($prod->price);
150                        
151                        // Calcul remise et nouveau prix
152                                    $remise = 0;
153                        if ($remise_percent > 0)
154                        {
155                            $remise = round(($prod->price * $remise_percent / 100), 2);
156                            $price = $prod->price - $remise;
157                        }
158            
159                        $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
160                        $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$txtva."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')";
161            
162                        if ($this->db->query($sql) )
163                        {
164                            $this->update_price();
165                            return 1;
166                        }
167                        else
168                        {
169                            $this->error=$this->db->error();
170                            return -1;
171                        }
172                  }                  }
173                  else                  else
174                  {                  {
175                      $this->error=$this->db->error();                      $this->error=$this->db->error();
176                      return -1;                      return -2;
177                  }                  }
178              }              }
             else  
             {  
                 $this->error=$this->db->error();  
                 return -2;  
             }  
179          }          }
180          else          else
181          {          {
# Line 192  class Propal Line 199  class Propal
199          dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent");          dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent");
200          if ($this->statut == 0)          if ($this->statut == 0)
201          {          {
202              if (strlen(trim($p_qty)) == 0)                          // Nettoyage paramètres
203              {              $remise_percent=price2num($remise_percent);
204                  $p_qty = 1;              $p_qty=price2num($p_qty);
205              }                          if (strlen(trim($p_qty))==0) $p_qty=1;
206                    $p_price = price2num($p_price);
207              $p_price = ereg_replace(",",".",$p_price);  
       
208              $price = $p_price;              $price = $p_price;
209              $subprice = $p_price;              $subprice = $p_price;
210            
# Line 211  class Propal Line 217  class Propal
217              $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";              $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
218              $sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; ";              $sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; ";
219            
       
220              if ($this->db->query($sql) )              if ($this->db->query($sql) )
221              {              {
222            
# Line 629  class Propal Line 634  class Propal
634          }          }
635    }    }
636                    
637    /**  
638     * \brief  Définit une remise globale sur la proposition      /**
639     *       *      \brief      Définit une remise globale sur la proposition
640     *       *      \param      user        Objet utilisateur qui modifie
641     */       *      \param      remise      Montant remise    
642                 *      \return     int         <0 si ko, >0 si ok
643    function set_remise($user, $remise)       */
644    {      function set_echeance($user, $date_fin_validite)
645      if ($user->rights->propale->creer)      {
646        {          if ($user->rights->propale->creer)
647          $remise = ereg_replace(",",".",$remise);          {
648                        $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".$this->db->idate($date_fin_validite);
649          $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;              $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
650          $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";      
651                        if ($this->db->query($sql) )
652          if ($this->db->query($sql) )              {
653            {                  $this->fin_validite = $date_fin_validite;
654              $this->remise_percent = $remise;                  return 1;
655              $this->update_price();              }
656              return 1;              else
657            }              {
658          else                  $this->error=$this->db->error();
659            {                  dolibarr_syslog("Propal::set_echeance Erreur SQL");
660              dolibarr_syslog("Propal::set_remise Erreur SQL");                  return -1;
661            }              }
662        }          }
663    }      }
664    
665    
666        /**
667         *      \brief      Définit une remise globale sur la proposition
668         *      \param      user        Objet utilisateur qui modifie
669         *      \param      remise      Montant remise    
670         *      \return     int         <0 si ko, >0 si ok
671         */
672        function set_remise($user, $remise)
673        {
674            if ($user->rights->propale->creer)
675            {
676                $remise = price2num($remise);
677        
678                $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
679                $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
680        
681                if ($this->db->query($sql) )
682                {
683                    $this->remise_percent = $remise;
684                    $this->update_price();
685                    return 1;
686                }
687                else
688                {
689                    $this->error=$this->db->error();
690                    dolibarr_syslog("Propal::set_remise Erreur SQL");
691                    return -1;
692                }
693            }
694        }
695    
696        
697    /*    /*
698     *     *
699     *     *
700     *     *
701     */     */
   
702    function set_project($user, $project_id)    function set_project($user, $project_id)
703    {    {
704      if ($user->rights->propale->creer)      if ($user->rights->propale->creer)

Legend:
Removed from v.1.61  
changed lines
  Added in v.1.62

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