28require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
51$langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin",
"accountancy"));
61 $year_start = $year_current;
63 $year_current = $year;
72if (empty($date_start) || empty($date_end)) {
77 $year_end = $year_start;
78 $month_end = $month_start;
80 if (!
GETPOST(
'year') && $month_start > $month_current) {
84 $month_end = $month_start - 1;
115$year_start = $tmps[
'year'];
117$year_end = $tmpe[
'year'];
120if ($tmp_date_end < $date_end || $date_end < $date_start) {
121 $date_end = $tmp_date_end;
135if (empty($modetax)) {
142 $socid = $user->socid;
152$form =
new Form($db);
153$company_static =
new Societe($db);
154$invoice_customer =
new Facture($db);
157$product_static =
new Product($db);
162$morequerystring =
'';
163$listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
164foreach ($listofparams as $param) {
166 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
170llxHeader(
'', $langs->trans(
"TurnoverReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
178$fsearch .=
' <input type="hidden" name="year" value="'.$year.
'">';
179$fsearch .=
' <input type="hidden" name="modetax" value="'.$modetax.
'">';
185$name = $langs->trans(
"xxx");
188 $calcmode = $langs->trans(
'OptionVATDefault');
191 $calcmode = $langs->trans(
'OptionVATDebitOption');
194 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
196$calcmode .=
'<br>('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')';
198$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
200$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
201$prevyear = $year_start;
203if ($prevquarter > 1) {
209$nextyear = $year_start;
211if ($nextquarter < 4) {
217$description = $fsearch;
221 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
224 $description .=
'<br>'.$langs->trans(
"RulesVATDueProducts");
227 $description .=
'<br>'.$langs->trans(
"RulesVATInProducts");
230 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
233 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
236 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
239 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
242$elementcust = $langs->trans(
"CustomersInvoices");
243$productcust = $langs->trans(
"ProductOrService");
244$amountcust = $langs->trans(
"AmountHT");
247$elementsup = $langs->trans(
"SuppliersInvoices");
248$productsup = $productcust;
249$amountsup = $amountcust;
252if ($modecompta ==
"BOOKKEEPING") {
253 $modecompta =
"CREANCES-DETTES";
255if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
256 $modecompta =
"RECETTES-DEPENSES";
260if ($modecompta ==
"CREANCES-DETTES") {
261 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
262 $calcmode = $langs->trans(
"CalcModeDebt");
265 $description .=
'<br>'.$langs->trans(
"RulesCADue");
267 $description .= $langs->trans(
"DepositsAreNotIncluded");
269 $description .= $langs->trans(
"DepositsAreIncluded");
272 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
276} elseif ($modecompta ==
"RECETTES-DEPENSES") {
277 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
278 $calcmode = $langs->trans(
"CalcModePayment");
281 $description .= $langs->trans(
"RulesCAIn");
282 $description .= $langs->trans(
"DepositsAreIncluded");
288$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0);
290$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
292 $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>';
297$description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
299report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
301if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
302 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
306if ($modecompta ==
'CREANCES-DETTES') {
307 print
'<table class="noborder centpercent">';
308 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
309 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
310 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
317 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
320 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
323 $sql =
"SELECT fd.tva_tx AS vatrate,";
324 $sql .=
" fd.product_type AS product_type,";
325 $sql .=
" cc.code, cc.label AS country,";
326 for ($i = 1; $i <= 12; $i++) {
327 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".((
int) $i),
"fd.total_ht",
"0").
") AS month".str_pad((
string) ((
int) $i), 2,
"0", STR_PAD_LEFT).
",";
329 $sql .=
" SUM(fd.total_ht) as total";
330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
331 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
332 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
333 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
334 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
335 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
336 $sql .=
" AND f.fk_statut in (1,2)";
338 $sql .=
" AND f.type IN (0,1,2,5)";
340 $sql .=
" AND f.type IN (0,1,2,3,5)";
343 $hookmanager->initHooks(array(
'turnoverreport'));
344 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
345 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
346 $sql .= $hookmanager->resPrint;
347 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
348 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
349 $sql .=
" ORDER BY country, product_type, vatrate";
351 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
352 $resql = $db->query($sql);
354 $num = $db->num_rows($resql);
355 $totalpermonth = array();
356 while ($obj = $db->fetch_object($resql)) {
357 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
358 if ($obj->product_type == 0) {
359 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
361 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
365 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
367 for ($i = 0; $i < 12; $i++) {
368 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
372 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
373 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
374 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
376 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
377 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
383 print
'<tr class="liste_total"><td class="right"></td>';
384 print
'<td class="left"></td>';
386 for ($i = 0; $i < 12; $i++) {
387 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
391 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
392 print
'<td class="right" width="6%">'.price((empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j])).
'</td>';
394 print
'<td class="right" width="6%"><b>'.price((empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total'])).
'</b></td>';
397 print $db->lasterror();
400 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
401 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
402 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
405 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
409 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
412 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
415 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
416 $sql2 .=
" ffd.product_type AS product_type,";
417 $sql2 .=
" cc.code, cc.label AS country,";
418 for ($i = 1; $i <= 12; $i++) {
419 $sql2 .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".((
int) $i),
"ffd.total_ht",
"0").
") AS month".str_pad((
string) ((
int) $i), 2,
"0", STR_PAD_LEFT).
",";
421 $sql2 .=
" SUM(ffd.total_ht) as total";
422 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
423 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
424 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
425 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
426 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
427 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
428 $sql .=
" AND ff.fk_statut in (1,2)";
430 $sql .=
" AND ff.type IN (0,1,2,5)";
432 $sql .=
" AND ff.type IN (0,1,2,3,5)";
435 $hookmanager->initHooks(array(
'turnoverreport'));
436 $parameters = array(
'invoicealias' =>
'ff',
'issupplier' => 1,
'datefield' =>
'datef');
437 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
438 $sql .= $hookmanager->resPrint;
439 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
440 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
441 $sql2 .=
" ORDER BY country, product_type, vatrate";
444 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
445 $resql2 = $db->query($sql2);
447 $num = $db->num_rows($resql2);
448 $totalpermonth = array();
449 while ($obj = $db->fetch_object($resql2)) {
450 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
451 if ($obj->product_type == 0) {
452 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
454 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
457 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
459 for ($i = 0; $i < 12; $i++) {
460 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
464 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
465 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
466 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
468 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
469 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
475 print
'<tr class="liste_total"><td class="right"></td>';
476 print
'<td class="left"></td>';
478 for ($i = 0; $i < 12; $i++) {
479 $j = $i + (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 1 :
$conf->global->SOCIETE_FISCAL_MONTH_START);
483 $monthj =
'month'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT);
484 print
'<td class="right" width="6%">'.price(empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]).
'</td>';
486 print
'<td class="right" width="6%"><b>'.price(empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']).
'</b></td>';
489 print $db->lasterror();
497 print
'<br>'.$langs->trans(
"TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").
'<br>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
img_next($titlealt='default', $moreatt='')
Show next logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.