dolibarr  16.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  *
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) && ((!empty($conf->expedition->enabled) && !empty($conf->expedition_bon->enabled) && $user->rights->expedition->lire)
46  || (!empty($conf->expedition->enabled) && !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');
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', 'remove');
114 
115  return $head;
116 }
117 
124 {
125  global $langs, $conf, $user;
126 
127  $h = 0;
128  $head = array();
129 
130  $head[$h][0] = DOL_URL_ROOT.'/admin/propal.php';
131  $head[$h][1] = $langs->trans("Miscellaneous");
132  $head[$h][2] = 'general';
133  $h++;
134 
135  // Show more tabs from modules
136  // Entries must be declared in modules descriptor with line
137  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
138  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
139  complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
140 
141  $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php';
142  $head[$h][1] = $langs->trans("ExtraFields");
143  $head[$h][2] = 'attributes';
144  $h++;
145 
146  $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php';
147  $head[$h][1] = $langs->trans("ExtraFieldsLines");
148  $head[$h][2] = 'attributeslines';
149  $h++;
150 
151  complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
152 
153  return $head;
154 }
155 
156 
157 
164 function getCustomerProposalPieChart($socid = 0)
165 {
166  global $conf, $db, $langs, $user;
167 
168  $result= '';
169 
170  if (empty($conf->propal->enabled) || empty($user->rights->propal->lire)) {
171  return '';
172  }
173 
175 
176  $propalstatic = new Propal($db);
177 
178  $sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
179  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
180  $sql .= ", ".MAIN_DB_PREFIX."propal as p";
181  if (empty($user->rights->societe->client->voir) && !$socid) {
182  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
183  }
184  $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
185  $sql .= " AND p.fk_soc = s.rowid";
186  if ($user->socid) {
187  $sql .= ' AND p.fk_soc = '.((int) $user->socid);
188  }
189  if (empty($user->rights->societe->client->voir) && !$socid) {
190  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
191  }
192  $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
193  $sql .= " GROUP BY p.fk_statut";
194  $resql = $db->query($sql);
195  if ($resql) {
196  $num = $db->num_rows($resql);
197  $i = 0;
198  $total = 0;
199  $totalinprocess = 0;
200  $dataseries = array();
201  $colorseries = array();
202  $vals = array();
203 
204  while ($i < $num) {
205  $obj = $db->fetch_object($resql);
206  if ($obj) {
207  $vals[$obj->status] = $obj->nb;
208  $totalinprocess += $obj->nb;
209 
210  $total += $obj->nb;
211  }
212  $i++;
213  }
214  $db->free($resql);
215 
216  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
217 
218  $result = '<div class="div-table-responsive-no-min">';
219  $result .= '<table class="noborder nohover centpercent">';
220 
221  $result .= '<tr class="liste_titre">';
222  $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td>';
223  $result .= '</tr>';
224 
225  foreach ($listofstatus as $status) {
226  $dataseries[] = array($propalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
227  if ($status == Propal::STATUS_DRAFT) {
228  $colorseries[$status] = '-'.$badgeStatus0;
229  }
230  if ($status == Propal::STATUS_VALIDATED) {
231  $colorseries[$status] = $badgeStatus1;
232  }
233  if ($status == Propal::STATUS_SIGNED) {
234  $colorseries[$status] = $badgeStatus4;
235  }
236  if ($status == Propal::STATUS_NOTSIGNED) {
237  $colorseries[$status] = $badgeStatus9;
238  }
239  if ($status == Propal::STATUS_BILLED) {
240  $colorseries[$status] = $badgeStatus6;
241  }
242 
243  if (empty($conf->use_javascript_ajax)) {
244  $result .= '<tr class="oddeven">';
245  $result .= '<td>'.$propalstatic->LibStatut($status, 0).'</td>';
246  $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
247  $result .= "</tr>\n";
248  }
249  }
250 
251  if ($conf->use_javascript_ajax) {
252  $result .= '<tr>';
253  $result .= '<td align="center" colspan="2">';
254 
255  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
256  $dolgraph = new DolGraph();
257  $dolgraph->SetData($dataseries);
258  $dolgraph->SetDataColor(array_values($colorseries));
259  $dolgraph->setShowLegend(2);
260  $dolgraph->setShowPercent(1);
261  $dolgraph->SetType(array('pie'));
262  $dolgraph->setHeight('150');
263  $dolgraph->setWidth('300');
264  $dolgraph->draw('idgraphthirdparties');
265  $result .= $dolgraph->show($total ? 0 : 1);
266 
267  $result .= '</td>';
268  $result .= '</tr>';
269  }
270 
271  //if ($totalinprocess != $total)
272  //{
273  // print '<tr class="liste_total">';
274  // print '<td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td>';
275  // print '<td class="right">'.$totalinprocess.'</td>';
276  // print '</tr>';
277  //}
278 
279  $result .= '<tr class="liste_total">';
280  $result .= '<td>'.$langs->trans("Total").'</td>';
281  $result .= '<td class="right">'.$total.'</td>';
282  $result .= '</tr>';
283 
284  $result .= '</table>';
285  $result .= '</div>';
286  $result .= '<br>';
287  } else {
288  dol_print_error($db);
289  }
290 
291  return $result;
292 }
Propal\STATUS_SIGNED
const STATUS_SIGNED
Signed quote.
Definition: propal.class.php:360
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
propal_admin_prepare_head
propal_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: propal.lib.php:123
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:4844
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)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
Propal\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: propal.class.php:352
Propal\STATUS_BILLED
const STATUS_BILLED
Billed or processed quote.
Definition: propal.class.php:368
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:356
getCustomerProposalPieChart
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
Definition: propal.lib.php:164
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Propal
Class to manage proposals.
Definition: propal.class.php:52
Propal\STATUS_NOTSIGNED
const STATUS_NOTSIGNED
Not signed quote.
Definition: propal.class.php:364