[ 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/ -> telephonie-tarif.class.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   * or see http://www.gnu.org/
  18   *
  19   * $Id: telephonie-tarif.class.php,v 1.2 2005/03/09 16:25:01 rodolphe Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/telephonie-tarif.class.php,v $
  21   *
  22   */
  23  
  24  class TelephonieTarif {
  25  
  26    var $_DB;
  27    var $tarif_fournisseur;
  28    var $prefixes;
  29    var $prefixe_max;
  30  
  31    /*
  32     * Constructeur
  33     *
  34     */
  35    function TelephonieTarif($_DB, $fournisseur_id, $type, $client_id = 0)
  36    {
  37      $this->db = $_DB;
  38  
  39      $this->tarif_fournisseur = array();
  40  
  41      $this->prefixes = array();
  42  
  43      $this->client_id = $client_id;
  44  
  45  
  46      for ($j = 0 ; $j++ ; $j < 10)
  47        {
  48      $this->prefixes[$j] = array();
  49      $this->prefixe_max = array();
  50        }
  51  
  52      $this->_load_tarif($fournisseur_id, $type);
  53  
  54    }
  55  
  56  
  57    function _load_tarif($fournisseur_id, $type)
  58    {
  59      
  60      if ($type == 'achat')
  61        {
  62      $sql = "SELECT prefix, temporel, fixe";
  63      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_achat ";
  64      $sql .= " WHERE fk_fournisseur = " . $fournisseur_id;
  65      
  66        }
  67      elseif ($type == 'vente')
  68        {
  69      $sql = "SELECT prefix, temporel, fixe, libelle";
  70      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_vente";
  71        }
  72          
  73      if ( $this->db->query($sql) )
  74        {
  75      $num = $this->db->num_rows();
  76      
  77      //print "$num tarif_fournisseur trouvés\n";
  78      
  79      $i = 0;
  80      
  81      while ($i < $num)
  82        {
  83          $row = $this->db->fetch_row($i);
  84          
  85          $l = $row[0];
  86  
  87          $this->tarif_fournisseur[$l] = $row;
  88                  
  89          // Tableaux des prefixes découpés en 10 tableaux
  90          
  91          $pref = substr($row[0],0,1);
  92          
  93          $i_pref = sizeof($this->prefixes[$pref]) + 1;
  94          
  95          $this->prefixes[$pref][$i_pref] = $row[0];
  96          
  97          // Taille maximale du prefixe
  98          $this->prefixe_max[$pref] = max(strlen($row[0]), $this->prefixe_max[$pref]);
  99          
 100          $i++;
 101        }
 102  
 103      $this->db->free();    
 104        }
 105      else
 106        {
 107      dolibarr_syslog("TelephonieTarif::_load_tarif Erreur 1");
 108      dolibarr_syslog($this->db->error());
 109        }
 110  
 111      /*
 112       * Tarifs client
 113       *
 114       *
 115       */
 116  
 117      if ($type == 'vente' && ($this->client_id > 0))
 118        {
 119      $sql = "SELECT p.prefix, tc.temporel, tc.fixe, t.libelle";
 120      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_client as tc"; 
 121      $sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p ";
 122      $sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t";
 123      $sql .= " WHERE tc.fk_tarif = t.rowid AND p.fk_tarif = t.rowid";
 124      $sql .= " AND tc.fk_client = ".$this->client_id;
 125  
 126      if ( $this->db->query($sql) )
 127        {
 128          $num = $this->db->num_rows();        
 129          $i = 0;
 130          
 131          while ($i < $num)
 132            {
 133          $row = $this->db->fetch_row($i);
 134          
 135          $l = $row[0];
 136  
 137          $this->tarif_fournisseur[$l] = $row;
 138          
 139          $i++;
 140            }
 141        }
 142      else
 143        {
 144          print $this->db->error();
 145        }
 146        }        
 147    }
 148    /*
 149     *
 150     *
 151     *
 152     */
 153    function cout($number, &$cout_tempo, &$cout_fixe, &$tarif_libelle)
 154    {
 155      $result = 0;
 156      $first_char_in_prefix = substr($number,2,1);
 157  
 158      $k = $this->prefixe_max[$first_char_in_prefix];
 159  
 160      //print "$first_char_in_prefix\t";
 161  
 162      $goon = 1;
 163      while ($goon == 1 && $k > 0)
 164        {
 165      
 166      $prefix_to_find = substr($number, 2, $k);
 167      
 168      //print "($k, $prefix_to_find)";
 169      
 170      if (in_array($prefix_to_find, $this->prefixes[$first_char_in_prefix]))
 171        {
 172          //        print "\t$prefix_to_find\n";
 173          $cout_tempo    = $this->tarif_fournisseur[$prefix_to_find][1];
 174          $cout_fixe     = $this->tarif_fournisseur[$prefix_to_find][2];
 175          $tarif_libelle = $this->tarif_fournisseur[$prefix_to_find][3];
 176  
 177          $goon = 0;
 178          $result = 1;
 179        }        
 180      $k = $k - 1;
 181        }
 182  
 183      return $result;
 184    }
 185  }
 186  
 187  ?>


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