diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index c9ef59fc3c5..2dd9c078784 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -28,12 +28,17 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/chargesociales.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); $langs->load("bills"); -if (!$user->rights->facture->lire) - accessforbidden(); +// Security check +$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +if ($user->societe_id > 0) $socid = $user->societe_id; +if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) +accessforbidden(); // Date range $year=$_REQUEST["year"]; @@ -50,7 +55,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:1; // TODO Set current quarter + $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:0; + if ($q==0) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"]); $date_end=dol_get_last_day($year_start,$_REQUEST["month"]); } + else { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,12); } + } if ($q==1) { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,3); } if ($q==2) { $date_start=dol_get_first_day($year_start,4); $date_end=dol_get_last_day($year_start,6); } if ($q==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); } @@ -68,6 +78,10 @@ if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; +/* + * View + */ + llxHeader(); $html=new Form($db); @@ -75,60 +89,61 @@ $html=new Form($db); // Affiche en-tete de rapport if ($modecompta=="CREANCES-DETTES") { - $nom=$langs->trans("AnnualByCompaniesDueDebtMode"); - $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$langs->trans("Year")." ".$year; - $periodlink=''.img_previous().' '.img_next().''; - $description=$langs->trans("RulesResultDue"); - $builddate=time(); - $exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("AnnualByCompaniesDueDebtMode"); + $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + //$period=$langs->trans("Year")." ".$year; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; + $description=$langs->trans("RulesResultDue"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); } else { - $nom=$langs->trans("AnnualByCompaniesInputOutputMode"); - $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - $period=$langs->trans("Year")." ".$year; - $periodlink=''.img_previous().' '.img_next().''; - $description=$langs->trans("RulesResultInOut"); - $builddate=time(); - $exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("AnnualByCompaniesInputOutputMode"); + $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + //$period=$langs->trans("Year")." ".$year; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; + $description=$langs->trans("RulesResultInOut"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); -// Affiche rapport +// Show report array print ''; print ''; print ''; if ($modecompta == 'CREANCES-DETTES') print ""; print ""; print "\n"; -print ''; /* * Factures clients */ -print ''; +print ''; 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"; - $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'"; + $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"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } 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) - */ + /* + * 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"; $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'"; + $sql.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; + $sql.= " AND f.fk_soc = s.rowid"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -137,80 +152,80 @@ $sql.= " ORDER BY nom"; $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; + $num = $db->num_rows($result); + $i = 0; + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; - print ""; - print "\n"; + print ""; + print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; - $total_ht = $total_ht + $objp->amount_ht; - $total_ttc = $total_ttc + $objp->amount_ttc; - print "\n"; - $i++; - } - $db->free($result); + $total_ht = $total_ht + $objp->amount_ht; + $total_ttc = $total_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } // On ajoute les paiements clients anciennes version, non lie par paiement_facture if ($modecompta != 'CREANCES-DETTES') { - $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; - $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 = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; + $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 ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql.= " GROUP BY nom"; + $sql.= " ORDER BY nom"; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; - if ($num) { - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + if ($num) { + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; - print ""; - print ""; + print "\n"; - print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; - $total_ht = $total_ht + $objp->amount_ht; - $total_ttc = $total_ttc + $objp->amount_ttc; - print "\n"; - $i++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } + $total_ht = $total_ht + $objp->amount_ht; + $total_ttc = $total_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } } if ($total_ttc == 0) { - $var=!$var; - print ""; - print ''; - print ''; + $var=!$var; + print ""; + print ''; + print ''; } print ''; @@ -225,13 +240,11 @@ 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"; - $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'"; - } + $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 ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } 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"; @@ -240,53 +253,51 @@ if ($modecompta == 'CREANCES-DETTES') $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'"; - } + $sql .= " WHERE p.rowid = pf.fk_paiementfourn "; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $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"; -print ''; +print ''; $subtotal_ht = 0; $subtotal_ttc = 0; $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - $var=true; - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); - $var=!$var; + $num = $db->num_rows($result); + $i = 0; + $var=true; + if ($num > 0) { + while ($i < $num) { + $objp = $db->fetch_object($result); + $var=!$var; - print ""; - print "\n"; + print ""; + print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; - $total_ht = $total_ht - $objp->amount_ht; - $total_ttc = $total_ttc - $objp->amount_ttc; - $subtotal_ht = $subtotal_ht + $objp->amount_ht; - $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; - print "\n"; - $i++; - } - } - else { - $var=!$var; - print ""; - print ''; - print ''; - } + $total_ht = $total_ht - $objp->amount_ht; + $total_ttc = $total_ttc - $objp->amount_ttc; + $subtotal_ht = $subtotal_ht + $objp->amount_ht; + $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + } + else { + $var=!$var; + print ""; + print ''; + print ''; + } - $db->free($result); + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''; @@ -302,26 +313,22 @@ print ''; print ''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; - $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 = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $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 ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; } else { - $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; - $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 = "SELECT c.libelle as nom, sum(p.amount) as amount"; + $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 ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND s.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; @@ -330,35 +337,35 @@ $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; if ($result) { - $num = $db->num_rows($result); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $var = !$var; - print ""; - print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; - print ''; - print ''; - $i++; - } - } - else { - $var = !$var; - print ""; - print ''; - print ''; - } + $var = !$var; + print ""; + print ''; + if ($modecompta == 'CREANCES-DETTES') print ''; + print ''; + print ''; + $i++; + } + } + else { + $var = !$var; + print ""; + print ''; + print ''; + } } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''; @@ -373,65 +380,61 @@ print ''; print ''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; - $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.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle DESC"; + $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $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 ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; + $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"; - $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 s.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle"; + $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; + $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 ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " GROUP BY c.libelle"; } $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; if ($result) { - $num = $db->num_rows($result); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $var = !$var; - print ""; - print ''; - if ($modecompta == 'CREANCES-DETTES') print ''; - print ''; - print ''; - $i++; - } - } - else { - $var = !$var; - print ""; - print ''; - print ''; - } + $var = !$var; + print ""; + print ''; + if ($modecompta == 'CREANCES-DETTES') print ''; + print ''; + print ''; + $i++; + } + } + else { + $var = !$var; + print ""; + print ''; + print ''; + } } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''; @@ -465,164 +468,156 @@ $subtotal_ttc = 0; 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)"; - if ($year) { - $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // 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)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $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); - $var=false; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $amount = $amount - $obj->amount; - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht - $obj->amount; - $subtotal_ttc = $subtotal_ttc - $obj->amount; - $i++; - } - } - } else { - dol_print_error($db); - } - print ""; - print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; - print "\n"; + $amount = $amount - $obj->amount; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht - $obj->amount; + $subtotal_ttc = $subtotal_ttc - $obj->amount; + $i++; + } + } + } else { + dol_print_error($db); + } + print ""; + print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; + print "\n"; - // 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)"; - if ($year) { - $sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // 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)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $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); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $amount = $amount + $obj->amount; - $total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount = $amount + $obj->amount; + $total_ht = $total_ht + $obj->amount; + $total_ttc = $total_ttc + $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $i++; - } - } - } else { - dol_print_error($db); - } - print ""; - print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; - print "\n"; + $i++; + } + } + } else { + dol_print_error($db); + } + print ""; + print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; + print "\n"; } 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"; - if ($year) { - $sql.= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } - $sql.= " AND t.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // 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"; + if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $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); - $var=false; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $amount = $amount - $obj->amount; - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht - $obj->amount; - $subtotal_ttc = $subtotal_ttc - $obj->amount; + $amount = $amount - $obj->amount; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht - $obj->amount; + $subtotal_ttc = $subtotal_ttc - $obj->amount; - $i++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } - print ""; - print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; - print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } + print ""; + print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; + print "\n"; - // 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"; - if ($year) { - $sql.= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; - } - $sql.= " AND t.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // 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"; + if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $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); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($result); + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); - $amount = $amount + $obj->amount; - $total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount = $amount + $obj->amount; + $total_ht = $total_ht + $obj->amount; + $total_ttc = $total_ttc + $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $i++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } - print ""; - print "\n"; - if ($modecompta == 'CREANCES-DETTES') print "\n"; - print "\n"; - print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } + print ""; + print "\n"; + if ($modecompta == 'CREANCES-DETTES') print "\n"; + print "\n"; + print "\n"; } @@ -637,7 +632,7 @@ if ($mysoc->tva_assuj != 'franchise') // Assujeti if ($mysoc->tva_assuj != 'franchise') // Assujeti { -// Total + // Total print ''; print ''; print ''; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 5e614076249..35a19a00f57 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -39,19 +39,22 @@ else { $year_end=$year_start + ($nbofyear-1); } -/* - * Securite acces client - */ -if ($user->societe_id > 0) -{ - $socid = $user->societe_id; -} +// Security check +$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +if ($user->societe_id > 0) $socid = $user->societe_id; +if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) +accessforbidden(); // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; + +/* + * View + */ + llxHeader(); $html=new Form($db); @@ -151,13 +154,6 @@ if ($modecompta != 'CREANCES-DETTES') { $encaiss[$row->dm] += $row->amount_ht; $encaiss_ttc[$row->dm] += $row->amount_ttc; - // For DEBUG Only - if (preg_match('/^2007/',$row->dm)) - { - $subtotal_ht = $subtotal_ht + $row->amount_ht; - $subtotal_ttc = $subtotal_ttc + $row->amount_ttc; - } - $i++; } } @@ -165,16 +161,7 @@ if ($modecompta != 'CREANCES-DETTES') { dol_print_error($db); } } -/* - print "
Facture clients: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."
\n"; - for ($mois = 1 ; $mois <= 12 ; $mois++) - { - $annee = 2007; - $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); - print 'Mois '.$mois.': '.$decaiss_ttc[$case].' '; - print 'Mois '.$mois.': '.$encaiss_ttc[$case].' '; - } - */ + /* * Frais, factures fournisseurs. @@ -210,13 +197,6 @@ if ($result) $decaiss[$row->dm] = $row->amount_ht; $decaiss_ttc[$row->dm] = $row->amount_ttc; - // For DEBUG Only - if (preg_match('/^2007/',$row->dm)) - { - $subtotal_ht = $subtotal_ht + $row->amount_ht; - $subtotal_ttc = $subtotal_ttc + $row->amount_ttc; - } - $i++; } $db->free($result); @@ -224,16 +204,7 @@ if ($result) else { dol_print_error($db); } -/* - print "
Facture fournisseurs: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."
\n"; - for ($mois = 1 ; $mois <= 12 ; $mois++) - { - $annee = 2007; - $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); - print 'Mois '.$mois.': '.$decaiss_ttc[$case].' '; - print 'Mois '.$mois.': '.$encaiss_ttc[$case].' '; - } - */ + /* * TVA @@ -311,12 +282,6 @@ else { $decaiss[$obj->dm] += $obj->amount; $decaiss_ttc[$obj->dm] += $obj->amount; - // For DEBUG Only - if (preg_match('/^2007/',$obj->dm)) - { - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; - } $i++; } @@ -342,12 +307,6 @@ else { $encaiss[$obj->dm] += $obj->amount; $encaiss_ttc[$obj->dm] += $obj->amount; - // For DEBUG Only - if (preg_match('/^2007/',$obj->dm)) - { - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; - } $i++; } @@ -356,16 +315,6 @@ else { dol_print_error($db); } } -/* - print "
TVA: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."
\n"; - for ($mois = 1 ; $mois <= 12 ; $mois++) - { - $annee = 2007; - $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); - print 'Mois '.$mois.': '.$decaiss_ttc[$case].' '; - print 'Mois '.$mois.': '.$encaiss_ttc[$case].' '; - } - */ /* * Charges sociales non deductibles @@ -378,9 +327,6 @@ if ($modecompta == 'CREANCES-DETTES') { $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'"; - } } 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"; @@ -390,9 +336,6 @@ else { $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 s.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle, dm"; @@ -410,33 +353,17 @@ if ($result) { $decaiss[$obj->dm] += $obj->amount_ht; $decaiss_ttc[$obj->dm] += $obj->amount_ttc; - // For DEBUG Only - if (preg_match('/^2007/',$obj->dm)) - { - $subtotal_ht = $subtotal_ht + $obj->amount_ht; - $subtotal_ttc = $subtotal_ttc + $obj->amount_ttc; - } - $i++; } } } else { dol_print_error($db); } -/* - print "
Charges sociales non deduc: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."
\n"; - for ($mois = 1 ; $mois <= 12 ; $mois++) - { - $annee = 2007; - $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); - print 'Mois '.$mois.': '.$decaiss_ttc[$case].' '; - print 'Mois '.$mois.': '.$encaiss_ttc[$case].' '; - } - */ /* * Charges sociales deductibles */ + $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') @@ -446,9 +373,6 @@ if ($modecompta == 'CREANCES-DETTES') $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'"; - } } else { @@ -459,9 +383,6 @@ else $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 s.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle, dm"; @@ -478,34 +399,19 @@ if ($result) { $decaiss[$obj->dm] += $obj->amount_ht; $decaiss_ttc[$obj->dm] += $obj->amount_ttc; - // For DEBUG Only - if (preg_match('/^2007/',$obj->dm)) - { - $subtotal_ht = $subtotal_ht + $obj->amount_ht; - $subtotal_ttc = $subtotal_ttc + $obj->amount_ttc; - } - $i++; } } } else { dol_print_error($db); } -/* - print "
Charges sociales deduc: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."
\n"; - for ($mois = 1 ; $mois <= 12 ; $mois++) - { - $annee = 2007; - $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); - print 'Mois '.$mois.': '.$decaiss_ttc[$case].' '; - print 'Mois '.$mois.': '.$encaiss_ttc[$case].' '; - } - */ + /* - * Affiche tableau + * Show result array */ + $totentrees=array(); $totsorties=array(); @@ -526,11 +432,12 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) print ''; $var=True; +// Loop on each month for ($mois = 1 ; $mois <= 12 ; $mois++) { $var=!$var; print ''; - print ""; + print ""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); @@ -538,7 +445,7 @@ for ($mois = 1 ; $mois <= 12 ; $mois++) print '"; @@ -546,7 +453,7 @@ for ($mois = 1 ; $mois <= 12 ; $mois++) print '"; diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index 7fc616b2c07..95038eeb20a 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -19,19 +19,22 @@ */ /** - \file htdocs/compta/stats/cabyuser.php - \brief Page reporting CA par utilisateur - \version $Id$ -*/ + * \file htdocs/compta/stats/cabyuser.php + * \brief Page reporting Salesover by user + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); -if (!$user->rights->compta->resultat->lire) - accessforbidden(); +// Security check +$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +if ($user->societe_id > 0) $socid = $user->societe_id; +if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) +accessforbidden(); -$year=$_GET["year"]; -if (! $year) { $year = strftime("%Y", time()); } // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; @@ -41,8 +44,37 @@ $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; if (! $sortorder) $sortorder="asc"; if (! $sortfield) $sortfield="name"; -// Security check -if ($user->societe_id > 0) $socid = $user->societe_id; +// Date range +$year=$_REQUEST["year"]; +if (empty($year)) +{ + $year_current = strftime("%Y",dol_now()); + $year_start = $year_current; +} else { + $year_current = $year; + $year_start = $year; +} +$date_start=dol_mktime($_REQUEST["date_starthour"],$_REQUEST["date_startmin"],$_REQUEST["date_startsec"],$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); +$date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUEST["date_endsec"],$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +// Quarter +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:0; + if ($q==0) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"]); $date_end=dol_get_last_day($year_start,$_REQUEST["month"]); } + else { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,12); } + } + if ($q==1) { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,3); } + if ($q==2) { $date_start=dol_get_first_day($year_start,4); $date_end=dol_get_last_day($year_start,6); } + if ($q==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); } + if ($q==4) { $date_start=dol_get_first_day($year_start,10); $date_end=dol_get_last_day($year_start,12); } +} +else +{ + // TODO We define q + +} /* @@ -59,8 +91,9 @@ if ($modecompta=="CREANCES-DETTES") { $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice"); $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$langs->trans("Year")." $year"; - $periodlink="".img_previous()." ".img_next().""; + //$period=$langs->trans("Year")." $year"; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink="".img_previous()." ".img_next().""; $description=$langs->trans("RulesCADue"); $builddate=time(); $exportlink=$langs->trans("NotYetAvailable"); @@ -68,8 +101,9 @@ if ($modecompta=="CREANCES-DETTES") else { $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice"); $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - $period=$langs->trans("Year")." $year"; - $periodlink="".img_previous()." ".img_next().""; + //$period=$langs->trans("Year")." $year"; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink="".img_previous()." ".img_next().""; $description=$langs->trans("RulesCAIn"); $builddate=time(); $exportlink=$langs->trans("NotYetAvailable"); @@ -85,7 +119,7 @@ if ($modecompta == 'CREANCES-DETTES') $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 ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { @@ -99,11 +133,11 @@ else $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.rowid = pf.fk_paiement"; $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 ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; -$sql .= " GROUP BY rowid"; +$sql .= " GROUP BY rowid, name, firstname"; $sql .= " ORDER BY rowid"; $result = $db->query($sql); @@ -136,7 +170,7 @@ if ($modecompta != 'CREANCES-DETTES') $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'"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY rowid"; $sql.= " ORDER BY rowid"; diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 8fffd9c6cbe..1c0c93dfe76 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * @@ -27,11 +27,11 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); $langs->load("companies"); -$year=$_GET["year"]; -if (! $year) { $year = strftime("%Y", time()); } // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; @@ -41,9 +41,49 @@ $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; if (! $sortorder) $sortorder="asc"; if (! $sortfield) $sortfield="nom"; -// Securite acces client +// Security check +$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; if ($user->societe_id > 0) $socid = $user->societe_id; +if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) +accessforbidden(); +// Date range +$year=$_REQUEST["year"]; +if (empty($year)) +{ + $year_current = strftime("%Y",dol_now()); + $year_start = $year_current; +} else { + $year_current = $year; + $year_start = $year; +} +$date_start=dol_mktime($_REQUEST["date_starthour"],$_REQUEST["date_startmin"],$_REQUEST["date_startsec"],$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); +$date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUEST["date_endsec"],$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); +// Quarter +if (empty($date_start) || empty($date_end)) // We define date_start and date_end +{ + $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:0; + if ($q==0) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"]); $date_end=dol_get_last_day($year_start,$_REQUEST["month"]); } + else { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,12); } + } + if ($q==1) { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,3); } + if ($q==2) { $date_start=dol_get_first_day($year_start,4); $date_end=dol_get_last_day($year_start,6); } + if ($q==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); } + if ($q==4) { $date_start=dol_get_first_day($year_start,10); $date_end=dol_get_last_day($year_start,12); } +} +else +{ + // TODO We define q + +} + + + +/* + * View + */ llxHeader(); @@ -54,8 +94,9 @@ if ($modecompta=="CREANCES-DETTES") { $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties"); $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$langs->trans("Year")." ".$year; - $periodlink=''.img_previous().' '.img_next().''; + //$period=$langs->trans("Year")." ".$year; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; $description=$langs->trans("RulesCADue"); $builddate=time(); $exportlink=$langs->trans("NotYetAvailable"); @@ -63,8 +104,9 @@ if ($modecompta=="CREANCES-DETTES") else { $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties"); $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - $period=$langs->trans("Year")." ".$year; - $periodlink=''.img_previous().' '.img_next().''; + //$period=$langs->trans("Year")." ".$year; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; $description=$langs->trans("RulesCAIn"); $builddate=time(); $exportlink=$langs->trans("NotYetAvailable"); @@ -81,7 +123,7 @@ if ($modecompta == 'CREANCES-DETTES') $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'"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { @@ -97,7 +139,7 @@ else $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 ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -134,7 +176,7 @@ if ($modecompta != 'CREANCES-DETTES') $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'"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY nom"; $sql.= " ORDER BY nom"; diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 5e14c90bf5c..3dd0bd7bf74 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -19,10 +19,10 @@ */ /** - \file htdocs/compta/stats/index.php - \brief Page reporting CA - \version $Id$ -*/ + * \file htdocs/compta/stats/index.php + * \brief Page reporting CA + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); @@ -31,67 +31,69 @@ require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); $year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"]; $year_current = strftime("%Y",time()); if (! $year_start) { - $year_start = $year_current - 4; - $year_end = $year_current; + $year_start = $year_current - 4; + $year_end = $year_current; } else { - $year_end=$year_start + 4; + $year_end=$year_start + 4; } -/* - * Securite acces client - */ -if ($user->societe_id > 0) -{ - $socid = $user->societe_id; -} +// Security check +$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +if ($user->societe_id > 0) $socid = $user->societe_id; +if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) +accessforbidden(); // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') $modecompta = $conf->compta->mode; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; +/* + * View + */ + llxHeader(); $html=new Form($db); -// Affiche en-tête du rapport +// Affiche en-tete du rapport if ($modecompta=="CREANCES-DETTES") { - $nom=$langs->trans("SalesTurnover"); - $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period="$year_start - $year_end"; - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); - $description=$langs->trans("RulesCADue"); - $builddate=time(); - $exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("SalesTurnover"); + $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $period="$year_start - $year_end"; + $periodlink=($year_start?"".img_previous()." ".img_next()."":""); + $description=$langs->trans("RulesCADue"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); } else { - $nom=$langs->trans("SalesTurnover"); - $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - $period="$year_start - $year_end"; - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); - $description=$langs->trans("RulesCAIn"); - $builddate=time(); - $exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("SalesTurnover"); + $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + $period="$year_start - $year_end"; + $periodlink=($year_start?"".img_previous()." ".img_next()."":""); + $description=$langs->trans("RulesCAIn"); + $builddate=time(); + $exportlink=$langs->trans("NotYetAvailable"); } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); -if ($modecompta == 'CREANCES-DETTES') { +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)"; } 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) - */ + /* + * 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"; $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.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -100,58 +102,58 @@ $sql.= " GROUP BY dm DESC"; $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($result); - $cum[$obj->dm] = $obj->amount_ttc; - if ($obj->amount_ttc) - { - $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); - $maxyearmonth=max($maxyearmonth,$obj->dm); - } - $i++; - } - $db->free($result); + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $cum[$obj->dm] = $obj->amount_ttc; + if ($obj->amount_ttc) + { + $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); + $maxyearmonth=max($maxyearmonth,$obj->dm); + } + $i++; + } + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } -// 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."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"; +// On ajoute les paiements 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."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) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($result); - $cum[$obj->dm] += $obj->amount_ttc; - if ($obj->amount_ttc) - { - $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); - $maxyearmonth=max($maxyearmonth,$obj->dm); - } - $i++; - } - } - else { - dol_print_error($db); - } + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $cum[$obj->dm] += $obj->amount_ttc; + if ($obj->amount_ttc) + { + $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); + $maxyearmonth=max($maxyearmonth,$obj->dm); + } + $i++; + } + } + else { + dol_print_error($db); + } } @@ -160,17 +162,17 @@ print '
'; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print ''; - if ($annee != $year_end) print ''; + print ''; + if ($annee != $year_end) print ''; } print ''; print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - print ''; - print ''; - if ($annee != $year_end) print ''; + print ''; + print ''; + if ($annee != $year_end) print ''; } print ''; @@ -184,227 +186,227 @@ $nowyearmonth=strftime("%Y-%m",mktime()); for ($mois = 1 ; $mois < 13 ; $mois++) { - $var=!$var; - print ""; + $var=!$var; + print ""; - print ""; - for ($annee = $year_start ; $annee <= $year_end ; $annee++) - { - $casenow = dol_print_date(mktime(),"%Y-%m"); - $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m"); - $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m"); + print ""; + for ($annee = $year_start ; $annee <= $year_end ; $annee++) + { + $casenow = dol_print_date(mktime(),"%Y-%m"); + $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m"); + $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m"); - if ($annee == $year_current) { - $total_CA += $cum[$case]; - } + if ($annee == $year_current) { + $total_CA += $cum[$case]; + } - // Valeur CA du mois - print '"; + // Valeur CA du mois + print '"; - // Pourcentage du mois - if ($annee > $minyear && $case <= $casenow) { - if ($cum[$caseprev] && $cum[$case]) - { - $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); - //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; - print ''; + // Pourcentage du mois + if ($annee > $minyear && $case <= $casenow) { + if ($cum[$caseprev] && $cum[$case]) + { + $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); + //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; + print ''; - } - if ($cum[$caseprev] && ! $cum[$case]) - { - print ''; - } - if (! $cum[$caseprev] && $cum[$case]) - { - print ''; - } - if (! $cum[$caseprev] && ! $cum[$case]) - { - print ''; - } - } - else - { - print ''; - } + } + if ($cum[$caseprev] && ! $cum[$case]) + { + print ''; + } + if (! $cum[$caseprev] && $cum[$case]) + { + print ''; + } + if (! $cum[$caseprev] && ! $cum[$case]) + { + print ''; + } + } + else + { + print ''; + } - $total[$annee]+=$cum[$case]; - if ($annee != $year_end) print ''; - } + $total[$annee]+=$cum[$case]; + if ($annee != $year_end) print ''; + } - print ''; + print ''; } // Affiche total print ''; for ($annee = $year_start ; $annee <= $year_end ; $annee++) { - // Montant total - if ($annee >= $minyear && $annee <= max($nowyear,$maxyear)) - { - print ""; - } - else - { - print ''; - } + // Montant total + if ($annee >= $minyear && $annee <= max($nowyear,$maxyear)) + { + print ""; + } + else + { + print ''; + } - // Pourcentage total - if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) { - if ($total[$annee-1] && $total[$annee]) { - $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); - print ''; - } - if ($total[$annee-1] && ! $total[$annee]) - { - print ''; - } - if (! $total[$annee-1] && $total[$annee]) - { - print ''; - } - if (! $total[$annee-1] && ! $total[$annee]) - { - print ''; - } - } - else - { - print ''; - } + // Pourcentage total + if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) { + if ($total[$annee-1] && $total[$annee]) { + $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); + print ''; + } + if ($total[$annee-1] && ! $total[$annee]) + { + print ''; + } + if (! $total[$annee-1] && $total[$annee]) + { + print ''; + } + if (! $total[$annee-1] && ! $total[$annee]) + { + print ''; + } + } + else + { + print ''; + } - if ($annee != $year_end) print ''; + if ($annee != $year_end) print ''; } print "\n"; print "
 '.$langs->trans("Element").'".$langs->trans("AmountHT")."".$langs->trans("AmountTTC")."
 
Facturation clients
'.$langs->trans("CustomersInvoices").'
 ".$langs->trans("Bills")." socid."\">$objp->nom
 ".$langs->trans("Bills")." socid."\">$objp->nom".price($objp->amount_ht)."".price($objp->amount_ttc)."".price($objp->amount_ht)."".price($objp->amount_ttc)."
 ".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; + print "
 ".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($objp->amount_ht)."".price($objp->amount_ttc)."".price($objp->amount_ht)."".price($objp->amount_ttc)."
 '.$langs->trans("None").'
 '.$langs->trans("None").'
Facturation fournisseurs
'.$langs->trans("SuppliersInvoices").'
 ".$langs->trans("Bills")." socid."\">".$objp->nom."
 ".$langs->trans("Bills")." socid."\">".$objp->nom."".price(-$objp->amount_ht)."".price(-$objp->amount_ttc)."".price(-$objp->amount_ht)."".price(-$objp->amount_ttc)."
 '.$langs->trans("None").'
 '.$langs->trans("None").'
'.price(-$subtotal_ht).'
Prestations/Charges NON deductibles
 '.$obj->nom.''.price(-$obj->amount).''.price(-$obj->amount).'
 '.$langs->trans("None").'
 '.$obj->nom.''.price(-$obj->amount).''.price(-$obj->amount).'
 '.$langs->trans("None").'
'.price(-$subtotal_ht).'
Prestations/Charges deductibles
 '.$obj->nom.''.price(-$obj->amount).''.price(-$obj->amount).'
 '.$langs->trans("None").'
 '.$obj->nom.''.price(-$obj->amount).''.price(-$obj->amount).'
 '.$langs->trans("None").'
'.price(-$subtotal_ht).'
 ".$langs->trans("VATToPay")."".price($amount)."".price($amount)."
 ".$langs->trans("VATToPay")."".price($amount)."".price($amount)."
 ".$langs->trans("VATToCollect")."".price($amount)."".price($amount)."
 ".$langs->trans("VATToCollect")."".price($amount)."".price($amount)."
 ".$langs->trans("VATPaid")."".price($amount)."".price($amount)."
 ".$langs->trans("VATPaid")."".price($amount)."".price($amount)."
 ".$langs->trans("VATCollected")."".price($amount)."".price($amount)."
 ".$langs->trans("VATCollected")."".price($amount)."".price($amount)."
 
".dol_print_date(dol_mktime(12,0,0,$mois,1,$annee),"%b")."".dol_print_date(dol_mktime(12,0,0,$mois,1,$annee),"%B")." '; if ($decaiss_ttc[$case] != 0) { - print price($decaiss_ttc[$case]); + print ''.price($decaiss_ttc[$case]).''; $totsorties[$annee]+=$decaiss_ttc[$case]; } print " '; if ($encaiss_ttc[$case] != 0) { - print price($encaiss_ttc[$case]); + print ''.price($encaiss_ttc[$case]).''; $totentrees[$annee]+=$encaiss_ttc[$case]; } print "
'.$langs->trans("Month").''.$annee.' '.$annee.' 
'.$langs->trans("AmountTTC").''.$langs->trans("Delta").' '.$langs->trans("AmountTTC").''.$langs->trans("Delta").' 
".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%b")."".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."'; - if ($cum[$case]) - { - $now_show_delta=1; // On a trouvé le premier mois de la première année générant du chiffre. - print price($cum[$case],1); - } - else - { - if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; } - else { print ' '; } - } - print "'; + if ($cum[$case]) + { + $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre. + print ''.price($cum[$case],1).''; + } + else + { + if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; } + else { print ' '; } + } + print "'.($percent>=0?"+$percent":"$percent").'%'.($percent>=0?"+$percent":"$percent").'%-100%+Inf%+0%'; - if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } - else { print ' '; } - print '-100%+Inf%+0%'; + if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } + else { print ' '; } + print '  
'.$langs->trans("Total").'".($total[$annee]?price($total[$annee]):"0")." ".($total[$annee]?price($total[$annee]):"0")." '.($percent>=0?"+$percent":"$percent").'%-100%+Inf%+0%'; - if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; } - else { print ' '; } - print ''.($percent>=0?"+$percent":"$percent").'%-100%+Inf%+0%'; + if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; } + else { print ' '; } + print '  
"; /* - * En mode recettes/dépenses, on complète avec les montants facturés non réglés - * et les propales signées mais pas facturées. En effet, en recettes-dépenses, - * on comptabilise lorsque le montant est sur le compte donc il est intéressant + * En mode recettes/depenses, on complete avec les montants factures non regles + * et les propales signees mais pas facturees. En effet, en recettes-depenses, + * on comptabilise lorsque le montant est sur le compte donc il est interessant * d'avoir une vision de ce qui va arriver. */ /* -Je commente toute cette partie car les chiffres affichées sont faux - Eldy. -En attendant correction. + Je commente toute cette partie car les chiffres affichees sont faux - Eldy. + En attendant correction. -if ($modecompta != 'CREANCES-DETTES') -{ - - print '
'; + if ($modecompta != 'CREANCES-DETTES') + { - // Factures non réglées - // \todo Y a bug ici. Il faut prendre le reste à payer et non le total des factures non réglèes ! + print '
'; - $sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; - $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; - if ($socid) - { - $sql .= " AND f.fk_soc = $socid"; - } - $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc"; - - if ( $db->query($sql) ) - { - $num = $db->num_rows(); - $i = 0; - - if ($num) - { - $var = True; - $total_ttc_Rac = $totalam_Rac = $total_Rac = 0; - while ($i < $num) - { - $obj = $db->fetch_object(); - $total_ttc_Rac += $obj->total_ttc; - $totalam_Rac += $obj->am; - $i++; - } - $var=!$var; - print ""; - $total_CA +=$total_ttc_Rac; - } - $db->free(); - } - else - { - dol_print_error($db); - } -*/ + // Factures non reglees + // \todo Y a bug ici. Il faut prendre le reste a payer et non le total des factures non reglees ! + + $sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; + $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; + if ($socid) + { + $sql .= " AND f.fk_soc = $socid"; + } + $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc"; + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + + if ($num) + { + $var = True; + $total_ttc_Rac = $totalam_Rac = $total_Rac = 0; + while ($i < $num) + { + $obj = $db->fetch_object(); + $total_ttc_Rac += $obj->total_ttc; + $totalam_Rac += $obj->am; + $i++; + } + $var=!$var; + print ""; + $total_CA +=$total_ttc_Rac; + } + $db->free(); + } + else + { + dol_print_error($db); + } + */ /* -* -* Propales signées, et non facturées -* -*/ + * + * Propales signees, et non facturees + * + */ /* -Je commente toute cette partie car les chiffres affichées sont faux - Eldy. -En attendant correction. + Je commente toute cette partie car les chiffres affichees sont faux - Eldy. + En attendant correction. - $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc - FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s - LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid - LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid - WHERE p.fk_soc = s.rowid - AND p.fk_statut >=1 - AND p.facture =0"; - if ($socid) - { - $sql .= " AND f.fk_soc = ".$socid; - } - $sql .= " GROUP BY p.rowid"; + $sql = "SELECT sum(f.total) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc + FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s + LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid + LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid + WHERE p.fk_soc = s.rowid + AND p.fk_statut >=1 + AND p.facture =0"; + if ($socid) + { + $sql .= " AND f.fk_soc = ".$socid; + } + $sql .= " GROUP BY p.rowid"; - if ( $db->query($sql) ) - { - $num = $db->num_rows(); - $i = 0; - - if ($num) - { - $var = True; - $total_pr = 0; - while ($i < $num) - { - $obj = $db->fetch_object(); - $total_pr += $obj->total_ttc-$obj->tot_fttc; - $i++; - } - $var=!$var; - print ""; - $total_CA += $total_pr; - } - $db->free(); - } - else - { - dol_print_error($db); - } - print ""; -} -print "
Facturé à encaisser : ".price($total_ttc_Rac)."<-- bug ici car n'exclut pas le deja réglé des factures partiellement réglées
Facture a encaisser : ".price($total_ttc_Rac)."<-- bug ici car n'exclut pas le deja r�gl� des factures partiellement r�gl�es
Signé et non facturé:".price($total_pr)."<-- bug ici, ca devrait exclure le déjà facturé
Total CA prévisionnel : ".price($total_CA)."<-- bug ici car bug sur les 2 précédents
"; + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; -*/ + if ($num) + { + $var = True; + $total_pr = 0; + while ($i < $num) + { + $obj = $db->fetch_object(); + $total_pr += $obj->total_ttc-$obj->tot_fttc; + $i++; + } + $var=!$var; + print "Signe et non facture:".price($total_pr)."<-- bug ici, ca devrait exclure le deja facture"; + $total_CA += $total_pr; + } + $db->free(); + } + else + { + dol_print_error($db); + } + print "Total CA previsionnel : ".price($total_CA)."<-- bug ici car bug sur les 2 precedents"; + } + print ""; + + */ $db->close(); diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php index da248c401d5..69a28b68f01 100644 --- a/htdocs/compta/tva/clients.php +++ b/htdocs/compta/tva/clients.php @@ -52,7 +52,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:1; // TODO Set current quarter + $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:0; + if ($q==0) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"]); $date_end=dol_get_last_day($year_start,$_REQUEST["month"]); } + else $q=1; + } if ($q==1) { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,3); } if ($q==2) { $date_start=dol_get_first_day($year_start,4); $date_end=dol_get_last_day($year_start,6); } if ($q==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); } diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index e93b8f52f8d..624c3ee38c3 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -58,7 +58,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:1; // TODO Set current quarter + $q=(! empty($_REQUEST["q"]))?$_REQUEST["q"]:0; + if ($q==0) + { + if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"]); $date_end=dol_get_last_day($year_start,$_REQUEST["month"]); } + else $q=1; + } if ($q==1) { $date_start=dol_get_first_day($year_start,1); $date_end=dol_get_last_day($year_start,3); } if ($q==2) { $date_start=dol_get_first_day($year_start,4); $date_end=dol_get_last_day($year_start,6); } if ($q==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); } diff --git a/htdocs/includes/modules/modComptabilite.class.php b/htdocs/includes/modules/modComptabilite.class.php index b37a88eda74..b3c88311c7c 100644 --- a/htdocs/includes/modules/modComptabilite.class.php +++ b/htdocs/includes/modules/modComptabilite.class.php @@ -20,7 +20,7 @@ */ /** \defgroup comptabilite Module comptabilite - \brief Module pour inclure des fonctions de comptabilit� (gestion de comptes comptables et rapports) + \brief Module pour inclure des fonctions de comptabilite (gestion de comptes comptables et rapports) \version $Id$ */ diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 8db1b16f6ae..f9b4561bf2a 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -359,7 +359,7 @@ Size=Size Received=Received Paid=Paid Topic=Sujet -ByCompanies=By companies +ByCompanies=By third parties ByUsers=By users Links=Links Link=Link diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 0d6b33ffe85..cad5c913911 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -358,7 +358,7 @@ Size=Taille Received=Reçu Paid=Payé Topic=Sujet -ByCompanies=Par société +ByCompanies=Par tiers ByUsers=Par utilisateur Links=Liens Link=Lien diff --git a/htdocs/lib/date.lib.php b/htdocs/lib/date.lib.php index cb69287b5a7..7b7cd2ab186 100644 --- a/htdocs/lib/date.lib.php +++ b/htdocs/lib/date.lib.php @@ -154,7 +154,7 @@ function dol_get_last_day($year,$month=12) } // On se deplace au debut du mois suivant, et on retire un jour - $datelim=dol_mktime(0,0,0,$month,1,$year,1); + $datelim=dol_mktime(23,59,59,$month,1,$year,1); $datelim -= (3600 * 24); return $datelim;