Files
dolibarr/htdocs/telephonie/facturetel.class.php
Rodolphe Quiedeville 92e45755d7 Nouveau fichier
2004-12-03 13:19:14 +00:00

144 lines
3.0 KiB
PHP

<?PHP
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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 FactureTel {
var $db;
var $id;
function FactureTel($DB, $id=0)
{
$this->db = $DB;
return 1;
}
/*
*
*
*/
function fetch($id)
{
$sql = "SELECT rowid, ligne, date, cout_vente, cout_vente_remise";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as tf";
$sql .= " WHERE tf.rowid = ".$id;
if ($this->db->query($sql))
{
if ($this->db->num_rows())
{
$obj = $this->db->fetch_object(0);
$this->id = $obj->rowid;
$this->ligne = $obj->ligne;
$this->cout_vente = $obj->cout_vente;
$this->cout_vente_remise = $obj->cout_vente_remise;
$result = 0;
}
else
{
dolibarr_syslog("Erreur FactureTel::fetch() id=$id");
$result = -2;
}
$this->db->free();
}
else
{
/* Erreur select SQL */
dolibarr_syslog("Erreur FactureTel::fetch(), sql error");
print $this->db->error();
$result = -1;
}
return $result;
}
/*
* Met à jout la facture téléphonique avec le numéro de la facture
* comptable
*/
function affect_num_facture_compta($facid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " SET ";
$sql .= " fk_facture = $facid ";
$sql .= " WHERE rowid = $this->id";
if ( $this->db->query($sql) )
{
return 0;
}
else
{
print $this->db->error();
print $sql ;
return 1;
}
}
function get_comm_min_date($date)
{
$sql = "SELECT ".$this->db->pdate("min(date)")." FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
$sql .= " WHERE ligne = '".$this->ligne."' and EXTRACT(YEAR_MONTH FROM date) = $date";
if ($this->db->query($sql))
{
if ($this->db->num_rows())
{
$row = $this->db->fetch_row(0);
return $row[0];
}
}
}
function get_comm_max_date($date)
{
$sql = "SELECT ".$this->db->pdate("max(date)")." FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
$sql .= " WHERE ligne = '".$this->ligne."' and EXTRACT(YEAR_MONTH FROM date) = $date";
if ($this->db->query($sql))
{
if ($this->db->num_rows())
{
$row = $this->db->fetch_row(0);
return $row[0];
}
}
}
}
?>