30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
38 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
42 $year_start = $year_current;
44 $month_start = $month_current;
48 include DOL_DOCUMENT_ROOT.
'/compta/tva/initdatesforvat.inc.php';
52 $modetax = $conf->global->TAX_MODE;
54 $modetax =
GETPOST(
"modetax",
'int');
56 if (empty($modetax)) {
61 $socid =
GETPOST(
'socid',
'int');
63 $socid = $user->socid;
76 function pt($db, $sql, $date)
78 global $conf, $bc, $langs,
$form;
80 $result = $db->query($sql);
82 $num = $db->num_rows($result);
85 print
'<table class="noborder centpercent">';
87 print
'<tr class="liste_titre">';
88 print
'<td class="nowrap">'.$date.
'</td>';
89 print
'<td class="right">'.$langs->trans(
"ClaimedForThisPeriod").
'</td>';
90 print
'<td class="right">'.$langs->trans(
"PaidDuringThisPeriod").$form->textwithpicto(
'', $langs->trans(
'PaidDuringThisPeriodDesc'), 1).
'</td>';
102 $obj = $db->fetch_object($result);
106 if ($obj->mode ==
'claimed' && !empty($previousmode)) {
107 print
'<tr class="oddeven">';
108 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
109 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
110 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
117 if ($obj->mode ==
'claimed') {
118 $amountclaimed = $obj->mm;
119 $totalclaimed = $totalclaimed + $amountclaimed;
121 if ($obj->mode ==
'paid') {
122 $amountpaid = $obj->mm;
123 $totalpaid = $totalpaid + $amountpaid;
126 if ($obj->mode ==
'paid') {
127 print
'<tr class="oddeven">';
128 print
'<td class="nowrap">'.$obj->dm.
"</td>\n";
129 print
'<td class="nowrap right"><span class="amount">'.price($amountclaimed).
"</span></td>\n";
130 print
'<td class="nowrap right"><span class="amount">'.price($amountpaid).
"</span></td>\n";
137 $previousmode = $obj->mode;
138 $previousmonth = $obj->dm;
144 if ($mode ==
'claimed' && !empty($previousmode)) {
145 print
'<tr class="oddeven">';
146 print
'<td class="nowrap">'.$previousmonth.
"</td>\n";
147 print
'<td class="nowrap right">'.price($amountclaimed).
"</td>\n";
148 print
'<td class="nowrap right">'.price($amountpaid).
"</td>\n";
155 print
'<tr class="liste_total">';
156 print
'<td class="right">'.$langs->trans(
"Total").
'</td>';
157 print
'<td class="nowrap right">'.price($totalclaimed).
'</td>';
158 print
'<td class="nowrap right">'.price($totalpaid).
'</td>';
175 $company_static =
new Societe($db);
178 $fsearch =
'<!-- hidden fields for form -->';
179 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
180 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
182 $description = $fsearch;
185 $name = $langs->trans(
"VATReportByMonth");
188 $calcmode = $langs->trans(
'OptionVATDefault');
191 $calcmode = $langs->trans(
'OptionVATDebitOption');
194 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
196 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
198 $description .= $langs->trans(
"VATSummary").
'<br>';
199 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
200 $description .= $langs->trans(
"RulesVATDueProducts");
202 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
203 $description .= $langs->trans(
"RulesVATInProducts");
205 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
206 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
208 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
209 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
211 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
212 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
214 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
215 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
217 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
218 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
221 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
232 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
238 if ($refresh ===
true) {
239 print
'<div class="fichecenter"><div class="fichethirdleft">';
243 print
'<table class="noborder centpercent">';
244 print
'<tr class="liste_titre">';
245 print
'<td width="30%">' . $langs->trans(
"Year") .
" " . $y .
'</td>';
246 print
'<td class="right">' . $langs->trans(
"VATToPay") .
'</td>';
247 print
'<td class="right">' . $langs->trans(
"VATToCollect") .
'</td>';
248 print
'<td class="right">' . $langs->trans(
"Balance") .
'</td>';
249 print
'<td> </td>' .
"\n";
250 print
'</tr>' .
"\n";
256 $yend = $tmp[
'year'];
266 while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) {
276 $x_coll =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'sell', $m);
277 $x_paye =
tax_by_rate(
'vat', $db, $y, 0, 0, 0, $modetax,
'buy', $m);
281 foreach (array_keys($x_coll) as $my_coll_rate) {
282 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
283 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
284 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
285 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
286 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
287 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
288 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
293 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
294 'id' => $x_coll[$my_coll_rate][
'facid'][$id],
295 'descr' => $x_coll[$my_coll_rate][
'descr'][$id],
296 'pid' => $x_coll[$my_coll_rate][
'pid'][$id],
297 'pref' => $x_coll[$my_coll_rate][
'pref'][$id],
298 'ptype' => $x_coll[$my_coll_rate][
'ptype'][$id],
299 'payment_id' => $x_coll[$my_coll_rate][
'payment_id'][$id],
300 'payment_amount' => $x_coll[$my_coll_rate][
'payment_amount'][$id],
301 'ftotal_ttc' => $x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
302 'dtotal_ttc' => $x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
303 'dtype' => $x_coll[$my_coll_rate][
'dtype'][$id],
304 'datef' => $x_coll[$my_coll_rate][
'datef'][$id],
305 'datep' => $x_coll[$my_coll_rate][
'datep'][$id],
307 'ddate_start' => $x_coll[$my_coll_rate][
'ddate_start'][$id],
308 'ddate_end' => $x_coll[$my_coll_rate][
'ddate_end'][$id],
309 'totalht' => $x_coll[$my_coll_rate][
'totalht_list'][$id],
310 'vat' => $x_coll[$my_coll_rate][
'vat_list'][$id],
317 foreach (array_keys($x_paye) as $my_paye_rate) {
318 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
319 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
320 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
321 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
322 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
324 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
325 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
327 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
329 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
334 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
335 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
336 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
337 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
338 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
339 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
340 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
341 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
342 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
343 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
344 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
345 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
346 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
347 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
348 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
356 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
357 'id' => $x_paye[$my_paye_rate][
'facid'][$id],
358 'descr' => $x_paye[$my_paye_rate][
'descr'][$id],
359 'pid' => $x_paye[$my_paye_rate][
'pid'][$id],
360 'pref' => $x_paye[$my_paye_rate][
'pref'][$id],
361 'ptype' => $x_paye[$my_paye_rate][
'ptype'][$id],
362 'payment_id' => $x_paye[$my_paye_rate][
'payment_id'][$id],
363 'payment_amount' => $x_paye[$my_paye_rate][
'payment_amount'][$id],
364 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
365 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
366 'dtype' => $x_paye[$my_paye_rate][
'dtype'][$id],
367 'datef' => $x_paye[$my_paye_rate][
'datef'][$id],
368 'datep' => $x_paye[$my_paye_rate][
'datep'][$id],
370 'ddate_start' => $x_paye[$my_paye_rate][
'ddate_start'][$id],
371 'ddate_end' => $x_paye[$my_paye_rate][
'ddate_end'][$id],
372 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
373 'vat' => $x_paye[$my_paye_rate][
'vat_list'][$id],
382 $object = array(&$x_coll, &$x_paye, &$x_both);
383 $parameters[
"mode"] = $modetax;
384 $parameters[
"year"] = $y;
385 $parameters[
"month"] = $m;
386 $parameters[
"type"] =
'vat';
389 $hookmanager->initHooks(array(
'externalbalance'));
390 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
393 print
'<tr class="oddeven">';
394 print
'<td class="nowrap"><a href="' . DOL_URL_ROOT .
'/compta/tva/quadri_detail.php?leftmenu=tax_vat&month=' . $m .
'&year=' . $y .
'">' .
dol_print_date(
dol_mktime(0, 0, 0, $m, 1, $y),
"%b %Y") .
'</a></td>';
397 foreach (array_keys($x_coll) as $rate) {
398 $subtot_coll_total_ht = 0;
399 $subtot_coll_vat = 0;
401 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
403 $ratiopaymentinvoice = 1;
407 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
410 if (!empty($fields[
'ddate_start'])) {
413 if (!empty($fields[
'ddate_end'])) {
417 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
418 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
421 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
422 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
427 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
428 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
429 $subtot_coll_total_ht += $temp_ht;
430 $subtot_coll_vat += $temp_vat;
431 $x_coll_sum += $temp_vat;
434 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_coll_sum,
'MT')) .
'</span></td>';
437 foreach (array_keys($x_paye) as $rate) {
438 $subtot_paye_total_ht = 0;
439 $subtot_paye_vat = 0;
441 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
443 $ratiopaymentinvoice = 1;
447 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
450 if (!empty($fields[
'ddate_start'])) {
453 if (!empty($fields[
'ddate_end'])) {
457 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
458 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
461 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
462 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
467 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
468 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
469 $subtot_paye_total_ht += $temp_ht;
470 $subtot_paye_vat += $temp_vat;
471 $x_paye_sum += $temp_vat;
474 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($x_paye_sum,
'MT')) .
'</span></td>';
476 $subtotalcoll = $subtotalcoll + $x_coll_sum;
477 $subtotalpaid = $subtotalpaid + $x_paye_sum;
479 $diff = $x_coll_sum - $x_paye_sum;
480 $total = $total + $diff;
481 $subtotal =
price2num($subtotal + $diff,
'MT');
483 print
'<td class="nowrap right"><span class="amount">' .
price(
price2num($diff,
'MT')) .
'</span></td>' .
"\n";
484 print
"<td> </td>\n";
491 print
'<tr class="liste_total">';
492 print
'<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q=' . round($m / 3) .
'&year=' . $y .
'">' . $langs->trans(
"SubTotal") .
'</a>:</td>';
493 print
'<td class="nowrap right">' .
price(
price2num($subtotalcoll,
'MT')) .
'</td>';
494 print
'<td class="nowrap right">' .
price(
price2num($subtotalpaid,
'MT')) .
'</td>';
495 print
'<td class="nowrap right">' .
price(
price2num($subtotal,
'MT')) .
'</td>';
496 print
'<td> </td></tr>';
503 print
'<tr class="liste_total"><td class="right" colspan="3">' . $langs->trans(
"TotalToPay") .
':</td><td class="nowrap right">' .
price(
price2num($total,
'MT')) .
'</td>';
504 print
"<td> </td>\n";
510 print
'</div><div class="fichetwothirdright">';
520 $sql .=
"SELECT SUM(amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'claimed' as mode";
521 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
522 $sql .=
" WHERE tva.entity = " . $conf->entity;
523 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
524 $sql .=
" GROUP BY dm";
528 $sql .=
"SELECT SUM(ptva.amount) as mm, date_format(tva.datev,'%Y-%m') as dm, 'paid' as mode";
529 $sql .=
" FROM " . MAIN_DB_PREFIX .
"tva as tva";
530 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"payment_vat as ptva ON (tva.rowid = ptva.fk_tva)";
531 $sql .=
" WHERE tva.entity = " . $conf->entity;
532 $sql .=
" AND (tva.datev >= '" . $db->idate($date_start) .
"' AND tva.datev <= '" . $db->idate($date_end) .
"')";
533 $sql .=
" GROUP BY dm";
535 $sql .=
" ORDER BY dm ASC, mode ASC";
538 pt($db, $sql, $langs->trans(
"Month"));
Class to manage third parties objects (customers, suppliers, prospects...)
Put here description of your class.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
pt($db, $sql, $date)
print function
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
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.
tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
Gets Tax to collect for the given year (and given quarter or month) The function gets the Tax in spli...