26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 $langs->loadLangs(array(
'contracts',
'products',
'companies'));
38 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
39 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
40 if ($user->socid) $socid = $user->socid;
41 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
44 $hookmanager->initHooks(array(
'productstatscontract'));
49 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
50 $sortfield =
GETPOST(
"sortfield",
'alpha');
51 $sortorder =
GETPOST(
"sortorder",
'alpha');
53 if (empty($page) || $page == -1) { $page = 0; }
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) $sortorder =
"DESC";
58 if (!$sortfield) $sortfield =
"c.date_contrat";
65 $staticcontrat =
new Contrat($db);
68 $form =
new Form($db);
70 if ($id > 0 || !empty($ref))
73 $result = $product->fetch($id, $ref);
77 $parameters = array(
'id'=>$id);
78 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
79 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
81 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
86 $titre = $langs->trans(
"CardProduct".$product->type);
90 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
91 print $hookmanager->resPrint;
92 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
94 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
97 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
101 print '<div class="fichecenter">';
103 print '<div class="underbanner clearboth"></div>';
104 print '<table class="border tableforfield" width="100%">';
111 print '<div style="clear:both"></div>';
119 $sql .=
' sum('.$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
120 $sql .=
' sum('.$db->ifsql(
"cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now).
"'", 1, 0).
") as nb_running,";
121 $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,';
122 $sql .=
' sum('.$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed,';
123 $sql .=
" c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
124 $sql .=
" s.nom as name, s.rowid as socid, s.code_client";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
126 if (!$user->rights->societe->client->voir && !$socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
127 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
128 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
129 $sql .=
" WHERE c.rowid = cd.fk_contrat";
130 $sql .=
" AND c.fk_soc = s.rowid";
131 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
132 $sql .=
" AND cd.fk_product =".$product->id;
133 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
134 if ($socid) $sql .=
" AND s.rowid = ".$socid;
135 $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";
136 $sql .= $db->order($sortfield, $sortorder);
143 $totalofrecords =
'';
144 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
146 $result = $db->query($sql);
147 $totalofrecords = $db->num_rows($result);
150 $sql .= $db->plimit($limit + 1, $offset);
152 $result = $db->query($sql);
155 $num = $db->num_rows($result);
157 if ($limit > 0 && $limit != $conf->liste_limit) $option .=
'&limit='.urlencode($limit);
158 if (!empty($id)) $option .=
'&id='.$product->id;
159 if (!empty($search_month)) $option .=
'&search_month='.urlencode($search_month);
160 if (!empty($search_year)) $option .=
'&search_year='.urlencode($search_year);
162 print '<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
164 if (!empty($sortfield))
165 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
166 if (!empty($sortorder))
167 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
169 print_barre_liste($langs->trans(
"Contrats"), $page,
$_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
171 if (!empty($page)) $option .=
'&page='.urlencode($page);
174 print '<div class="div-table-responsive">';
175 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
177 print '<tr class="liste_titre">';
178 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
179 print_liste_field_titre(
"Company", $_SERVER[
"PHP_SELF"],
"s.nom",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
180 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
181 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
183 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
184 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
185 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
188 $contracttmp =
new Contrat($db);
192 while ($i < min($num, $limit))
194 $objp = $db->fetch_object($result);
196 $contracttmp->id = $objp->rowid;
197 $contracttmp->ref = $objp->ref;
198 $contracttmp->ref_customer = $objp->ref_customer;
199 $contracttmp->ref_supplier = $objp->ref_supplier;
201 print
'<tr class="oddeven">';
203 print $contracttmp->getNomUrl(1);
205 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>';
206 print
"<td>".$objp->code_client.
"</td>\n";
207 print
"<td align=\"center\">";
208 print
dol_print_date($db->jdate($objp->date_contrat),
'dayhour').
"</td>";
211 print
'<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial :
'').
'</td>';
212 print
'<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late :
'').
'</td>';
213 print
'<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed :
'').
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage contracts.
const TYPE_SERVICE
Service.
Class to manage lines of contracts.
show_stats_for_company($product, $socid)
Show stats for company.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
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.
product_prepare_head($object)
Prepare array with list of tabs.