27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
50$langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin",
"accountancy"));
52$modecompta = (
GETPOST(
'modecompta',
'alpha') ?
GETPOST(
'modecompta',
'alpha') :
$conf->global->ACCOUNTING_MODE);
60 $year_start = $year_current;
62 $year_current = $year;
71if (empty($date_start) || empty($date_end)) {
76 $year_end = $year_start;
77 $month_end = $month_start;
79 if (!
GETPOST(
'year') && $month_start > $month_current) {
83 $month_end = $month_start - 1;
114$year_start = $tmps[
'year'];
116$year_end = $tmpe[
'year'];
119if ($tmp_date_end < $date_end || $date_end < $date_start) {
120 $date_end = $tmp_date_end;
131if (GETPOSTISSET(
"modetax")) {
134if (empty($modetax)) {
141 $socid = $user->socid;
151$form =
new Form($db);
152$company_static =
new Societe($db);
153$invoice_customer =
new Facture($db);
156$product_static =
new Product($db);
161$morequerystring =
'';
162$listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
163foreach ($listofparams as $param) {
165 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
169llxHeader(
'', $langs->trans(
"TurnoverReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
177$fsearch .=
' <input type="hidden" name="year" value="'.$year.
'">';
178$fsearch .=
' <input type="hidden" name="modetax" value="'.$modetax.
'">';
184$name = $langs->trans(
"xxx");
187 $calcmode = $langs->trans(
'OptionVATDefault');
190 $calcmode = $langs->trans(
'OptionVATDebitOption');
193 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
195$calcmode .=
'<br>('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')';
197$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
199$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
200$prevyear = $year_start;
202if ($prevquarter > 1) {
208$nextyear = $year_start;
210if ($nextquarter < 4) {
216$description = $fsearch;
219if (isModEnabled(
'comptabilite')) {
220 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
223 $description .=
'<br>'.$langs->trans(
"RulesVATDueProducts");
226 $description .=
'<br>'.$langs->trans(
"RulesVATInProducts");
229 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
232 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
235 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
238 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
241$elementcust = $langs->trans(
"CustomersInvoices");
242$productcust = $langs->trans(
"ProductOrService");
243$amountcust = $langs->trans(
"AmountHT");
246$elementsup = $langs->trans(
"SuppliersInvoices");
247$productsup = $productcust;
248$amountsup = $amountcust;
251if ($modecompta ==
"BOOKKEEPING") {
252 $modecompta =
"CREANCES-DETTES";
254if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
255 $modecompta =
"RECETTES-DEPENSES";
259if ($modecompta ==
"CREANCES-DETTES") {
260 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
261 $calcmode = $langs->trans(
"CalcModeDebt");
264 $description .=
'<br>'.$langs->trans(
"RulesCADue");
266 $description .= $langs->trans(
"DepositsAreNotIncluded");
268 $description .= $langs->trans(
"DepositsAreIncluded");
271 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
275} elseif ($modecompta ==
"RECETTES-DEPENSES") {
276 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
277 $calcmode = $langs->trans(
"CalcModePayment");
280 $description .= $langs->trans(
"RulesCAIn");
281 $description .= $langs->trans(
"DepositsAreIncluded");
287$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0);
289$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
291 $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>';
296$description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
298report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
300if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
301 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
305if ($modecompta ==
'CREANCES-DETTES') {
306 print
'<table class="noborder centpercent">';
307 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
308 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
309 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
312 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
316 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
319 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
322 $sql =
"SELECT fd.tva_tx AS vatrate,";
323 $sql .=
" fd.product_type AS product_type,";
324 $sql .=
" cc.code, cc.label AS country,";
325 for ($i = 1; $i <= 12; $i++) {
326 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$i,
"fd.total_ht",
"0").
") AS month".str_pad((
string) $i, 2,
"0", STR_PAD_LEFT).
",";
328 $sql .=
" SUM(fd.total_ht) as total";
329 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
330 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
331 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
332 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
333 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
334 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
335 $sql .=
" AND f.fk_statut in (1,2)";
337 $sql .=
" AND f.type IN (0,1,2,5)";
339 $sql .=
" AND f.type IN (0,1,2,3,5)";
341 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
342 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
343 $sql .=
" ORDER BY country, product_type, vatrate";
345 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
346 $resql = $db->query($sql);
348 $num = $db->num_rows($resql);
349 $totalpermonth = array();
350 while ($obj = $db->fetch_object($resql)) {
351 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
352 if ($obj->product_type == 0) {
353 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
355 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
359 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
361 for ($i = 0; $i < 12; $i++) {
362 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
366 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
367 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
368 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
370 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
371 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
377 print
'<tr class="liste_total"><td class="right"></td>';
378 print
'<td class="left"></td>';
380 for ($i = 0; $i < 12; $i++) {
381 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
385 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
386 print
'<td class="right" width="6%">'.price((empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j])).
'</td>';
388 print
'<td class="right" width="6%"><b>'.price((empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total'])).
'</b></td>';
391 print $db->lasterror();
394 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
395 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
396 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
399 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
403 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
406 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
409 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
410 $sql2 .=
" ffd.product_type AS product_type,";
411 $sql2 .=
" cc.code, cc.label AS country,";
412 for ($i = 1; $i <= 12; $i++) {
413 $sql2 .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$i,
"ffd.total_ht",
"0").
") AS month".str_pad((
string) $i, 2,
"0", STR_PAD_LEFT).
",";
415 $sql2 .=
" SUM(ffd.total_ht) as total";
416 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
417 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
418 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
419 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
420 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
421 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
422 $sql .=
" AND ff.fk_statut in (1,2)";
424 $sql .=
" AND ff.type IN (0,1,2,5)";
426 $sql .=
" AND ff.type IN (0,1,2,3,5)";
428 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
429 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
430 $sql2 .=
" ORDER BY country, product_type, vatrate";
433 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
434 $resql2 = $db->query($sql2);
436 $num = $db->num_rows($resql2);
437 $totalpermonth = array();
438 while ($obj = $db->fetch_object($resql2)) {
439 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
440 if ($obj->product_type == 0) {
441 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
443 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
446 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
448 for ($i = 0; $i < 12; $i++) {
449 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
453 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
454 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
455 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
457 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
458 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
464 print
'<tr class="liste_total"><td class="right"></td>';
465 print
'<td class="left"></td>';
467 for ($i = 0; $i < 12; $i++) {
468 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
472 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
473 print
'<td class="right" width="6%">'.price(empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]).
'</td>';
475 print
'<td class="right" width="6%"><b>'.price(empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']).
'</b></td>';
478 print $db->lasterror();
486 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.