dolibarr 25.0.0-alpha
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
51$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
52
53// Security check
54$socid = GETPOSTINT('socid');
55if (!empty($user->socid) && $user->socid > 0) {
56 $action = '';
57 $socid = $user->socid;
58}
59
60restrictedArea($user, 'propal');
61
62
63/*
64 * View
65 */
66
67$propalstatic = new Propal($db);
68$companystatic = new Societe($db);
69$form = new Form($db);
70$formfile = new FormFile($db);
71$help_url = "EN:Module_Commercial_Proposals|FR:Module_Propositions_commerciales|ES:Módulo_Presupuestos";
72
73llxHeader("", $langs->trans("ProspectionArea"), $help_url);
74
75print load_fiche_titre($langs->trans("ProspectionArea"), '', 'propal');
76
77print '<div class="fichecenter">';
78print '<div class="fichethirdleft">';
79
80$tmp = getCustomerProposalPieChart($socid);
81if ($tmp) {
82 print $tmp;
83 print '<br>';
84}
85
86/*
87 * Draft proposals
88 */
89if (isModEnabled("propal")) {
90 $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc,";
91 $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";
92 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
93 $sql .= " ".MAIN_DB_PREFIX."societe as s";
94 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
95 $sql .= " AND p.fk_soc = s.rowid";
96 $sql .= " AND p.fk_statut =".Propal::STATUS_DRAFT;
97 // If the internal user must only see his customers, force searching by him
98 $search_sale = 0;
99 if (!$user->hasRight('societe', 'client', 'voir')) {
100 $search_sale = $user->id;
101 }
102 // Search on sale representative
103 if ($search_sale && $search_sale != '-1') {
104 if ($search_sale == -2) {
105 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
106 } elseif ($search_sale > 0) {
107 $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).")";
108 }
109 }
110 // Search on socid
111 if ($socid) {
112 $sql .= " AND p.fk_soc = ".((int) $socid);
113 }
114 // Add where from hooks
115 $parameters = array('socid' => $user->socid);
116 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
117 $sql .= $hookmanager->resPrint;
118 $resql = $db->query($sql);
119 if ($resql) {
120 $num = $db->num_rows($resql);
121 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
122 startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
123
124 $total = 0;
125 if ($num) {
126 $i = 0;
127
128 while ($i < $nbofloop) {
129 $obj = $db->fetch_object($resql);
130
131 $propalstatic->id = $obj->rowid;
132 $propalstatic->ref = $obj->ref;
133 $propalstatic->ref_client = $obj->ref_client;
134 $propalstatic->ref_customer = $obj->ref_client;
135 $propalstatic->total_ht = $obj->total_ht;
136 $propalstatic->total_tva = $obj->total_tva;
137 $propalstatic->total_ttc = $obj->total_ttc;
138
139 $companystatic->id = $obj->socid;
140 $companystatic->name = $obj->name;
141 $companystatic->client = $obj->client;
142 $companystatic->code_client = $obj->code_client;
143 $companystatic->code_fournisseur = $obj->code_fournisseur;
144 $companystatic->canvas = $obj->canvas;
145 $companystatic->entity = $obj->entity;
146 $companystatic->email = $obj->email;
147 $companystatic->code_compta = $obj->code_compta_client;
148 $companystatic->code_compta_client = $obj->code_compta_client;
149
150 print '<tr class="oddeven">';
151 print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
152 print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
153 print '<td class="nowrap right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
154 print '</tr>';
155
156 $i++;
157 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
158 }
159 }
160
161 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
162 finishSimpleTable(true);
163 $db->free($resql);
164 } else {
166 }
167}
168
169print '</div>';
170
171print '<div class="fichetwothirdright">';
172
173/*
174 * Last modified proposals
175 */
176
177$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,";
178$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client";
179$sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
180$sql .= " ".MAIN_DB_PREFIX."societe as s";
181$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
182$sql .= " AND p.fk_soc = s.rowid";
183// If the internal user must only see his customers, force searching by him
184$search_sale = 0;
185if (!$user->hasRight('societe', 'client', 'voir')) {
186 $search_sale = $user->id;
187}
188// Search on sale representative
189if ($search_sale && $search_sale != '-1') {
190 if ($search_sale == -2) {
191 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
192 } elseif ($search_sale > 0) {
193 $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).")";
194 }
195}
196// Search on socid
197if ($socid) {
198 $sql .= " AND p.fk_soc = ".((int) $socid);
199}
200// Add where from hooks
201$parameters = array('socid' => $user->socid);
202$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
203$sql .= $hookmanager->resPrint;
204$sql .= " ORDER BY p.tms DESC";
205
206$sql .= $db->plimit($max, 0);
207
208$resql = $db->query($sql);
209if ($resql) {
210 $num = $db->num_rows($resql);
211
212 startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
213
214 if ($num) {
215 $i = 0;
216 while ($i < $num) {
217 $obj = $db->fetch_object($resql);
218
219 $propalstatic->id = $obj->rowid;
220 $propalstatic->ref = $obj->ref;
221 $propalstatic->total_ht = $obj->total_ht;
222 $propalstatic->total_tva = $obj->total_tva;
223 $propalstatic->total_ttc = $obj->total_ttc;
224
225 $companystatic->id = $obj->socid;
226 $companystatic->name = $obj->socname;
227 $companystatic->client = $obj->client;
228 $companystatic->canvas = $obj->canvas;
229 $companystatic->email = $obj->email;
230 $companystatic->code_compta = $obj->code_compta_client;
231 $companystatic->code_compta_client = $obj->code_compta_client;
232
233 $filename = dol_sanitizeFileName($obj->ref);
234 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
235 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
236
237 print '<tr class="oddeven">';
238
239 print '<td class="nowrap">';
240 print '<table class="nobordernopadding">';
241 print '<tr class="nocellnopadd">';
242 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
243 print '<td width="16" class="nobordernopadding nowrap"></td>';
244 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
245 print '</tr>';
246 print '</table>';
247 print '</td>';
248
249 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
250
251 $datem = $db->jdate($obj->datem);
252 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
253 print dol_print_date($datem, 'day', 'tzuserrel');
254 print '</td>';
255
256 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
257
258 print '</tr>';
259
260 $i++;
261 }
262 }
263
264 finishSimpleTable(true);
265 $db->free($resql);
266} else {
268}
269
270
271/*
272 * Open (validated) proposals
273 */
274if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
275 $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client,";
276 $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";
277 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
278 $sql .= " ".MAIN_DB_PREFIX."propal as p";
279 $sql .= " WHERE p.fk_soc = s.rowid";
280 $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
281 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
282 // If the internal user must only see his customers, force searching by him
283 $search_sale = 0;
284 if (!$user->hasRight('societe', 'client', 'voir')) {
285 $search_sale = $user->id;
286 }
287 // Search on sale representative
288 if ($search_sale && $search_sale != '-1') {
289 if ($search_sale == -2) {
290 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
291 } elseif ($search_sale > 0) {
292 $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).")";
293 }
294 }
295 // Search on socid
296 if ($socid) {
297 $sql .= " AND p.fk_soc = ".((int) $socid);
298 }
299 // Add where from hooks
300 $parameters = array('socid' => $user->socid);
301 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
302 $sql .= $hookmanager->resPrint;
303 $sql .= " ORDER BY p.rowid DESC";
304
305 $resql = $db->query($sql);
306 if ($resql) {
307 $total = 0;
308 $num = $db->num_rows($resql);
309 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
310 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
311
312 if ($num > 0) {
313 $i = 0;
314 while ($i < $nbofloop) {
315 $obj = $db->fetch_object($resql);
316
317 $propalstatic->id = $obj->propalid;
318 $propalstatic->ref = $obj->ref;
319 $propalstatic->total_ht = $obj->total_ht;
320 $propalstatic->total_tva = $obj->total_tva;
321 $propalstatic->total_ttc = $obj->total_ttc;
322
323 $companystatic->id = $obj->socid;
324 $companystatic->name = $obj->socname;
325 $companystatic->client = $obj->client;
326 $companystatic->canvas = $obj->canvas;
327 $companystatic->email = $obj->email;
328 $companystatic->code_compta = $obj->code_compta_client;
329 $companystatic->code_compta_client = $obj->code_compta_client;
330
331 $filename = dol_sanitizeFileName($obj->ref);
332 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
333 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
334
335 $warning = ($db->jdate($obj->dfv) < ($now - getWarningDelay('propal', 'cloture'))) ? img_warning($langs->trans("Late")) : '';
336
337 print '<tr class="oddeven">';
338
339 // Ref
340 print '<td class="nowrap" width="140">';
341 print '<table class="nobordernopadding">';
342 print '<tr class="nocellnopadd">';
343 print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
344 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
345 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
346 print '</tr>';
347 print '</table>';
348 print '</td>';
349
350 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
351 print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
352 print '<td class="right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
353 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
354
355 print '</tr>';
356
357 $i++;
358 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
359 }
360 }
361
362 addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
363 finishSimpleTable(true);
364 $db->free($resql);
365 } else {
367 }
368}
369
370print '</div>';
371print '</div>';
372
373$parameters = array('user' => $user);
374$reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
375
376// End of page
377llxFooter();
378$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.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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.
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).
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.
addSummaryTableLine($tableColumnCount, $num, $nbofloop=0, $total=0, $noneWord="None", $extraRightColumn=false)
Add a summary line to the current open table ("None", "XMoreLines" or "Total xxx")
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...
startSimpleTable($header, $link="", $arguments="", $emptyColumns=0, $number=-1, $pictofulllist='')
Start a table with headers and a optional clickable number (don't forget to use "finishSimpleTable()"...
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.