26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
38 require_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);
47 $month =
GETPOST(
"month",
'int');
51 $year_start = $year_current;
53 $year_current = $year;
62 if (empty($date_start) || empty($date_end)) {
66 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
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'];
110 if ($tmp_date_end < $date_end || $date_end < $date_start) {
111 $date_end = $tmp_date_end;
121 $modetax = empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE;
123 $modetax =
GETPOST(
"modetax",
'int');
125 if (empty($modetax)) {
130 $socid =
GETPOST(
'socid',
'int');
132 $socid = $user->socid;
143 $company_static =
new Societe($db);
144 $invoice_customer =
new Facture($db);
147 $product_static =
new Product($db);
148 $payment_static =
new Paiement($db);
152 $morequerystring =
'';
153 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
154 foreach ($listofparams as $param) {
156 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
160 llxHeader(
'', $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;
193 if ($prevquarter > 1) {
199 $nextyear = $year_start;
201 if ($nextquarter < 4) {
207 $description = $fsearch;
210 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
211 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
213 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
214 $description .=
'<br>'.$langs->trans(
"RulesVATDueProducts");
216 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
217 $description .=
'<br>'.$langs->trans(
"RulesVATInProducts");
219 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
220 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
222 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
223 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
225 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
226 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
228 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
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;
242 if ($modecompta ==
"BOOKKEEPING") {
243 $modecompta =
"CREANCES-DETTES";
245 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
246 $modecompta =
"RECETTES-DEPENSES";
250 if ($modecompta ==
"CREANCES-DETTES") {
251 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
252 $calcmode = $langs->trans(
"CalcModeDebt");
255 $description .=
'<br>'.$langs->trans(
"RulesCADue");
256 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
257 $description .= $langs->trans(
"DepositsAreNotIncluded");
259 $description .= $langs->trans(
"DepositsAreIncluded");
261 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
262 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
266 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
267 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
268 $calcmode = $langs->trans(
"CalcModeEngagement");
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.
'">';
289 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
291 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
292 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
296 if ($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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
307 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($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($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)";
327 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
357 $monthj =
'month'.str_pad($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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
376 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
377 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
379 print
'<td class="right" width="6%"><b>'.price($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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
394 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($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($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)";
414 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
444 $monthj =
'month'.str_pad($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 + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
463 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
464 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
466 print
'<td class="right" width="6%"><b>'.price($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()
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...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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 informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
img_next($titlealt='default', $moreatt='')
Show next logo.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
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.