28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
42$langs->loadLangs(array(
'contracts',
'products',
'companies'));
48$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
49$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
51 $socid = $user->socid;
55$hookmanager->initHooks(array(
'productstatscontract'));
59$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
60$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
62if (empty($page) || $page == -1) {
65$offset = $limit * $page;
72 $sortfield =
"c.date_contrat";
77$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
84$staticcontrat =
new Contrat($db);
89if ($id > 0 || !empty($ref)) {
91 $result = $product->fetch($id, $ref);
95 $parameters = array(
'id' => $id);
96 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
101 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'mod-product page-stats_contrat');
105 $titre = $langs->trans(
"CardProduct".$product->type);
109 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
110 print $hookmanager->resPrint;
115 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
118 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
122 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
124 print
'<div class="fichecenter">';
126 print
'<div class="underbanner clearboth"></div>';
127 print
'<table class="border tableforfield" width="100%">';
134 print
'<div class="clearboth"></div>';
142 $sql .=
" sum(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
143 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now).
"'", 1, 0).
") as nb_running,";
144 $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,';
145 $sql .=
" sum(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed,';
146 $sql .=
" c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
147 $sql .=
" s.nom as name, s.rowid as socid, s.code_client";
148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
149 if (!$user->hasRight(
'societe',
'client',
'voir')) {
150 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
152 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
153 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
154 $sql .=
" WHERE c.rowid = cd.fk_contrat";
155 $sql .=
" AND c.fk_soc = s.rowid";
156 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
157 $sql .=
" AND cd.fk_product = ".((int) $product->id);
158 if (!$user->hasRight(
'societe',
'client',
'voir')) {
159 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
162 $sql .=
" AND s.rowid = ".((int) $socid);
164 $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";
165 $sql .= $db->order($sortfield, $sortorder);
172 $totalofrecords =
'';
174 $result = $db->query($sql);
175 $totalofrecords = $db->num_rows($result);
178 $sql .= $db->plimit($limit + 1, $offset);
180 $result = $db->query($sql);
182 $num = $db->num_rows($result);
184 $option =
'&id='.$product->id;
186 if ($limit > 0 && $limit !=
$conf->liste_limit) {
187 $option .=
'&limit='.((int) $limit);
198 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
199 print
'<input type="hidden" name="token" value="'.newToken().
'">';
200 if (!empty($sortfield)) {
201 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
203 if (!empty($sortorder)) {
204 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
208 print_barre_liste($langs->trans(
"Contrats"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
211 $option .=
'&page='.urlencode((
string) ($page));
215 print
'<div class="div-table-responsive">';
216 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
218 print
'<tr class="liste_titre">';
219 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
220 print_liste_field_titre(
"Company", $_SERVER[
"PHP_SELF"],
"s.nom",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
221 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
222 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
224 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
225 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
226 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
229 $contracttmp =
new Contrat($db);
232 while ($i < min($num, $limit)) {
233 $objp = $db->fetch_object($result);
235 $contracttmp->id = $objp->rowid;
236 $contracttmp->ref = $objp->ref;
237 $contracttmp->ref_customer = $objp->ref_customer;
238 $contracttmp->ref_supplier = $objp->ref_supplier;
240 print
'<tr class="oddeven">';
242 print $contracttmp->getNomUrl(1);
244 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>';
245 print
"<td>".$objp->code_client.
"</td>\n";
246 print
"<td align=\"center\">";
247 print
dol_print_date($db->jdate($objp->date_contrat),
'dayhour').
"</td>";
250 print
'<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial :
'').
'</td>';
251 print
'<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late :
'').
'</td>';
252 print
'<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed :
'').
'</td>';
258 print
'<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage lines of contracts.
Class to manage products or services.
const TYPE_SERVICE
Service.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
product_prepare_head($object)
Prepare array with list of tabs.
show_stats_for_company($product, $socid)
Show stats for a product.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.