[ 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/ -> facturation-verif.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: facturation-verif.php,v 1.7 2005/11/08 13:42:45 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/facturation-verif.php,v $
  20   *
  21   *
  22   * Script de vérification avant facturation
  23   */
  24  
  25  require  ("../../master.inc.php");
  26  
  27  require_once  (DOL_DOCUMENT_ROOT."/societe.class.php");
  28  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
  29  require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");
  30  require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie.tarif.class.php");
  31  require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php");
  32  
  33  $error = 0;
  34  
  35  $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."telephonie_import_cdr";
  36    
  37  if ( $db->query($sql) )
  38  {
  39    $row = $db->fetch_row();
  40    print $row[0]." lignes de communications\n";
  41  }
  42  
  43  /*******************************************************************************
  44   *
  45   * Verifie la présence des tarifs adequat
  46   *
  47   */
  48  
  49  $tarif_achat = new TelephonieTarif($db, 1, "achat");
  50  $tarif_vente = new TelephonieTarif($db, 1, "vente");
  51  
  52  $sql = "SELECT distinct(num) FROM ".MAIN_DB_PREFIX."telephonie_import_cdr";
  53  
  54  $resql = $db->query($sql);
  55    
  56  if ( $resql )
  57  {
  58    $nums = $db->num_rows($resql);
  59  
  60    $i = 0;
  61  
  62    while($i < $nums)
  63      {
  64        $row = $db->fetch_row($resql);
  65  
  66        $numero = $row[0];
  67  
  68        /* Reformatage du numéro */
  69  
  70        if (substr($numero,0,2) == '00') /* International */
  71      {
  72      }     
  73        elseif (substr($numero,0,2) == '06') /* Telephones Mobiles */
  74      {    
  75        $numero = "0033".substr($numero,1);
  76      }
  77        elseif (substr($numero,0,4) == substr($objp->client,0,4) ) /* Tarif Local */
  78      {
  79        $numero = "0033999".substr($numero, 1);
  80      }
  81        else
  82      {
  83        $numero = "0033".substr($numero, 1);
  84      }      
  85  
  86        /* Recherche du tarif */
  87  
  88        /* Numéros spéciaux */
  89        if (substr($numero,4,1) == 8)
  90      {
  91  
  92      }
  93        else
  94      {
  95        if (! $tarif_achat->cout($numero, $x, $y, $z))
  96          {
  97            print "\nTarif achat manquant pour $numero\n";
  98            exit(1);
  99          }
 100        
 101        if (! $tarif_vente->cout($numero, $x, $y, $z))
 102          {
 103            print "\nTarif vente manquant pour $numero\n";
 104            exit(1);
 105          }
 106      }
 107        
 108        print ".";
 109        $i++;
 110      }
 111    $db->free();
 112  }
 113  print "\n";
 114  
 115  /*
 116   * Verification des contrats
 117   */
 118  $contrats = array();
 119  
 120  $sql = "SELECT rowid, fk_client_comm, fk_soc, fk_soc_facture";
 121  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat ";
 122  
 123  $resql = $db->query($sql) ;
 124  
 125  if ( $resql )
 126  {
 127    $num = $db->num_rows($resql);
 128    
 129    $i = 0;
 130    
 131    while ($i < $num)
 132      {
 133        $objp = $db->fetch_object($resql);
 134        
 135        $contrats[$i] = $objp;
 136        
 137        $i++;
 138      }            
 139    $db->free();
 140  }
 141  dolibarr_syslog(sizeof($contrats) ." contrats a vérifier"); 
 142  
 143  $error = 0;
 144  
 145  foreach ($contrats as $contrat)
 146  {
 147  
 148    $sql = "SELECT rowid, fk_client_comm, fk_soc, fk_soc_facture";
 149    $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne";
 150    $sql .= " WHERE fk_contrat = ".$contrat->rowid;
 151  
 152    $resql = $db->query($sql) ;
 153    
 154    if ( $resql )
 155      {
 156        $num = $db->num_rows($resql);      
 157        $i = 0;
 158        
 159        while ($i < $num)
 160      {
 161        $objp = $db->fetch_object($resql);
 162        
 163        if ($objp->fk_client_comm <> $contrat->fk_client_comm)
 164          {
 165            dolibarr_syslog("Erreur fk_client_comm contrat ".$contrat->rowid." ligne ".$objp->rowid);
 166            $error++;
 167          }
 168        
 169        if ($objp->fk_soc <> $contrat->fk_soc)
 170          {
 171            dolibarr_syslog("Erreur fk_soc contrat ".$contrat->rowid." ligne ".$objp->rowid);
 172            $error++;
 173          }
 174  
 175        if ($objp->fk_soc_facture <> $contrat->fk_soc_facture)
 176          {
 177            dolibarr_syslog("Erreur fk_soc_facture contrat ".$contrat->rowid." ligne ".$objp->rowid);
 178            $error++;
 179          }
 180        $i++;
 181      }            
 182        $db->free();
 183      } 
 184    else
 185      {
 186        dolibarr_syslog("Erreur SQL");
 187      }
 188  }
 189  dolibarr_syslog($error ." erreurs trouvées"); 
 190  ?>


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