dolibarr 22.0.5
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
34{
35 global $db, $langs, $conf, $user;
36 $langs->loadLangs(array('propal', 'compta', 'companies'));
37
38 $h = 0;
39 $head = array();
40
41 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id;
42 $head[$h][1] = $langs->trans('Proposal');
43 $head[$h][2] = 'comm';
44 $h++;
45
46 if ((!isModEnabled('order') && ((isModEnabled("shipping") && getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'lire'))
47 || (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'lire'))))) {
48 $langs->load("sendings");
49 $text = '';
50 $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$object->id;
51 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION')) {
52 $text = $langs->trans("Shipment");
53 }
54 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
55 $text .= '/';
56 }
57 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
58 $text .= $langs->trans("Receivings");
59 }
60 $head[$h][1] = $text;
61 $head[$h][2] = 'shipping';
62 $h++;
63 }
64
65 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
66 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
67 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/contact.php?id='.$object->id;
68 $head[$h][1] = $langs->trans('ContactsAddresses');
69 if ($nbContact > 0) {
70 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
71 }
72 $head[$h][2] = 'contact';
73 $h++;
74 }
75
76 // Show more tabs from modules
77 // Entries must be declared in modules descriptor with line
78 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
79 // $this->tabs = array('entity:-tabname); to remove a tab
80 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'core');
81
82 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
83 $nbNote = 0;
84 if (!empty($object->note_private)) {
85 $nbNote++;
86 }
87 if (!empty($object->note_public)) {
88 $nbNote++;
89 }
90 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id;
91 $head[$h][1] = $langs->trans('Notes');
92 if ($nbNote > 0) {
93 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
94 }
95 $head[$h][2] = 'note';
96 $h++;
97 }
98
99 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
100 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
101 $upload_dir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
102 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
103 $nbLinks = Link::count($db, $object->element, $object->id);
104 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id;
105 $head[$h][1] = $langs->trans('Documents');
106 if (($nbFiles + $nbLinks) > 0) {
107 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
108 }
109 $head[$h][2] = 'document';
110 $h++;
111
112
113 $head[$h][0] = DOL_URL_ROOT.'/comm/propal/agenda.php?id='.$object->id;
114 $head[$h][1] = $langs->trans("Events");
115 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
116 $nbEvent = 0;
117 // Enable caching of thirdparty count actioncomm
118 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
119 $cachekey = 'count_events_propal_'.$object->id;
120 $dataretrieved = dol_getcache($cachekey);
121 if (!is_null($dataretrieved)) {
122 $nbEvent = $dataretrieved;
123 } else {
124 $sql = "SELECT COUNT(id) as nb";
125 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
126 $sql .= " WHERE fk_element = ".((int) $object->id);
127 $sql .= " AND elementtype = 'propal'";
128 $resql = $db->query($sql);
129 if ($resql) {
130 $obj = $db->fetch_object($resql);
131 $nbEvent = $obj->nb;
132 } else {
133 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
134 }
135 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
136 }
137
138 $head[$h][1] .= '/';
139 $head[$h][1] .= $langs->trans("Agenda");
140 if ($nbEvent > 0) {
141 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
142 }
143 }
144 $head[$h][2] = 'agenda';
145 $h++;
146
147 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'external');
148
149 complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'remove');
150
151 return $head;
152}
153
160{
161 global $langs, $conf, $user, $db;
162
163 $extrafields = new ExtraFields($db);
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] = DOL_URL_ROOT.'/admin/propal.php';
171 $head[$h][1] = $langs->trans("Miscellaneous");
172 $head[$h][2] = 'general';
173 $h++;
174
175 $head[$h][0] = DOL_URL_ROOT.'/admin/propal_pdf.php';
176 $head[$h][1] = $langs->trans("PDF");
177 $head[$h][2] = 'pdf';
178 $h++;
179
180 // Show more tabs from modules
181 // Entries must be declared in modules descriptor with line
182 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
183 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
184 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
185
186 $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php';
187 $head[$h][1] = $langs->trans("ExtraFields");
188 $nbExtrafields = $extrafields->attributes['propal']['count'];
189 if ($nbExtrafields > 0) {
190 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
191 }
192 $head[$h][2] = 'attributes';
193 $h++;
194
195 $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php';
196 $head[$h][1] = $langs->trans("ExtraFieldsLines");
197 $nbExtrafields = $extrafields->attributes['propaldet']['count'];
198 if ($nbExtrafields > 0) {
199 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
200 }
201 $head[$h][2] = 'attributeslines';
202 $h++;
203
204 complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
205
206 return $head;
207}
208
209
210
217function getCustomerProposalPieChart($socid = 0)
218{
219 global $conf, $db, $langs, $user;
220
221 $result = '';
222
223 if (!isModEnabled('propal') || !$user->hasRight('propal', 'lire')) {
224 return '';
225 }
226
228
229 $propalstatic = new Propal($db);
230 if ($user->socid > 0) $socid = $user->socid;
231 $sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
232 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
233 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
234 if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
235 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
236 }
237 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
238 $sql .= " AND p.fk_soc = s.rowid";
239 if ($user->socid) {
240 $sql .= ' AND p.fk_soc = '.((int) $user->socid);
241 }
242 if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
243 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
244 }
245 $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
246 $sql .= " GROUP BY p.fk_statut";
247 $resql = $db->query($sql);
248 if ($resql) {
249 $num = $db->num_rows($resql);
250 $i = 0;
251 $total = 0;
252 $totalinprocess = 0;
253 $dataseries = array();
254 $colorseries = array();
255 $vals = array();
256
257 while ($i < $num) {
258 $obj = $db->fetch_object($resql);
259 if ($obj) {
260 $vals[$obj->status] = $obj->nb;
261 $totalinprocess += $obj->nb;
262
263 $total += $obj->nb;
264 }
265 $i++;
266 }
267 $db->free($resql);
268
269 global $badgeStatus0, $badgeStatus1, $badgeStatus4, $badgeStatus6, $badgeStatus9;
270 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
271
272 $result = '<div class="div-table-responsive-no-min">';
273 $result .= '<table class="noborder nohover centpercent">';
274
275 $result .= '<tr class="liste_titre">';
276 $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td>';
277 $result .= '</tr>';
278
279 foreach ($listofstatus as $status) {
280 $dataseries[] = array($propalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
281 if ($status == Propal::STATUS_DRAFT) {
282 $colorseries[$status] = '-'.$badgeStatus0;
283 }
284 if ($status == Propal::STATUS_VALIDATED) {
285 $colorseries[$status] = $badgeStatus1;
286 }
287 if ($status == Propal::STATUS_SIGNED) {
288 $colorseries[$status] = $badgeStatus4;
289 }
290 if ($status == Propal::STATUS_NOTSIGNED) {
291 $colorseries[$status] = $badgeStatus9;
292 }
293 if ($status == Propal::STATUS_BILLED) {
294 $colorseries[$status] = $badgeStatus6;
295 }
296
297 if (empty($conf->use_javascript_ajax)) {
298 $result .= '<tr class="oddeven">';
299 $result .= '<td>'.$propalstatic->LibStatut($status, 0).'</td>';
300 $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
301 $result .= "</tr>\n";
302 }
303 }
304
305 if ($conf->use_javascript_ajax) {
306 $result .= '<tr>';
307 $result .= '<td align="center" colspan="2">';
308
309 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
310 $dolgraph = new DolGraph();
311 $dolgraph->SetData($dataseries);
312 $dolgraph->SetDataColor(array_values($colorseries));
313 $dolgraph->setShowLegend(2);
314 $dolgraph->setShowPercent(1);
315 $dolgraph->SetType(array('pie'));
316 $dolgraph->setHeight('150');
317 $dolgraph->setWidth('300');
318 $dolgraph->draw('idgraphthirdparties');
319 $result .= $dolgraph->show($total ? 0 : 1);
320
321 $result .= '</td>';
322 $result .= '</tr>';
323 }
324
325 //if ($totalinprocess != $total)
326 //{
327 // print '<tr class="liste_total">';
328 // print '<td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td>';
329 // print '<td class="right">'.$totalinprocess.'</td>';
330 // print '</tr>';
331 //}
332
333 $result .= '<tr class="liste_total">';
334 $result .= '<td>'.$langs->trans("Total").'</td>';
335 $result .= '<td class="right">'.$total.'</td>';
336 $result .= '</tr>';
337
338 $result .= '</table>';
339 $result .= '</div>';
340 $result .= '<br>';
341 } else {
342 dol_print_error($db);
343 }
344
345 return $result;
346}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to build graphs.
Class to manage standard extra fields.
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.
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:63
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).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.