[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: ServiceFactureTableur.class.php,v 1.1 2005/07/26 16:30:56 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/service/modules/ServiceFactureTableur.class.php,v $ 20 * 21 * 22 * Génération des détails de facture en tableur 23 * 24 */ 25 26 require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); 27 require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php"); 28 require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php"); 29 30 class ServiceFactureTableur 31 { 32 33 var $year; 34 var $month; 35 36 Function Process($contrat) 37 { 38 dolibarr_syslog("ServiceFactureTableur::Process Contrat ".$contrat->id); 39 40 $facids = array(); 41 42 /* 43 * Recherche des factures comptables liées au contrat 44 * 45 */ 46 47 $sql2 = "SELECT distinct fk_facture"; 48 $sql2 .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 49 $sql2 .= " WHERE fk_contrat = ".$contrat->id; 50 $sql2 .= " AND date = '".$this->year."-".$this->month."-01'"; 51 52 $resql2 = $contrat->db->query($sql2); 53 54 if ( $resql2 ) 55 { 56 $j = 0; 57 $num2 = $contrat->db->num_rows($resql2); 58 59 dolibarr_syslog("ServiceFactureTableur::Process Nb factures ".$num2); 60 61 while ($j < $num2) 62 { 63 $row2 = $contrat->db->fetch_row($resql2); 64 65 array_push($facids, $row2[0]); 66 $j++; 67 } 68 } 69 70 /* 71 * Recherche des facture de téléphonie liée à la facture comptable 72 * 73 */ 74 75 foreach ($facids as $facid) 76 { 77 $error = 0; 78 79 $facture = new Facture($contrat->db); 80 $facture->fetch($facid); 81 82 $factels = array(); 83 84 85 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."telephonie_facture"; 86 $sql .= " WHERE fk_facture =".$facture->id; 87 88 $resql = $contrat->db->query($sql); 89 90 if ( $resql ) 91 { 92 $num = $contrat->db->num_rows($resql); 93 $i = 0; 94 95 while ($i < $num) 96 { 97 $row = $contrat->db->fetch_row($resql); 98 array_push($factels, $row[0]); 99 $i++; 100 } 101 $contrat->db->free($resql); 102 } 103 else 104 { 105 $error++; 106 } 107 108 $fname = "/tmp/".$facture->ref.".xls"; 109 110 /* 111 * Génération du fchier tableur 112 */ 113 114 $workbook = &new writeexcel_workbook($fname); 115 116 $page = &$workbook->addworksheet("Facture $facture->ref"); 117 118 $fnb =& $workbook->addformat(); 119 $fnb->set_align('vcenter'); 120 $fnb->set_align('right'); 121 122 $fp =& $workbook->addformat(); 123 $fp->set_align('vcenter'); 124 $fp->set_align('right'); 125 $fp->set_num_format('0.000'); 126 127 $fdest =& $workbook->addformat(); 128 $fdest->set_align('vcenter'); 129 130 $page->set_column(0,0,12); // A 131 $page->set_column(1,1,20); // B 132 $page->set_column(2,2,15); // C 133 134 $page->set_column(3,3,30); // D 135 $page->set_column(6,6,7); // G 136 $page->set_column(9,9,7); // J 137 $page->set_column(12,12,7); // M 138 139 $page->write(0, 0, "Ligne", $format_titre_agence1); 140 $page->write(0, 1, "Date", $format_titre); 141 $page->write(0, 2, "Numero", $format_titre); 142 $page->write(0, 3, "Destination", $format_titre); 143 $page->write(0, 4, "Durée", $format_titre); 144 $page->write(0, 5, "Cout", $format_titre); 145 146 $xx = 1; 147 148 foreach ($factels as $factel) 149 { 150 $sql = "SELECT ligne, date, numero, dest, dureetext, duree, cout_vente"; 151 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 152 $sql .= " WHERE fk_telephonie_facture =".$factel; 153 $sql .= " ORDER BY date ASC"; 154 155 $resql = $contrat->db->query($sql); 156 157 if ($resql) 158 { 159 $i = 0; 160 $numsql = $contrat->db->num_rows($resql); 161 162 while ($i < $numsql) 163 { 164 $obj = $contrat->db->fetch_object($resql); 165 166 $page->write_string($xx, 0, $obj->ligne, $fdest); 167 $page->write_string($xx, 1, $obj->date, $fdest); 168 $page->write_string($xx, 2, $obj->numero, $fdest); 169 $page->write_string($xx, 3, $obj->dest, $fdest); 170 $page->write($xx, 4, $obj->duree, $fnb); 171 $page->write($xx, 5, $obj->cout_vente, $fp); 172 $xx++; 173 $i++; 174 } 175 $contrat->db->free($resql); 176 } 177 else 178 { 179 dolibarr_syslog($contrat->db->error()); 180 } 181 } 182 183 $workbook->close(); 184 dolibarr_syslog("Close $fname"); 185 186 dolibarr_syslog("Conso mémoire ".memory_get_usage() ); 187 } 188 } 189 } 190 191 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |