dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
31
40// Load translation files required by the page
41$langs->load("propal");
42
43if ($user->socid > 0) {
44 $socid = $user->socid;
45}
46
47// Security check
48$socid = GETPOSTINT('socid');
49if ($user->socid) {
50 $action = '';
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'propal', $socid, '');
54
55
56
57/*
58 * View
59 */
60
61$companystatic = new Societe($db);
62
63llxHeader();
64
65print load_fiche_titre($langs->trans("ProspectionArea"));
66
67//print '<table border="0" width="100%" class="notopnoleftnoright">';
68//print '<tr><td valign="top" width="30%" class="notopnoleft">';
69print '<div class="fichecenter"><div class="fichethirdleft">';
70
71
72if (isModEnabled("propal")) {
73 $var = false;
74 print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
75 print '<input type="hidden" name="token" value="'.newToken().'">';
76 print '<table class="noborder nohover centpercent">';
77 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
78 print '<tr class="oddeven"><td>';
79 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>';
80 print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
81 print '</tr>';
82 print "</table></form><br>\n";
83}
84
85/*
86 * Prospects par statut
87 */
88
89$sql = "SELECT count(*) as cc, st.libelle as stcomm, st.picto, st.id";
90$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
91$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
92$sql .= " WHERE s.fk_stcomm = st.id";
93$sql .= " AND s.client IN (2, 3)";
94$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
95// If the internal user must only see his customers, force searching by him
96$search_sale = 0;
97if (!$user->hasRight('societe', 'client', 'voir')) {
98 $search_sale = $user->id;
99}
100// Search on sale representative
101if ($search_sale && $search_sale != '-1') {
102 if ($search_sale == -2) {
103 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
104 } elseif ($search_sale > 0) {
105 $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).")";
106 }
107}
108// Search on socid
109if ($socid) {
110 $sql .= " AND s.rowid = ".((int) $socid);
111}
112$sql .= " GROUP BY st.id";
113$sql .= " ORDER BY st.id";
114
115$resql = $db->query($sql);
116if ($resql) {
117 $num = $db->num_rows($resql);
118 $i = 0;
119 if ($num > 0) {
120 print '<table class="noborder centpercent">';
121 print '<tr class="liste_titre">';
122 print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
123 while ($i < $num) {
124 $obj = $db->fetch_object($resql);
125
126 print '<tr class="oddeven"><td>';
127 print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
128 print img_action($langs->trans("Show"), $obj->id, $obj->picto).' ';
129 print $langs->trans("StatusProspect".$obj->id);
130 print '</a></td><td class="right">'.$obj->cc.'</td></tr>';
131 $i++;
132 }
133 print "</table><br>";
134 }
135}
136
137
138/*
139 * Liste des propal brouillons
140 */
141if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
142 $sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
143 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
144 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
145 $sql .= " WHERE p.fk_statut = 0";
146 $sql .= " AND p.fk_soc = s.rowid";
147 $sql .= " AND p.entity IN (".getEntity('propal').")";
148 // If the internal user must only see his customers, force searching by him
149 $search_sale = 0;
150 if (!$user->hasRight('societe', 'client', 'voir')) {
151 $search_sale = $user->id;
152 }
153 // Search on sale representative
154 if ($search_sale && $search_sale != '-1') {
155 if ($search_sale == -2) {
156 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
157 } elseif ($search_sale > 0) {
158 $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).")";
159 }
160 }
161 // Search on socid
162 if ($socid) {
163 $sql .= " AND s.rowid = ".((int) $socid);
164 }
165
166 $resql = $db->query($sql);
167 if ($resql) {
168 $total = 0;
169 $num = $db->num_rows($resql);
170 $i = 0;
171 if ($num > 0) {
172 print '<table class="noborder"" width="100%">';
173 print '<tr class="liste_titre">';
174 print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
175
176 while ($i < $num) {
177 $obj = $db->fetch_object($resql);
178
179 print '<tr class="oddeven"><td>';
180 print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
181 print '</td><td class="right">';
182 print price($obj->price);
183 print "</td></tr>";
184 $i++;
185 $total += $obj->price;
186 }
187 if ($total > 0) {
188 print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
189 }
190 print "</table><br>";
191 }
192 $db->free($resql);
193 }
194}
195
196
197print '</div><div class="fichetwothirdright">';
198
199
200/*
201 * Actions commerciales a faire
202 */
203if (isModEnabled('agenda')) {
205}
206
207/*
208 * Dernieres propales ouvertes
209 */
210if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
211 $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
212 $sql .= " p.rowid as propalid, p.total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
213 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
214 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
215 $sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
216 $sql .= " WHERE p.fk_soc = s.rowid";
217 $sql .= " AND p.fk_statut = c.id";
218 $sql .= " AND p.fk_statut = 1";
219 $sql .= " AND p.entity IN (".getEntity('propal').")";
220 // If the internal user must only see his customers, force searching by him
221 $search_sale = 0;
222 if (!$user->hasRight('societe', 'client', 'voir')) {
223 $search_sale = $user->id;
224 }
225 // Search on sale representative
226 if ($search_sale && $search_sale != '-1') {
227 if ($search_sale == -2) {
228 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
229 } elseif ($search_sale > 0) {
230 $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).")";
231 }
232 }
233 // Search on socid
234 if ($socid) {
235 $sql .= " AND p.fk_soc = ".((int) $socid);
236 }
237 $sql .= " ORDER BY p.rowid DESC";
238 $sql .= $db->plimit(5, 0);
239
240 $resql = $db->query($sql);
241 if ($resql) {
242 $total = 0;
243 $num = $db->num_rows($resql);
244 $i = 0;
245 if ($num > 0) {
246 print '<table class="noborder centpercent">';
247 print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
248
249 while ($i < $num) {
250 $obj = $db->fetch_object($resql);
251
252 print '<tr class="oddeven"><td>';
253 print '<a href="../propal.php?id='.$obj->propalid.'">';
254 print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
255
256 print "<td>";
257 $companystatic->id = $obj->socid;
258 $companystatic->name = $obj->name;
259 $companystatic->client = $obj->client;
260 $companystatic->canvas = $obj->canvas;
261 print $companystatic->getNomUrl(1, '', 44);
262 print "</td>\n";
263 print "<td align=\"right\">";
264 print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
265 print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
266 $i++;
267 $total += $obj->price;
268 }
269 if ($total > 0) {
270 print '<tr class="liste_total"><td colspan="3" class="right">'.$langs->trans("Total")."</td><td class=\"right\">".price($total)."</td></tr>";
271 }
272 print "</table><br>";
273 }
274 } else {
275 dol_print_error($db);
276 }
277}
278
279/*
280 * Companies to contact
281 */
282$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
283$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
284$sql .= " WHERE s.fk_stcomm = 1";
285$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
286// If the internal user must only see his customers, force searching by him
287$search_sale = 0;
288if (!$user->hasRight('societe', 'client', 'voir')) {
289 $search_sale = $user->id;
290}
291// Search on sale representative
292if ($search_sale && $search_sale != '-1') {
293 if ($search_sale == -2) {
294 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
295 } elseif ($search_sale > 0) {
296 $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).")";
297 }
298}
299// Search on socid
300if ($socid) {
301 $sql .= " AND s.rowid = ".((int) $socid);
302}
303$sql .= " ORDER BY s.tms ASC";
304$sql .= $db->plimit(15, 0);
305
306$resql = $db->query($sql);
307if ($resql) {
308 $num = $db->num_rows($resql);
309 $i = 0;
310 if ($num > 0) {
311 print '<table class="noborder centpercent">';
312 print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
313
314 while ($i < $num) {
315 $obj = $db->fetch_object($resql);
316
317 print '<tr class="oddeven"><td width="12%">';
318 $companystatic->id = $obj->socid;
319 $companystatic->name = $obj->name;
320 $companystatic->client = $obj->client;
321 $companystatic->canvas = $obj->canvas;
322 print $companystatic->getNomUrl(1, 'prospect', 44);
323 print '</td></tr>';
324 $i++;
325 }
326 print "</table><br>";
327 }
328}
329
330
331print '</div></div>';
332
333// End of page
334llxFooter();
335$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooter()
Footer empty.
Definition document.php:107
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.