2005-09-04 23:42:55 +02:00
|
|
|
<?php
|
2007-01-02 16:27:51 +01:00
|
|
|
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2009-10-29 03:15:37 +01:00
|
|
|
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
|
2005-09-04 23:42:55 +02: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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-09-04 23:42:55 +02: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/>.
|
2005-09-04 23:42:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-27 20:19:51 +01:00
|
|
|
* \file htdocs/product/stats/contrat.php
|
2011-08-08 18:07:47 +02:00
|
|
|
* \ingroup product service contrat
|
2008-10-27 20:19:51 +01:00
|
|
|
* \brief Page des stats des contrats pour un produit
|
|
|
|
|
*/
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../../main.inc.php';
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2018-05-27 00:06:49 +02:00
|
|
|
// Load translation files required by the page
|
|
|
|
|
$langs->loadLangs(array('contracts', 'products', 'companies'));
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2012-02-11 11:44:15 +01:00
|
|
|
$id = GETPOST('id', 'int');
|
|
|
|
|
$ref = GETPOST('ref', 'alpha');
|
|
|
|
|
|
2009-05-04 10:31:42 +02:00
|
|
|
// Security check
|
2019-12-16 13:06:25 +01:00
|
|
|
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
|
|
|
|
|
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($user->socid) {
|
|
|
|
|
$socid = $user->socid;
|
|
|
|
|
}
|
2009-05-04 10:31:42 +02:00
|
|
|
|
2017-06-10 12:56:28 +02:00
|
|
|
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
2013-06-11 11:46:38 +02:00
|
|
|
$hookmanager->initHooks(array('productstatscontract'));
|
|
|
|
|
|
2018-07-05 15:53:28 +02:00
|
|
|
// Load variable for pagination
|
2019-12-16 13:06:25 +01:00
|
|
|
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
|
2022-01-13 11:09:37 +01:00
|
|
|
$sortfield = GETPOST('sortfield', 'aZ09comma');
|
|
|
|
|
$sortorder = GETPOST('sortorder', 'aZ09comma');
|
2020-03-13 13:07:11 +01:00
|
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
|
2021-02-26 14:25:17 +01:00
|
|
|
if (empty($page) || $page == -1) {
|
|
|
|
|
$page = 0;
|
|
|
|
|
} // If $page is not defined, or '' or -1
|
2018-07-05 15:53:28 +02:00
|
|
|
$offset = $limit * $page;
|
2010-11-20 14:08:44 +01:00
|
|
|
$pageprev = $page - 1;
|
|
|
|
|
$pagenext = $page + 1;
|
2021-02-26 14:25:17 +01:00
|
|
|
if (!$sortorder) {
|
|
|
|
|
$sortorder = "DESC";
|
|
|
|
|
}
|
|
|
|
|
if (!$sortfield) {
|
|
|
|
|
$sortfield = "c.date_contrat";
|
|
|
|
|
}
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2021-05-21 15:54:11 +02:00
|
|
|
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
|
|
|
|
|
|
2005-09-04 23:42:55 +02:00
|
|
|
|
|
|
|
|
/*
|
2008-10-27 20:19:51 +01:00
|
|
|
* View
|
2005-09-04 23:42:55 +02:00
|
|
|
*/
|
2008-10-27 20:19:51 +01:00
|
|
|
|
2019-12-16 13:06:25 +01:00
|
|
|
$staticcontrat = new Contrat($db);
|
|
|
|
|
$staticcontratligne = new ContratLigne($db);
|
2008-10-27 20:19:51 +01:00
|
|
|
|
2011-11-08 10:18:45 +01:00
|
|
|
$form = new Form($db);
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($id > 0 || !empty($ref)) {
|
2009-04-27 22:37:50 +02:00
|
|
|
$product = new Product($db);
|
2012-07-06 10:22:37 +02:00
|
|
|
$result = $product->fetch($id, $ref);
|
2014-09-13 19:04:25 +02:00
|
|
|
|
2015-11-07 15:13:51 +01:00
|
|
|
$object = $product;
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2019-12-16 13:06:25 +01:00
|
|
|
$parameters = array('id'=>$id);
|
|
|
|
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($reshook < 0) {
|
|
|
|
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
|
|
|
|
}
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
llxHeader("", "", $langs->trans("CardProduct".$product->type));
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($result > 0) {
|
2019-12-16 13:06:25 +01:00
|
|
|
$head = product_prepare_head($product);
|
|
|
|
|
$titre = $langs->trans("CardProduct".$product->type);
|
|
|
|
|
$picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
|
2020-10-22 22:50:03 +02:00
|
|
|
print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
|
2014-09-13 19:04:25 +02:00
|
|
|
|
2019-12-16 13:06:25 +01:00
|
|
|
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
|
2020-10-31 14:32:18 +01:00
|
|
|
print $hookmanager->resPrint;
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($reshook < 0) {
|
|
|
|
|
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
|
|
|
|
}
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$shownav = 1;
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
|
|
|
|
|
$shownav = 0;
|
|
|
|
|
}
|
2017-06-12 16:26:25 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<div class="fichecenter">';
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
|
|
print '<table class="border tableforfield" width="100%">';
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$nboflines = show_stats_for_company($product, $socid);
|
2009-06-08 20:14:37 +02:00
|
|
|
|
2009-10-29 03:15:37 +01:00
|
|
|
print "</table>";
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print '</div>';
|
|
|
|
|
print '<div style="clear:both"></div>';
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2020-10-27 18:19:31 +01:00
|
|
|
print dol_get_fiche_end();
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2009-06-08 20:14:37 +02:00
|
|
|
|
2019-12-16 13:06:25 +01:00
|
|
|
$now = dol_now();
|
2005-09-04 23:42:55 +02:00
|
|
|
|
2009-10-29 03:15:37 +01:00
|
|
|
$sql = "SELECT";
|
2021-08-28 03:09:18 +02:00
|
|
|
$sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
|
|
|
|
|
$sql .= " sum(".$db->ifsql("cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now)."'", 1, 0).") as nb_running,";
|
|
|
|
|
$sql .= " sum(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite <= '".$db->idate($now)."')", 1, 0).') as nb_late,';
|
|
|
|
|
$sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
|
2019-12-16 13:06:25 +01:00
|
|
|
$sql .= " c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
|
|
|
|
|
$sql .= " s.nom as name, s.rowid as socid, s.code_client";
|
|
|
|
|
$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-26 14:25:17 +01:00
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
|
|
|
|
}
|
2019-12-16 13:06:25 +01:00
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
|
|
|
|
|
$sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
|
|
|
|
|
$sql .= " WHERE c.rowid = cd.fk_contrat";
|
|
|
|
|
$sql .= " AND c.fk_soc = s.rowid";
|
|
|
|
|
$sql .= " AND c.entity IN (".getEntity('contract').")";
|
2021-06-09 15:36:47 +02:00
|
|
|
$sql .= " AND cd.fk_product = ".((int) $product->id);
|
2021-10-22 22:15:59 +02:00
|
|
|
if (empty($user->rights->societe->client->voir) && !$socid) {
|
2021-08-23 17:41:11 +02:00
|
|
|
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
2021-02-26 14:25:17 +01:00
|
|
|
}
|
|
|
|
|
if ($socid) {
|
2021-03-22 13:31:06 +01:00
|
|
|
$sql .= " AND s.rowid = ".((int) $socid);
|
2021-02-26 14:25:17 +01:00
|
|
|
}
|
2019-12-16 13:06:25 +01:00
|
|
|
$sql .= " GROUP BY c.rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut, s.nom, s.rowid, s.code_client";
|
|
|
|
|
$sql .= $db->order($sortfield, $sortorder);
|
2018-07-05 15:53:28 +02:00
|
|
|
|
|
|
|
|
//Calcul total qty and amount for global if full scan list
|
2019-12-16 13:06:25 +01:00
|
|
|
$total_ht = 0;
|
|
|
|
|
$total_qty = 0;
|
2018-07-05 15:57:27 +02:00
|
|
|
|
2018-07-05 15:53:28 +02:00
|
|
|
// Count total nb of records
|
|
|
|
|
$totalofrecords = '';
|
2021-02-26 14:25:17 +01:00
|
|
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
2018-07-05 15:53:28 +02:00
|
|
|
$result = $db->query($sql);
|
|
|
|
|
$totalofrecords = $db->num_rows($result);
|
|
|
|
|
}
|
2018-07-05 15:57:27 +02:00
|
|
|
|
2018-07-05 15:53:28 +02:00
|
|
|
$sql .= $db->plimit($limit + 1, $offset);
|
2009-10-29 03:15:37 +01:00
|
|
|
|
|
|
|
|
$result = $db->query($sql);
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($result) {
|
2009-10-29 03:15:37 +01:00
|
|
|
$num = $db->num_rows($result);
|
2020-05-05 16:33:02 +02:00
|
|
|
|
2022-10-13 09:10:22 +02:00
|
|
|
$option .= '&id='.$product->id;
|
|
|
|
|
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($limit > 0 && $limit != $conf->liste_limit) {
|
|
|
|
|
$option .= '&limit='.urlencode($limit);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($search_month)) {
|
|
|
|
|
$option .= '&search_month='.urlencode($search_month);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($search_year)) {
|
|
|
|
|
$option .= '&search_year='.urlencode($search_year);
|
|
|
|
|
}
|
2019-12-16 13:06:25 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
|
2022-04-06 09:19:56 +02:00
|
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
2021-02-26 14:25:17 +01:00
|
|
|
if (!empty($sortfield)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
|
2021-02-26 14:25:17 +01:00
|
|
|
}
|
|
|
|
|
if (!empty($sortorder)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
|
2021-02-26 14:25:17 +01:00
|
|
|
}
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
print_barre_liste($langs->trans("Contrats"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
|
2020-05-05 16:33:02 +02:00
|
|
|
|
2021-02-26 14:25:17 +01:00
|
|
|
if (!empty($page)) {
|
|
|
|
|
$option .= '&page='.urlencode($page);
|
|
|
|
|
}
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$i = 0;
|
|
|
|
|
print '<div class="div-table-responsive">';
|
2015-10-09 20:00:43 +02:00
|
|
|
print '<table class="tagtable liste listwithfilterbefore" width="100%">';
|
2009-10-29 03:15:37 +01:00
|
|
|
|
|
|
|
|
print '<tr class="liste_titre">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&id=".$product->id, '', $sortfield, $sortorder);
|
|
|
|
|
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&id=".$product->id, '', $sortfield, $sortorder);
|
|
|
|
|
print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&id=".$product->id, '', $sortfield, $sortorder);
|
|
|
|
|
print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_contrat", "", "&id=".$product->id, 'align="center"', $sortfield, $sortorder);
|
2017-08-02 13:31:53 +02:00
|
|
|
//print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&id=".$product->id,'align="right"',$sortfield,$sortorder);
|
2020-02-10 21:28:49 +01:00
|
|
|
print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
|
|
|
|
|
print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
|
|
|
|
|
print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
|
2009-10-29 03:15:37 +01:00
|
|
|
print "</tr>\n";
|
|
|
|
|
|
2019-12-16 13:06:25 +01:00
|
|
|
$contracttmp = new Contrat($db);
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2021-02-26 14:25:17 +01:00
|
|
|
if ($num > 0) {
|
|
|
|
|
while ($i < min($num, $limit)) {
|
2009-10-29 03:15:37 +01:00
|
|
|
$objp = $db->fetch_object($result);
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2017-12-21 23:48:33 +01:00
|
|
|
$contracttmp->id = $objp->rowid;
|
|
|
|
|
$contracttmp->ref = $objp->ref;
|
|
|
|
|
$contracttmp->ref_customer = $objp->ref_customer;
|
|
|
|
|
$contracttmp->ref_supplier = $objp->ref_supplier;
|
2009-10-29 03:15:37 +01:00
|
|
|
|
2017-04-14 11:22:48 +02:00
|
|
|
print '<tr class="oddeven">';
|
2017-12-21 23:48:33 +01:00
|
|
|
print '<td>';
|
|
|
|
|
print $contracttmp->getNomUrl(1);
|
|
|
|
|
print "</td>\n";
|
2019-01-27 11:55:16 +01:00
|
|
|
print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).'</a></td>';
|
2009-10-29 03:15:37 +01:00
|
|
|
print "<td>".$objp->code_client."</td>\n";
|
|
|
|
|
print "<td align=\"center\">";
|
2017-09-17 18:08:23 +02:00
|
|
|
print dol_print_date($db->jdate($objp->date_contrat), 'dayhour')."</td>";
|
2009-10-29 03:15:37 +01:00
|
|
|
//print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
|
|
|
|
|
//print '<td align="right">';
|
2019-12-16 13:06:25 +01:00
|
|
|
print '<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial : '').'</td>';
|
|
|
|
|
print '<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late : '').'</td>';
|
|
|
|
|
print '<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed : '').'</td>';
|
2009-10-29 03:15:37 +01:00
|
|
|
//$contratstatic->LibStatut($objp->statut,5).'</td>';
|
|
|
|
|
print "</tr>\n";
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-11 10:37:58 +02:00
|
|
|
|
2016-11-27 11:41:10 +01:00
|
|
|
print '</table>';
|
|
|
|
|
print '</div>';
|
|
|
|
|
print '</form>';
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2009-10-29 03:15:37 +01:00
|
|
|
dol_print_error($db);
|
|
|
|
|
}
|
|
|
|
|
$db->free($result);
|
|
|
|
|
}
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2009-04-27 22:37:50 +02:00
|
|
|
dol_print_error();
|
2005-09-04 23:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-14 09:55:58 +02:00
|
|
|
// End of page
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2012-07-06 10:22:37 +02:00
|
|
|
$db->close();
|