[ 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/ -> recalcul-facture.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: recalcul-facture.php,v 1.1 2005/07/26 08:29:55 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/tools/recalcul-facture.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  
  38  $lines = array ('0297754500','0297740033','0297753052','0297754791','0297754790','0297754767','0297754766','0297753788');
  39  
  40  $facture = 1687;
  41  
  42  $factels = array();
  43  
  44  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."telephonie_facture";
  45  $sql .= " WHERE fk_facture =".$facture;
  46  
  47  $resql = $db->query($sql);
  48    
  49  if ( $resql )
  50  {
  51    $num = $db->num_rows($resql);
  52    $i = 0;
  53  
  54    $row = $db->fetch_row($resql);
  55    print "Factures téléphoniques : $row[0]";
  56    array_push($factels, $row[0]);
  57    $i++;
  58  
  59    while ($i < $num)
  60      {
  61        $row = $db->fetch_row($resql);
  62  
  63        print ", $row[0]";
  64        array_push($factels, $row[0]);
  65        $i++;
  66      }
  67    $db->free($resql);
  68  }
  69  else
  70  {
  71    $error++;
  72  }
  73  print "\n";
  74  
  75  $total = 0;
  76  
  77  foreach ($factels as $factel)
  78  {
  79  
  80    $sql = "SELECT sum(cout_vente) FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
  81    $sql .= " WHERE fk_telephonie_facture =".$factel;
  82    
  83    $resql = $db->query($sql);
  84    
  85    if ( $resql )
  86      {
  87        $row = $db->fetch_row($resql);
  88        $total += $row[0];
  89        print "Facture $factel - $row[0]\n";
  90        $db->free($resql);
  91      }
  92    else
  93      {
  94        $error++;
  95      } 
  96  }
  97  
  98  print "Total : $total\n";
  99  
 100  // Analyse
 101  
 102  reset($factels);
 103  foreach ($factels as $factel)
 104  {
 105  
 106    $sql = "SELECT distinct(dest) FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
 107    $sql .= " WHERE fk_telephonie_facture =".$factel;
 108    $sql .= " AND tarif_vente_temp = 0.18";
 109    
 110    $resql = $db->query($sql);
 111    
 112    if ( $resql )
 113      {
 114        $row = $db->fetch_row($resql);
 115        print "Facture $factel - $row[0]\n";
 116        $db->free($resql);
 117      }
 118    else
 119      {
 120        $error++;
 121      } 
 122  }
 123  
 124  //
 125  
 126  $totale = 0;
 127  $totald = 0;
 128  reset($factels);
 129  foreach ($factels as $factel)
 130  {
 131  
 132    $sql = "SELECT count(*), sum(cout_vente), sum(duree) FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
 133    $sql .= " WHERE fk_telephonie_facture =".$factel;
 134    $sql .= " AND tarif_vente_temp = 0.18";
 135    
 136    $resql = $db->query($sql);
 137    
 138    if ( $resql )
 139      {
 140        $row = $db->fetch_row($resql);
 141        $totale += $row[1];
 142        $totald += $row[2];
 143        print "Facture $factel - $row[0] - $row[1] - $row[2]\n";
 144        $db->free($resql);
 145      }
 146    else
 147      {
 148        $error++;
 149      } 
 150  }
 151  print "Total : $totale duree $totald\n";
 152  
 153  $coutreel = $totald * 0.015 / 60;
 154  
 155  print "Cout reel à 0.015 : $coutreel\n";
 156  
 157  $reel = $total - $totale + $coutreel;
 158  
 159  print "Nouvelle facture = $reel\n";
 160  
 161  $db->close();
 162  
 163  
 164  ?>


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