/[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.91 by rodolphe, Fri Sep 2 09:05:26 2005 UTC revision 1.92 by eldy, Fri Sep 2 21:25:43 2005 UTC
# Line 411  class Societe { Line 411  class Societe {
411    
412    }    }
413        
414    /**      /**
415     *    \brief      Charge depuis la base l'objet societe       *    \brief      Charge depuis la base l'objet societe
416     *    \param      socid       id de la société à charger en mémoire       *    \param      socid       Id de la société à charger en mémoire
417     *    \return     int         >0 si ok, <0 si erreur       *    \param      user        Objet de l'utilisateur
418     */       *    \return     int         >0 si ok, <0 si erreur
419                 */
420    function fetch($socid, $user=0)      function fetch($socid, $user=0)
421    {      {
422      global $langs;          global $langs;
423            
424      /* Lecture des permissions */          /* Lecture des permissions */
425      if ($user <> 0)          if ($user <> 0)
426        {          {
427          $sql = "SELECT p.pread, p.pwrite, p.pperms";              $sql = "SELECT p.pread, p.pwrite, p.pperms";
428          $sql .= " FROM ".MAIN_DB_PREFIX."societe_perms as p";              $sql .= " FROM ".MAIN_DB_PREFIX."societe_perms as p";
429          $sql .= " WHERE p.fk_user = '".$user->id."'";              $sql .= " WHERE p.fk_user = '".$user->id."'";
430          $sql .= " AND p.fk_soc = '".$socid."';";              $sql .= " AND p.fk_soc = '".$socid."';";
431                
432          $resql=$this->db->query($sql);              $resql=$this->db->query($sql);
433                
434          if ($resql)              if ($resql)
435            {              {
436              if ($row = $this->db->fetch_row($resql))                  if ($row = $this->db->fetch_row($resql))
437                {                  {
438                  $this->perm_read  = $row[0];                      $this->perm_read  = $row[0];
439                  $this->perm_write = $row[1];                      $this->perm_write = $row[1];
440                  $this->perm_perms = $row[2];                      $this->perm_perms = $row[2];
441                }                  }
442            }              }
443        }          }
444        
445      $sql = "SELECT s.idp, s.nom, s.address,".$this->db->pdate("s.datec")." as dc, prefix_comm";          $sql = "SELECT s.idp, s.nom, s.address,".$this->db->pdate("s.datec")." as dc, prefix_comm";
446      $sql .= ",". $this->db->pdate("s.tms")." as date_update";          $sql .= ",". $this->db->pdate("s.tms")." as date_update";
447      $sql .= ", s.tel, s.fax, s.url,s.cp,s.ville, s.note, s.siren, client, fournisseur";          $sql .= ", s.tel, s.fax, s.url,s.cp,s.ville, s.note, s.siren, client, fournisseur";
448      $sql .= ", s.siret, s.capital, s.ape, s.tva_intra, s.rubrique";          $sql .= ", s.siret, s.capital, s.ape, s.tva_intra, s.rubrique";
449      $sql .= ", s.fk_typent as typent_id";          $sql .= ", s.fk_typent as typent_id";
450      $sql .= ", s.fk_effectif as effectif_id, e.libelle as effectif";          $sql .= ", s.fk_effectif as effectif_id, e.libelle as effectif";
451      $sql .= ", s.fk_forme_juridique as forme_juridique_code, fj.libelle as forme_juridique";          $sql .= ", s.fk_forme_juridique as forme_juridique_code, fj.libelle as forme_juridique";
452      $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.parent";          $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.parent";
453      $sql .= ", s.fk_departement, s.fk_pays, s.fk_stcomm, s.remise_client";          $sql .= ", s.fk_departement, s.fk_pays, s.fk_stcomm, s.remise_client";
454      $sql .= ", p.code as pays_code, p.libelle as pays";          $sql .= ", p.code as pays_code, p.libelle as pays";
455      $sql .= ", st.libelle as stcomm";          $sql .= ", st.libelle as stcomm";
456      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";          $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
457      $sql .= ", ".MAIN_DB_PREFIX."c_effectif as e";          $sql .= ", ".MAIN_DB_PREFIX."c_effectif as e";
458      $sql .= ", ".MAIN_DB_PREFIX."c_pays as p";          $sql .= ", ".MAIN_DB_PREFIX."c_pays as p";
459      $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";          $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
460      $sql .= ", ".MAIN_DB_PREFIX."c_forme_juridique as fj";          $sql .= ", ".MAIN_DB_PREFIX."c_forme_juridique as fj";
461      $sql .= " WHERE s.idp = ".$socid;          $sql .= " WHERE s.idp = ".$socid;
462      $sql .= " AND s.fk_stcomm = st.id";          $sql .= " AND s.fk_stcomm = st.id";
463      $sql .= " AND s.fk_effectif = e.id";          $sql .= " AND s.fk_effectif = e.id";
464      $sql .= " AND s.fk_pays = p.rowid";          $sql .= " AND s.fk_pays = p.rowid";
465      $sql .= " AND s.fk_forme_juridique = fj.code";          $sql .= " AND s.fk_forme_juridique = fj.code";
466        
467      $resql=$this->db->query($sql);          $resql=$this->db->query($sql);
468        
469      if ($resql)          if ($resql)
470        {          {
471          if ($this->db->num_rows($resql))              if ($this->db->num_rows($resql))
472            {              {
473              $obj = $this->db->fetch_object($resql);                  $obj = $this->db->fetch_object($resql);
474        
475              $this->id = $obj->idp;                  $this->id = $obj->idp;
476        
477              $this->date_update = $obj->date_update;                  $this->date_update = $obj->date_update;
478        
479              $this->nom = stripslashes($obj->nom);                  $this->nom = stripslashes($obj->nom);
480              $this->adresse =  stripslashes($obj->address);                  $this->adresse =  stripslashes($obj->address);
481              $this->cp = $obj->cp;                  $this->cp = $obj->cp;
482              $this->ville =  stripslashes($obj->ville);                  $this->ville =  stripslashes($obj->ville);
483        
484              $this->adresse_full =  stripslashes($obj->address) . "\n". $obj->cp . " ". stripslashes($obj->ville);                  $this->adresse_full =  stripslashes($obj->address) . "\n". $obj->cp . " ". stripslashes($obj->ville);
485        
486              $this->departement_id = $obj->fk_departement;                  $this->departement_id = $obj->fk_departement;
487              $this->pays_id = $obj->fk_pays;                  $this->pays_id = $obj->fk_pays;
488              $this->pays_code = $obj->fk_pays?$obj->pays_code:'';                  $this->pays_code = $obj->fk_pays?$obj->pays_code:'';
489              $this->pays = $obj->fk_pays?$obj->pays:'';                  $this->pays = $obj->fk_pays?$obj->pays:'';
490        
491              $transcode=$langs->trans("StatusProspect".$obj->fk_stcomm);                  $transcode=$langs->trans("StatusProspect".$obj->fk_stcomm);
492              $libelle=($transcode!="StatusProspect".$obj->fk_stcomm?$transcode:$obj->stcomm);                  $libelle=($transcode!="StatusProspect".$obj->fk_stcomm?$transcode:$obj->stcomm);
493              $this->stcomm_id = $obj->fk_stcomm;     // id statut commercial                  $this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
494              $this->statut_commercial = $libelle;    // libelle statut commercial                  $this->statut_commercial = $libelle;    // libelle statut commercial
495        
496              $this->url = $obj->url;                  $this->url = $obj->url;
497              $this->tel = $obj->tel;                  $this->tel = $obj->tel;
498              $this->fax = $obj->fax;                  $this->fax = $obj->fax;
499                      
500              $this->parent    = $obj->parent;                  $this->parent    = $obj->parent;
501        
502              $this->siren     = $obj->siren;                  $this->siren     = $obj->siren;
503              $this->siret     = $obj->siret;                  $this->siret     = $obj->siret;
504              $this->ape       = $obj->ape;                  $this->ape       = $obj->ape;
505              $this->capital   = $obj->capital;                  $this->capital   = $obj->capital;
506        
507              $this->code_client = $obj->code_client;                  $this->code_client = $obj->code_client;
508              $this->code_fournisseur = $obj->code_fournisseur;                  $this->code_fournisseur = $obj->code_fournisseur;
509        
510              if (! $this->code_client && $this->mod_codeclient->code_modifiable_null == 1)                  if (! $this->code_client && $this->mod_codeclient->code_modifiable_null == 1)
511                {                  {
512                  $this->codeclient_modifiable = 1;                      $this->codeclient_modifiable = 1;
513                }                  }
514        
515              if (! $this->code_fournisseur && $this->mod_codefournisseur->code_modifiable_null == 1)                  if (! $this->code_fournisseur && $this->mod_codefournisseur->code_modifiable_null == 1)
516                {                  {
517                  $this->codefournisseur_modifiable = 1;                      $this->codefournisseur_modifiable = 1;
518                }                  }
519        
520              $this->code_compta = $obj->code_compta;                  $this->code_compta = $obj->code_compta;
521              $this->code_compta_fournisseur = $obj->code_compta_fournisseur;                  $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
522        
523              $this->tva_intra      = $obj->tva_intra;                  $this->tva_intra      = $obj->tva_intra;
524              $this->tva_intra_code = substr($obj->tva_intra,0,2);                  $this->tva_intra_code = substr($obj->tva_intra,0,2);
525              $this->tva_intra_num  = substr($obj->tva_intra,2);                  $this->tva_intra_num  = substr($obj->tva_intra,2);
526        
527              $this->typent_id      = $obj->typent_id;                  $this->typent_id      = $obj->typent_id;
528              //$this->typent         = $obj->fk_typent?$obj->typeent:'';                  //$this->typent         = $obj->fk_typent?$obj->typeent:'';
529        
530              $this->effectif_id    = $obj->effectif_id;                  $this->effectif_id    = $obj->effectif_id;
531              $this->effectif       = $obj->effectif_id?$obj->effectif:'';                  $this->effectif       = $obj->effectif_id?$obj->effectif:'';
532        
533              $this->forme_juridique_code= $obj->forme_juridique_code;                  $this->forme_juridique_code= $obj->forme_juridique_code;
534              $this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';                  $this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
535        
536              $this->prefix_comm = $obj->prefix_comm;                  $this->prefix_comm = $obj->prefix_comm;
537        
538              $this->remise_client = $obj->remise_client;                  $this->remise_client = $obj->remise_client;
539                      
540              $this->client      = $obj->client;                  $this->client      = $obj->client;
541              $this->fournisseur = $obj->fournisseur;                  $this->fournisseur = $obj->fournisseur;
542        
543              if ($this->client == 1)                  if ($this->client == 1)
544                {                  {
545                  $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$this->id.'">'.$obj->nom.'</a>';                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$this->id.'">'.$obj->nom.'</a>';
546                }                  }
547              elseif($this->client == 2)                  elseif($this->client == 2)
548                {                  {
549                  $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$this->id.'">'.$obj->nom.'</a>';                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$this->id.'">'.$obj->nom.'</a>';
550                }                  }
551              else                  else
552                {                  {
553                  $this->nom_url = '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$this->id.'">'.$obj->nom.'</a>';                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$this->id.'">'.$obj->nom.'</a>';
554                }                  }
555        
556              $this->rubrique = $obj->rubrique;                          $this->rubrique = $obj->rubrique;
557              $this->note = $obj->note;                  $this->note = $obj->note;
558        
559              $result = 1;                                $result = 1;
560            }              }
561          else              else
562            {              {
563              dolibarr_syslog("Erreur Societe::Fetch aucune societe avec id=".$this->id);                  dolibarr_syslog("Erreur Societe::Fetch aucune societe avec id=".$this->id);
564              $result = -2;                  $result = -2;
565            }              }
566        
567          $this->db->free($resql);              $this->db->free($resql);
568        }          }
569      else          else
570        {          {
571          dolibarr_syslog("Erreur Societe::Fetch echec sql=$sql");              dolibarr_syslog("Erreur Societe::Fetch echec sql=$sql");
572          dolibarr_syslog("Erreur Societe::Fetch ".$this->db->error());              dolibarr_syslog("Erreur Societe::Fetch ".$this->db->error());
573          $result = -3;              $result = -3;
574        }          }
575        
576      return $result;          return $result;
577    }      }
578    
579    /**    /**
580     *    \brief      Suppression d'une societe de la base avec ses dépendances (contacts, rib...)     *    \brief      Suppression d'une societe de la base avec ses dépendances (contacts, rib...)
581     *    \param      id      id de la societe à supprimer     *    \param      id      id de la societe à supprimer
582     */     */
     
583    function delete($id)    function delete($id)
584    {    {
585      dolibarr_syslog("Societe::Delete");      dolibarr_syslog("Societe::Delete");

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.92

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