dolibarr  17.0.3
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 
32 function propal_prepare_head($object)
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("expedition") && !empty($conf->expedition_bon->enabled) && $user->rights->expedition->lire)
46  || (isModEnabled("expedition") && !empty($conf->delivery_note->enabled) && $user->rights->expedition->delivery->lire)))) {
47  $langs->load("sendings");
48  $text = '';
49  $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$object->id;
50  if ($conf->expedition_bon->enabled) {
51  $text = $langs->trans("Shipment");
52  }
53  if ($conf->delivery_note->enabled) {
54  $text .= '/'.$langs->trans("Receivings");
55  }
56  $head[$h][1] = $text;
57  $head[$h][2] = 'shipping';
58  $h++;
59  }
60 
61  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
62  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
63  $head[$h][0] = DOL_URL_ROOT.'/comm/propal/contact.php?id='.$object->id;
64  $head[$h][1] = $langs->trans('ContactsAddresses');
65  if ($nbContact > 0) {
66  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
67  }
68  $head[$h][2] = 'contact';
69  $h++;
70  }
71 
72  // Show more tabs from modules
73  // Entries must be declared in modules descriptor with line
74  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
75  // $this->tabs = array('entity:-tabname); to remove a tab
76  complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'core');
77 
78  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
79  $nbNote = 0;
80  if (!empty($object->note_private)) {
81  $nbNote++;
82  }
83  if (!empty($object->note_public)) {
84  $nbNote++;
85  }
86  $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id;
87  $head[$h][1] = $langs->trans('Notes');
88  if ($nbNote > 0) {
89  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
90  }
91  $head[$h][2] = 'note';
92  $h++;
93  }
94 
95  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
96  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
97  $upload_dir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
98  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
99  $nbLinks = Link::count($db, $object->element, $object->id);
100  $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id;
101  $head[$h][1] = $langs->trans('Documents');
102  if (($nbFiles + $nbLinks) > 0) {
103  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
104  }
105  $head[$h][2] = 'document';
106  $h++;
107 
108  $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?id='.$object->id;
109  $head[$h][1] = $langs->trans('Info');
110  $head[$h][2] = 'info';
111  $h++;
112 
113  complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'add', 'external');
114 
115  complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'remove');
116 
117  return $head;
118 }
119 
126 {
127  global $langs, $conf, $user, $db;
128 
129  $extrafields = new ExtraFields($db);
130  $extrafields->fetch_name_optionals_label('propal');
131  $extrafields->fetch_name_optionals_label('propaldet');
132 
133  $h = 0;
134  $head = array();
135 
136  $head[$h][0] = DOL_URL_ROOT.'/admin/propal.php';
137  $head[$h][1] = $langs->trans("Miscellaneous");
138  $head[$h][2] = 'general';
139  $h++;
140 
141  // Show more tabs from modules
142  // Entries must be declared in modules descriptor with line
143  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
144  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
145  complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
146 
147  $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php';
148  $head[$h][1] = $langs->trans("ExtraFields");
149  $nbExtrafields = $extrafields->attributes['propal']['count'];
150  if ($nbExtrafields > 0) {
151  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
152  }
153  $head[$h][2] = 'attributes';
154  $h++;
155 
156  $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php';
157  $head[$h][1] = $langs->trans("ExtraFieldsLines");
158  $nbExtrafields = $extrafields->attributes['propaldet']['count'];
159  if ($nbExtrafields > 0) {
160  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
161  }
162  $head[$h][2] = 'attributeslines';
163  $h++;
164 
165  complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
166 
167  return $head;
168 }
169 
170 
171 
178 function getCustomerProposalPieChart($socid = 0)
179 {
180  global $conf, $db, $langs, $user;
181 
182  $result= '';
183 
184  if (!isModEnabled('propal') || empty($user->rights->propal->lire)) {
185  return '';
186  }
187 
189 
190  $propalstatic = new Propal($db);
191 
192  $sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
193  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
194  $sql .= ", ".MAIN_DB_PREFIX."propal as p";
195  if (empty($user->rights->societe->client->voir) && !$socid) {
196  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
197  }
198  $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
199  $sql .= " AND p.fk_soc = s.rowid";
200  if ($user->socid) {
201  $sql .= ' AND p.fk_soc = '.((int) $user->socid);
202  }
203  if (empty($user->rights->societe->client->voir) && !$socid) {
204  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
205  }
206  $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
207  $sql .= " GROUP BY p.fk_statut";
208  $resql = $db->query($sql);
209  if ($resql) {
210  $num = $db->num_rows($resql);
211  $i = 0;
212  $total = 0;
213  $totalinprocess = 0;
214  $dataseries = array();
215  $colorseries = array();
216  $vals = array();
217 
218  while ($i < $num) {
219  $obj = $db->fetch_object($resql);
220  if ($obj) {
221  $vals[$obj->status] = $obj->nb;
222  $totalinprocess += $obj->nb;
223 
224  $total += $obj->nb;
225  }
226  $i++;
227  }
228  $db->free($resql);
229 
230  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
231 
232  $result = '<div class="div-table-responsive-no-min">';
233  $result .= '<table class="noborder nohover centpercent">';
234 
235  $result .= '<tr class="liste_titre">';
236  $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td>';
237  $result .= '</tr>';
238 
239  foreach ($listofstatus as $status) {
240  $dataseries[] = array($propalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
241  if ($status == Propal::STATUS_DRAFT) {
242  $colorseries[$status] = '-'.$badgeStatus0;
243  }
244  if ($status == Propal::STATUS_VALIDATED) {
245  $colorseries[$status] = $badgeStatus1;
246  }
247  if ($status == Propal::STATUS_SIGNED) {
248  $colorseries[$status] = $badgeStatus4;
249  }
250  if ($status == Propal::STATUS_NOTSIGNED) {
251  $colorseries[$status] = $badgeStatus9;
252  }
253  if ($status == Propal::STATUS_BILLED) {
254  $colorseries[$status] = $badgeStatus6;
255  }
256 
257  if (empty($conf->use_javascript_ajax)) {
258  $result .= '<tr class="oddeven">';
259  $result .= '<td>'.$propalstatic->LibStatut($status, 0).'</td>';
260  $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
261  $result .= "</tr>\n";
262  }
263  }
264 
265  if ($conf->use_javascript_ajax) {
266  $result .= '<tr>';
267  $result .= '<td align="center" colspan="2">';
268 
269  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
270  $dolgraph = new DolGraph();
271  $dolgraph->SetData($dataseries);
272  $dolgraph->SetDataColor(array_values($colorseries));
273  $dolgraph->setShowLegend(2);
274  $dolgraph->setShowPercent(1);
275  $dolgraph->SetType(array('pie'));
276  $dolgraph->setHeight('150');
277  $dolgraph->setWidth('300');
278  $dolgraph->draw('idgraphthirdparties');
279  $result .= $dolgraph->show($total ? 0 : 1);
280 
281  $result .= '</td>';
282  $result .= '</tr>';
283  }
284 
285  //if ($totalinprocess != $total)
286  //{
287  // print '<tr class="liste_total">';
288  // print '<td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td>';
289  // print '<td class="right">'.$totalinprocess.'</td>';
290  // print '</tr>';
291  //}
292 
293  $result .= '<tr class="liste_total">';
294  $result .= '<td>'.$langs->trans("Total").'</td>';
295  $result .= '<td class="right">'.$total.'</td>';
296  $result .= '</tr>';
297 
298  $result .= '</table>';
299  $result .= '</div>';
300  $result .= '<br>';
301  } else {
302  dol_print_error($db);
303  }
304 
305  return $result;
306 }
Propal\STATUS_SIGNED
const STATUS_SIGNED
Signed quote.
Definition: propal.class.php:365
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
propal_admin_prepare_head
propal_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: propal.lib.php:125
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
dol_dir_list
dol_dir_list($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:61
Propal\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: propal.class.php:357
complete_head_from_modules
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).
Definition: functions.lib.php:9395
Propal\STATUS_BILLED
const STATUS_BILLED
Billed or processed quote.
Definition: propal.class.php:373
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
propal_prepare_head
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
Propal\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: propal.class.php:361
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
getCustomerProposalPieChart
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
Definition: propal.lib.php:178
Propal
Class to manage proposals.
Definition: propal.class.php:52
Propal\STATUS_NOTSIGNED
const STATUS_NOTSIGNED
Not signed quote.
Definition: propal.class.php:369