PageRenderTime 125ms CodeModel.GetById 40ms app.highlight 41ms RepoModel.GetById 40ms app.codeStats 0ms

/htdocs/compta/localtax/clients.php

https://bitbucket.org/speedealing/speedealing
PHP | 299 lines | 235 code | 32 blank | 32 comment | 46 complexity | 2bb469e57ae02e1724d30e95d593ae7b MD5 | raw file
  1<?php
  2/* Copyright (C) 2011	Juanjo Menent <jmenent@2byte.es>
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License as published by
  6 * the Free Software Foundation; either version 3 of the License, or
  7 * (at your option) any later version.
  8 *
  9 * This program is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18/**
 19 *	    \file       htdocs/compta/localtax/clients.php
 20 *      \ingroup    tax
 21 *		\brief      Third parties localtax report
 22 */
 23
 24require '../../main.inc.php';
 25require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
 26require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
 27require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 28require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
 29
 30$langs->load("bills");
 31$langs->load("compta");
 32$langs->load("companies");
 33$langs->load("products");
 34
 35// Date range
 36$year=GETPOST("year");
 37if (empty($year))
 38{
 39	$year_current = strftime("%Y",dol_now());
 40	$year_start = $year_current;
 41} else {
 42	$year_current = $year;
 43	$year_start = $year;
 44}
 45$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
 46$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
 47// Quarter
 48if (empty($date_start) || empty($date_end)) // We define date_start and date_end
 49{
 50    $q=GETPOST("q");
 51    if (empty($q))
 52	{
 53		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); }
 54		else
 55		{
 56		    $month_current = strftime("%m",dol_now());
 57		    if ($month_current >= 10) $q=4;
 58            elseif ($month_current >= 7) $q=3;
 59            elseif ($month_current >= 4) $q=2;
 60            else $q=1;
 61		}
 62	}
 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$min = GETPOST("min");
 70if (empty($min)) $min = 0;
 71
 72// Define modetax (0 or 1)
 73// 0=normal, 1=option vat for services is on debit
 74$modetax = $conf->global->TAX_MODE;
 75if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
 76
 77// Security check
 78$socid = GETPOST('socid','int');
 79if ($user->societe_id) $socid=$user->societe_id;
 80$result = restrictedArea($user, 'tax', '', '', 'charges');
 81
 82/*
 83 * View
 84 */
 85
 86$form=new Form($db);
 87$company_static=new Societe($db);
 88
 89$morequerystring='';
 90$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
 91foreach($listofparams as $param)
 92{
 93	if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
 94}
 95
 96llxHeader('','','','',0,0,'','',$morequerystring);
 97
 98$fsearch.='<br>';
 99$fsearch.='  <input type="hidden" name="year" value="'.$year.'">';
100$fsearch.='  <input type="hidden" name="modetax" value="'.$modetax.'">';
101$fsearch.='  '.$langs->trans("SalesTurnover").' '.$langs->trans("Minimum").': ';
102$fsearch.='  <input type="text" name="min" id="min" value="'.$min.'" size="6">';
103
104// Affiche en-tete du rapport
105if ($modetax==1)	// Calculate on invoice for goods and services
106{
107    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
108    $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);
109    $description=$langs->trans("RulesVATDue");
110    if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
111    $description.=$fsearch;
112    $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
113	$builddate=time();
114
115	$elementcust=$langs->trans("CustomersInvoices");
116	$productcust=$langs->trans("Description");
117	$amountcust=$langs->trans("AmountHT");
118	$elementsup=$langs->trans("SuppliersInvoices");
119	$productsup=$langs->trans("Description");
120	$amountsup=$langs->trans("AmountHT");
121}
122if ($modetax==0) 	// Invoice for goods, payment for services
123{
124    $nom=$langs->transcountry("LT2ReportByCustomersInInputOutputMode",$mysoc->country_code);
125    $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);
126    $description=$langs->trans("RulesVATIn");
127    if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
128    $description.=$fsearch;
129    $description.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
130    $builddate=time();
131
132	$elementcust=$langs->trans("CustomersInvoices");
133	$productcust=$langs->trans("Description");
134	$amountcust=$langs->trans("AmountHT");
135	$elementsup=$langs->trans("SuppliersInvoices");
136	$productsup=$langs->trans("Description");
137	$amountsup=$langs->trans("AmountHT");
138}
139report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
140
141$vatcust=$langs->transcountry("LT2",$mysoc->country_code);
142$vatsup=$langs->transcountry("LT2",$mysoc->country_code);
143
144// IRPF that the customer has retained me
145
146print "<table class=\"noborder\" width=\"100%\">";
147print "<tr class=\"liste_titre\">";
148print '<td align="left">'.$langs->trans("Num")."</td>";
149print '<td align="left">'.$langs->trans("Customer")."</td>";
150print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
151print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
152print "<td align=\"right\">".$vatcust."</td>";
153print "</tr>\n";
154
155$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
156if (is_array($coll_list))
157{
158	$var=true;
159	$total = 0;  $totalamount = 0;
160	$i = 1;
161	foreach($coll_list as $coll)
162	{
163		if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2>0)
164		{
165			$var=!$var;
166			$intra = str_replace($find,$replace,$coll->tva_intra);
167			if(empty($intra))
168			{
169				if($coll->assuj == '1')
170				{
171					$intra = $langs->trans('Unknown');
172				}
173				else
174				{
175					$intra = '';
176				}
177			}
178			print "<tr ".$bc[$var].">";
179			print "<td nowrap>".$i."</td>";
180			$company_static->id=$coll->socid;
181			$company_static->nom=$coll->nom;
182			print '<td nowrap>'.$company_static->getNomUrl(1).'</td>';
183			$find = array(' ','.');
184			$replace = array('','');
185			print "<td nowrap>".$intra."</td>";
186			print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
187			print "<td nowrap align=\"right\">".price($coll->localtax2)."</td>";
188            $totalamount = $totalamount + $coll->amount;
189			$total = $total + $coll->localtax2;
190			print "</tr>\n";
191			$i++;
192		}
193	}
194    $x_coll_sum = $total;
195
196	print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
197    print '<td nowrap align="right">'.price($totalamount).'</td>';
198	print '<td nowrap align="right">'.price($total).'</td>';
199	print '</tr>';
200}
201else
202{
203	$langs->load("errors");
204	if ($coll_list == -1)
205		print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
206	else if ($coll_list == -2)
207		print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
208	else
209		print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
210}
211
212// IRPF I retained my supplier
213
214print "<tr class=\"liste_titre\">";
215print '<td align="left">'.$langs->trans("Num")."</td>";
216print '<td align="left">'.$langs->trans("Supplier")."</td>";
217print "<td>".$langs->transcountry("ProfId1",$mysoc->country_code)."</td>";
218print "<td align=\"right\">".$langs->trans("TotalHT")."</td>";
219print "<td align=\"right\">".$vatsup."</td>";
220print "</tr>\n";
221
222$company_static=new Societe($db);
223
224$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
225if (is_array($coll_list))
226{
227	$var=true;
228	$total = 0;  $totalamount = 0;
229	$i = 1;
230	foreach($coll_list as $coll)
231	{
232		if(($min == 0 or ($min > 0 && $coll->amount > $min)) && $coll->localtax2>0)
233		{
234			$var=!$var;
235			$intra = str_replace($find,$replace,$coll->tva_intra);
236			if(empty($intra))
237			{
238				if($coll->assuj == '1')
239				{
240					$intra = $langs->trans('Unknown');
241				}
242				else
243				{
244					$intra = '';
245				}
246			}
247			print "<tr $bc[$var]>";
248			print "<td nowrap>".$i."</td>";
249			$company_static->id=$coll->socid;
250			$company_static->nom=$coll->nom;
251			print '<td nowrap>'.$company_static->getNomUrl(1).'</td>';
252			$find = array(' ','.');
253			$replace = array('','');
254			print "<td nowrap>".$intra."</td>";
255			print "<td nowrap align=\"right\">".price($coll->amount)."</td>";
256			print "<td nowrap align=\"right\">".price($coll->localtax2)."</td>";
257            $totalamount = $totalamount + $coll->amount;
258			$total = $total + $coll->localtax2;
259			print "</tr>\n";
260			$i++;
261		}
262	}
263    $x_paye_sum = $total;
264
265	print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
266    print '<td nowrap align="right">'.price($totalamount).'</td>';
267	print '<td nowrap align="right">'.price($total).'</td>';
268	print '</tr>';
269
270	print '</table>';
271
272    // Total to pay
273    print '<br><br>';
274    print '<table class="noborder" width="100%">';
275    $diff = $x_paye_sum;
276    print '<tr class="liste_total">';
277    print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
278    print '<td class="liste_total" nowrap="nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
279    print "</tr>\n";
280
281}
282else
283{
284	$langs->load("errors");
285	if ($coll_list == -1)
286		print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
287	else if ($coll_list == -2)
288		print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
289	else
290		print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
291}
292
293print '</table>';
294
295
296$db->close();
297
298llxFooter();
299?>