dolibarr  13.0.2
clients.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
4  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin"));
35 
36 $local = GETPOST('localTaxType', 'int');
37 
38 // Date range
39 $year = GETPOST("year", "int");
40 if (empty($year))
41 {
42  $year_current = strftime("%Y", dol_now());
43  $year_start = $year_current;
44 } else {
45  $year_current = $year;
46  $year_start = $year;
47 }
48 $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
49 $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
50 // Quarter
51 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
52 {
53  $q = GETPOST("q");
54  if (empty($q))
55  {
56  if (GETPOST("month")) { $date_start = dol_get_first_day($year_start, GETPOST("month"), false); $date_end = dol_get_last_day($year_start, GETPOST("month"), false); } else {
57  $date_start = dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
58  if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
59  elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
60  elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
61  }
62  } else {
63  if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
64  if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
65  if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
66  if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
67  }
68 }
69 
70 $min = price2num(GETPOST("min", "alpha"));
71 if (empty($min)) $min = 0;
72 
73 // Define modetax (0 or 1)
74 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
75 $modetax = $conf->global->TAX_MODE;
76 if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
77 if (empty($modetax)) $modetax = 0;
78 
79 // Security check
80 $socid = GETPOST('socid', 'int');
81 if ($user->socid) $socid = $user->socid;
82 $result = restrictedArea($user, 'tax', '', '', 'charges');
83 
84 if (empty($local))
85 {
86  accessforbidden('Parameter localTaxType is missing');
87  exit;
88 }
89 
90 
91 $calc = 0;
92 /*
93  * View
94  */
95 
96 $form = new Form($db);
97 $company_static = new Societe($db);
98 
99 $morequerystring = '';
100 $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
101 foreach ($listofparams as $param)
102 {
103  if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
104 }
105 
106 llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
107 
108 
109 $name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code);
110 
111 $fsearch = '<!-- hidden fields for form -->';
112 $fsearch .= '<input type="hidden" name="token" value="'.newToken().'">';
113 $fsearch .= '<input type="hidden" name="modetax" value="'.$modetax.'">';
114 $fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
115 $fsearch .= $langs->trans("SalesTurnoverMinimum").': ';
116 $fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" size="6">';
117 
118 $calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
119 // Affiche en-tete du rapport
120 if ($calc == 0 || $calc == 1) // Calculate on invoice for goods and services
121 {
122  $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
123  $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
124  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
125  if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
126  $description .= $fsearch;
127  $description .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
128  $builddate = dol_now();
129 
130  $elementcust = $langs->trans("CustomersInvoices");
131  $productcust = $langs->trans("Description");
132  $amountcust = $langs->trans("AmountHT");
133  $elementsup = $langs->trans("SuppliersInvoices");
134  $productsup = $langs->trans("Description");
135  $amountsup = $langs->trans("AmountHT");
136 }
137 if ($calc == 2) // Invoice for goods, payment for services
138 {
139  $calcmode = $langs->trans("CalcModeLT2Debt");
140  $calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
141  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
142  if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
143  $description .= $fsearch;
144  $description .= '<span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
145  $builddate = dol_now();
146 
147  $elementcust = $langs->trans("CustomersInvoices");
148  $productcust = $langs->trans("Description");
149  $amountcust = $langs->trans("AmountHT");
150  $elementsup = $langs->trans("SuppliersInvoices");
151  $productsup = $langs->trans("Description");
152  $amountsup = $langs->trans("AmountHT");
153 }
154 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
155 
156 
157 $vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
158 $vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code);
159 
160 print '<div class="div-table-responsive">';
161 print '<table class="noborder centpercent">';
162 
163 // IRPF that the customer has retained me
164 if ($calc == 0 || $calc == 2)
165 {
166  print '<tr class="liste_titre">';
167  print '<td class="left">'.$langs->trans("Num").'</td>';
168  print '<td class="left">'.$langs->trans("Customer").'</td>';
169  print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</td>';
170  print '<td class="right">'.$langs->trans("TotalHT").'</td>';
171  print '<td class="right">'.$vatcust.'</td>';
172  print "</tr>\n";
173 
174  $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'sell');
175 
176  $action = "tvaclient";
177  $object = &$coll_list;
178  $parameters["mode"] = $modetax;
179  $parameters["start"] = $date_start;
180  $parameters["end"] = $date_end;
181  $parameters["direction"] = 'sell';
182  $parameters["type"] = 'localtax'.$local;
183 
184  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
185  $hookmanager->initHooks(array('externalbalance'));
186  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
187 
188  if (is_array($coll_list))
189  {
190  $total = 0; $totalamount = 0;
191  $i = 1;
192  foreach ($coll_list as $coll)
193  {
194  if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
195  {
196  $intra = str_replace($find, $replace, $coll->tva_intra);
197  if (empty($intra))
198  {
199  if ($coll->assuj == '1')
200  {
201  $intra = $langs->trans('Unknown');
202  } else {
203  $intra = '';
204  }
205  }
206  print '<tr class="oddeven">';
207  print '<td class="nowrap">'.$i."</td>";
208  $company_static->id = $coll->socid;
209  $company_static->name = $coll->name;
210  print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
211  $find = array(' ', '.');
212  $replace = array('', '');
213  print '<td class="nowrap">'.$intra.'</td>';
214  print '<td class="nowrap right">'.price($coll->amount).'</td>';
215  print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
216  $totalamount = $totalamount + $coll->amount;
217  $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
218  print "</tr>\n";
219  $i++;
220  }
221  }
222  $x_coll_sum = $total;
223 
224  print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
225  print '<td class="nowrap right">'.price($totalamount).'</td>';
226  print '<td class="nowrap right">'.price($total).'</td>';
227  print '</tr>';
228  } else {
229  $langs->load("errors");
230  if ($coll_list == -1)
231  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
232  elseif ($coll_list == -2)
233  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
234  else print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
235  }
236 }
237 
238 // IRPF I retained my supplier
239 if ($calc == 0 || $calc == 1) {
240  print '<tr class="liste_titre">';
241  print '<td class="left">'.$langs->trans("Num")."</td>";
242  print '<td class="left">'.$langs->trans("Supplier")."</td>";
243  print '<td>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</td>';
244  print '<td class="right">'.$langs->trans("TotalHT").'</td>';
245  print '<td class="right">'.$vatsup.'</td>';
246  print "</tr>\n";
247 
248  $company_static = new Societe($db);
249 
250  $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy');
251  $parameters["direction"] = 'buy';
252  $parameters["type"] = 'localtax'.$local;
253 
254  $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
255  if (is_array($coll_list))
256  {
257  $total = 0; $totalamount = 0;
258  $i = 1;
259  foreach ($coll_list as $coll)
260  {
261  if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
262  {
263  $intra = str_replace($find, $replace, $coll->tva_intra);
264  if (empty($intra))
265  {
266  if ($coll->assuj == '1')
267  {
268  $intra = $langs->trans('Unknown');
269  } else {
270  $intra = '';
271  }
272  }
273  print '<tr class="oddeven">';
274  print '<td class="nowrap">'.$i."</td>";
275  $company_static->id = $coll->socid;
276  $company_static->name = $coll->name;
277  print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
278  $find = array(' ', '.');
279  $replace = array('', '');
280  print '<td class="nowrap">'.$intra."</td>";
281  print '<td class="nowrap right">'.price($coll->amount).'</td>';
282  print '<td class="nowrap right">'.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'</td>';
283  $totalamount = $totalamount + $coll->amount;
284  $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2);
285  print "</tr>\n";
286  $i++;
287  }
288  }
289  $x_paye_sum = $total;
290 
291  print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("Total").':</td>';
292  print '<td class="nowrap right">'.price($totalamount).'</td>';
293  print '<td class="nowrap right">'.price($total).'</td>';
294  print '</tr>';
295  } else {
296  $langs->load("errors");
297  if ($coll_list == -1)
298  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
299  elseif ($coll_list == -2)
300  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
301  else print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
302  }
303 }
304 
305 if ($calc == 0) {
306  // Total to pay
307  print '<tr><td colspan="5"></td></tr>';
308 
309  $diff = $x_coll_sum - $x_paye_sum;
310  print '<tr class="liste_total">';
311  print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>';
312  print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n";
313  print "</tr>\n";
314 }
315 
316 print '</table>';
317 print '</div>';
318 
319 
320 // End of page
321 llxFooter();
322 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $direction, $m=0, $q=0)
Look for collectable VAT clients in the chosen year (and month)
Definition: tax.lib.php:91
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
Definition: report.lib.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:114
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.