1<?php 2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> 5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21/** 22 * \file htdocs/supplier_proposal/index.php 23 * \ingroup supplier_proposal 24 * \brief Home page of vendor proposal area 25 */ 26 27require '../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; 30 31$hookmanager = new HookManager($db); 32 33// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array 34$hookmanager->initHooks(array('suppliersproposalsindex')); 35 36// Load translation files required by the page 37$langs->loadLangs(array('supplier_proposal', 'companies')); 38 39// Security check 40$socid = GETPOST('socid', 'int'); 41if (isset($user->socid) && $user->socid > 0) { 42 $action = ''; 43 $socid = $user->socid; 44} 45$result = restrictedArea($user, 'supplier_proposal'); 46 47 48/* 49 * View 50 */ 51$now = dol_now(); 52$supplier_proposalstatic = new SupplierProposal($db); 53$companystatic = new Societe($db); 54$form = new Form($db); 55$formfile = new FormFile($db); 56$help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur"; 57 58llxHeader("", $langs->trans("SupplierProposalArea"), $help_url); 59 60print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal'); 61 62print '<div class="fichecenter"><div class="fichethirdleft">'; 63 64// Statistics 65 66$sql = "SELECT count(p.rowid), p.fk_statut"; 67$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; 68$sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; 69if (!$user->rights->societe->client->voir && !$socid) { 70 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 71} 72$sql .= " WHERE p.fk_soc = s.rowid"; 73$sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; 74if ($user->socid) { 75 $sql .= ' AND p.fk_soc = '.$user->socid; 76} 77if (!$user->rights->societe->client->voir && !$socid) { 78 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); 79} 80$sql .= " AND p.fk_statut IN (0,1,2,3,4)"; 81$sql .= " GROUP BY p.fk_statut"; 82$resql = $db->query($sql); 83if ($resql) { 84 $num = $db->num_rows($resql); 85 $i = 0; 86 87 $total = 0; 88 $totalinprocess = 0; 89 $dataseries = array(); 90 $colorseries = array(); 91 $vals = array(); 92 // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) 93 while ($i < $num) { 94 $row = $db->fetch_row($resql); 95 if ($row) { 96 //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1)) 97 { 98 $vals[$row[1]] = $row[0]; 99 $totalinprocess += $row[0]; 100 } 101 $total += $row[0]; 102 } 103 $i++; 104 } 105 $db->free($resql); 106 107 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; 108 109 print '<div class="div-table-responsive-no-min">'; 110 print '<table class="noborder centpercent">'; 111 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n"; 112 $listofstatus = array(0, 1, 2, 3, 4); 113 foreach ($listofstatus as $status) { 114 $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0)); 115 if ($status == SupplierProposal::STATUS_DRAFT) { 116 $colorseries[$status] = '-'.$badgeStatus0; 117 } 118 if ($status == SupplierProposal::STATUS_VALIDATED) { 119 $colorseries[$status] = $badgeStatus1; 120 } 121 if ($status == SupplierProposal::STATUS_SIGNED) { 122 $colorseries[$status] = $badgeStatus4; 123 } 124 if ($status == SupplierProposal::STATUS_NOTSIGNED) { 125 $colorseries[$status] = $badgeStatus9; 126 } 127 if ($status == SupplierProposal::STATUS_CLOSE) { 128 $colorseries[$status] = $badgeStatus6; 129 } 130 131 if (empty($conf->use_javascript_ajax)) { 132 print '<tr class="oddeven">'; 133 print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>'; 134 print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>'; 135 print "</tr>\n"; 136 } 137 } 138 if ($conf->use_javascript_ajax) { 139 print '<tr><td class="center" colspan="2">'; 140 141 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; 142 $dolgraph = new DolGraph(); 143 $dolgraph->SetData($dataseries); 144 $dolgraph->SetDataColor(array_values($colorseries)); 145 $dolgraph->setShowLegend(2); 146 $dolgraph->setShowPercent(1); 147 $dolgraph->SetType(array('pie')); 148 $dolgraph->setHeight('200'); 149 $dolgraph->draw('idgraphstatus'); 150 print $dolgraph->show($total ? 0 : 1); 151 152 print '</td></tr>'; 153 } 154 155 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>'; 156 print "</table></div><br>"; 157} else { 158 dol_print_error($db); 159} 160 161 162/* 163 * Draft askprice 164 */ 165if (!empty($conf->supplier_proposal->enabled)) { 166 $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client"; 167 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c"; 168 $sql .= ", ".MAIN_DB_PREFIX."societe as s"; 169 if (!$user->rights->societe->client->voir && !$socid) { 170 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 171 } 172 $sql .= " WHERE c.fk_soc = s.rowid"; 173 $sql .= " AND c.entity = ".$conf->entity; 174 $sql .= " AND c.fk_statut = 0"; 175 if ($socid) { 176 $sql .= " AND c.fk_soc = ".((int) $socid); 177 } 178 if (!$user->rights->societe->client->voir && !$socid) { 179 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); 180 } 181 182 $resql = $db->query($sql); 183 if ($resql) { 184 print '<div class="div-table-responsive-no-min">'; 185 print '<table class="noborder centpercent">'; 186 print '<tr class="liste_titre">'; 187 print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>'; 188 $langs->load("supplier_proposal"); 189 $num = $db->num_rows($resql); 190 if ($num) { 191 $i = 0; 192 while ($i < $num) { 193 $obj = $db->fetch_object($resql); 194 195 print '<tr class="oddeven">'; 196 $supplier_proposalstatic->id = $obj->rowid; 197 $supplier_proposalstatic->ref = $obj->ref; 198 print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>'; 199 200 $companystatic->id = $obj->socid; 201 $companystatic->name = $obj->socname; 202 $companystatic->client = $obj->client; 203 $companystatic->canvas = $obj->canvas; 204 print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>'; 205 206 print '</tr>'; 207 $i++; 208 } 209 } 210 print "</table></div><br>"; 211 } 212} 213 214print '</div><div class="fichetwothirdright"><div class="ficheaddleft">'; 215 216 217$max = 5; 218 219/* 220 * Last modified askprice 221 */ 222 223$sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,"; 224$sql .= " date_cloture as datec"; 225$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c"; 226$sql .= ", ".MAIN_DB_PREFIX."societe as s"; 227if (!$user->rights->societe->client->voir && !$socid) { 228 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 229} 230$sql .= " WHERE c.fk_soc = s.rowid"; 231$sql .= " AND c.entity = ".$conf->entity; 232//$sql.= " AND c.fk_statut > 2"; 233if ($socid) { 234 $sql .= " AND c.fk_soc = ".((int) $socid); 235} 236if (!$user->rights->societe->client->voir && !$socid) { 237 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); 238} 239$sql .= " ORDER BY c.tms DESC"; 240$sql .= $db->plimit($max, 0); 241 242$resql = $db->query($sql); 243if ($resql) { 244 print '<div class="div-table-responsive-no-min">'; 245 print '<table class="noborder centpercent">'; 246 print '<tr class="liste_titre">'; 247 print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>'; 248 249 $num = $db->num_rows($resql); 250 if ($num) { 251 $i = 0; 252 while ($i < $num) { 253 $obj = $db->fetch_object($resql); 254 255 print '<tr class="oddeven">'; 256 print '<td width="20%" class="nowrap">'; 257 258 $supplier_proposalstatic->id = $obj->rowid; 259 $supplier_proposalstatic->ref = $obj->ref; 260 261 print '<table class="nobordernopadding"><tr class="nocellnopadd">'; 262 print '<td width="96" class="nobordernopadding nowrap">'; 263 print $supplier_proposalstatic->getNomUrl(1); 264 print '</td>'; 265 266 print '<td width="16" class="nobordernopadding nowrap">'; 267 print ' '; 268 print '</td>'; 269 270 print '<td width="16" class="right nobordernopadding">'; 271 $filename = dol_sanitizeFileName($obj->ref); 272 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref); 273 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid; 274 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir); 275 print '</td></tr></table>'; 276 277 print '</td>'; 278 279 $companystatic->id = $obj->socid; 280 $companystatic->name = $obj->socname; 281 $companystatic->client = $obj->client; 282 $companystatic->canvas = $obj->canvas; 283 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>'; 284 285 print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>'; 286 print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'; 287 print '</tr>'; 288 $i++; 289 } 290 } 291 print "</table></div><br>"; 292} else { 293 dol_print_error($db); 294} 295 296 297/* 298 * Opened askprice 299 */ 300if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) { 301 $langs->load("supplier_proposal"); 302 303 $now = dol_now(); 304 305 $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total_ttc, p.total_tva, p.total_ht, p.ref, p.fk_statut, p.datec as dp"; 306 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; 307 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; 308 if (!$user->rights->societe->client->voir && !$socid) { 309 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 310 } 311 $sql .= " WHERE p.fk_soc = s.rowid"; 312 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; 313 $sql .= " AND p.fk_statut = 1"; 314 if (!$user->rights->societe->client->voir && !$socid) { 315 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); 316 } 317 if ($socid) { 318 $sql .= " AND s.rowid = ".((int) $socid); 319 } 320 $sql .= " ORDER BY p.rowid DESC"; 321 322 $result = $db->query($sql); 323 if ($result) { 324 $total = 0; 325 $num = $db->num_rows($result); 326 $i = 0; 327 if ($num > 0) { 328 print '<div class="div-table-responsive-no-min">'; 329 print '<table class="noborder centpercent">'; 330 print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened").' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1"><span class="badge">'.$num.'</span></a></th></tr>'; 331 332 $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD)); 333 while ($i < $nbofloop) { 334 $obj = $db->fetch_object($result); 335 336 print '<tr class="oddeven">'; 337 338 // Ref 339 print '<td class="nowrap" width="140">'; 340 341 $supplier_proposalstatic->id = $obj->supplier_proposalid; 342 $supplier_proposalstatic->ref = $obj->ref; 343 344 print '<table class="nobordernopadding"><tr class="nocellnopadd">'; 345 print '<td class="nobordernopadding nowrap">'; 346 print $supplier_proposalstatic->getNomUrl(1); 347 print '</td>'; 348 print '<td width="18" class="nobordernopadding nowrap">'; 349 if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) { 350 print img_warning($langs->trans("Late")); 351 } 352 print '</td>'; 353 print '<td width="16" class="center nobordernopadding">'; 354 $filename = dol_sanitizeFileName($obj->ref); 355 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref); 356 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid; 357 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir); 358 print '</td></tr></table>'; 359 360 print "</td>"; 361 362 $companystatic->id = $obj->socid; 363 $companystatic->name = $obj->socname; 364 $companystatic->client = $obj->client; 365 $companystatic->canvas = $obj->canvas; 366 print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n"; 367 368 print '<td class="right">'; 369 print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n"; 370 print '<td class="right">'.price($obj->total_ttc).'</td>'; 371 print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n"; 372 print '</tr>'."\n"; 373 $i++; 374 $total += $obj->total_ttc; 375 } 376 if ($num > $nbofloop) { 377 print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>"; 378 } elseif ($total > 0) { 379 print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td> </td></tr>"; 380 } 381 print "</table></div><br>"; 382 } 383 } else { 384 dol_print_error($db); 385 } 386} 387 388print '</div></div></div>'; 389 390$parameters = array('user' => $user); 391$reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook 392 393// End of page 394llxFooter(); 395$db->close(); 396