dolibarr/htdocs/telephonie/communication.class.php

251 lines
6.3 KiB
PHP
Raw Normal View History

2005-03-09 17:21:24 +01:00
<?PHP
2007-07-11 13:01:55 +02:00
/* Copyright (C) 2005-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2005-03-09 17:21:24 +01:00
*
* 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$
*
*/
class CommunicationTelephonique {
var $index;
var $ligne;
var $date;
var $duree;
var $dest;
var $numero;
var $montant;
2007-07-11 13:01:55 +02:00
var $messages;
2005-04-07 17:53:24 +02:00
/**
* Constructeur
*
*/
2005-03-09 17:21:24 +01:00
function CommunicationTelephonique()
{
2007-07-11 13:01:55 +02:00
$this->messages = array();
2005-03-09 17:21:24 +01:00
return 1;
}
2005-04-07 17:53:24 +02:00
/**
2007-07-11 18:09:10 +02:00
* Calcul le cout de la communication
2005-04-07 17:53:24 +02:00
*
*/
2005-11-08 15:02:48 +01:00
function cout($tarif_achat, $tarif_vente, $ligne, $_db)
2005-03-09 17:21:24 +01:00
{
$error = 0;
2007-07-11 18:09:10 +02:00
/*
if (substr($this->numero,0,2) == '00')
2005-03-09 17:21:24 +01:00
{
$nbinter++;
$duree_international += $objp->duree;
$num = $this->numero;
$this->remise = 0;
}
2007-07-11 18:09:10 +02:00
elseif (substr($this->numero,0,2) == '06')
2005-03-09 17:21:24 +01:00
{
$dureemob += $objp->duree;
$nbmob++;
$num = "0033".substr($this->numero,1);
$this->remise = $ligne->remise;
}
2007-07-11 18:09:10 +02:00
*/
2005-11-08 15:02:48 +01:00
/* Tarif Local */
/*
elseif (substr($this->numero,0,4) == substr($objp->client,0,4) )
2005-03-09 17:21:24 +01:00
{
$dureenat += $objp->duree;
2005-11-08 15:02:48 +01:00
$nbnat++;
2005-03-09 17:21:24 +01:00
$num = "0033999".substr($this->numero, 1);
$this->remise = $ligne->remise;
2005-11-08 15:02:48 +01:00
}*/
2007-07-11 18:09:10 +02:00
//else
//{
2005-03-09 17:21:24 +01:00
$dureenat += $objp->duree;
$nbnat++;
2007-07-11 20:50:42 +02:00
$num = "00".$this->numero;
2005-03-09 17:21:24 +01:00
$this->remise = $ligne->remise;
2007-07-11 18:09:10 +02:00
//}
2005-03-09 17:21:24 +01:00
2005-04-07 17:53:24 +02:00
/*
*
*
2005-11-08 15:02:48 +01:00
*/
2007-07-11 18:09:10 +02:00
/* Numeros speciaux */
/*
2005-11-08 15:02:48 +01:00
if (substr($num,4,1) == 8)
2005-03-09 17:21:24 +01:00
{
2005-11-08 15:02:48 +01:00
$this->remise = 0;
$this->cout_temp_vente = 0;
2007-07-11 18:09:10 +02:00
$this->tarif_libelle_vente = "Numeros speciaux";
2005-11-08 15:02:48 +01:00
$this->cout_fixe_vente = ereg_replace(",",".", $this->montant);
2005-03-09 17:21:24 +01:00
}
2005-11-08 15:02:48 +01:00
else
{
2007-07-11 18:09:10 +02:00
*/
/* Fin Numeros speciaux */
2007-07-03 16:41:39 +02:00
if ($tarif_achat->cout($num, $this->cout_temp_achat, $this->cout_fixe_achat, $tarif_libelle_achat) == 0)
2005-11-08 15:02:48 +01:00
{
dolibarr_syslog("CommunicationTelephonique::Cout Tarif achat manquant pour $num");
2007-07-11 20:50:42 +02:00
array_push($this->messages, array('warning',"Tarif achat manquant pour le numero $this->numero"));
2007-07-03 16:41:39 +02:00
//$error++;
2005-11-08 15:02:48 +01:00
}
2007-07-03 16:41:39 +02:00
if ($tarif_vente->cout($num, $this->cout_temp_vente, $this->cout_fixe_vente, $this->tarif_libelle_vente) == 0)
2005-11-08 15:02:48 +01:00
{
dolibarr_syslog("CommunicationTelephonique::Cout Tarif vente manquant pour $num");
2007-07-11 20:50:42 +02:00
array_push($this->messages, array('error',"Tarif vente manquant pour le numero $this->numero"));
2005-11-08 15:02:48 +01:00
$error++;
}
2007-07-11 18:09:10 +02:00
//}
2005-11-08 15:02:48 +01:00
/* Specification VoIP */
if ($ligne->techno == 'voip')
2005-03-09 17:21:24 +01:00
{
2005-11-08 15:02:48 +01:00
if (substr($num,4,1) < 6)
{
$lignedest = new LigneTel($_db);
if ($lignedest->fetch("0".substr($num, -9)) == 1)
{
if ($lignedest->techno == 'voip' && ($ligne->client_comm_id == $lignedest->client_comm_id))
{
$this->remise = 0;
$this->cout_fixe_vente = 0;
$this->cout_temp_vente = 0;
$this->tarif_libelle_vente = "Appel Interne VoIP";
}
}
}
2005-03-09 17:21:24 +01:00
}
2005-11-08 15:02:48 +01:00
/* Fin VoIP */
2005-03-09 17:21:24 +01:00
$this->cout_achat = ( ($this->duree * $this->cout_temp_achat / 60) + $this->cout_fixe_achat);
if ($ligne->facturable == 1)
{
$this->cout_vente = ( ($this->duree * $this->cout_temp_vente / 60));
$this->cout_vente = ( $this->cout_vente * ( 1 - ($this->remise / 100)));
2005-12-02 14:26:19 +01:00
/* Ajout<75> round le 2/12/05 */
$this->cout_vente = round(($this->cout_vente + $this->cout_fixe_vente), 3);
2005-03-09 17:21:24 +01:00
}
else
{
$this->cout_vente = 0;
}
return $error;
}
/*
2005-04-08 10:15:05 +02:00
* Enregistre la ligne de communications dans
* llx_telephonie_communications_details
*
*/
2005-03-09 17:21:24 +01:00
function logsql($db)
{
$this->cout_achat = ereg_replace(",",".", $this->cout_achat);
$this->cout_vente = ereg_replace(",",".", $this->cout_vente);
$this->remise = ereg_replace(",",".", $this->remise);
2005-11-08 15:02:48 +01:00
$this->montant = ereg_replace(",",".", $this->montant);
2005-03-09 17:21:24 +01:00
$this->dateheure = mktime(substr($this->heure, 0,2),
substr($this->heure, 3,2),
substr($this->heure, 6,2),
substr($this->date, 3,2),
substr($this->date, 0,2),
substr($this->date, 6,4));
$sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_communications_details";
2005-04-07 17:53:24 +02:00
$sql .= " (fk_ligne,ligne, date, numero, duree";
2005-03-09 17:21:24 +01:00
$sql .= ", tarif_achat_temp, tarif_achat_fixe, tarif_vente_temp, tarif_vente_fixe";
$sql .= ", cout_achat, cout_vente, remise,dest, fourn_montant";
2007-07-12 11:35:59 +02:00
$sql .= " , fichier_cdr, fk_fournisseur, fk_telephonie_facture,ym)";
2005-03-09 17:21:24 +01:00
$sql .= " VALUES (";
2005-04-07 17:53:24 +02:00
$sql .= $this->fk_ligne.",";
2005-03-09 17:21:24 +01:00
$sql .= "'$this->ligne','".$db->idate($this->dateheure)."','$this->numero','$this->duree'";
$sql .= ", '$this->cout_temp_achat','$this->cout_fixe_achat','$this->cout_temp_vente','$this->cout_fixe_vente'";
$sql .= ", '$this->cout_achat','$this->cout_vente', '$this->remise'";
$sql .= ",'".addslashes($this->tarif_libelle_vente)."','$this->montant'";
$sql .= ",'".$this->fichier_cdr."','".$this->fournisseur."'";
2007-07-12 11:35:59 +02:00
$sql .= ",'".$this->facture_id."','".strftime("%y%m",$this->dateheure)."')";
2005-03-09 17:21:24 +01:00
if (! $db->query($sql))
{
dolibarr_syslog("CommunicationTelephonique::logsql Erreur");
2005-03-10 12:27:17 +01:00
dolibarr_syslog("CommunicationTelephonique::logsql ".$db->error());
2005-03-09 17:21:24 +01:00
return 1;
}
else
{
return 0;
}
}
2005-04-08 10:15:05 +02:00
/*
*
*/
2005-03-09 17:21:24 +01:00
function _log( $text)
{
if ($this->file_details)
{
fputs($this->file_details, $text);
}
}
2005-04-08 10:15:05 +02:00
/*
*
*/
2005-04-07 17:53:24 +02:00
function loghtml($file)
{
$this->file_details = $file;
$this->_log( '<tr>');
$this->_log( "<td>$this->index");
$this->_log( "<td>$this->ligne");
$this->_log( "<td>".$this->dest);
$this->_log( "<td>".$this->duree);
$this->_log( "<td>".$this->montant);
$this->_log( "<td>".$cout_calcul);
2005-03-09 17:21:24 +01:00
2005-04-07 17:53:24 +02:00
if (round($cout_calcul,3) <> $objp->montant)
{
_log($file_details, "<td bgcolor=pink>".round($cout_calcul,3));
$err++;
}
else
{
_log($file_details, "<td>".round($cout_calcul,3));
}
_log($file_details, "<td>$err");
}
}
2005-03-09 17:21:24 +01:00
?>