dolibarr  20.0.0-alpha
commande.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-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
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
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('orders', 'products', 'companies'));
37 
38 $id = GETPOSTINT('id');
39 $ref = GETPOST('ref', 'alpha');
40 
41 // Security check
42 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
43 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
44 $socid = '';
45 if (!empty($user->socid)) {
46  $socid = $user->socid;
47 }
48 
49 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
50 $hookmanager->initHooks(array('productstatsorder'));
51 
52 // Load variable for pagination
53 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
54 $sortfield = GETPOST('sortfield', 'aZ09comma');
55 $sortorder = GETPOST('sortorder', 'aZ09comma');
56 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57 if (empty($page) || $page == -1) {
58  $page = 0;
59 } // If $page is not defined, or '' or -1
60 $offset = $limit * $page;
61 $pageprev = $page - 1;
62 $pagenext = $page + 1;
63 if (!$sortorder) {
64  $sortorder = "DESC";
65 }
66 if (!$sortfield) {
67  $sortfield = "c.date_commande";
68 }
69 $search_month = GETPOSTINT('search_month');
70 $search_year = GETPOSTINT('search_year');
71 if (GETPOSTISARRAY('search_status')) {
72  $search_status = implode(',', GETPOST('search_status', 'array:intcomma'));
73 } else {
74  $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma'));
75 }
76 
77 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
78  $search_month = '';
79  $search_year = '';
80  $search_status = '';
81 }
82 
83 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
84 
85 
86 /*
87  * View
88  */
89 
90 $orderstatic = new Commande($db);
91 $societestatic = new Societe($db);
92 
93 $form = new Form($db);
94 $formother = new FormOther($db);
95 $formorder = new FormOrder($db);
96 
97 if ($id > 0 || !empty($ref)) {
98  $product = new Product($db);
99  $result = $product->fetch($id, $ref);
100 
101  $object = $product;
102 
103  $parameters = array('id' => $id);
104  $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
105  if ($reshook < 0) {
106  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107  }
108 
109  llxHeader("", "", $langs->trans("CardProduct".$product->type));
110 
111  if ($result > 0) {
112  $head = product_prepare_head($product);
113  $titre = $langs->trans("CardProduct".$product->type);
114  $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
115  print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
116 
117  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
118  print $hookmanager->resPrint;
119  if ($reshook < 0) {
120  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
121  }
122 
123  $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
124 
125  $shownav = 1;
126  if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
127  $shownav = 0;
128  }
129 
130  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
131 
132  print '<div class="fichecenter">';
133 
134  print '<div class="underbanner clearboth"></div>';
135  print '<table class="border tableforfield" width="100%">';
136 
137  $nboflines = show_stats_for_company($product, $socid);
138 
139  print "</table>";
140 
141  print '</div>';
142  print '<div class="clearboth"></div>';
143 
144  print dol_get_fiche_end();
145 
146 
147  if ($user->hasRight('commande', 'lire')) {
148  $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client, c.rowid, d.total_ht as total_ht, c.ref,";
149  $sql .= " c.ref_client,";
150  $sql .= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.rowid, d.qty,";
151  $sql .= " c.date_livraison as delivery_date";
152  if (!$user->hasRight('societe', 'client', 'voir')) {
153  $sql .= ", sc.fk_soc, sc.fk_user ";
154  }
155  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
156  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
157  $sql .= ", ".MAIN_DB_PREFIX."commandedet as d";
158  if (!$user->hasRight('societe', 'client', 'voir')) {
159  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
160  }
161  $sql .= " WHERE c.fk_soc = s.rowid";
162  $sql .= " AND c.entity IN (".getEntity('commande').")";
163  $sql .= " AND d.fk_commande = c.rowid";
164  $sql .= " AND d.fk_product = ".((int) $product->id);
165  if (!empty($search_month)) {
166  $sql .= " AND MONTH(c.date_commande) IN (".$db->sanitize($search_month).")";
167  }
168  if (!empty($search_year)) {
169  $sql .= " AND YEAR(c.date_commande) IN (".$db->sanitize($search_year).")";
170  }
171  if (!$user->hasRight('societe', 'client', 'voir')) {
172  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
173  }
174  if ($socid) {
175  $sql .= " AND c.fk_soc = ".((int) $socid);
176  }
177 
178  if ($search_status != '') {
179  $sql .= " AND c.fk_statut IN (".$db->sanitize($search_status).")";
180  }
181 
182  $sql .= $db->order($sortfield, $sortorder);
183 
184  //Calcul total qty and amount for global if full scan list
185  $total_ht = 0;
186  $total_qty = 0;
187 
188  // Count total nb of records
189  $totalofrecords = '';
190  if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
191  $result = $db->query($sql);
192  $totalofrecords = $db->num_rows($result);
193  }
194 
195  $sql .= $db->plimit($limit + 1, $offset);
196 
197  $result = $db->query($sql);
198  if ($result) {
199  $num = $db->num_rows($result);
200 
201  $option = '&id='.$product->id;
202 
203  if ($limit > 0 && $limit != $conf->liste_limit) {
204  $option .= '&limit='.((int) $limit);
205  }
206  if (!empty($search_month)) {
207  $option .= '&search_month='.urlencode((string) ($search_month));
208  }
209  if (!empty($search_year)) {
210  $option .= '&search_year='.urlencode((string) ($search_year));
211  }
212 
213  if ($search_status != '') {
214  $option .= '&search_status='.urlencode($search_status);
215  }
216 
217  print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
218  print '<input type="hidden" name="token" value="'.newToken().'">';
219  if (!empty($sortfield)) {
220  print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
221  }
222  if (!empty($sortorder)) {
223  print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
224  }
225 
226  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
227  print_barre_liste($langs->trans("CustomersOrders"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
228 
229  if (!empty($page)) {
230  $option .= '&page='.urlencode((string) ($page));
231  }
232 
233  print '<div class="liste_titre liste_titre_bydiv centpercent">';
234  print '<div class="divsearchfield">';
235  print $langs->trans('Period').' ('.$langs->trans("OrderDate").') - ';
236  print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.($search_month > 0 ? $search_month : '').'"> ';
237  print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
238  print $langs->trans('Status');
239  $formorder->selectOrderStatus($search_status, 1, 'search_status');
240  print '<div style="vertical-align: middle; display: inline-block">';
241  print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
242  print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
243  print '</div>';
244  print '</div>';
245  print '</div>';
246 
247  $i = 0;
248  print '<div class="div-table-responsive">';
249  print '<table class="tagtable liste listwithfilterbefore" width="100%">';
250  print '<tr class="liste_titre">';
251  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", $option, '', $sortfield, $sortorder);
252  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
253  print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
254  print_liste_field_titre("OrderDate", $_SERVER["PHP_SELF"], "c.date_commande", "", $option, '', $sortfield, $sortorder, 'center ');
255  print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'c.date_livraison', '', $option, '', $sortfield, $sortorder, 'center ');
256  print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, '', $sortfield, $sortorder, 'center ');
257  print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "c.total_ht", "", $option, '', $sortfield, $sortorder, 'right ');
258  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.fk_statut", "", $option, '', $sortfield, $sortorder, 'right ');
259  print "</tr>\n";
260 
261  if ($num > 0) {
262  while ($i < min($num, $limit)) {
263  $objp = $db->fetch_object($result);
264 
265  $total_ht += $objp->total_ht;
266  $total_qty += $objp->qty;
267 
268  $orderstatic->id = $objp->commandeid;
269  $orderstatic->ref = $objp->ref;
270  $orderstatic->ref_client = $objp->ref_client;
271  $societestatic->fetch($objp->socid);
272 
273  print '<tr class="oddeven">';
274  print '<td>';
275  print $orderstatic->getNomUrl(1);
276  print "</td>\n";
277  print '<td>'.$societestatic->getNomUrl(1).'</td>';
278  print "<td>".$objp->code_client."</td>\n";
279  print '<td class="center">';
280  print dol_print_date($db->jdate($objp->date_commande), 'dayhour')."</td>";
281  // delivery planned date
282  print '<td class="center">';
283  print dol_print_date($db->jdate($objp->delivery_date), 'dayhour');
284  print '</td>';
285  print '<td class="center">'.$objp->qty."</td>\n";
286  print '<td align="right">'.price($objp->total_ht)."</td>\n";
287  print '<td align="right">'.$orderstatic->LibStatut($objp->statut, $objp->facture, 5).'</td>';
288  print "</tr>\n";
289  $i++;
290  }
291  }
292  print '<tr class="liste_total">';
293  if ($num < $limit && empty($offset)) {
294  print '<td>'.$langs->trans("Total").'</td>';
295  } else {
296  print '<td>'.$form->textwithpicto($langs->trans("Total"), $langs->trans("Totalforthispage")).'</td>';
297  }
298  print '<td colspan="3"></td>';
299  // delivery planned date
300  print '<td></td>';
301  print '<td class="center">'.$total_qty.'</td>';
302  print '<td align="right">'.price($total_ht).'</td>';
303  print '<td></td>';
304  print "</table>";
305  print "</div>";
306  print '</form>';
307  } else {
308  dol_print_error($db);
309  }
310  $db->free($result);
311  }
312  }
313 } else {
314  dol_print_error();
315 }
316 
317 // End of page
318 llxFooter();
319 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage customers orders.
Class to manage generation of HTML components Only common components must be here.
Class to manage HTML output components for orders Before adding component here, check they are not in...
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
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.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:37
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.