31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
46 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
50 $vat_rate_show =
GETPOSTISSET(
'vat_rate_show') ?
GETPOST(
'vat_rate_show',
'alphanohtml') : -1;
52 include DOL_DOCUMENT_ROOT.
'/compta/tva/initdatesforvat.inc.php';
61 $modetax = (empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE);
65 if (empty($modetax)) {
69 $object =
new Tva($db);
74 $socid = $user->socid;
84 $company_static =
new Societe($db);
85 $invoice_customer =
new Facture($db);
88 $product_static =
new Product($db);
93 $morequerystring =
'';
94 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
95 foreach ($listofparams as $param) {
97 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
102 llxHeader(
'', $title,
'',
'', 0, 0,
'',
'', $morequerystring);
108 $fsearch =
'<!-- hidden fields for form -->';
109 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
110 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
116 $name = $langs->trans(
"VATReportByRates");
119 $calcmode = $langs->trans(
'OptionVATDefault');
122 $calcmode = $langs->trans(
'OptionVATDebitOption');
125 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
127 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
129 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
131 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
132 $prevyear = $date_start_year;
134 if ($prevquarter > 1) {
140 $nextyear = $date_start_year;
142 if ($nextquarter < 4) {
148 $description .= $fsearch;
151 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
152 $description .= $langs->trans(
"RulesVATDueProducts");
154 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
155 $description .= $langs->trans(
"RulesVATInProducts");
157 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
158 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
160 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
161 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
163 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
164 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
166 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
167 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
169 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
170 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
174 $elementcust = $langs->trans(
"CustomersInvoices");
175 $productcust = $langs->trans(
"ProductOrService");
176 $amountcust = $langs->trans(
"AmountHT");
177 $vatcust = $langs->trans(
"VATReceived");
178 $namecust = $langs->trans(
"Name");
179 if ($mysoc->tva_assuj) {
180 $vatcust .=
' ('.$langs->trans(
"VATToPay").
')';
184 $elementsup = $langs->trans(
"SuppliersInvoices");
185 $productsup = $productcust;
186 $amountsup = $amountcust;
187 $vatsup = $langs->trans(
"VATPaid");
188 $namesup = $namecust;
189 if ($mysoc->tva_assuj) {
190 $vatsup .=
' ('.$langs->trans(
"ToGetBack").
')';
193 $optioncss =
GETPOST(
'optioncss',
'alpha');
194 if ($optioncss !=
"print") {
195 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
198 $vatcust = $langs->trans(
"VATReceived");
199 $vatsup = $langs->trans(
"VATPaid");
200 $vatexpensereport = $langs->trans(
"VATPaid");
204 print
'<div class="div-table-responsive">';
205 print
'<table class="noborder centpercent">';
217 $x_coll =
tax_by_rate(
'vat', $db, 0, 0, $date_start, $date_end, $modetax,
'sell');
218 $x_paye =
tax_by_rate(
'vat', $db, 0, 0, $date_start, $date_end, $modetax,
'buy');
220 if (!is_array($x_coll) || !is_array($x_paye)) {
221 $langs->load(
"errors");
223 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
224 } elseif ($x_coll == -2) {
225 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
227 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
232 foreach (array_keys($x_coll) as $my_coll_rate) {
233 $x_both[$my_coll_rate][
'coll'][
'totalht'] = $x_coll[$my_coll_rate][
'totalht'];
234 $x_both[$my_coll_rate][
'coll'][
'vat'] = $x_coll[$my_coll_rate][
'vat'];
235 $x_both[$my_coll_rate][
'paye'][
'totalht'] = 0;
236 $x_both[$my_coll_rate][
'paye'][
'vat'] = 0;
237 $x_both[$my_coll_rate][
'coll'][
'links'] =
'';
238 $x_both[$my_coll_rate][
'coll'][
'detail'] = array();
239 foreach ($x_coll[$my_coll_rate][
'facid'] as $id => $dummy) {
240 $invoice_customer->id = $x_coll[$my_coll_rate][
'facid'][$id];
241 $invoice_customer->ref = $x_coll[$my_coll_rate][
'facnum'][$id];
242 $invoice_customer->type = $x_coll[$my_coll_rate][
'type'][$id];
245 $company_static->id = $x_coll[$my_coll_rate][
'company_id'][$id];
246 $company_static->name = $x_coll[$my_coll_rate][
'company_name'][$id];
247 $company_static->name_alias = $x_coll[$my_coll_rate][
'company_alias'][$id];
248 $company_static->email = $x_coll[$my_coll_rate][
'company_email'][$id];
249 $company_static->tva_intra = $x_coll[$my_coll_rate][
'tva_intra'][$id];
250 $company_static->client = $x_coll[$my_coll_rate][
'company_client'][$id];
251 $company_static->fournisseur = $x_coll[$my_coll_rate][
'company_fournisseur'][$id];
252 $company_static->status = $x_coll[$my_coll_rate][
'company_status'][$id];
253 $company_static->code_client = $x_coll[$my_coll_rate][
'company_customer_code'][$id];
254 $company_static->code_compta_client = $x_coll[$my_coll_rate][
'company_customer_accounting_code'][$id];
255 $company_static->code_fournisseur = $x_coll[$my_coll_rate][
'company_supplier_code'][$id];
256 $company_static->code_compta_fournisseur = $x_coll[$my_coll_rate][
'company_supplier_accounting_code'][$id];
258 $x_both[$my_coll_rate][
'coll'][
'detail'][] = array(
259 'id' =>$x_coll[$my_coll_rate][
'facid'][$id],
260 'descr' =>$x_coll[$my_coll_rate][
'descr'][$id],
261 'pid' =>$x_coll[$my_coll_rate][
'pid'][$id],
262 'pref' =>$x_coll[$my_coll_rate][
'pref'][$id],
263 'ptype' =>$x_coll[$my_coll_rate][
'ptype'][$id],
264 'payment_id'=>$x_coll[$my_coll_rate][
'payment_id'][$id],
265 'payment_ref'=>$x_coll[$my_coll_rate][
'payment_ref'][$id],
266 'payment_amount'=>$x_coll[$my_coll_rate][
'payment_amount'][$id],
267 'ftotal_ttc'=>$x_coll[$my_coll_rate][
'ftotal_ttc'][$id],
268 'dtotal_ttc'=>$x_coll[$my_coll_rate][
'dtotal_ttc'][$id],
269 'dtype' =>$x_coll[$my_coll_rate][
'dtype'][$id],
270 'datef' =>$x_coll[$my_coll_rate][
'datef'][$id],
271 'datep' =>$x_coll[$my_coll_rate][
'datep'][$id],
273 'company_link'=>$company_static->getNomUrl(1,
'', 20),
275 'ddate_start'=>$x_coll[$my_coll_rate][
'ddate_start'][$id],
276 'ddate_end' =>$x_coll[$my_coll_rate][
'ddate_end'][$id],
277 'totalht' =>$x_coll[$my_coll_rate][
'totalht_list'][$id],
278 'vat' =>$x_coll[$my_coll_rate][
'vat_list'][$id],
279 'link' =>$invoice_customer->getNomUrl(1,
'', 12)
284 foreach (array_keys($x_paye) as $my_paye_rate) {
285 $x_both[$my_paye_rate][
'paye'][
'totalht'] = $x_paye[$my_paye_rate][
'totalht'];
286 $x_both[$my_paye_rate][
'paye'][
'vat'] = $x_paye[$my_paye_rate][
'vat'];
287 if (!isset($x_both[$my_paye_rate][
'coll'][
'totalht'])) {
288 $x_both[$my_paye_rate][
'coll'][
'totalht'] = 0;
289 $x_both[$my_paye_rate][
'coll'][
'vat'] = 0;
291 $x_both[$my_paye_rate][
'paye'][
'links'] =
'';
292 $x_both[$my_paye_rate][
'paye'][
'detail'] = array();
294 foreach ($x_paye[$my_paye_rate][
'facid'] as $id => $dummy) {
296 if ($x_paye[$my_paye_rate][
'ptype'][$id] ==
'ExpenseReportPayment') {
297 $expensereport->id = $x_paye[$my_paye_rate][
'facid'][$id];
298 $expensereport->ref = $x_paye[$my_paye_rate][
'facnum'][$id];
299 $expensereport->type = $x_paye[$my_paye_rate][
'type'][$id];
301 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
302 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
303 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
304 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
305 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
306 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
307 'payment_id' =>$x_paye[$my_paye_rate][
'payment_id'][$id],
308 'payment_ref' =>$x_paye[$my_paye_rate][
'payment_ref'][$id],
309 'payment_amount' =>$x_paye[$my_paye_rate][
'payment_amount'][$id],
310 'ftotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
311 'dtotal_ttc' =>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
312 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
313 'ddate_start' =>$x_paye[$my_paye_rate][
'ddate_start'][$id],
314 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
315 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
316 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
317 'link' =>$expensereport->getNomUrl(1)
320 $invoice_supplier->id = $x_paye[$my_paye_rate][
'facid'][$id];
321 $invoice_supplier->ref = $x_paye[$my_paye_rate][
'facnum'][$id];
322 $invoice_supplier->type = $x_paye[$my_paye_rate][
'type'][$id];
324 $company_static->id = $x_paye[$my_paye_rate][
'company_id'][$id];
325 $company_static->name = $x_paye[$my_paye_rate][
'company_name'][$id];
326 $company_static->name_alias = $x_paye[$my_paye_rate][
'company_alias'][$id];
327 $company_static->email = $x_paye[$my_paye_rate][
'company_email'][$id];
328 $company_static->tva_intra = $x_paye[$my_paye_rate][
'tva_intra'][$id];
329 $company_static->client = $x_paye[$my_paye_rate][
'company_client'][$id];
330 $company_static->fournisseur = $x_paye[$my_paye_rate][
'company_fournisseur'][$id];
331 $company_static->status = $x_paye[$my_paye_rate][
'company_status'][$id];
332 $company_static->code_client = $x_paye[$my_paye_rate][
'company_customer_code'][$id];
333 $company_static->code_compta_client = $x_paye[$my_paye_rate][
'company_customer_accounting_code'][$id];
334 $company_static->code_fournisseur = $x_paye[$my_paye_rate][
'company_supplier_code'][$id];
335 $company_static->code_compta_fournisseur = $x_paye[$my_paye_rate][
'company_supplier_accounting_code'][$id];
337 $x_both[$my_paye_rate][
'paye'][
'detail'][] = array(
338 'id' =>$x_paye[$my_paye_rate][
'facid'][$id],
339 'descr' =>$x_paye[$my_paye_rate][
'descr'][$id],
340 'pid' =>$x_paye[$my_paye_rate][
'pid'][$id],
341 'pref' =>$x_paye[$my_paye_rate][
'pref'][$id],
342 'ptype' =>$x_paye[$my_paye_rate][
'ptype'][$id],
343 'payment_id'=>$x_paye[$my_paye_rate][
'payment_id'][$id],
344 'payment_ref'=>$x_paye[$my_paye_rate][
'payment_ref'][$id],
345 'payment_amount'=>$x_paye[$my_paye_rate][
'payment_amount'][$id],
346 'ftotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'ftotal_ttc'][$id]),
347 'dtotal_ttc'=>
price2num($x_paye[$my_paye_rate][
'dtotal_ttc'][$id]),
348 'dtype' =>$x_paye[$my_paye_rate][
'dtype'][$id],
349 'datef' =>$x_paye[$my_paye_rate][
'datef'][$id],
350 'datep' =>$x_paye[$my_paye_rate][
'datep'][$id],
352 'company_link'=>$company_static->getNomUrl(1,
'', 20),
354 'ddate_start'=>$x_paye[$my_paye_rate][
'ddate_start'][$id],
355 'ddate_end' =>$x_paye[$my_paye_rate][
'ddate_end'][$id],
356 'totalht' =>
price2num($x_paye[$my_paye_rate][
'totalht_list'][$id]),
357 'vat' =>$x_paye[$my_paye_rate][
'vat_list'][$id],
358 'link' =>$invoice_supplier->getNomUrl(1,
'', 12)
376 print
'<tr class="liste_titre">';
377 print
'<td class="left">'.$elementcust.
'</td>';
378 print
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
379 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment' || $conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
380 print
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
384 print
'<td class="left">'.$namecust.
'</td>';
385 print
'<td class="left">'.$productcust.
'</td>';
387 print
'<td class="right">'.$amountcust.
'</td>';
388 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
390 print
'<td class="right">'.$langs->trans(
"AmountHTVATRealReceived").
'</td>';
391 print
'<td class="right">'.$vatcust.
'</td>';
394 $action =
"tvadetail";
395 $parameters[
"mode"] = $modetax;
396 $parameters[
"start"] = $date_start;
397 $parameters[
"end"] = $date_end;
398 $parameters[
"type"] =
'vat';
400 $object = array(&$x_coll, &$x_paye, &$x_both);
402 $hookmanager->initHooks(array(
'externalbalance'));
403 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
405 foreach (array_keys($x_coll) as $rate) {
406 $subtot_coll_total_ht = 0;
407 $subtot_coll_vat = 0;
409 if (is_array($x_both[$rate][
'coll'][
'detail'])) {
412 print
'<td class="tax_rate" colspan="' . ($span+1) .
'">';
413 print $langs->trans(
'Rate') .
' : ' .
vatrate($rate) .
'%';
414 print
' - <a href="'.DOL_URL_ROOT.
'/compta/tva/quadri_detail.php?invoice_type=customer';
415 if ($invoice_type !=
'customer' || !
GETPOSTISSET(
'vat_rate_show') ||
GETPOST(
'vat_rate_show') != $rate) {
416 print
'&vat_rate_show='.urlencode($rate);
418 print
'&date_startyear='.urlencode($date_start_year).
'&date_startmonth='.urlencode($date_start_month).
'&date_startday='.urlencode($date_start_day).
'&date_endyear='.urlencode($date_end_year).
'&date_endmonth='.urlencode($date_end_month).
'&date_endday='.urlencode($date_end_day).
'">' .
img_picto(
'',
'chevron-down',
'class="paddingrightonly"') . $langs->trans(
'VATReportShowByRateDetails') .
'</a>';
422 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
425 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
428 if (!empty($fields[
'ddate_start'])) {
431 if (!empty($fields[
'ddate_end'])) {
436 $ratiopaymentinvoice=1;
438 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
439 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
441 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
442 $ratiopaymentinvoice=($fields[
'payment_amount']/$fields[
'ftotal_ttc']);
448 $temp_ht=$fields[
'totalht']*$ratiopaymentinvoice;
451 $temp_vat=$fields[
'vat']*$ratiopaymentinvoice;
453 $subtot_coll_total_ht += $temp_ht;
454 $subtot_coll_vat += $temp_vat;
455 $x_coll_sum += $temp_vat;
459 if ($invoice_type ==
'customer' && $vat_rate_show == $rate) {
460 if (is_array($x_both[$rate][
'coll'][
'detail'])) {
461 foreach ($x_both[$rate][
'coll'][
'detail'] as $index => $fields) {
477 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
480 if (!empty($fields[
'ddate_start'])) {
483 if (!empty($fields[
'ddate_end'])) {
488 print
'<tr class="oddeven">';
491 print
'<td class="nowrap left">' . $fields[
'link'] .
'</td>';
494 print
'<td class="left">' .
dol_print_date($fields[
'datef'],
'day') .
'</td>';
497 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment' || $conf->global->TAX_MODE_SELL_SERVICE ==
'payment') print
'<td class="left">' .
dol_print_date($fields[
'datep'],
'day') .
'</td>';
498 else print
'<td></td>';
501 print
'<td class="tdmaxoverflow150">';
503 print $fields[
'company_link'];
507 print
'<td class="left">';
508 if ($fields[
'pid']) {
509 $product_static->id = $fields[
'pid'];
510 $product_static->ref = $fields[
'pref'];
511 $product_static->type = $fields[
'dtype'];
512 print $product_static->getNomUrl(1);
518 $text =
img_object($langs->trans(
'Service'),
'service');
520 $text =
img_object($langs->trans(
'Product'),
'product');
522 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
523 if ($reg[1] ==
'DEPOSIT') {
524 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
525 } elseif ($reg[1] ==
'CREDIT_NOTE') {
526 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
528 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
540 print
'<td class="nowrap right">';
541 print
price($fields[
'totalht']);
544 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
551 $ratiopaymentinvoice = 1;
553 print
'<td class="nowrap right">';
555 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
556 $payment_static->id = $fields[
'payment_id'];
557 $payment_static->ref = $fields[
'payment_ref'];
558 print $payment_static->getNomUrl(2,
'',
'', 0).
' ';
560 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
561 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
562 print $langs->trans(
"NA");
564 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
565 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
568 if (isset($fields[
'payment_amount'])) {
569 print
' (' . round($ratiopaymentinvoice * 100, 2) .
'%)';
576 print
'<td class="nowrap right">';
577 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
582 print
'<td class="nowrap right">';
583 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
596 print
'<tr class="liste_total">';
597 print
'<td colspan="4"></td>';
598 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
600 print
'<td class="nowrap right"> </td>';
601 print
'<td class="right"> </td>';
603 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht,
'MT')).
'</span></td>';
604 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat,
'MT')).
'</span></td>';
608 if (count($x_coll) == 0) {
609 print
'<tr class="liste_total">';
610 print
'<td colspan="4"></td>';
611 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
613 print
'<td class="nowrap right"> </td>';
614 print
'<td class="right"> </td>';
616 print
'<td class="right">'.price(
price2num(0,
'MT')).
'</td>';
617 print
'<td class="nowrap right">'.price(
price2num(0,
'MT')).
'</td>';
622 print
'<tr><td colspan="'.($span+2).
'"> </td></tr>';
625 print
'<tr class="liste_titre liste_titre_topborder">';
626 print
'<td class="left">'.$elementsup.
'</td>';
627 print
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
628 if ($conf->global->TAX_MODE_BUY_PRODUCT ==
'payment' || $conf->global->TAX_MODE_BUY_SERVICE ==
'payment') print
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
629 else print
'<td></td>';
630 print
'<td class="left">'.$namesup.
'</td>';
631 print
'<td class="left">'.$productsup.
'</td>';
633 print
'<td class="right">'.$amountsup.
'</td>';
634 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
636 print
'<td class="right">'.$langs->trans(
"AmountHTVATRealPaid").
'</td>';
637 print
'<td class="right">'.$vatsup.
'</td>';
640 foreach (array_keys($x_paye) as $rate) {
641 $subtot_paye_total_ht = 0;
642 $subtot_paye_vat = 0;
644 if (is_array($x_both[$rate][
'paye'][
'detail'])) {
646 print
'<td class="tax_rate" colspan="' . ($span+1) .
'">';
647 print $langs->trans(
'Rate') .
' : ' .
vatrate($rate) .
'%';
648 print
' - <a href="'.DOL_URL_ROOT.
'/compta/tva/quadri_detail.php?invoice_type=supplier';
649 if ($invoice_type !=
'supplier' || !
GETPOSTISSET(
'vat_rate_show') ||
GETPOST(
'vat_rate_show') != $rate) {
650 print
'&vat_rate_show='.urlencode($rate);
652 print
'&date_startyear='.urlencode($date_start_year).
'&date_startmonth='.urlencode($date_start_month).
'&date_startday='.urlencode($date_start_day).
'&date_endyear='.urlencode($date_end_year).
'&date_endmonth='.urlencode($date_end_month).
'&date_endday='.urlencode($date_end_day).
'">' .
img_picto(
'',
'chevron-down',
'class="paddingrightonly"') . $langs->trans(
'VATReportShowByRateDetails') .
'</a>';
656 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
659 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
662 if (!empty($fields[
'ddate_start'])) {
665 if (!empty($fields[
'ddate_end'])) {
670 $ratiopaymentinvoice = 1;
672 if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT ==
'invoice')
673 || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE ==
'invoice')) {
675 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
676 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
682 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
685 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
687 $subtot_paye_total_ht += $temp_ht;
688 $subtot_paye_vat += $temp_vat;
689 $x_paye_sum += $temp_vat;
692 if ($invoice_type ==
'supplier' && $vat_rate_show == $rate) {
693 foreach ($x_both[$rate][
'paye'][
'detail'] as $index => $fields) {
709 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
712 if (!empty($fields[
'ddate_start'])) {
715 if (!empty($fields[
'ddate_end'])) {
720 print
'<tr class="oddeven">';
723 print
'<td class="nowrap left">' . $fields[
'link'] .
'</td>';
726 print
'<td class="left">' .
dol_print_date($fields[
'datef'],
'day') .
'</td>';
729 if ($conf->global->TAX_MODE_BUY_PRODUCT ==
'payment' || $conf->global->TAX_MODE_BUY_SERVICE ==
'payment') {
730 print
'<td class="left">' .
dol_print_date($fields[
'datep'],
'day') .
'</td>';
736 print
'<td class="tdmaxoverflow150">';
738 print $fields[
'company_link'];
742 print
'<td class="left">';
743 if ($fields[
'pid']) {
744 $product_static->id = $fields[
'pid'];
745 $product_static->ref = $fields[
'pref'];
746 $product_static->type = $fields[
'dtype'];
747 print $product_static->getNomUrl(1);
753 $text =
img_object($langs->trans(
'Service'),
'service');
755 $text =
img_object($langs->trans(
'Product'),
'product');
757 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
758 if ($reg[1] ==
'DEPOSIT') {
759 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
760 } elseif ($reg[1] ==
'CREDIT_NOTE') {
761 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
763 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
775 print
'<td class="nowrap right">';
776 print
price($fields[
'totalht']);
779 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
786 $ratiopaymentinvoice = 1;
788 print
'<td class="nowrap right">';
789 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
790 $paymentfourn_static->id = $fields[
'payment_id'];
791 $paymentfourn_static->ref = $fields[
'payment_ref'];
792 print $paymentfourn_static->getNomUrl(2,
'',
'', 0).
' ';
795 if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT ==
'invoice')
796 || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE ==
'invoice')) {
797 print $langs->trans(
"NA");
799 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
800 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
803 if (isset($fields[
'payment_amount'])) {
804 print
' (' . round($ratiopaymentinvoice * 100, 2) .
'%)';
811 print
'<td class="nowrap right">';
812 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
817 print
'<td class="nowrap right">';
818 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
832 print
'<tr class="liste_total">';
833 print
'<td colspan="4"></td>';
834 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
836 print
'<td class="nowrap right"> </td>';
837 print
'<td class="right"> </td>';
839 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht,
'MT')).
'</span></td>';
840 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat,
'MT')).
'</span></td>';
844 if (count($x_paye) == 0) {
845 print
'<tr class="liste_total">';
846 print
'<td colspan="4"></td>';
847 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
849 print
'<td class="nowrap right"> </td>';
850 print
'<td class="right"> </td>';
852 print
'<td class="right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
853 print
'<td class="nowrap right"><span class="amount">'.price(
price2num(0,
'MT')).
'</span></td>';
862 print
'<table class="noborder centpercent">';
863 $diff = $x_coll_sum - $x_paye_sum;
864 print
'<tr class="liste_total">';
865 print
'<td class="liste_total" colspan="'.$span.
'">'.$langs->trans(
"TotalToPay").($q ?
', '.$langs->trans(
"Quadri").
' '.$q :
'').
'</td>';
866 print
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff,
'MT')).
"</b></td>\n";