diff --git a/htdocs/telephonie/script/facturation-calcul.php b/htdocs/telephonie/script/facturation-calcul.php new file mode 100644 index 00000000000..9a57386d131 --- /dev/null +++ b/htdocs/telephonie/script/facturation-calcul.php @@ -0,0 +1,436 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + * + * Script de calcul de la facturation + * - Lit les entrées dans la table import_cdr + * - Verifie que tous les tarifs sont dispos + * - Importe les lignes dans llx_communications_details + * - Calcul la facture téléphonique par ligne + */ + +require ("../../master.inc.php"); + +require_once (DOL_DOCUMENT_ROOT."/societe.class.php"); +//require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php"); + + +$error = 0; + +$datetime = time(); + +$date = strftime("%d%h%Y%Hh%Mm%S",$datetime); + +$month = strftime("%m", $datetime); +$year = strftime("%Y", $datetime); + +if ($month == 1) +{ + $month = "12"; + $year = $year - 1; +} +else +{ + $month = substr("00".($month - 1), -2) ; +} + +$month = "01"; +$year = "2005"; + + + +/******************************************************************************* + * + * Verifie la présence des tarifs adequat + * + */ + +$tarif_achat = new TelephonieTarif($db, 1, "achat"); +$tarif_vente = new TelephonieTarif($db, 1, "vente"); + +$sql = "SELECT distinct(num) FROM ".MAIN_DB_PREFIX."telephonie_import_cdr"; + +if ( $db->query($sql) ) +{ + $nums = $db->num_rows(); + $i = 0; + + while($i < $nums) + { + $row = $db->fetch_row(); + + $numero = $row[0]; + + /* Reformatage du numéro */ + + if (substr($numero,0,2) == '00') /* International */ + { + } + elseif (substr($numero,0,2) == '06') /* Telephones Mobiles */ + { + $numero = "0033".substr($numero,1); + } + elseif (substr($numero,0,4) == substr($objp->client,0,4) ) /* Tarif Local */ + { + $numero = "0033999".substr($numero, 1); + } + else + { + $numero = "0033".substr($numero, 1); + } + + /* Recherche du tarif */ + + if (! $tarif_achat->cout($numero, $x, $y, $z)) + { + print "\nTarif achat manquant pour $numero\n"; + exit(1); + } + + if (! $tarif_vente->cout($numero, $x, $y, $z)) + { + print "\nTarif vente manquant pour $numero\n"; + exit(1); + } + + print "."; + $i++; + } + $db->free(); +} +print "\n"; + +unset ($nums, $row, $tarif_achat, $tarif_vente); + +$file_log_import = fopen(DOL_DATA_ROOT."/telephonie/logs/$date.log","w"); +$file_log = fopen(DOL_DATA_ROOT."/telephonie/logs/$date.html","w"); +$file_details = fopen(DOL_DATA_ROOT."/telephonie/logs/$date-detail.html","w"); + +/******************************************************** + * + * Affiche le nombre de ligne a facturer + * + *********************************************************/ + +$sql = "SELECT count(*)"; +$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_import_cdr";; + +if ( $db->query($sql) ) +{ + $num = $db->num_rows(); + $row = $db->fetch_row(); + + dolibarr_syslog("Communications à traiter ".$row[0]); + $db->free(); +} + +/** + * + * Lectures de différentes lignes + * + */ + +if (!$error) +{ + $user = new user($db,1); + + $sql = "SELECT distinct(t.ligne)"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_import_cdr as t"; + $sql .= " ORDER BY ligne ASC"; + + $clients = array(); + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + + $i = 0; + + while ($i < $num) + { + $row = $db->fetch_row(); + + $clients[$i] = $row[0]; + + $i++; + } + $db->free(); + print "$i lignes trouvées\n"; + } + else + { + $error = 1; + } +} + +/*************************************** + * + * Traitements + * + */ + +if (!$error) +{ + _log($file_log, 'detail
| Client | Nb Appel | Duree moyenne | Inter | '); + _log($file_log, 'Inter | Nat | Cout Fourn. | '); + _log($file_log, 'Fourn. Calculé | |