dolibarr 20.0.0
commande_fournisseur.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('companies', 'bills', 'products', 'orders'));
39
40$id = GETPOSTINT('id');
41$ref = GETPOST('ref', 'alpha');
42$batch = GETPOST('batch', 'alpha');
43$objectid = GETPOSTINT('productid');
44
45// Security check
46$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
47$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
48$socid = '';
49if (!empty($user->socid)) {
50 $socid = $user->socid;
51}
52
53// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
54$hookmanager->initHooks(array('batchproductstatssupplierorder'));
55
56$showmessage = GETPOST('showmessage');
57
58// Load variable for pagination
59$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60$sortfield = GETPOST('sortfield', 'aZ09comma');
61$sortorder = GETPOST('sortorder', 'aZ09comma');
62$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63if (empty($page) || $page == -1) {
64 $page = 0;
65} // If $page is not defined, or '' or -1
66$offset = $limit * $page;
67$pageprev = $page - 1;
68$pagenext = $page + 1;
69if (!$sortorder) {
70 $sortorder = "DESC";
71}
72if (!$sortfield) {
73 $sortfield = "cf.date_commande";
74}
75
76$search_month = GETPOSTINT('search_month');
77$search_year = GETPOSTINT('search_year');
78
79if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
80 $search_month = '';
81 $search_year = '';
82}
83
84if (!$user->hasRight('produit', 'lire')) {
86}
87
88
89/*
90 * View
91 */
92
93$commandefournisseurstatic = new CommandeFournisseur($db);
94$societestatic = new Societe($db);
95
96$form = new Form($db);
97$formother = new FormOther($db);
98
99if ($id > 0 || !empty($ref)) {
100 $object = new Productlot($db);
101 if ($ref) {
102 $tmp = explode('_', $ref);
103 $objectid = $tmp[0];
104 $batch = $tmp[1];
105 }
106 $result = $object->fetch($id, $objectid, $batch);
107
108 $parameters = array('id' => $id);
109 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110 if ($reshook < 0) {
111 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112 }
113
114 $helpurl = '';
115 $shortlabel = dol_trunc($object->batch, 16);
116 $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
117 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
118
119 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock-stats_commande_fournisseur');
120
121 if ($result > 0) {
123 $titre = $langs->trans("CardProduct".$object->type);
124 $picto = 'lot';
125 print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
126
127 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
128 print $hookmanager->resPrint;
129 if ($reshook < 0) {
130 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
131 }
132
133 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
134
135 $shownav = 1;
136 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
137 $shownav = 0;
138 }
139
140 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
141
142 print '<div class="fichecenter">';
143
144 print '<div class="underbanner clearboth"></div>';
145 print '<table class="border centpercent tableforfield" width="100%">';
146
147
148 // Product
149 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
150 $producttmp = new Product($db);
151 $producttmp->fetch($object->fk_product);
152 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
153 print '</td></tr>';
154 print "</table>";
155
156 echo '<br>';
157
158 // // Sell by
159 // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
160 // print '<tr><td>';
161 // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
162 // print '</td><td>';
163 // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
164 // print '</td>';
165 // print '</tr>';
166 // }
167 //
168 // // Eat by
169 // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
170 // print '<tr><td>';
171 // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
172 // print '</td><td>';
173 // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
174 // print '</td>';
175 // print '</tr>';
176 // }
177 //
178 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) {
179 // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
180 // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
181 // print '</tr>';
182 // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
183 // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
184 // // print '</tr>';
185 // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
186 // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
187 // print '</tr>';
188 // }
189 //
190 // // Quality control
191 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
192 // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
193 // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
194 // print '</tr>';
195 // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
196 // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
197 // print '</tr>';
198 // }
199 //
200 // // Other attributes
201 // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
202
203 print '<table class="border centpercent tableforfield" width="100%">';
204
205 $nboflines = show_stats_for_batch($object, $socid);
206
207 print "</table>";
208
209 print '</div>';
210 print '<div class="clearboth"></div>';
211
212 print dol_get_fiche_end();
213
214 if ($showmessage && $nboflines > 1) {
215 print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
216 } elseif ($user->hasRight('fournisseur', 'commande', 'lire')) {
217 $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
218 $sql .= " cf.ref, cf.date_commande, cf.date_livraison as delivery_date, cf.fk_statut as statut, cf.rowid as facid,";
219 $sql .= " cfd.rowid, SUM(cfdi.qty) as qty";
220 // $sql.= ", cfd.total_ht * SUM(cfdi.qty) / cfd.qty as total_ht_pondere";
221 if (!$user->hasRight('societe', 'client', 'voir')) {
222 $sql .= ", sc.fk_soc, sc.fk_user ";
223 }
224 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
225 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseur as cf ON (cf.fk_soc = s.rowid)";
226 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cfd ON (cfd.fk_commande = cf.rowid)";
227 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as cfdi ON (cfdi.fk_elementdet = cfd.rowid)";
228 if (!$user->hasRight('societe', 'client', 'voir')) {
229 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
230 }
231 $sql .= " WHERE cf.entity IN (".getEntity('product').")";
232 $sql .= " AND cfdi.batch = '".($db->escape($object->batch))."'";
233 if (!empty($search_month)) {
234 $sql .= ' AND MONTH(cf.date_commande) IN ('.$db->sanitize($search_month).')';
235 }
236 if (!empty($search_year)) {
237 $sql .= ' AND YEAR(cf.date_commande) IN ('.$db->sanitize($search_year).')';
238 }
239 if (!$user->hasRight('societe', 'client', 'voir')) {
240 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
241 }
242 if ($socid) {
243 $sql .= " AND cf.fk_soc = ".((int) $socid);
244 }
245 $sql .= " GROUP BY cf.rowid";
246 $sql .= $db->order($sortfield, $sortorder);
247
248 // Calcul total qty and amount for global if full scan list
249 $total_ht_pondere = 0;
250 $total_qty = 0;
251
252 // Count total nb of records
253 $totalofrecords = '';
254 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
255 $result = $db->query($sql);
256 $totalofrecords = $db->num_rows($result);
257 }
258
259 $sql .= $db->plimit($limit + 1, $offset);
260
261 $result = $db->query($sql);
262 if ($result) {
263 $num = $db->num_rows($result);
264
265 $option .= '&id='.$object->id;
266
267 if ($limit > 0 && $limit != $conf->liste_limit) {
268 $option .= '&limit='.((int) $limit);
269 }
270 if (!empty($search_month)) {
271 $option .= '&search_month='.urlencode((string) ($search_month));
272 }
273 if (!empty($search_year)) {
274 $option .= '&search_year='.urlencode((string) ($search_year));
275 }
276
277 print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
278 print '<input type="hidden" name="token" value="'.newToken().'">';
279 if (!empty($sortfield)) {
280 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
281 }
282 if (!empty($sortorder)) {
283 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
284 }
285
286 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
287 print_barre_liste($langs->trans("SuppliersOrders"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
288
289 if (!empty($page)) {
290 $option .= '&page='.urlencode((string) ($page));
291 }
292
293 print '<div class="liste_titre liste_titre_bydiv centpercent">';
294 print '<div class="divsearchfield">';
295 print $langs->trans('Period').' ('.$langs->trans("OrderDate").') - ';
296 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
297 print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
298 print '<div style="vertical-align: middle; display: inline-block">';
299 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")).'">';
300 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")).'">';
301 print '</div>';
302 print '</div>';
303 print '</div>';
304
305 $i = 0;
306 print '<div class="div-table-responsive">';
307 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
308 print '<tr class="liste_titre">';
309 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
310 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
311 print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
312 print_liste_field_titre("OrderDate", $_SERVER["PHP_SELF"], "cf.date_commande", "", $option, 'align="center"', $sortfield, $sortorder);
313 print_liste_field_titre("DateDeliveryPlanned", $_SERVER["PHP_SELF"], "cf.date_livraison", "", $option, 'align="center"', $sortfield, $sortorder);
314 print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "cfdi.qty", "", $option, 'align="center"', $sortfield, $sortorder);
315 // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "total_ht_pondere", "", $option, 'align="right"', $sortfield, $sortorder);
316 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cf.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
317 print "</tr>\n";
318
319 if ($num > 0) {
320 while ($i < min($num, $limit)) {
321 $objp = $db->fetch_object($result);
322
323 if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
324 $objp->qty = -($objp->qty);
325 }
326
327 // $total_ht_pondere += $objp->total_ht_pondere;
328 $total_qty += $objp->qty;
329
330 $commandefournisseurstatic->id = $objp->facid;
331 $commandefournisseurstatic->ref = $objp->ref;
332 $societestatic->fetch($objp->socid);
333 // $paiement = $commandefournisseurstatic->getSommePaiement();
334
335 print '<tr class="oddeven">';
336 print '<td>';
337 print $commandefournisseurstatic->getNomUrl(1);
338 print "</td>\n";
339 print '<td>'.$societestatic->getNomUrl(1).'</td>';
340 print "<td>".$objp->code_fournisseur."</td>\n";
341 print '<td class="center">';
342 print dol_print_date($db->jdate($objp->date_commande), 'dayhour')."</td>";
343 print '<td class="center">';
344 print dol_print_date($db->jdate($objp->delivery_date), 'dayhour')."</td>";
345 print '<td class="center">'.$objp->qty."</td>\n";
346 // print '<td align="right">'.price($objp->total_ht_pondere)."</td>\n";
347 print '<td align="right">'.$commandefournisseurstatic->LibStatut($objp->statut, 5).'</td>';
348 print "</tr>\n";
349 $i++;
350 }
351 }
352 print '<tr class="liste_total">';
353 if ($num < $limit) {
354 print '<td class="left">'.$langs->trans("Total").'</td>';
355 } else {
356 print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
357 }
358 print '<td colspan="2"></td>';
359 print '<td></td>';
360 print '<td></td>';
361 print '<td class="center">'.$total_qty.'</td>';
362 // print '<td class="right">'.$total_ht_pondere.'</td>';
363 print '<td></td>';
364 print "</table>";
365 print '</div>';
366 print '</form>';
367 } else {
368 dol_print_error($db);
369 }
370 $db->free($result);
371 }
372 }
373} else {
375}
376
377// End of page
378llxFooter();
379$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 predefined suppliers products.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
Class with list of lots and properties.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
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.
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...
show_stats_for_batch($batch, $socid)
Show stats for product batch.
productlot_prepare_head($object)
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.