dolibarr 25.0.0-alpha
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';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32
41// Load translation files required by the page
42$langs->load("propal");
43
44if ($user->socid > 0) {
45 $socid = $user->socid;
46}
47
48// Security check
49$socid = GETPOSTINT('socid');
50if ($user->socid) {
51 $action = '';
52 $socid = $user->socid;
53}
54$result = restrictedArea($user, 'propal', $socid, '');
55
56
57
58/*
59 * View
60 */
61
62$companystatic = new Societe($db);
63
64llxHeader();
65
66print load_fiche_titre($langs->trans("ProspectionArea"));
67
68//print '<table border="0" width="100%" class="notopnoleftnoright">';
69//print '<tr><td valign="top" width="30%" class="notopnoleft">';
70print '<div class="fichecenter"><div class="fichethirdleft">';
71
72
73if (isModEnabled("propal")) {
74 $var = false;
75 print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
76 print '<input type="hidden" name="token" value="'.newToken().'">';
77 print '<table class="noborder nohover centpercent">';
78 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
79 print '<tr class="oddeven"><td>';
80 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>';
81 print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
82 print '</tr>';
83 print "</table></form><br>\n";
84}
85
86/*
87 * Prospects par statut
88 */
89
90$sql = "SELECT count(*) as cc, st.libelle as stcomm, st.picto, st.id";
91$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
93$sql .= " WHERE s.fk_stcomm = st.id";
94$sql .= " AND s.client IN (2, 3)";
95$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
96// If the internal user must only see his customers, force searching by him
97$search_sale = 0;
98if (!$user->hasRight('societe', 'client', 'voir')) {
99 $search_sale = $user->id;
100}
101// Search on sale representative
102if ($search_sale && $search_sale != '-1') {
103 if ($search_sale == -2) {
104 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', 0, 1);
105 } elseif ($search_sale > 0) {
106 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', (int) $search_sale);
107 }
108}
109// Search on socid
110if ($socid) {
111 $sql .= " AND s.rowid = ".((int) $socid);
112}
113$sql .= " GROUP BY st.id";
114$sql .= " ORDER BY st.id";
115
116$resql = $db->query($sql);
117if ($resql) {
118 $num = $db->num_rows($resql);
119 $i = 0;
120 if ($num > 0) {
121 print '<table class="noborder centpercent">';
122 print '<tr class="liste_titre">';
123 print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
124 while ($i < $num) {
125 $obj = $db->fetch_object($resql);
126
127 print '<tr class="oddeven"><td>';
128 print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
129 print img_action($langs->trans("Show"), $obj->id, $obj->picto).' ';
130 print $langs->trans("StatusProspect".$obj->id);
131 print '</a></td><td class="right">'.$obj->cc.'</td></tr>';
132 $i++;
133 }
134 print "</table><br>";
135 }
136}
137
138
139/*
140 * Liste des propal brouillons
141 */
142if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
143 $sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
144 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
145 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
146 $sql .= " WHERE p.fk_statut = 0";
147 $sql .= " AND p.fk_soc = s.rowid";
148 $sql .= " AND p.entity IN (".getEntity('propal').")";
149 // If the internal user must only see his customers, force searching by him
150 $search_sale = 0;
151 if (!$user->hasRight('societe', 'client', 'voir')) {
152 $search_sale = $user->id;
153 }
154 // Search on sale representative
155 if ($search_sale && $search_sale != '-1') {
156 if ($search_sale == -2) {
157 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', 0, 1);
158 } elseif ($search_sale > 0) {
159 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', (int) $search_sale);
160 }
161 }
162 // Search on socid
163 if ($socid) {
164 $sql .= " AND s.rowid = ".((int) $socid);
165 }
166
167 $resql = $db->query($sql);
168 if ($resql) {
169 $total = 0;
170 $num = $db->num_rows($resql);
171 $i = 0;
172 if ($num > 0) {
173 print '<table class="noborder"" width="100%">';
174 print '<tr class="liste_titre">';
175 print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
176
177 while ($i < $num) {
178 $obj = $db->fetch_object($resql);
179
180 print '<tr class="oddeven"><td>';
181 print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
182 print '</td><td class="right">';
183 print price($obj->price);
184 print "</td></tr>";
185 $i++;
186 $total += $obj->price;
187 }
188 if ($total > 0) {
189 print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
190 }
191 print "</table><br>";
192 }
193 $db->free($resql);
194 }
195}
196
197
198print '</div><div class="fichetwothirdright">';
199
200
201/*
202 * Actions commerciales a faire
203 */
204if (isModEnabled('agenda')) {
206}
207
208/*
209 * Dernieres propales ouvertes
210 */
211if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
212 $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
213 $sql .= " p.rowid as propalid, p.total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
214 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
215 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
216 $sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
217 $sql .= " WHERE p.fk_soc = s.rowid";
218 $sql .= " AND p.fk_statut = c.id";
219 $sql .= " AND p.fk_statut = 1";
220 $sql .= " AND p.entity IN (".getEntity('propal').")";
221 // If the internal user must only see his customers, force searching by him
222 $search_sale = 0;
223 if (!$user->hasRight('societe', 'client', 'voir')) {
224 $search_sale = $user->id;
225 }
226 // Search on sale representative
227 if ($search_sale && $search_sale != '-1') {
228 if ($search_sale == -2) {
229 $sql .= " AND ".getSalesRepresentativeSqlFilter('p.fk_soc', 0, 1);
230 } elseif ($search_sale > 0) {
231 $sql .= " AND ".getSalesRepresentativeSqlFilter('p.fk_soc', (int) $search_sale);
232 }
233 }
234 // Search on socid
235 if ($socid) {
236 $sql .= " AND p.fk_soc = ".((int) $socid);
237 }
238 $sql .= " ORDER BY p.rowid DESC";
239 $sql .= $db->plimit(5, 0);
240
241 $resql = $db->query($sql);
242 if ($resql) {
243 $total = 0;
244 $num = $db->num_rows($resql);
245 $i = 0;
246 if ($num > 0) {
247 print '<table class="noborder centpercent">';
248 print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
249
250 while ($i < $num) {
251 $obj = $db->fetch_object($resql);
252
253 print '<tr class="oddeven"><td>';
254 print '<a href="../propal.php?id='.$obj->propalid.'">';
255 print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
256
257 print "<td>";
258 $companystatic->id = $obj->socid;
259 $companystatic->name = $obj->name;
260 $companystatic->client = $obj->client;
261 $companystatic->canvas = $obj->canvas;
262 print $companystatic->getNomUrl(1, '', 44);
263 print "</td>\n";
264 print "<td align=\"right\">";
265 print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
266 print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
267 $i++;
268 $total += $obj->price;
269 }
270 if ($total > 0) {
271 print '<tr class="liste_total"><td colspan="3" class="right">'.$langs->trans("Total")."</td><td class=\"right\">".price($total)."</td></tr>";
272 }
273 print "</table><br>";
274 }
275 } else {
277 }
278}
279
280/*
281 * Companies to contact
282 */
283$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
284$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
285$sql .= " WHERE s.fk_stcomm = 1";
286$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
287// If the internal user must only see his customers, force searching by him
288$search_sale = 0;
289if (!$user->hasRight('societe', 'client', 'voir')) {
290 $search_sale = $user->id;
291}
292// Search on sale representative
293if ($search_sale && $search_sale != '-1') {
294 if ($search_sale == -2) {
295 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', 0, 1);
296 } elseif ($search_sale > 0) {
297 $sql .= " AND ".getSalesRepresentativeSqlFilter('s.rowid', (int) $search_sale);
298 }
299}
300// Search on socid
301if ($socid) {
302 $sql .= " AND s.rowid = ".((int) $socid);
303}
304$sql .= " ORDER BY s.tms ASC";
305$sql .= $db->plimit(15, 0);
306
307$resql = $db->query($sql);
308if ($resql) {
309 $num = $db->num_rows($resql);
310 $i = 0;
311 if ($num > 0) {
312 print '<table class="noborder centpercent">';
313 print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
314
315 while ($i < $num) {
316 $obj = $db->fetch_object($resql);
317
318 print '<tr class="oddeven"><td width="12%">';
319 $companystatic->id = $obj->socid;
320 $companystatic->name = $obj->name;
321 $companystatic->client = $obj->client;
322 $companystatic->canvas = $obj->canvas;
323 print $companystatic->getNomUrl(1, 'prospect', 44);
324 print '</td></tr>';
325 $i++;
326 }
327 print "</table><br>";
328 }
329}
330
331
332print '</div></div>';
333
334// End of page
335llxFooter();
336$db->close();
show_array_actions_to_do($max=5)
Show actions to do array.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.