dolibarr 21.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 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';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
34
43// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
44$hookmanager = new HookManager($db);
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$max = 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
115 $resql = $db->query($sql);
116 if ($resql) {
117 $num = $db->num_rows($resql);
118 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
119 startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
120
121 $total = 0;
122 if ($num) {
123 $i = 0;
124
125 while ($i < $nbofloop) {
126 $obj = $db->fetch_object($resql);
127
128 $propalstatic->id = $obj->rowid;
129 $propalstatic->ref = $obj->ref;
130 $propalstatic->ref_client = $obj->ref_client;
131 $propalstatic->ref_customer = $obj->ref_client;
132 $propalstatic->total_ht = $obj->total_ht;
133 $propalstatic->total_tva = $obj->total_tva;
134 $propalstatic->total_ttc = $obj->total_ttc;
135
136 $companystatic->id = $obj->socid;
137 $companystatic->name = $obj->name;
138 $companystatic->client = $obj->client;
139 $companystatic->code_client = $obj->code_client;
140 $companystatic->code_fournisseur = $obj->code_fournisseur;
141 $companystatic->canvas = $obj->canvas;
142 $companystatic->entity = $obj->entity;
143 $companystatic->email = $obj->email;
144 $companystatic->code_compta = $obj->code_compta_client;
145 $companystatic->code_compta_client = $obj->code_compta_client;
146
147 print '<tr class="oddeven">';
148 print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
149 print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
150 print '<td class="nowrap right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
151 print '</tr>';
152
153 $i++;
154 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
155 }
156 }
157
158 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
159 finishSimpleTable(true);
160 $db->free($resql);
161 } else {
162 dol_print_error($db);
163 }
164}
165
166print '</div>';
167
168print '<div class="fichetwothirdright">';
169
170/*
171 * Last modified proposals
172 */
173
174$sql = "SELECT c.rowid, c.entity, c.ref, c.total_ht, c.total_tva, c.total_ttc, c.fk_statut as status, date_cloture as datec, c.tms as datem,";
175$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client";
176$sql .= " FROM ".MAIN_DB_PREFIX."propal as c,";
177$sql .= " ".MAIN_DB_PREFIX."societe as s";
178$sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")";
179$sql .= " AND c.fk_soc = s.rowid";
180// If the internal user must only see his customers, force searching by him
181$search_sale = 0;
182if (!$user->hasRight('societe', 'client', 'voir')) {
183 $search_sale = $user->id;
184}
185// Search on sale representative
186if ($search_sale && $search_sale != '-1') {
187 if ($search_sale == -2) {
188 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
189 } elseif ($search_sale > 0) {
190 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
191 }
192}
193// Search on socid
194if ($socid) {
195 $sql .= " AND c.fk_soc = ".((int) $socid);
196}
197$sql .= " ORDER BY c.tms DESC";
198
199$sql .= $db->plimit($max, 0);
200
201$resql = $db->query($sql);
202if ($resql) {
203 $num = $db->num_rows($resql);
204
205 startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
206
207 if ($num) {
208 $i = 0;
209 while ($i < $num) {
210 $obj = $db->fetch_object($resql);
211
212 $propalstatic->id = $obj->rowid;
213 $propalstatic->ref = $obj->ref;
214 $propalstatic->total_ht = $obj->total_ht;
215 $propalstatic->total_tva = $obj->total_tva;
216 $propalstatic->total_ttc = $obj->total_ttc;
217
218 $companystatic->id = $obj->socid;
219 $companystatic->name = $obj->socname;
220 $companystatic->client = $obj->client;
221 $companystatic->canvas = $obj->canvas;
222 $companystatic->email = $obj->email;
223 $companystatic->code_compta = $obj->code_compta_client;
224 $companystatic->code_compta_client = $obj->code_compta_client;
225
226 $filename = dol_sanitizeFileName($obj->ref);
227 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
228 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
229
230 print '<tr class="oddeven">';
231
232 print '<td class="nowrap">';
233 print '<table class="nobordernopadding">';
234 print '<tr class="nocellnopadd">';
235 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
236 print '<td width="16" class="nobordernopadding nowrap"></td>';
237 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
238 print '</tr>';
239 print '</table>';
240 print '</td>';
241
242 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
243
244 $datem = $db->jdate($obj->datem);
245 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
246 print dol_print_date($datem, 'day', 'tzuserrel');
247 print '</td>';
248
249 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
250
251 print '</tr>';
252
253 $i++;
254 }
255 }
256
257 finishSimpleTable(true);
258 $db->free($resql);
259} else {
260 dol_print_error($db);
261}
262
263
264/*
265 * Open (validated) proposals
266 */
267if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
268 $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client,";
269 $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";
270 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,";
271 $sql .= " ".MAIN_DB_PREFIX."propal as p";
272 $sql .= " WHERE p.fk_soc = s.rowid";
273 $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
274 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
275 // If the internal user must only see his customers, force searching by him
276 $search_sale = 0;
277 if (!$user->hasRight('societe', 'client', 'voir')) {
278 $search_sale = $user->id;
279 }
280 // Search on sale representative
281 if ($search_sale && $search_sale != '-1') {
282 if ($search_sale == -2) {
283 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
284 } elseif ($search_sale > 0) {
285 $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).")";
286 }
287 }
288 // Search on socid
289 if ($socid) {
290 $sql .= " AND p.fk_soc = ".((int) $socid);
291 }
292 $sql .= " ORDER BY p.rowid DESC";
293
294 $resql = $db->query($sql);
295 if ($resql) {
296 $total = 0;
297 $num = $db->num_rows($resql);
298 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
299 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
300
301 if ($num > 0) {
302 $i = 0;
303 while ($i < $nbofloop) {
304 $obj = $db->fetch_object($resql);
305
306 $propalstatic->id = $obj->propalid;
307 $propalstatic->ref = $obj->ref;
308 $propalstatic->total_ht = $obj->total_ht;
309 $propalstatic->total_tva = $obj->total_tva;
310 $propalstatic->total_ttc = $obj->total_ttc;
311
312 $companystatic->id = $obj->socid;
313 $companystatic->name = $obj->socname;
314 $companystatic->client = $obj->client;
315 $companystatic->canvas = $obj->canvas;
316 $companystatic->email = $obj->email;
317 $companystatic->code_compta = $obj->code_compta_client;
318 $companystatic->code_compta_client = $obj->code_compta_client;
319
320 $filename = dol_sanitizeFileName($obj->ref);
321 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
322 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
323
324 $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
325
326 print '<tr class="oddeven">';
327
328 // Ref
329 print '<td class="nowrap" width="140">';
330 print '<table class="nobordernopadding">';
331 print '<tr class="nocellnopadd">';
332 print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
333 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
334 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
335 print '</tr>';
336 print '</table>';
337 print '</td>';
338
339 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
340 print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
341 print '<td class="right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
342 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
343
344 print '</tr>';
345
346 $i++;
347 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
348 }
349 }
350
351 addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
352 finishSimpleTable(true);
353 $db->free($resql);
354 } else {
355 dol_print_error($db);
356 }
357}
358
359print '</div>';
360print '</div>';
361
362$parameters = array('user' => $user);
363$reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
364
365// End of page
366llxFooter();
367$db->close();
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 offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage hooks.
Class to manage proposals.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage third parties objects (customers, suppliers, prospects...)
llxFooter()
Footer empty.
Definition document.php:107
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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()"...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.