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