From a59d65b6eabae4eee2b07bd16631c6ce71aecb11 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 8 May 2009 15:58:01 +0000 Subject: [PATCH] New: early development of multi-company module --- htdocs/compta/resultat/clientfourn.php | 172 +++++++++++++++---------- htdocs/compta/resultat/index.php | 152 +++++++++++++--------- htdocs/compta/stats/cabyuser.php | 26 ++-- htdocs/compta/stats/casoc.php | 42 ++++-- htdocs/compta/stats/comp.php | 73 +++++------ htdocs/compta/stats/cumul.php | 38 +++--- htdocs/compta/stats/exercices.php | 50 ++++--- htdocs/compta/stats/index.php | 34 +++-- htdocs/compta/stats/prev.php | 40 +++--- 9 files changed, 359 insertions(+), 268 deletions(-) diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index c37784597a1..c080a7f7736 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -46,7 +47,7 @@ llxHeader(); $html=new Form($db); -// Affiche en-t�te de rapport +// Affiche en-tete de rapport if ($modecompta=="CREANCES-DETTES") { $nom=$langs->trans("AnnualByCompaniesDueDebtMode"); @@ -84,22 +85,30 @@ print 'Facturation clients'; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT s.nom, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)"; - if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; + if ($year) $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } else { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ $sql = "SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.rowid"; - if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; + $sql.= " AND f.fk_soc = s.rowid"; + if ($year) $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } -if ($socid) $sql .= " AND f.fk_soc = $socid"; -$sql .= " GROUP BY nom"; -$sql .= " ORDER BY nom"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY nom"; +$sql.= " ORDER BY nom"; $result = $db->query($sql); if ($result) { @@ -131,12 +140,17 @@ if ($result) { if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; - if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - $sql .= " GROUP BY nom"; - $sql .= " ORDER BY nom"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + if ($year) $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " GROUP BY nom"; + $sql.= " ORDER BY nom"; $result = $db->query($sql); if ($result) { @@ -185,28 +199,29 @@ print ''; */ if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT s.nom, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)"; - if ($year) { - $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } + $sql = "SELECT s.nom, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; + if ($year) { + $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } } else { $sql = "SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; + $sql.= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " ON pf.fk_facturefourn = f.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s"; $sql .= " ON f.fk_soc = s.rowid"; - $sql .= " WHERE p.rowid = pf.fk_paiementfourn "; - if ($year) { - $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } -} -if ($socid) -{ - $sql .= " AND f.fk_soc = ".$socid; + $sql .= " WHERE p.rowid = pf.fk_paiementfourn "; + if ($year) { + $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } } +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; $sql .= " GROUP BY nom, s.rowid"; $sql .= " ORDER BY nom, s.rowid"; @@ -263,22 +278,29 @@ print 'Prestations/Charges NON deductibles'; if ($modecompta == 'CREANCES-DETTES') { $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.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " 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.= " AND s.date_ech between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle"; } else { $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=0"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql.= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 0"; if ($year) { - $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; + $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle"; } +$sql.= " AND s.entity = ".$conf->entity; +$sql.= " GROUP BY c.libelle"; + $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; @@ -327,22 +349,31 @@ print 'Prestations/Charges deductibles'; if ($modecompta == 'CREANCES-DETTES') { $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.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " 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.= " AND s.date_ech between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle DESC"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " GROUP BY c.libelle DESC"; } else { $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=1"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql .= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 1"; if ($year) { - $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; + $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " GROUP BY c.libelle"; } + $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; @@ -412,13 +443,15 @@ if ($modecompta == 'CREANCES-DETTES') // TVA a payer $amount=0; $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; if ($year) { - $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm DESC"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -448,13 +481,14 @@ if ($modecompta == 'CREANCES-DETTES') // TVA a recuperer $amount=0; $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; if ($year) { - $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm DESC"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; $result=$db->query($sql); if ($result) { @@ -488,13 +522,15 @@ else // TVA reellement deja payee $amount=0; $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql .= " WHERE amount > 0"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount > 0"; if ($year) { - $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm DESC"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -526,13 +562,15 @@ else // TVA recuperee $amount=0; $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql .= " WHERE amount < 0"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount < 0"; if ($year) { - $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm DESC"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 363e497a72f..5ccfad1387b 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -39,7 +40,7 @@ else { } /* - * S�curit� acc�s client + * Securite acces client */ if ($user->societe_id > 0) { @@ -55,7 +56,7 @@ llxHeader(); $html=new Form($db); -// Affiche en-t�te du rapport +// Affiche en-tete du rapport if ($modecompta=="CREANCES-DETTES") { $nom=$langs->trans("AnnualSummaryDueDebtMode"); @@ -85,20 +86,26 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; } else { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les - * vieilles versions, ils n'�taient pas li�s via paiement_facture. On les ajoute plus loin) + * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; } -if ($socid) $sql .= " AND f.fk_soc = $socid"; -$sql .= " GROUP BY dm"; -$sql .= " ORDER BY dm"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = $socid"; +$sql.= " GROUP BY dm"; +$sql.= " ORDER BY dm"; $result=$db->query($sql); if ($result) @@ -118,14 +125,19 @@ else { dol_print_error($db); } -// On ajoute les paiements clients anciennes version, non li�s par paiement_facture +// On ajoute les paiements clients anciennes version, non lies par paiement_facture if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm"; $result = $db->query($sql); if ($result) { @@ -170,20 +182,20 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " WHERE f.fk_soc = s.rowid AND f.fk_statut in (1,2)"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; } else { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " ON f.rowid = p.fk_facture_fourn"; - $sql .= " WHERE 1=1"; + $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " ON f.rowid = p.fk_facture_fourn"; + $sql.= " WHERE 1=1"; } -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY dm"; $result=$db->query($sql); if ($result) @@ -228,11 +240,13 @@ for ($mois = 1 ; $mois <= 12 ; $mois++) $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { - // TVA � payer + // TVA a payer $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; - $sql .= " GROUP BY dm DESC"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm DESC"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -251,11 +265,13 @@ if ($modecompta == 'CREANCES-DETTES') { } else { dol_print_error($db); } - // TVA � r�cup�rer + // TVA a recuperer $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -276,11 +292,13 @@ if ($modecompta == 'CREANCES-DETTES') { } } else { - // TVA r�ellement d�ja pay�e + // TVA reellement deja payee $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql .= " WHERE amount > 0"; - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount > 0"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -305,11 +323,13 @@ else { } else { dol_print_error($db); } - // TVA r�cup�r�e + // TVA recuperee $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql .= " WHERE amount < 0"; - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount < 0"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -353,22 +373,29 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT c.libelle as nom, date_format(s.date_ech,'%Y-%m') as dm, sum(s.amount) as amount_ht, sum(s.amount) as amount_ttc"; - $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.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " 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.= " AND s.date_ech between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle, dm"; } else { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=0"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql.= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 0"; if ($year) { - $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; + $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle, dm"; } +$sql.= " AND s.entity = ".$conf->entity; +$sql.= " GROUP BY c.libelle, dm"; + $result=$db->query($sql); if ($result) { @@ -414,23 +441,30 @@ $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT c.libelle as nom, date_format(s.date_ech,'%Y-%m') as dm, sum(s.amount) as amount_ht, sum(s.amount) as amount_ttc"; - $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.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " 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.= " AND s.date_ech between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle, dm"; } else { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."chargesociales as s, ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid AND s.fk_type = c.id AND c.deductible=1"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql.= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 1"; if ($year) { - $sql .= " AND p.datep between '$year-01-01 00:00:00' and '$year-12-31 23:59:59'"; + $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } - $sql .= " GROUP BY c.libelle, dm"; } +$sql.= " AND s.entity = ".$conf->entity; +$sql.= " GROUP BY c.libelle, dm"; + $result=$db->query($sql); if ($result) { $num = $db->num_rows($result); diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index e7f3a83dc08..6a729e85197 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -53,7 +54,7 @@ llxHeader(); $html=new Form($db); -// Affiche en-t�te du rapport +// Affiche en-tete du rapport if ($modecompta=="CREANCES-DETTES") { $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice"); @@ -81,9 +82,10 @@ $catotal=0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT u.rowid as rowid, u.name as name, u.firstname as firstname, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.fk_user_author = u.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.fk_user_author = u.rowid"; $sql.= " WHERE f.fk_statut in (1,2) "; - if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + if ($year) $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } else { @@ -99,7 +101,8 @@ else $sql.= " WHERE 1=1"; if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } -if ($socid) $sql .= " AND f.fk_soc = $socid"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; $sql .= " GROUP BY rowid"; $sql .= " ORDER BY rowid"; @@ -125,12 +128,17 @@ else { if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT -1 as rowid, '' as name, '' as firstname, sum(p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - $sql .= " GROUP BY rowid"; - $sql .= " ORDER BY rowid"; + $sql.= " GROUP BY rowid"; + $sql.= " ORDER BY rowid"; $result = $db->query($sql); if ($result) diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 38081354c8a..a75786c0620 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * * This program is free software; you can redistribute it and/or modify @@ -76,9 +77,11 @@ $catotal=0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT s.rowid as socid, s.nom as name, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2) AND f.fk_soc = s.rowid"; - if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.fk_soc = s.rowid"; + if ($year) $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } else { @@ -87,13 +90,19 @@ else * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ $sql = "SELECT s.rowid as socid, s.nom as name, sum(pf.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.rowid"; - if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; + $sql.= " AND f.fk_soc = s.rowid"; + if ($year) $sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; } -if ($socid) $sql .= " AND f.fk_soc = ".$socid; -$sql .= " GROUP BY s.rowid"; -$sql .= " ORDER BY s.rowid"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY s.rowid"; +$sql.= " ORDER BY s.rowid"; $result = $db->query($sql); if ($result) @@ -117,12 +126,17 @@ else { if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - $sql .= " GROUP BY nom"; - $sql .= " ORDER BY nom"; + $sql.= " GROUP BY nom"; + $sql.= " ORDER BY nom"; $result = $db->query($sql); if ($result) diff --git a/htdocs/compta/stats/comp.php b/htdocs/compta/stats/comp.php index ca1f16364a9..e266fb5f232 100644 --- a/htdocs/compta/stats/comp.php +++ b/htdocs/compta/stats/comp.php @@ -1,6 +1,7 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -35,13 +36,18 @@ if ($user->societe_id > 0) function propals ($db, $year, $month) { - global $bc,$langs; + global $bc,$langs,$conf; + $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.price, p.ref,".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; - $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id"; - $sql .= " AND c.id in (1,2,4)"; - $sql .= " AND date_format(p.datep, '%Y') = ".$year; - $sql .= " AND round(date_format(p.datep, '%m')) = ".$month; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."propal as p"; + $sql.= ", ".MAIN_DB_PREFIX."c_propalst as c"; + $sql.= " WHERE p.fk_soc = s.rowid"; + $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.fk_statut = c.id"; + $sql.= " AND c.id in (1,2,4)"; + $sql.= " AND date_format(p.datep, '%Y') = ".$year; + $sql.= " AND round(date_format(p.datep, '%m')) = ".$month; $sql .= " ORDER BY p.fk_statut"; @@ -105,19 +111,20 @@ function propals ($db, $year, $month) } -function factures ($db, $year, $month, $paye) { +function factures ($db, $year, $month, $paye) +{ global $bc,$conf; $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid "; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut = 1"; - if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = ".$paye; - } - $sql .= " AND f.fk_soc = s.rowid"; - $sql .= " AND date_format(f.datef, '%Y') = ".$year; - $sql .= " AND round(date_format(f.datef, '%m')) = ".$month; - $sql .= " ORDER BY f.datef DESC "; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ",".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut = 1"; + $sql.= " AND f.entity = ".$conf->entity; + if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = ".$paye; + $sql.= " AND f.fk_soc = s.rowid"; + $sql.= " AND date_format(f.datef, '%Y') = ".$year; + $sql.= " AND round(date_format(f.datef, '%m')) = ".$month; + $sql.= " ORDER BY f.datef DESC "; $result = $db->query($sql); if ($result) @@ -261,32 +268,26 @@ function ppt ($db, $year, $socid) print ''; - $sql = "SELECT sum(f.price) as sum, round(date_format(f.datep,'%m')) as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in (1,2,4) AND date_format(f.datep,'%Y') = $year "; - - if ($socid) - { - $sql .= " AND f.fk_soc = $socid"; - } - - $sql .= " GROUP BY dm"; + $sql = "SELECT sum(p.price) as sum, round(date_format(p.datep,'%m')) as dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; + $sql.= " WHERE p.fk_statut in (1,2,4)"; + $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND date_format(p.datep,'%Y') = ".$year; + if ($socid) $sql.= " AND p.fk_soc = ".$socid; + $sql.= " GROUP BY dm"; $prev = pt($db, $sql, $year); print ""; $sql = "SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; - if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; - } - $sql .= " AND date_format(f.datef,'%Y') = $year "; - if ($socid) - { - $sql .= " AND f.fk_soc = $socid"; - } - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.entity = ".$conf->entity; + if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; + $sql.= " AND date_format(f.datef,'%Y') = ".$year; + if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql.= " GROUP BY dm"; $ca = pt($db, $sql, $year); diff --git a/htdocs/compta/stats/cumul.php b/htdocs/compta/stats/cumul.php index e2a95dfeb35..e294642fffc 100644 --- a/htdocs/compta/stats/cumul.php +++ b/htdocs/compta/stats/cumul.php @@ -1,6 +1,7 @@ - * Copyright (C) 2004-2005 Laurent Destailleur +/* Copyright (C) 2001-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -45,33 +46,24 @@ print_titre("Chiffre d'affaire cumul print '
'; $sql = "SELECT sum(f.total) as amount , date_format(f.datef,'%Y-%m') as dm"; -$sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; -$sql .= " WHERE f.fk_statut in (1,2)"; -if ($modecompta != 'CREANCES-DETTES') -{ - $sql .= " AND f.paye = 1"; -} -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; +$sql.= " WHERE f.fk_statut in (1,2)"; +$sql.= " AND f.entity = ".$conf->entity; +if ($modecompta != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY dm"; pt($db, $sql,"Suivi cumul par mois"); print ''; $sql = "SELECT sum(f.total) as amount, year(f.datef) as dm"; -$sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; -$sql .= " WHERE f.fk_statut in (1,2)"; -if ($modecompta != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; -} -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; +$sql.= " WHERE f.fk_statut in (1,2)"; +$sql.= " AND f.entity = ".$conf->entity; +if ($modecompta != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY dm"; pt($db, $sql,"Suivi cumul par année"); diff --git a/htdocs/compta/stats/exercices.php b/htdocs/compta/stats/exercices.php index e10bcf08dea..1bc0adca54a 100644 --- a/htdocs/compta/stats/exercices.php +++ b/htdocs/compta/stats/exercices.php @@ -1,6 +1,7 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -49,10 +50,14 @@ function factures ($db, $year, $month, $paye) global $bc,$langs; $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.total as amount,".$db->pdate("f.datef")." as df, f.paye, f.rowid as facid "; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.rowid AND f.paye = ".$paye; - $sql .= " AND date_format(f.datef, '%Y') = ".$year; - $sql .= " AND round(date_format(f.datef, '%m')) = ".$month; - $sql .= " ORDER BY f.datef DESC "; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.paye = ".$paye; + $sql.= " AND date_format(f.datef, '%Y') = ".$year; + $sql.= " AND round(date_format(f.datef, '%m')) = ".$month; + $sql.= " ORDER BY f.datef DESC "; $result = $db->query($sql); if ($result) { @@ -185,35 +190,26 @@ function ppt ($db, $year, $socid) print "
"; $sql = "SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; - $sql .= " AND date_format(f.datef,'%Y') = ".($year-1); - - if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; - } - if ($socid) - { - $sql .= " AND f.fk_soc = $socid"; - } - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND date_format(f.datef,'%Y') = ".($year-1); + if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; + if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql.= " GROUP BY dm"; $prev = pt($db, $sql, $year - 1); print ""; $sql = "SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; - $sql .= " AND date_format(f.datef,'%Y') = $year "; - if ($conf->compta->mode != 'CREANCES-DETTES') { - $sql .= " AND f.paye = 1"; - } - if ($socid) - { - $sql .= " AND f.fk_soc = $socid"; - } - $sql .= " GROUP BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND date_format(f.datef,'%Y') = $year "; + if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; + if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql.= " GROUP BY dm"; $ca = pt($db, $sql, $year); diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 4e014752119..5e14c90bf5c 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -38,7 +39,7 @@ else { } /* - * Sécurité accés client + * Securite acces client */ if ($user->societe_id > 0) { @@ -78,19 +79,23 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT sum(f.total) as amount, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.fk_statut in (1,2)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; } else { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; } -if ($socid) $sql .= " AND f.fk_soc = $socid"; -$sql .= " GROUP BY dm DESC"; +$sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; +$sql.= " GROUP BY dm DESC"; $result = $db->query($sql); if ($result) @@ -117,11 +122,16 @@ else { // On ajoute les paiements anciennes version, non liés par paiement_facture if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql .= " WHERE pf.rowid IS NULL"; - $sql .= " GROUP BY dm"; - $sql .= " ORDER BY dm"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm"; $result = $db->query($sql); if ($result) { diff --git a/htdocs/compta/stats/prev.php b/htdocs/compta/stats/prev.php index c257b76eece..47cb6f0bf69 100644 --- a/htdocs/compta/stats/prev.php +++ b/htdocs/compta/stats/prev.php @@ -1,6 +1,7 @@ * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -96,37 +97,34 @@ print ''; print '
'; -$sql = "SELECT sum(f.price) as amount, date_format(f.datep,'%Y-%m') as dm"; -$sql .= " FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in $in"; -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm DESC"; +$sql = "SELECT sum(p.price) as amount, date_format(p.datep,'%Y-%m') as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; +$sql.= " WHERE p.fk_statut in ".$in; +$sql.= " AND p.entity = ".$conf->entity; +if ($socid) $sql.= " AND p.fk_soc = ".$socid; +$sql.= " GROUP BY dm DESC"; pt($db, $sql, $langs->trans("Month")); print ''; -$sql = "SELECT sum(f.price) as amount, year(f.datep) as dm"; -$sql .= " FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in $in"; -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm DESC"; +$sql = "SELECT sum(p.price) as amount, year(p.datep) as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; +$sql.= " WHERE p.fk_statut in ".$in; +$sql.= " AND p.entity = ".$conf->entity; +if ($socid) $sql.= " AND p.fk_soc = ".$socid; +$sql.= " GROUP BY dm DESC"; pt($db, $sql, "Année"); print "
"; -$sql = "SELECT sum(f.price) as amount, month(f.datep) as dm"; -$sql .= " FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in $in"; -if ($socid) -{ - $sql .= " AND f.fk_soc = $socid"; -} -$sql .= " GROUP BY dm"; +$sql = "SELECT sum(p.price) as amount, month(p.datep) as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; +$sql.= " WHERE p.fk_statut in ".$in; +$sql.= " AND p.entity = ".$conf->entity; +if ($socid) $sql.= " AND p.fk_soc = ".$socid; +$sql.= " GROUP BY dm"; pt($db, $sql, "Mois cumulés");