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

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

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

revision 1.93 by eldy, Sun Sep 4 13:11:47 2005 UTC revision 1.94 by eldy, Wed Sep 7 20:27:32 2005 UTC
# Line 1356  class Societe { Line 1356  class Societe {
1356          }          }
1357      }      }
1358    
1359    /**      /**
1360     *    \brief  Verifie la validite du siren       *      \brief      Verifie la validite d'un identifiant professionnel en
1361     */       *                  fonction du pays de la societe (siren, siret, ...)
1362    function check_siren()       *      \param      idprof          1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
1363    {       *      \param      soc             Objet societe
1364      if (strlen($this->siren) == 9)       *      \return     int             <0 si ko, >0 si ok
1365        {       */
1366          $sum = 0;      function id_prof_check($idprof,$soc)
1367        {
1368          for ($i = 0 ; $i < 10 ; $i = $i+2)          $ok=1;
1369            {          
1370              $sum = $sum + substr($this->siren, (8 - $i), 1);          // Verifie SIREN si pays FR
1371            }          if ($idprof == 1 && $soc->pays_code == 'FR')
1372            {
1373          for ($i = 1 ; $i < 9 ; $i = $i+2)              $chaine=trim($this->siren);
1374            {              $chaine=eregi_replace(' ','',$chaine);
1375              $ps = 2 * substr($this->siren, (8 - $i), 1);              
1376                if (strlen($chaine) != 9) return -1;
1377              if ($ps > 9)  
1378                {              $sum = 0;
1379                  $ps = substr($ps, 0,1) + substr($ps, 1 ,1);      
1380                }              for ($i = 0 ; $i < 10 ; $i = $i+2)
1381              $sum = $sum + $ps;              {
1382            }                  $sum = $sum + substr($this->siren, (8 - $i), 1);
1383                }
1384          if (substr($sum, -1) == 0)      
1385            {              for ($i = 1 ; $i < 9 ; $i = $i+2)
1386              return 0;              {
1387            }                  $ps = 2 * substr($this->siren, (8 - $i), 1);
1388          else      
1389            {                  if ($ps > 9)
1390              return -1;                  {
1391            }                      $ps = substr($ps, 0,1) + substr($ps, 1 ,1);
1392        }                  }
1393      else                  $sum = $sum + $ps;
1394        {              }
1395          return -2;          
1396        }              if (substr($sum, -1) != 0) return -1;
1397    }          }
1398    
1399    /**          // Verifie SIRET si pays FR
1400     *    \brief      Indique si la société a des projets          if ($idprof == 2 && $soc->pays_code == 'FR')
1401     *    \return     bool           true si la société a des projets, false sinon          {
1402     */              $chaine=trim($this->siret);
1403    function has_projects()              $chaine=eregi_replace(' ','',$chaine);
1404    {              
1405      $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;              if (strlen($chaine) != 14) return -1;
1406      $resql = $this->db->query($sql);          }
1407      if ($resql)  
1408        {          return $ok;
1409          $nump = $this->db->num_rows($resql);      }
1410          $obj = $this->db->fetch_object();  
1411          $count = $obj->numproj;      /**
1412        }       *      \brief      Renvoi url de vérification d'un identifiant professionnal
1413      else       *      \param      idprof          1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
1414        {       *      \param      soc             Objet societe
1415          $count = 0;       *      \return     string          url ou chaine vide si aucune url connue
1416          print $this->db->error();       */
1417        }      function id_prof_url($idprof,$soc)
1418      $this->db->free($resql);      {
1419      return ($count > 0);          global $langs;
1420    }  
1421              $url='';        
1422            if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren;
1423            if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';
1424                
1425            if ($url) return '<a target="_blank" href="'.$url.'">['.$langs->trans("Check").']</a>';
1426            return '';
1427        }
1428    
1429    function AddPerms($user_id, $read, $write, $perms)      /**
1430    {       *      \brief      Indique si la société a des projets
1431      $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms";       *      \return     bool       true si la société a des projets, false sinon
1432      $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) ";       */
1433      $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");";      function has_projects()
1434                {
1435      $resql=$this->db->query($sql);          $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
1436                    $resql = $this->db->query($sql);
1437      if ($resql)          if ($resql)
1438        {          {
1439                $nump = $this->db->num_rows($resql);
1440                $obj = $this->db->fetch_object();
1441                $count = $obj->numproj;
1442            }
1443            else
1444            {
1445                $count = 0;
1446                print $this->db->error();
1447            }
1448            $this->db->free($resql);
1449            return ($count > 0);
1450        }
1451      
1452    
1453        }      function AddPerms($user_id, $read, $write, $perms)
1454    }      {
1455            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms";
1456            $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) ";
1457            $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");";
1458        
1459            $resql=$this->db->query($sql);
1460            if ($resql)
1461            {
1462        
1463            }
1464        }
1465        
1466  }  }
1467    
1468  ?>  ?>

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.94

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