dolibarr/htdocs/telephonie/script/facturation-details.php

153 lines
3.3 KiB
PHP
Raw Normal View History

2005-03-31 15:05:15 +00:00
<?PHP
/* Copyright (C) 2005 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$
*
*
* G<EFBFBD>n<EFBFBD>ration des factures d<EFBFBD>taill<EFBFBD>es
*
* G<EFBFBD>n<EFBFBD>re les factures d<EFBFBD>taill<EFBFBD>es du dernier mois.
*
*
*/
require ("../../master.inc.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");
require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
$error = 0;
$datetime = time();
/*
*
*/
$sql = "SELECT max(date) FROM ".MAIN_DB_PREFIX."telephonie_facture";
$resql = $db->query($sql);
if ( $resql )
{
$num = $db->num_rows($resql);
$row = $db->fetch_row($resql);
$date = $row[0];
}
else
{
$error++;
}
dolibarr_syslog("G<EFBFBD>n<EFBFBD>re les factures d<>taill<6C>es pour : ".$date);
/*
* Lectures de diff<EFBFBD>rentes factures
* Bas<EFBFBD> sur le dernier mois de facturation
*/
if (!$error)
{
$user = new user($db,1);
$sql = "SELECT rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " WHERE date='".$date."'";
$sql .= " AND fk_facture IS NOT NULL";
$factures = array();
$resql = $db->query($sql);
if ( $resql )
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$factures[$i] = $objp->rowid;
$i++;
}
$db->free($resql);
dolibarr_syslog("$i lignes trouv<75>es");
}
else
{
$error = 1;
dolibarr_syslog($db->error());
}
}
/*
* Traitements
*
*/
if (!$error && sizeof($factures))
{
2005-04-08 07:56:35 +00:00
$facok = 0;
2005-03-31 15:05:15 +00:00
foreach ($factures as $facid)
{
$error = 0;
/* Creation des factures d<>taill<6C>e */
$factel = new FactureTel($db);
if ($factel->fetch($facid) == 0)
{
$objligne = new LigneTel($db);
2005-04-08 07:56:35 +00:00
2005-03-31 15:05:15 +00:00
if ($objligne->fetch($factel->ligne) == 1)
{
// Diff<66>rents mod<6F>les de factures d<>taill<6C>es
2005-04-08 07:56:35 +00:00
2005-03-31 15:05:15 +00:00
$modele = "standard";
require_once (DOL_DOCUMENT_ROOT."/telephonie/pdf/pdfdetail_".$modele.".modules.php");
$class = "pdfdetail_".$modele;
$facdet = new $class($db, $ligne, $year, $month, $factel);
2005-04-08 07:56:35 +00:00
if ($facdet->write_pdf_file($factel, $factel->ligne) == 0)
{
$facok++;
}
else
2005-03-31 15:05:15 +00:00
{
dolibarr_syslog("ERREUR lors de G<>n<EFBFBD>ration du pdf d<>taill<6C>");
$error = 19;
}
}
}
}
2005-04-08 07:56:35 +00:00
dolibarr_syslog(sizeof($factures)." factures trait<69>es");
dolibarr_syslog($facok." factures g<>n<EFBFBD>r<EFBFBD>es");
2005-03-31 15:05:15 +00:00
}
$db->close();
?>