[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/telephonie/script/tools/ -> viper.hook.php (source)

   1  <?PHP
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: viper.hook.php,v 1.7 2005/12/06 08:39:21 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/tools/viper.hook.php,v $
  20   *
  21   *
  22   * Ce script se veut plus un squelette pour effectuer des opérations sur la base
  23   * qu'un réel scrip de production.
  24   *
  25   * Recalcul le montant d'une facture lors d'une erreur de tarif
  26   *
  27   */
  28  
  29  require  ("../../../master.inc.php");
  30  
  31  $month = "11";
  32  $year = "2005";
  33  
  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  $resqls = $db->query($sqls);  
  41  if ( $resqls )
  42  {
  43    while ($obj = $db->fetch_object($resqls))
  44      {
  45        $title = "Marge négative ligne ".$obj->ligne." pour $month-$year";
  46        $desc = "La facturation de la ligne ".$obj->ligne. " présente une marge négative en $month/$year";
  47        $userlid = $obj->fk_commercial_suiv;
  48  
  49        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 $userlid in llx_user  \n";
  67          }
  68          }
  69        else
  70          {
  71            print "Error 7\n";
  72          }
  73        
  74        if ($result == 0)
  75          {
  76            $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("%A %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        /*      
 200        if ($result == 0 )
 201          {
 202            $sql = "DELETE from vtiger.tracker WHERE user_id='".$user_id."' and item_id='".$tid".'";
 203            $resql = $db->query($sql);
 204            $result = 1;
 205            if ( $resql )
 206          {
 207            $result = 0;
 208          }
 209          }
 210        
 211        if ($result == 0 )
 212          {
 213            $sql = "INSERT INTO vtiger.tracker ";
 214            $sql .= " (user_id, module_name, item_id, item_summary) values ";
 215            $sql .= " ('".$user_id."', 'HelpDesk', '".$tid."', '".$title."')";
 216            
 217            $resql = $db->query($sql);
 218            $result = 1;
 219            if ( $resql )
 220          {
 221            $result = 0;
 222          }
 223          }
 224        */
 225        if ($result == 0)
 226          {
 227            $db->commit();
 228            print "COMMIT $tid\n";
 229          }
 230        else
 231          {
 232            $db->rollback();
 233            print "ROLLBACK $tid\n";
 234          }
 235        
 236      }
 237      }
 238  }
 239  
 240  


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics