From 60de3a4ec737794d733bd79cf091f7ce5755f17b Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 17 May 2006 12:00:04 +0000 Subject: [PATCH] Nouveau fichier --- .../script/facturation-consolidation.php | 183 ++++++++++++++++++ .../sql/llx_telephonie_facture_consol.sql | 57 ++++++ 2 files changed, 240 insertions(+) create mode 100644 htdocs/telephonie/script/facturation-consolidation.php create mode 100644 htdocs/telephonie/sql/llx_telephonie_facture_consol.sql diff --git a/htdocs/telephonie/script/facturation-consolidation.php b/htdocs/telephonie/script/facturation-consolidation.php new file mode 100644 index 00000000000..825c25953a2 --- /dev/null +++ b/htdocs/telephonie/script/facturation-consolidation.php @@ -0,0 +1,183 @@ + + * + * 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$ + * + * Prépare les factures à imprimer + */ + +/** + \file htdocs/telephonie/script/facturation-consolidation.php + \ingroup telephonie + \brief Consolidation des données de facturation + \version $Revision$ +*/ + +require ("../../master.inc.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); + +$ligne = new LigneTel($db); + +if ($opt['m'] > 0) +{ + $datetime = mktime(10,10,10,$opt['m'],10,2006); +} +else +{ + $datetime = time(); +} + +$month = strftime("%m", $datetime); +$year = strftime("%y", $datetime); + +if ($month == 1) +{ + $month = "12"; + $year = $year - 1; +} +else +{ + $month = substr("00".($month - 1), -2) ; +} + +$sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_facture_consol"; +$resql = $db->query($sql); + +if (! $resql ) +{ + print $db->error(); + die(); +} + + +$sql = "SELECT groupe.nom, agence.nom, l.ligne, l.statut, u.firstname,u.name "; +$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; +$sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c"; +$sql .= " , ".MAIN_DB_PREFIX."societe as groupe"; +$sql .= " , ".MAIN_DB_PREFIX."societe as agence"; +$sql .= " , ".MAIN_DB_PREFIX."user as u"; +$sql .= " WHERE l.fk_contrat = c.rowid"; +$sql .= " AND c.fk_client_comm = groupe.idp"; +$sql .= " AND c.fk_soc = agence.idp"; +$sql .= " AND c.fk_commercial_sign = u.rowid"; +$sql .= " LIMIT 10"; + +print "$sql\n"; + +$resql = $db->query($sql); + +if ( $resql ) +{ + $num = $db->num_rows(); + + print "$num\n"; + + while ($row = $db->fetch_row($resql)) + { + print $row[0]."\t".$row[1]."\t".$row[2]."\t".$ligne->statuts[$row[3]]."\t".$row[4]."\n"; + + $sqli = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_facture_consol"; + $sqli .= " (groupe,agence,ligne,statut,repre_ib) VALUES "; + $sqli .= " ('$row[0]','$row[1]','$row[2]',"; + $sqli .= "'".$ligne->statuts[$row[3]]."',"; + $sqli .= "'".$row[4]." ".$row[5]."')"; + + $resqli = $db->query($sqli); + + $m = 0; + $mc = $month + 1; + $yc = $year; + + while ($m < 7) + { + $mc = $mc - 1; + + if ($mc == 0) + { + $mc = 12; + $yc = $yc - 1; + } + + $msc = substr("00".$mc, -2) ; + $ysc = substr("00".$yc, -2) ; + + $sqls = "SELECT round(sum(cout_vente),2) "; + $sqls .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; + $sqls .= " WHERE ligne = '$row[2]'"; + $sqls .= " AND ym = '".$ysc.$msc."'"; + $sqls .= " AND num_prefix = '06'"; + $resqls = $db->query($sqls); + print "$sqls\n"; + if ( $resqls ) + { + while ($rows = $db->fetch_row($resqls)) + { + $sqlu = "UPDATE ".MAIN_DB_PREFIX."telephonie_facture_consol"; + $sqlu .= " SET mobi_m".$m."='".$rows[0]."'"; + $sqlu .= " WHERE ligne = '$row[2]'"; + if (! $resqlu = $db->query($sqlu)) + { + die($db->error()); + } + + } + } + else + { + die($db->error()); + } + + /* Fixes */ + $sqls = "SELECT round(sum(cout_vente),2) "; + $sqls .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; + $sqls .= " WHERE ligne = '$row[2]'"; + $sqls .= " AND ym = '".$ysc.$msc."'"; + $sqls .= " AND num_prefix in ('01','02','03','04','05')"; + $resqls = $db->query($sqls); + + if ( $resqls ) + { + while ($rows = $db->fetch_row($resqls)) + { + $sqlu = "UPDATE ".MAIN_DB_PREFIX."telephonie_facture_consol"; + $sqlu .= " SET fixe_m".$m."='".$rows[0]."'"; + $sqlu .= " WHERE ligne = '$row[2]'"; + if (! $resqlu = $db->query($sqlu)) + { + die($db->error()); + } + + } + } + else + { + die($db->error()); + } + + $m++; + } + + } +} +else +{ + print $db->error(); +} + +$db->close(); +?> diff --git a/htdocs/telephonie/sql/llx_telephonie_facture_consol.sql b/htdocs/telephonie/sql/llx_telephonie_facture_consol.sql new file mode 100644 index 00000000000..c722ad16b82 --- /dev/null +++ b/htdocs/telephonie/sql/llx_telephonie_facture_consol.sql @@ -0,0 +1,57 @@ +-- ======================================================================== +-- Copyright (C) 2006 Rodolphe Quiedeville +-- +-- 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$ +-- +-- ======================================================================== +-- +-- Consolidation des factures de téléphonie +-- + +create table llx_telephonie_facture_consol ( + groupe varchar(255), + agence varchar(255), + ligne varchar(255) NOT NULL, + statut varchar(255) NOT NULL, + fixe_m0 real, + mobi_m0 real, + paye_m0 enum('oui','non'), + fixe_m1 real, + mobi_m1 real, + paye_m1 enum('oui','non'), + fixe_m2 real, + mobi_m2 real, + paye_m2 enum('oui','non'), + fixe_m3 real, + mobi_m3 real, + paye_m3 enum('oui','non'), + fixe_m4 real, + mobi_m4 real, + paye_m4 enum('oui','non'), + fixe_m5 real, + mobi_m5 real, + paye_m5 enum('oui','non'), + fixe_m6 real, + mobi_m6 real, + paye_m6 enum('oui','non'), + repre varchar(255), + distri varchar(255), + repre_ib varchar(255) + +)type=innodb; +