/[dolibarr]/dolibarr/htdocs/telephonie/script/tools/viper.hook.php
ViewVC logotype

Diff of /dolibarr/htdocs/telephonie/script/tools/viper.hook.php

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

revision 1.2 by rodolphe, Fri Dec 2 15:17:03 2005 UTC revision 1.3 by rodolphe, Fri Dec 2 15:33:41 2005 UTC
# Line 28  Line 28 
28    
29  require ("../../../master.inc.php");  require ("../../../master.inc.php");
30    
31  $title = "DEVEL TITLE";  $month = "10";
32  $desc = "Developpements en cours";  $year = "2005";
 $userlid = 1;  
33    
 if ($db->begin())  
 {  
   $result = -1;  
34    
35    $sqls  = "SELECT l.rowid,l.ligne,l.fk_commercial_suiv";
36    $sqls .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
37    $sqls .= " WHERE l.rowid =f.fk_ligne AND f.cout_vente < f.fourn_montant";
38    $sqls .= " AND f.date ='".$year."-".$month."-01'";
39    
40    $sql = "SELECT vtiger_id from ".MAIN_DB_PREFIX."vtiger_users";  $resqls = $db->query($sqls);  
41    $sql .= " WHERE fk_user =".$userlid.";";  if ( $resqls )
42        $result = 1;  {
43        $resql = $db->query($sql);      while ($obj = $db->fetch_object($resqls))
44        if ( $resql )      {
45          {        $title = "Marge négative ligne ".$obj->ligne." pour $month-$year";
46            if ($row = $db->fetch_row($resql))        $desc = "La facturation de la ligne ".$obj->ligne. " présente une marge négative en $month/$year";
47              {        $userlid = $obj->fk_commercial_suiv;
48                $user_id = $row[0];  
49                $result = 0;        if ($db->begin())
50            {
51              $result = -1;
52              
53              $sql = "SELECT vtiger_id from ".MAIN_DB_PREFIX."vtiger_users";
54              $sql .= " WHERE fk_user =".$userlid.";";
55              $result = 1;
56              $resql = $db->query($sql);  
57              if ( $resql )
58                {
59                  if ($row = $db->fetch_row($resql))
60                    {
61                      $user_id = $row[0];
62                      $result = 0;
63                    }
64                  else
65                    {
66                      print "Error user id missing\n";
67                    }
68              }              }
69            else            else
70              {              {
71                print "Error user id missing\n";                print "Error 7\n";
             }  
         }  
       else  
         {  
           print "Error 7\n";  
         }  
   
   
   if ($result == 0)  
     {  
       $sql = "UPDATE vtiger.crmentity_seq set id=LAST_INSERT_ID(id+1)";  
       $resql = $db->query($sql);  
       if ( $resql )  
         {  
           $result = 0;  
         }  
       else  
         {  
           print "Error 1\n";  
         }  
     }  
   
   if ($result == 0)  
     {  
       $sql = "SELECT user_name from vtiger.users where id =".$user_id.";";  
       $result = 1;  
       $resql = $db->query($sql);    
       if ( $resql )  
         {  
           if ($row = $db->fetch_row($resql))  
             {  
               $username = $row[0];  
               $result = 0;  
72              }              }
73            else            
74              if ($result == 0)
75              {              {
76                print "Error 4\n";                $sql = "UPDATE vtiger.crmentity_seq set id=LAST_INSERT_ID(id+1)";
77                  $resql = $db->query($sql);
78                  if ( $resql )
79                    {
80                      $result = 0;
81                    }
82                  else
83                    {
84                      print "Error 1\n";
85                    }
86                }
87              
88              if ($result == 0)
89                {
90                  $sql = "SELECT user_name from vtiger.users where id =".$user_id.";";
91                  $result = 1;
92                  $resql = $db->query($sql);  
93                  if ( $resql )
94                    {
95                      if ($row = $db->fetch_row($resql))
96                        {
97                          $username = $row[0];
98                          $result = 0;
99                        }
100                      else
101                        {
102                          print "Error 4 Missing id for $user_id\n";
103                        }
104                    }
105                  else
106                    {
107                      print "Error 5\n";
108                    }
109                }
110              
111              
112              if ($result == 0)
113                {
114                  $sql = "SELECT id from vtiger.crmentity_seq;";
115                  $result = 1;
116                  $resql = $db->query($sql);  
117                  $tid = 0;
118                  if ( $resql )
119                    {
120                      if ($row = $db->fetch_row($resql))
121                        {
122                          $tid = $row[0];
123                          $result = 0;
124                        }
125                      else
126                        {
127                          print "Error 2\n";
128                        }
129                    }
130                  else
131                    {
132                      print "Error 3\n";
133                    }
134                }
135              
136              if ($result == 0 && $tid > 0)
137                {
138                  $sql = "INSERT INTO vtiger.troubletickets (ticketid, parent_id, priority, product_id, severity, status, category, update_log, title, description, solution) values ";
139                  $sql .= " (".$tid.", '', 'High', '', 'Major', 'Open', 'Big Problem','";
140                  $sql .= strftime("%E %d %B %Y %H:%M:%S", time())." by dolibarr--//--Ticket created. Assigned to $username--//--'";
141                  $sql .= ", '".$title."', '".$desc."', '')";
142                  
143                  $result = 1;
144                  $resql = $db->query($sql);
145                  if ( $resql )
146                    {
147                      $result = 0;
148                    }
149                  else
150                    {
151                      print $db->error()."\n";
152                      print "$sql\n";
153                    }
154                }
155              
156              
157              
158              if ($result == 0 && $tid > 0)
159                {
160                  $sql = "INSERT INTO vtiger.crmentity ";
161                  $sql .= " (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) ";
162                  $sql .= " VALUES ('".$tid."','$user_id','$user_id','HelpDesk','".$desc."',now(),now())";
163                  
164                  $resql = $db->query($sql);
165                  $result = 1;
166                  if ( $resql )
167                    {
168                      $result = 0;
169                    }
170                  else
171                    {
172                      print $db->error()."\n";
173                      print "$sql\n";
174                    }
175                }
176              
177              if ($result == 0 && $tid > 0)
178                {
179                  $sql = "INSERT INTO vtiger.ticketcf (ticketid) values ($tid)";
180                  $resql = $db->query($sql);
181                  $result = 1;
182                  if ( $resql )
183                    {
184                      $result = 0;
185                    }
186                }
187              
188              if ($result == 0 )
189                {
190                  $sql = "INSERT INTO vtiger.ticketcomments (ticketid, comments) values ($tid, '')";
191                  $resql = $db->query($sql);
192                  $result = 1;
193                  if ( $resql )
194                    {
195                      $result = 0;
196                    }
197                }
198              
199              if ($result == 0 )
200                {
201                  $sql = "DELETE from vtiger.tracker WHERE user_id='$user_id' and item_id='$tid'";
202                  $resql = $db->query($sql);
203                  $result = 1;
204                  if ( $resql )
205                    {
206                      $result = 0;
207                    }
208                }
209              
210              if ($result == 0 )
211                {
212                  $sql = "INSERT INTO vtiger.tracker ";
213                  $sql .= " (user_id, module_name, item_id, item_summary) values ";
214                  $sql .= " ('".$user_id."', 'HelpDesk', '".$tid."', 'Test pour dev')";
215                  
216                  $resql = $db->query($sql);
217                  $result = 1;
218                  if ( $resql )
219                    {
220                      $result = 0;
221                    }
222              }              }
223          }            
224        else            if ($result == 0)
         {  
           print "Error 5\n";  
         }  
     }  
   
   
   if ($result == 0)  
     {  
       $sql = "SELECT id from vtiger.crmentity_seq;";  
       $result = 1;  
       $resql = $db->query($sql);    
       $tid = 0;  
       if ( $resql )  
         {  
           if ($row = $db->fetch_row($resql))  
225              {              {
226                $tid = $row[0];                $db->commit();
227                $result = 0;                print "COMMIT $tid\n";
228              }              }
229            else            else
230              {              {
231                print "Error 2\n";                $db->rollback();
232                  print "ROLLBACK $tid\n";
233              }              }
234          }            
       else  
         {  
           print "Error 3\n";  
         }  
     }  
   
   if ($result == 0 && $tid > 0)  
     {  
       $sql = "INSERT INTO vtiger.troubletickets (ticketid, parent_id, priority, product_id, severity, status, category, update_log, title, description, solution) values ";  
       $sql .= " (".$tid.", '', 'High', '', 'Major', 'Open', 'Big Problem','";  
       $sql .= strftime("%E %d %B %Y %H:%M:%S", time())." by dolibarr--//--Ticket created. Assigned to $username--//--'";  
       $sql .= ", '".$title."', '".$desc."', '')";  
         
       $result = 1;  
       $resql = $db->query($sql);  
       if ( $resql )  
         {  
           $result = 0;  
         }  
       else  
         {  
           print $db->error()."\n";  
           print "$sql\n";  
         }  
     }  
   
   
   
   if ($result == 0 && $tid > 0)  
     {  
       $sql = "INSERT INTO vtiger.crmentity ";  
       $sql .= " (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) ";  
       $sql .= " VALUES ('".$tid."','$user_id','$user_id','HelpDesk','".$desc."',now(),now())";  
         
       $resql = $db->query($sql);  
       $result = 1;  
       if ( $resql )  
         {  
           $result = 0;  
         }  
       else  
         {  
           print $db->error()."\n";  
           print "$sql\n";  
         }  
     }  
     
   if ($result == 0 && $tid > 0)  
     {  
       $sql = "INSERT INTO vtiger.ticketcf (ticketid) values ($tid)";  
       $resql = $db->query($sql);  
       $result = 1;  
       if ( $resql )  
         {  
           $result = 0;  
         }  
     }  
   
   if ($result == 0 )  
     {  
       $sql = "INSERT INTO vtiger.ticketcomments (ticketid, comments) values ($tid, '')";  
       $resql = $db->query($sql);  
       $result = 1;  
       if ( $resql )  
         {  
           $result = 0;  
         }  
     }  
     
   if ($result == 0 )  
     {  
       $sql = "DELETE from vtiger.tracker WHERE user_id='$user_id' and item_id='$tid'";  
       $resql = $db->query($sql);  
       $result = 1;  
       if ( $resql )  
         {  
           $result = 0;  
         }  
     }  
   
   if ($result == 0 )  
     {  
       $sql = "INSERT INTO vtiger.tracker ";  
       $sql .= " (user_id, module_name, item_id, item_summary) values ";  
       $sql .= " ('".$user_id."', 'HelpDesk', '".$tid."', 'Test pour dev')";  
         
       $resql = $db->query($sql);  
       $result = 1;  
       if ( $resql )  
         {  
           $result = 0;  
235          }          }
236      }      }
   
   if ($result == 0)  
     {  
       $db->commit();  
       print "COMMIT $tid\n";  
     }  
   else  
     {  
       $db->rollback();  
       print "ROLLBACK $tid\n";  
     }  
   
237  }  }
238    
239    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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