dolibarr/htdocs/comm/prospect/index.php

287 lines
8.8 KiB
PHP
Raw Normal View History

<?php
2004-02-07 19:36:36 +01:00
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2011-02-21 09:58:45 +01:00
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
2004-02-07 19:36:36 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2004-02-07 19:36:36 +01:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2004-02-07 19:36:36 +01:00
*/
/**
* \file htdocs/comm/prospect/index.php
* \ingroup commercial
2011-02-21 09:58:45 +01:00
* \brief Home page of propest area
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
2004-02-07 19:36:36 +01:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
$langs->load("propal");
2021-02-22 13:14:13 +01:00
if ($user->socid > 0) {
$socid = $user->socid;
2004-02-07 19:36:36 +01:00
}
2021-03-29 22:43:39 +02:00
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) {
$action = '';
$socid = $user->socid;
}
$result = restrictedArea($user, 'propal', $socid, '');
2004-02-07 19:36:36 +01:00
/*
* View
2004-02-07 19:36:36 +01:00
*/
$companystatic = new Societe($db);
2011-02-21 09:58:45 +01:00
llxHeader();
print load_fiche_titre($langs->trans("ProspectionArea"));
2004-02-07 19:36:36 +01:00
//print '<table border="0" width="100%" class="notopnoleftnoright">';
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
print '<div class="fichecenter"><div class="fichethirdleft">';
2004-02-07 19:36:36 +01:00
2021-02-22 13:14:13 +01:00
if (!empty($conf->propal->enabled)) {
$var = false;
print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-11-05 21:24:41 +01:00
print '<table class="noborder nohover centpercent">';
2010-08-09 17:42:57 +02:00
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
print '<tr class="oddeven"><td>';
2010-08-09 17:42:57 +02:00
print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
2010-08-09 17:42:57 +02:00
print '</tr>';
print "</table></form><br>\n";
}
/*
2011-06-13 10:15:30 +02:00
* Prospects par statut
*
*/
2022-01-18 13:44:52 +01:00
$sql = "SELECT count(*) as cc, st.libelle as stcomm, st.picto, st.id";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-02-22 13:14:13 +01:00
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fk_stcomm = st.id";
$sql .= " AND s.client IN (2, 3)";
$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2021-02-22 13:14:13 +01:00
}
$sql .= " GROUP BY st.id";
$sql .= " ORDER BY st.id";
$resql = $db->query($sql);
2021-02-22 13:14:13 +01:00
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
2021-02-22 13:14:13 +01:00
if ($num > 0) {
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
2021-02-22 13:14:13 +01:00
while ($i < $num) {
$obj = $db->fetch_object($resql);
2018-01-30 15:48:09 +01:00
print '<tr class="oddeven"><td>';
2011-06-13 10:15:30 +02:00
print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
print img_action($langs->trans("Show"), $obj->id, $obj->picto).' ';
print $langs->trans("StatusProspect".$obj->id);
2019-01-22 14:09:14 +01:00
print '</a></td><td class="right">'.$obj->cc.'</td></tr>';
$i++;
}
print "</table><br>";
}
}
2005-05-14 17:11:52 +02:00
/*
* Liste des propal brouillons
*/
2021-02-22 13:14:13 +01:00
if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
2011-02-21 09:58:45 +01:00
$sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-02-22 13:14:13 +01:00
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE p.fk_statut = 0";
$sql .= " AND p.fk_soc = s.rowid";
$sql .= " AND p.entity IN (".getEntity('propal').")";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2021-02-22 13:14:13 +01:00
}
$resql = $db->query($sql);
2021-02-22 13:14:13 +01:00
if ($resql) {
$total = 0;
2010-08-09 17:42:57 +02:00
$num = $db->num_rows($resql);
$i = 0;
2021-02-22 13:14:13 +01:00
if ($num > 0) {
2010-08-09 17:42:57 +02:00
print '<table class="noborder"" width="100%">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
2021-02-22 13:14:13 +01:00
while ($i < $num) {
2010-08-09 17:42:57 +02:00
$obj = $db->fetch_object($resql);
2018-01-30 15:48:09 +01:00
print '<tr class="oddeven"><td>';
print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
2019-01-22 14:09:14 +01:00
print '</td><td class="right">';
2010-08-09 17:42:57 +02:00
print price($obj->price);
print "</td></tr>";
$i++;
$total += $obj->price;
}
if ($total > 0) {
2010-08-09 17:42:57 +02:00
print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
}
print "</table><br>";
}
$db->free($resql);
}
2004-02-07 19:36:36 +01:00
}
2021-10-23 17:18:35 +02:00
print '</div><div class="fichetwothirdright">';
2004-02-07 19:36:36 +01:00
/*
* Actions commerciales a faire
*/
2022-06-09 22:16:48 +02:00
if (isModEnabled('agenda')) {
2021-02-22 13:14:13 +01:00
show_array_actions_to_do(10);
}
2004-02-07 19:36:36 +01:00
2005-05-14 17:11:52 +02:00
/*
* Dernieres propales ouvertes
2005-05-14 17:11:52 +02:00
*/
2021-02-22 13:14:13 +01:00
if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
2011-02-21 09:58:45 +01:00
$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
2021-02-22 13:14:13 +01:00
$sql .= " p.rowid as propalid, p.total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."propal as p";
$sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-02-22 13:14:13 +01:00
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE p.fk_soc = s.rowid";
$sql .= " AND p.fk_statut = c.id";
$sql .= " AND p.fk_statut = 1";
$sql .= " AND p.entity IN (".getEntity('propal').")";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2021-02-22 13:14:13 +01:00
}
if ($socid) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = ".((int) $socid);
2021-02-22 13:14:13 +01:00
}
$sql .= " ORDER BY p.rowid DESC";
$sql .= $db->plimit(5, 0);
$resql = $db->query($sql);
2021-02-22 13:14:13 +01:00
if ($resql) {
2010-08-09 17:42:57 +02:00
$total = 0;
$num = $db->num_rows($resql);
$i = 0;
2021-02-22 13:14:13 +01:00
if ($num > 0) {
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
2010-08-09 17:42:57 +02:00
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
2021-02-22 13:14:13 +01:00
while ($i < $num) {
2010-08-09 17:42:57 +02:00
$obj = $db->fetch_object($resql);
2018-01-30 15:48:09 +01:00
print '<tr class="oddeven"><td>';
2011-06-13 10:15:30 +02:00
print '<a href="../propal.php?id='.$obj->propalid.'">';
print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
2010-08-09 17:42:57 +02:00
2011-02-21 09:58:45 +01:00
print "<td>";
$companystatic->id = $obj->socid;
$companystatic->name = $obj->name;
$companystatic->client = $obj->client;
$companystatic->canvas = $obj->canvas;
print $companystatic->getNomUrl(1, '', 44);
2011-02-21 09:58:45 +01:00
print "</td>\n";
2010-08-09 17:42:57 +02:00
print "<td align=\"right\">";
print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
2010-08-09 17:42:57 +02:00
print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
$i++;
$total += $obj->price;
}
2021-02-22 13:14:13 +01:00
if ($total > 0) {
2019-02-04 10:35:53 +01:00
print '<tr class="liste_total"><td colspan="3" class="right">'.$langs->trans("Total")."</td><td class=\"right\">".price($total)."</td></tr>";
2010-08-09 17:42:57 +02:00
}
print "</table><br>";
}
2020-05-21 15:05:19 +02:00
} else {
dol_print_error($db);
2008-03-31 06:08:28 +02:00
}
2004-02-07 19:36:36 +01:00
}
2004-02-27 12:52:17 +01:00
/*
* Societes a contacter
2004-02-27 12:52:17 +01:00
*
*/
2011-02-21 09:58:45 +01:00
$sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-02-22 13:14:13 +01:00
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fk_stcomm = 1";
$sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
2021-10-22 22:15:59 +02:00
if (empty($user->rights->societe->client->voir) && !$socid) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2021-02-22 13:14:13 +01:00
}
$sql .= " ORDER BY s.tms ASC";
$sql .= $db->plimit(15, 0);
$resql = $db->query($sql);
2021-02-22 13:14:13 +01:00
if ($resql) {
2010-08-09 17:42:57 +02:00
$num = $db->num_rows($resql);
$i = 0;
2021-02-22 13:14:13 +01:00
if ($num > 0) {
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">';
2011-06-13 10:15:30 +02:00
print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
2021-02-22 13:14:13 +01:00
while ($i < $num) {
2010-08-09 17:42:57 +02:00
$obj = $db->fetch_object($resql);
2018-01-30 15:48:09 +01:00
print '<tr class="oddeven"><td width="12%">';
$companystatic->id = $obj->socid;
$companystatic->name = $obj->name;
$companystatic->client = $obj->client;
$companystatic->canvas = $obj->canvas;
print $companystatic->getNomUrl(1, 'prospect', 44);
2011-02-21 09:58:45 +01:00
print '</td></tr>';
2010-08-09 17:42:57 +02:00
$i++;
}
print "</table><br>";
2004-02-27 12:52:17 +01:00
}
}
2004-02-07 19:36:36 +01:00
2021-10-23 17:18:35 +02:00
print '</div></div>';
2004-02-07 19:36:36 +01:00
2018-07-29 17:17:29 +02:00
// End of page
2012-02-02 07:49:50 +01:00
llxFooter();
$db->close();