2
0
forked from Wavyzz/dolibarr

Debug reporting

This commit is contained in:
Laurent Destailleur
2010-02-02 23:23:20 +00:00
parent d82fff31d4
commit c19fe2dfa0
11 changed files with 779 additions and 789 deletions

View File

@@ -28,12 +28,17 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/tva/tva.class.php");
require_once(DOL_DOCUMENT_ROOT."/chargesociales.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/report.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/tax.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
$langs->load("bills"); $langs->load("bills");
if (!$user->rights->facture->lire) // Security check
accessforbidden(); $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 // Date range
$year=$_REQUEST["year"]; $year=$_REQUEST["year"];
@@ -50,7 +55,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES
// Quarter // Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end 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==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==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==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(); llxHeader();
$html=new Form($db); $html=new Form($db);
@@ -75,60 +89,61 @@ $html=new Form($db);
// Affiche en-tete de rapport // Affiche en-tete de rapport
if ($modecompta=="CREANCES-DETTES") if ($modecompta=="CREANCES-DETTES")
{ {
$nom=$langs->trans("AnnualByCompaniesDueDebtMode"); $nom=$langs->trans("AnnualByCompaniesDueDebtMode");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period=$langs->trans("Year")." ".$year; //$period=$langs->trans("Year")." ".$year;
$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; $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);
$description=$langs->trans("RulesResultDue"); //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
$builddate=time(); $description=$langs->trans("RulesResultDue");
$exportlink=$langs->trans("NotYetAvailable"); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
} }
else { else {
$nom=$langs->trans("AnnualByCompaniesInputOutputMode"); $nom=$langs->trans("AnnualByCompaniesInputOutputMode");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$period=$langs->trans("Year")." ".$year; //$period=$langs->trans("Year")." ".$year;
$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; $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);
$description=$langs->trans("RulesResultInOut"); //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
$builddate=time(); $description=$langs->trans("RulesResultInOut");
$exportlink=$langs->trans("NotYetAvailable"); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
} }
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
// Affiche rapport // Show report array
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="10%">&nbsp;</td><td>'.$langs->trans("Element").'</td>'; print '<td width="10%">&nbsp;</td><td>'.$langs->trans("Element").'</td>';
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".$langs->trans("AmountHT")."</td>"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".$langs->trans("AmountHT")."</td>";
print "<td align=\"right\">".$langs->trans("AmountTTC")."</td>"; print "<td align=\"right\">".$langs->trans("AmountTTC")."</td>";
print "</tr>\n"; print "</tr>\n";
print '<tr><td colspan="4">&nbsp;</td></tr>';
/* /*
* Factures clients * Factures clients
*/ */
print '<tr><td colspan="4">Facturation clients</td></tr>'; print '<tr><td colspan="4">'.$langs->trans("CustomersInvoices").'</td></tr>';
if ($modecompta == 'CREANCES-DETTES') { 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 = "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.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.fk_statut in (1,2)"; $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'"; if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
} else { } else {
/* /*
* Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * 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) * 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 = "SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
$sql.= " WHERE p.rowid = pf.fk_paiement"; $sql.= " WHERE p.rowid = pf.fk_paiement";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.fk_soc = s.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; $sql.= " AND f.entity = ".$conf->entity;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
@@ -137,80 +152,80 @@ $sql.= " ORDER BY nom";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
$var=true; $var=true;
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socid=".$objp->socid."\">$objp->nom</td>\n"; print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socid=".$objp->socid."\">$objp->nom</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n";
print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n"; print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n";
$total_ht = $total_ht + $objp->amount_ht; $total_ht = $total_ht + $objp->amount_ht;
$total_ttc = $total_ttc + $objp->amount_ttc; $total_ttc = $total_ttc + $objp->amount_ttc;
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
$db->free($result); $db->free($result);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
// On ajoute les paiements clients anciennes version, non lie par paiement_facture // On ajoute les paiements clients anciennes version, non lie par paiement_facture
if ($modecompta != 'CREANCES-DETTES') if ($modecompta != 'CREANCES-DETTES')
{ {
$sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " WHERE pf.rowid IS NULL"; $sql.= " WHERE pf.rowid IS NULL";
$sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND p.fk_bank = b.rowid";
$sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND b.fk_account = ba.rowid";
$sql.= " AND ba.entity = ".$conf->entity; $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.= " GROUP BY nom";
$sql.= " ORDER BY nom"; $sql.= " ORDER BY nom";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($objp->amount_ht)."</td>\n";
print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n"; print "<td align=\"right\">".price($objp->amount_ttc)."</td>\n";
$total_ht = $total_ht + $objp->amount_ht; $total_ht = $total_ht + $objp->amount_ht;
$total_ttc = $total_ttc + $objp->amount_ttc; $total_ttc = $total_ttc + $objp->amount_ttc;
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
} }
$db->free($result); $db->free($result);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
} }
if ($total_ttc == 0) if ($total_ttc == 0)
{ {
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>'; print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>'; print '</tr>';
} }
print '<tr class="liste_total">'; print '<tr class="liste_total">';
@@ -225,13 +240,11 @@ print '</tr>';
if ($modecompta == 'CREANCES-DETTES') 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 = "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.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
$sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.fk_statut in (1,2)"; $sql.= " AND f.fk_statut in (1,2)";
if ($year) { if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$sql.= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
} else { } else {
$sql = "SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; $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"; $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
@@ -240,53 +253,51 @@ if ($modecompta == 'CREANCES-DETTES')
$sql .= " ON pf.fk_facturefourn = f.rowid"; $sql .= " ON pf.fk_facturefourn = f.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
$sql .= " ON f.fk_soc = s.rowid"; $sql .= " ON f.fk_soc = s.rowid";
$sql .= " WHERE p.rowid = pf.fk_paiementfourn "; $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
if ($year) { if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
$sql.= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity = ".$conf->entity;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql .= " GROUP BY nom, s.rowid"; $sql .= " GROUP BY nom, s.rowid";
$sql .= " ORDER BY nom, s.rowid"; $sql .= " ORDER BY nom, s.rowid";
print '<tr><td colspan="4">Facturation fournisseurs</td></tr>'; print '<tr><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
$subtotal_ht = 0; $subtotal_ht = 0;
$subtotal_ttc = 0; $subtotal_ttc = 0;
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
$var=true; $var=true;
if ($num > 0) { if ($num > 0) {
while ($i < $num) { while ($i < $num) {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("Bills")." <a href=\"".DOL_URL_ROOT."/fourn/facture/index.php?socid=".$objp->socid."\">".$objp->nom."</a></td>\n"; print "<td>".$langs->trans("Bills")." <a href=\"".DOL_URL_ROOT."/fourn/facture/index.php?socid=".$objp->socid."\">".$objp->nom."</a></td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price(-$objp->amount_ht)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price(-$objp->amount_ht)."</td>\n";
print "<td align=\"right\">".price(-$objp->amount_ttc)."</td>\n"; print "<td align=\"right\">".price(-$objp->amount_ttc)."</td>\n";
$total_ht = $total_ht - $objp->amount_ht; $total_ht = $total_ht - $objp->amount_ht;
$total_ttc = $total_ttc - $objp->amount_ttc; $total_ttc = $total_ttc - $objp->amount_ttc;
$subtotal_ht = $subtotal_ht + $objp->amount_ht; $subtotal_ht = $subtotal_ht + $objp->amount_ht;
$subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc;
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
} }
else { else {
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>'; print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>'; print '</tr>';
} }
$db->free($result); $db->free($result);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print '<tr class="liste_total">'; print '<tr class="liste_total">';
if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>'; if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
@@ -302,26 +313,22 @@ print '</tr>';
print '<tr><td colspan="4">Prestations/Charges NON deductibles</td></tr>'; print '<tr><td colspan="4">Prestations/Charges NON deductibles</td></tr>';
if ($modecompta == 'CREANCES-DETTES') { if ($modecompta == 'CREANCES-DETTES') {
$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; $sql = "SELECT c.libelle as nom, sum(s.amount) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= " WHERE s.fk_type = c.id"; $sql.= " WHERE s.fk_type = c.id";
$sql.= " AND c.deductible = 0"; $sql.= " AND c.deductible = 0";
if ($year) { 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.date_ech between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'";
}
} }
else { else {
$sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; $sql = "SELECT c.libelle as nom, sum(p.amount) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p";
$sql.= " WHERE p.fk_charge = s.rowid"; $sql.= " WHERE p.fk_charge = s.rowid";
$sql.= " AND s.fk_type = c.id"; $sql.= " AND s.fk_type = c.id";
$sql.= " AND c.deductible = 0"; $sql.= " AND c.deductible = 0";
if ($year) { if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
$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.= " AND s.entity = ".$conf->entity;
$sql.= " GROUP BY c.libelle"; $sql.= " GROUP BY c.libelle";
@@ -330,35 +337,35 @@ $result=$db->query($sql);
$subtotal_ht = 0; $subtotal_ht = 0;
$subtotal_ttc = 0; $subtotal_ttc = 0;
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=true; $var=true;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$total_ht = $total_ht - $obj->amount; $total_ht = $total_ht - $obj->amount;
$total_ttc = $total_ttc - $obj->amount; $total_ttc = $total_ttc - $obj->amount;
$subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount;
$subtotal_ttc = $subtotal_ttc + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount;
$var = !$var; $var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>'; print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>'; if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>'; print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>'; print '</tr>';
$i++; $i++;
} }
} }
else { else {
$var = !$var; $var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>'; print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>'; print '</tr>';
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print '<tr class="liste_total">'; print '<tr class="liste_total">';
if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>'; if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
@@ -373,65 +380,61 @@ print '</tr>';
print '<tr><td colspan="4">Prestations/Charges deductibles</td></tr>'; print '<tr><td colspan="4">Prestations/Charges deductibles</td></tr>';
if ($modecompta == 'CREANCES-DETTES') { if ($modecompta == 'CREANCES-DETTES') {
$sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; $sql = "SELECT c.libelle as nom, sum(s.amount) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= " WHERE s.fk_type = c.id"; $sql.= " WHERE s.fk_type = c.id";
$sql.= " AND c.deductible = 1"; $sql.= " AND c.deductible = 1";
if ($year) { 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.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.= " AND s.entity = ".$conf->entity;
$sql.= " GROUP BY c.libelle DESC";
} }
else { else {
$sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; $sql = "SELECT c.libelle as nom, sum(p.amount) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p";
$sql .= " WHERE p.fk_charge = s.rowid"; $sql .= " WHERE p.fk_charge = s.rowid";
$sql.= " AND s.fk_type = c.id"; $sql.= " AND s.fk_type = c.id";
$sql.= " AND c.deductible = 1"; $sql.= " AND c.deductible = 1";
if ($year) { if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
$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.= " AND s.entity = ".$conf->entity;
$sql.= " GROUP BY c.libelle";
} }
$result=$db->query($sql); $result=$db->query($sql);
$subtotal_ht = 0; $subtotal_ht = 0;
$subtotal_ttc = 0; $subtotal_ttc = 0;
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=true; $var=true;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$total_ht = $total_ht - $obj->amount; $total_ht = $total_ht - $obj->amount;
$total_ttc = $total_ttc - $obj->amount; $total_ttc = $total_ttc - $obj->amount;
$subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount;
$subtotal_ttc = $subtotal_ttc + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount;
$var = !$var; $var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>'; print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>'; if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>'; print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>'; print '</tr>';
$i++; $i++;
} }
} }
else { else {
$var = !$var; $var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>'; print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>'; print '</tr>';
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print '<tr class="liste_total">'; print '<tr class="liste_total">';
if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>'; if ($modecompta == 'CREANCES-DETTES') print '<td colspan="3" align="right">'.price(-$subtotal_ht).'</td>';
@@ -465,164 +468,156 @@ $subtotal_ttc = 0;
if ($modecompta == 'CREANCES-DETTES') if ($modecompta == 'CREANCES-DETTES')
{ {
// TVA a payer // TVA a payer
$amount=0; $amount=0;
$sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
if ($year) { if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$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.= " AND f.entity = ".$conf->entity; $sql.= " ORDER BY dm DESC";
$sql.= " GROUP BY dm";
$sql.= " ORDER BY dm DESC";
$result=$db->query($sql); $result=$db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=false; $var=false;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$amount = $amount - $obj->amount; $amount = $amount - $obj->amount;
$total_ht = $total_ht - $obj->amount; $total_ht = $total_ht - $obj->amount;
$total_ttc = $total_ttc - $obj->amount; $total_ttc = $total_ttc - $obj->amount;
$subtotal_ht = $subtotal_ht - $obj->amount; $subtotal_ht = $subtotal_ht - $obj->amount;
$subtotal_ttc = $subtotal_ttc - $obj->amount; $subtotal_ttc = $subtotal_ttc - $obj->amount;
$i++; $i++;
} }
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToPay")."</td>\n"; print "<td>".$langs->trans("VATToPay")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n"; print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n"; print "</tr>\n";
// TVA a recuperer // TVA a recuperer
$amount=0; $amount=0;
$sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; $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.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
if ($year) { if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$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.= " AND f.entity = ".$conf->entity; $sql.= " ORDER BY dm DESC";
$sql.= " GROUP BY dm";
$sql.= " ORDER BY dm DESC";
$result=$db->query($sql); $result=$db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=true; $var=true;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$amount = $amount + $obj->amount; $amount = $amount + $obj->amount;
$total_ht = $total_ht + $obj->amount; $total_ht = $total_ht + $obj->amount;
$total_ttc = $total_ttc + $obj->amount; $total_ttc = $total_ttc + $obj->amount;
$subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount;
$subtotal_ttc = $subtotal_ttc + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount;
$i++; $i++;
} }
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToCollect")."</td>\n"; print "<td>".$langs->trans("VATToCollect")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n"; print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n"; print "</tr>\n";
} }
else else
{ {
// TVA reellement deja payee // TVA reellement deja payee
$amount=0; $amount=0;
$sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql.= " WHERE amount > 0"; $sql.= " WHERE amount > 0";
if ($year) { if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
$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.= " AND t.entity = ".$conf->entity; $sql.= " ORDER BY dm DESC";
$sql.= " GROUP BY dm";
$sql.= " ORDER BY dm DESC";
$result=$db->query($sql); $result=$db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=false; $var=false;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$amount = $amount - $obj->amount; $amount = $amount - $obj->amount;
$total_ht = $total_ht - $obj->amount; $total_ht = $total_ht - $obj->amount;
$total_ttc = $total_ttc - $obj->amount; $total_ttc = $total_ttc - $obj->amount;
$subtotal_ht = $subtotal_ht - $obj->amount; $subtotal_ht = $subtotal_ht - $obj->amount;
$subtotal_ttc = $subtotal_ttc - $obj->amount; $subtotal_ttc = $subtotal_ttc - $obj->amount;
$i++; $i++;
} }
} }
$db->free($result); $db->free($result);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATPaid")."</td>\n"; print "<td>".$langs->trans("VATPaid")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n"; print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n"; print "</tr>\n";
// TVA recuperee // TVA recuperee
$amount=0; $amount=0;
$sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql.= " WHERE amount < 0"; $sql.= " WHERE amount < 0";
if ($year) { if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
$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.= " AND t.entity = ".$conf->entity; $sql.= " ORDER BY dm DESC";
$sql.= " GROUP BY dm";
$sql.= " ORDER BY dm DESC";
$result=$db->query($sql); $result=$db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$var=true; $var=true;
$i = 0; $i = 0;
if ($num) { if ($num) {
while ($i < $num) { while ($i < $num) {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$amount = $amount + $obj->amount; $amount = $amount + $obj->amount;
$total_ht = $total_ht + $obj->amount; $total_ht = $total_ht + $obj->amount;
$total_ttc = $total_ttc + $obj->amount; $total_ttc = $total_ttc + $obj->amount;
$subtotal_ht = $subtotal_ht + $obj->amount; $subtotal_ht = $subtotal_ht + $obj->amount;
$subtotal_ttc = $subtotal_ttc + $obj->amount; $subtotal_ttc = $subtotal_ttc + $obj->amount;
$i++; $i++;
} }
} }
$db->free($result); $db->free($result);
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
print "<tr $bc[$var]><td>&nbsp;</td>"; print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATCollected")."</td>\n"; print "<td>".$langs->trans("VATCollected")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n"; if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n"; print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n"; print "</tr>\n";
} }
@@ -637,7 +632,7 @@ if ($mysoc->tva_assuj != 'franchise') // Assujeti
if ($mysoc->tva_assuj != 'franchise') // Assujeti if ($mysoc->tva_assuj != 'franchise') // Assujeti
{ {
// Total // Total
print '<tr>'; print '<tr>';
print '<td colspan="4">&nbsp;</td>'; print '<td colspan="4">&nbsp;</td>';
print '</tr>'; print '</tr>';

View File

@@ -39,19 +39,22 @@ else {
$year_end=$year_start + ($nbofyear-1); $year_end=$year_start + ($nbofyear-1);
} }
/* // Security check
* Securite acces client $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:'';
*/ if ($user->societe_id > 0) $socid = $user->societe_id;
if ($user->societe_id > 0) if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire)
{ accessforbidden();
$socid = $user->societe_id;
}
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->compta->mode; $modecompta = $conf->compta->mode;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
/*
* View
*/
llxHeader(); llxHeader();
$html=new Form($db); $html=new Form($db);
@@ -151,13 +154,6 @@ if ($modecompta != 'CREANCES-DETTES') {
$encaiss[$row->dm] += $row->amount_ht; $encaiss[$row->dm] += $row->amount_ht;
$encaiss_ttc[$row->dm] += $row->amount_ttc; $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++; $i++;
} }
} }
@@ -165,16 +161,7 @@ if ($modecompta != 'CREANCES-DETTES') {
dol_print_error($db); dol_print_error($db);
} }
} }
/*
print "<br>Facture clients: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."<br>\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. * Frais, factures fournisseurs.
@@ -210,13 +197,6 @@ if ($result)
$decaiss[$row->dm] = $row->amount_ht; $decaiss[$row->dm] = $row->amount_ht;
$decaiss_ttc[$row->dm] = $row->amount_ttc; $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++; $i++;
} }
$db->free($result); $db->free($result);
@@ -224,16 +204,7 @@ if ($result)
else { else {
dol_print_error($db); dol_print_error($db);
} }
/*
print "<br>Facture fournisseurs: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."<br>\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 * TVA
@@ -311,12 +282,6 @@ else {
$decaiss[$obj->dm] += $obj->amount; $decaiss[$obj->dm] += $obj->amount;
$decaiss_ttc[$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++; $i++;
} }
@@ -342,12 +307,6 @@ else {
$encaiss[$obj->dm] += $obj->amount; $encaiss[$obj->dm] += $obj->amount;
$encaiss_ttc[$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++; $i++;
} }
@@ -356,16 +315,6 @@ else {
dol_print_error($db); dol_print_error($db);
} }
} }
/*
print "<br>TVA: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."<br>\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 * Charges sociales non deductibles
@@ -378,9 +327,6 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= " WHERE s.fk_type = c.id"; $sql.= " WHERE s.fk_type = c.id";
$sql.= " AND c.deductible = 0"; $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 { 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 = "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.= " WHERE p.fk_charge = s.rowid";
$sql.= " AND s.fk_type = c.id"; $sql.= " AND s.fk_type = c.id";
$sql.= " AND c.deductible = 0"; $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.= " AND s.entity = ".$conf->entity;
$sql.= " GROUP BY c.libelle, dm"; $sql.= " GROUP BY c.libelle, dm";
@@ -410,33 +353,17 @@ if ($result) {
$decaiss[$obj->dm] += $obj->amount_ht; $decaiss[$obj->dm] += $obj->amount_ht;
$decaiss_ttc[$obj->dm] += $obj->amount_ttc; $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++; $i++;
} }
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
/*
print "<br>Charges sociales non deduc: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."<br>\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 * Charges sociales deductibles
*/ */
$subtotal_ht = 0; $subtotal_ht = 0;
$subtotal_ttc = 0; $subtotal_ttc = 0;
if ($modecompta == 'CREANCES-DETTES') if ($modecompta == 'CREANCES-DETTES')
@@ -446,9 +373,6 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s";
$sql.= " WHERE s.fk_type = c.id"; $sql.= " WHERE s.fk_type = c.id";
$sql.= " AND c.deductible = 1"; $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 else
{ {
@@ -459,9 +383,6 @@ else
$sql.= " WHERE p.fk_charge = s.rowid"; $sql.= " WHERE p.fk_charge = s.rowid";
$sql.= " AND s.fk_type = c.id"; $sql.= " AND s.fk_type = c.id";
$sql.= " AND c.deductible = 1"; $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.= " AND s.entity = ".$conf->entity;
$sql.= " GROUP BY c.libelle, dm"; $sql.= " GROUP BY c.libelle, dm";
@@ -478,34 +399,19 @@ if ($result) {
$decaiss[$obj->dm] += $obj->amount_ht; $decaiss[$obj->dm] += $obj->amount_ht;
$decaiss_ttc[$obj->dm] += $obj->amount_ttc; $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++; $i++;
} }
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
/*
print "<br>Charges sociales deduc: subtotal_ht=".$subtotal_ht.' - subtotal_ttc='.$subtotal_ttc."<br>\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(); $totentrees=array();
$totsorties=array(); $totsorties=array();
@@ -526,11 +432,12 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
print '</tr>'; print '</tr>';
$var=True; $var=True;
// Loop on each month
for ($mois = 1 ; $mois <= 12 ; $mois++) for ($mois = 1 ; $mois <= 12 ; $mois++)
{ {
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,$annee),"%b")."</td>"; print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,$annee),"%B")."</td>";
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
$case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee)); $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois,1,$annee));
@@ -538,7 +445,7 @@ for ($mois = 1 ; $mois <= 12 ; $mois++)
print '<td align="right">&nbsp;'; print '<td align="right">&nbsp;';
if ($decaiss_ttc[$case] != 0) if ($decaiss_ttc[$case] != 0)
{ {
print price($decaiss_ttc[$case]); print '<a href="clientfourn.php?year='.$annee.'&month='.$mois.'">'.price($decaiss_ttc[$case]).'</a>';
$totsorties[$annee]+=$decaiss_ttc[$case]; $totsorties[$annee]+=$decaiss_ttc[$case];
} }
print "</td>"; print "</td>";
@@ -546,7 +453,7 @@ for ($mois = 1 ; $mois <= 12 ; $mois++)
print '<td align="right">&nbsp;'; print '<td align="right">&nbsp;';
if ($encaiss_ttc[$case] != 0) if ($encaiss_ttc[$case] != 0)
{ {
print price($encaiss_ttc[$case]); print '<a href="clientfourn.php?year='.$annee.'&month='.$mois.'">'.price($encaiss_ttc[$case]).'</a>';
$totentrees[$annee]+=$encaiss_ttc[$case]; $totentrees[$annee]+=$encaiss_ttc[$case];
} }
print "</td>"; print "</td>";

View File

@@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -19,19 +19,22 @@
*/ */
/** /**
\file htdocs/compta/stats/cabyuser.php * \file htdocs/compta/stats/cabyuser.php
\brief Page reporting CA par utilisateur * \brief Page reporting Salesover by user
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.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) // Security check
accessforbidden(); $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') // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->compta->mode; $modecompta = $conf->compta->mode;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
@@ -41,8 +44,37 @@ $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
if (! $sortorder) $sortorder="asc"; if (! $sortorder) $sortorder="asc";
if (! $sortfield) $sortfield="name"; if (! $sortfield) $sortfield="name";
// Security check // Date range
if ($user->societe_id > 0) $socid = $user->societe_id; $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("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period=$langs->trans("Year")." $year"; //$period=$langs->trans("Year")." $year";
$periodlink="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>"; $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="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
$description=$langs->trans("RulesCADue"); $description=$langs->trans("RulesCADue");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
@@ -68,8 +101,9 @@ if ($modecompta=="CREANCES-DETTES")
else { else {
$nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice"); $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$period=$langs->trans("Year")." $year"; //$period=$langs->trans("Year")." $year";
$periodlink="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>"; $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="<a href='".$_SERVER["PHP_SELF"]."?year=".($year-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year+1)."&modecompta=".$modecompta."'>".img_next()."</a>";
$description=$langs->trans("RulesCAIn"); $description=$langs->trans("RulesCAIn");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
@@ -85,7 +119,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $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.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.fk_user_author = u.rowid";
$sql.= " WHERE f.fk_statut in (1,2) "; $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 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_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.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.rowid = pf.fk_paiement";
$sql.= " WHERE 1=1"; $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; $sql.= " AND f.entity = ".$conf->entity;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql .= " GROUP BY rowid"; $sql .= " GROUP BY rowid, name, firstname";
$sql .= " ORDER BY rowid"; $sql .= " ORDER BY rowid";
$result = $db->query($sql); $result = $db->query($sql);
@@ -136,7 +170,7 @@ if ($modecompta != 'CREANCES-DETTES')
$sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND p.fk_bank = b.rowid";
$sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND b.fk_account = ba.rowid";
$sql.= " AND ba.entity = ".$conf->entity; $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.= " GROUP BY rowid";
$sql.= " ORDER BY rowid"; $sql.= " ORDER BY rowid";

View File

@@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be> * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* *
@@ -27,11 +27,11 @@
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.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"); $langs->load("companies");
$year=$_GET["year"];
if (! $year) { $year = strftime("%Y", time()); }
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->compta->mode; $modecompta = $conf->compta->mode;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
@@ -41,9 +41,49 @@ $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
if (! $sortorder) $sortorder="asc"; if (! $sortorder) $sortorder="asc";
if (! $sortfield) $sortfield="nom"; 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->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(); llxHeader();
@@ -54,8 +94,9 @@ if ($modecompta=="CREANCES-DETTES")
{ {
$nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties"); $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period=$langs->trans("Year")." ".$year; //$period=$langs->trans("Year")." ".$year;
$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; $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='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
$description=$langs->trans("RulesCADue"); $description=$langs->trans("RulesCADue");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
@@ -63,8 +104,9 @@ if ($modecompta=="CREANCES-DETTES")
else { else {
$nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties"); $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$period=$langs->trans("Year")." ".$year; //$period=$langs->trans("Year")." ".$year;
$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; $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='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
$description=$langs->trans("RulesCAIn"); $description=$langs->trans("RulesCAIn");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
@@ -81,7 +123,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
$sql.= " AND f.fk_soc = s.rowid"; $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 else
{ {
@@ -97,7 +139,7 @@ else
$sql .= " WHERE p.rowid = pf.fk_paiement"; $sql .= " WHERE p.rowid = pf.fk_paiement";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
$sql.= " AND f.fk_soc = s.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; $sql.= " AND f.entity = ".$conf->entity;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; 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 p.fk_bank = b.rowid";
$sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND b.fk_account = ba.rowid";
$sql.= " AND ba.entity = ".$conf->entity; $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.= " GROUP BY nom";
$sql.= " ORDER BY nom"; $sql.= " ORDER BY nom";

View File

@@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -19,10 +19,10 @@
*/ */
/** /**
\file htdocs/compta/stats/index.php * \file htdocs/compta/stats/index.php
\brief Page reporting CA * \brief Page reporting CA
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php");
@@ -31,48 +31,50 @@ require_once(DOL_DOCUMENT_ROOT."/lib/report.lib.php");
$year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"]; $year_start=isset($_GET["year_start"])?$_GET["year_start"]:$_POST["year_start"];
$year_current = strftime("%Y",time()); $year_current = strftime("%Y",time());
if (! $year_start) { if (! $year_start) {
$year_start = $year_current - 4; $year_start = $year_current - 4;
$year_end = $year_current; $year_end = $year_current;
} }
else { else {
$year_end=$year_start + 4; $year_end=$year_start + 4;
} }
/* // Security check
* Securite acces client $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:'';
*/ if ($user->societe_id > 0) $socid = $user->societe_id;
if ($user->societe_id > 0) if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire)
{ accessforbidden();
$socid = $user->societe_id;
}
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES') // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->compta->mode; $modecompta = $conf->compta->mode;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
/*
* View
*/
llxHeader(); llxHeader();
$html=new Form($db); $html=new Form($db);
// Affiche en-t<EFBFBD>te du rapport // Affiche en-tete du rapport
if ($modecompta=="CREANCES-DETTES") if ($modecompta=="CREANCES-DETTES")
{ {
$nom=$langs->trans("SalesTurnover"); $nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period="$year_start - $year_end"; $period="$year_start - $year_end";
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":""); $periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
$description=$langs->trans("RulesCADue"); $description=$langs->trans("RulesCADue");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
} }
else { else {
$nom=$langs->trans("SalesTurnover"); $nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')'; $nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
$period="$year_start - $year_end"; $period="$year_start - $year_end";
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":""); $periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
$description=$langs->trans("RulesCAIn"); $description=$langs->trans("RulesCAIn");
$builddate=time(); $builddate=time();
$exportlink=$langs->trans("NotYetAvailable"); $exportlink=$langs->trans("NotYetAvailable");
} }
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
@@ -82,16 +84,16 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
} else { } else {
/* /*
* Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * 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) * 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 = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
$sql.= " WHERE p.rowid = pf.fk_paiement"; $sql.= " WHERE p.rowid = pf.fk_paiement";
$sql.= " AND pf.fk_facture = f.rowid"; $sql.= " AND pf.fk_facture = f.rowid";
} }
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity = ".$conf->entity;
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
@@ -100,58 +102,58 @@ $sql.= " GROUP BY dm DESC";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$cum[$obj->dm] = $obj->amount_ttc; $cum[$obj->dm] = $obj->amount_ttc;
if ($obj->amount_ttc) if ($obj->amount_ttc)
{ {
$minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm);
$maxyearmonth=max($maxyearmonth,$obj->dm); $maxyearmonth=max($maxyearmonth,$obj->dm);
} }
$i++; $i++;
} }
$db->free($result); $db->free($result);
} }
else { else {
dol_print_error($db); dol_print_error($db);
} }
// On ajoute les paiements anciennes version, non li<EFBFBD>s par paiement_facture // On ajoute les paiements anciennes version, non lies par paiement_facture
if ($modecompta != 'CREANCES-DETTES') { if ($modecompta != 'CREANCES-DETTES') {
$sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; $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.= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " WHERE pf.rowid IS NULL"; $sql.= " WHERE pf.rowid IS NULL";
$sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND p.fk_bank = b.rowid";
$sql.= " AND b.fk_account = ba.rowid"; $sql.= " AND b.fk_account = ba.rowid";
$sql.= " AND ba.entity = ".$conf->entity; $sql.= " AND ba.entity = ".$conf->entity;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= " ORDER BY dm"; $sql.= " ORDER BY dm";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result) {
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$cum[$obj->dm] += $obj->amount_ttc; $cum[$obj->dm] += $obj->amount_ttc;
if ($obj->amount_ttc) if ($obj->amount_ttc)
{ {
$minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm); $minyearmonth=($minyearmonth?min($minyearmonth,$obj->dm):$obj->dm);
$maxyearmonth=max($maxyearmonth,$obj->dm); $maxyearmonth=max($maxyearmonth,$obj->dm);
} }
$i++; $i++;
} }
} }
else { else {
dol_print_error($db); dol_print_error($db);
} }
} }
@@ -160,17 +162,17 @@ print '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>';
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
print '<td align="center" width="10%" colspan="2"><a href="casoc.php?year='.$annee.'">'.$annee.'</a></td>'; print '<td align="center" width="10%" colspan="2"><a href="casoc.php?year='.$annee.'">'.$annee.'</a></td>';
if ($annee != $year_end) print '<td width="15">&nbsp;</td>'; if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
print '<td align="right">'.$langs->trans("AmountTTC").'</td>'; print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
print '<td align="right">'.$langs->trans("Delta").'</td>'; print '<td align="right">'.$langs->trans("Delta").'</td>';
if ($annee != $year_end) print '<td width="15">&nbsp;</td>'; if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
@@ -184,227 +186,227 @@ $nowyearmonth=strftime("%Y-%m",mktime());
for ($mois = 1 ; $mois < 13 ; $mois++) for ($mois = 1 ; $mois < 13 ; $mois++)
{ {
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%b")."</td>"; print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
$casenow = dol_print_date(mktime(),"%Y-%m"); $casenow = dol_print_date(mktime(),"%Y-%m");
$case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%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"); $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
if ($annee == $year_current) { if ($annee == $year_current) {
$total_CA += $cum[$case]; $total_CA += $cum[$case];
} }
// Valeur CA du mois // Valeur CA du mois
print '<td align="right">'; print '<td align="right">';
if ($cum[$case]) if ($cum[$case])
{ {
$now_show_delta=1; // On a trouv<EFBFBD> le premier mois de la premi<EFBFBD>re ann<EFBFBD>e g<EFBFBD>n<EFBFBD>rant du chiffre. $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
print price($cum[$case],1); print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cum[$case],1).'</a>';
} }
else else
{ {
if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; } if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
else { print '&nbsp;'; } else { print '&nbsp;'; }
} }
print "</td>"; print "</td>";
// Pourcentage du mois // Pourcentage du mois
if ($annee > $minyear && $case <= $casenow) { if ($annee > $minyear && $case <= $casenow) {
if ($cum[$caseprev] && $cum[$case]) if ($cum[$caseprev] && $cum[$case])
{ {
$percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100); $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
//print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>'; print '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
} }
if ($cum[$caseprev] && ! $cum[$case]) if ($cum[$caseprev] && ! $cum[$case])
{ {
print '<td align="right">-100%</td>'; print '<td align="right">-100%</td>';
} }
if (! $cum[$caseprev] && $cum[$case]) if (! $cum[$caseprev] && $cum[$case])
{ {
print '<td align="right">+Inf%</td>'; print '<td align="right">+Inf%</td>';
} }
if (! $cum[$caseprev] && ! $cum[$case]) if (! $cum[$caseprev] && ! $cum[$case])
{ {
print '<td align="right">+0%</td>'; print '<td align="right">+0%</td>';
} }
} }
else else
{ {
print '<td align="right">'; print '<td align="right">';
if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
else { print '&nbsp;'; } else { print '&nbsp;'; }
print '</td>'; print '</td>';
} }
$total[$annee]+=$cum[$case]; $total[$annee]+=$cum[$case];
if ($annee != $year_end) print '<td width="15">&nbsp;</td>'; if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
} }
print '</tr>'; print '</tr>';
} }
// Affiche total // Affiche total
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>'; print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
for ($annee = $year_start ; $annee <= $year_end ; $annee++) for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{ {
// Montant total // Montant total
if ($annee >= $minyear && $annee <= max($nowyear,$maxyear)) if ($annee >= $minyear && $annee <= max($nowyear,$maxyear))
{ {
print "<td align=\"right\" nowrap>".($total[$annee]?price($total[$annee]):"0")."</td>"; print "<td align=\"right\" nowrap>".($total[$annee]?price($total[$annee]):"0")."</td>";
} }
else else
{ {
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
} }
// Pourcentage total // Pourcentage total
if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) { if ($annee > $minyear && $annee <= max($nowyear,$maxyear)) {
if ($total[$annee-1] && $total[$annee]) { if ($total[$annee-1] && $total[$annee]) {
$percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100); $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1],4)*100);
print '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>'; print '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>';
} }
if ($total[$annee-1] && ! $total[$annee]) if ($total[$annee-1] && ! $total[$annee])
{ {
print '<td align="right">-100%</td>'; print '<td align="right">-100%</td>';
} }
if (! $total[$annee-1] && $total[$annee]) if (! $total[$annee-1] && $total[$annee])
{ {
print '<td align="right">+Inf%</td>'; print '<td align="right">+Inf%</td>';
} }
if (! $total[$annee-1] && ! $total[$annee]) if (! $total[$annee-1] && ! $total[$annee])
{ {
print '<td align="right">+0%</td>'; print '<td align="right">+0%</td>';
} }
} }
else else
{ {
print '<td align="right">'; print '<td align="right">';
if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; } if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; }
else { print '&nbsp;'; } else { print '&nbsp;'; }
print '</td>'; print '</td>';
} }
if ($annee != $year_end) print '<td width="15">&nbsp;</td>'; if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
} }
print "</tr>\n"; print "</tr>\n";
print "</table>"; print "</table>";
/* /*
* En mode recettes/d<EFBFBD>penses, on compl<EFBFBD>te avec les montants factur<EFBFBD>s non r<EFBFBD>gl<EFBFBD>s * En mode recettes/depenses, on complete avec les montants factures non regles
* et les propales sign<EFBFBD>es mais pas factur<EFBFBD>es. En effet, en recettes-d<EFBFBD>penses, * et les propales signees mais pas facturees. En effet, en recettes-depenses,
* on comptabilise lorsque le montant est sur le compte donc il est int<EFBFBD>ressant * on comptabilise lorsque le montant est sur le compte donc il est interessant
* d'avoir une vision de ce qui va arriver. * d'avoir une vision de ce qui va arriver.
*/ */
/* /*
Je commente toute cette partie car les chiffres affich<EFBFBD>es sont faux - Eldy. Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
En attendant correction. En attendant correction.
if ($modecompta != 'CREANCES-DETTES') if ($modecompta != 'CREANCES-DETTES')
{ {
print '<br><table width="100%" class="noborder">'; print '<br><table width="100%" class="noborder">';
// Factures non r<EFBFBD>gl<EFBFBD>es // Factures non reglees
// \todo Y a bug ici. Il faut prendre le reste <EFBFBD> payer et non le total des factures non r<EFBFBD>gl<EFBFBD>es ! // \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 = "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 .= " 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"; $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
if ($socid) if ($socid)
{ {
$sql .= " AND f.fk_soc = $socid"; $sql .= " AND f.fk_soc = $socid";
} }
$sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc"; $sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.rowid, f.total_ttc";
if ( $db->query($sql) ) if ( $db->query($sql) )
{ {
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $i = 0;
if ($num) if ($num)
{ {
$var = True; $var = True;
$total_ttc_Rac = $totalam_Rac = $total_Rac = 0; $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object(); $obj = $db->fetch_object();
$total_ttc_Rac += $obj->total_ttc; $total_ttc_Rac += $obj->total_ttc;
$totalam_Rac += $obj->am; $totalam_Rac += $obj->am;
$i++; $i++;
} }
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Factur<EFBFBD> <20> encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja r<>gl<67> des factures partiellement r<>gl<67>es</td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Facture a encaisser : </i></td><td align=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja r<>gl<67> des factures partiellement r<>gl<67>es</td></tr>";
$total_CA +=$total_ttc_Rac; $total_CA +=$total_ttc_Rac;
} }
$db->free(); $db->free();
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
*/ */
/* /*
* *
* Propales sign<EFBFBD>es, et non factur<EFBFBD>es * Propales signees, et non facturees
* *
*/ */
/* /*
Je commente toute cette partie car les chiffres affich<EFBFBD>es sont faux - Eldy. Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
En attendant correction. 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 $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 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."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 LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
WHERE p.fk_soc = s.rowid WHERE p.fk_soc = s.rowid
AND p.fk_statut >=1 AND p.fk_statut >=1
AND p.facture =0"; AND p.facture =0";
if ($socid) if ($socid)
{ {
$sql .= " AND f.fk_soc = ".$socid; $sql .= " AND f.fk_soc = ".$socid;
} }
$sql .= " GROUP BY p.rowid"; $sql .= " GROUP BY p.rowid";
if ( $db->query($sql) ) if ( $db->query($sql) )
{ {
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $i = 0;
if ($num) if ($num)
{ {
$var = True; $var = True;
$total_pr = 0; $total_pr = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object(); $obj = $db->fetch_object();
$total_pr += $obj->total_ttc-$obj->tot_fttc; $total_pr += $obj->total_ttc-$obj->tot_fttc;
$i++; $i++;
} }
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Sign<EFBFBD> et non factur<EFBFBD>:</i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le d<EFBFBD>j<EFBFBD> factur<EFBFBD></td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Signe et non facture:</i></td><td align=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le deja facture</td></tr>";
$total_CA += $total_pr; $total_CA += $total_pr;
} }
$db->free(); $db->free();
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Total CA pr<EFBFBD>visionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 pr<EFBFBD>c<EFBFBD>dents</td></tr>"; print "<tr $bc[$var]><td align=\"right\" colspan=\"5\"><i>Total CA previsionnel : </i></td><td align=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 precedents</td></tr>";
} }
print "</table>"; print "</table>";
*/ */
$db->close(); $db->close();

View File

@@ -52,7 +52,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES
// Quarter // Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end 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==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==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==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); }

View File

@@ -58,7 +58,12 @@ $date_end=dol_mktime($_REQUEST["date_endhour"],$_REQUEST["date_endmin"],$_REQUES
// Quarter // Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end 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==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==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==3) { $date_start=dol_get_first_day($year_start,7); $date_end=dol_get_last_day($year_start,9); }

View File

@@ -20,7 +20,7 @@
*/ */
/** \defgroup comptabilite Module comptabilite /** \defgroup comptabilite Module comptabilite
\brief Module pour inclure des fonctions de comptabilit<EFBFBD> (gestion de comptes comptables et rapports) \brief Module pour inclure des fonctions de comptabilite (gestion de comptes comptables et rapports)
\version $Id$ \version $Id$
*/ */

View File

@@ -359,7 +359,7 @@ Size=Size
Received=Received Received=Received
Paid=Paid Paid=Paid
Topic=Sujet Topic=Sujet
ByCompanies=By companies ByCompanies=By third parties
ByUsers=By users ByUsers=By users
Links=Links Links=Links
Link=Link Link=Link

View File

@@ -358,7 +358,7 @@ Size=Taille
Received=Reçu Received=Reçu
Paid=Payé Paid=Payé
Topic=Sujet Topic=Sujet
ByCompanies=Par société ByCompanies=Par tiers
ByUsers=Par utilisateur ByUsers=Par utilisateur
Links=Liens Links=Liens
Link=Lien Link=Lien

View File

@@ -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 // 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); $datelim -= (3600 * 24);
return $datelim; return $datelim;