/[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.118 by eldy, Tue Sep 6 01:20:13 2005 UTC revision 1.119 by eldy, Fri Sep 9 21:15:26 2005 UTC
# Line 184  class Facture Line 184  class Facture
184              }              }
185                            
186              /*              /*
187              * Produits de la facture récurrente               * Produits de la facture récurrente
188              *               *
189              */               */
190              if ($this->fac_rec > 0)              if ($this->fac_rec > 0)
191              {              {
192                  for ($i = 0 ; $i < sizeof($_facrec->lignes) ; $i++)                  for ($i = 0 ; $i < sizeof($_facrec->lignes) ; $i++)
# Line 205  class Facture Line 205  class Facture
205                      $_facrec->lignes[$i]->produit_id,                      $_facrec->lignes[$i]->produit_id,
206                      $_facrec->lignes[$i]->remise_percent);                      $_facrec->lignes[$i]->remise_percent);
207    
208                      if ( $result_insert < 0)                      if ($result_insert < 0)
209                      {                      {
210                          dolibarr_print_error($this->db);                          dolibarr_print_error($this->db);
211                      }                      }
212                  }                  }
213              }              }
214    
215              $this->updateprice($this->id);              $result=$this->updateprice($this->id);
216                if ($result)
217              $this->db->commit();              {
218                    // Appel des triggers
219              return $this->id;                  include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
220                    $interface=new Interfaces($this->db);
221                    $interface->run_triggers('BILL_CREATE',$this,$user,$lang,$conf);
222                    // Fin appel triggers
223        
224                    $this->db->commit();
225                    return $this->id;
226                }
227                else
228                {
229                    $this->db->rollback();
230                    return -2;
231                }
232          }          }
233          else          else
234          {          {
235              $this->db->rollback();              $this->db->rollback();
236                return -1;
             dolibarr_print_error($this->db);  
237          }          }
   
238      }      }
239    
240    
# Line 552  class Facture Line 562  class Facture
562      }      }
563    
564      /**      /**
565      * \brief     Supprime la facture       *      \brief     Supprime la facture
566      * \param     rowid      id de la facture à supprimer       *      \param     rowid      id de la facture à supprimer
567      */       */
568      function delete($rowid)      function delete($rowid)
569      {      {
570            $this->db->begin();
571            
572          $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_tva_sum WHERE fk_facture = $rowid;";          $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_tva_sum WHERE fk_facture = $rowid;";
573    
574          if ( $this->db->query( $sql) )          if ( $this->db->query( $sql) )
# Line 575  class Facture Line 587  class Facture
587                      if ($this->db->query( $sql) )                      if ($this->db->query( $sql) )
588                      {                      {
589                          /*                          /*
590                          * On repositionne la remise                           * On repositionne la remise
591                          */                           */
592                          $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";                          $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
593                          $sql .= " SET fk_facture = NULL WHERE fk_facture = $rowid";                          $sql .= " SET fk_facture = NULL WHERE fk_facture = $rowid";
594    
# Line 584  class Facture Line 596  class Facture
596                          {                          {
597    
598                              $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture WHERE rowid = $rowid AND fk_statut = 0;";                              $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture WHERE rowid = $rowid AND fk_statut = 0;";
599                                $resql=$this->db->query($sql) ;
600    
601                              $this->db->query( $sql) ;                              if ($resql)
602                                {
603                                    // Appel des triggers
604                              return 1;                                  include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
605                                    $interface=new Interfaces($this->db);
606                                    $interface->run_triggers('BILL_DELETE',$this,$user,$lang,$conf);
607                                    // Fin appel triggers
608                    
609                                    $this->db->commit();
610                                    return 1;
611                                }
612                                else
613                                {
614                                    $this->db->rollback();
615                                    return -6;
616                                }
617                          }                          }
618                          else                          else
619                          {                          {
620                              dolibarr_print_error($this->db);                              $this->db->rollback();
621                                return -5;
622                          }                          }
   
623                      }                      }
624                      else                      else
625                      {                      {
626                          dolibarr_print_error($this->db);                          $this->db->rollback();
627                            return -4;
628                      }                      }
629                  }                  }
630                  else                  else
631                  {                  {
632                      dolibarr_print_error($this->db);                      $this->db->rollback();
633                        return -3;
634                  }                  }
635              }              }
636              else              else
637              {              {
638                  dolibarr_print_error($this->db);                  $this->db->rollback();
639                    return -2;
640              }              }
641          }          }
642          else          else
643          {          {
644              dolibarr_print_error($this->db);              $this->db->rollback();
645                return -1;
646          }          }
647      }      }
648    
# Line 724  class Facture Line 753  class Facture
753                  $numfa = facture_get_num($soc, $this->prefixe_facture); // définit dans includes/modules/facture                  $numfa = facture_get_num($soc, $this->prefixe_facture); // définit dans includes/modules/facture
754              }              }
755    
756              if ($this->db->begin())              $this->db->begin();
757              {              
758                  /*              /*
759                  * Lecture de la remise exceptionnelle               * Lecture de la remise exceptionnelle
760                  *               */
761                  */              $sql  = "SELECT rowid, rc.amount_ht, fk_soc, fk_user";
762                  $sql  = "SELECT rowid, rc.amount_ht, fk_soc, fk_user";              $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
763                  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";              $sql .= " WHERE rc.fk_soc =". $this->socidp;
764                  $sql .= " WHERE rc.fk_soc =". $this->socidp;              $sql .= " AND fk_facture IS NULL";
                 $sql .= " AND fk_facture IS NULL";  
   
                 $resql = $this->db->query($sql) ;  
   
                 if ($resql)  
                 {  
                     $nurmx = $this->db->num_rows($resql);  
   
                     if ($nurmx > 0)  
                     {  
                         $row = $this->db->fetch_row($resql);  
                         $this->remise_exceptionnelle = $row;  
                     }  
                     $this->db->free($resql);  
                 }  
                 else  
                 {  
                     dolibarr_syslog("Facture::Valide Erreur lecture Remise");  
                     $error++;  
                 }  
   
                 /* Affectation de la remise exceptionnelle */  
                 if ( $this->_affect_remise_exceptionnelle() <> 0)  
                 {  
                     $error++;  
                 }  
                 else  
                 {  
                     $this->updateprice($this->id);  
                 }  
765    
766                  /* Validation de la facture */              $resql = $this->db->query($sql) ;
767                  $sql = "UPDATE ".MAIN_DB_PREFIX."facture ";              if ($resql)
768                  $sql .= " SET facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id";              {
769                    $nurmx = $this->db->num_rows($resql);
770    
771                  /* Si l'option est activée on force la date de facture */                  if ($nurmx > 0)
                 if (defined("FAC_FORCE_DATE_VALIDATION") && FAC_FORCE_DATE_VALIDATION == "1")  
772                  {                  {
773                      $this->date=time();                      $row = $this->db->fetch_row($resql);
774                      $datelim=$this->calculate_date_lim_reglement();                      $this->remise_exceptionnelle = $row;
   
                     $sql .= ", datef=".$this->db->idate($this->date);  
                     $sql .= ", date_lim_reglement=".$this->db->idate($datelim);  
775                  }                  }
776                    $this->db->free($resql);
777                }
778                else
779                {
780                    dolibarr_syslog("Facture::Valide Erreur lecture Remise");
781                    $error++;
782                }
783    
784                  $sql .= " WHERE rowid = $rowid ;";              /* Affectation de la remise exceptionnelle */
785                if ( $this->_affect_remise_exceptionnelle() <> 0)
786                {
787                    $error++;
788                }
789                else
790                {
791                    $this->updateprice($this->id);
792                }
793    
794                  $resql = $this->db->query($sql);              /* Validation de la facture */
795                  if ($resql)              $sql = "UPDATE ".MAIN_DB_PREFIX."facture ";
796                  {              $sql .= " SET facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id";
                     // Appel des triggers  
                     include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");  
                     $interface=new Interfaces($this->db);  
                     $ret=$interface->run_triggers('BILL_VALIDATE',$this,$user,$lang,$conf);  
                     // Fin appel triggers  
797    
798                      if ($ret < 0) $error++;              /* Si l'option est activée on force la date de facture */
799                  }              if (defined("FAC_FORCE_DATE_VALIDATION") && FAC_FORCE_DATE_VALIDATION == "1")
800                  else              {
801                  {                  $this->date=time();
802                      dolibarr_syslog("Facture::set_valid() Echec - 10");                  $datelim=$this->calculate_date_lim_reglement();
                     dolibarr_print_error($this->db);  
                     $error++;  
                 }  
803    
804                  /*                  $sql .= ", datef=".$this->db->idate($this->date);
805                   * Update Stats                  $sql .= ", date_lim_reglement=".$this->db->idate($datelim);
806                   */              }
                 $sql = "SELECT fk_product FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = ".$this->id;  
                 $sql .= " AND fk_product > 0";  
807    
808                  $resql = $this->db->query($sql);              $sql .= " WHERE rowid = $rowid ;";
                 if ($resql)  
                 {  
                     $num = $this->db->num_rows($resql);  
                     $i = 0;  
                     while ($i < $num)  
                     {  
                         $obj = $this->db->fetch_object($resql);  
809    
810                          $sql = "UPDATE ".MAIN_DB_PREFIX."product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;              $resql = $this->db->query($sql);
811                          $resql2 = $this->db->query($sql);              if (! $resql)
812                {
813                    dolibarr_syslog("Facture::set_valid() Echec - 10");
814                    dolibarr_print_error($this->db);
815                    $error++;
816                }
817                    
818                /*
819                 * Update Stats
820                 */
821                $sql = "SELECT fk_product FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture = ".$this->id;
822                $sql .= " AND fk_product > 0";
823    
824                          $i++;              $resql = $this->db->query($sql);
825                      }              if ($resql)
826                  }              {
827                  else                  $num = $this->db->num_rows($resql);
828                    $i = 0;
829                    while ($i < $num)
830                  {                  {
831                      $error++;                      $obj = $this->db->fetch_object($resql);
                 }  
832    
833                  if ($error == 0)                      $sql = "UPDATE ".MAIN_DB_PREFIX."product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
834                  {                      $resql2 = $this->db->query($sql);
                     $this->db->commit();  
835    
836                      /*                      $i++;
                      * Notify  
                      */  
                     $facref = sanitize_string($this->ref);  
                     $filepdf = FAC_OUTPUTDIR . "/" . $facref . "/" . $facref . ".pdf";  
       
                     $mesg = "La facture ".$this->ref." a été validée.\n";  
       
                     $notify = New Notify($this->db);  
                     $notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);  
                 }  
                 else  
                 {  
                     $this->db->rollback();  
837                  }                  }
838              }              }
839                else
840                {
841                    $error++;
842                }
843    
844              if ($error == 0)              if ($error == 0)
845              {              {
846                    // Appel des triggers
847                    include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
848                    $interface=new Interfaces($this->db);
849                    $interface->run_triggers('BILL_VALIDATE',$this,$user,$lang,$conf);
850                    // Fin appel triggers
851    
852                    $this->db->commit();
853    
854                    /*
855                     * Notify
856                     */
857                    $facref = sanitize_string($this->ref);
858                    $filepdf = FAC_OUTPUTDIR . "/" . $facref . "/" . $facref . ".pdf";
859    
860                    $mesg = "La facture ".$this->ref." a été validée.\n";
861    
862                    $notify = New Notify($this->db);
863                    $notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);
864    
865                  return 1;                  return 1;
866              }              }
867              else              else
868              {              {
869                  return 0;                  $this->db->rollback();
870                    $this->error=$this->db->error();
871                    return -1;
872              }              }
873          }          }
874      }      }

Legend:
Removed from v.1.118  
changed lines
  Added in v.1.119

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