From 5589ef91175d55771b27920b920440ef6b22e9ca Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Mon, 16 Jan 2006 15:45:35 +0000 Subject: [PATCH] Nouveau fichier --- .../facture-detail-tableur-two.class.php | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 htdocs/telephonie/script/facture-detail-tableur-two.class.php diff --git a/htdocs/telephonie/script/facture-detail-tableur-two.class.php b/htdocs/telephonie/script/facture-detail-tableur-two.class.php new file mode 100644 index 00000000000..afda21cd01b --- /dev/null +++ b/htdocs/telephonie/script/facture-detail-tableur-two.class.php @@ -0,0 +1,146 @@ + + * + * 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$ + * + * Créé un ou plusieurs fichiers xls avec les communications + * d'un contrat + * + */ +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 FactureDetailTableurTwo { + + Function FactureDetailTableurTwo($DB) + { + $this->db = $DB; + } + + Function GenerateFile($contrat_id, $year, $month) + { + $error = 0; + + + $contrat_id = substr("0000".$contrat_id, -4); + + + $dir = DOL_DATA_ROOT.'/telephonie/contrat/'; + + $dir .= substr($contrat_id,0,1)."/"; + $dir .= substr($contrat_id,1,1)."/"; + $dir .= substr($contrat_id,2,1)."/"; + $dir .= substr($contrat_id,3,1)."/"; + + create_exdir($dir); + + $fname = $dir . $contrat_id . "-$month-$year-detail.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, "Duree", $format_titre); + $page->write(0, 5, "Cout", $format_titre); + + $sql = "SELECT f.rowid, l.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f"; + $sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; + $sql .= " WHERE f.fk_ligne = l.rowid"; + $sql .= " AND l.fk_contrat = ".$contrat_id; + $sql .= " AND f.date = '".$year."-".$month."-01';"; + + $resql = $this->db->query($sql); + + if ($resql) + { + while ($row = $this->db->fetch_row[$resql]) + { + $sql = "SELECT ligne, date, numero, dest, dureetext, duree, cout_vente"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; + $sql .= " WHERE fk_ligne = '".$row[1]."'"; + $sql .= " AND fk_telephonie_facture = ".$row[0]; + $sql .= " ORDER BY date ASC"; + + $resql = $this->db->query($sql); + + if ($resql) + { + $i = 0; + $numsql = $this->db->num_rows($resql); + + dolibarr_syslog("Ligne : ".$this->ligne->id . " : ".$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; + } +} +?>