* Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2019 Juanjo Menent * Copyright (C) 2014 Cedric Gross * Copyright (C) 2016 Florian Henry * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018 Frédéric France * Copyright (C) 2019 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see https://www.gnu.org/ */ /** * \file htdocs/fourn/commande/dispatch.php * \ingroup commande * \brief Page to dispatch receiving */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; if (!empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; // Load translation files required by the page $langs->loadLangs(array("bills", "orders", "sendings", "companies", "deliveries", "products", "stocks", "receptions")); if (!empty($conf->productbatch->enabled)) $langs->load('productbatch'); // Security check $id = GETPOST("id", 'int'); $ref = GETPOST('ref'); $lineid = GETPOST('lineid', 'int'); $action = GETPOST('action', 'aZ09'); $fk_default_warehouse = GETPOST('fk_default_warehouse', 'int'); if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande'); if (empty($conf->stock->enabled)) { accessforbidden(); } $hookmanager->initHooks(array('ordersupplierdispatch')); // Recuperation de l'id de projet $projectid = 0; if ($_GET["projectid"]) $projectid = GETPOST("projectid", 'int'); $object = new CommandeFournisseur($db); if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } $result = $object->fetch_thirdparty(); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $error = 0; $supplierorderdispatch = new CommandeFournisseurDispatch($db); $db->begin(); $result = $supplierorderdispatch->fetch($lineid); if (!$result) { $error++; setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $action = ''; } if (!$error) { $result = $supplierorderdispatch->setStatut(1); if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $result = $object->calcAndSetStatusDispatch($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $db->commit(); } else { $db->rollback(); } } if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $error = 0; $supplierorderdispatch = new CommandeFournisseurDispatch($db); $db->begin(); $result = $supplierorderdispatch->fetch($lineid); if (!$result) { $error++; setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $action = ''; } if (!$error) { $result = $supplierorderdispatch->setStatut(0); if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $result = $object->calcAndSetStatusDispatch($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $db->commit(); } else { $db->rollback(); } } if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $error = 0; $supplierorderdispatch = new CommandeFournisseurDispatch($db); $db->begin(); $result = $supplierorderdispatch->fetch($lineid); if (!$result) { $error++; setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $action = ''; } if (!$error) { $result = $supplierorderdispatch->setStatut(2); if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $result = $object->calcAndSetStatusDispatch($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; $action = ''; } } if (!$error) { $db->commit(); } else { $db->rollback(); } } if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) { $error = 0; $db->begin(); $pos = 0; foreach ($_POST as $key => $value) { // without batch module enabled if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) { $pos++; // $numline=$reg[2] + 1; // line of product $numline = $pos; $prod = "product_".$reg[1].'_'.$reg[2]; $qty = "qty_".$reg[1].'_'.$reg[2]; $ent = "entrepot_".$reg[1].'_'.$reg[2]; if (empty(GETPOST($ent))) $ent = $fk_default_warehouse; $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2]; if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { $dto = GETPOST("dto_".$reg[1].'_'.$reg[2]); if (!empty($dto)) { $unit_price = price2num(GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU'); } $saveprice = "saveprice_".$reg[1].'_'.$reg[2]; } } // We ask to move a qty if (GETPOST($qty) != 0) { if (!(GETPOST($ent, 'int') > 0)) { dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.'); $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); $error++; } if (!$error) { $result = $object->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { $dto = GETPOST("dto_".$reg[1].'_'.$reg[2]); //update supplier price if (GETPOSTISSET($saveprice)) { // TODO Use class $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql .= " SET unitprice='".GETPOST($pu)."'"; $sql .= ", price=".GETPOST($pu)."*quantity"; $sql .= ", remise_percent='".$dto."'"; $sql .= " WHERE fk_soc=".$object->socid; $sql .= " AND fk_product=".GETPOST($prod, 'int'); $resql = $db->query($sql); } } } } } } // with batch module enabled if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { $pos++; // eat-by date dispatch // $numline=$reg[2] + 1; // line of product $numline = $pos; $prod = 'product_batch_'.$reg[1].'_'.$reg[2]; $qty = 'qty_'.$reg[1].'_'.$reg[2]; $ent = 'entrepot_'.$reg[1].'_'.$reg[2]; $pu = 'pu_'.$reg[1].'_'.$reg[2]; $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; $lot = 'lot_number_'.$reg[1].'_'.$reg[2]; $dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']); $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']); $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; // We ask to move a qty if (GETPOST($qty) > 0) { if (!(GETPOST($ent, 'int') > 0)) { dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.'); $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); $error++; } if (!(GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) { dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set'); $text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1); setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); $error++; } if (!$error) { $result = $object->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } } } } if (!$error) { $result = $object->calcAndSetStatusDispatch($user, GETPOST('closeopenorder') ? 1 : 0, GETPOST('comment')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } if (!$notrigger && !$error) { global $conf, $langs, $user; // Call trigger $result = $object->call_trigger('ORDER_SUPPLIER_DISPATCH', $user); // End call triggers if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } if ($result >= 0 && !$error) { $db->commit(); header("Location: dispatch.php?id=".$id); exit(); } else { $db->rollback(); } } /* * View */ $now = dol_now(); $form = new Form($db); $formproduct = new FormProduct($db); $warehouse_static = new Entrepot($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db); $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; llxHeader('', $langs->trans("Order"), $help_url, '', 0, 0, array('/fourn/js/lib_dispatch.js.php')); if ($id > 0 || !empty($ref)) { $soc = new Societe($db); $soc->fetch($object->socid); $author = new User($db); $author->fetch($object->user_author_id); $head = ordersupplier_prepare_head($object); $title = $langs->trans("SupplierOrder"); dol_fiche_head($head, 'dispatch', $title, -1, 'order'); // Supplier order card $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; // Ref supplier $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); // Project if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; if ($user->rights->fournisseur->commande->creer) { if ($action != 'classify') { //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; $morehtmlref .= ' : '; } if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; } else { $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); $morehtmlref .= ''; $morehtmlref .= $proj->ref; $morehtmlref .= ''; } else { $morehtmlref .= ''; } } } $morehtmlref .= '
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; print ''; // Date if ($object->methode_commande_id > 0) { print '"; if ($object->methode_commande) { print ''; } } // Author print ''; print ''; print ''; $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print "
'.$langs->trans("Date").''; if ($object->date_commande) { print dol_print_date($object->date_commande, "dayhour")."\n"; } print "
'.$langs->trans("Method").''.$object->getInputMethod().'
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1, '', 0, 0, 0).'
"; print '
'; // if ($mesg) print $mesg; print '
'; $disabled = 1; if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) $disabled = 0; // Line of orders if ($object->statut <= CommandeFournisseur::STATUS_ACCEPTED || $object->statut >= CommandeFournisseur::STATUS_CANCELED) { print '
'.$langs->trans("OrderStatusNotReadyToDispatch").''; } if ($object->statut == CommandeFournisseur::STATUS_ORDERSENT || $object->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $object->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) { require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); $formproduct->loadWarehouses(); if (empty($conf->reception->enabled))print '
'; else print ''; print ''; if (empty($conf->reception->enabled))print ''; else print ''; print '
'; print ''; // Set $products_dispatched with qty dispatched for each product id $products_dispatched = array(); $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet"; $sql .= " WHERE cfd.fk_commande = ".$object->id; $sql .= " GROUP BY l.rowid, cfd.fk_product"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $objd = $db->fetch_object($resql); $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); $i++; } } $db->free($resql); } $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,"; $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse"; // Enable hooks to alter the SQL query (SELECT) $parameters = array(); $reshook = $hookmanager->executeHooks( 'printFieldListSelect', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; $sql .= " WHERE l.fk_commande = ".$object->id; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND l.product_type = 0"; // Enable hooks to alter the SQL query (WHERE) $parameters = array(); $reshook = $hookmanager->executeHooks( 'printFieldListWhere', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); $sql .= $hookmanager->resPrint; $sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent, p.fk_default_warehouse"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product $sql .= " ORDER BY p.ref, p.label"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { $entrepot = new Entrepot($db); $listwarehouses = $entrepot->list_array(1); print ''; print ''; if (!empty($conf->productbatch->enabled)) { print ''; print ''; print ''; } else { print ''; print ''; print ''; } print ''; print ''; print ''; print ''; print ''; if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { print ''; print ''; print ''; } } print ''; // Enable hooks to append additional columns $parameters = array(); $reshook = $hookmanager->executeHooks( 'printFieldListTitle', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); print $hookmanager->resPrint; print "\n"; } $nbfreeproduct = 0; // Nb of lins of free products/services $nbproduct = 0; // Nb of predefined product lines to dispatch (already done or not) if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is off (default) // or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on. while ($i < $num) { $objp = $db->fetch_object($resql); // On n'affiche pas les produits libres if (!$objp->fk_product > 0) { $nbfreeproduct++; } else { $remaintodispatch = price2num($objp->qty - ((float) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched if ($remaintodispatch < 0) $remaintodispatch = 0; if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) { $nbproduct++; // To show detail cref and description value, we must make calculation by cref // print ($objp->cref?' ('.$objp->cref.')':''); // if ($objp->description) print '
'.nl2br($objp->description); $suffix = '_0_'.$i; print "\n"; print ''."\n"; // hidden fields for js function print ''; print ''; print ''; $linktoprod = ''.img_object($langs->trans("ShowProduct"), 'product').' '.$objp->ref.''; $linktoprod .= ' - '.$objp->label."\n"; if (!empty($conf->productbatch->enabled)) { if ($objp->tobatch) { print '"; print ''; print ''; print ''; } else { print '"; print ''; print ''; print ''; } } else { print '"; } // Define unit price for PMP calculation $up_ht_disc = $objp->subprice; if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); // Supplier ref print ''; // Qty ordered print ''; // Already dispatched print ''; if (!empty($conf->productbatch->enabled) && $objp->tobatch == 1) { $type = 'batch'; print ''; // Qty to dispatch print ''; // Dispatch column print ''; // Warehouse column // Enable hooks to append additional columns $parameters = array( 'is_information_row' => true, // allows hook to distinguish between the // rows with information and the rows with // dispatch form input 'objp' => $objp ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); print $hookmanager->resPrint; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Supplier ref + Qty ordered + qty already dispatched } else { $type = 'dispatch'; print ''; // Qty to dispatch print ''; // Dispatch column print ''; // Warehouse column // Enable hooks to append additional columns $parameters = array( 'is_information_row' => true, // allows hook to distinguish between the // rows with information and the rows with // dispatch form input 'objp' => $objp ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); print $hookmanager->resPrint; print ''; print ''; print ''; } // Qty to dispatch print ''; print ''; if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) { if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) { // Price print ''; // Discount print ''; // Save price print ''; } } // Warehouse print '\n"; // Enable hooks to append additional columns $parameters = array( 'is_information_row' => false // this is a dispatch form row ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); print $hookmanager->resPrint; print "\n"; } } $i++; } $db->free($resql); } else { dol_print_error($db); } print "
'.$langs->trans("Description").''.$langs->trans("batch_number").''.$langs->trans("EatByDate").''.$langs->trans("SellByDate").''.$langs->trans("SupplierRef").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyDispatchedShort").''.$langs->trans("QtyToDispatchShort").''.$langs->trans("Price").''.$langs->trans("ReductionShort").' (%)'.$langs->trans("UpdatePrice").''.$langs->trans("Warehouse"); // Select warehouse to force it everywhere if (count($listwarehouses) > 1) { print '
'.$langs->trans("ForceTo").' '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0, '', 0, 0, $disabled); } elseif (count($listwarehouses) == 1) { print '
'.$langs->trans("ForceTo").' '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled); } print '
'; print $linktoprod; print "'; print $linktoprod; print "'; print $langs->trans("ProductDoesNotUseBatchSerial"); print ''; print $linktoprod; print "'.$objp->sref.''.$objp->qty.''.$products_dispatched[$objp->rowid].''; print ''; //print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); print '
'; print ''; print ''; print ''; if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested ! { print $langs->trans("BuyingPrice").': '; } else { print ''; } print ''; print ''; print ''; $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOST('dlc'.$suffix.'month'), GETPOST('dlc'.$suffix.'day'), GETPOST('dlc'.$suffix.'year')); print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, '', '', 1, ''); print ''; $dluodatesuffix = dol_mktime(0, 0, 0, GETPOST('dluo'.$suffix.'month'), GETPOST('dluo'.$suffix.'day'), GETPOST('dluo'.$suffix.'year')); print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, '', '', 1, ''); print ' '; print ''; //print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"'); print '
'; print ''; print ''; print ''; if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested ! { print $langs->trans("BuyingPrice").': '; } else { print ''; } print ''; print ''; print ''; if (!empty($conf->productbatch->enabled) && $objp->tobatch == 1) { $type = 'batch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } else { $type = 'dispatch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (count($listwarehouses) > 1) { print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix); } elseif (count($listwarehouses) == 1) { print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix); } else { $langs->load("errors"); print $langs->trans("ErrorNoWarehouseDefined"); } print "
\n"; print '
'; if ($nbproduct) { $checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll')); print '
'; $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if (empty($reshook)) { if (empty($conf->reception->enabled)) { print $langs->trans("Comment").' : '; print 'trans("DispatchSupplierOrder", $object->ref); // print ' / '.$object->ref_supplier; // Not yet available print '" class="flat">
'; print ' '.$checkboxlabel; } $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception"); print '
'; } print '
'; } // Message if nothing to dispatch if (!$nbproduct) { print "
\n"; if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) print '
'.$langs->trans("NoPredefinedProductToDispatch").'
'; // No predefined line at all else print '
'.$langs->trans("NoMorePredefinedProductToDispatch").'
'; // No predefined line that remain to be dispatched. } print '
'; } dol_fiche_end(); // traitement entrepot par défaut print ''; // List of lines already dispatched $sql = "SELECT p.ref, p.label,"; $sql .= " e.rowid as warehouse_id, e.ref as entrepot,"; $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec"; if ($conf->reception->enabled)$sql .= " ,cfd.fk_reception, r.date_delivery"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; if ($conf->reception->enabled)$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid"; $sql .= " WHERE cfd.fk_commande = ".$object->id; $sql .= " AND cfd.fk_product = p.rowid"; $sql .= " ORDER BY cfd.rowid ASC"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num > 0) { print "
\n"; print load_fiche_titre($langs->trans("ReceivingForSameOrder")); print '
'; print ''; print ''; if ($conf->reception->enabled)print ''; print ''; print ''; print ''; if (!empty($conf->productbatch->enabled)) { print ''; print ''; print ''; } print ''; print ''; print ''; print ''; // Status if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) { print ''; } elseif (!empty($conf->reception->enabled)) { print ''; } print ''; print "\n"; while ($i < $num) { $objp = $db->fetch_object($resql); print ""; if (!empty($conf->reception->enabled)) { print '"; } print '\n"; print ''; print ''; if (!empty($conf->productbatch->enabled)) { print ''; print ''; print ''; } // Qty print ''; print ''; // Warehouse print ''; // Comment print ''; // Status if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) { print ''; // Add button to check/uncheck disaptching print ''; } elseif (!empty($conf->reception->enabled)) { print ''; } print ''; print "\n"; $i++; } $db->free($resql); print "
'.$langs->trans("Reception").''.$langs->trans("Product").''.$langs->trans("DateCreation").''.$langs->trans("DateDeliveryPlanned").''.$langs->trans("batch_number").''.$langs->trans("EatByDate").''.$langs->trans("SellByDate").''.$langs->trans("QtyDispatched").''.$langs->trans("Warehouse").''.$langs->trans("Comment").''.$langs->trans("Status").'
'; if (!empty($objp->fk_reception)) { $reception = new Reception($db); $reception->fetch($objp->fk_reception); print $reception->getNomUrl(1); } print "'; print ''.img_object($langs->trans("ShowProduct"), 'product').' '.$objp->ref.''; print ' - '.$objp->label; print "'.dol_print_date($db->jdate($objp->datec), 'day').''.dol_print_date($db->jdate($objp->date_delivery), 'day').''.$objp->batch.''.dol_print_date($db->jdate($objp->eatby), 'day').''.dol_print_date($db->jdate($objp->sellby), 'day').''.$objp->qty.' '; $warehouse_static->id = $objp->warehouse_id; $warehouse_static->libelle = $objp->entrepot; print $warehouse_static->getNomUrl(1); print ''.$objp->comment.''; $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status); // print $supplierorderdispatch->status; print $supplierorderdispatch->getLibStatut(5); print ''; if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) { if (empty($objp->status)) { print ''.$langs->trans("Approve").''; print ''.$langs->trans("Deny").''; } else { print ''.$langs->trans("Disapprove").''; print ''.$langs->trans("Deny").''; } } else { $disabled = ''; if ($object->statut == 5) $disabled = 1; if (empty($objp->status)) { print 'dispatchlineid.'">'.$langs->trans("Approve").''; print 'dispatchlineid.'">'.$langs->trans("Deny").''; } if ($objp->status == 1) { print 'dispatchlineid.'">'.$langs->trans("Reinit").''; print 'dispatchlineid.'">'.$langs->trans("Deny").''; } if ($objp->status == 2) { print 'dispatchlineid.'">'.$langs->trans("Reinit").''; print 'dispatchlineid.'">'.$langs->trans("Approve").''; } } print ''; if (!empty($reception->id)) { print $reception->getLibStatut(5); } print '
\n"; print '
'; } } else { dol_print_error($db); } } // End of page llxFooter(); $db->close();