|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2011-2014 Juanjo Menent <[email protected]> |
|
3
|
|
|
* Copyright (C) 2014 Ferran Marcet <[email protected]> |
|
4
|
|
|
* Copyright (C) 2018 Laurent Destailleur <[email protected]> |
|
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
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* \file htdocs/compta/localtax/index.php |
|
22
|
|
|
* \ingroup tax |
|
23
|
|
|
* \brief Index page of IRPF reports |
|
24
|
|
|
*/ |
|
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/tva/class/tva.class.php'; |
|
30
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php'; |
|
31
|
|
|
|
|
32
|
|
|
// Load translation files required by the page |
|
33
|
|
|
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin")); |
|
34
|
|
|
|
|
35
|
|
|
$localTaxType=GETPOST('localTaxType', 'int'); |
|
36
|
|
|
|
|
37
|
|
|
// Date range |
|
38
|
|
|
$year=GETPOST("year","int"); |
|
39
|
|
|
if (empty($year)) |
|
40
|
|
|
{ |
|
41
|
|
|
$year_current = strftime("%Y",dol_now()); |
|
42
|
|
|
$year_start = $year_current; |
|
43
|
|
|
} else { |
|
44
|
|
|
$year_current = $year; |
|
45
|
|
|
$year_start = $year; |
|
46
|
|
|
} |
|
47
|
|
|
$date_start=dol_mktime(0,0,0,GETPOST("date_startmonth"),GETPOST("date_startday"),GETPOST("date_startyear")); |
|
48
|
|
|
$date_end=dol_mktime(23,59,59,GETPOST("date_endmonth"),GETPOST("date_endday"),GETPOST("date_endyear")); |
|
49
|
|
|
if (empty($date_start) || empty($date_end)) // We define date_start and date_end |
|
50
|
|
|
{ |
|
51
|
|
|
$q=GETPOST("q","int"); |
|
52
|
|
|
if (empty($q)) |
|
53
|
|
|
{ |
|
54
|
|
|
if (GETPOST("month","int")) { $date_start=dol_get_first_day($year_start,GETPOST("month","int"),false); $date_end=dol_get_last_day($year_start,GETPOST("month","int"),false); } |
|
55
|
|
|
else |
|
56
|
|
|
{ |
|
57
|
|
|
$date_start=dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,false); |
|
58
|
|
|
$date_end=dol_time_plus_duree($date_start, 1, 'y') - 1; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
else |
|
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
|
|
|
|
|
70
|
|
|
// Define modetax (0 or 1) |
|
71
|
|
|
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products |
|
72
|
|
|
$modetax = $conf->global->TAX_MODE; |
|
73
|
|
|
if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax",'int'); |
|
74
|
|
|
if (empty($modetax)) $modetax=0; |
|
75
|
|
|
|
|
76
|
|
|
// Security check |
|
77
|
|
|
$socid = GETPOST('socid','int'); |
|
78
|
|
|
if ($user->societe_id) $socid=$user->societe_id; |
|
79
|
|
|
$result = restrictedArea($user, 'tax', '', '', 'charges'); |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* print function |
|
84
|
|
|
* |
|
85
|
|
|
* @param DoliDB $db Database handler |
|
86
|
|
|
* @param string $sql SQL Request |
|
87
|
|
|
* @param string $date Date |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
function pt($db, $sql, $date) |
|
91
|
|
|
{ |
|
92
|
|
|
global $conf, $bc,$langs; |
|
93
|
|
|
|
|
94
|
|
|
$result = $db->query($sql); |
|
95
|
|
|
if ($result) { |
|
96
|
|
|
$num = $db->num_rows($result); |
|
97
|
|
|
$i = 0; |
|
98
|
|
|
$total = 0; |
|
99
|
|
|
print '<table class="noborder" width="100%">'; |
|
100
|
|
|
|
|
101
|
|
|
print '<tr class="liste_titre">'; |
|
102
|
|
|
print '<td class="nowrap">'.$date.'</td>'; |
|
103
|
|
|
print '<td align="right">'.$langs->trans("ClaimedForThisPeriod").'</td>'; |
|
104
|
|
|
print '<td align="right">'.$langs->trans("PaidDuringThisPeriod").'</td>'; |
|
105
|
|
|
print "</tr>\n"; |
|
106
|
|
|
|
|
107
|
|
|
$totalclaimed = 0; |
|
108
|
|
|
$totalpaid = 0; |
|
109
|
|
|
$amountclaimed = 0; |
|
110
|
|
|
$amountpaid = 0; |
|
111
|
|
|
$previousmonth = ''; |
|
112
|
|
|
$previousmode = ''; |
|
113
|
|
|
$mode = ''; |
|
114
|
|
|
|
|
115
|
|
|
while ($i < $num) { |
|
116
|
|
|
$obj = $db->fetch_object($result); |
|
117
|
|
|
$mode = $obj->mode; |
|
118
|
|
|
|
|
119
|
|
|
//print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode; |
|
120
|
|
|
if ($obj->mode == 'claimed' && ! empty($previousmode)) |
|
121
|
|
|
{ |
|
122
|
|
|
print '<tr class="oddeven">'; |
|
123
|
|
|
print '<td class="nowrap">'.$obj->dm."</td>\n"; |
|
124
|
|
|
print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n"; |
|
125
|
|
|
print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n"; |
|
126
|
|
|
print "</tr>\n"; |
|
127
|
|
|
|
|
128
|
|
|
$amountclaimed = 0; |
|
129
|
|
|
$amountpaid = 0; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if ($obj->mode == 'claimed') |
|
133
|
|
|
{ |
|
134
|
|
|
$amountclaimed = $obj->mm; |
|
135
|
|
|
$totalclaimed = $totalclaimed + $amountclaimed; |
|
136
|
|
|
} |
|
137
|
|
|
if ($obj->mode == 'paid') |
|
138
|
|
|
{ |
|
139
|
|
|
$amountpaid = $obj->mm; |
|
140
|
|
|
$totalpaid = $totalpaid + $amountpaid; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
if ($obj->mode == 'paid') |
|
144
|
|
|
{ |
|
145
|
|
|
print '<tr class="oddeven">'; |
|
146
|
|
|
print '<td class="nowrap">'.$obj->dm."</td>\n"; |
|
147
|
|
|
print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n"; |
|
148
|
|
|
print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n"; |
|
149
|
|
|
print "</tr>\n"; |
|
150
|
|
|
$amountclaimed = 0; |
|
151
|
|
|
$amountpaid = 0; |
|
152
|
|
|
$previousmode = ''; |
|
153
|
|
|
$previousmonth = ''; |
|
154
|
|
|
} |
|
155
|
|
|
else |
|
156
|
|
|
{ |
|
157
|
|
|
$previousmode = $obj->mode; |
|
158
|
|
|
$previousmonth = $obj->dm; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
$i++; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if ($mode == 'claimed' && ! empty($previousmode)) |
|
165
|
|
|
{ |
|
166
|
|
|
print '<tr class="oddeven">'; |
|
167
|
|
|
print '<td class="nowrap">'.$previousmonth."</td>\n"; |
|
168
|
|
|
print '<td class="nowrap" align="right">'.price($amountclaimed)."</td>\n"; |
|
169
|
|
|
print '<td class="nowrap" align="right">'.price($amountpaid)."</td>\n"; |
|
170
|
|
|
print "</tr>\n"; |
|
171
|
|
|
|
|
172
|
|
|
$amountclaimed = 0; |
|
173
|
|
|
$amountpaid = 0; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
print '<tr class="liste_total">'; |
|
177
|
|
|
print '<td align="right">'.$langs->trans("Total").'</td>'; |
|
178
|
|
|
print '<td class="nowrap" align="right">'.price($totalclaimed).'</td>'; |
|
179
|
|
|
print '<td class="nowrap" align="right">'.price($totalpaid).'</td>'; |
|
180
|
|
|
print "</tr>"; |
|
181
|
|
|
|
|
182
|
|
|
print "</table>"; |
|
183
|
|
|
$db->free($result); |
|
184
|
|
|
} |
|
185
|
|
|
else { |
|
186
|
|
|
dol_print_error($db); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
/* |
|
192
|
|
|
* View |
|
193
|
|
|
*/ |
|
194
|
|
|
|
|
195
|
|
|
$form=new Form($db); |
|
196
|
|
|
$company_static=new Societe($db); |
|
197
|
|
|
$tva = new Tva($db); |
|
198
|
|
|
|
|
199
|
|
|
if($localTaxType==1) { |
|
200
|
|
|
$LT='LT1'; |
|
201
|
|
|
$LTSummary='LT1Summary'; |
|
202
|
|
|
$LTPaid='LT1Paid'; |
|
203
|
|
|
$LTCustomer='LT1Customer'; |
|
204
|
|
|
$LTSupplier='LT1Supplier'; |
|
205
|
|
|
$CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC1; |
|
206
|
|
|
} else { |
|
207
|
|
|
$LT='LT2'; |
|
208
|
|
|
$LTSummary='LT2Summary'; |
|
209
|
|
|
$LTPaid='LT2Paid'; |
|
210
|
|
|
$LTCustomer='LT2Customer'; |
|
211
|
|
|
$LTSupplier='LT2Supplier'; |
|
212
|
|
|
$CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC2; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$fsearch.=' <input type="hidden" name="localTaxType" value="'.$localTaxType.'">'; |
|
216
|
|
|
$description = $fsearch; |
|
217
|
|
|
|
|
218
|
|
|
// Show report header |
|
219
|
|
|
$name = $langs->trans("ReportByMonth"); |
|
220
|
|
|
$description .= $langs->trans($LT); |
|
221
|
|
|
$calcmode = $langs->trans("LTReportBuildWithOptionDefinedInModule").' '; |
|
222
|
|
|
$calcmode.= '('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')<br>'; |
|
223
|
|
|
|
|
224
|
|
|
//if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue"); |
|
225
|
|
|
|
|
226
|
|
|
$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); |
|
227
|
|
|
|
|
228
|
|
|
$builddate=dol_now(); |
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
llxHeader('', $name); |
|
232
|
|
|
|
|
233
|
|
|
//$textprevyear="<a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current-1) . "\">".img_previous()."</a>"; |
|
234
|
|
|
//$textnextyear=" <a href=\"index.php?localTaxType=".$localTaxType."&year=" . ($year_current+1) . "\">".img_next()."</a>"; |
|
235
|
|
|
//print load_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear", 'title_accountancy.png'); |
|
236
|
|
|
|
|
237
|
|
|
report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); |
|
238
|
|
|
//report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode); |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
print '<br>'; |
|
242
|
|
|
|
|
243
|
|
|
print '<div class="fichecenter"><div class="fichethirdleft">'; |
|
244
|
|
|
|
|
245
|
|
|
print load_fiche_titre($langs->transcountry($LTSummary,$mysoc->country_code), '', ''); |
|
246
|
|
|
|
|
247
|
|
|
print '<table class="noborder" width="100%">'; |
|
248
|
|
|
print '<tr class="liste_titre">'; |
|
249
|
|
|
print '<td width="30%">'.$langs->trans("Year")." ".$y."</td>"; |
|
250
|
|
|
if($CalcLT==0) { |
|
251
|
|
|
print "<td align=\"right\">".$langs->transcountry($LTCustomer,$mysoc->country_code)."</td>"; |
|
252
|
|
|
print "<td align=\"right\">".$langs->transcountry($LTSupplier,$mysoc->country_code)."</td>"; |
|
253
|
|
|
} |
|
254
|
|
|
if($CalcLT==1) { |
|
255
|
|
|
print "<td align=\"right\">".$langs->transcountry($LTSupplier,$mysoc->country_code)."</td><td></td>"; |
|
256
|
|
|
} |
|
257
|
|
|
if($CalcLT==2) { |
|
258
|
|
|
print "<td align=\"right\">".$langs->transcountry($LTCustomer,$mysoc->country_code)."</td><td></td>"; |
|
259
|
|
|
} |
|
260
|
|
|
print "<td align=\"right\">".$langs->trans("TotalToPay")."</td>"; |
|
261
|
|
|
print "<td> </td>\n"; |
|
262
|
|
|
print "</tr>\n"; |
|
263
|
|
|
|
|
264
|
|
|
$tmp=dol_getdate($date_start); |
|
265
|
|
|
$y = $tmp['year']; |
|
266
|
|
|
$m = $tmp['mon']; |
|
267
|
|
|
$tmp=dol_getdate($date_end); |
|
268
|
|
|
$yend = $tmp['year']; |
|
269
|
|
|
$mend = $tmp['mon']; |
|
270
|
|
|
|
|
271
|
|
|
$total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; |
|
272
|
|
|
$i=0; $mcursor=0; |
|
273
|
|
|
while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop |
|
274
|
|
|
{ |
|
275
|
|
|
//$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); |
|
276
|
|
|
if ($m == 13) $y++; |
|
277
|
|
|
if ($m > 12) $m -= 12; |
|
278
|
|
|
$mcursor++; |
|
279
|
|
|
|
|
280
|
|
|
// Get array with details of each line |
|
281
|
|
|
$x_coll = tax_by_rate(($localTaxType==1?'localtax1':'localtax2'), $db, $y, 0, 0, 0, $modetax, 'sell', $m); |
|
282
|
|
|
$x_paye = tax_by_rate(($localTaxType==1?'localtax1':'localtax2'), $db, $y, 0, 0, 0, $modetax, 'buy', $m); |
|
283
|
|
|
|
|
284
|
|
|
$x_both = array(); |
|
285
|
|
|
//now, from these two arrays, get another array with one rate per line |
|
286
|
|
|
foreach(array_keys($x_coll) as $my_coll_rate) |
|
287
|
|
|
{ |
|
288
|
|
|
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht']; |
|
289
|
|
|
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat']; |
|
290
|
|
|
$x_both[$my_coll_rate]['coll']['localtax1'] = $x_coll[$my_coll_rate]['localtax1']; |
|
291
|
|
|
$x_both[$my_coll_rate]['coll']['localtax2'] = $x_coll[$my_coll_rate]['localtax2']; |
|
292
|
|
|
$x_both[$my_coll_rate]['paye']['totalht'] = 0; |
|
293
|
|
|
$x_both[$my_coll_rate]['paye']['vat'] = 0; |
|
294
|
|
|
$x_both[$my_coll_rate]['paye']['localtax1'] = 0; |
|
295
|
|
|
$x_both[$my_coll_rate]['paye']['localtax2'] = 0; |
|
296
|
|
|
$x_both[$my_coll_rate]['coll']['links'] = ''; |
|
297
|
|
|
$x_both[$my_coll_rate]['coll']['detail'] = array(); |
|
298
|
|
|
foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) { |
|
299
|
|
|
//$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id]; |
|
300
|
|
|
//$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id]; |
|
301
|
|
|
//$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id]; |
|
302
|
|
|
//$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]); |
|
303
|
|
|
$x_both[$my_coll_rate]['coll']['detail'][] = array( |
|
304
|
|
|
'id' =>$x_coll[$my_coll_rate]['facid'][$id], |
|
305
|
|
|
'descr' =>$x_coll[$my_coll_rate]['descr'][$id], |
|
306
|
|
|
'pid' =>$x_coll[$my_coll_rate]['pid'][$id], |
|
307
|
|
|
'pref' =>$x_coll[$my_coll_rate]['pref'][$id], |
|
308
|
|
|
'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id], |
|
309
|
|
|
'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id], |
|
310
|
|
|
'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id], |
|
311
|
|
|
'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id], |
|
312
|
|
|
'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id], |
|
313
|
|
|
'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id], |
|
314
|
|
|
'datef' =>$x_coll[$my_coll_rate]['datef'][$id], |
|
315
|
|
|
'datep' =>$x_coll[$my_coll_rate]['datep'][$id], |
|
316
|
|
|
//'company_link'=>$company_static->getNomUrl(1,'',20), |
|
317
|
|
|
'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id], |
|
318
|
|
|
'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id], |
|
319
|
|
|
|
|
320
|
|
|
'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id], |
|
321
|
|
|
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id], |
|
322
|
|
|
'localtax1' =>$x_coll[$my_coll_rate]['localtax1_list'][$id], |
|
323
|
|
|
'localtax2' =>$x_coll[$my_coll_rate]['localtax2_list'][$id], |
|
324
|
|
|
//'link' =>$invoice_customer->getNomUrl(1,'',12) |
|
325
|
|
|
); |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
// tva paid |
|
330
|
|
|
foreach (array_keys($x_paye) as $my_paye_rate) { |
|
331
|
|
|
$x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht']; |
|
332
|
|
|
$x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat']; |
|
333
|
|
|
$x_both[$my_paye_rate]['paye']['localtax1'] = $x_paye[$my_paye_rate]['localtax1']; |
|
334
|
|
|
$x_both[$my_paye_rate]['paye']['localtax2'] = $x_paye[$my_paye_rate]['localtax2']; |
|
335
|
|
|
if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) { |
|
336
|
|
|
$x_both[$my_paye_rate]['coll']['totalht'] = 0; |
|
337
|
|
|
$x_both[$my_paye_rate]['coll']['vat'] = 0; |
|
338
|
|
|
$x_both[$my_paye_rate]['coll']['localtax1'] = 0; |
|
339
|
|
|
$x_both[$my_paye_rate]['coll']['localtax2'] = 0; |
|
340
|
|
|
} |
|
341
|
|
|
$x_both[$my_paye_rate]['paye']['links'] = ''; |
|
342
|
|
|
$x_both[$my_paye_rate]['paye']['detail'] = array(); |
|
343
|
|
|
|
|
344
|
|
|
foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) |
|
345
|
|
|
{ |
|
346
|
|
|
// ExpenseReport |
|
347
|
|
|
if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') |
|
348
|
|
|
{ |
|
349
|
|
|
//$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id]; |
|
350
|
|
|
//$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id]; |
|
351
|
|
|
//$expensereport->type=$x_paye[$my_paye_rate]['type'][$id]; |
|
352
|
|
|
|
|
353
|
|
|
$x_both[$my_paye_rate]['paye']['detail'][] = array( |
|
354
|
|
|
'id' =>$x_paye[$my_paye_rate]['facid'][$id], |
|
355
|
|
|
'descr' =>$x_paye[$my_paye_rate]['descr'][$id], |
|
356
|
|
|
'pid' =>$x_paye[$my_paye_rate]['pid'][$id], |
|
357
|
|
|
'pref' =>$x_paye[$my_paye_rate]['pref'][$id], |
|
358
|
|
|
'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], |
|
359
|
|
|
'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id], |
|
360
|
|
|
'payment_amount' =>$x_paye[$my_paye_rate]['payment_amount'][$id], |
|
361
|
|
|
'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), |
|
362
|
|
|
'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), |
|
363
|
|
|
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], |
|
364
|
|
|
'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id], |
|
365
|
|
|
'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], |
|
366
|
|
|
|
|
367
|
|
|
'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), |
|
368
|
|
|
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], |
|
369
|
|
|
'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id], |
|
370
|
|
|
'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id], |
|
371
|
|
|
//'link' =>$expensereport->getNomUrl(1) |
|
372
|
|
|
); |
|
373
|
|
|
} |
|
374
|
|
|
else |
|
375
|
|
|
{ |
|
376
|
|
|
//$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; |
|
377
|
|
|
//$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; |
|
378
|
|
|
//$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; |
|
379
|
|
|
//$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]); |
|
380
|
|
|
$x_both[$my_paye_rate]['paye']['detail'][] = array( |
|
381
|
|
|
'id' =>$x_paye[$my_paye_rate]['facid'][$id], |
|
382
|
|
|
'descr' =>$x_paye[$my_paye_rate]['descr'][$id], |
|
383
|
|
|
'pid' =>$x_paye[$my_paye_rate]['pid'][$id], |
|
384
|
|
|
'pref' =>$x_paye[$my_paye_rate]['pref'][$id], |
|
385
|
|
|
'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id], |
|
386
|
|
|
'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id], |
|
387
|
|
|
'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id], |
|
388
|
|
|
'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]), |
|
389
|
|
|
'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]), |
|
390
|
|
|
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id], |
|
391
|
|
|
'datef' =>$x_paye[$my_paye_rate]['datef'][$id], |
|
392
|
|
|
'datep' =>$x_paye[$my_paye_rate]['datep'][$id], |
|
393
|
|
|
//'company_link'=>$company_static->getNomUrl(1,'',20), |
|
394
|
|
|
'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id], |
|
395
|
|
|
'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id], |
|
396
|
|
|
|
|
397
|
|
|
'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]), |
|
398
|
|
|
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], |
|
399
|
|
|
'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id], |
|
400
|
|
|
'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id], |
|
401
|
|
|
//'link' =>$invoice_supplier->getNomUrl(1,'',12) |
|
402
|
|
|
); |
|
403
|
|
|
} |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
//now we have an array (x_both) indexed by rates for coll and paye |
|
407
|
|
|
|
|
408
|
|
|
$action = "tva"; |
|
409
|
|
|
$object = array(&$x_coll, &$x_paye, &$x_both); |
|
410
|
|
|
$parameters["mode"] = $modetax; |
|
411
|
|
|
$parameters["year"] = $y; |
|
412
|
|
|
$parameters["month"] = $m; |
|
413
|
|
|
$parameters["type"] = 'localtax'.$localTaxType; |
|
414
|
|
|
|
|
415
|
|
|
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array |
|
416
|
|
|
$hookmanager->initHooks(array('externalbalance')); |
|
417
|
|
|
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
418
|
|
|
|
|
419
|
|
|
if (! is_array($x_coll) && $coll_listbuy == -1) |
|
420
|
|
|
{ |
|
421
|
|
|
$langs->load("errors"); |
|
422
|
|
|
print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>'; |
|
423
|
|
|
break; |
|
424
|
|
|
} |
|
425
|
|
|
if (! is_array($x_paye) && $coll_listbuy == -2) |
|
426
|
|
|
{ |
|
427
|
|
|
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; |
|
428
|
|
|
break; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
|
|
432
|
|
|
print '<tr class="oddeven">'; |
|
433
|
|
|
print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/localtax/quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'</a></td>'; |
|
434
|
|
|
|
|
435
|
|
|
$x_coll_sum = 0; |
|
436
|
|
|
foreach (array_keys($x_coll) as $rate) |
|
437
|
|
|
{ |
|
438
|
|
|
$subtot_coll_total_ht = 0; |
|
439
|
|
|
$subtot_coll_vat = 0; |
|
440
|
|
|
|
|
441
|
|
|
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) |
|
442
|
|
|
{ |
|
443
|
|
|
// Payment |
|
444
|
|
|
$ratiopaymentinvoice=1; |
|
445
|
|
|
if ($modetax != 1) |
|
446
|
|
|
{ |
|
447
|
|
|
// Define type |
|
448
|
|
|
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. |
|
449
|
|
|
$type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']); |
|
450
|
|
|
// Try to enhance type detection using date_start and date_end for free lines where type |
|
451
|
|
|
// was not saved. |
|
452
|
|
|
if (!empty($fields['ddate_start'])) { |
|
453
|
|
|
$type=1; |
|
454
|
|
|
} |
|
455
|
|
|
if (!empty($fields['ddate_end'])) { |
|
456
|
|
|
$type=1; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') |
|
460
|
|
|
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) |
|
461
|
|
|
{ |
|
462
|
|
|
//print $langs->trans("NA"); |
|
463
|
|
|
} else { |
|
464
|
|
|
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { |
|
465
|
|
|
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
} |
|
469
|
|
|
//var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); |
|
470
|
|
|
$temp_ht=$fields['totalht']*$ratiopaymentinvoice; |
|
471
|
|
|
$temp_vat=$fields['localtax'.$localTaxType]*$ratiopaymentinvoice; |
|
472
|
|
|
$subtot_coll_total_ht += $temp_ht; |
|
473
|
|
|
$subtot_coll_vat += $temp_vat; |
|
474
|
|
|
$x_coll_sum += $temp_vat; |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
print "<td class=\"nowrap\" align=\"right\">".price(price2num($x_coll_sum,'MT'))."</td>"; |
|
478
|
|
|
|
|
479
|
|
|
$x_paye_sum = 0; |
|
480
|
|
|
foreach (array_keys($x_paye) as $rate) |
|
481
|
|
|
{ |
|
482
|
|
|
$subtot_paye_total_ht = 0; |
|
483
|
|
|
$subtot_paye_vat = 0; |
|
484
|
|
|
|
|
485
|
|
|
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) |
|
486
|
|
|
{ |
|
487
|
|
|
// Payment |
|
488
|
|
|
$ratiopaymentinvoice=1; |
|
489
|
|
|
if ($modetax != 1) |
|
490
|
|
|
{ |
|
491
|
|
|
// Define type |
|
492
|
|
|
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. |
|
493
|
|
|
$type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']); |
|
494
|
|
|
// Try to enhance type detection using date_start and date_end for free lines where type |
|
495
|
|
|
// was not saved. |
|
496
|
|
|
if (!empty($fields['ddate_start'])) { |
|
497
|
|
|
$type=1; |
|
498
|
|
|
} |
|
499
|
|
|
if (!empty($fields['ddate_end'])) { |
|
500
|
|
|
$type=1; |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') |
|
504
|
|
|
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) |
|
505
|
|
|
{ |
|
506
|
|
|
//print $langs->trans("NA"); |
|
507
|
|
|
} else { |
|
508
|
|
|
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { |
|
509
|
|
|
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']); |
|
510
|
|
|
} |
|
511
|
|
|
} |
|
512
|
|
|
} |
|
513
|
|
|
//var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); |
|
514
|
|
|
$temp_ht=$fields['totalht']*$ratiopaymentinvoice; |
|
515
|
|
|
$temp_vat=$fields['localtax'.$localTaxType]*$ratiopaymentinvoice; |
|
516
|
|
|
$subtot_paye_total_ht += $temp_ht; |
|
517
|
|
|
$subtot_paye_vat += $temp_vat; |
|
518
|
|
|
$x_paye_sum += $temp_vat; |
|
519
|
|
|
} |
|
520
|
|
|
} |
|
521
|
|
|
print "<td class=\"nowrap\" align=\"right\">".price(price2num($x_paye_sum,'MT'))."</td>"; |
|
522
|
|
|
|
|
523
|
|
|
$subtotalcoll = $subtotalcoll + $x_coll_sum; |
|
524
|
|
|
$subtotalpaye = $subtotalpaye + $x_paye_sum; |
|
525
|
|
|
|
|
526
|
|
|
$diff = $x_coll_sum - $x_paye_sum; |
|
527
|
|
|
$total = $total + $diff; |
|
528
|
|
|
$subtotal = price2num($subtotal + $diff, 'MT'); |
|
529
|
|
|
|
|
530
|
|
|
print "<td class=\"nowrap\" align=\"right\">".price(price2num($diff,'MT'))."</td>\n"; |
|
531
|
|
|
print "<td> </td>\n"; |
|
532
|
|
|
print "</tr>\n"; |
|
533
|
|
|
|
|
534
|
|
|
$i++; $m++; |
|
535
|
|
|
if ($i > 2) |
|
536
|
|
|
{ |
|
537
|
|
|
print '<tr class="liste_total">'; |
|
538
|
|
|
print '<td align="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.($m/3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>'; |
|
539
|
|
|
print '<td class="nowrap" align="right">'.price(price2num($subtotalcoll,'MT')).'</td>'; |
|
540
|
|
|
print '<td class="nowrap" align="right">'.price(price2num($subtotalpaye,'MT')).'</td>'; |
|
541
|
|
|
print '<td class="nowrap" align="right">'.price(price2num($subtotal,'MT')).'</td>'; |
|
542
|
|
|
print '<td> </td></tr>'; |
|
543
|
|
|
$i = 0; |
|
544
|
|
|
$subtotalcoll=0; $subtotalpaye=0; $subtotal=0; |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap" align="right">'.price(price2num($total, 'MT')).'</td>'; |
|
548
|
|
|
print "<td> </td>\n"; |
|
549
|
|
|
print '</tr>'; |
|
550
|
|
|
|
|
551
|
|
|
print '</table>'; |
|
552
|
|
|
|
|
553
|
|
|
|
|
554
|
|
|
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">'; |
|
555
|
|
|
|
|
556
|
|
|
|
|
557
|
|
|
|
|
558
|
|
|
/* |
|
559
|
|
|
* Payed |
|
560
|
|
|
*/ |
|
561
|
|
|
|
|
562
|
|
|
print load_fiche_titre($langs->transcountry($LTPaid,$mysoc->country_code), '', ''); |
|
563
|
|
|
|
|
564
|
|
|
$sql=''; |
|
565
|
|
|
|
|
566
|
|
|
$sql.= "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm, 'claimed' as mode"; |
|
567
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."localtax as f"; |
|
568
|
|
|
$sql.= " WHERE f.entity = ".$conf->entity; |
|
569
|
|
|
$sql.= " AND (f.datev >= '".$db->idate($date_start)."' AND f.datev <= '".$db->idate($date_end)."')"; |
|
570
|
|
|
$sql.= " AND localtaxtype=".$localTaxType; |
|
571
|
|
|
$sql.= " GROUP BY dm"; |
|
572
|
|
|
|
|
573
|
|
|
$sql.= " UNION "; |
|
574
|
|
|
|
|
575
|
|
|
$sql.= "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm, 'paid' as mode"; |
|
576
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."localtax as f"; |
|
577
|
|
|
$sql.= " WHERE f.entity = ".$conf->entity; |
|
578
|
|
|
$sql.= " AND (f.datep >= '".$db->idate($date_start)."' AND f.datep <= '".$db->idate($date_end)."')"; |
|
579
|
|
|
$sql.= " AND localtaxtype=".$localTaxType; |
|
580
|
|
|
$sql.= " GROUP BY dm"; |
|
581
|
|
|
|
|
582
|
|
|
$sql.= " ORDER BY dm ASC, mode ASC"; |
|
583
|
|
|
//print $sql; |
|
584
|
|
|
|
|
585
|
|
|
pt($db, $sql, $langs->trans("Month")); |
|
586
|
|
|
|
|
587
|
|
|
|
|
588
|
|
|
print '</div></div>'; |
|
589
|
|
|
|
|
590
|
|
|
llxFooter(); |
|
591
|
|
|
$db->close(); |
|
592
|
|
|
|