/[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.133 by eldy, Fri Nov 11 22:36:56 2005 UTC revision 1.134 by hregis, Wed Nov 30 17:37:02 2005 UTC
# Line 92  class Facture Line 92  class Facture
92           */           */
93          function create($user)          function create($user)
94          {          {
95                    global $langs,$conf;
96                  $this->db->begin();                  $this->db->begin();
97    
98                  /* On positionne en mode brouillon la facture */                  /* On positionne en mode brouillon la facture */
# Line 575  class Facture Line 576  class Facture
576          */          */
577          function delete($rowid)          function delete($rowid)
578          {          {
579                    global $user,$langs,$conf;
580                    
581          $this->db->begin();          $this->db->begin();
582                  $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;
583    
# Line 1760  class Facture Line 1763  class Facture
1763                  }                  }
1764          }          }
1765    
1766    
1767       /**
1768             *      \brief      Ajoute un contact associé une facture
1769         *      \param      fk_socpeople        Id du contact a ajouter.
1770         *      \param      type_contact        Type de contact
1771         *      \param      source              extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user)
1772         *      \return     int                 <0 si erreur, >0 si ok
1773         */
1774            function add_contact($fk_socpeople, $type_contact, $source='extern')
1775            {
1776            dolibarr_syslog("Facture::add_contact $fk_socpeople, $type_contact, $source");
1777    
1778            if ($fk_socpeople <= 0) return -1;
1779    
1780            // Verifie type_contact
1781            if (! $type_contact || ! is_numeric($type_contact))
1782            {
1783                $this->error="Valeur pour type_contact incorrect";
1784                return -3;  
1785            }
1786            
1787            $datecreate = time();
1788            
1789            // Insertion dans la base
1790            $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
1791            $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1792            $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
1793                                    $sql.= $this->db->idate($datecreate);
1794                                    $sql.= ", 4, '". $type_contact . "' ";
1795            $sql.= ");";
1796            
1797            // Retour
1798            if ( $this->db->query($sql) )
1799            {
1800                return 1;
1801            }
1802            else
1803            {
1804    //            dolibarr_print_error($this->db);
1805                $this->error=$this->db->error()." - $sql";
1806                return -1;
1807            }
1808            }    
1809    
1810        /**
1811                     *
1812                     *      \brief      Mise a jour du contact associé une facture
1813         *      \param      rowid           La reference du lien facture-contact
1814         *          \param          statut          Le nouveau statut
1815         *      \param      type_contact_id   Description du type de contact
1816         *      \return     int             <0 si erreur, >0 si ok
1817         */
1818            function update_contact($rowid, $statut, $type_contact_id)
1819            {
1820            // Insertion dans la base
1821            $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
1822            $sql.= " statut = $statut ,";
1823            $sql.= " fk_c_type_contact = '".$type_contact_id ."'";
1824            $sql.= " where rowid = $rowid ;";
1825            // Retour
1826            if (  $this->db->query($sql) )
1827            {
1828                return 0;
1829            }
1830            else
1831            {
1832                dolibarr_print_error($this->db);
1833                return -1;
1834            }
1835             }    
1836            
1837                    /**
1838         *    \brief      Supprime une ligne de contact de contrat
1839         *    \param      rowid             La reference du contact
1840         *    \return     statur        >0 si ok, <0 si ko
1841         */
1842        function delete_contact($rowid)
1843        {
1844        
1845            $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact WHERE rowid =".$rowid;
1846            if ($this->db->query($sql))
1847            {
1848                return 1;
1849            }
1850            else
1851            {
1852                return -1;
1853            }
1854        }
1855                            
1856        /**
1857         *    \brief      Récupère les lignes de contact du contrat
1858         *    \param      statut        Statut des lignes detail à récupérer
1859         *    \param      source        Source du contact external (llx_socpeople) ou internal (llx_user)
1860         *    \return     array         Tableau des rowid des contacts
1861         */
1862        function liste_contact($statut=-1,$source='external')
1863        {
1864            global $langs;
1865            
1866            $tab=array();
1867        
1868            $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,";
1869            if ($source == 'internal') $sql.=" '-1' as socid,";
1870            if ($source == 'external') $sql.=" t.fk_soc as socid,";
1871            if ($source == 'internal') $sql.=" t.name as nom,";
1872            if ($source == 'external') $sql.=" t.name as nom,";
1873            $sql.= "tc.source, tc.element, tc.code, tc.libelle";
1874            $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
1875            if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,";
1876            if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,";
1877            $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
1878            $sql.= " WHERE element_id =".$this->id;
1879            $sql.= " AND ec.fk_c_type_contact=tc.rowid";
1880            $sql.= " AND tc.element='facture'";
1881            if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
1882            if ($source == 'external') $sql.= " AND tc.source = 'external'";
1883            $sql.= " AND tc.active=1";
1884            if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid";
1885            if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp";
1886            if ($statut >= 0) $sql.= " AND statut = '$statut'";
1887            $sql.=" ORDER BY t.name ASC";
1888            
1889            $resql=$this->db->query($sql);
1890            if ($resql)
1891            {
1892                $num=$this->db->num_rows($resql);
1893                $i=0;
1894                while ($i < $num)
1895                {
1896                    $obj = $this->db->fetch_object($resql);
1897                    
1898                    $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
1899                    $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle);
1900                    $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom,
1901                                   'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut);
1902                    $i++;
1903                }
1904                return $tab;
1905            }
1906            else
1907            {
1908                $this->error=$this->db->error();
1909                dolibarr_print_error($this->db);
1910                return -1;
1911            }
1912        }
1913    
1914             /**
1915         *    \brief      Le détail d'un contact
1916         *    \param      rowid      L'identifiant du contact
1917         *    \return     object     L'objet construit par DoliDb.fetch_object
1918         */
1919            function detail_contact($rowid)
1920        {
1921            $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1922            $sql.= " tc.code, tc.libelle, s.fk_soc";
1923            $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, ";
1924            $sql.= " ".MAIN_DB_PREFIX."socpeople as s";
1925            $sql.= " WHERE ec.rowid =".$rowid;
1926            $sql.= " AND ec.fk_socpeople=s.idp";
1927            $sql.= " AND ec.fk_c_type_contact=tc.rowid";
1928            $sql.= " AND tc.element = 'facture'";
1929    
1930            $resql=$this->db->query($sql);
1931            if ($resql)
1932            {
1933                $obj = $this->db->fetch_object($resql);
1934                return $obj;
1935            }
1936            else
1937            {
1938                $this->error=$this->db->error();
1939                dolibarr_print_error($this->db);
1940                return null;
1941            }
1942        }  
1943    
1944        /**
1945         *      \brief      La liste des valeurs possibles de type de contacts
1946         *      \param      source      internal ou external
1947         *      \return     array       La liste des natures
1948         */
1949            function liste_type_contact($source)
1950        {
1951            global $langs;
1952            
1953                    $element='facture';
1954                    
1955                    $tab = array();
1956                    
1957            $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
1958            $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
1959            $sql.= " WHERE element='".$element."'";
1960            $sql.= " AND source='".$source."'";
1961            $sql.= " ORDER by tc.code";
1962    
1963            $resql=$this->db->query($sql);
1964            if ($resql)
1965            {
1966                $num=$this->db->num_rows($resql);
1967                $i=0;
1968                while ($i < $num)
1969                {
1970                    $obj = $this->db->fetch_object($resql);
1971    
1972                    $transkey="TypeContact_".$element."_".$source."_".$obj->code;
1973                    $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle);
1974                    $tab[$obj->rowid]=$libelle_type;
1975                    $i++;
1976                }
1977                return $tab;
1978            }
1979            else
1980            {
1981                $this->error=$this->db->error();
1982    //            dolibarr_print_error($this->db);
1983                return null;
1984            }
1985        }                                  
1986        
1987  }  }
1988    
1989    
# Line 1809  class FactureLigne Line 2033  class FactureLigne
2033                          $this->produit_id     = $objp->fk_product;                          $this->produit_id     = $objp->fk_product;
2034                          $this->date_start     = $objp->date_start;                          $this->date_start     = $objp->date_start;
2035                          $this->date_end       = $objp->date_end;                          $this->date_end       = $objp->date_end;
2036                          $i++;  //                      $i++; //modification suite à la tache 4984
2037                          $this->db->free($result);                          $this->db->free($result);
2038                  }                  }
2039                  else                  else

Legend:
Removed from v.1.133  
changed lines
  Added in v.1.134

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