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."/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.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$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>';
$description=$langs->trans("RulesResultDue");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
$nom=$langs->trans("AnnualByCompaniesDueDebtMode");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
//$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='<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("RulesResultDue");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
}
else {
$nom=$langs->trans("AnnualByCompaniesInputOutputMode");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$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>';
$description=$langs->trans("RulesResultInOut");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
$nom=$langs->trans("AnnualByCompaniesInputOutputMode");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
//$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='<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("RulesResultInOut");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
}
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
// Affiche rapport
// Show report array
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="10%">&nbsp;</td><td>'.$langs->trans("Element").'</td>';
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".$langs->trans("AmountHT")."</td>";
print "<td align=\"right\">".$langs->trans("AmountTTC")."</td>";
print "</tr>\n";
print '<tr><td colspan="4">&nbsp;</td></tr>';
/*
* 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') {
$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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("Bills")." <a href=\"../facture.php?socid=".$objp->socid."\">$objp->nom</td>\n";
print "<tr $bc[$var]><td>&nbsp;</td>";
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";
print "<td align=\"right\">".price($objp->amount_ttc)."</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";
$total_ht = $total_ht + $objp->amount_ht;
$total_ttc = $total_ttc + $objp->amount_ttc;
print "</tr>\n";
$i++;
}
$db->free($result);
$total_ht = $total_ht + $objp->amount_ht;
$total_ttc = $total_ttc + $objp->amount_ttc;
print "</tr>\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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n";
print "<tr $bc[$var]><td>&nbsp;</td>";
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";
print "<td align=\"right\">".price($objp->amount_ttc)."</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";
$total_ht = $total_ht + $objp->amount_ht;
$total_ttc = $total_ttc + $objp->amount_ttc;
print "</tr>\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 "</tr>\n";
$i++;
}
}
$db->free($result);
} else {
dol_print_error($db);
}
}
if ($total_ttc == 0)
{
$var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
$var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
print '<tr class="liste_total">';
@@ -225,13 +240,11 @@ print '</tr>';
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 '<tr><td colspan="4">Facturation fournisseurs</td></tr>';
print '<tr><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
$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 "<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 "<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";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price(-$objp->amount_ht)."</td>\n";
print "<td align=\"right\">".price(-$objp->amount_ttc)."</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";
$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 "</tr>\n";
$i++;
}
}
else {
$var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
$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 "</tr>\n";
$i++;
}
}
else {
$var=!$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
$db->free($result);
$db->free($result);
} else {
dol_print_error($db);
dol_print_error($db);
}
print '<tr class="liste_total">';
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>';
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 "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>';
$i++;
}
}
else {
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>';
$i++;
}
}
else {
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
} else {
dol_print_error($db);
dol_print_error($db);
}
print '<tr class="liste_total">';
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>';
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 "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>';
$i++;
}
}
else {
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td>'.$obj->nom.'</td>';
if ($modecompta == 'CREANCES-DETTES') print '<td align="right">'.price(-$obj->amount).'</td>';
print '<td align="right">'.price(-$obj->amount).'</td>';
print '</tr>';
$i++;
}
}
else {
$var = !$var;
print "<tr $bc[$var]><td>&nbsp;</td>";
print '<td colspan="3">'.$langs->trans("None").'</td>';
print '</tr>';
}
} else {
dol_print_error($db);
dol_print_error($db);
}
print '<tr class="liste_total">';
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')
{
// 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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToPay")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToPay")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToCollect")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n";
$i++;
}
}
} else {
dol_print_error($db);
}
print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATToCollect")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATPaid")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n";
$i++;
}
}
$db->free($result);
} else {
dol_print_error($db);
}
print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATPaid")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\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 "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATCollected")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n";
$i++;
}
}
$db->free($result);
} else {
dol_print_error($db);
}
print "<tr $bc[$var]><td>&nbsp;</td>";
print "<td>".$langs->trans("VATCollected")."</td>\n";
if ($modecompta == 'CREANCES-DETTES') print "<td align=\"right\">".price($amount)."</td>\n";
print "<td align=\"right\">".price($amount)."</td>\n";
print "</tr>\n";
}
@@ -637,7 +632,7 @@ if ($mysoc->tva_assuj != 'franchise') // Assujeti
if ($mysoc->tva_assuj != 'franchise') // Assujeti
{
// Total
// Total
print '<tr>';
print '<td colspan="4">&nbsp;</td>';
print '</tr>';

View File

@@ -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 "<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.
@@ -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 "<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
@@ -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 "<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
@@ -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 "<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
*/
$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 "<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();
$totsorties=array();
@@ -526,11 +432,12 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++)
print '</tr>';
$var=True;
// Loop on each month
for ($mois = 1 ; $mois <= 12 ; $mois++)
{
$var=!$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++)
{
$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;';
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];
}
print "</td>";
@@ -546,7 +453,7 @@ for ($mois = 1 ; $mois <= 12 ; $mois++)
print '<td align="right">&nbsp;';
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];
}
print "</td>";

View File

@@ -1,6 +1,6 @@
<?php
/* 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>
*
* 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.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$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=$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="<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");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
@@ -68,8 +101,9 @@ if ($modecompta=="CREANCES-DETTES")
else {
$nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByUserAuthorOfInvoice");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$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=$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="<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");
$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";

View File

@@ -1,6 +1,6 @@
<?php
/* 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) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
*
@@ -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.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$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=$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='<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");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
@@ -63,8 +104,9 @@ if ($modecompta=="CREANCES-DETTES")
else {
$nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByThirdParties");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">','</a>').')';
$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=$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='<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");
$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";

View File

@@ -1,6 +1,6 @@
<?php
/* 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>
*
* 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,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_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<EFBFBD>te du rapport
// Affiche en-tete du rapport
if ($modecompta=="CREANCES-DETTES")
{
$nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$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>":"");
$description=$langs->trans("RulesCADue");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
$nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$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>":"");
$description=$langs->trans("RulesCADue");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
}
else {
$nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
$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>":"");
$description=$langs->trans("RulesCAIn");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
$nom=$langs->trans("SalesTurnover");
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
$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>":"");
$description=$langs->trans("RulesCAIn");
$builddate=time();
$exportlink=$langs->trans("NotYetAvailable");
}
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.= " 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<EFBFBD>s par paiement_facture
// 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";
$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 '<tr class="liste_titre"><td rowspan="2">'.$langs->trans("Month").'</td>';
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>';
if ($annee != $year_end) print '<td width="15">&nbsp;</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>';
}
print '</tr>';
print '<tr class="liste_titre">';
for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{
print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
print '<td align="right">'.$langs->trans("Delta").'</td>';
if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
print '<td align="right">'.$langs->trans("Delta").'</td>';
if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
}
print '</tr>';
@@ -184,227 +186,227 @@ $nowyearmonth=strftime("%Y-%m",mktime());
for ($mois = 1 ; $mois < 13 ; $mois++)
{
$var=!$var;
print "<tr $bc[$var]>";
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%b")."</td>";
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 "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
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 '<td align="right">';
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.
print price($cum[$case],1);
}
else
{
if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
else { print '&nbsp;'; }
}
print "</td>";
// Valeur CA du mois
print '<td align="right">';
if ($cum[$case])
{
$now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cum[$case],1).'</a>';
}
else
{
if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
else { print '&nbsp;'; }
}
print "</td>";
// 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 '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
// 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 '<td align="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
}
if ($cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">-100%</td>';
}
if (! $cum[$caseprev] && $cum[$case])
{
print '<td align="right">+Inf%</td>';
}
if (! $cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="right">';
if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
else { print '&nbsp;'; }
print '</td>';
}
}
if ($cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">-100%</td>';
}
if (! $cum[$caseprev] && $cum[$case])
{
print '<td align="right">+Inf%</td>';
}
if (! $cum[$caseprev] && ! $cum[$case])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="right">';
if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
else { print '&nbsp;'; }
print '</td>';
}
$total[$annee]+=$cum[$case];
if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
}
$total[$annee]+=$cum[$case];
if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
}
print '</tr>';
print '</tr>';
}
// Affiche total
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
for ($annee = $year_start ; $annee <= $year_end ; $annee++)
{
// Montant total
if ($annee >= $minyear && $annee <= max($nowyear,$maxyear))
{
print "<td align=\"right\" nowrap>".($total[$annee]?price($total[$annee]):"0")."</td>";
}
else
{
print '<td>&nbsp;</td>';
}
// Montant total
if ($annee >= $minyear && $annee <= max($nowyear,$maxyear))
{
print "<td align=\"right\" nowrap>".($total[$annee]?price($total[$annee]):"0")."</td>";
}
else
{
print '<td>&nbsp;</td>';
}
// 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 '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>';
}
if ($total[$annee-1] && ! $total[$annee])
{
print '<td align="right">-100%</td>';
}
if (! $total[$annee-1] && $total[$annee])
{
print '<td align="right">+Inf%</td>';
}
if (! $total[$annee-1] && ! $total[$annee])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="right">';
if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; }
else { print '&nbsp;'; }
print '</td>';
}
// 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 '<td align="right" nowrap>'.($percent>=0?"+$percent":"$percent").'%</td>';
}
if ($total[$annee-1] && ! $total[$annee])
{
print '<td align="right">-100%</td>';
}
if (! $total[$annee-1] && $total[$annee])
{
print '<td align="right">+Inf%</td>';
}
if (! $total[$annee-1] && ! $total[$annee])
{
print '<td align="right">+0%</td>';
}
}
else
{
print '<td align="right">';
if ($minyear <= $annee && $annee <= max($nowyear,$maxyear)) { print '-'; }
else { print '&nbsp;'; }
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 "</table>";
/*
* En mode recettes/d<EFBFBD>penses, on compl<EFBFBD>te avec les montants factur<EFBFBD>s non r<EFBFBD>gl<EFBFBD>s
* et les propales sign<EFBFBD>es mais pas factur<EFBFBD>es. En effet, en recettes-d<EFBFBD>penses,
* on comptabilise lorsque le montant est sur le compte donc il est int<EFBFBD>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<EFBFBD>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')
{
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
// \todo Y a bug ici. Il faut prendre le reste <EFBFBD> payer et non le total des factures non r<EFBFBD>gl<EFBFBD>es !
// 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";
$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 ( $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 "<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>";
$total_CA +=$total_ttc_Rac;
}
$db->free();
}
else
{
dol_print_error($db);
}
*/
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 "<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;
}
$db->free();
}
else
{
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.
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 ( $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 "<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>";
$total_CA += $total_pr;
}
$db->free();
}
else
{
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 "</table>";
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 "<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;
}
$db->free();
}
else
{
dol_print_error($db);
}
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>";
*/
*/
$db->close();

View File

@@ -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); }

View File

@@ -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); }

View File

@@ -20,7 +20,7 @@
*/
/** \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$
*/

View File

@@ -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

View File

@@ -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

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
$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;