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