From 6548b522f4f23d7687d66cdcba109a0ea25d31cb Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 30 Mar 2005 15:51:44 +0000 Subject: [PATCH] Nouveau fichier --- .../script/facturation-details-tableur.php | 124 ++++++++++++++++++ .../facture-detail-tableur-one.class.php | 120 +++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 htdocs/telephonie/script/facturation-details-tableur.php create mode 100644 htdocs/telephonie/script/facture-detail-tableur-one.class.php diff --git a/htdocs/telephonie/script/facturation-details-tableur.php b/htdocs/telephonie/script/facturation-details-tableur.php new file mode 100644 index 00000000000..dc36ca5f8ed --- /dev/null +++ b/htdocs/telephonie/script/facturation-details-tableur.php @@ -0,0 +1,124 @@ + + * + * 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énération des détails de facture en tableur + * + */ +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."/facture.class.php"); +require_once (DOL_DOCUMENT_ROOT."/societe.class.php"); +require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/script/facture-detail-tableur-one.class.php"); + +$error = 0; + +/* + * + * + */ +$sql = "SELECT max(date_format(date,'%Y%m')) "; +$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details" ; + +$resql = $db->query($sql); + +if ( $resql) +{ + + $row = $db->fetch_row($resql); + + $year = substr($row[0],0,4); + $month = substr($row[0],4,2); +} +else +{ + $error++; +} + +dolibarr_syslog("Mois $month Année $year"); + +/* + * Lectures de différentes lignes + */ + +if (!$error) +{ + + $sql = "SELECT distinct(ligne) as client"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; + $sql .= " ORDER BY ligne ASC"; + + $clients = array(); + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + + $i = 0; + + while ($i < $num) + { + $objp = $db->fetch_object( $i); + + $clients[$i] = $objp->client; + + $i++; + } + $db->free(); + print "$i lignes trouvées\n"; + } + else + { + $error = 1; + dolibarr_syslog($db->error()); + } +} + +/* + * Traitements + * + */ + +if (!$error) +{ + foreach ($clients as $client) + { + + $facdet = new FactureDetailTableurOne($db); + $resg = $facdet->GenerateFile ($client, $year, $month); + + if ($resg <> 0) + { + print "- ERREUR lors de Génération du pdf détaillé\n"; + $error = 19; + } + } +} + +$db->close(); + +dolibarr_syslog("Conso mémoire ".memory_get_usage() ); + +?> diff --git a/htdocs/telephonie/script/facture-detail-tableur-one.class.php b/htdocs/telephonie/script/facture-detail-tableur-one.class.php new file mode 100644 index 00000000000..b259430e08d --- /dev/null +++ b/htdocs/telephonie/script/facture-detail-tableur-one.class.php @@ -0,0 +1,120 @@ + + * + * 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$ + * + * + */ +require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php"); +require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php"); + +class FactureDetailTableurOne { + + Function FactureDetailTableurOne($DB) + { + $this->db = $DB; + } + + Function GenerateFile($ligne, $year, $month) + { + $this->ligne = $ligne; + + $dir = "/tmp"; + $error = 0; + + $fname = $dir."/".$this->ligne."-".substr('00'.$month, -2)."-".$year.".xls"; + + dolibarr_syslog("Open $fname"); + + $workbook = &new writeexcel_workbook($fname); + + $page = &$workbook->addworksheet($year."/".substr("00".$month,-2)); + + $fnb =& $workbook->addformat(); + $fnb->set_align('vcenter'); + $fnb->set_align('right'); + + $fp =& $workbook->addformat(); + $fp->set_align('vcenter'); + $fp->set_align('right'); + $fp->set_num_format('0.000'); + + $fdest =& $workbook->addformat(); + $fdest->set_align('vcenter'); + + $page->set_column(0,0,12); // A + $page->set_column(1,1,20); // B + $page->set_column(2,2,15); // C + + $page->set_column(3,3,30); // D + $page->set_column(6,6,7); // G + $page->set_column(9,9,7); // J + $page->set_column(12,12,7); // M + + $page->write(0, 0, "Ligne", $format_titre_agence1); + $page->write(0, 1, "Date", $format_titre); + $page->write(0, 2, "Numero", $format_titre); + $page->write(0, 3, "Destination", $format_titre); + $page->write(0, 4, "Durée", $format_titre); + $page->write(0, 5, "Cout", $format_titre); + + $sql = "SELECT ligne, date, numero, dest, dureetext, duree, cout_vente"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; + $sql .= " WHERE ligne = '".$this->ligne."'"; + $sql .= " ORDER BY date ASC"; + + $resql = $this->db->query($sql); + + if ($resql) + { + $i = 0; + $numsql = $this->db->num_rows($resql); + + dolibarr_syslog($this->ligne . " : ".$numsql); + + while ($i < $numsql) + { + $obj = $this->db->fetch_object($resql); + + $xx = $i + 1; + + $page->write_string($xx, 0, $obj->ligne, $fdest); + $page->write_string($xx, 1, $obj->date, $fdest); + $page->write_string($xx, 2, $obj->numero, $fdest); + $page->write_string($xx, 3, $obj->dest, $fdest); + $page->write($xx, 4, $obj->duree, $fnb); + $page->write($xx, 5, $obj->cout_vente, $fp); + + + $i++; + } + $this->db->free($resql); + } + else + { + dolibarr_syslog($this->db->error()); + } + + $workbook->close(); + dolibarr_syslog("Close $fname"); + + return $error; + + } +} +?>