forked from Darkjeff/ultimateimmo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ultimateimmoindex.php
382 lines (330 loc) · 13.9 KB
/
ultimateimmoindex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2015 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2012 Regis Houssin <[email protected]>
* Copyright (C) 2015 Jean-François Ferry <[email protected]>
* Copyright (C) 2018 Philippe GRAND <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/ultimateimmo/template/ultimateimmoindex.php
* \ingroup ultimateimmo
* \brief Home page of ultimateimmo top menu
*/
// Load Dolibarr environment
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php");
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php");
// Try main.inc.php using relative path
if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php");
if (! $res) die("Include of main fails");
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
dol_include_once('/ultimateimmo/class/immoowner.class.php');
dol_include_once('/ultimateimmo/class/immoowner_type.class.php');
dol_include_once('/ultimateimmo/class/immoproperty.class.php');
$langs->loadLangs(array("ultimateimmo@ultimateimmo"));
$action=GETPOST('action', 'alpha');
$id = GETPOST('id','int')?GETPOST('id','int'):GETPOST('rowid','int');
// Securite acces client
if (! $user->rights->ultimateimmo->read) accessforbidden();
$socid=GETPOST('socid','int');
if (isset($user->societe_id) && $user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
$max=5;
$now=dol_now();
/*
* Actions
*/
// None
/*
* View
*/
$form = new Form($db);
$formfile = new FormFile($db);
$staticowner=new ImmoOwner($db);
$statictype=new ImmoOwner_Type($db);
$immopropertystatic=new ImmoProperty($db);
llxHeader("",$langs->trans("UltimateimmoArea"));
print load_fiche_titre($langs->trans("UltimateimmoArea"),'','ultimateimmo.png@ultimateimmo');
$Immoowners=array();
$OwnerToValidate=array();
$OwnersValidated=array();
$OwnerUpToDate=array();
$OwnersResiliated=array();
$ImmoownerType=array();
// Liste les proprietaires
$sql = "SELECT t.rowid, t.label,";
$sql.= " d.status, count(d.rowid) as somme";
$sql.= " FROM ".MAIN_DB_PREFIX."ultimateimmo_immoowner_type as t";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ultimateimmo_immoowner as d";
$sql.= " ON t.rowid = d.fk_immoowner_type";
$sql.= " AND d.entity IN (".getEntity('immoowner').")";
$sql.= " WHERE t.entity IN (".getEntity('immoowner_type').")";
$sql.= " GROUP BY t.rowid, t.label, d.status";
dol_syslog("index.php::select nb of immoowners by type", LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$ownertype=new ImmoOwner_Type($db);
$ownertype->id=$objp->rowid;
$ownertype->label=$objp->label;
$ImmoownerType[$objp->rowid]=$ownertype;
if ($objp->status == -1) { $OwnerToValidate[$objp->rowid]=$objp->somme; }
if ($objp->status == 1) { $OwnersValidated[$objp->rowid]=$objp->somme; }
if ($objp->status == 0) { $OwnersResiliated[$objp->rowid]=$objp->somme; }
$i++;
}
$db->free($result);
}
$now=dol_now();
// current rule: uptodate = the end date is in future whatever is type
// old rule: uptodate = if type does not need payment, that end date is null, if type need payment that end date is in future)
$sql = "SELECT count(*) as somme , d.fk_immoowner_type";
$sql.= " FROM ".MAIN_DB_PREFIX."ultimateimmo_immoowner as d, ".MAIN_DB_PREFIX."ultimateimmo_immoowner_type as t";
$sql.= " WHERE d.entity IN (".getEntity('immoowner').")";
//$sql.= " AND d.statut = 1 AND ((t.subscription = 0 AND d.datefin IS NULL) OR d.datefin >= '".$db->idate($now)."')";
$sql.= " AND d.status = 1 AND d.datefin >= '".$db->idate($now)."'";
$sql.= " AND t.rowid = d.fk_immoowner_type";
$sql.= " GROUP BY d.fk_immoowner_type";
dol_syslog("index.php::select nb of uptodate owners by type", LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$OwnerUpToDate[$objp->fk_immoowner_type]=$objp->somme;
$i++;
}
$db->free();
}
print '<div class="fichecenter"><div class="fichethirdleft">';
/*
* Statistics
*/
if ($conf->use_javascript_ajax)
{
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder nohover" width="100%">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
print '<tr><td align="center" colspan="2">';
$SommeA=0;
$SommeB=0;
$SommeC=0;
$SommeD=0;
$total=0;
$dataval=array();
$datalabels=array();
$i=0;
foreach ($ImmoownerType as $key => $ownertype)
{
$datalabels[]=array($i,$ownertype->getNomUrl(0,dol_size(16)));
$dataval['draft'][]=array($i,isset($OwnerToValidate[$key])?$OwnerToValidate[$key]:0);
$dataval['notuptodate'][]=array($i,isset($OwnersValidated[$key])?$OwnersValidated[$key]-(isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0):0);
$dataval['uptodate'][]=array($i,isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0);
$dataval['resiliated'][]=array($i,isset($OwnersResiliated[$key])?$OwnersResiliated[$key]:0);
$SommeA+=isset($OwnerToValidate[$key])?$OwnerToValidate[$key]:0;
$SommeB+=isset($OwnersValidated[$key])?$OwnersValidated[$key]-(isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0):0;
$SommeC+=isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0;
$SommeD+=isset($OwnersResiliated[$key])?$OwnersResiliated[$key]:0;
$i++;
}
$total = $SommeA + $SommeB + $SommeC + $SommeD;
$dataseries=array();
$dataseries[]=array($langs->trans("MenuOwnersNotUpToDate"), round($SommeB));
$dataseries[]=array($langs->trans("MenuOwnersUpToDate"), round($SommeC));
$dataseries[]=array($langs->trans("OwnersStatusResiliated"), round($SommeD));
$dataseries[]=array($langs->trans("OwnersStatusToValid"), round($SommeA));
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
$dolgraph = new DolGraph();
$dolgraph->SetData($dataseries);
$dolgraph->setShowLegend(1);
$dolgraph->setShowPercent(1);
$dolgraph->SetType(array('pie'));
$dolgraph->setWidth('100%');
$dolgraph->draw('idgraphstatus');
print $dolgraph->show($total?0:1);
print '</td></tr>';
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
print $SommeA+$SommeB+$SommeC+$SommeD;
print '</td></tr>';
print '</table>';
print '</div>';
}
print '<br>';
// List of rent by year
$Total=array();
$Number=array();
$tot=0;
$numb=0;
$sql = "SELECT c.notice, c.date_start as datestart";
$sql.= " FROM ".MAIN_DB_PREFIX."ultimateimmo_immoowner as d, ".MAIN_DB_PREFIX."ultimateimmo_immoproperty as c";
$sql.= " WHERE d.entity IN (".getEntity('immoowner').")";
$sql.= " AND d.rowid = c.fk_soc";
if(isset($date_select) && $date_select != '')
{
$sql .= " AND c.datestart LIKE '".$date_select."%'";
}
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$year=dol_print_date($db->jdate($objp->datestart),"%Y");
$Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->notice;
$Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1;
$tot+=$objp->notice;
$numb+=1;
$i++;
}
}
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Subscriptions").'</th>';
print '<th align="right">'.$langs->trans("Number").'</th>';
print '<th align="right">'.$langs->trans("AmountTotal").'</th>';
print '<th align="right">'.$langs->trans("AmountAverage").'</th>';
print "</tr>\n";
krsort($Total);
foreach ($Total as $key=>$value)
{
print '<tr class="oddeven">';
print '<td><a href=\"'.dol_buildpath('/ultimateimmo/property/immoproperty_list.php',1).'?date_select=$key\">$key</a></td>';
print "<td align=\"right\">".$Number[$key]."</td>";
print "<td align=\"right\">".price($value)."</td>";
print "<td align=\"right\">".price(price2num($value/$Number[$key],'MT'))."</td>";
print "</tr>\n";
}
// Total
print '<tr class="liste_total">';
print '<td>'.$langs->trans("Total").'</td>';
print "<td align=\"right\">".$numb."</td>";
print '<td align="right">'.price($tot)."</td>";
print "<td align=\"right\">".price(price2num($numb>0?($tot/$numb):0,'MT'))."</td>";
print "</tr>\n";
print "</table></div>";
print "<br>\n";
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
/*
* Last modified owners
*/
$max=5;
$sql = "SELECT a.rowid, a.status, a.lastname, a.firstname, a.fk_soc,";
$sql.= " a.tms as datem, a.date_creation,";
$sql.= " ta.rowid as typeid, ta.label";
$sql.= " FROM ".MAIN_DB_PREFIX."ultimateimmo_immoowner as a, ".MAIN_DB_PREFIX."ultimateimmo_immoowner_type as ta";
$sql.= " WHERE a.entity IN (".getEntity('immoowner').")";
$sql.= " AND a.fk_immoowner_type = ta.rowid";
$sql.= $db->order("a.tms","DESC");
$sql.= $db->plimit($max, 0);
$resql=$db->query($sql);
if ($resql)
{
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th colspan="4">'.$langs->trans("LastOwnersModified",$max).'</th></tr>';
$num = $db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
$staticowner->id=$obj->rowid;
$staticowner->lastname=$obj->lastname;
$staticowner->firstname=$obj->firstname;
if (! empty($obj->fk_soc))
{
$staticowner->fk_soc = $obj->fk_soc;
$staticowner->fetch_thirdparty();
$staticowner->name=$staticowner->thirdparty->name;
}
else
{
$staticowner->name=$obj->company;
}
$staticowner->ref=$staticowner->getFullName($langs);
$statictype->id=$obj->typeid;
$statictype->label=$obj->label;
print '<td>'.$staticowner->getNomUrl(1,32).'</td>';
print '<td>'.$statictype->getNomUrl(1,32).'</td>';
print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';
print '<td align="right">'.$staticowner->LibStatut($obj->status,($obj->phone_mobile=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>';
print '</tr>';
$i++;
}
}
print "</table></div>";
print "<br>";
}
else
{
dol_print_error($db);
}
// Summary of renters by type
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("OwnersTypes").'</th>';
print '<th align=right>'.$langs->trans("OwnersStatusToValid").'</th>';
print '<th align=right>'.$langs->trans("MenuOwnersNotUpToDate").'</th>';
print '<th align=right>'.$langs->trans("MenuOwnersUpToDate").'</th>';
print '<th align=right>'.$langs->trans("OwnersStatusResiliated").'</th>';
print "</tr>\n";
foreach ($ImmoownerType as $key => $ownertype)
{
print '<tr class="oddeven">';
print '<td>'.$ownertype->getNomUrl(1, dol_size(32)).'</td>';
print '<td align="right">'.(isset($OwnerToValidate[$key]) && $OwnerToValidate[$key] > 0?$OwnerToValidate[$key]:'').' '.$staticowner->LibStatut(-1,$ownertype->label,0,3).'</td>';
print '<td align="right">'.(isset($OwnersValidated[$key]) && ($OwnersValidated[$key]-(isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0) > 0) ? $OwnersValidated[$key]-(isset($OwnerUpToDate[$key])?$OwnerUpToDate[$key]:0):'').' '.$staticowner->LibStatut(1,$ownertype->label,0,3).'</td>';
print '<td align="right">'.(isset($OwnerUpToDate[$key]) && $OwnerUpToDate[$key] > 0 ? $OwnerUpToDate[$key]:'').' '.$staticowner->LibStatut(1,$ownertype->label,$now,3).'</td>';
print '<td align="right">'.(isset($OwnersResiliated[$key]) && $OwnersResiliated[$key]> 0 ?$OwnersResiliated[$key]:'').' '.$staticowner->LibStatut(0,$ownertype->label,0,3).'</td>';
print "</tr>\n";
}
print '<tr class="liste_total">';
print '<td class="liste_total">'.$langs->trans("Total").'</td>';
print '<td class="liste_total" align="right">'.$SommeA.' '.$staticowner->LibStatut(-1,$ownertype->label,0,3).'</td>';
print '<td class="liste_total" align="right">'.$SommeB.' '.$staticowner->LibStatut(1,$ownertype->label,0,3).'</td>';
print '<td class="liste_total" align="right">'.$SommeC.' '.$staticowner->LibStatut(1,$ownertype->label,$now,3).'</td>';
print '<td class="liste_total" align="right">'.$SommeD.' '.$staticowner->LibStatut(0,$ownertype->label,0,3).'</td>';
print '</tr>';
print "</table>\n";
print "</div>";
print '</div></div></div>';
llxFooter();
$db->close();