Passed
Push — master ( 284492...2c3033 )
by Alxarafe
27:10
created

Controllers/ThirdParty.php (9 issues)

1
<?php
2
3
namespace Alixar\Controllers;
4
5
use Alixar\Base\AlixarController;
6
use Alixar\Base\Translate;
7
8
class ThirdParty extends AlixarController
9
{
10
11
    public function __construct()
12
    {
13
        parent::__construct();
14
    }
15
16
    public function main()
17
    {
18
        $langs = new Translate();
0 ignored issues
show
The call to Alixar\Base\Translate::__construct() has too few arguments starting with dir. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $langs = /** @scrutinizer ignore-call */ new Translate();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
19
20
        $langs->load("companies");
21
22
        $socid = GETPOST('socid', 'int');
23
        if ($user->societe_id) $socid = $user->societe_id;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $user seems to be never defined.
Loading history...
24
25
// Security check
26
        $result = restrictedArea($user, 'societe', 0, '', '', '', '');
27
28
        $thirdparty_static = new Societe($db);
0 ignored issues
show
The type Alixar\Controllers\Societe was not found. Did you mean Societe? If so, make sure to prefix the type with \.
Loading history...
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
29
30
31
        /*
32
         * View
33
         */
34
35
        $transAreaType = $langs->trans("ThirdPartiesArea");
36
        $helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
37
38
        llxHeader("", $langs->trans("ThirdParties"), $helpurl);
39
        $linkback = '';
40
        print load_fiche_titre($transAreaType, $linkback, 'title_companies.png');
41
42
43
//print '<table border="0" width="100%" class="notopnoleftnoright">';
44
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
45
        print '<div class="fichecenter"><div class="fichethirdleft">';
46
47
48
        if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $conf seems to be never defined.
Loading history...
49
        {
50
            // Search thirdparty
51
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire) {
52
                $listofsearchfields['search_thirdparty'] = array('text' => 'ThirdParty');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$listofsearchfields was never initialized. Although not strictly required by PHP, it is generally a good practice to add $listofsearchfields = array(); before regardless.
Loading history...
53
            }
54
            // Search contact/address
55
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire) {
56
                $listofsearchfields['search_contact'] = array('text' => 'Contact');
57
            }
58
59
            if (count($listofsearchfields)) {
60
                // print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
61
                print '<form method="post" action="' . BASE_URI . '?controller=core&method=search">';
0 ignored issues
show
The constant Alixar\Controllers\BASE_URI was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
62
                print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
63
                print '<table class="noborder nohover centpercent">';
64
                $i = 0;
65
                foreach ($listofsearchfields as $key => $value) {
66
                    if ($i == 0) print '<tr class="liste_titre"><th colspan="3">' . $langs->trans("Search") . '</th></tr>';
67
                    print '<tr ' . $bc[false] . '>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $bc seems to be never defined.
Loading history...
68
                    print '<td class="nowrap"><label for="' . $key . '">' . $langs->trans($value["text"]) . '</label></td><td><input type="text" class="flat inputsearch" name="' . $key . '" id="' . $key . '" size="18"></td>';
69
                    if ($i == 0) print '<td rowspan="' . count($listofsearchfields) . '"><input type="submit" value="' . $langs->trans("Search") . '" class="button"></td>';
70
                    print '</tr>';
71
                    $i++;
72
                }
73
                print '</table>';
74
                print '</form>';
75
                print '<br>';
76
            }
77
        }
78
79
80
        /*
81
         * Statistics area
82
         */
83
84
        $third = array(
85
            'customer' => 0,
86
            'prospect' => 0,
87
            'supplier' => 0,
88
            'other' => 0
89
        );
90
        $total = 0;
91
92
        $sql = "SELECT s.rowid, s.client, s.fournisseur";
93
        $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
94
        if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
95
        $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')';
96
        if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
97
        if ($socid) $sql .= " AND s.rowid = " . $socid;
98
        if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)";    // client=0, fournisseur=0 must be visible
99
//print $sql;
100
        $result = $db->query($sql);
101
        if ($result) {
102
            while ($objp = $db->fetch_object($result)) {
103
                $found = 0;
104
                if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) {
105
                    $found = 1;
106
                    $third['prospect']++;
107
                }
108
                if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) {
109
                    $found = 1;
110
                    $third['customer']++;
111
                }
112
                if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) {
113
                    $found = 1;
114
                    $third['supplier']++;
115
                }
116
                if (!empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) {
117
                    $found = 1;
118
                    $third['other']++;
119
                }
120
                if ($found) $total++;
121
            }
122
        } else dol_print_error($db);
123
124
        print '<div class="div-table-responsive-no-min">';
125
        print '<table class="noborder nohover" width="100%">' . "\n";
126
        print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Statistics") . '</th></tr>';
127
        if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2)) {
128
            print '<tr><td align="center" colspan="2">';
129
            $dataseries = array();
130
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
131
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
132
            if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
133
            if (!empty($conf->societe->enabled)) $dataseries[] = array($langs->trans("Others"), round($third['other']));
134
            include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
135
            $dolgraph = new DolGraph();
0 ignored issues
show
The type Alixar\Controllers\DolGraph was not found. Did you mean DolGraph? If so, make sure to prefix the type with \.
Loading history...
136
            $dolgraph->SetData($dataseries);
137
            $dolgraph->setShowLegend(1);
138
            $dolgraph->setShowPercent(1);
139
            $dolgraph->SetType(array('pie'));
140
            $dolgraph->setWidth('100%');
141
            $dolgraph->draw('idgraphthirdparties');
142
            print $dolgraph->show();
143
            print '</td></tr>' . "\n";
144
        } else {
145
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
146
                $statstring = "<tr>";
147
                //$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td align="right">'.round($third['prospect']).'</td>';
148
                $statstring .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&type=p">' . $langs->trans("Prospects") . '</a></td><td align="right">' . round($third['prospect']) . '</td>';
149
                $statstring .= "</tr>";
150
            }
151
            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
152
                $statstring .= "<tr>";
153
                //$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td align="right">'.round($third['customer']).'</td>';
154
                $statstring .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&type=c">' . $langs->trans("Customers") . '</a></td><td align="right">' . round($third['customer']) . '</td>';
155
                $statstring .= "</tr>";
156
            }
157
            if (!empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire) {
158
                $statstring2 = "<tr>";
159
                //$statstring2.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td align="right">'.round($third['supplier']).'</td>';
160
                $statstring2 .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&typef">' . $langs->trans("Suppliers") . '</a></td><td align="right">' . round($third['supplier']) . '</td>';
161
                $statstring2 .= "</tr>";
162
            }
163
            print $statstring;
164
            print $statstring2;
165
        }
166
        print '<tr class="liste_total"><td>' . $langs->trans("UniqueThirdParties") . '</td><td align="right">';
167
        print $total;
168
        print '</td></tr>';
169
        print '</table>';
170
        print '</div>';
171
172
        if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
173
            require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
174
            $elementtype = 'societe';
175
176
            print '<br>';
177
178
            print '<div class="div-table-responsive-no-min">';
179
            print '<table class="noborder nohover" width="100%">';
180
            print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Categories") . '</th></tr>';
181
            print '<tr ' . $bc[0] . '><td align="center" colspan="2">';
182
            $sql = "SELECT c.label, count(*) as nb";
183
            $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_societe as cs";
184
            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "categorie as c ON cs.fk_categorie = c.rowid";
185
            $sql .= " WHERE c.type = 2";
186
            if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '" . $db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES) . "'";
187
            $sql .= " AND c.entity IN (" . getEntity('category') . ")";
188
            $sql .= " GROUP BY c.label";
189
            $total = 0;
190
            $result = $db->query($sql);
191
            if ($result) {
192
                $num = $db->num_rows($result);
193
                $i = 0;
194
                if (!empty($conf->use_javascript_ajax)) {
195
                    $dataseries = array();
196
                    $rest = 0;
197
                    $nbmax = 10;
198
199
                    while ($i < $num) {
200
                        $obj = $db->fetch_object($result);
201
                        if ($i < $nbmax) {
202
                            $dataseries[] = array($obj->label, round($obj->nb));
203
                        } else {
204
                            $rest += $obj->nb;
205
                        }
206
                        $total += $obj->nb;
207
                        $i++;
208
                    }
209
                    if ($i > $nbmax) {
210
                        $dataseries[] = array($langs->trans("Other"), round($rest));
211
                    }
212
                    include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
213
                    $dolgraph = new DolGraph();
214
                    $dolgraph->SetData($dataseries);
215
                    $dolgraph->setShowLegend(1);
216
                    $dolgraph->setShowPercent(1);
217
                    $dolgraph->SetType(array('pie'));
218
                    $dolgraph->setWidth('100%');
219
                    $dolgraph->draw('idgraphcateg');
220
                    print $dolgraph->show();
221
                } else {
222
                    while ($i < $num) {
223
                        $obj = $db->fetch_object($result);
224
225
                        print '<tr class="oddeven"><td>' . $obj->label . '</td><td>' . $obj->nb . '</td></tr>';
226
                        $total += $obj->nb;
227
                        $i++;
228
                    }
229
                }
230
            }
231
            print '</td></tr>';
232
            print '<tr class="liste_total"><td>' . $langs->trans("Total") . '</td><td align="right">';
233
            print $total;
234
            print '</td></tr>';
235
            print '</table>';
236
            print '</div>';
237
        }
238
239
//print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
240
        print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
241
242
243
        /*
244
         * Last third parties modified
245
         */
246
        $max = 15;
247
        $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
248
        $sql .= ", s.code_client";
249
        $sql .= ", s.code_fournisseur";
250
        $sql .= ", s.logo";
251
        $sql .= ", s.canvas, s.tms as datem, s.status as status";
252
        $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
253
        if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
254
        $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')';
255
        if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
256
        if ($socid) $sql .= " AND s.rowid = " . $socid;
257
        if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
258
        $sql .= $db->order("s.tms", "DESC");
259
        $sql .= $db->plimit($max, 0);
260
261
//print $sql;
262
        $result = $db->query($sql);
263
        if ($result) {
264
            $num = $db->num_rows($result);
265
266
            $i = 0;
267
268
            if ($num > 0) {
269
                $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
270
271
                print "\n<!-- last thirdparties modified -->\n";
272
                print '<div class="div-table-responsive-no-min">';
273
                print '<table class="noborder" width="100%">';
274
275
                print '<tr class="liste_titre"><th colspan="2">' . $transRecordedType . '</th>';
276
                print '<th>&nbsp;</th>';
277
                //print '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
278
                print '<th class="right"><a href="' . BASE_URI . '?controller=societe&method=list&sortfield=s.tms&sortorder=DESC">' . $langs->trans("FullList") . '</th>';
279
                print '</tr>' . "\n";
280
281
                while ($i < $num) {
282
                    $objp = $db->fetch_object($result);
283
284
                    $thirdparty_static->id = $objp->rowid;
285
                    $thirdparty_static->name = $objp->name;
286
                    $thirdparty_static->client = $objp->client;
287
                    $thirdparty_static->fournisseur = $objp->fournisseur;
288
                    $thirdparty_static->logo = $objp->logo;
289
                    $thirdparty_static->datem = $db->jdate($objp->datem);
290
                    $thirdparty_static->status = $objp->status;
291
                    $thirdparty_static->code_client = $objp->code_client;
292
                    $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
293
                    $thirdparty_static->canvas = $objp->canvas;
294
                    $thirdparty_static->email = $objp->email;
295
296
                    print '<tr class="oddeven">';
297
                    // Name
298
                    print '<td class="nowrap">';
299
                    print $thirdparty_static->getNomUrl(1);
300
                    print "</td>\n";
301
                    // Type
302
                    print '<td align="center">';
303
                    if ($thirdparty_static->client == 1 || $thirdparty_static->client == 3) {
304
                        $thirdparty_static->name = $langs->trans("Customer");
305
                        print $thirdparty_static->getNomUrl(0, 'customer', 0, 1);
306
                    }
307
                    if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print " / ";
308
                    if (($thirdparty_static->client == 2 || $thirdparty_static->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
309
                        $thirdparty_static->name = $langs->trans("Prospect");
310
                        print $thirdparty_static->getNomUrl(0, 'prospect', 0, 1);
311
                    }
312
                    if (!empty($conf->fournisseur->enabled) && $thirdparty_static->fournisseur) {
313
                        if ($thirdparty_static->client) print " / ";
314
                        $thirdparty_static->name = $langs->trans("Supplier");
315
                        print $thirdparty_static->getNomUrl(0, 'supplier', 0, 1);
316
                    }
317
                    print '</td>';
318
                    // Last modified date
319
                    print '<td align="right">';
320
                    print dol_print_date($thirdparty_static->datem, 'day');
321
                    print "</td>";
322
                    print '<td align="right" class="nowrap">';
323
                    print $thirdparty_static->getLibStatut(3);
324
                    print "</td>";
325
                    print "</tr>\n";
326
                    $i++;
327
                }
328
329
                $db->free($result);
330
331
                print "</table>\n";
332
                print '</div>';
333
                print "<!-- End last thirdparties modified -->\n";
334
            }
335
        } else {
336
            dol_print_error($db);
337
        }
338
339
//print '</td></tr></table>';
340
        print '</div></div></div>';
341
342
// End of page
343
        llxFooter();
344
        $db->close();
345
    }
346
}