dolibarr  16.0.5
quadri_detail.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2006-2015 Yannick Warnier <ywarnier@beeznest.org>
6  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
9  * Copyright (C) 2021-2022 Open-Dsi <support@open-dsi.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
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';
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
47 
48 $refresh = (GETPOSTISSET('submit') || GETPOSTISSET('vat_rate_show') || GETPOSTISSET('invoice_type')) ? true : false;
49 $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : '';
50 $vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'alphanohtml') : -1;
51 
52 include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php';
53 
54 $min = price2num(GETPOST("min", "alpha"));
55 if (empty($min)) {
56  $min = 0;
57 }
58 
59 // Define modetax (0 or 1)
60 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
61 $modetax = (empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE);
62 if (GETPOSTISSET("modetax")) {
63  $modetax = GETPOSTINT("modetax");
64 }
65 if (empty($modetax)) {
66  $modetax = 0;
67 }
68 
69 $object = new Tva($db);
70 
71 // Security check
72 $socid = GETPOSTINT('socid');
73 if ($user->socid) {
74  $socid = $user->socid;
75 }
76 $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
77 
78 
79 /*
80  * View
81  */
82 
83 $form = new Form($db);
84 $company_static = new Societe($db);
85 $invoice_customer = new Facture($db);
86 $invoice_supplier = new FactureFournisseur($db);
87 $expensereport = new ExpenseReport($db);
88 $product_static = new Product($db);
89 $payment_static = new Paiement($db);
90 $paymentfourn_static = new PaiementFourn($db);
91 $paymentexpensereport_static = new PaymentExpenseReport($db);
92 
93 $morequerystring = '';
94 $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
95 foreach ($listofparams as $param) {
96  if (GETPOST($param) != '') {
97  $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
98  }
99 }
100 
101 $title = $langs->trans("VATReport")." ".dol_print_date($date_start, '', 'tzserver')." -> ".dol_print_date($date_end, '', 'tzserver');
102 llxHeader('', $title, '', '', 0, 0, '', '', $morequerystring);
103 
104 
105 //print load_fiche_titre($langs->trans("VAT"),"");
106 
107 //$fsearch.='<br>';
108 $fsearch = '<!-- hidden fields for form -->';
109 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
110 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
111 //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
112 //$fsearch.=' <input type="text" name="min" value="'.$min.'">';
113 
114 
115 // Show report header
116 $name = $langs->trans("VATReportByRates");
117 $calcmode = '';
118 if ($modetax == 0) {
119  $calcmode = $langs->trans('OptionVATDefault');
120 }
121 if ($modetax == 1) {
122  $calcmode = $langs->trans('OptionVATDebitOption');
123 }
124 if ($modetax == 2) {
125  $calcmode = $langs->trans('OptionPaymentForProductAndServices');
126 }
127 $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
128 // Set period
129 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
130 $period .= ' - ';
131 $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
132 $prevyear = $date_start_year;
133 $prevquarter = $q;
134 if ($prevquarter > 1) {
135  $prevquarter--;
136 } else {
137  $prevquarter = 4;
138  $prevyear--;
139 }
140 $nextyear = $date_start_year;
141 $nextquarter = $q;
142 if ($nextquarter < 4) {
143  $nextquarter++;
144 } else {
145  $nextquarter = 1;
146  $nextyear++;
147 }
148 $description .= $fsearch;
149 $builddate = dol_now();
150 
151 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') {
152  $description .= $langs->trans("RulesVATDueProducts");
153 }
154 if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') {
155  $description .= $langs->trans("RulesVATInProducts");
156 }
157 if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') {
158  $description .= '<br>'.$langs->trans("RulesVATDueServices");
159 }
160 if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') {
161  $description .= '<br>'.$langs->trans("RulesVATInServices");
162 }
163 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
164  $description .= '<br>'.$langs->trans("DepositsAreNotIncluded");
165 }
166 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
167  $description .= $langs->trans("SupplierDepositsAreNotIncluded");
168 }
169 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
170  $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue");
171 }
172 
173 // Customers invoices
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").')';
181 }
182 
183 // Suppliers invoices
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").')';
191 }
192 
193 $optioncss = GETPOST('optioncss', 'alpha');
194 if ($optioncss != "print") {
195  report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
196 }
197 
198 $vatcust = $langs->trans("VATReceived");
199 $vatsup = $langs->trans("VATPaid");
200 $vatexpensereport = $langs->trans("VATPaid");
201 
202 
203 // VAT Received and paid
204 print '<div class="div-table-responsive">';
205 print '<table class="noborder centpercent">';
206 
207 $y = $year_current;
208 $i = 0;
209 
210 $columns = 7;
211 $span = $columns;
212 if ($modetax != 1) {
213  $span += 2;
214 }
215 
216 // Load arrays of datas
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');
219 
220 if (!is_array($x_coll) || !is_array($x_paye)) {
221  $langs->load("errors");
222  if ($x_coll == -1) {
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>';
226  } else {
227  print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
228  }
229 } else {
230  $x_both = array();
231  //now, from these two arrays, get another array with one rate per line
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];
243 
244  //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$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];
257 
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],
272 
273  'company_link'=>$company_static->getNomUrl(1, '', 20),
274 
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)
280  );
281  }
282  }
283  // tva paid
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;
290  }
291  $x_both[$my_paye_rate]['paye']['links'] = '';
292  $x_both[$my_paye_rate]['paye']['detail'] = array();
293 
294  foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
295  // ExpenseReport
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];
300 
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)
318  );
319  } else {
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];
323 
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];
336 
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],
351 
352  'company_link'=>$company_static->getNomUrl(1, '', 20),
353 
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)
359  );
360  }
361  }
362  }
363  //now we have an array (x_both) indexed by rates for coll and paye
364 
365 
366  //print table headers for this quadri - incomes first
367 
368  $x_coll_sum = 0;
369  $x_coll_ht = 0;
370  $x_paye_sum = 0;
371  $x_paye_ht = 0;
372 
373  //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
374 
375  // Customers invoices
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>';
381  } else {
382  print '<td></td>';
383  }
384  print '<td class="left">'.$namecust.'</td>';
385  print '<td class="left">'.$productcust.'</td>';
386  if ($modetax != 1) {
387  print '<td class="right">'.$amountcust.'</td>';
388  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
389  }
390  print '<td class="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
391  print '<td class="right">'.$vatcust.'</td>';
392  print '</tr>';
393 
394  $action = "tvadetail";
395  $parameters["mode"] = $modetax;
396  $parameters["start"] = $date_start;
397  $parameters["end"] = $date_end;
398  $parameters["type"] = 'vat';
399 
400  $object = array(&$x_coll, &$x_paye, &$x_both);
401  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
402  $hookmanager->initHooks(array('externalbalance'));
403  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
404 
405  foreach (array_keys($x_coll) as $rate) {
406  $subtot_coll_total_ht = 0;
407  $subtot_coll_vat = 0;
408 
409  if (is_array($x_both[$rate]['coll']['detail'])) {
410  // VAT Rate
411  print "<tr>";
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 '&amp;vat_rate_show='.urlencode($rate);
417  }
418  print '&amp;date_startyear='.urlencode($date_start_year).'&amp;date_startmonth='.urlencode($date_start_month).'&amp;date_startday='.urlencode($date_start_day).'&amp;date_endyear='.urlencode($date_end_year).'&amp;date_endmonth='.urlencode($date_end_month).'&amp;date_endday='.urlencode($date_end_day).'">' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '</a>';
419  print '</td>';
420  print '</tr>'."\n";
421 
422  foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
423  // Define type
424  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
425  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
426  // Try to enhance type detection using date_start and date_end for free lines where type
427  // was not saved.
428  if (!empty($fields['ddate_start'])) {
429  $type = 1;
430  }
431  if (!empty($fields['ddate_end'])) {
432  $type = 1;
433  }
434 
435  // Payment
436  $ratiopaymentinvoice=1;
437  if ($modetax != 1) {
438  if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
439  || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
440  } else {
441  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
442  $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
443  }
444  }
445  }
446 
447  // Total collected
448  $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
449 
450  // VAT
451  $temp_vat=$fields['vat']*$ratiopaymentinvoice;
452 
453  $subtot_coll_total_ht += $temp_ht;
454  $subtot_coll_vat += $temp_vat;
455  $x_coll_sum += $temp_vat;
456  }
457  }
458 
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) {
462  /*$company_static->id = $fields['company_id'];
463  $company_static->name = $fields['company_name'];
464  $company_static->name_alias = $fields['company_alias'];
465  $company_static->email = $fields['company_email'];
466  $company_static->tva_intra = $fields['tva_intra'];
467  $company_static->client = $fields['company_client'];
468  $company_static->fournisseur = $fields['company_fournisseur'];
469  $company_static->status = $fields['company_status'];
470  $company_static->code_client = $fields['company_client'];
471  $company_static->code_compta_client = $fields['company_customer_code'];
472  $company_static->code_fournisseur = $fields['company_customer_accounting_code'];
473  $company_static->code_compta_fournisseur = $fields['company_supplier_accounting_code'];*/
474 
475  // Define type
476  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
477  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
478  // Try to enhance type detection using date_start and date_end for free lines where type
479  // was not saved.
480  if (!empty($fields['ddate_start'])) {
481  $type = 1;
482  }
483  if (!empty($fields['ddate_end'])) {
484  $type = 1;
485  }
486 
487 
488  print '<tr class="oddeven">';
489 
490  // Ref
491  print '<td class="nowrap left">' . $fields['link'] . '</td>';
492 
493  // Invoice date
494  print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
495 
496  // Payment date
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>';
499 
500  // Company name
501  print '<td class="tdmaxoverflow150">';
502  //print $company_static->getNomUrl(1);
503  print $fields['company_link'];
504  print '</td>';
505 
506  // Description
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']; // We force with the type of line to have type how line is registered
512  print $product_static->getNomUrl(1);
513  if (dol_string_nohtmltag($fields['descr'])) {
514  print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
515  }
516  } else {
517  if ($type) {
518  $text = img_object($langs->trans('Service'), 'service');
519  } else {
520  $text = img_object($langs->trans('Product'), 'product');
521  }
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');
527  } else {
528  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
529  }
530  }
531  print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
532 
533  // Show range
534  print_date_range($fields['ddate_start'], $fields['ddate_end']);
535  }
536  print '</td>';
537 
538  // Total HT
539  if ($modetax != 1) {
540  print '<td class="nowrap right">';
541  print price($fields['totalht']);
542  if (price2num($fields['ftotal_ttc'])) {
543  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
544  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
545  //print ' ('.round($ratiolineinvoice*100,2).'%)';
546  }
547  print '</td>';
548  }
549 
550  // Payment
551  $ratiopaymentinvoice = 1;
552  if ($modetax != 1) {
553  print '<td class="nowrap right">';
554  //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
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).' ';
559  }
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");
563  } else {
564  if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
565  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
566  }
567  print price(price2num($fields['payment_amount'], 'MT'));
568  if (isset($fields['payment_amount'])) {
569  print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
570  }
571  }
572  print '</td>';
573  }
574 
575  // Total collected
576  print '<td class="nowrap right">';
577  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
578  print price(price2num($temp_ht, 'MT'), 1);
579  print '</td>';
580 
581  // VAT
582  print '<td class="nowrap right">';
583  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
584  print price(price2num($temp_vat, 'MT'), 1);
585  //print price($fields['vat']);
586  print '</td>';
587  print '</tr>';
588 
589  //$subtot_coll_total_ht += $temp_ht;
590  //$subtot_coll_vat += $temp_vat;
591  //$x_coll_sum += $temp_vat;
592  }
593  }
594  }
595  // Total customers for this vat rate
596  print '<tr class="liste_total">';
597  print '<td colspan="4"></td>';
598  print '<td class="right">'.$langs->trans("Total").':</td>';
599  if ($modetax != 1) {
600  print '<td class="nowrap right">&nbsp;</td>';
601  print '<td class="right">&nbsp;</td>';
602  }
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>';
605  print '</tr>';
606  }
607 
608  if (count($x_coll) == 0) { // Show a total line if nothing shown
609  print '<tr class="liste_total">';
610  print '<td colspan="4"></td>';
611  print '<td class="right">'.$langs->trans("Total").':</td>';
612  if ($modetax != 1) {
613  print '<td class="nowrap right">&nbsp;</td>';
614  print '<td class="right">&nbsp;</td>';
615  }
616  print '<td class="right">'.price(price2num(0, 'MT')).'</td>';
617  print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>';
618  print '</tr>';
619  }
620 
621  // Blank line
622  print '<tr><td colspan="'.($span+2).'">&nbsp;</td></tr>';
623 
624  // Print table headers for this quadri - expenses
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>';
632  if ($modetax != 1) {
633  print '<td class="right">'.$amountsup.'</td>';
634  print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
635  }
636  print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
637  print '<td class="right">'.$vatsup.'</td>';
638  print '</tr>'."\n";
639 
640  foreach (array_keys($x_paye) as $rate) {
641  $subtot_paye_total_ht = 0;
642  $subtot_paye_vat = 0;
643 
644  if (is_array($x_both[$rate]['paye']['detail'])) {
645  print "<tr>";
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 '&amp;vat_rate_show='.urlencode($rate);
651  }
652  print '&amp;date_startyear='.urlencode($date_start_year).'&amp;date_startmonth='.urlencode($date_start_month).'&amp;date_startday='.urlencode($date_start_day).'&amp;date_endyear='.urlencode($date_end_year).'&amp;date_endmonth='.urlencode($date_end_month).'&amp;date_endday='.urlencode($date_end_day).'">' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . '</a>';
653  print '</td>';
654  print '</tr>'."\n";
655 
656  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
657  // Define type
658  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
659  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
660  // Try to enhance type detection using date_start and date_end for free lines where type
661  // was not saved.
662  if (!empty($fields['ddate_start'])) {
663  $type = 1;
664  }
665  if (!empty($fields['ddate_end'])) {
666  $type = 1;
667  }
668 
669  // Payment
670  $ratiopaymentinvoice = 1;
671  if ($modetax != 1) {
672  if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
673  || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) {
674  } else {
675  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
676  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
677  }
678  }
679  }
680 
681  // VAT paid
682  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
683 
684  // VAT
685  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
686 
687  $subtot_paye_total_ht += $temp_ht;
688  $subtot_paye_vat += $temp_vat;
689  $x_paye_sum += $temp_vat;
690  }
691 
692  if ($invoice_type == 'supplier' && $vat_rate_show == $rate) {
693  foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
694  /*$company_static->id = $fields['company_id'];
695  $company_static->name = $fields['company_name'];
696  $company_static->name_alias = $fields['company_alias'];
697  $company_static->email = $fields['company_email'];
698  $company_static->tva_intra = $fields['tva_intra'];
699  $company_static->client = $fields['company_client'];
700  $company_static->fournisseur = $fields['company_fournisseur'];
701  $company_static->status = $fields['company_status'];
702  $company_static->code_client = $fields['company_client'];
703  $company_static->code_compta_client = $fields['company_customer_code'];
704  $company_static->code_fournisseur = $fields['company_customer_accounting_code'];
705  $company_static->code_compta_fournisseur = $fields['company_supplier_accounting_code'];*/
706 
707  // Define type
708  // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
709  $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
710  // Try to enhance type detection using date_start and date_end for free lines where type
711  // was not saved.
712  if (!empty($fields['ddate_start'])) {
713  $type = 1;
714  }
715  if (!empty($fields['ddate_end'])) {
716  $type = 1;
717  }
718 
719 
720  print '<tr class="oddeven">';
721 
722  // Ref
723  print '<td class="nowrap left">' . $fields['link'] . '</td>';
724 
725  // Invoice date
726  print '<td class="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
727 
728  // Payment date
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>';
731  } else {
732  print '<td></td>';
733  }
734 
735  // Company name
736  print '<td class="tdmaxoverflow150">';
737  //print $company_static->getNomUrl(1);
738  print $fields['company_link'];
739  print '</td>';
740 
741  // Description
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']; // We force with the type of line to have type how line is registered
747  print $product_static->getNomUrl(1);
748  if (dol_string_nohtmltag($fields['descr'])) {
749  print ' - ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
750  }
751  } else {
752  if ($type) {
753  $text = img_object($langs->trans('Service'), 'service');
754  } else {
755  $text = img_object($langs->trans('Product'), 'product');
756  }
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');
762  } else {
763  $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
764  }
765  }
766  print $text . ' ' . dol_trunc(dol_string_nohtmltag($fields['descr']), 24);
767 
768  // Show range
769  print_date_range($fields['ddate_start'], $fields['ddate_end']);
770  }
771  print '</td>';
772 
773  // Total HT
774  if ($modetax != 1) {
775  print '<td class="nowrap right">';
776  print price($fields['totalht']);
777  if (price2num($fields['ftotal_ttc'])) {
778  //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
779  $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
780  //print ' ('.round($ratiolineinvoice*100,2).'%)';
781  }
782  print '</td>';
783  }
784 
785  // Payment
786  $ratiopaymentinvoice = 1;
787  if ($modetax != 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).' ';
793  }
794 
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");
798  } else {
799  if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
800  $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
801  }
802  print price(price2num($fields['payment_amount'], 'MT'));
803  if (isset($fields['payment_amount'])) {
804  print ' (' . round($ratiopaymentinvoice * 100, 2) . '%)';
805  }
806  }
807  print '</td>';
808  }
809 
810  // VAT paid
811  print '<td class="nowrap right">';
812  $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
813  print price(price2num($temp_ht, 'MT'), 1);
814  print '</td>';
815 
816  // VAT
817  print '<td class="nowrap right">';
818  $temp_vat = $fields['vat'] * $ratiopaymentinvoice;
819  print price(price2num($temp_vat, 'MT'), 1);
820  //print price($fields['vat']);
821  print '</td>';
822  print '</tr>';
823 
824  //$subtot_paye_total_ht += $temp_ht;
825  //$subtot_paye_vat += $temp_vat;
826  //$x_paye_sum += $temp_vat;
827  }
828  }
829  }
830 
831  // Total suppliers for this vat rate
832  print '<tr class="liste_total">';
833  print '<td colspan="4"></td>';
834  print '<td class="right">'.$langs->trans("Total").':</td>';
835  if ($modetax != 1) {
836  print '<td class="nowrap right">&nbsp;</td>';
837  print '<td class="right">&nbsp;</td>';
838  }
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>';
841  print '</tr>';
842  }
843 
844  if (count($x_paye) == 0) { // Show a total line if nothing shown
845  print '<tr class="liste_total">';
846  print '<td colspan="4"></td>';
847  print '<td class="right">'.$langs->trans("Total").':</td>';
848  if ($modetax != 1) {
849  print '<td class="nowrap right">&nbsp;</td>';
850  print '<td class="right">&nbsp;</td>';
851  }
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>';
854  print '</tr>';
855  }
856 
857  print '</table>';
858  print '</div>';
859 
860  // Total to pay
861  print '<br><br>';
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";
867  print "</tr>\n";
868 
869  $i++;
870 }
871 print '</table>';
872 
873 llxFooter();
874 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
restrictedArea
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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
tax_by_rate
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...
Definition: tax.lib.php:699
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
GETPOSTINT
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:795
PaymentExpenseReport
Class to manage payments of expense report.
Definition: paymentexpensereport.class.php:31
print_date_range
print_date_range($date_start, $date_end, $format='', $outputlangs='')
Format output for start and end date.
Definition: functions.lib.php:8016
PaiementFourn
Class to manage payments for supplier invoices.
Definition: paiementfourn.class.php:37
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
price
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.
Definition: functions.lib.php:5541
report_header
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5492
Tva
Put here description of your class.
Definition: tva.class.php:35