From 77a046fb6156f557eb1b2fd243dde56e2fc802de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Mar 2004 21:26:03 +0000 Subject: [PATCH] =?UTF-8?q?Pr=E9paration=20pour=20ajout=20du=20"compte=20d?= =?UTF-8?q?e=20r=E9sultat"=20et=20"bilan".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/resultat/bilan.php | 52 +++++ htdocs/compta/resultat/clientfourn.php | 217 ++++++++++++++++++ htdocs/compta/resultat/compteres.php | 52 +++++ htdocs/compta/resultat/index.php | 295 +++++++++++-------------- htdocs/compta/resultat/pre.inc.php | 30 +-- htdocs/compta/stats/pre.inc.php | 17 +- 6 files changed, 480 insertions(+), 183 deletions(-) create mode 100644 htdocs/compta/resultat/bilan.php create mode 100644 htdocs/compta/resultat/clientfourn.php create mode 100644 htdocs/compta/resultat/compteres.php diff --git a/htdocs/compta/resultat/bilan.php b/htdocs/compta/resultat/bilan.php new file mode 100644 index 00000000000..1dac2239caa --- /dev/null +++ b/htdocs/compta/resultat/bilan.php @@ -0,0 +1,52 @@ + + * + * 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("./pre.inc.php"); +require("../../tva.class.php"); +require("../../chargesociales.class.php"); + +/* + * + */ +$user->getrights('compta'); +if (!$user->rights->compta->resultat) + accessforbidden(); + +llxHeader(); + +$year=$_GET["year"]; +$month=$_GET["month"]; +if (! $year) { $year = strftime("%Y", time()); } + + +/* Le compte de résultat est un document officiel requis par l'administration selon le status ou activité */ + +print_titre("Bilan".($year?" année $year":"")); + +print '
'; + +print "Cet état n'est pas disponible."; + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php new file mode 100644 index 00000000000..59b93a97afc --- /dev/null +++ b/htdocs/compta/resultat/clientfourn.php @@ -0,0 +1,217 @@ + + * Copyright (C) 2004 Laurent Destailleur + * + * 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("./pre.inc.php"); +require("../../tva.class.php"); +require("../../chargesociales.class.php"); + +/* + * + */ +$user->getrights('compta'); +if (!$user->rights->compta->resultat) + accessforbidden(); + +llxHeader(); + +$year=$_GET["year"]; +$month=$_GET["month"]; +if (! $year) { $year = strftime("%Y", time()); } + + +print_titre("Résultat comptable".($year?" année $year":"").", détail par client/fournisseur"); + +print '
'; + +print ""; +print ''; +print ''; +print ""; +print "\n"; + +/* Factures clients */ + +$sql = "SELECT s.nom,s.idp,sum(f.total) as amount"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; +if ($year) { + $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +$sql .= " GROUP BY s.nom ASC"; + + +print ''; + +$result = $db->query($sql); +if ($result) { + $num = $db->num_rows(); + + $i = 0; + + if ($num > 0) { + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + + print ""; + print "\n"; + + print "\n"; + + $total = $total + $objp->amount; + print "\n"; + $i++; + } + } + $db->free(); +} else { + print $db->error(); +} +print ''; +/* + * Frais, factures fournisseurs. + * + * + */ +$sql = "SELECT s.nom,s.idp,sum(f.total_ht) as amount"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f WHERE f.fk_soc = s.idp"; +if ($year) { + $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +$sql .= " GROUP BY s.nom ASC, s.idp"; + +print ''; +$subtotal = 0; +$result = $db->query($sql); +if ($result) { + $num = $db->num_rows(); + $i = 0; + + if ($num > 0) { + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + + print ""; + print "\n"; + + print "\n"; + + $total = $total - $objp->amount; + $subtotal = $subtotal + $objp->amount; + print "\n"; + $i++; + } + } + $db->free(); +} else { + print $db->error(); +} +print ''; + +/* + * Charges sociales + * + */ +$subtotal = 0; +print ''; + +$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; +$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; +$sql .= " WHERE s.fk_type = c.id AND c.deductible=1"; +if ($year) { + $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +$sql .= " GROUP BY c.libelle DESC"; + +if ( $db->query($sql) ) { + $num = $db->num_rows(); + $i = 0; + + while ($i < $num) { + $obj = $db->fetch_object( $i); + + $total = $total - $obj->amount; + $subtotal = $subtotal + $obj->amount; + + $var = !$var; + print ""; + print ''; + print ''; + print ''; + $i++; + } +} else { + print $db->error(); +} +print ''; + +print ''; +/* + * Charges sociales non déductibles + * + */ +$subtotal = 0; +print ''; + +$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; +$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; +$sql .= " WHERE s.fk_type = c.id AND c.deductible=0"; +if ($year) { + $sql .= " AND s.date_ech between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +$sql .= " GROUP BY c.libelle DESC"; + +if ( $db->query($sql) ) { + $num = $db->num_rows(); + $i = 0; + + while ($i < $num) { + $obj = $db->fetch_object( $i); + + $total = $total - $obj->amount; + $subtotal = $subtotal + $obj->amount; + + $var = !$var; + print ""; + print ''; + print ''; + print ''; + $i++; + } +} else { + print $db->error(); +} +print ''; + +print ''; + + +print "
 ElémentMontant HT
Facturation clients
 Factures idp\">$objp->nom".price($objp->amount)."
'.price($total).'
Facturation fournisseurs
 Factures idp."\">$objp->nom".price($objp->amount)."
'.price($subtotal).'
Prestations/Charges déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
Prestations/Charges NON déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
"; + + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/compta/resultat/compteres.php b/htdocs/compta/resultat/compteres.php new file mode 100644 index 00000000000..8214078b161 --- /dev/null +++ b/htdocs/compta/resultat/compteres.php @@ -0,0 +1,52 @@ + + * + * 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("./pre.inc.php"); +require("../../tva.class.php"); +require("../../chargesociales.class.php"); + +/* + * + */ +$user->getrights('compta'); +if (!$user->rights->compta->resultat) + accessforbidden(); + +llxHeader(); + +$year=$_GET["year"]; +$month=$_GET["month"]; +if (! $year) { $year = strftime("%Y", time()); } + + +/* Le compte de résultat est un document officiel requis par l'administration selon le status ou activité */ + +print_titre("Compte de résultat".($year?" année $year":"")); + +print '
'; + +print "Cet état n'est pas disponible."; + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 90898a560f7..dbe94295589 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (C) 2004 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -21,179 +21,150 @@ * */ require("./pre.inc.php"); -require("../../tva.class.php"); -require("../../chargesociales.class.php"); /* * */ -$user->getrights('compta'); -if (!$user->rights->compta->resultat) - accessforbidden(); llxHeader(); -print_titre("Résultat"); +/* + * Sécurité accés client + */ +if ($user->societe_id > 0) +{ + $socidp = $user->societe_id; +} -print ""; -print ''; -print ''; -print ""; +$year_current = $_GET["year"];; +if (! $year_current) { $year_current = strftime("%Y", time()); } + + +print_titre("Résultat comptable, résumé annuel"); +print '
'; + + +$sql = "SELECT sum(f.total) as amount, date_format(f.datef,'%Y-%m') as dm"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp AND f.fk_statut = 1"; +if ($year) { + $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +if ($socidp) +{ + $sql .= " WHERE f.fk_soc = $socidp"; +} +$sql .= " GROUP BY dm DESC"; + +if ($db->query($sql)) +{ + $num = $db->num_rows(); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($i); + $encaiss[$row[1]] = $row[0]; + $i++; + } +} +else { + print $db->error(); +} + +$sql = "SELECT sum(f.total_ht) as amount, date_format(f.datef,'%Y-%m') as dm"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f WHERE f.fk_soc = s.idp"; +if ($year) { + $sql .= " AND f.datef between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; +} +if ($socidp) +{ + $sql .= " AND f.fk_soc = $socidp"; +} +$sql .= " GROUP BY dm DESC"; + +if ($db->query($sql)) +{ + $num = $db->num_rows(); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($i); + $decaiss[$row[1]] = $row[0]; + $i++; + } +} +else { + print $db->error(); +} + +print '
 ElémentMontant
'; +print ''; + + +if ($year_current < (MAIN_START_YEAR + 2)) +{ + $year_start = MAIN_START_YEAR; + $year_end = (MAIN_START_YEAR + 2); +} +else +{ + $year_start = $year_current - 2; + $year_end = $year_current; +} + +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} +print ''; +print ''; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} +print ''; + +$var=True; +for ($mois = 1 ; $mois < 13 ; $mois++) +{ + $var=!$var; + print ''; + print ""; + for ($annee = $year_start ; $annee <= $year_end ; $annee++) + { + print '"; + + print '"; + } + + print ''; +} + +$var=!$var; +print ""; +for ($annee = $year_start ; $annee <= $year_end ; $annee++) +{ + print ''; +} print "\n"; -$sql = "SELECT s.nom,s.idp,sum(f.amount) as amount"; -$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp AND f.fk_statut = 1 AND f.fk_user_valid is not NULL"; - -$sql .= " GROUP BY s.nom ASC"; - -print ''; - -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows(); - - $i = 0; - - if ($num > 0) { - $var=True; - while ($i < $num) { - $objp = $db->fetch_object( $i); - $var=!$var; - - print ""; - print "\n"; - - print "\n"; - - $total = $total + $objp->amount; - print "\n"; - $i++; - } - } - $db->free(); -} else { - print $db->error(); -} -print ''; -/* - * Frais, factures fournisseurs. - * - * - */ -$sql = "SELECT s.nom,s.idp,sum(f.total_ht) as amount"; -$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f WHERE f.fk_soc = s.idp"; - -$sql .= " GROUP BY s.nom ASC, s.idp"; - -print ''; -$subtotal = 0; -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows(); - $i = 0; - - if ($num > 0) { - $var=True; - while ($i < $num) { - $objp = $db->fetch_object( $i); - $var=!$var; - - print ""; - print "\n"; - - print "\n"; - - $total = $total - $objp->amount; - $subtotal = $subtotal + $objp->amount; - print "\n"; - $i++; - } - } - $db->free(); -} else { - print $db->error(); -} -print ''; - -/* - * Charges sociales - * - */ -$subtotal = 0; -print ''; - -$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; -$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; -$sql .= " WHERE s.fk_type = c.id AND c.deductible=1"; - -$sql .= " GROUP BY c.libelle DESC"; - -if ( $db->query($sql) ) { - $num = $db->num_rows(); - $i = 0; - - while ($i < $num) { - $obj = $db->fetch_object( $i); - - $total = $total - $obj->amount; - $subtotal = $subtotal + $obj->amount; - - $var = !$var; - print ""; - print ''; - print ''; - print ''; - $i++; - } -} else { - print $db->error(); -} -print ''; - -print ''; -/* - * Charges sociales non déductibles - * - */ -$subtotal = 0; -print ''; - -$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; -$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s"; -$sql .= " WHERE s.fk_type = c.id AND c.deductible=0"; - -$sql .= " GROUP BY c.libelle DESC"; - -if ( $db->query($sql) ) { - $num = $db->num_rows(); - $i = 0; - - while ($i < $num) { - $obj = $db->fetch_object( $i); - - $total = $total - $obj->amount; - $subtotal = $subtotal + $obj->amount; - - $var = !$var; - print ""; - print ''; - print ''; - print ''; - $i++; - } -} else { - print $db->error(); -} -print ''; - -print ''; - - -print "
Mois'.$annee.'
RecettesDépenses
".strftime("%B",mktime(1,1,1,$mois,1,$annee))." '; + $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); + if ($encaiss[$case]>0) + { + print price($encaiss[$case]); + $totentrees[$annee]+=$encaiss[$case]; + } + print " '; + $case = strftime("%Y-%m",mktime(1,1,1,$mois,1,$annee)); + if ($decaiss[$case]>0) + { + print price($decaiss[$case]); + $totsorties[$annee]+=$decaiss[$case]; + } + print "
Total annuel'.price($totentrees[$annee]).''.price($totsorties[$annee]).'
Factures
 Factures idp\">$objp->nom".price($objp->amount)."
'.price($total).'
Frais
 Factures idp."\">$objp->nom".price($objp->amount)."
'.price($subtotal).'
Prestations déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
Prestations NON déductibles
 '.$obj->nom.''.price($obj->amount).'
'.price($subtotal).'
Résultat'.price($total).'
"; - - +print ""; $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); + ?> diff --git a/htdocs/compta/resultat/pre.inc.php b/htdocs/compta/resultat/pre.inc.php index fc6f9d2da5d..d19041aedea 100644 --- a/htdocs/compta/resultat/pre.inc.php +++ b/htdocs/compta/resultat/pre.inc.php @@ -1,5 +1,6 @@ + * Copyright (C) 2004 Laurent Destailleur * * 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 @@ -24,7 +25,6 @@ require("../../main.inc.php"); function llxHeader($head = "") { global $conf; - /* * * @@ -33,19 +33,21 @@ function llxHeader($head = "") { $menu = new Menu(); - $menu->add(DOL_URL_ROOT."/compta/resultat/","Résultat / Exercice"); - - $menu->add(DOL_URL_ROOT."/compta/stats/index.php","Chiffre d'affaire"); - - - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cumul.php","Cumulé"); - if ($conf->propal->enabled) { - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/prev.php","Prévisionnel"); - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/comp.php","Transformé"); - } - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/exercices.php","Evolution"); - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/casoc.php","Par société"); - $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cabyuser.php","Par utilisateur"); + $menu->add(DOL_URL_ROOT."/compta/resultat/","Résultat / Exercice"); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/clientfourn.php","Détail client/fourn."); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/compteres.php","Compte de résultat"); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/bilan.php","Bilan"); + + $menu->add(DOL_URL_ROOT."/compta/stats/index.php","Chiffre d'affaire"); + + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cumul.php","Cumulé"); + if ($conf->propal->enabled) { + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/prev.php","Prévisionnel"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/comp.php","Transformé"); + } + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/exercices.php","Evolution"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/casoc.php","Par société"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cabyuser.php","Par utilisateur"); left_menu($menu->liste); } diff --git a/htdocs/compta/stats/pre.inc.php b/htdocs/compta/stats/pre.inc.php index 927a8563b90..c5810762b82 100644 --- a/htdocs/compta/stats/pre.inc.php +++ b/htdocs/compta/stats/pre.inc.php @@ -34,17 +34,20 @@ function llxHeader($head = "") { $menu = new Menu(); $menu->add(DOL_URL_ROOT."/compta/resultat/","Résultat / Exercice"); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/resbysource.php","Détail client/fourn."); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/compteres.php","Compte de résultat"); + $menu->add_submenu(DOL_URL_ROOT."/compta/resultat/bilan.php","Bilan"); - $menu->add("index.php","Chiffre d'affaire"); + $menu->add(DOL_URL_ROOT."/compta/stats/index.php","Chiffre d'affaire"); - $menu->add_submenu("cumul.php","Cumulé"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cumul.php","Cumulé"); if ($conf->propal->enabled) { - $menu->add_submenu("prev.php","Prévisionnel"); - $menu->add_submenu("comp.php","Transformé"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/prev.php","Prévisionnel"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/comp.php","Transformé"); } - $menu->add_submenu("exercices.php","Evolution"); - $menu->add_submenu("casoc.php","Par société"); - $menu->add_submenu("cabyuser.php","Par utilisateur"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/exercices.php","Evolution"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/casoc.php","Par société"); + $menu->add_submenu(DOL_URL_ROOT."/compta/stats/cabyuser.php","Par utilisateur"); left_menu($menu->liste); }