25 require
'../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
40 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin",
"accountancy"));
42 $modecompta = (
GETPOST(
'modecompta',
'alpha') ?
GETPOST(
'modecompta',
'alpha') : $conf->global->ACCOUNTING_MODE);
46 $month =
GETPOST(
"month",
'int');
50 $year_start = $year_current;
52 $year_current = $year;
61 if (empty($date_start) || empty($date_end)) {
65 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
66 $year_end = $year_start;
67 $month_end = $month_start;
69 if (!
GETPOST(
'year') && $month_start > $month_current) {
73 $month_end = $month_start - 1;
104 $year_start = $tmps[
'year'];
106 $year_end = $tmpe[
'year'];
109 if ($tmp_date_end < $date_end || $date_end < $date_start) {
110 $date_end = $tmp_date_end;
120 $modetax = empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE;
122 $modetax =
GETPOST(
"modetax",
'int');
124 if (empty($modetax)) {
129 $socid =
GETPOST(
'socid',
'int');
131 $socid = $user->socid;
142 $company_static =
new Societe($db);
143 $invoice_customer =
new Facture($db);
146 $product_static =
new Product($db);
147 $payment_static =
new Paiement($db);
151 $morequerystring =
'';
152 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
153 foreach ($listofparams as $param) {
155 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
159 llxHeader(
'', $langs->trans(
"TurnoverReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
167 $fsearch .=
' <input type="hidden" name="year" value="'.$year.
'">';
168 $fsearch .=
' <input type="hidden" name="modetax" value="'.$modetax.
'">';
174 $name = $langs->trans(
"xxx");
177 $calcmode = $langs->trans(
'OptionVATDefault');
180 $calcmode = $langs->trans(
'OptionVATDebitOption');
183 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
185 $calcmode .=
'<br>('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')';
187 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
189 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
190 $prevyear = $year_start;
192 if ($prevquarter > 1) {
198 $nextyear = $year_start;
200 if ($nextquarter < 4) {
206 $description = $fsearch;
209 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
210 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
212 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
213 $description .=
'<br>'.$langs->trans(
"RulesVATDueProducts");
215 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
216 $description .=
'<br>'.$langs->trans(
"RulesVATInProducts");
218 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
219 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
221 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
222 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
224 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
225 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
227 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
228 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
231 $elementcust = $langs->trans(
"CustomersInvoices");
232 $productcust = $langs->trans(
"ProductOrService");
233 $amountcust = $langs->trans(
"AmountHT");
236 $elementsup = $langs->trans(
"SuppliersInvoices");
237 $productsup = $productcust;
238 $amountsup = $amountcust;
241 if ($modecompta ==
"BOOKKEEPING") {
242 $modecompta =
"CREANCES-DETTES";
244 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
245 $modecompta =
"RECETTES-DEPENSES";
249 if ($modecompta ==
"CREANCES-DETTES") {
250 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
251 $calcmode = $langs->trans(
"CalcModeDebt");
254 $description .=
'<br>'.$langs->trans(
"RulesCADue");
255 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
256 $description .= $langs->trans(
"DepositsAreNotIncluded");
258 $description .= $langs->trans(
"DepositsAreIncluded");
260 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
261 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
265 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
266 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
267 $calcmode = $langs->trans(
"CalcModeEngagement");
270 $description .= $langs->trans(
"RulesCAIn");
271 $description .= $langs->trans(
"DepositsAreIncluded");
274 } elseif ($modecompta ==
"BOOKKEEPING") {
275 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
277 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0);
279 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
281 $periodlink =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_start - 1).
'&modecompta='.$modecompta.
'">'.
img_previous().
'</a> <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_start + 1).
'&modecompta='.$modecompta.
'">'.
img_next().
'</a>';
286 $description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
288 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
290 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
291 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
295 if ($modecompta ==
'CREANCES-DETTES') {
296 print
'<table class="noborder centpercent">';
297 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
298 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
299 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
302 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
306 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
309 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
312 $sql =
"SELECT fd.tva_tx AS vatrate,";
313 $sql .=
" fd.product_type AS product_type,";
314 $sql .=
" cc.code, cc.label AS country,";
315 for ($i = 1; $i <= 12; $i++) {
316 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$i,
"fd.total_ht",
"0").
") AS month".str_pad($i, 2,
"0", STR_PAD_LEFT).
",";
318 $sql .=
" SUM(fd.total_ht) as total";
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
320 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
321 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
322 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
323 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
324 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
325 $sql .=
" AND f.fk_statut in (1,2)";
326 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
327 $sql .=
" AND f.type IN (0,1,2,5)";
329 $sql .=
" AND f.type IN (0,1,2,3,5)";
331 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
332 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
333 $sql .=
" ORDER BY country, product_type, vatrate";
335 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
336 $resql = $db->query($sql);
338 $num = $db->num_rows(
$resql);
339 $totalpermonth = array();
340 while ($obj = $db->fetch_object(
$resql)) {
341 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
342 if ($obj->product_type == 0) {
343 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
345 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
349 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
351 for ($i = 0; $i < 12; $i++) {
352 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
356 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
357 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
358 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
360 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
361 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
367 print
'<tr class="liste_total"><td class="right"></td>';
368 print
'<td class="left"></td>';
370 for ($i = 0; $i < 12; $i++) {
371 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
375 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
376 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
378 print
'<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
381 print $db->lasterror();
384 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
385 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
386 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
389 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
393 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
396 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
399 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
400 $sql2 .=
" ffd.product_type AS product_type,";
401 $sql2 .=
" cc.code, cc.label AS country,";
402 for ($i = 1; $i <= 12; $i++) {
403 $sql2 .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$i,
"ffd.total_ht",
"0").
") AS month".str_pad($i, 2,
"0", STR_PAD_LEFT).
",";
405 $sql2 .=
" SUM(ffd.total_ht) as total";
406 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
407 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
408 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
409 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
410 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
411 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
412 $sql .=
" AND ff.fk_statut in (1,2)";
413 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
414 $sql .=
" AND ff.type IN (0,1,2,5)";
416 $sql .=
" AND ff.type IN (0,1,2,3,5)";
418 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
419 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
420 $sql2 .=
" ORDER BY country, product_type, vatrate";
423 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
424 $resql2 = $db->query($sql2);
426 $num = $db->num_rows($resql2);
427 $totalpermonth = array();
428 while ($obj = $db->fetch_object($resql2)) {
429 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
430 if ($obj->product_type == 0) {
431 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
433 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
436 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
438 for ($i = 0; $i < 12; $i++) {
439 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
443 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
444 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
445 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
447 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
448 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
454 print
'<tr class="liste_total"><td class="right"></td>';
455 print
'<td class="left"></td>';
457 for ($i = 0; $i < 12; $i++) {
458 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
462 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
463 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
465 print
'<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
468 print $db->lasterror();
476 print
'<br>'.$langs->trans(
"TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").
'<br>';