dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array('contracts', 'products', 'companies'));
35
36$id = GETPOSTINT('id');
37$ref = GETPOST('ref', 'alpha');
38
39// Security check
40$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
41$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
42if ($user->socid) {
43 $socid = $user->socid;
44}
45
46// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
47$hookmanager->initHooks(array('productstatscontract'));
48
49// Load variable for pagination
50$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
51$sortfield = GETPOST('sortfield', 'aZ09comma');
52$sortorder = GETPOST('sortorder', 'aZ09comma');
53$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
54if (empty($page) || $page == -1) {
55 $page = 0;
56} // If $page is not defined, or '' or -1
57$offset = $limit * $page;
58$pageprev = $page - 1;
59$pagenext = $page + 1;
60if (!$sortorder) {
61 $sortorder = "DESC";
62}
63if (!$sortfield) {
64 $sortfield = "c.date_contrat";
65}
66
67$socid = 0;
68
69$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
70
71
72/*
73 * View
74 */
75
76$staticcontrat = new Contrat($db);
77$staticcontratligne = new ContratLigne($db);
78
79$form = new Form($db);
80
81if ($id > 0 || !empty($ref)) {
82 $product = new Product($db);
83 $result = $product->fetch($id, $ref);
84
85 $object = $product;
86
87 $parameters = array('id' => $id);
88 $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
89 if ($reshook < 0) {
90 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 }
92
93 llxHeader("", "", $langs->trans("CardProduct".$product->type), '', 0, 0, '', '', 'mod-product page-stats_contrat');
94
95 if ($result > 0) {
96 $head = product_prepare_head($product);
97 $titre = $langs->trans("CardProduct".$product->type);
98 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
99 print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
100
101 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
102 print $hookmanager->resPrint;
103 if ($reshook < 0) {
104 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105 }
106
107 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
108
109 $shownav = 1;
110 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
111 $shownav = 0;
112 }
113
114 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
115
116 print '<div class="fichecenter">';
117
118 print '<div class="underbanner clearboth"></div>';
119 print '<table class="border tableforfield" width="100%">';
120
121 $nboflines = show_stats_for_company($product, $socid);
122
123 print "</table>";
124
125 print '</div>';
126 print '<div class="clearboth"></div>';
127
128 print dol_get_fiche_end();
129
130
131 $now = dol_now();
132
133 $sql = "SELECT";
134 $sql .= " sum(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
135 $sql .= " sum(".$db->ifsql("cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now)."'", 1, 0).") as nb_running,";
136 $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,';
137 $sql .= " sum(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed,';
138 $sql .= " c.rowid as rowid, c.ref, c.ref_customer, c.ref_supplier, c.date_contrat, c.statut as statut,";
139 $sql .= " s.nom as name, s.rowid as socid, s.code_client";
140 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
141 if (!$user->hasRight('societe', 'client', 'voir')) {
142 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
143 }
144 $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
145 $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd";
146 $sql .= " WHERE c.rowid = cd.fk_contrat";
147 $sql .= " AND c.fk_soc = s.rowid";
148 $sql .= " AND c.entity IN (".getEntity('contract').")";
149 $sql .= " AND cd.fk_product = ".((int) $product->id);
150 if (!$user->hasRight('societe', 'client', 'voir')) {
151 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
152 }
153 if ($socid) {
154 $sql .= " AND s.rowid = ".((int) $socid);
155 }
156 $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";
157 $sql .= $db->order($sortfield, $sortorder);
158
159 //Calcul total qty and amount for global if full scan list
160 $total_ht = 0;
161 $total_qty = 0;
162
163 // Count total nb of records
164 $totalofrecords = '';
165 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
166 $result = $db->query($sql);
167 $totalofrecords = $db->num_rows($result);
168 }
169
170 $sql .= $db->plimit($limit + 1, $offset);
171
172 $result = $db->query($sql);
173 if ($result) {
174 $num = $db->num_rows($result);
175
176 $option = '&id='.$product->id;
177
178 if ($limit > 0 && $limit != $conf->liste_limit) {
179 $option .= '&limit='.((int) $limit);
180 }
181 /*
182 if (!empty($search_month)) {
183 $option .= '&search_month='.urlencode($search_month);
184 }
185 if (!empty($search_year)) {
186 $option .= '&search_year='.urlencode((string) ($search_year));
187 }
188 */
189
190 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
191 print '<input type="hidden" name="token" value="'.newToken().'">';
192 if (!empty($sortfield)) {
193 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
194 }
195 if (!empty($sortorder)) {
196 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
197 }
198
199 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
200 print_barre_liste($langs->trans("Contrats"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
201
202 if (!empty($page)) {
203 $option .= '&page='.urlencode((string) ($page));
204 }
205
206 $i = 0;
207 print '<div class="div-table-responsive">';
208 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
209
210 print '<tr class="liste_titre">';
211 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
212 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
213 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
214 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_contrat", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
215 //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
216 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_INITIAL, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
217 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_OPEN, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
218 print_liste_field_titre($staticcontratligne->LibStatut($staticcontratligne::STATUS_CLOSED, 3, -1, 'class="nochangebackground"'), $_SERVER["PHP_SELF"], "", '', '', 'align="center" width="16"', $sortfield, $sortorder, 'maxwidthsearch ');
219 print "</tr>\n";
220
221 $contracttmp = new Contrat($db);
222
223 if ($num > 0) {
224 while ($i < min($num, $limit)) {
225 $objp = $db->fetch_object($result);
226
227 $contracttmp->id = $objp->rowid;
228 $contracttmp->ref = $objp->ref;
229 $contracttmp->ref_customer = $objp->ref_customer;
230 $contracttmp->ref_supplier = $objp->ref_supplier;
231
232 print '<tr class="oddeven">';
233 print '<td>';
234 print $contracttmp->getNomUrl(1);
235 print "</td>\n";
236 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>';
237 print "<td>".$objp->code_client."</td>\n";
238 print "<td align=\"center\">";
239 print dol_print_date($db->jdate($objp->date_contrat), 'dayhour')."</td>";
240 //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
241 //print '<td align="right">';
242 print '<td class="center">'.($objp->nb_initial > 0 ? $objp->nb_initial : '').'</td>';
243 print '<td class="center">'.($objp->nb_running + $objp->nb_late > 0 ? $objp->nb_running + $objp->nb_late : '').'</td>';
244 print '<td class="center">'.($objp->nb_closed > 0 ? $objp->nb_closed : '').'</td>';
245 //$contratstatic->LibStatut($objp->statut,5).'</td>';
246 print "</tr>\n";
247 $i++;
248 }
249 } else {
250 print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
251 }
252
253 print '</table>';
254 print '</div>';
255 print '</form>';
256 } else {
257 dol_print_error($db);
258 }
259 $db->free($result);
260 }
261} else {
263}
264
265// End of page
266llxFooter();
267$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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.
llxFooter()
Footer empty.
Definition document.php:107
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a 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.