24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
39 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin",
"accountancy"));
41 $modecompta = (
GETPOST(
'modecompta',
'alpha') ?
GETPOST(
'modecompta',
'alpha') : $conf->global->ACCOUNTING_MODE);
45 $month =
GETPOST(
"month",
'int');
48 $year_current = strftime(
"%Y",
dol_now());
49 $month_current = strftime(
"%m",
dol_now());
50 $year_start = $year_current;
52 $year_current = $year;
53 $month_current = strftime(
"%m",
dol_now());
59 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;
70 if (!
GETPOST(
'year') && $month_start > $month_current)
75 $month_end = $month_start - 1;
76 if ($month_end < 1) $month_end = 12;
90 $year_start = $tmps[
'year'];
92 $year_end = $tmpe[
'year'];
95 if ($tmp_date_end < $date_end || $date_end < $date_start) $date_end = $tmp_date_end;
98 if (empty($min)) $min = 0;
102 $modetax = $conf->global->TAX_MODE;
104 if (empty($modetax)) $modetax = 0;
107 $socid =
GETPOST(
'socid',
'int');
108 if ($user->socid) $socid = $user->socid;
117 $form =
new Form($db);
118 $company_static =
new Societe($db);
119 $invoice_customer =
new Facture($db);
122 $product_static =
new Product($db);
123 $payment_static =
new Paiement($db);
127 $morequerystring =
'';
128 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
129 foreach ($listofparams as $param)
131 if (
GETPOST($param) !=
'') $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
134 llxHeader(
'', $langs->trans(
"TurnoverReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
140 $fsearch .=
' <input type="hidden" name="year" value="'.$year.
'">';
141 $fsearch .=
' <input type="hidden" name="modetax" value="'.$modetax.
'">';
147 $name = $langs->trans(
"xxx");
149 if ($modetax == 0) $calcmode = $langs->trans(
'OptionVATDefault');
150 if ($modetax == 1) $calcmode = $langs->trans(
'OptionVATDebitOption');
151 if ($modetax == 2) $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
152 $calcmode .=
'<br>('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')';
154 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
155 $prevyear = $year_start; $prevquarter = $q;
156 if ($prevquarter > 1) {
159 $prevquarter = 4; $prevyear--;
161 $nextyear = $year_start; $nextquarter = $q;
162 if ($nextquarter < 4) {
165 $nextquarter = 1; $nextyear++;
167 $description .= $fsearch;
170 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') $description .= $langs->trans(
"RulesVATDueProducts");
171 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') $description .= $langs->trans(
"RulesVATInProducts");
172 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
173 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
174 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
175 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
177 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
180 $elementcust = $langs->trans(
"CustomersInvoices");
181 $productcust = $langs->trans(
"ProductOrService");
182 $amountcust = $langs->trans(
"AmountHT");
185 $elementsup = $langs->trans(
"SuppliersInvoices");
186 $productsup = $productcust;
187 $amountsup = $amountcust;
188 $namesup = $namecust;
193 if ($modecompta ==
"BOOKKEEPING") $modecompta =
"CREANCES-DETTES";
194 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") $modecompta =
"RECETTES-DEPENSES";
197 if ($modecompta ==
"CREANCES-DETTES") {
198 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByVatRate");
199 $calcmode = $langs->trans(
"CalcModeDebt");
202 $description = $langs->trans(
"RulesCADue");
203 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
204 $description .= $langs->trans(
"DepositsAreNotIncluded");
206 $description .= $langs->trans(
"DepositsAreIncluded");
210 } elseif ($modecompta ==
"RECETTES-DEPENSES")
212 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByVatRate");
213 $calcmode = $langs->trans(
"CalcModeEngagement");
216 $description = $langs->trans(
"RulesCAIn");
217 $description .= $langs->trans(
"DepositsAreIncluded");
220 } elseif ($modecompta ==
"BOOKKEEPING")
222 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED")
225 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
226 if ($date_end ==
dol_time_plus_duree($date_start, 1,
'y') - 1) $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>';
227 else $periodlink =
'';
229 $description .=
' <input type="hidden" name="modecompta" value="'.$modecompta.
'">';
231 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
233 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
239 if ($modecompta ==
'CREANCES-DETTES') {
240 print '<table class="noborder centpercent">';
241 print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"TurnoverbyVatrate").
'</td>';
242 print '<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
243 print '<td class="left">'.$langs->trans(
"Country").
'</td>';
246 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
247 if ($j > 12) $j -= 12;
248 print '<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
251 print '<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
253 $sql =
"SELECT fd.tva_tx AS vatrate,";
254 $sql .=
" fd.product_type AS product_type,";
255 $sql .=
" cc.code, cc.label AS country,";
256 for ($i = 1; $i <= 12; $i++) {
257 $sql .=
" SUM(".$db->ifsql(
'MONTH(f.datef)='.$i,
'fd.total_ht',
'0').
") AS month".str_pad($i, 2,
'0', STR_PAD_LEFT).
",";
259 $sql .=
" SUM(fd.total_ht) as total";
260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd";
261 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture as f ON f.rowid = fd.fk_facture";
262 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = f.fk_soc";
263 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
264 $sql .=
" WHERE f.datef >= '".$db->idate($date_start).
"'";
265 $sql .=
" AND f.datef <= '".$db->idate($date_end).
"'";
266 $sql .=
" AND f.fk_statut in (1,2)";
267 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
268 $sql .=
" AND f.type IN (0,1,2,5)";
270 $sql .=
" AND f.type IN (0,1,2,3,5)";
272 $sql .=
" AND f.entity IN (".getEntity(
'invoice', 0).
")";
273 $sql .=
" GROUP BY fd.tva_tx,fd.product_type, cc.label, cc.code ";
274 $sql .=
" ORDER BY country, product_type, vatrate";
277 dol_syslog(
"htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
278 $resql = $db->query($sql);
280 $num = $db->num_rows(
$resql);
281 $totalpermonth = array();
282 while ($obj = $db->fetch_object(
$resql)) {
283 print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
284 if ($obj->product_type == 0) {
285 print '<td class="left">'.$langs->trans(
"Product").
'</td>';
287 print '<td class="left">'.$langs->trans(
"Service").
'</td>';
291 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
293 for ($i = 0; $i < 12; $i++) {
294 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
295 if ($j > 12) $j -= 12;
296 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
297 print '<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
298 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
300 print '<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
301 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
307 print '<tr class="liste_total"><td class="right"></td>';
308 print '<td class="left"></td>';
310 for ($i = 0; $i < 12; $i++) {
311 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
312 if ($j > 12) $j -= 12;
313 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
314 print '<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
316 print '<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
319 print $db->lasterror();
323 print '<tr class="liste_titre"><td width="6%" class="right">'.$langs->trans(
"PurchasebyVatrate").
'</td>';
324 print '<td class="left">'.$langs->trans(
"ProductOrService").
'</td>';
325 print '<td class="left">'.$langs->trans(
"Country").
'</td>';
329 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
330 if ($j > 12) $j -= 12;
331 print '<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
334 print '<td width="60" class="right"><b>'.$langs->trans(
"TotalHT").
'</b></td></tr>';
336 $sql2 =
"SELECT ffd.tva_tx AS vatrate,";
337 $sql2 .=
" ffd.product_type AS product_type,";
338 $sql2 .=
" cc.code, cc.label AS country,";
339 for ($i = 1; $i <= 12; $i++) {
340 $sql2 .=
" SUM(".$db->ifsql(
'MONTH(ff.datef)='.$i,
'ffd.total_ht',
'0').
") AS month".str_pad($i, 2,
'0', STR_PAD_LEFT).
",";
342 $sql2 .=
" SUM(ffd.total_ht) as total";
343 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det as ffd";
344 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
345 $sql2 .=
" INNER JOIN ".MAIN_DB_PREFIX.
"societe as soc ON soc.rowid = ff.fk_soc";
346 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as cc ON cc.rowid = soc.fk_pays";
347 $sql2 .=
" WHERE ff.datef >= '".$db->idate($date_start).
"'";
348 $sql2 .=
" AND ff.datef <= '".$db->idate($date_end).
"'";
349 $sql .=
" AND ff.fk_statut in (1,2)";
350 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
351 $sql .=
" AND ff.type IN (0,1,2,5)";
353 $sql .=
" AND ff.type IN (0,1,2,3,5)";
355 $sql2 .=
" AND ff.entity IN (".getEntity(
"facture_fourn", 0).
")";
356 $sql2 .=
" GROUP BY ffd.tva_tx, ffd.product_type, cc.label, cc.code ";
357 $sql2 .=
" ORDER BY country, product_type, vatrate";
360 dol_syslog(
"htdocs/compta/tva/index.php sql=".$sql, LOG_DEBUG);
361 $resql2 = $db->query($sql2);
363 $num = $db->num_rows($resql2);
364 $totalpermonth = array();
365 while ($obj = $db->fetch_object($resql2)) {
366 print '<tr class="oddeven"><td class="right">'.vatrate($obj->vatrate).
'</td>';
367 if ($obj->product_type == 0) {
368 print '<td class="left">'.$langs->trans(
"Product").
'</td>';
370 print '<td class="left">'.$langs->trans(
"Service").
'</td>';
373 print $langs->trans(
"Country".$obj->code) !=
"Country".$obj->code ? $langs->trans(
"Country".$obj->code) : $obj->country;
375 for ($i = 0; $i < 12; $i++) {
376 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
377 if ($j > 12) $j -= 12;
378 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
379 print '<td class="right" width="6%">'.price($obj->$monthj).
'</td>';
380 $totalpermonth[$j] = (empty($totalpermonth[$j]) ? 0 : $totalpermonth[$j]) + $obj->$monthj;
382 print '<td class="right" width="6%"><b>'.price($obj->total).
'</b></td>';
383 $totalpermonth[
'total'] = (empty($totalpermonth[
'total']) ? 0 : $totalpermonth[
'total']) + $obj->total;
389 print '<tr class="liste_total"><td class="right"></td>';
390 print '<td class="left"></td>';
392 for ($i = 0; $i < 12; $i++) {
393 $j = $i + (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START);
394 if ($j > 12) $j -= 12;
395 $monthj =
'month'.str_pad($j, 2,
'0', STR_PAD_LEFT);
396 print '<td class="right" width="6%">'.price($totalpermonth[$j]).
'</td>';
398 print '<td class="right" width="6%"><b>'.price($totalpermonth[
'total']).
'</b></td>';
401 print $db->lasterror();
409 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.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage Trips and Expenses.
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Class to manage invoices.
Class to manage payments for supplier invoices.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.