dolibarr 20.0.0
contrat.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
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';
31
32// Load translation files required by the page
33$langs->loadLangs(array('contracts', 'products', 'companies'));
34
35$id = GETPOSTINT('id');
36$ref = GETPOST('ref', 'alpha');
37
38// Security check
39$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
40$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
41if ($user->socid) {
42 $socid = $user->socid;
43}
44
45// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
46$hookmanager->initHooks(array('productstatscontract'));
47
48// Load variable for pagination
49$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
50$sortfield = GETPOST('sortfield', 'aZ09comma');
51$sortorder = GETPOST('sortorder', 'aZ09comma');
52$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
53if (empty($page) || $page == -1) {
54 $page = 0;
55} // If $page is not defined, or '' or -1
56$offset = $limit * $page;
57$pageprev = $page - 1;
58$pagenext = $page + 1;
59if (!$sortorder) {
60 $sortorder = "DESC";
61}
62if (!$sortfield) {
63 $sortfield = "c.date_contrat";
64}
65
66$socid = 0;
67
68$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
69
70
71/*
72 * View
73 */
74
75$staticcontrat = new Contrat($db);
76$staticcontratligne = new ContratLigne($db);
77
78$form = new Form($db);
79
80if ($id > 0 || !empty($ref)) {
81 $product = new Product($db);
82 $result = $product->fetch($id, $ref);
83
84 $object = $product;
85
86 $parameters = array('id' => $id);
87 $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
88 if ($reshook < 0) {
89 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
90 }
91
92 llxHeader("", "", $langs->trans("CardProduct".$product->type), '', '', 0, 0, '', '', 'mod-product page-stats_contrat');
93
94 if ($result > 0) {
95 $head = product_prepare_head($product);
96 $titre = $langs->trans("CardProduct".$product->type);
97 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
98 print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
99
100 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
101 print $hookmanager->resPrint;
102 if ($reshook < 0) {
103 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104 }
105
106 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
107
108 $shownav = 1;
109 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
110 $shownav = 0;
111 }
112
113 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
114
115 print '<div class="fichecenter">';
116
117 print '<div class="underbanner clearboth"></div>';
118 print '<table class="border tableforfield" width="100%">';
119
120 $nboflines = show_stats_for_company($product, $socid);
121
122 print "</table>";
123
124 print '</div>';
125 print '<div class="clearboth"></div>';
126
127 print dol_get_fiche_end();
128
129
130 $now = dol_now();
131
132 $sql = "SELECT";
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";
142 }
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);
151 }
152 if ($socid) {
153 $sql .= " AND s.rowid = ".((int) $socid);
154 }
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);
157
158 //Calcul total qty and amount for global if full scan list
159 $total_ht = 0;
160 $total_qty = 0;
161
162 // Count total nb of records
163 $totalofrecords = '';
164 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
165 $result = $db->query($sql);
166 $totalofrecords = $db->num_rows($result);
167 }
168
169 $sql .= $db->plimit($limit + 1, $offset);
170
171 $result = $db->query($sql);
172 if ($result) {
173 $num = $db->num_rows($result);
174
175 $option = '&id='.$product->id;
176
177 if ($limit > 0 && $limit != $conf->liste_limit) {
178 $option .= '&limit='.((int) $limit);
179 }
180 /*
181 if (!empty($search_month)) {
182 $option .= '&search_month='.urlencode($search_month);
183 }
184 if (!empty($search_year)) {
185 $option .= '&search_year='.urlencode((string) ($search_year));
186 }
187 */
188
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.'"/>';
193 }
194 if (!empty($sortorder)) {
195 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
196 }
197
198 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
199 print_barre_liste($langs->trans("Contrats"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
200
201 if (!empty($page)) {
202 $option .= '&page='.urlencode((string) ($page));
203 }
204
205 $i = 0;
206 print '<div class="div-table-responsive">';
207 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
208
209 print '<tr class="liste_titre">';
210 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
211 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
212 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
213 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_contrat", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
214 //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$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 ');
218 print "</tr>\n";
219
220 $contracttmp = new Contrat($db);
221
222 if ($num > 0) {
223 while ($i < min($num, $limit)) {
224 $objp = $db->fetch_object($result);
225
226 $contracttmp->id = $objp->rowid;
227 $contracttmp->ref = $objp->ref;
228 $contracttmp->ref_customer = $objp->ref_customer;
229 $contracttmp->ref_supplier = $objp->ref_supplier;
230
231 print '<tr class="oddeven">';
232 print '<td>';
233 print $contracttmp->getNomUrl(1);
234 print "</td>\n";
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>";
239 //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
240 //print '<td align="right">';
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>';
244 //$contratstatic->LibStatut($objp->statut,5).'</td>';
245 print "</tr>\n";
246 $i++;
247 }
248 } else {
249 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
250 }
251
252 print '</table>';
253 print '</div>';
254 print '</form>';
255 } else {
256 dol_print_error($db);
257 }
258 $db->free($result);
259 }
260} else {
262}
263
264// End of page
265llxFooter();
266$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage contracts.
Class to manage lines of contracts.
Class to manage generation of HTML components Only common components must be here.
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.