dolibarr  9.0.0
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 <http://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); }
57  else
58  {
59  $date_start=dol_get_first_day($year_start,empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START,false);
60  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;
61  else if ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1;
62  else if ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end=dol_time_plus_duree($date_start, 1, 'm') - 1;
63  }
64  }
65  else
66  {
67  if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
68  if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
69  if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
70  if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
71  }
72 }
73 
74 $min = price2num(GETPOST("min","alpha"));
75 if (empty($min)) $min = 0;
76 
77 // Define modetax (0 or 1)
78 // 0=normal, 1=option vat for services is on debit, 2=option on payments for products
79 $modetax = $conf->global->TAX_MODE;
80 if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax",'int');
81 if (empty($modetax)) $modetax=0;
82 
83 // Security check
84 $socid = GETPOST('socid','int');
85 if ($user->societe_id) $socid=$user->societe_id;
86 $result = restrictedArea($user, 'tax', '', '', 'charges');
87 
88 
89 
90 /*
91  * View
92  */
93 
94 $form=new Form($db);
95 $company_static=new Societe($db);
96 
97 $morequerystring='';
98 $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
99 foreach($listofparams as $param)
100 {
101  if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
102 }
103 
104 llxHeader('','','','',0,0,'','',$morequerystring);
105 
106 
107 $name=$langs->transcountry($local==1?"LT1ReportByCustomers":"LT2ReportByCustomers", $mysoc->country_code);
108 
109 $fsearch.='<br>';
110 $fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
111 $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
112 $fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
113 $fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
114 
115 $calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
116 // Affiche en-tete du rapport
117 if ($calc==0 || $calc==1) // Calculate on invoice for goods and services
118 {
119  $calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
120  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
121  $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
122  if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
123  $description.=$fsearch;
124  $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
125  $builddate=dol_now();
126 
127  $elementcust=$langs->trans("CustomersInvoices");
128  $productcust=$langs->trans("Description");
129  $amountcust=$langs->trans("AmountHT");
130  $elementsup=$langs->trans("SuppliersInvoices");
131  $productsup=$langs->trans("Description");
132  $amountsup=$langs->trans("AmountHT");
133 }
134 if ($calc==2) // Invoice for goods, payment for services
135 {
136  $calcmode=$langs->trans("CalcModeLT2Debt");
137  $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
138  $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
139  if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
140  $description.=$fsearch;
141  $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
142  $builddate=dol_now();
143 
144  $elementcust=$langs->trans("CustomersInvoices");
145  $productcust=$langs->trans("Description");
146  $amountcust=$langs->trans("AmountHT");
147  $elementsup=$langs->trans("SuppliersInvoices");
148  $productsup=$langs->trans("Description");
149  $amountsup=$langs->trans("AmountHT");
150 }
151 report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
152 
153 
154 $vatcust=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code);
155 $vatsup=$langs->transcountry($local==1?"LT1":"LT2",$mysoc->country_code);
156 
157 // IRPF that the customer has retained me
158 if($calc ==0 || $calc == 2)
159 {
160  print "<table class=\"noborder\" width=\"100%\">";
161  print "<tr class=\"liste_titre\">";
162  print '<td align="left">'.$langs->trans("Num")."</td>";
163  print '<td align="left">'.$langs->trans("Customer")."</td>";
164  print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
165  print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
166  print "<td align=\"right\">".$vatcust."</td>";
167  print "</tr>\n";
168 
169  $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'sell');
170 
171  $action = "tvaclient";
172  $object = &$coll_list;
173  $parameters["mode"] = $modetax;
174  $parameters["start"] = $date_start;
175  $parameters["end"] = $date_end;
176  $parameters["direction"] = 'sell';
177  $parameters["type"] = 'localtax'.$local;
178 
179  // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
180  $hookmanager->initHooks(array('externalbalance'));
181  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
182 
183  if (is_array($coll_list))
184  {
185  $total = 0; $totalamount = 0;
186  $i = 1;
187  foreach($coll_list as $coll)
188  {
189  if(($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) !=0)
190  {
191 
192  $intra = str_replace($find,$replace,$coll->tva_intra);
193  if(empty($intra))
194  {
195  if($coll->assuj == '1')
196  {
197  $intra = $langs->trans('Unknown');
198  }
199  else
200  {
201  $intra = '';
202  }
203  }
204  print '<tr class="oddeven">';
205  print '<td class="nowrap">'.$i."</td>";
206  $company_static->id=$coll->socid;
207  $company_static->name=$coll->name;
208  print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
209  $find = array(' ','.');
210  $replace = array('','');
211  print '<td class="nowrap">'.$intra."</td>";
212  print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
213  print "<td class=\"nowrap\" align=\"right\">".price($local==1?$coll->localtax1:$coll->localtax2)."</td>";
214  $totalamount = $totalamount + $coll->amount;
215  $total = $total + ($local==1?$coll->localtax1:$coll->localtax2);
216  print "</tr>\n";
217  $i++;
218  }
219  }
220  $x_coll_sum = $total;
221 
222  print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
223  print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
224  print '<td class="nowrap" align="right">'.price($total).'</td>';
225  print '</tr>';
226  }
227  else
228  {
229  $langs->load("errors");
230  if ($coll_list == -1)
231  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
232  else if ($coll_list == -2)
233  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
234  else
235  print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
236  }
237 }
238 
239 // IRPF I retained my supplier
240 if($calc ==0 || $calc == 1){
241  print "<table class=\"noborder\" width=\"100%\">";
242  print "<tr class=\"liste_titre\">";
243  print '<td align="left">'.$langs->trans("Num")."</td>";
244  print '<td align="left">'.$langs->trans("Supplier")."</td>";
245  print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
246  print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
247  print "<td align=\"right\">".$vatsup."</td>";
248  print "</tr>\n";
249 
250  $company_static=new Societe($db);
251 
252  $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end,$modetax, 'buy');
253  $parameters["direction"] = 'buy';
254  $parameters["type"] = 'localtax'.$local;
255 
256  $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
257  if (is_array($coll_list))
258  {
259  $total = 0; $totalamount = 0;
260  $i = 1;
261  foreach($coll_list as $coll)
262  {
263  if(($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local==1?$coll->localtax1:$coll->localtax2) != 0)
264  {
265 
266  $intra = str_replace($find,$replace,$coll->tva_intra);
267  if(empty($intra))
268  {
269  if($coll->assuj == '1')
270  {
271  $intra = $langs->trans('Unknown');
272  }
273  else
274  {
275  $intra = '';
276  }
277  }
278  print '<tr class="oddeven">';
279  print '<td class="nowrap">'.$i."</td>";
280  $company_static->id=$coll->socid;
281  $company_static->name=$coll->name;
282  print '<td class="nowrap">'.$company_static->getNomUrl(1).'</td>';
283  $find = array(' ','.');
284  $replace = array('','');
285  print '<td class="nowrap">'.$intra."</td>";
286  print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
287  print "<td class=\"nowrap\" align=\"right\">".price($local==1?$coll->localtax1:$coll->localtax2)."</td>";
288  $totalamount = $totalamount + $coll->amount;
289  $total = $total + ($local==1?$coll->localtax1:$coll->localtax2);
290  print "</tr>\n";
291  $i++;
292  }
293  }
294  $x_paye_sum = $total;
295 
296  print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
297  print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
298  print '<td class="nowrap" align="right">'.price($total).'</td>';
299  print '</tr>';
300 
301  print '</table>';
302  }
303  else
304  {
305  $langs->load("errors");
306  if ($coll_list == -1)
307  print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
308  else if ($coll_list == -2)
309  print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
310  else
311  print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
312  }
313 }
314 
315 if($calc ==0){
316  // Total to pay
317  print '<br><br>';
318  print '<table class="noborder" width="100%">';
319  $diff = $x_coll_sum - $x_paye_sum ;
320  print '<tr class="liste_total">';
321  print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
322  print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
323  print "</tr>\n";
324 }
325 print '</table>';
326 
327 // End of page
328 llxFooter();
329 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
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_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
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 a parameter.
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_now($mode='gmt')
Return date for now.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
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.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
Definition: report.lib.php:41
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...