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'));
49$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
50$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
53if (empty($page) || $page == -1) {
56$offset = $limit * $page;
63 $sortfield =
"c.date_contrat";
66$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
73$staticcontrat =
new Contrat($db);
78if ($id > 0 || !empty($ref)) {
80 $result = $product->fetch($id, $ref);
84 $parameters = array(
'id'=>$id);
85 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
90 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
94 $titre = $langs->trans(
"CardProduct".$product->type);
98 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
99 print $hookmanager->resPrint;
104 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
107 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
113 print
'<div class="fichecenter">';
115 print
'<div class="underbanner clearboth"></div>';
116 print
'<table class="border tableforfield" width="100%">';
123 print
'<div class="clearboth"></div>';
131 $sql .=
" sum(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
132 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now).
"'", 1, 0).
") as nb_running,";
133 $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,';
134 $sql .=
" sum(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed,';
135 $sql .=
" c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
136 $sql .=
" s.nom as name, s.rowid as socid, s.code_client";
137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
138 if (empty($user->rights->societe->client->voir) && !$socid) {
139 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
141 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
142 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
143 $sql .=
" WHERE c.rowid = cd.fk_contrat";
144 $sql .=
" AND c.fk_soc = s.rowid";
145 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
146 $sql .=
" AND cd.fk_product = ".((int) $product->id);
147 if (empty($user->rights->societe->client->voir) && !$socid) {
148 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
151 $sql .=
" AND s.rowid = ".((int) $socid);
153 $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";
154 $sql .= $db->order($sortfield, $sortorder);
161 $totalofrecords =
'';
163 $result = $db->query($sql);
164 $totalofrecords = $db->num_rows($result);
167 $sql .= $db->plimit($limit + 1, $offset);
169 $result = $db->query($sql);
171 $num = $db->num_rows($result);
173 $option =
'&id='.$product->id;
175 if ($limit > 0 && $limit != $conf->liste_limit) {
176 $option .=
'&limit='.((int) $limit);
178 if (!empty($search_month)) {
179 $option .=
'&search_month='.urlencode($search_month);
181 if (!empty($search_year)) {
182 $option .=
'&search_year='.urlencode($search_year);
185 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
186 print
'<input type="hidden" name="token" value="'.newToken().
'">';
187 if (!empty($sortfield)) {
188 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
190 if (!empty($sortorder)) {
191 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
194 print_barre_liste($langs->trans(
"Contrats"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
197 $option .=
'&page='.urlencode($page);
201 print
'<div class="div-table-responsive">';
202 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
204 print
'<tr class="liste_titre">';
205 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
206 print_liste_field_titre(
"Company", $_SERVER[
"PHP_SELF"],
"s.nom",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
207 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
208 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
210 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
211 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
212 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
215 $contracttmp =
new Contrat($db);
218 while ($i < min($num, $limit)) {
219 $objp = $db->fetch_object($result);
221 $contracttmp->id = $objp->rowid;
222 $contracttmp->ref = $objp->ref;
223 $contracttmp->ref_customer = $objp->ref_customer;
224 $contracttmp->ref_supplier = $objp->ref_supplier;
226 print
'<tr class="oddeven">';
228 print $contracttmp->getNomUrl(1);
230 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>';
231 print
"<td>".$objp->code_client.
"</td>\n";
232 print
"<td align=\"center\">";
233 print
dol_print_date($db->jdate($objp->date_contrat),
'dayhour').
"</td>";
236 print
'<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial :
'').
'</td>';
237 print
'<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late :
'').
'</td>';
238 print
'<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed :
'').
'</td>';
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $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.
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.
product_prepare_head($object)
Prepare array with list of tabs.
show_stats_for_company($product, $socid)
Show stats for company.
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.