29require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
43$langs->loadLangs(array(
'contracts',
'products',
'companies'));
52$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
53$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
56 $socid = $user->socid;
60$hookmanager->initHooks(array(
'productstatscontract'));
64$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
65$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67if (empty($page) || $page == -1) {
70$offset = $limit * $page;
77 $sortfield =
"c.date_contrat";
80$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
87$staticcontrat =
new Contrat($db);
92if ($id > 0 || !empty($ref)) {
94 $result = $product->fetch($id, $ref);
98 $parameters = array(
'id' => $id);
99 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
101 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
104 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'mod-product page-stats_contrat');
108 $titre = $langs->trans(
"CardProduct".$product->type);
112 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
113 print $hookmanager->resPrint;
115 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
118 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
121 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
125 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
127 print
'<div class="fichecenter">';
129 print
'<div class="clearboth"></div>';
130 print
'<table class="noborder tableforfield centpercent">';
137 print
'<div class="clearboth"></div>';
145 $sql .=
" sum(".$db->ifsql(
"cd.statut=0",
'1',
'0').
') as nb_initial,';
146 $sql .=
" sum(".$db->ifsql(
"cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now).
"'",
'1',
'0').
") as nb_running,";
147 $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,';
148 $sql .=
" sum(".$db->ifsql(
"cd.statut=5",
'1',
'0').
') as nb_closed,';
149 $sql .=
" c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
150 $sql .=
" s.nom as name, s.rowid as socid, s.code_client";
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
152 if (!$user->hasRight(
'societe',
'client',
'voir')) {
153 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
155 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
156 $sql .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
157 $sql .=
" WHERE c.rowid = cd.fk_contrat";
158 $sql .=
" AND c.fk_soc = s.rowid";
159 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
160 $sql .=
" AND cd.fk_product = ".((int) $product->id);
161 if (!$user->hasRight(
'societe',
'client',
'voir')) {
162 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
165 $sql .=
" AND s.rowid = ".((int) $socid);
167 $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";
168 $sql .= $db->order($sortfield, $sortorder);
175 $totalofrecords =
'';
177 $result = $db->query($sql);
178 $totalofrecords = $db->num_rows($result);
181 $sql .= $db->plimit($limit + 1, $offset);
183 $result = $db->query($sql);
185 $num = $db->num_rows($result);
187 $option =
'&id='.$product->id;
189 if ($limit > 0 && $limit !=
$conf->liste_limit) {
190 $option .=
'&limit='.((int) $limit);
192 if (!empty($search_month)) {
193 $option .=
'&search_month='.urlencode((
string) $search_month);
195 if (!empty($search_year)) {
196 $option .=
'&search_year='.urlencode((
string) $search_year);
199 print
'<span id="anchorundermenu" class="anchorundermenu"></span>';
200 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
201 print
'<input type="hidden" name="token" value="'.newToken().
'">';
202 print
'<input type="hidden" name="page_y" value="">';
203 if (!empty($sortfield)) {
204 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
206 if (!empty($sortorder)) {
207 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
211 print_barre_liste($langs->trans(
"Contracts"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
214 $option .=
'&page='.urlencode((
string) ($page));
218 print
'<div class="div-table-responsive">';
219 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
221 print
'<tr class="liste_titre">';
222 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
223 print_liste_field_titre(
"Company", $_SERVER[
"PHP_SELF"],
"s.nom",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
224 print_liste_field_titre(
"CustomerCode", $_SERVER[
"PHP_SELF"],
"s.code_client",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
225 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
227 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
228 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
229 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1,
'class="nochangebackground"'), $_SERVER[
"PHP_SELF"],
"",
'',
'',
'align="center" width="16"', $sortfield, $sortorder,
'maxwidthsearch ');
232 $contracttmp =
new Contrat($db);
235 while ($i < min($num, $limit)) {
236 $objp = $db->fetch_object($result);
238 $contracttmp->id = $objp->rowid;
239 $contracttmp->ref = $objp->ref;
240 $contracttmp->ref_customer = $objp->ref_customer;
241 $contracttmp->ref_supplier = $objp->ref_supplier;
243 print
'<tr class="oddeven">';
245 print $contracttmp->getNomUrl(1);
247 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>';
248 print
"<td>".$objp->code_client.
"</td>\n";
249 print
"<td align=\"center\">";
250 print
dol_print_date($db->jdate($objp->date_contrat),
'dayhour').
"</td>";
253 print
'<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial :
'').
'</td>';
254 print
'<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late :
'').
'</td>';
255 print
'<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed :
'').
'</td>';
261 print
'<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
268 dol_print_error($db);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
dol_now($mode='gmt')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.