26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
41$langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin",
"accountancy"));
43$modecompta = (
GETPOST(
'modecompta',
'alpha') ?
GETPOST(
'modecompta',
'alpha') : $conf->global->ACCOUNTING_MODE);
51 $year_start = $year_current;
53 $year_current = $year;
62if (empty($date_start) || empty($date_end)) {
67 $year_end = $year_start;
68 $month_end = $month_start;
70 if (!
GETPOST(
'year') && $month_start > $month_current) {
74 $month_end = $month_start - 1;
105$year_start = $tmps[
'year'];
107$year_end = $tmpe[
'year'];
110if ($tmp_date_end < $date_end || $date_end < $date_start) {
111 $date_end = $tmp_date_end;
122if (GETPOSTISSET(
"modetax")) {
125if (empty($modetax)) {
132 $socid = $user->socid;
142$form =
new Form($db);
143$company_static =
new Societe($db);
144$invoice_customer =
new Facture($db);
147$product_static =
new Product($db);
152$morequerystring =
'';
153$listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
154foreach ($listofparams as $param) {
156 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
160llxHeader(
'', $langs->trans(
"TurnoverReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
168$fsearch .=
' <input type="hidden" name="year" value="'.$year.
'">';
169$fsearch .=
' <input type="hidden" name="modetax" value="'.$modetax.
'">';
175$name = $langs->trans(
"xxx");
178 $calcmode = $langs->trans(
'OptionVATDefault');
181 $calcmode = $langs->trans(
'OptionVATDebitOption');
184 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
186$calcmode .=
'<br>('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')';
188$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
190$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
191$prevyear = $year_start;
193if ($prevquarter > 1) {
199$nextyear = $year_start;
201if ($nextquarter < 4) {
207$description = $fsearch;
210if (isModEnabled(
'comptabilite')) {
211 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
214 $description .=
'<br>'.$langs->trans(
"RulesVATDueProducts");
217 $description .=
'<br>'.$langs->trans(
"RulesVATInProducts");
220 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
223 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
226 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
229 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
232$elementcust = $langs->trans(
"CustomersInvoices");
233$productcust = $langs->trans(
"ProductOrService");
234$amountcust = $langs->trans(
"AmountHT");
237$elementsup = $langs->trans(
"SuppliersInvoices");
238$productsup = $productcust;
239$amountsup = $amountcust;
242if ($modecompta ==
"BOOKKEEPING") {
243 $modecompta =
"CREANCES-DETTES";
245if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
246 $modecompta =
"RECETTES-DEPENSES";
250if ($modecompta ==
"CREANCES-DETTES") {
251 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
252 $calcmode = $langs->trans(
"CalcModeDebt");
255 $description .=
'<br>'.$langs->trans(
"RulesCADue");
257 $description .= $langs->trans(
"DepositsAreNotIncluded");
259 $description .= $langs->trans(
"DepositsAreIncluded");
262 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
266} elseif ($modecompta ==
"RECETTES-DEPENSES") {
267 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
268 $calcmode = $langs->trans(
"CalcModePayment");
271 $description .= $langs->trans(
"RulesCAIn");
272 $description .= $langs->trans(
"DepositsAreIncluded");
275} elseif ($modecompta ==
"BOOKKEEPING") {
276} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
278$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0);
280$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
282 $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>';
287$description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
289report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
291if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
292 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
296if ($modecompta ==
'CREANCES-DETTES') {
297 print
'<table class="noborder centpercent">';
298 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
299 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
300 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
303 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
307 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
310 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
313 $sql =
"SELECT fd.tva_tx AS vatrate,";
314 $sql .=
" fd.product_type AS product_type,";
315 $sql .=
" cc.code, cc.label AS country,";
316 for ($i = 1; $i <= 12; $i++) {
317 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$i,
"fd.total_ht",
"0").
") AS month".str_pad((
string) $i, 2,
"0", STR_PAD_LEFT).
",";
319 $sql .=
" SUM(fd.total_ht) as total";
320 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
321 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
322 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
324 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
325 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
326 $sql .=
" AND f.fk_statut in (1,2)";
328 $sql .=
" AND f.type IN (0,1,2,5)";
330 $sql .=
" AND f.type IN (0,1,2,3,5)";
332 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
333 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
334 $sql .=
" ORDER BY country, product_type, vatrate";
336 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
337 $resql = $db->query($sql);
339 $num = $db->num_rows($resql);
340 $totalpermonth = array();
341 while ($obj = $db->fetch_object($resql)) {
342 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
343 if ($obj->product_type == 0) {
344 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
346 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
350 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
352 for ($i = 0; $i < 12; $i++) {
353 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
357 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
358 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
359 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
361 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
362 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
368 print
'<tr class="liste_total"><td class="right"></td>';
369 print
'<td class="left"></td>';
371 for ($i = 0; $i < 12; $i++) {
372 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
376 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
377 print
'<td class="right" width="6%">'.price((empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j])).
'</td>';
379 print
'<td class="right" width="6%"><b>'.price((empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total'])).
'</b></td>';
382 print $db->lasterror();
385 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
386 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
387 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
390 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
394 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
397 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
400 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
401 $sql2 .=
" ffd.product_type AS product_type,";
402 $sql2 .=
" cc.code, cc.label AS country,";
403 for ($i = 1; $i <= 12; $i++) {
404 $sql2 .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$i,
"ffd.total_ht",
"0").
") AS month".str_pad((
string) $i, 2,
"0", STR_PAD_LEFT).
",";
406 $sql2 .=
" SUM(ffd.total_ht) as total";
407 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
408 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
409 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
410 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
411 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
412 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
413 $sql .=
" AND ff.fk_statut in (1,2)";
415 $sql .=
" AND ff.type IN (0,1,2,5)";
417 $sql .=
" AND ff.type IN (0,1,2,3,5)";
419 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
420 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
421 $sql2 .=
" ORDER BY country, product_type, vatrate";
424 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
425 $resql2 = $db->query($sql2);
427 $num = $db->num_rows($resql2);
428 $totalpermonth = array();
429 while ($obj = $db->fetch_object($resql2)) {
430 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
431 if ($obj->product_type == 0) {
432 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
434 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
437 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
439 for ($i = 0; $i < 12; $i++) {
440 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
444 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
445 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
446 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
448 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
449 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
455 print
'<tr class="liste_total"><td class="right"></td>';
456 print
'<td class="left"></td>';
458 for ($i = 0; $i < 12; $i++) {
459 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
463 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
464 print
'<td class="right" width="6%">'.price(empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]).
'</td>';
466 print
'<td class="right" width="6%"><b>'.price(empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']).
'</b></td>';
469 print $db->lasterror();
477 print
'<br>'.$langs->trans(
"TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").
'<br>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of expense report.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.