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

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

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

revision 1.47 by eldy, Sat Sep 17 02:06:06 2005 UTC revision 1.48 by eldy, Sat Sep 17 16:58:58 2005 UTC
# Line 420  class Contrat Line 420  class Contrat
420          $this->db->begin();          $this->db->begin();
421    
422          // Insère contrat          // Insère contrat
423          $sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, fk_commercial_signature, fk_commercial_suivi, date_contrat)";          $sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat";
424    //        $sql.= ", fk_commercial_signature, fk_commercial_suivi";
425            $sql.= ")";
426          $sql.= " VALUES (now(),".$this->soc_id.",".$user->id;          $sql.= " VALUES (now(),".$this->soc_id.",".$user->id;
427          $sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");          $sql.= ",".$this->db->idate($this->date_contrat);
428          $sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");  //        $sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");
429          $sql.= ",".$this->db->idate($this->date_contrat) .")";  //        $sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");
430            $sql.= ")";
431          $resql=$this->db->query($sql);          $resql=$this->db->query($sql);
432          if ($resql)          if ($resql)
433          {          {
434                $error=0;
435                
436              $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");              $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");
437            
438              // Appel des triggers              // Insère contacts commerciaux ('SALESREPSIGN','contrat')
439              include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");              $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal');
440              $interface=new Interfaces($this->db);              if ($result < 0) $error++;
441              $interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);              
442              // Fin appel triggers              // Insère contacts commerciaux ('SALESREPFOLL','contrat')
443                $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal');
444                if ($result < 0) $error++;
445    
446                if (! $error)
447                {
448                    // Appel des triggers
449                    include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
450                    $interface=new Interfaces($this->db);
451                    $interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);
452                    // Fin appel triggers
453            
454                    $this->db->commit();
455            
456              $this->db->commit();                  return $this->id;
457                }
458                else
459                {
460                    $this->db->rollback();
461    
462              return $this->id;                  return -1;
463                }
464          }          }
465          else          else
466          {          {
# Line 905  class Contrat Line 927  class Contrat
927      /* gestion des contacts d'un contrat */      /* gestion des contacts d'un contrat */
928    
929          /**          /**
          *  
930           *      \brief      Ajoute un contact associé au contrat           *      \brief      Ajoute un contact associé au contrat
931       *      \param      fk_socpeople    Id du contact a ajouter.       *      \param      fk_socpeople        Id du contact a ajouter.
932       *      \param      nature          description du contact       *      \param      type_contact        Type de contact
933       *      \return     int             <0 si erreur, >0 si ok       *      \param      source              extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user)
934       */       *      \return     int                 <0 si erreur, >0 si ok
935           function add_contact($fk_socpeople, $nature)       */
936           {          function add_contact($fk_socpeople, $type_contact, $source='extern')
937                    {
938          if ($fk_socpeople <= 0          dolibarr_syslog("Contrat::add_contact $fk_socpeople, $type_contact, $source");
939                  || $this->societe->contact_get_email($fk_socpeople) == "" )  
940          {          if ($fk_socpeople <= 0) return -1;
941                          // le contact n'existe pas ou est invalide  
942                          return -1;          // \todo si type_contact = texte, aller chercher code dans table llx_c_type_contact
943          }          if ($type_contact == 'SALESREPSIGN') $type_contact=11;
944            if ($type_contact == 'SALESREPFOLL') $type_contact=12;
945                    
946          $lNature = addslashes(trim($nature));          $datecreate = time();
         $datecreate = mktime();  
947                    
948          // Insertion dans la base          // Insertion dans la base
949          $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";          $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
950          $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";          $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
951          $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;          $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
952                  $sql.= $this->db->idate(time());                  $sql.= $this->db->idate($datecreate);
953                  $sql.= ", 4, '". $lNature . "' ";                  $sql.= ", 4, '". $type_contact . "' ";
954          $sql.= ");";          $sql.= ");";
955                    
956          // Retour          // Retour
# Line 943  class Contrat Line 964  class Contrat
964              $this->error=$this->db->error()." - $sql";              $this->error=$this->db->error()." - $sql";
965              return -1;              return -1;
966          }          }
967           }              }    
968            
969           /**      /**
970           *           *
971           *      \brief      Misea jour du contact associé au contrat           *      \brief      Misea jour du contact associé au contrat
972       *      \param      rowid           La reference du lien contant contact.       *      \param      rowid           La reference du lien contant contact.
# Line 953  class Contrat Line 974  class Contrat
974       *      \param      nature          Description du contact       *      \param      nature          Description du contact
975       *      \return     int             <0 si erreur, >0 si ok       *      \return     int             <0 si erreur, >0 si ok
976       */       */
977           function update_contact($rowid, $statut, $type_contact_id)          function update_contact($rowid, $statut, $type_contact_id)
978           {          {
979          // Insertion dans la base          // Insertion dans la base
980          $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";          $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
981          $sql.= " statut = $statut ,";          $sql.= " statut = $statut ,";
# Line 993  class Contrat Line 1014  class Contrat
1014                                                    
1015      /**      /**
1016       *    \brief      Récupère les lignes de contact du contrat       *    \brief      Récupère les lignes de contact du contrat
1017       *    \param      statut      Statut des lignes detail à récupérer       *    \param      statut        Statut des lignes detail à récupérer
1018       *    \return     array       Tableau des rowid des contacts       *    \param      source        Source du contact external (llx_socpeople) ou internal (llx_user)
1019         *    \return     array         Tableau des rowid des contacts
1020       */       */
1021      function liste_contact($statut=-1)      function liste_contact($statut=-1,$source='external')
1022      {      {
1023            global $langs;
1024            
1025          $tab=array();          $tab=array();
1026            
1027          $sql = "SELECT ec.rowid, tc.code";          $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,";
1028          $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec, ".MAIN_DB_PREFIX."socpeople sp,";          if ($source == 'internal') $sql.=" '-1' as socid,";
1029            if ($source == 'external') $sql.=" t.fk_soc as socid,";
1030            if ($source == 'internal') $sql.=" t.name as nom,";
1031            if ($source == 'external') $sql.=" t.name as nom,";
1032            $sql.= "tc.code, tc.source, tc.libelle";
1033            $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
1034            if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,";
1035            if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,";
1036          $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";          $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
1037          $sql.= " WHERE element_id =".$this->id;          $sql.= " WHERE element_id =".$this->id;
1038          $sql.= " AND ec.fk_c_type_contact=tc.rowid";          $sql.= " AND ec.fk_c_type_contact=tc.rowid";
1039          $sql.= " AND tc.element='contrat'";          $sql.= " AND tc.element='contrat'";
1040            if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
1041            if ($source == 'external') $sql.= " AND tc.source = 'external'";
1042          $sql.= " AND tc.active=1";          $sql.= " AND tc.active=1";
1043          $sql.= " AND ec.fk_socpeople = sp.idp";          if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid";
1044            if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp";
1045          if ($statut >= 0) $sql.= " AND statut = '$statut'";          if ($statut >= 0) $sql.= " AND statut = '$statut'";
1046          $sql.=" order by sp.name asc ;";          $sql.=" ORDER BY t.name ASC";
1047                    
1048          $resql=$this->db->query($sql);          $resql=$this->db->query($sql);
1049          if ($resql)          if ($resql)
# Line 1019  class Contrat Line 1053  class Contrat
1053              while ($i < $num)              while ($i < $num)
1054              {              {
1055                  $obj = $this->db->fetch_object($resql);                  $obj = $this->db->fetch_object($resql);
1056                  $tab[$i]=$obj->rowid;                  
1057                    $libelle_type=($langs->trans("TypeContact".$obj->code)!=$langs->trans("TypeContact".$obj->code) ? $langs->trans("TypeContact".$obj->code) : $obj->libelle);
1058                    $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom,
1059                                   'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut);
1060                  $i++;                  $i++;
1061              }              }
1062              return $tab;              return $tab;
# Line 1027  class Contrat Line 1064  class Contrat
1064          else          else
1065          {          {
1066              $this->error=$this->db->error();              $this->error=$this->db->error();
1067  //            dolibarr_print_error($this->db);              dolibarr_print_error($this->db);
1068              return -1;              return -1;
1069          }          }
1070      }      }
# Line 1063  class Contrat Line 1100  class Contrat
1100      }        }  
1101    
1102      /**      /**
1103       *    \brief      La liste des valeurs possibles de type de contats       *      \brief      La liste des valeurs possibles de type de contacts
1104       *    \return     array   La liste des natures       *      \param      source      internal ou externam
1105         *      \return     array       La liste des natures
1106       */       */
1107          function liste_nature_contact()          function liste_type_contact($source)
1108      {      {
1109                  $tab = array();                  $tab = array();
1110                                    
1111          $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";          $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
1112          $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";          $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
1113          $sql.= " WHERE element='contrat'";          $sql.= " WHERE element='contrat'";
1114            $sql.= " AND source='".$source."'";
1115          $sql.= " ORDER by tc.code";          $sql.= " ORDER by tc.code";
1116    
1117          $resql=$this->db->query($sql);          $resql=$this->db->query($sql);

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

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