dolibarr 24.0.0-beta
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-2025 Frédéric 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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
29
34{
35 public $boxcode = "project_opportunities";
36 public $boximg = "object_projectpub";
40 public $boxlabel;
41 // var $depends = array("projet");
42
49 public function __construct($db, $param = '') // @phpstan-ignore constructor.unusedParameter
50 {
51 global $user, $langs;
52
53 // Load translation files required by the page
54 $langs->loadLangs(array('boxes', 'projects'));
55
56 $this->db = $db;
57 $this->boxlabel = "OpenedProjectsOpportunities";
58
59 $this->enabled = getDolGlobalInt('PROJECT_USE_OPPORTUNITIES');
60 $this->hidden = !$user->hasRight('projet', 'lire');
61 $this->urltoaddentry = DOL_URL_ROOT.'/projet/card.php?action=create';
62 $this->msgNoRecords = 'NoOpenedProjectsOpportunities';
63 }
64
71 public function loadBox($max = 5)
72 {
73 global $user, $langs;
74
75 $this->max = $max;
76
77 $textHead = $langs->trans("OpenedProjectsOpportunities");
78 $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
79
80 $num = 0;
81 $i = 0;
82 // list the summary of the orders
83 if ($user->hasRight('projet', 'lire')) {
84 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
85 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
86 $projectstatic = new Project($this->db);
87 $companystatic = new Societe($this->db);
88
89 $socid = 0;
90 //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.
91
92 // Get list of project id allowed to user (in a string list separated by coma)
93 $projectsListId = '';
94 if (!$user->hasRight('projet', 'all', 'lire')) {
95 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
96 }
97
98 $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,";
99 $sql .= " s.nom as name, s.name_alias,";
100 $sql .= " cls.code as opp_status_code";
101 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
102 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
103 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
104 $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
105 $sql .= " AND p.usage_opportunity = 1";
106 $sql .= " AND p.fk_opp_status > 0";
107 $sql .= " AND p.fk_statut IN (".$this->db->sanitize($projectstatic::STATUS_DRAFT.",".$projectstatic::STATUS_VALIDATED).")"; // draft and open projects
108 //$sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
109 if (!$user->hasRight('projet', 'all', 'lire')) {
110 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
111 }
112
113 $sql .= " ORDER BY p.datec DESC";
114 //$sql.= $this->db->plimit($max, 0);
115
116 $result = $this->db->query($sql);
117
118 if ($result) {
119 $num = $this->db->num_rows($result);
120 while ($i < min($num, $max)) {
121 $objp = $this->db->fetch_object($result);
122
123 $projectstatic->id = $objp->rowid;
124 $projectstatic->ref = $objp->ref;
125 $projectstatic->title = $objp->title;
126 $projectstatic->public = $objp->public;
127 $projectstatic->statut = $objp->status;
128 $projectstatic->status = $objp->status;
129 $projectstatic->opp_status = $objp->opp_status;
130 $projectstatic->opp_status_code = $objp->opp_status_code;
131 $projectstatic->opp_percent = $objp->opp_percent;
132 $projectstatic->opp_amount = $objp->opp_amount;
133
134 $companystatic->id = $objp->fk_soc;
135 $companystatic->name = $objp->name;
136 $companystatic->name_alias = $objp->name_alias;
137
138 $this->info_box_contents[$i][] = array(
139 'td' => 'class="nowraponall"',
140 'text' => $projectstatic->getNomUrl(1),
141 'asis' => 1
142 );
143
144 $this->info_box_contents[$i][] = array(
145 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
146 'text' => $objp->title,
147 );
148
149 $this->info_box_contents[$i][] = array(
150 'td' => 'class="tdoverflowmax100"',
151 'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
152 'asis' => 1
153 );
154
155 $this->info_box_contents[$i][] = array('td' => 'class="amount right nowraponall"', 'text' => ($projectstatic->opp_amount ? price($projectstatic->opp_amount) : ''));
156
157 $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>');
158
159 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
160
161 $i++;
162 }
163 if ($max < $num) {
164 $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
165 $i++;
166 }
167 }
168 }
169
170 if ($num > 0) {
171 // Add the sum à the bottom of the boxes
172 $this->info_box_contents[$i][] = array(
173 'tr' => 'class="liste_total_wrap"',
174 'td' => 'class="liste_total"',
175 'text' => $langs->trans("Total")."&nbsp;".$textHead,
176 );
177 $this->info_box_contents[$i][] = array(
178 'td' => 'class="right liste_total" ',
179 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
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 $this->info_box_contents[$i][] = array(
190 'td' => 'class="liste_total"',
191 'text' => "&nbsp;",
192 );
193 $this->info_box_contents[$i][] = array(
194 'td' => 'class="liste_total"',
195 'text' => "&nbsp;",
196 );
197 }
198 }
199
200
201
210 public function showBox($head = null, $contents = null, $nooutput = 0)
211 {
212 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
213 }
214}
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.
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.