* Copyright (C) 2004-2010 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 * 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, see . */ /** * \file htdocs/compta/stats/comp.php * \ingroup commercial * \version $Id: comp.php,v 1.45 2011/07/31 22:23:14 eldy Exp $ * TODO Remove or add page in menus */ require('../../main.inc.php'); require_once(DOL_DOCUMENT_ROOT."/lib/accountancy.lib.php"); // Security check if ($user->societe_id > 0) { $socid = $user->societe_id; } function propals ($db, $year, $month) { global $bc,$langs,$conf; $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.price, p.ref, p.datep as dp, p.fk_statut as statutid, c.label as statut"; $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 AND p.fk_statut = c.id"; $sql.= " AND p.entity = ".$conf->entity; $sql.= " AND p.fk_statut in (1,2,4)"; // TODO Use between instead of date_format $sql.= " AND date_format(p.datep, '%Y') = '".$year."'"; $sql.= " AND round(date_format(p.datep, '%m')) = '".$month."'"; $sql.= " ORDER BY p.fk_statut"; $result = $db->query($sql); $num = $db->num_rows($result); $i = 0; print ""; print ""; $oldstatut = -1; $subtotal = 0; while ($i < $num) { $objp = $db->fetch_object($result); if ($objp->statut <> $oldstatut ) { $oldstatut = $objp->statut; if ($i > 0) { print "\n"; print "\n"; } $subtotal = 0; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; $var=True; } $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $total = $total + $objp->price; $subtotal = $subtotal + $objp->price; $i++; } print "\n"; print "\n"; print ""; print ""; print ""; print "
Propal
".$langs->trans("Total").": ".price($subtotal)."".$langs->trans("Currency".$conf->monnaie)."
Societe".$langs->trans("Ref")."".$langs->trans("Date")."".$langs->trans("Price")."".$langs->trans("Status")."
socid."\">".$objp->nom."propalid."\">".$objp->ref."".dol_print_date($db->jdate($objp->dp))."".price($objp->price)."".$objp->statut."
".$langs->trans("Total").": ".price($subtotal)."".$langs->trans("Currency".$conf->monnaie)."
".$langs->trans("Total").": ".price($total)."".$langs->trans("Currency".$conf->monnaie)."
"; $db->free(); } function factures ($db, $year, $month, $paye) { global $bc,$conf; $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.total, f.datef as df, f.paye, f.rowid as facid "; $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) { $num = $db->num_rows($result); if ($num > 0) { $i = 0; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; print "\n"; print "\n"; if ($objp->df > 0 ) { print "\n"; } else { print "\n"; } print "\n"; $payes[1] = "oui"; $payes[0] = "non"; print "\n"; print "\n"; $total = $total + $objp->total; $i++; } print ""; print "
Factures
SocieteNumDateMontantPay�
socid."\">".$objp->nom."facid."\">".$objp->facnumber."".dol_print_date($db->jdate($objp->df))."!!!".price($objp->total)."".$payes[$objp->paye]."
"; print "Total : ".price($total)."
"; $db->free(); } } else { print $db->error(); } } function pt ($db, $sql, $year) { global $bc, $langs; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $total = 0 ; print ''; print ""; print ''; print "\n"; $var=True; $month = 1 ; while ($i < $num) { $obj = $db->fetch_object($result); $var=!$var; if ($obj->dm > $month ) { for ($b = $month ; $b < $obj->dm ; $b++) { print ""; print "\n"; print "\n"; print "\n"; $var=!$var; $ca[$b] = 0; } } if ($obj->sum > 0) { print ""; print "\n"; print "\n"; print "\n"; $month = $obj->dm + 1; $ca[$obj->dm] = $obj->sum; $total = $total + $obj->sum; } $i++; } if ($num) { $beg = $obj->dm; } else { $beg = 0 ; } if ($beg <= 12 ) { for ($b = $beg + 1 ; $b < 13 ; $b++) { $var=!$var; print ""; print "\n"; print "\n"; print "\n"; $ca[$b] = 0; } } print ""; print "
'.$langs->trans("Month").'Montant
".dol_print_date(dol_mktime(12,0,0,$b, 1, $year),"%b")."0
dm\">"; print dol_print_date(dol_mktime(12,0,0,$obj->dm, 1, $year),"%b")."".price($obj->sum)."
".dol_print_date(dol_mktime(12,0,0,$b, 1, $year),"%b")."0
Total :".price($total)."
"; $db->free(); return $ca; } else { print $db->error(); } } function ppt ($db, $year, $socid) { global $bc,$conf,$langs; print ""; print '"; print ""; print '
'; print "CA Previsionnel base sur les propal $year"; print "CA Realise $yearDelta $year
'; $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)"; $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); print ""; print ''; print ""; print ''; print ''; print "\n"; $var = 1 ; for ($b = 1 ; $b <= 12 ; $b++) { $var=!$var; $delta = $ca[$b] - $prev[$b]; $deltat = $deltat + $delta ; print ""; print "\n"; print "\n"; print "\n"; } $ayear = $year - 1; $acat = get_ca($db, $ayear, $socid) - get_ca_propal($db, $ayear, $socid); print ""; print ""; print ""; print "
'.$langs->trans("Month").''.$langs->trans("Amount").'
".dol_print_date(dol_mktime(12,0,0,$b, 1, $year),"%b")."".price($delta)."
Total :".price($deltat)."
Rappel $ayear :".price($acat)."
Soit :".price($acat+$deltat)."
"; print "
"; } /* * View */ llxHeader(); $cyear = isset($_GET["year"])?$_GET["year"]:0; if (! $cyear) { $cyear = strftime ("%Y", time()); } print_fiche_titre("Chiffre d'Affaire transform� (pr�vu-r�alis�)",($cyear?"".img_previous()." Ann�e $cyear ".img_next()."":"")); ppt($db, $cyear, $socid); if ($details == 1) { print "
"; factures ($db, $year, $month, 1); print ""; propals ($db, $year, $month); print "
"; } $db->close(); llxFooter('$Date: 2011/07/31 22:23:14 $ - $Revision: 1.45 $'); ?>