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