dolibarr  18.0.6
box_project_opportunities.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
3  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5  * Copyright (C) 2016 Juan José Menent <jmenent@2byte.es>
6  * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28 
33 {
34  public $boxcode = "project_opportunities";
35  public $boximg = "object_projectpub";
36  public $boxlabel;
37  //var $depends = array("projet");
38 
42  public $db;
43 
44  public $param;
45 
46  public $info_box_head = array();
47  public $info_box_contents = array();
48 
55  public function __construct($db, $param = '')
56  {
57  global $user, $langs;
58 
59  // Load translation files required by the page
60  $langs->loadLangs(array('boxes', 'projects'));
61 
62  $this->db = $db;
63  $this->boxlabel = "OpenedProjectsOpportunities";
64 
65  $this->enabled = getDolGlobalInt('PROJECT_USE_OPPORTUNITIES');
66  $this->hidden = !$user->hasRight('projet', 'lire');
67  }
68 
75  public function loadBox($max = 5)
76  {
77  global $user, $langs;
78 
79  $this->max = $max;
80 
81  $textHead = $langs->trans("OpenedProjectsOpportunities");
82  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
83 
84  $i = 0;
85  // list the summary of the orders
86  if ($user->hasRight('projet', 'lire')) {
87  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
89  $projectstatic = new Project($this->db);
90  $companystatic = new Societe($this->db);
91 
92  $socid = 0;
93  //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
94 
95  // Get list of project id allowed to user (in a string list separated by coma)
96  $projectsListId = '';
97  if (empty($user->rights->projet->all->lire)) {
98  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
99  }
100 
101  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_percent, p.opp_amount, p.public,";
102  $sql .= " s.nom as name, s.name_alias,";
103  $sql .= " cls.code as opp_status_code";
104  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
105  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
106  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
107  $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
108  $sql .= " AND p.usage_opportunity = 1";
109  $sql .= " AND p.fk_opp_status > 0";
110  $sql .= " AND p.fk_statut IN (".$this->db->sanitize($projectstatic::STATUS_DRAFT.",".$projectstatic::STATUS_VALIDATED).")"; // draft and open projects
111  //$sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
112  if (empty($user->rights->projet->all->lire)) {
113  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
114  }
115 
116  $sql .= " ORDER BY p.datec DESC";
117  //$sql.= $this->db->plimit($max, 0);
118 
119  $result = $this->db->query($sql);
120 
121  if ($result) {
122  $num = $this->db->num_rows($result);
123  while ($i < min($num, $max)) {
124  $objp = $this->db->fetch_object($result);
125 
126  $projectstatic->id = $objp->rowid;
127  $projectstatic->ref = $objp->ref;
128  $projectstatic->title = $objp->title;
129  $projectstatic->public = $objp->public;
130  $projectstatic->statut = $objp->status;
131  $projectstatic->opp_status = $objp->opp_status;
132  $projectstatic->opp_status_code = $objp->opp_status_code;
133  $projectstatic->opp_percent = $objp->opp_percent;
134  $projectstatic->opp_amount = $objp->opp_amount;
135 
136  $companystatic->id = $objp->fk_soc;
137  $companystatic->name = $objp->name;
138  $companystatic->name_alias = $objp->name_alias;
139 
140  $this->info_box_contents[$i][] = array(
141  'td' => 'class="nowraponall"',
142  'text' => $projectstatic->getNomUrl(1),
143  'asis' => 1
144  );
145 
146  $this->info_box_contents[$i][] = array(
147  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
148  'text' => $objp->title,
149  );
150 
151  $this->info_box_contents[$i][] = array(
152  'td' => 'class="tdoverflowmax100"',
153  'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
154  'asis' => 1
155  );
156 
157  $this->info_box_contents[$i][] = array('td' => 'class="amount right nowraponall"', 'text' => ($projectstatic->opp_amount ? price($projectstatic->opp_amount) : ''));
158 
159  $this->info_box_contents[$i][] = array('td' => 'class="nowraponall"', 'asis'=>1, 'text' => ($projectstatic->opp_status_code ? $langs->trans("OppStatus".$projectstatic->opp_status_code).' ' : '').'<span class="opacitymedium small">('.round($projectstatic->opp_percent).'%)</span>');
160 
161  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
162 
163  $i++;
164  }
165  if ($max < $num) {
166  $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
167  $i++;
168  }
169  }
170  }
171 
172 
173  // Add the sum à the bottom of the boxes
174  $this->info_box_contents[$i][] = array(
175  'tr' => 'class="liste_total_wrap"',
176  'td' => 'class="liste_total"',
177  'text' => $langs->trans("Total")."&nbsp;".$textHead,
178  );
179  $this->info_box_contents[$i][] = array(
180  'td' => 'class="right liste_total" ',
181  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
182  );
183  $this->info_box_contents[$i][] = array(
184  'td' => 'class="liste_total"',
185  'text' => "&nbsp;",
186  );
187  $this->info_box_contents[$i][] = array(
188  'td' => 'class="liste_total"',
189  'text' => "&nbsp;",
190  );
191  $this->info_box_contents[$i][] = array(
192  'td' => 'class="liste_total"',
193  'text' => "&nbsp;",
194  );
195  $this->info_box_contents[$i][] = array(
196  'td' => 'class="liste_total"',
197  'text' => "&nbsp;",
198  );
199  }
200 
209  public function showBox($head = null, $contents = null, $nooutput = 0)
210  {
211  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
212  }
213 }
Class ModeleBoxes.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last projet.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.