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");
229 $elementcust = $langs->trans(
"CustomersInvoices");
230 $productcust = $langs->trans(
"ProductOrService");
231 $amountcust = $langs->trans(
"AmountHT");
234 $elementsup = $langs->trans(
"SuppliersInvoices");
235 $productsup = $productcust;
236 $amountsup = $amountcust;
239 if ($modecompta ==
"BOOKKEEPING") {
240 $modecompta =
"CREANCES-DETTES";
242 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
243 $modecompta =
"RECETTES-DEPENSES";
247 if ($modecompta ==
"CREANCES-DETTES") {
248 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
249 $calcmode = $langs->trans(
"CalcModeDebt");
252 $description .=
'<br>'.$langs->trans(
"RulesCADue");
253 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
254 $description .= $langs->trans(
"DepositsAreNotIncluded");
256 $description .= $langs->trans(
"DepositsAreIncluded");
260 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
261 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
262 $calcmode = $langs->trans(
"CalcModeEngagement");
265 $description .= $langs->trans(
"RulesCAIn");
266 $description .= $langs->trans(
"DepositsAreIncluded");
269 } elseif ($modecompta ==
"BOOKKEEPING") {
270 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
272 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0);
274 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
276 $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>';
281 $description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
283 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
285 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
286 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
290 if ($modecompta ==
'CREANCES-DETTES') {
291 print
'<table class="noborder centpercent">';
292 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
293 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
294 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
297 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
301 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
304 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
307 $sql =
"SELECT fd.tva_tx AS vatrate,";
308 $sql .=
" fd.product_type AS product_type,";
309 $sql .=
" cc.code, cc.label AS country,";
310 for ($i = 1; $i <= 12; $i++) {
311 $sql .=
" SUM(".$db->ifsql(
"MONTH(f.datef)=".$i,
"fd.total_ht",
"0").
") AS month".str_pad($i, 2,
"0", STR_PAD_LEFT).
",";
313 $sql .=
" SUM(fd.total_ht) as total";
314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
315 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
316 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
317 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
318 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
319 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
320 $sql .=
" AND f.fk_statut in (1,2)";
321 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
322 $sql .=
" AND f.type IN (0,1,2,5)";
324 $sql .=
" AND f.type IN (0,1,2,3,5)";
326 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
327 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
328 $sql .=
" ORDER BY country, product_type, vatrate";
330 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
331 $resql = $db->query($sql);
333 $num = $db->num_rows(
$resql);
334 $totalpermonth = array();
335 while ($obj = $db->fetch_object(
$resql)) {
336 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
337 if ($obj->product_type == 0) {
338 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
340 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
344 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
346 for ($i = 0; $i < 12; $i++) {
347 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
351 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
352 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
353 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
355 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
356 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
362 print
'<tr class="liste_total"><td class="right"></td>';
363 print
'<td class="left"></td>';
365 for ($i = 0; $i < 12; $i++) {
366 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
370 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
371 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
373 print
'<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
376 print $db->lasterror();
379 print
'<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
380 print
'<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
381 print
'<td class="left">'.$langs->trans(
"Country").
'</td>';
384 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
388 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
391 print
'<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
394 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
395 $sql2 .=
" ffd.product_type AS product_type,";
396 $sql2 .=
" cc.code, cc.label AS country,";
397 for ($i = 1; $i <= 12; $i++) {
398 $sql2 .=
" SUM(".$db->ifsql(
"MONTH(ff.datef)=".$i,
"ffd.total_ht",
"0").
") AS month".str_pad($i, 2,
"0", STR_PAD_LEFT).
",";
400 $sql2 .=
" SUM(ffd.total_ht) as total";
401 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
402 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
403 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
404 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
405 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
406 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
407 $sql .=
" AND ff.fk_statut in (1,2)";
408 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
409 $sql .=
" AND ff.type IN (0,1,2,5)";
411 $sql .=
" AND ff.type IN (0,1,2,3,5)";
413 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
414 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
415 $sql2 .=
" ORDER BY country, product_type, vatrate";
418 dol_syslog(
"htdocs/compta/tva/index.php", LOG_DEBUG);
419 $resql2 = $db->query($sql2);
421 $num = $db->num_rows($resql2);
422 $totalpermonth = array();
423 while ($obj = $db->fetch_object($resql2)) {
424 print
'<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
425 if ($obj->product_type == 0) {
426 print
'<td class="left">'.$langs->trans(
"Product").
'</td>';
428 print
'<td class="left">'.$langs->trans(
"Service").
'</td>';
431 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
433 for ($i = 0; $i < 12; $i++) {
434 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
438 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
439 print
'<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
440 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
442 print
'<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
443 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
449 print
'<tr class="liste_total"><td class="right"></td>';
450 print
'<td class="left"></td>';
452 for ($i = 0; $i < 12; $i++) {
453 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
457 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
458 print
'<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
460 print
'<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
463 print $db->lasterror();
471 print
'<br>'.$langs->trans(
"TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant").
'<br>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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...
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Class to manage suppliers invoices.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
Class to manage Trips and Expenses.
restrictedArea($user, $features, $objectid=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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
Class to manage payments of expense report.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage invoices.
Class to manage payments for supplier invoices.