dolibarr  20.0.0-alpha
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 
45  public function __construct($db, $param = '')
46  {
47  global $user, $langs;
48 
49  // Load translation files required by the page
50  $langs->loadLangs(array('boxes', 'projects'));
51 
52  $this->db = $db;
53  $this->boxlabel = "OpenedProjectsOpportunities";
54 
55  $this->enabled = getDolGlobalInt('PROJECT_USE_OPPORTUNITIES');
56  $this->hidden = !$user->hasRight('projet', 'lire');
57  }
58 
65  public function loadBox($max = 5)
66  {
67  global $user, $langs;
68 
69  $this->max = $max;
70 
71  $textHead = $langs->trans("OpenedProjectsOpportunities");
72  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
73 
74  $i = 0;
75  // list the summary of the orders
76  if ($user->hasRight('projet', 'lire')) {
77  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
78  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
79  $projectstatic = new Project($this->db);
80  $companystatic = new Societe($this->db);
81 
82  $socid = 0;
83  //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 assignment.
84 
85  // Get list of project id allowed to user (in a string list separated by coma)
86  $projectsListId = '';
87  if (!$user->hasRight('projet', 'all', 'lire')) {
88  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
89  }
90 
91  $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,";
92  $sql .= " s.nom as name, s.name_alias,";
93  $sql .= " cls.code as opp_status_code";
94  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
95  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
96  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
97  $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
98  $sql .= " AND p.usage_opportunity = 1";
99  $sql .= " AND p.fk_opp_status > 0";
100  $sql .= " AND p.fk_statut IN (".$this->db->sanitize($projectstatic::STATUS_DRAFT.",".$projectstatic::STATUS_VALIDATED).")"; // draft and open projects
101  //$sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
102  if (!$user->hasRight('projet', 'all', 'lire')) {
103  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
104  }
105 
106  $sql .= " ORDER BY p.datec DESC";
107  //$sql.= $this->db->plimit($max, 0);
108 
109  $result = $this->db->query($sql);
110 
111  if ($result) {
112  $num = $this->db->num_rows($result);
113  while ($i < min($num, $max)) {
114  $objp = $this->db->fetch_object($result);
115 
116  $projectstatic->id = $objp->rowid;
117  $projectstatic->ref = $objp->ref;
118  $projectstatic->title = $objp->title;
119  $projectstatic->public = $objp->public;
120  $projectstatic->statut = $objp->status;
121  $projectstatic->opp_status = $objp->opp_status;
122  $projectstatic->opp_status_code = $objp->opp_status_code;
123  $projectstatic->opp_percent = $objp->opp_percent;
124  $projectstatic->opp_amount = $objp->opp_amount;
125 
126  $companystatic->id = $objp->fk_soc;
127  $companystatic->name = $objp->name;
128  $companystatic->name_alias = $objp->name_alias;
129 
130  $this->info_box_contents[$i][] = array(
131  'td' => 'class="nowraponall"',
132  'text' => $projectstatic->getNomUrl(1),
133  'asis' => 1
134  );
135 
136  $this->info_box_contents[$i][] = array(
137  'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
138  'text' => $objp->title,
139  );
140 
141  $this->info_box_contents[$i][] = array(
142  'td' => 'class="tdoverflowmax100"',
143  'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
144  'asis' => 1
145  );
146 
147  $this->info_box_contents[$i][] = array('td' => 'class="amount right nowraponall"', 'text' => ($projectstatic->opp_amount ? price($projectstatic->opp_amount) : ''));
148 
149  $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>');
150 
151  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
152 
153  $i++;
154  }
155  if ($max < $num) {
156  $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
157  $i++;
158  }
159  }
160  }
161 
162 
163  // Add the sum à the bottom of the boxes
164  $this->info_box_contents[$i][] = array(
165  'tr' => 'class="liste_total_wrap"',
166  'td' => 'class="liste_total"',
167  'text' => $langs->trans("Total")."&nbsp;".$textHead,
168  );
169  $this->info_box_contents[$i][] = array(
170  'td' => 'class="right liste_total" ',
171  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
172  );
173  $this->info_box_contents[$i][] = array(
174  'td' => 'class="liste_total"',
175  'text' => "&nbsp;",
176  );
177  $this->info_box_contents[$i][] = array(
178  'td' => 'class="liste_total"',
179  'text' => "&nbsp;",
180  );
181  $this->info_box_contents[$i][] = array(
182  'td' => 'class="liste_total"',
183  'text' => "&nbsp;",
184  );
185  $this->info_box_contents[$i][] = array(
186  'td' => 'class="liste_total"',
187  'text' => "&nbsp;",
188  );
189  }
190 
199  public function showBox($head = null, $contents = null, $nooutput = 0)
200  {
201  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
202  }
203 }
Class ModeleBoxes.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show project opportunities.
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('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
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 a Dolibarr global constant int value.