29 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
44 $langs->loadLangs(array(
"other",
"compta",
"banks",
"bills",
"companies",
"product",
"trips",
"admin"));
46 include DOL_DOCUMENT_ROOT.
'/compta/tva/initdatesforvat.inc.php';
55 $modetax = (empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE);
59 if (empty($modetax)) {
66 $socid = $user->socid;
77 $company_static =
new Societe($db);
78 $invoice_customer =
new Facture($db);
81 $product_static =
new Product($db);
85 $user_static =
new User($db);
87 $morequerystring =
'';
88 $listofparams = array(
'date_startmonth',
'date_startyear',
'date_startday',
'date_endmonth',
'date_endyear',
'date_endday');
89 foreach ($listofparams as $param) {
91 $morequerystring .= ($morequerystring ?
'&' :
'').$param.
'='.
GETPOST($param);
95 $special_report =
false;
96 if (isset($_REQUEST[
'extra_report']) && $_REQUEST[
'extra_report'] == 1) {
97 $special_report =
true;
100 llxHeader(
'', $langs->trans(
"VATReport"),
'',
'', 0, 0,
'',
'', $morequerystring);
102 $fsearch =
'<!-- hidden fields for form -->';
103 $fsearch .=
'<input type="hidden" name="token" value="'.newToken().
'">';
104 $fsearch .=
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
105 $fsearch .= $langs->trans(
"SalesTurnoverMinimum").
': ';
106 $fsearch .=
'<input type="text" name="min" id="min" value="'.$min.
'" size="6">';
109 $name = $langs->trans(
"VATReportByThirdParties");
112 $calcmode = $langs->trans(
'OptionVATDefault');
115 $calcmode = $langs->trans(
'OptionVATDebitOption');
118 $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
120 $calcmode .=
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
122 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
123 $prevyear = $date_start_year;
125 if ($prevquarter > 1) {
131 $nextyear = $date_start_year;
133 if ($nextquarter < 4) {
141 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice') {
142 $description .= $langs->trans(
"RulesVATDueProducts");
144 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment') {
145 $description .= $langs->trans(
"RulesVATInProducts");
147 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'invoice') {
148 $description .=
'<br>'.$langs->trans(
"RulesVATDueServices");
150 if ($conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
151 $description .=
'<br>'.$langs->trans(
"RulesVATInServices");
153 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
154 $description .=
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
156 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
157 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
159 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
160 $description .=
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
164 $description .= ($description ?
'<br>' :
'').$fsearch;
165 if (!empty($conf->global->TAX_REPORT_EXTRA_REPORT)) {
166 $description .=
'<br>';
167 $description .=
'<input type="radio" name="extra_report" value="0" '.($special_report ?
'' :
'checked="checked"').
'> ';
168 $description .= $langs->trans(
'SimpleReport');
169 $description .=
'</input>';
170 $description .=
'<br>';
171 $description .=
'<input type="radio" name="extra_report" value="1" '.($special_report ?
'checked="checked"' :
'').
'> ';
172 $description .= $langs->trans(
'AddExtraReport');
173 $description .=
'</input>';
174 $description .=
'<br>';
177 $elementcust = $langs->trans(
"CustomersInvoices");
178 $productcust = $langs->trans(
"Description");
179 $namerate = $langs->trans(
"VATRate");
180 $amountcust = $langs->trans(
"AmountHT");
181 if ($mysoc->tva_assuj) {
182 $vatcust .=
' ('.$langs->trans(
"StatusToPay").
')';
184 $elementsup = $langs->trans(
"SuppliersInvoices");
185 $productsup = $langs->trans(
"Description");
186 $amountsup = $langs->trans(
"AmountHT");
187 if ($mysoc->tva_assuj) {
188 $vatsup .=
' ('.$langs->trans(
"ToGetBack").
')';
190 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
192 $vatcust = $langs->trans(
"VATReceived");
193 $vatsup = $langs->trans(
"VATPaid");
197 print
'<div class="div-table-responsive">';
198 print
"<table class=\"noborder\" width=\"100%\">";
210 $x_coll =
tax_by_thirdparty(
'vat', $db, 0, $date_start, $date_end, $modetax,
'sell');
211 $x_paye =
tax_by_thirdparty(
'vat', $db, 0, $date_start, $date_end, $modetax,
'buy');
213 if (!is_array($x_coll) || !is_array($x_paye)) {
214 $langs->load(
"errors");
216 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
217 } elseif ($x_coll == -2) {
218 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
220 print
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
225 foreach (array_keys($x_coll) as $my_coll_thirdpartyid) {
226 $x_both[$my_coll_thirdpartyid][
'coll'][
'totalht'] = $x_coll[$my_coll_thirdpartyid][
'totalht'];
227 $x_both[$my_coll_thirdpartyid][
'coll'][
'vat'] = $x_coll[$my_coll_thirdpartyid][
'vat'];
228 $x_both[$my_coll_thirdpartyid][
'paye'][
'totalht'] = 0;
229 $x_both[$my_coll_thirdpartyid][
'paye'][
'vat'] = 0;
230 $x_both[$my_coll_thirdpartyid][
'coll'][
'links'] =
'';
231 $x_both[$my_coll_thirdpartyid][
'coll'][
'detail'] = array();
232 foreach ($x_coll[$my_coll_thirdpartyid][
'facid'] as $id => $dummy) {
233 $invoice_customer->id = $x_coll[$my_coll_thirdpartyid][
'facid'][$id];
234 $invoice_customer->ref = $x_coll[$my_coll_thirdpartyid][
'facnum'][$id];
235 $invoice_customer->type = $x_coll[$my_coll_thirdpartyid][
'type'][$id];
238 $company_static->id = $x_coll[$my_coll_thirdpartyid][
'company_id'][$id];
239 $company_static->name = $x_coll[$my_coll_thirdpartyid][
'company_name'][$id];
240 $company_static->name_alias = $x_coll[$my_coll_thirdpartyid][
'company_alias'][$id];
241 $company_static->email = $x_coll[$my_coll_thirdpartyid][
'company_email'][$id];
242 $company_static->tva_intra = $x_coll[$my_coll_thirdpartyid][
'tva_intra'][$id];
243 $company_static->client = $x_coll[$my_coll_thirdpartyid][
'company_client'][$id];
244 $company_static->fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_fournisseur'][$id];
245 $company_static->status = $x_coll[$my_coll_thirdpartyid][
'company_status'][$id];
246 $company_static->code_client = $x_coll[$my_coll_thirdpartyid][
'company_customer_code'][$id];
247 $company_static->code_compta_client = $x_coll[$my_coll_thirdpartyid][
'company_customer_accounting_code'][$id];
248 $company_static->code_fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_supplier_code'][$id];
249 $company_static->code_compta_fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_supplier_accounting_code'][$id];
251 $x_both[$my_coll_thirdpartyid][
'coll'][
'detail'][] = array(
252 'id' =>$x_coll[$my_coll_thirdpartyid][
'facid'][$id],
253 'descr' =>$x_coll[$my_coll_thirdpartyid][
'descr'][$id],
255 'pid' =>$x_coll[$my_coll_thirdpartyid][
'pid'][$id],
256 'pref' =>$x_coll[$my_coll_thirdpartyid][
'pref'][$id],
257 'ptype' =>$x_coll[$my_coll_thirdpartyid][
'ptype'][$id],
258 'pstatus' =>$x_paye[$my_coll_thirdpartyid][
'pstatus'][$id],
259 'pstatusbuy'=>$x_paye[$my_coll_thirdpartyid][
'pstatusbuy'][$id],
261 'payment_id'=>$x_coll[$my_coll_thirdpartyid][
'payment_id'][$id],
262 'payment_ref'=>$x_coll[$my_coll_thirdpartyid][
'payment_ref'][$id],
263 'payment_amount'=>$x_coll[$my_coll_thirdpartyid][
'payment_amount'][$id],
264 'ftotal_ttc'=>$x_coll[$my_coll_thirdpartyid][
'ftotal_ttc'][$id],
265 'dtotal_ttc'=>$x_coll[$my_coll_thirdpartyid][
'dtotal_ttc'][$id],
266 'dtype' =>$x_coll[$my_coll_thirdpartyid][
'dtype'][$id],
267 'drate' =>$x_coll[$my_coll_thirdpartyid][
'drate'][$id],
268 'datef' =>$x_coll[$my_coll_thirdpartyid][
'datef'][$id],
269 'datep' =>$x_coll[$my_coll_thirdpartyid][
'datep'][$id],
271 'company_link'=>$company_static->getNomUrl(1,
'', 20),
273 'ddate_start'=>$x_coll[$my_coll_thirdpartyid][
'ddate_start'][$id],
274 'ddate_end' =>$x_coll[$my_coll_thirdpartyid][
'ddate_end'][$id],
275 'totalht' =>$x_coll[$my_coll_thirdpartyid][
'totalht_list'][$id],
276 'vat' =>$x_coll[$my_coll_thirdpartyid][
'vat_list'][$id],
277 'link' =>$invoice_customer->getNomUrl(1,
'', 12)
282 foreach (array_keys($x_paye) as $my_paye_thirdpartyid) {
283 $x_both[$my_paye_thirdpartyid][
'paye'][
'totalht'] = $x_paye[$my_paye_thirdpartyid][
'totalht'];
284 $x_both[$my_paye_thirdpartyid][
'paye'][
'vat'] = $x_paye[$my_paye_thirdpartyid][
'vat'];
285 if (!isset($x_both[$my_paye_thirdpartyid][
'coll'][
'totalht'])) {
286 $x_both[$my_paye_thirdpartyid][
'coll'][
'totalht'] = 0;
287 $x_both[$my_paye_thirdpartyid][
'coll'][
'vat'] = 0;
289 $x_both[$my_paye_thirdpartyid][
'paye'][
'links'] =
'';
290 $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'] = array();
292 foreach ($x_paye[$my_paye_thirdpartyid][
'facid'] as $id => $dummy) {
294 if ($x_paye[$my_paye_thirdpartyid][
'ptype'][$id] ==
'ExpenseReportPayment') {
295 $expensereport->id = $x_paye[$my_paye_thirdpartyid][
'facid'][$id];
296 $expensereport->ref = $x_paye[$my_paye_thirdpartyid][
'facnum'][$id];
297 $expensereport->type = $x_paye[$my_paye_thirdpartyid][
'type'][$id];
299 $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'][] = array(
300 'id' =>$x_paye[$my_paye_thirdpartyid][
'facid'][$id],
301 'descr' =>$x_paye[$my_paye_thirdpartyid][
'descr'][$id],
303 'pid' =>$x_paye[$my_paye_thirdpartyid][
'pid'][$id],
304 'pref' =>$x_paye[$my_paye_thirdpartyid][
'pref'][$id],
305 'ptype' =>$x_paye[$my_paye_thirdpartyid][
'ptype'][$id],
306 'pstatus' =>$x_paye[$my_paye_thirdpartyid][
'pstatus'][$id],
307 'pstatusbuy' =>$x_paye[$my_paye_thirdpartyid][
'pstatusbuy'][$id],
309 'payment_id' =>$x_paye[$my_paye_thirdpartyid][
'payment_id'][$id],
310 'payment_ref' =>$x_paye[$my_paye_thirdpartyid][
'payment_ref'][$id],
311 'payment_amount' =>$x_paye[$my_paye_thirdpartyid][
'payment_amount'][$id],
312 'ftotal_ttc' =>
price2num($x_paye[$my_paye_thirdpartyid][
'ftotal_ttc'][$id]),
313 'dtotal_ttc' =>
price2num($x_paye[$my_paye_thirdpartyid][
'dtotal_ttc'][$id]),
314 'dtype' =>$x_paye[$my_paye_thirdpartyid][
'dtype'][$id],
315 'drate' =>$x_paye[$my_coll_thirdpartyid][
'drate'][$id],
316 'ddate_start' =>$x_paye[$my_paye_thirdpartyid][
'ddate_start'][$id],
317 'ddate_end' =>$x_paye[$my_paye_thirdpartyid][
'ddate_end'][$id],
318 'totalht' =>
price2num($x_paye[$my_paye_thirdpartyid][
'totalht_list'][$id]),
319 'vat' =>$x_paye[$my_paye_thirdpartyid][
'vat_list'][$id],
320 'link' =>$expensereport->getNomUrl(1)
323 $invoice_supplier->id = $x_paye[$my_paye_thirdpartyid][
'facid'][$id];
324 $invoice_supplier->ref = $x_paye[$my_paye_thirdpartyid][
'facnum'][$id];
325 $invoice_supplier->type = $x_paye[$my_paye_thirdpartyid][
'type'][$id];
328 $company_static->id = $x_paye[$my_paye_thirdpartyid][
'company_id'][$id];
329 $company_static->name = $x_paye[$my_paye_thirdpartyid][
'company_name'][$id];
330 $company_static->name_alias = $x_paye[$my_paye_thirdpartyid][
'company_alias'][$id];
331 $company_static->email = $x_paye[$my_paye_thirdpartyid][
'company_email'][$id];
332 $company_static->tva_intra = $x_paye[$my_paye_thirdpartyid][
'tva_intra'][$id];
333 $company_static->client = $x_paye[$my_paye_thirdpartyid][
'company_client'][$id];
334 $company_static->fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_fournisseur'][$id];
335 $company_static->status = $x_paye[$my_paye_thirdpartyid][
'company_status'][$id];
336 $company_static->code_client = $x_paye[$my_paye_thirdpartyid][
'company_customer_code'][$id];
337 $company_static->code_compta_client = $x_paye[$my_paye_thirdpartyid][
'company_customer_accounting_code'][$id];
338 $company_static->code_fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_supplier_code'][$id];
339 $company_static->code_compta_fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_supplier_accounting_code'][$id];
341 $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'][] = array(
342 'id' =>$x_paye[$my_paye_thirdpartyid][
'facid'][$id],
343 'descr' =>$x_paye[$my_paye_thirdpartyid][
'descr'][$id],
345 'pid' =>$x_paye[$my_paye_thirdpartyid][
'pid'][$id],
346 'pref' =>$x_paye[$my_paye_thirdpartyid][
'pref'][$id],
347 'ptype' =>$x_paye[$my_paye_thirdpartyid][
'ptype'][$id],
348 'pstatus' =>$x_paye[$my_paye_thirdpartyid][
'pstatus'][$id],
349 'pstatusbuy'=>$x_paye[$my_paye_thirdpartyid][
'pstatusbuy'][$id],
351 'payment_id'=>$x_paye[$my_paye_thirdpartyid][
'payment_id'][$id],
352 'payment_ref'=>$x_paye[$my_paye_thirdpartyid][
'payment_ref'][$id],
353 'payment_amount'=>$x_paye[$my_paye_thirdpartyid][
'payment_amount'][$id],
354 'ftotal_ttc'=>
price2num($x_paye[$my_paye_thirdpartyid][
'ftotal_ttc'][$id]),
355 'dtotal_ttc'=>
price2num($x_paye[$my_paye_thirdpartyid][
'dtotal_ttc'][$id]),
356 'dtype' =>$x_paye[$my_paye_thirdpartyid][
'dtype'][$id],
357 'drate' =>$x_paye[$my_coll_thirdpartyid][
'drate'][$id],
358 'datef' =>$x_paye[$my_paye_thirdpartyid][
'datef'][$id],
359 'datep' =>$x_paye[$my_paye_thirdpartyid][
'datep'][$id],
361 'company_link'=>$company_static->getNomUrl(1,
'', 20),
363 'ddate_start'=>$x_paye[$my_paye_thirdpartyid][
'ddate_start'][$id],
364 'ddate_end' =>$x_paye[$my_paye_thirdpartyid][
'ddate_end'][$id],
365 'totalht' =>
price2num($x_paye[$my_paye_thirdpartyid][
'totalht_list'][$id]),
366 'vat' =>$x_paye[$my_paye_thirdpartyid][
'vat_list'][$id],
367 'link' =>$invoice_supplier->getNomUrl(1,
'', 12)
385 print
'<tr class="liste_titre">';
386 print
'<td class="left">'.$elementcust.
'</td>';
387 print
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
388 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment' || $conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
389 print
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
393 print
'<td class="right">'.$namerate.
'</td>';
394 print
'<td class="left">'.$productcust.
'</td>';
396 print
'<td class="right">'.$amountcust.
'</td>';
397 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
399 print
'<td class="right">'.$langs->trans(
"AmountHTVATRealReceived").
'</td>';
400 print
'<td class="right">'.$vatcust.
'</td>';
403 $action =
"tvadetail";
404 $parameters[
"mode"] = $modetax;
405 $parameters[
"start"] = $date_start;
406 $parameters[
"end"] = $date_end;
407 $parameters[
"type"] =
'vat';
409 $object = array(&$x_coll, &$x_paye, &$x_both);
411 $hookmanager->initHooks(array(
'externalbalance'));
412 $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action);
414 foreach (array_keys($x_coll) as $thirdparty_id) {
415 $subtot_coll_total_ht = 0;
416 $subtot_coll_vat = 0;
418 if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id][
'coll'][
'totalht'] > $min)) {
419 if (is_array($x_both[$thirdparty_id][
'coll'][
'detail'])) {
422 print
'<td class="tax_rate">';
423 if (is_numeric($thirdparty_id)) {
424 $company_static->fetch($thirdparty_id);
425 print $langs->trans(
"ThirdParty").
': '.$company_static->getNomUrl(1);
427 $tmpid = preg_replace(
'/userid_/',
'', $thirdparty_id);
428 $user_static->fetch($tmpid);
429 print $langs->trans(
"User").
': '.$user_static->getNomUrl(1);
431 print
'</td><td colspan="'.($span + 1).
'"></td>';
434 foreach ($x_both[$thirdparty_id][
'coll'][
'detail'] as $index => $fields) {
437 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
440 if (!empty($fields[
'ddate_start'])) {
443 if (!empty($fields[
'ddate_end'])) {
447 print
'<tr class="oddeven">';
450 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
453 print
'<td class="left">'.dol_print_date($fields[
'datef'],
'day').
'</td>';
456 if ($conf->global->TAX_MODE_SELL_PRODUCT ==
'payment' || $conf->global->TAX_MODE_SELL_SERVICE ==
'payment') {
457 print
'<td class="left">'.dol_print_date($fields[
'datep'],
'day').
'</td>';
463 print
'<td class="right">'.$fields[
'drate'].
'</td>';
466 print
'<td class="left">';
467 if ($fields[
'pid']) {
468 $product_static->id = $fields[
'pid'];
469 $product_static->ref = $fields[
'pref'];
470 $product_static->type = $fields[
'dtype'];
471 $product_static->status = $fields[
'pstatus'];
472 $product_static->status_buy = $fields[
'pstatusbuy'];
474 print $product_static->getNomUrl(1);
480 $text =
img_object($langs->trans(
'Service'),
'service');
482 $text =
img_object($langs->trans(
'Product'),
'product');
484 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
485 if ($reg[1] ==
'DEPOSIT') {
486 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
487 } elseif ($reg[1] ==
'CREDIT_NOTE') {
488 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
490 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
502 print
'<td class="nowrap right"><span class="amount">';
503 print
price($fields[
'totalht']);
506 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
509 print
'</span></td>';
513 $ratiopaymentinvoice = 1;
515 print
'<td class="nowrap right">';
517 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
518 $payment_static->id = $fields[
'payment_id'];
519 $payment_static->ref = $fields[
'payment_ref'];
520 print $payment_static->getNomUrl(2,
'',
'', 0).
' ';
522 if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT ==
'invoice')
523 || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE ==
'invoice')) {
524 print $langs->trans(
"NA");
526 if (isset($fields[
'payment_amount']) &&
price2num($fields[
'ftotal_ttc'])) {
527 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
529 print
'<span class="amount">'.price(
price2num($fields[
'payment_amount'],
'MT')).
'</span>';
530 if (isset($fields[
'payment_amount'])) {
531 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
538 print
'<td class="nowrap right"><span class="amount">';
539 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
541 print
'</span></td>';
544 print
'<td class="nowrap right"><span class="amount">';
545 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
548 print
'</span></td>';
551 $subtot_coll_total_ht += $temp_ht;
552 $subtot_coll_vat += $temp_vat;
553 $x_coll_sum += $temp_vat;
558 print
'<tr class="liste_total">';
559 print
'<td colspan="4"></td>';
560 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
562 print
'<td class="nowrap right"> </td>';
563 print
'<td class="right"> </td>';
565 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht,
'MT')).
'</span></td>';
566 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat,
'MT')).
'</span></td>';
571 if (count($x_coll) == 0) {
572 print
'<tr class="liste_total">';
573 print
'<td colspan="4"></td>';
574 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
576 print
'<td class="nowrap right"> </td>';
577 print
'<td class="right"> </td>';
579 print
'<td class="right">'.price(
price2num(0,
'MT')).
'</td>';
580 print
'<td class="nowrap right">'.price(
price2num(0,
'MT')).
'</td>';
585 print
'<tr><td colspan="'.($span + 1).
'"> </td></tr>';
588 print
'<tr class="liste_titre liste_titre_topborder">';
589 print
'<td class="left">'.$elementsup.
'</td>';
590 print
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
591 if ($conf->global->TAX_MODE_BUY_PRODUCT ==
'payment' || $conf->global->TAX_MODE_BUY_SERVICE ==
'payment') {
592 print
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
596 print
'<td class="left">'.$namesup.
'</td>';
597 print
'<td class="left">'.$productsup.
'</td>';
599 print
'<td class="right">'.$amountsup.
'</td>';
600 print
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
602 print
'<td class="right">'.$langs->trans(
"AmountHTVATRealPaid").
'</td>';
603 print
'<td class="right">'.$vatsup.
'</td>';
606 foreach (array_keys($x_paye) as $thirdparty_id) {
607 $subtot_paye_total_ht = 0;
608 $subtot_paye_vat = 0;
610 if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id][
'paye'][
'totalht'] > $min)) {
611 if (is_array($x_both[$thirdparty_id][
'paye'][
'detail'])) {
613 print
'<td class="tax_rate">';
614 if (is_numeric($thirdparty_id)) {
615 $company_static->fetch($thirdparty_id);
616 print $langs->trans(
"ThirdParty").
': '.$company_static->getNomUrl(1);
618 $tmpid = preg_replace(
'/userid_/',
'', $thirdparty_id);
619 $user_static->fetch($tmpid);
620 print $langs->trans(
"User").
': '.$user_static->getNomUrl(1);
622 print
'<td colspan="'.($span + 1).
'"></td>';
625 foreach ($x_both[$thirdparty_id][
'paye'][
'detail'] as $index => $fields) {
628 $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
631 if (!empty($fields[
'ddate_start'])) {
634 if (!empty($fields[
'ddate_end'])) {
639 print
'<tr class="oddeven">';
642 print
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
645 print
'<td class="left">'.dol_print_date($fields[
'datef'],
'day').
'</td>';
648 if ($conf->global->TAX_MODE_BUY_PRODUCT ==
'payment' || $conf->global->TAX_MODE_BUY_SERVICE ==
'payment') {
649 print
'<td class="left">'.dol_print_date($fields[
'datep'],
'day').
'</td>';
655 print
'<td class="tdmaxoverflow150">';
656 print $fields[
'company_link'];
660 print
'<td class="left">';
661 if ($fields[
'pid']) {
662 $product_static->id = $fields[
'pid'];
663 $product_static->ref = $fields[
'pref'];
664 $product_static->type = $fields[
'dtype'];
665 print $product_static->getNomUrl(1);
671 $text =
img_object($langs->trans(
'Service'),
'service');
673 $text =
img_object($langs->trans(
'Product'),
'product');
675 if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
676 if ($reg[1] ==
'DEPOSIT') {
677 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
678 } elseif ($reg[1] ==
'CREDIT_NOTE') {
679 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
681 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
693 print
'<td class="nowrap right"><span class="amount">';
694 print
price($fields[
'totalht']);
697 $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
700 print
'</span></td>';
704 $ratiopaymentinvoice = 1;
706 print
'<td class="nowrap right">';
707 if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
708 $paymentfourn_static->id = $fields[
'payment_id'];
709 $paymentfourn_static->ref = $fields[
'payment_ref'];
710 print $paymentfourn_static->getNomUrl(2,
'',
'', 0);
713 if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT ==
'invoice')
714 || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE ==
'invoice')) {
715 print $langs->trans(
"NA");
717 if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
718 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
720 print
'<span class="amount">'.price(
price2num($fields[
'payment_amount'],
'MT')).
'</span>';
721 if (isset($fields[
'payment_amount'])) {
722 print
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
729 print
'<td class="nowrap right"><span class="amount">';
730 $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
732 print
'</span></td>';
735 print
'<td class="nowrap right"><span class="amount">';
736 $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
739 print
'</span></td>';
742 $subtot_paye_total_ht += $temp_ht;
743 $subtot_paye_vat += $temp_vat;
744 $x_paye_sum += $temp_vat;
748 print
'<tr class="liste_total">';
749 print
'<td colspan="4"></td>';
750 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
752 print
'<td class="nowrap right"> </td>';
753 print
'<td class="right"> </td>';
755 print
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht,
'MT')).
'</span></td>';
756 print
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat,
'MT')).
'</span></td>';
761 if (count($x_paye) == 0) {
762 print
'<tr class="liste_total">';
763 print
'<td colspan="4"></td>';
764 print
'<td class="right">'.$langs->trans(
"Total").
':</td>';
766 print
'<td class="nowrap right"> </td>';
767 print
'<td class="right"> </td>';
769 print
'<td class="right">'.price(
price2num(0,
'MT')).
'</td>';
770 print
'<td class="nowrap right">'.price(
price2num(0,
'MT')).
'</td>';
775 print
'<tr><td colspan="'.($span + 2).
'"></td></tr>';
777 $diff = $x_coll_sum - $x_paye_sum;
778 print
'<tr class="liste_total">';
779 print
'<td class="liste_total" colspan="'.($span + 1).
'">'.$langs->trans(
"TotalToPay").($q ?
', '.$langs->trans(
"Quadri").
' '.$q :
'').
'</td>';
780 print
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff,
'MT')).
"</b></td>\n";