dolibarr 20.0.0
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
30
31// Load translation files required by the page
32$langs->load("propal");
33
34if ($user->socid > 0) {
35 $socid = $user->socid;
36}
37
38// Security check
39$socid = GETPOSTINT('socid');
40if ($user->socid) {
41 $action = '';
42 $socid = $user->socid;
43}
44$result = restrictedArea($user, 'propal', $socid, '');
45
46
47
48/*
49 * View
50 */
51
52$companystatic = new Societe($db);
53
54llxHeader();
55
56print load_fiche_titre($langs->trans("ProspectionArea"));
57
58//print '<table border="0" width="100%" class="notopnoleftnoright">';
59//print '<tr><td valign="top" width="30%" class="notopnoleft">';
60print '<div class="fichecenter"><div class="fichethirdleft">';
61
62
63if (isModEnabled("propal")) {
64 $var = false;
65 print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
66 print '<input type="hidden" name="token" value="'.newToken().'">';
67 print '<table class="noborder nohover centpercent">';
68 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
69 print '<tr class="oddeven"><td>';
70 print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
71 print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
72 print '</tr>';
73 print "</table></form><br>\n";
74}
75
76/*
77 * Prospects par statut
78 */
79
80$sql = "SELECT count(*) as cc, st.libelle as stcomm, st.picto, st.id";
81$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
82$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
83$sql .= " WHERE s.fk_stcomm = st.id";
84$sql .= " AND s.client IN (2, 3)";
85$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
86// If the internal user must only see his customers, force searching by him
87$search_sale = 0;
88if (!$user->hasRight('societe', 'client', 'voir')) {
89 $search_sale = $user->id;
90}
91// Search on sale representative
92if ($search_sale && $search_sale != '-1') {
93 if ($search_sale == -2) {
94 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
95 } elseif ($search_sale > 0) {
96 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid AND sc.fk_user = ".((int) $search_sale).")";
97 }
98}
99// Search on socid
100if ($socid) {
101 $sql .= " AND s.rowid = ".((int) $socid);
102}
103$sql .= " GROUP BY st.id";
104$sql .= " ORDER BY st.id";
105
106$resql = $db->query($sql);
107if ($resql) {
108 $num = $db->num_rows($resql);
109 $i = 0;
110 if ($num > 0) {
111 print '<table class="noborder centpercent">';
112 print '<tr class="liste_titre">';
113 print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
114 while ($i < $num) {
115 $obj = $db->fetch_object($resql);
116
117 print '<tr class="oddeven"><td>';
118 print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
119 print img_action($langs->trans("Show"), $obj->id, $obj->picto).' ';
120 print $langs->trans("StatusProspect".$obj->id);
121 print '</a></td><td class="right">'.$obj->cc.'</td></tr>';
122 $i++;
123 }
124 print "</table><br>";
125 }
126}
127
128
129/*
130 * Liste des propal brouillons
131 */
132if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
133 $sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
134 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
135 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
136 $sql .= " WHERE p.fk_statut = 0";
137 $sql .= " AND p.fk_soc = s.rowid";
138 $sql .= " AND p.entity IN (".getEntity('propal').")";
139 // If the internal user must only see his customers, force searching by him
140 $search_sale = 0;
141 if (!$user->hasRight('societe', 'client', 'voir')) {
142 $search_sale = $user->id;
143 }
144 // Search on sale representative
145 if ($search_sale && $search_sale != '-1') {
146 if ($search_sale == -2) {
147 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
148 } elseif ($search_sale > 0) {
149 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid AND sc.fk_user = ".((int) $search_sale).")";
150 }
151 }
152 // Search on socid
153 if ($socid) {
154 $sql .= " AND s.rowid = ".((int) $socid);
155 }
156
157 $resql = $db->query($sql);
158 if ($resql) {
159 $total = 0;
160 $num = $db->num_rows($resql);
161 $i = 0;
162 if ($num > 0) {
163 print '<table class="noborder"" width="100%">';
164 print '<tr class="liste_titre">';
165 print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
166
167 while ($i < $num) {
168 $obj = $db->fetch_object($resql);
169
170 print '<tr class="oddeven"><td>';
171 print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
172 print '</td><td class="right">';
173 print price($obj->price);
174 print "</td></tr>";
175 $i++;
176 $total += $obj->price;
177 }
178 if ($total > 0) {
179 print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
180 }
181 print "</table><br>";
182 }
183 $db->free($resql);
184 }
185}
186
187
188print '</div><div class="fichetwothirdright">';
189
190
191/*
192 * Actions commerciales a faire
193 */
194if (isModEnabled('agenda')) {
196}
197
198/*
199 * Dernieres propales ouvertes
200 */
201if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
202 $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
203 $sql .= " p.rowid as propalid, p.total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
204 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
205 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
206 $sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
207 $sql .= " WHERE p.fk_soc = s.rowid";
208 $sql .= " AND p.fk_statut = c.id";
209 $sql .= " AND p.fk_statut = 1";
210 $sql .= " AND p.entity IN (".getEntity('propal').")";
211 // If the internal user must only see his customers, force searching by him
212 $search_sale = 0;
213 if (!$user->hasRight('societe', 'client', 'voir')) {
214 $search_sale = $user->id;
215 }
216 // Search on sale representative
217 if ($search_sale && $search_sale != '-1') {
218 if ($search_sale == -2) {
219 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
220 } elseif ($search_sale > 0) {
221 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
222 }
223 }
224 // Search on socid
225 if ($socid) {
226 $sql .= " AND p.fk_soc = ".((int) $socid);
227 }
228 $sql .= " ORDER BY p.rowid DESC";
229 $sql .= $db->plimit(5, 0);
230
231 $resql = $db->query($sql);
232 if ($resql) {
233 $total = 0;
234 $num = $db->num_rows($resql);
235 $i = 0;
236 if ($num > 0) {
237 print '<table class="noborder centpercent">';
238 print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
239
240 while ($i < $num) {
241 $obj = $db->fetch_object($resql);
242
243 print '<tr class="oddeven"><td>';
244 print '<a href="../propal.php?id='.$obj->propalid.'">';
245 print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
246
247 print "<td>";
248 $companystatic->id = $obj->socid;
249 $companystatic->name = $obj->name;
250 $companystatic->client = $obj->client;
251 $companystatic->canvas = $obj->canvas;
252 print $companystatic->getNomUrl(1, '', 44);
253 print "</td>\n";
254 print "<td align=\"right\">";
255 print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
256 print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
257 $i++;
258 $total += $obj->price;
259 }
260 if ($total > 0) {
261 print '<tr class="liste_total"><td colspan="3" class="right">'.$langs->trans("Total")."</td><td class=\"right\">".price($total)."</td></tr>";
262 }
263 print "</table><br>";
264 }
265 } else {
266 dol_print_error($db);
267 }
268}
269
270/*
271 * Companies to contact
272 */
273$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
274$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
275$sql .= " WHERE s.fk_stcomm = 1";
276$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
277// If the internal user must only see his customers, force searching by him
278$search_sale = 0;
279if (!$user->hasRight('societe', 'client', 'voir')) {
280 $search_sale = $user->id;
281}
282// Search on sale representative
283if ($search_sale && $search_sale != '-1') {
284 if ($search_sale == -2) {
285 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
286 } elseif ($search_sale > 0) {
287 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid AND sc.fk_user = ".((int) $search_sale).")";
288 }
289}
290// Search on socid
291if ($socid) {
292 $sql .= " AND s.rowid = ".((int) $socid);
293}
294$sql .= " ORDER BY s.tms ASC";
295$sql .= $db->plimit(15, 0);
296
297$resql = $db->query($sql);
298if ($resql) {
299 $num = $db->num_rows($resql);
300 $i = 0;
301 if ($num > 0) {
302 print '<table class="noborder centpercent">';
303 print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
304
305 while ($i < $num) {
306 $obj = $db->fetch_object($resql);
307
308 print '<tr class="oddeven"><td width="12%">';
309 $companystatic->id = $obj->socid;
310 $companystatic->name = $obj->name;
311 $companystatic->client = $obj->client;
312 $companystatic->canvas = $obj->canvas;
313 print $companystatic->getNomUrl(1, 'prospect', 44);
314 print '</td></tr>';
315 $i++;
316 }
317 print "</table><br>";
318 }
319}
320
321
322print '</div></div>';
323
324// End of page
325llxFooter();
326$db->close();
show_array_actions_to_do($max=5)
Show actions to do array.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.