[ 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/ -> correction-tarifs-clients.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: correction-tarifs-clients.php,v 1.2 2005/07/27 15:31:34 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/tools/correction-tarifs-clients.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  require_once  (DOL_DOCUMENT_ROOT."/societe.class.php");
  32  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
  33  require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");
  34  require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php");
  35  require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php");
  36  
  37  $tarifs = array(1290,1291,1292);
  38  $corrections = array();
  39  
  40  $corrections[1290] = array();
  41  $corrections[1291] = array();
  42  $corrections[1292] = array();
  43  
  44  $clients = array();
  45  
  46  $sql = "SELECT fk_client FROM ".MAIN_DB_PREFIX."telephonie_tarif_client";
  47  $sql .= " WHERE fk_tarif = 1289";
  48  
  49  $resql = $db->query($sql);
  50    
  51  if ( $resql )
  52  {
  53    $num = $db->num_rows($resql);
  54    $i = 0;
  55  
  56    print "$num clients trouvés\n";
  57  
  58    while ($i < $num)
  59      {
  60        $row = $db->fetch_row($resql);
  61  
  62        array_push($clients, $row[0]);
  63        $i++;
  64      }
  65    $db->free($resql);
  66  }
  67  else
  68  {
  69    $error++;
  70  }
  71  
  72  
  73  foreach ($tarifs as $tarif)
  74  {
  75    foreach ($clients as $client)
  76      {
  77        $sql = "SELECT fk_client FROM ".MAIN_DB_PREFIX."telephonie_tarif_client";
  78        $sql .= " WHERE fk_client = ".$client;
  79        $sql .= " AND fk_tarif = ".$tarif;
  80    
  81        $resql = $db->query($sql);
  82    
  83        if ( $resql )
  84      {
  85        $num = $db->num_rows($resql);
  86  
  87        if ($num == 0)
  88          {
  89            array_push($corrections[$tarif], $client);
  90  
  91            correct_tarif($db, $client, $tarif);
  92  
  93          }
  94  
  95        $db->free($resql);
  96      }
  97        else
  98      {
  99        $error++;
 100      } 
 101      }
 102  }
 103  
 104  
 105  foreach ($tarifs as $tarif)
 106  {
 107    print "Tarif $tarif : ".sizeof($corrections[$tarif])."\n";
 108  }
 109  
 110  function correct_tarif($db, $client, $tarif)
 111  {
 112    $error = 0;
 113  
 114    $sql = "SELECT temporel, fixe FROM ".MAIN_DB_PREFIX."telephonie_tarif_client";
 115    $sql .= " WHERE fk_tarif = 1289";
 116    $sql .= " AND fk_client = $client";
 117    
 118    $resql = $db->query($sql);
 119  
 120    if ($resql)
 121      {
 122        $row = $db->fetch_row($resql);
 123  
 124        $temporel = $row[0];
 125        $fixe = $row[1];
 126      }
 127    else
 128      {
 129        print $db->error();
 130        $error++;
 131      }
 132  
 133    $db->begin();
 134    
 135    $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client";
 136    $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES ";
 137    $sql .= " (".$tarif.",".$client.",'".$temporel."','".$fixe."',1)";
 138    
 139    if (! $db->query($sql) )
 140      {
 141        $error++;
 142        print $db->error();
 143      }
 144    
 145    $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log";
 146    $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES ";
 147    $sql .= " (".$tarif.",".$client.",'".$temporel."','".$fixe."',1,now())";
 148    
 149    if (! $db->query($sql) )
 150      {
 151        $error++;
 152        print $db->error();
 153      }
 154    
 155    if ( $error == 0 )
 156      {
 157        $db->commit();
 158      }
 159    else
 160      {
 161        $db->rollback();
 162        print $db->error();
 163      }     
 164  }
 165  
 166  
 167  $db->close();
 168  ?>


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