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