dolibarr 24.0.0-beta
propal.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
35{
36 global $db, $langs, $conf, $user;
37 $langs->loadLangs(array('propal', 'compta', 'companies'));
38
39 $h = 0;
40 $head = array();
41
42 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/card.php', ['id' => $object->id]);
43 $head[$h][1] = $langs->trans('Proposal');
44 $head[$h][2] = 'comm';
45 $h++;
46
47 if ((!isModEnabled('order') && ((isModEnabled("shipping") && getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'lire'))
48 || (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'lire'))))) {
49 $langs->load("sendings");
50 $text = '';
51 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/expedition/propal.php', ['id' => $object->id]);
52 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION')) {
53 $text = $langs->trans("Shipment");
54 }
55 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
56 $text .= '/';
57 }
58 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
59 $text .= $langs->trans("Receivings");
60 }
61 $head[$h][1] = $text;
62 $head[$h][2] = 'shipping';
63 $h++;
64 }
65
66 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
67 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
68 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/contact.php', ['id' => $object->id]);
69 $head[$h][1] = $langs->trans('ContactsAddresses');
70 if ($nbContact > 0) {
71 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
72 }
73 $head[$h][2] = 'contact';
74 $h++;
75 }
76
77 // Show more tabs from modules
78 // Entries must be declared in modules descriptor with line
79 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
80 // $this->tabs = array('entity:-tabname); to remove a tab
81 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'core');
82
83 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
84 $nbNote = 0;
85 if (!empty($object->note_private)) {
86 $nbNote++;
87 }
88 if (!empty($object->note_public)) {
89 $nbNote++;
90 }
91 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/note.php', ['id' => $object->id]);
92 $head[$h][1] = $langs->trans('Notes');
93 if ($nbNote > 0) {
94 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
95 }
96 $head[$h][2] = 'note';
97 $h++;
98 }
99
100 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
101 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
102 $upload_dir = $conf->propal->multidir_output[$object->entity ?? $conf->entity]."/".dol_sanitizeFileName($object->ref);
103 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
104 $nbLinks = Link::count($db, $object->element, $object->id);
105 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/document.php', ['id' => $object->id]);
106 $head[$h][1] = $langs->trans('Documents');
107 if (($nbFiles + $nbLinks) > 0) {
108 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
109 }
110 $head[$h][2] = 'document';
111 $h++;
112
113
114 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/agenda.php', ['id' => $object->id]);
115 $head[$h][1] = $langs->trans("Events");
116 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
117 $nbEvent = 0;
118 // Enable caching of thirdparty count actioncomm
119 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
120 $cachekey = 'count_events_propal_'.$object->id;
121 $dataretrieved = dol_getcache($cachekey);
122 if (!is_null($dataretrieved)) {
123 $nbEvent = $dataretrieved;
124 } else {
125 $sql = "SELECT COUNT(id) as nb";
126 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
127 $sql .= " WHERE fk_element = ".((int) $object->id);
128 $sql .= " AND elementtype = 'propal'";
129 $resql = $db->query($sql);
130 if ($resql) {
131 $obj = $db->fetch_object($resql);
132 $nbEvent = $obj->nb;
133 } else {
134 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
135 }
136 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
137 }
138
139 $head[$h][1] .= '/';
140 $head[$h][1] .= $langs->trans("Agenda");
141 if ($nbEvent > 0) {
142 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
143 }
144 }
145 $head[$h][2] = 'agenda';
146 $h++;
147
148 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'external');
149
150 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'remove');
151
152 return $head;
153}
154
161{
162 global $langs, $conf, $extrafields;
163
164 $extrafields->fetch_name_optionals_label('propal');
165 $extrafields->fetch_name_optionals_label('propaldet');
166
167 $h = 0;
168 $head = array();
169
170 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/propal.php');
171 $head[$h][1] = $langs->trans("Miscellaneous");
172 $head[$h][2] = 'general';
173 $h++;
174
175 // Show more tabs from modules
176 // Entries must be declared in modules descriptor with line
177 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
178 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
179 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
180
181 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/admin/propal_extrafields.php');
182 $head[$h][1] = $langs->trans("ExtraFields");
183 $nbExtrafields = $extrafields->attributes['propal']['count'];
184 if ($nbExtrafields > 0) {
185 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
186 }
187 $head[$h][2] = 'attributes';
188 $h++;
189
190 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php');
191 $head[$h][1] = $langs->trans("ExtraFieldsLines");
192 $nbExtrafields = $extrafields->attributes['propaldet']['count'];
193 if ($nbExtrafields > 0) {
194 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
195 }
196 $head[$h][2] = 'attributeslines';
197 $h++;
198
199 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
200
201 return $head;
202}
203
204
205
212function getCustomerProposalPieChart($socid = 0)
213{
214 global $conf, $db, $langs, $user, $hookmanager;
215
216 $result = '';
217
218 if (!isModEnabled('propal') || !$user->hasRight('propal', 'lire')) {
219 return '';
220 }
221
223
224 $propalstatic = new Propal($db);
225 if ($user->socid > 0) $socid = $user->socid;
226 $sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
227 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
228 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
229 if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
230 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
231 }
232 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
233 $sql .= " AND p.fk_soc = s.rowid";
234 if ($user->socid) {
235 $sql .= ' AND p.fk_soc = '.((int) $user->socid);
236 }
237 if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
238 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
239 }
240 $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
241 // Add where from hooks
242 $parameters = array('socid' => $user->socid);
243 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
244 $sql .= $hookmanager->resPrint;
245 $sql .= " GROUP BY p.fk_statut";
246 $resql = $db->query($sql);
247 if ($resql) {
248 $num = $db->num_rows($resql);
249 $i = 0;
250 $total = 0;
251 $totalinprocess = 0;
252 $dataseries = array();
253 $colorseries = array();
254 $vals = array();
255
256 while ($i < $num) {
257 $obj = $db->fetch_object($resql);
258 if ($obj) {
259 $vals[$obj->status] = $obj->nb;
260 $totalinprocess += $obj->nb;
261
262 $total += $obj->nb;
263 }
264 $i++;
265 }
266 $db->free($resql);
267
268 global $badgeStatus0, $badgeStatus1, $badgeStatus4, $badgeStatus6, $badgeStatus9;
269 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
270
271 $result = '<div class="div-table-responsive-no-min">';
272 $result .= '<table class="noborder nohover centpercent">';
273
274 $result .= '<tr class="liste_titre">';
275 $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td>';
276 $result .= '</tr>';
277
278 foreach ($listofstatus as $status) {
279 $dataseries[] = array($propalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
280 if ($status == Propal::STATUS_DRAFT) {
281 $colorseries[$status] = '-'.$badgeStatus0;
282 }
283 if ($status == Propal::STATUS_VALIDATED) {
284 $colorseries[$status] = $badgeStatus1;
285 }
286 if ($status == Propal::STATUS_SIGNED) {
287 $colorseries[$status] = $badgeStatus4;
288 }
289 if ($status == Propal::STATUS_NOTSIGNED) {
290 $colorseries[$status] = $badgeStatus9;
291 }
292 if ($status == Propal::STATUS_BILLED) {
293 $colorseries[$status] = $badgeStatus6;
294 }
295
296 if (empty($conf->use_javascript_ajax)) {
297 $result .= '<tr class="oddeven">';
298 $result .= '<td>'.$propalstatic->LibStatut($status, 0).'</td>';
299 $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
300 $result .= "</tr>\n";
301 }
302 }
303
304 if ($conf->use_javascript_ajax) {
305 $result .= '<tr>';
306 $result .= '<td align="center" colspan="2">';
307
308 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
309 $dolgraph = new DolGraph();
310 $dolgraph->SetData($dataseries);
311 $dolgraph->SetDataColor(array_values($colorseries));
312 $dolgraph->setShowLegend(2);
313 $dolgraph->setShowPercent(1);
314 $dolgraph->SetType(array('pie'));
315 $dolgraph->setHeight('150');
316 $dolgraph->setWidth('300');
317 $dolgraph->draw('idgraphthirdparties');
318 $result .= $dolgraph->show($total ? 0 : 1);
319
320 $result .= '</td>';
321 $result .= '</tr>';
322 }
323
324 //if ($totalinprocess != $total)
325 //{
326 // print '<tr class="liste_total">';
327 // print '<td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td>';
328 // print '<td class="right">'.$totalinprocess.'</td>';
329 // print '</tr>';
330 //}
331
332 $result .= '<tr class="liste_total">';
333 $result .= '<td>'.$langs->trans("Total").'</td>';
334 $result .= '<td class="right">'.$total.'</td>';
335 $result .= '</tr>';
336
337 $result .= '</table>';
338 $result .= '</div>';
339 $result .= '<br>';
340 } else {
342 }
343
344 return $result;
345}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to build graphs.
Class to manage proposals.
const STATUS_DRAFT
Draft status.
const STATUS_SIGNED
Signed quote.
const STATUS_NOTSIGNED
Not signed quote.
const STATUS_BILLED
Billed or processed quote.
const STATUS_VALIDATED
Validated status.
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_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.
propal_admin_prepare_head()
Return array head with list of tabs to view object information.
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
propal_prepare_head($object)
Prepare array with list of tabs.