27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33$langs->loadLangs(array(
'contracts',
'products',
'companies'));
39$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
40$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
42 $socid = $user->socid;
46$hookmanager->initHooks(array(
'productstatscontract'));
50$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
53if (empty($page) || $page == -1) {
56$offset = $limit * $page;
63 $sortfield =
"c.date_contrat";
68$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
75$staticcontrat =
new Contrat($db);
80if ($id > 0 || !empty($ref)) {
82 $result = $product->fetch($id, $ref);
86 $parameters = array(
'id' => $id);
87 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
92 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'',
'', 0, 0,
'',
'',
'mod-product page-stats_contrat');
96 $titre = $langs->trans(
"CardProduct".$product->type);
100 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
101 print $hookmanager->resPrint;
106 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
109 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
113 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
115 print
'<div class="fichecenter">';
117 print
'<div class="underbanner clearboth"></div>';
118 print
'<table class="border tableforfield" width="100%">';
125 print
'<div class="clearboth"></div>';
133 $sql .=
" sum(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
134 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now).
"'", 1, 0).
") as nb_running,";
135 $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,';
136 $sql .=
" sum(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed,';
137 $sql .=
" c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
138 $sql .=
" s.nom as name, s.rowid as socid, s.code_client";
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
140 if (!$user->hasRight(
'societe',
'client',
'voir')) {
141 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
143 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
144 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
145 $sql .=
" WHERE c.rowid = cd.fk_contrat";
146 $sql .=
" AND c.fk_soc = s.rowid";
147 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
148 $sql .=
" AND cd.fk_product = ".((int) $product->id);
149 if (!$user->hasRight(
'societe',
'client',
'voir')) {
150 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
153 $sql .=
" AND s.rowid = ".((int) $socid);
155 $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";
156 $sql .= $db->order($sortfield, $sortorder);
163 $totalofrecords =
'';
165 $result = $db->query($sql);
166 $totalofrecords = $db->num_rows($result);
169 $sql .= $db->plimit($limit + 1, $offset);
171 $result = $db->query($sql);
173 $num = $db->num_rows($result);
175 $option =
'&id='.$product->id;
177 if ($limit > 0 && $limit != $conf->liste_limit) {
178 $option .=
'&limit='.((int) $limit);
189 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
190 print
'<input type="hidden" name="token" value="'.newToken().
'">';
191 if (!empty($sortfield)) {
192 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
194 if (!empty($sortorder)) {
195 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
199 print_barre_liste($langs->trans(
"Contrats"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
202 $option .=
'&page='.urlencode((
string) ($page));
206 print
'<div class="div-table-responsive">';
207 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
209 print
'<tr class="liste_titre">';
210 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
211 print_liste_field_titre(
"Company", $_SERVER[
"PHP_SELF"],
"s.nom",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
212 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
213 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
215 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
216 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
217 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
220 $contracttmp =
new Contrat($db);
223 while ($i < min($num, $limit)) {
224 $objp = $db->fetch_object($result);
226 $contracttmp->id = $objp->rowid;
227 $contracttmp->ref = $objp->ref;
228 $contracttmp->ref_customer = $objp->ref_customer;
229 $contracttmp->ref_supplier = $objp->ref_supplier;
231 print
'<tr class="oddeven">';
233 print $contracttmp->getNomUrl(1);
235 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>';
236 print
"<td>".$objp->code_client.
"</td>\n";
237 print
"<td align=\"center\">";
238 print
dol_print_date($db->jdate($objp->date_contrat),
'dayhour').
"</td>";
241 print
'<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial :
'').
'</td>';
242 print
'<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late :
'').
'</td>';
243 print
'<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed :
'').
'</td>';
249 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()
Empty header.
Class to manage contracts.
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)
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
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.