[ Index ] |
|
Code source de Dolibarr 2.0.1 |
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/06/06 13:28:10 rodolphe Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/telephonie.tarif.class.php,v $ 21 * 22 */ 23 24 /** 25 \file htdocs/telephonie.tarif.class.php 26 \ingroup facture 27 \brief Fichier de la classe des tarifs telephonies 28 \version $Revision: 1.2 $ 29 */ 30 31 32 /** 33 \class TelephonieTarif 34 \brief Classe permettant la gestion des tarifs de telephonie 35 */ 36 37 38 class TelephonieTarif { 39 40 var $_DB; 41 var $tableau_tarif; 42 var $prefixes; 43 var $prefixe_max; 44 45 /* 46 * Constructeur 47 * 48 */ 49 function TelephonieTarif($_DB, $fournisseur_id, $type, $tarif_spec = 0, $client_id = 0) 50 { 51 $this->db = $_DB; 52 53 $this->tableau_tarif = array(); 54 55 $this->prefixes = array(); 56 57 $this->client_id = $client_id; 58 59 $this->tarif_spec = $tarif_spec; 60 61 62 for ($j = 0 ; $j++ ; $j < 10) 63 { 64 $this->prefixes[$j] = array(); 65 $this->prefixe_max = array(); 66 } 67 68 $this->_load_tarif($fournisseur_id, $type); 69 } 70 71 72 function _load_tarif($fournisseur_id, $type) 73 { 74 75 if ($type == 'achat') 76 { 77 $sql = "SELECT prefix, temporel, fixe"; 78 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_achat "; 79 $sql .= " WHERE fk_fournisseur = " . $fournisseur_id; 80 81 $sql = "SELECT p.prefix, m.temporel, m.fixe"; 82 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_montant as m "; 83 $sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p "; 84 $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f "; 85 86 $sql .= " WHERE p.fk_tarif = m.fk_tarif "; 87 88 $sql .= " AND f.fk_tarif_grille = m.fk_tarif_desc"; 89 90 $sql .= " AND f.rowid = " . $fournisseur_id; 91 92 } 93 elseif ($type == 'vente') 94 { 95 $sql = "SELECT p.prefix, m.temporel, m.fixe, t.libelle"; 96 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_montant as m"; 97 $sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t"; 98 $sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p"; 99 100 $sql .= " WHERE t.rowid = m.fk_tarif"; 101 $sql .= " AND t.rowid = p.fk_tarif"; 102 $sql .= " AND m.fk_tarif_desc = 1"; 103 } 104 105 if ( $this->db->query($sql) ) 106 { 107 $num = $this->db->num_rows(); 108 109 //print "$num tableau_tarif trouvés\n"; 110 111 $i = 0; 112 113 while ($i < $num) 114 { 115 $row = $this->db->fetch_row($i); 116 117 $l = $row[0]; 118 119 $this->tableau_tarif[$l] = $row; 120 121 // Tableaux des prefixes découpés en 10 tableaux 122 123 $pref = substr($row[0],0,1); 124 125 $i_pref = sizeof($this->prefixes[$pref]) + 1; 126 127 $this->prefixes[$pref][$i_pref] = $row[0]; 128 129 // Taille maximale du prefixe 130 $this->prefixe_max[$pref] = max(strlen($row[0]), $this->prefixe_max[$pref]); 131 132 $i++; 133 } 134 135 $this->db->free(); 136 } 137 else 138 { 139 dolibarr_syslog("TelephonieTarif::_load_tarif Erreur 1"); 140 dolibarr_syslog($this->db->error()); 141 } 142 143 /* 144 * Tarif Spécifique 145 * 146 */ 147 148 if ($this->tarif_spec <> 1) 149 { 150 151 $sql = "SELECT p.prefix, m.temporel, m.fixe, t.libelle"; 152 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_montant as m"; 153 $sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t"; 154 $sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p"; 155 156 $sql .= " WHERE t.rowid = m.fk_tarif"; 157 $sql .= " AND t.rowid = p.fk_tarif"; 158 $sql .= " AND m.fk_tarif_desc = ".$this->tarif_spec; 159 160 $resql = $this->db->query($sql); 161 162 if ($resql) 163 { 164 $num = $this->db->num_rows($resql); 165 $i = 0; 166 167 while ($i < $num) 168 { 169 $row = $this->db->fetch_row($resql); 170 171 $l = $row[0]; 172 $this->tableau_tarif[$l] = $row; 173 174 $i++; 175 } 176 177 $this->db->free($resql); 178 } 179 else 180 { 181 dolibarr_syslog("TelephonieTarif::_load_tarif Erreur 59"); 182 dolibarr_syslog($this->db->error()); 183 } 184 } 185 /* 186 * Tarifs client 187 * 188 * 189 */ 190 191 if ($type == 'vente' && ($this->client_id > 0)) 192 { 193 $sql = "SELECT p.prefix, tc.temporel, tc.fixe, t.libelle"; 194 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_tarif_client as tc"; 195 $sql .= " , ".MAIN_DB_PREFIX."telephonie_prefix as p "; 196 $sql .= " , ".MAIN_DB_PREFIX."telephonie_tarif as t"; 197 $sql .= " WHERE tc.fk_tarif = t.rowid AND p.fk_tarif = t.rowid"; 198 $sql .= " AND tc.fk_client = ".$this->client_id; 199 200 if ( $this->db->query($sql) ) 201 { 202 $num = $this->db->num_rows(); 203 $i = 0; 204 205 while ($i < $num) 206 { 207 $row = $this->db->fetch_row($i); 208 209 $l = $row[0]; 210 211 $this->tableau_tarif[$l] = $row; 212 213 $i++; 214 } 215 } 216 else 217 { 218 print $this->db->error(); 219 } 220 } 221 } 222 /* 223 * 224 * 225 * 226 */ 227 function cout($number, &$cout_tempo, &$cout_fixe, &$tarif_libelle) 228 { 229 $result = 0; 230 $first_char_in_prefix = substr($number,2,1); 231 232 $k = $this->prefixe_max[$first_char_in_prefix]; 233 234 $goon = 1; 235 while ($goon == 1 && $k > 0) 236 { 237 238 $prefix_to_find = substr($number, 2, $k); 239 240 if (in_array($prefix_to_find, $this->prefixes[$first_char_in_prefix])) 241 { 242 // print "\t$prefix_to_find\n"; 243 $cout_tempo = $this->tableau_tarif[$prefix_to_find][1]; 244 $cout_fixe = $this->tableau_tarif[$prefix_to_find][2]; 245 $tarif_libelle = $this->tableau_tarif[$prefix_to_find][3]; 246 247 $goon = 0; 248 $result = 1; 249 } 250 $k = $k - 1; 251 } 252 253 return $result; 254 } 255 } 256 257 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |