dolibarr 24.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
7 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
41
42
43// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
44$hookmanager->initHooks(array('proposalindex'));
45
46// Load translation files required by the page
47$langs->loadLangs(array('propal', 'companies'));
48
49$now = dol_now();
50$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
51
52// Security check
53$socid = GETPOSTINT('socid');
54if (!empty($user->socid) && $user->socid > 0) {
55 $action = '';
56 $socid = $user->socid;
57}
58
59restrictedArea($user, 'propal');
60
61
62/*
63 * View
64 */
65
66$propalstatic = new Propal($db);
67$companystatic = new Societe($db);
68$form = new Form($db);
69$formfile = new FormFile($db);
70$help_url = "EN:Module_Commercial_Proposals|FR:Module_Propositions_commerciales|ES:Módulo_Presupuestos";
71
72llxHeader("", $langs->trans("ProspectionArea"), $help_url);
73
74print load_fiche_titre($langs->trans("ProspectionArea"), '', 'propal');
75
76print '<div class="fichecenter">';
77print '<div class="fichethirdleft">';
78
79$tmp = getCustomerProposalPieChart($socid);
80if ($tmp) {
81 print $tmp;
82 print '<br>';
83}
84
85/*
86 * Draft proposals
87 */
88if (isModEnabled("propal")) {
89 $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc,";
90 $sql .= " s.rowid as socid, s.nom as name, s.client, s.canvas, s.code_client, s.code_fournisseur, s.email, s.entity, s.code_compta as code_compta_client";
91 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
92 $sql .= " ".MAIN_DB_PREFIX."societe as s";
93 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
94 $sql .= " AND p.fk_soc = s.rowid";
95 $sql .= " AND p.fk_statut =".Propal::STATUS_DRAFT;
96 // If the internal user must only see his customers, force searching by him
97 $search_sale = 0;
98 if (!$user->hasRight('societe', 'client', 'voir')) {
99 $search_sale = $user->id;
100 }
101 // Search on sale representative
102 if ($search_sale && $search_sale != '-1') {
103 if ($search_sale == -2) {
104 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
105 } elseif ($search_sale > 0) {
106 $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).")";
107 }
108 }
109 // Search on socid
110 if ($socid) {
111 $sql .= " AND p.fk_soc = ".((int) $socid);
112 }
113 // Add where from hooks
114 $parameters = array('socid' => $user->socid);
115 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
116 $sql .= $hookmanager->resPrint;
117 $resql = $db->query($sql);
118 if ($resql) {
119 $num = $db->num_rows($resql);
120 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
121 startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
122
123 $total = 0;
124 if ($num) {
125 $i = 0;
126
127 while ($i < $nbofloop) {
128 $obj = $db->fetch_object($resql);
129
130 $propalstatic->id = $obj->rowid;
131 $propalstatic->ref = $obj->ref;
132 $propalstatic->ref_client = $obj->ref_client;
133 $propalstatic->ref_customer = $obj->ref_client;
134 $propalstatic->total_ht = $obj->total_ht;
135 $propalstatic->total_tva = $obj->total_tva;
136 $propalstatic->total_ttc = $obj->total_ttc;
137
138 $companystatic->id = $obj->socid;
139 $companystatic->name = $obj->name;
140 $companystatic->client = $obj->client;
141 $companystatic->code_client = $obj->code_client;
142 $companystatic->code_fournisseur = $obj->code_fournisseur;
143 $companystatic->canvas = $obj->canvas;
144 $companystatic->entity = $obj->entity;
145 $companystatic->email = $obj->email;
146 $companystatic->code_compta = $obj->code_compta_client;
147 $companystatic->code_compta_client = $obj->code_compta_client;
148
149 print '<tr class="oddeven">';
150 print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
151 print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
152 print '<td class="nowrap right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
153 print '</tr>';
154
155 $i++;
156 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
157 }
158 }
159
160 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
161 finishSimpleTable(true);
162 $db->free($resql);
163 } else {
165 }
166}
167
168print '</div>';
169
170print '<div class="fichetwothirdright">';
171
172/*
173 * Last modified proposals
174 */
175
176$sql = "SELECT p.rowid, p.entity, p.ref, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status, date_cloture as datec, p.tms as datem,";
177$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client";
178$sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
179$sql .= " ".MAIN_DB_PREFIX."societe as s";
180$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
181$sql .= " AND p.fk_soc = s.rowid";
182// If the internal user must only see his customers, force searching by him
183$search_sale = 0;
184if (!$user->hasRight('societe', 'client', 'voir')) {
185 $search_sale = $user->id;
186}
187// Search on sale representative
188if ($search_sale && $search_sale != '-1') {
189 if ($search_sale == -2) {
190 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
191 } elseif ($search_sale > 0) {
192 $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).")";
193 }
194}
195// Search on socid
196if ($socid) {
197 $sql .= " AND p.fk_soc = ".((int) $socid);
198}
199// Add where from hooks
200$parameters = array('socid' => $user->socid);
201$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
202$sql .= $hookmanager->resPrint;
203$sql .= " ORDER BY p.tms DESC";
204
205$sql .= $db->plimit($max, 0);
206
207$resql = $db->query($sql);
208if ($resql) {
209 $num = $db->num_rows($resql);
210
211 startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
212
213 if ($num) {
214 $i = 0;
215 while ($i < $num) {
216 $obj = $db->fetch_object($resql);
217
218 $propalstatic->id = $obj->rowid;
219 $propalstatic->ref = $obj->ref;
220 $propalstatic->total_ht = $obj->total_ht;
221 $propalstatic->total_tva = $obj->total_tva;
222 $propalstatic->total_ttc = $obj->total_ttc;
223
224 $companystatic->id = $obj->socid;
225 $companystatic->name = $obj->socname;
226 $companystatic->client = $obj->client;
227 $companystatic->canvas = $obj->canvas;
228 $companystatic->email = $obj->email;
229 $companystatic->code_compta = $obj->code_compta_client;
230 $companystatic->code_compta_client = $obj->code_compta_client;
231
232 $filename = dol_sanitizeFileName($obj->ref);
233 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
234 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
235
236 print '<tr class="oddeven">';
237
238 print '<td class="nowrap">';
239 print '<table class="nobordernopadding">';
240 print '<tr class="nocellnopadd">';
241 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
242 print '<td width="16" class="nobordernopadding nowrap"></td>';
243 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
244 print '</tr>';
245 print '</table>';
246 print '</td>';
247
248 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
249
250 $datem = $db->jdate($obj->datem);
251 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
252 print dol_print_date($datem, 'day', 'tzuserrel');
253 print '</td>';
254
255 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
256
257 print '</tr>';
258
259 $i++;
260 }
261 }
262
263 finishSimpleTable(true);
264 $db->free($resql);
265} else {
267}
268
269
270/*
271 * Open (validated) proposals
272 */
273if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
274 $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client,";
275 $sql .= " p.rowid as propalid, p.entity, p.total_ttc, p.total_ht, p.total_tva, p.ref, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
276 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
277 $sql .= " ".MAIN_DB_PREFIX."propal as p";
278 $sql .= " WHERE p.fk_soc = s.rowid";
279 $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
280 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
281 // If the internal user must only see his customers, force searching by him
282 $search_sale = 0;
283 if (!$user->hasRight('societe', 'client', 'voir')) {
284 $search_sale = $user->id;
285 }
286 // Search on sale representative
287 if ($search_sale && $search_sale != '-1') {
288 if ($search_sale == -2) {
289 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
290 } elseif ($search_sale > 0) {
291 $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).")";
292 }
293 }
294 // Search on socid
295 if ($socid) {
296 $sql .= " AND p.fk_soc = ".((int) $socid);
297 }
298 // Add where from hooks
299 $parameters = array('socid' => $user->socid);
300 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
301 $sql .= $hookmanager->resPrint;
302 $sql .= " ORDER BY p.rowid DESC";
303
304 $resql = $db->query($sql);
305 if ($resql) {
306 $total = 0;
307 $num = $db->num_rows($resql);
308 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
309 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
310
311 if ($num > 0) {
312 $i = 0;
313 while ($i < $nbofloop) {
314 $obj = $db->fetch_object($resql);
315
316 $propalstatic->id = $obj->propalid;
317 $propalstatic->ref = $obj->ref;
318 $propalstatic->total_ht = $obj->total_ht;
319 $propalstatic->total_tva = $obj->total_tva;
320 $propalstatic->total_ttc = $obj->total_ttc;
321
322 $companystatic->id = $obj->socid;
323 $companystatic->name = $obj->socname;
324 $companystatic->client = $obj->client;
325 $companystatic->canvas = $obj->canvas;
326 $companystatic->email = $obj->email;
327 $companystatic->code_compta = $obj->code_compta_client;
328 $companystatic->code_compta_client = $obj->code_compta_client;
329
330 $filename = dol_sanitizeFileName($obj->ref);
331 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
332 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
333
334 $warning = ($db->jdate($obj->dfv) < ($now - getWarningDelay('propal', 'cloture'))) ? img_warning($langs->trans("Late")) : '';
335
336 print '<tr class="oddeven">';
337
338 // Ref
339 print '<td class="nowrap" width="140">';
340 print '<table class="nobordernopadding">';
341 print '<tr class="nocellnopadd">';
342 print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
343 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
344 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
345 print '</tr>';
346 print '</table>';
347 print '</td>';
348
349 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
350 print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
351 print '<td class="right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
352 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
353
354 print '</tr>';
355
356 $i++;
357 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
358 }
359 }
360
361 addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
362 finishSimpleTable(true);
363 $db->free($resql);
364 } else {
366 }
367}
368
369print '</div>';
370print '</div>';
371
372$parameters = array('user' => $user);
373$reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
374
375// End of page
376llxFooter();
377$db->close();
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 offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage proposals.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getWarningDelay($module, $parmlevel1, $parmlevel2='')
Return a warning delay You can use it like this: if (getWarningDelay('module', 'paramlevel1')) It rep...
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
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.