*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
('.$langs->trans("SeeReportInBookkeepingMode", '{link1}', '{link2}').')';
$calcmode = str_replace('{link1}', '', $calcmode);
$calcmode = str_replace('{link2}', '', $calcmode);
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$periodlink = ($year_start ? "".img_previous()." ".img_next()."" : "");
$description = $langs->trans("RulesPurchaseTurnoverDue");
$builddate = dol_now();
//$exportlink=$langs->trans("NotYetAvailable");
} elseif ($modecompta == "RECETTES-DEPENSES")
{
$name = $langs->trans("PurchaseTurnoverCollected");
$calcmode = $langs->trans("CalcModeEngagement");
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$periodlink = ($year_start ? "".img_previous()." ".img_next()."" : "");
$description = $langs->trans("RulesPurchaseTurnoverIn");
$builddate = dol_now();
//$exportlink=$langs->trans("NotYetAvailable");
} elseif ($modecompta == "BOOKKEEPING")
{
$name = $langs->trans("PurchaseTurnover");
$calcmode = $langs->trans("CalcModeBookkeeping");
$calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '{link1}', '{link2}').')';
$calcmode = str_replace('{link1}', '', $calcmode);
$calcmode = str_replace('{link2}', '', $calcmode);
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$periodlink = ($year_start ? "".img_previous()." ".img_next()."" : "");
$description = $langs->trans("RulesPurchaseTurnoverTotalPurchaseJournal");
$builddate = dol_now();
//$exportlink=$langs->trans("NotYetAvailable");
}
$moreparam = array();
if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta;
report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
{
print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
}
if ($modecompta == 'CREANCES-DETTES')
{
$sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql .= " WHERE f.fk_statut in (1,2)";
$sql .= " AND f.type IN (0,2)";
$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
} elseif ($modecompta == "RECETTES-DEPENSES")
{
$sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
$sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
$sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
$sql .= " WHERE p.rowid = pf.fk_paiementfourn";
$sql .= " AND pf.fk_facturefourn = f.rowid";
$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
} elseif ($modecompta == "BOOKKEEPING")
{
$sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as amount_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj";
$sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
$sql .= " AND aj.entity = ".$conf->entity;
$sql .= " AND b.code_journal = aj.code AND aj.nature = 3"; // @todo currently count amount in sale journal, but we need to define a category group for turnover
}
$sql .= " GROUP BY dm";
$sql .= " ORDER BY dm";
// TODO Add a filter on $date_start and $date_end to reduce quantity on data
//print $sql;
$minyearmonth = $maxyearmonth = 0;
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($result);
$cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
$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);
}
$moreforfilter = '';
print '
| '; for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') print ' | '; else print ' | '; if ($modecompta != 'BOOKKEEPING') print ''; print $annee; if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1); if ($modecompta != 'BOOKKEEPING') print ''; print ' | '; if ($annee != $year_end) print ''; } print ' | |||||||
| '.$langs->trans("Month").' | '; for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') print ''.$langs->trans("AmountHT").' | '; print ''.$langs->trans("AmountTTC").' | '; print ''.$langs->trans("Delta").' | '; if ($annee != $year_end) print ''; } print ' | ||||||
| ".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")." | "; for ($annee = $year_start - 1; $annee <= $year_end; $annee++) // We start one year before to have data to be able to make delta { $annee_decalage = $annee; if ($mois > 12) {$annee_decalage = $annee + 1; } $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m"); $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m"); if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. { if ($modecompta == 'CREANCES-DETTES') { // Valeur CA du mois w/o VAT print ''; if ($cum_ht[$case]) { $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. print ''.price($cum_ht[$case], 1).''; } else { if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } } print " | "; } // Valeur CA du mois print ''; if ($cum[$case]) { $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. if ($modecompta != 'BOOKKEEPING') print ''; print price($cum[$case], 1); if ($modecompta != 'BOOKKEEPING') print ''; } else { if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print ' '; } } print " | "; // Pourcentage du mois if ($annee_decalage > $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 ''.($percent >= 0 ? "+$percent" : "$percent").'% | '; } if ($cum[$caseprev] && !$cum[$case]) { print '-100% | '; } if (!$cum[$caseprev] && $cum[$case]) { //print '+Inf% | '; print '- | '; } if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) { print '+0% | '; } if (!isset($cum[$caseprev]) && !$cum[$case]) { print '- | '; } } else { print ''; if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print ' '; } print ' | '; } if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ''; } $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); $total[$annee] += $cum[$case]; } print ' |
| '.$langs->trans("Total").' | '; for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') { // Montant total HT if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { print ''.($total_ht[$annee] ?price($total_ht[$annee]) : "0")." | "; } else { print ''; } } // Montant total if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { print ' | '.($total[$annee] ?price($total[$annee]) : "0")." | "; } else { print ''; } // Pourcentage total if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) { if ($total[$annee - 1] && $total[$annee]) { $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100); print ' | '.($percent >= 0 ? "+$percent" : "$percent").'% | '; } if ($total[$annee - 1] && !$total[$annee]) { print '-100% | '; } if (!$total[$annee - 1] && $total[$annee]) { print '+'.$langs->trans('Inf').'% | '; } if (!$total[$annee - 1] && !$total[$annee]) { print '+0% | '; } } else { print ''; if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { print '-'; } else { print ' '; } print ' | '; } if ($annee != $year_end) print ''; } print " |