* Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2021 Juanjo Menent * Copyright (C) 2014 Cedric Gross * Copyright (C) 2016 Florian Henry * Copyright (C) 2017-2022 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2019-2020 Christophe Battarel * Copyright (C) 2024-2025 MDW * * 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 3 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 . */ /** * \file htdocs/expedition/dispatch.php * \ingroup expedition * \brief Page to dispatch shipments */ // Load Dolibarr environment 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'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php'; if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; } /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'receptions')); if (isModEnabled('productbatch')) { $langs->load('productbatch'); } // Security check $id = GETPOSTINT("id"); $ref = GETPOST('ref'); $lineid = GETPOSTINT('lineid'); $action = GETPOST('action', 'aZ09'); $fk_default_warehouse = GETPOSTINT('fk_default_warehouse'); $cancel = GETPOST('cancel', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $error = 0; $errors = array(); if ($user->socid) { $socid = $user->socid; } $hookmanager->initHooks(array('expeditiondispatch')); // Recuperation de l'id de projet $projectid = 0; if (GETPOSTISSET("projectid")) { $projectid = GETPOSTINT("projectid"); } $object = new Expedition($db); $objectorder = new Commande($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'); } if (!empty($object->origin)) { $origin = $object->origin; $typeobject = $object->origin; $object->fetch_origin(); } } // $id is id of a purchase order. $result = restrictedArea($user, 'expedition', $object, ''); if (!isModEnabled('stock')) { accessforbidden('Module stock disabled'); } $usercancreate = $user->hasRight('expedition', 'creer'); $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php /* * 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'); } // Update a dispatched line if ($action == 'updatelines' && $usercancreate) { $db->begin(); $error = 0; $expeditiondispatch = new ExpeditionLigne($db); $expeditionlinebatch = new ExpeditionLineBatch($db); $pos = 0; foreach ($_POST as $key => $value) { // without batch module enabled $reg = array(); if (preg_match('/^product_.*([0-9]+)_([0-9]+)$/i', $key, $reg)) { $pos++; $modebatch = null; if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) { $modebatch = "barcode"; } elseif (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { // With batchmode enabled $modebatch = "batch"; } $numline = $pos; if ($modebatch == "barcode") { $prod = "product_".$reg[1].'_'.$reg[2]; } else { $prod = 'product_batch_'.$reg[1].'_'.$reg[2]; } $qty = "qty_".$reg[1].'_'.$reg[2]; $ent = "entrepot_".$reg[1].'_'.$reg[2]; $fk_commandedet = "fk_commandedet_".$reg[1].'_'.$reg[2]; $idline = GETPOSTINT("idline_".$reg[1].'_'.$reg[2]); $warehouse_id = GETPOSTINT($ent); $prod_id = GETPOSTINT($prod); //$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount $lot = ''; $dDLUO = ''; $dDLC = ''; if ($modebatch == "batch") { //TODO: Make impossible to input non existing batch code $lot = GETPOST('lot_number_'.$reg[1].'_'.$reg[2]); $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'month'), GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'day'), GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'year')); $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'month'), GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'day'), GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'year')); } $newqty = GETPOSTFLOAT($qty, 'MS'); //var_dump("modebatch=".$modebatch." newqty=".$newqty." ent=".$ent." idline=".$idline); // We ask to move a qty if (($modebatch == "batch" && $newqty >= 0) || ($modebatch == "barcode" && $newqty != 0)) { if ($newqty > 0) { // If we want a qty, we make test on input data if (!($warehouse_id > 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 && $modebatch == "batch") { $sql = "SELECT pb.rowid "; $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; $sql .= " JOIN ".MAIN_DB_PREFIX."product_stock as ps"; $sql .= " ON ps.rowid = pb.fk_product_stock"; $sql .= " WHERE pb.batch = '".$db->escape($lot)."'"; $sql .= " AND ps.fk_product = ".((int) $prod_id) ; $sql .= " AND ps.fk_entrepot = ".((int) $warehouse_id) ; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num > 1) { dol_syslog('No dispatch for line '.$key.' as too many combination warehouse, product, batch code was found ('.$num.').'); setEventMessages($langs->trans('ErrorTooManyCombinationBatchcode', $numline, $num), null, 'errors'); $error++; } elseif ($num < 1) { $tmpwarehouse = new Entrepot($db); $tmpwarehouse->fetch($warehouse_id); $tmpprod = new Product($db); $tmpprod->fetch($prod_id); dol_syslog('No dispatch for line '.$key.' as no combination warehouse, product, batch code was found.'); setEventMessages($langs->trans('ErrorNoCombinationBatchcode', $numline, $tmpwarehouse->ref, $tmpprod->ref, $lot), null, 'errors'); $error++; } $db->free($resql); } } } if (!$error) { $qtystart = 0; if ($idline > 0) { $result = $expeditiondispatch->fetch($idline); // get line from llx_expeditiondet if ($result < 0) { setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors'); $error++; } else { $qtystart = $expeditiondispatch->qty; $expeditiondispatch->qty = $newqty; $expeditiondispatch->entrepot_id = GETPOSTINT($ent); if ($newqty > 0) { $result = $expeditiondispatch->update($user); } else { $result = $expeditiondispatch->delete($user); } if ($result < 0) { setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors'); $error++; } if (!$error && $modebatch == "batch") { if ($newqty > 0) { $suffixkeyfordate = preg_replace('/^product_batch/', '', $key); $sellby = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffixkeyfordate.'month'), GETPOSTINT('dlc'.$suffixkeyfordate.'day'), GETPOSTINT('dlc'.$suffixkeyfordate.'year'), ''); $eatby = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffixkeyfordate.'month'), GETPOSTINT('dluo'.$suffixkeyfordate.'day'), GETPOSTINT('dluo'.$suffixkeyfordate.'year')); $sqlsearchdet = "SELECT rowid FROM ".MAIN_DB_PREFIX.$expeditionlinebatch->table_element; $sqlsearchdet .= " WHERE fk_expeditiondet = ".((int) $idline); $sqlsearchdet .= " AND batch = '".$db->escape($lot)."'"; $resqlsearchdet = $db->query($sqlsearchdet); $objsearchdet = null; if ($resqlsearchdet) { $objsearchdet = $db->fetch_object($resqlsearchdet); } else { dol_print_error($db); } if ($objsearchdet) { $sql = "UPDATE ".MAIN_DB_PREFIX.$expeditionlinebatch->table_element." SET"; $sql .= " eatby = ".($eatby ? "'".$db->idate($eatby)."'" : "null"); $sql .= " , sellby = ".($sellby ? "'".$db->idate($sellby)."'" : "null"); $sql .= " , qty = ".((float) $newqty); $sql .= " , fk_warehouse = ".((int) $warehouse_id); $sql .= " WHERE rowid = ".((int) $objsearchdet->rowid); } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX.$expeditionlinebatch->table_element." ("; $sql .= "fk_expeditiondet, eatby, sellby, batch, qty, fk_origin_stock, fk_warehouse)"; $sql .= " VALUES (".((int) $idline).", ".($eatby ? "'".$db->idate($eatby)."'" : "null").", ".($sellby ? "'".$db->idate($sellby)."'" : "null").", "; $sql .= " '".$db->escape($lot)."', ".((float) $newqty).", 0, ".((int) $warehouse_id).")"; } } else { $sql = " DELETE FROM ".MAIN_DB_PREFIX.$expeditionlinebatch->table_element; $sql .= " WHERE fk_expeditiondet = ".((int) $idline); $sql .= " AND batch = '".$db->escape($lot)."'"; } $resql = $db->query($sql); if (!$resql) { dol_print_error($db); $error++; } } } } else { $expeditiondispatch->fk_expedition = $object->id; $expeditiondispatch->entrepot_id = GETPOSTINT($ent); $expeditiondispatch->fk_elementdet = GETPOSTINT($fk_commandedet); $expeditiondispatch->qty = $newqty; if ($newqty > 0) { $idline = $expeditiondispatch->insert($user); if ($idline < 0) { setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors'); $error++; } if ($modebatch == "batch" && !$error) { $expeditionlinebatch->sellby = $dDLUO; $expeditionlinebatch->eatby = $dDLC; $expeditionlinebatch->batch = $lot; $expeditionlinebatch->qty = $newqty; $expeditionlinebatch->fk_origin_stock = 0; $expeditionlinebatch->fk_warehouse = GETPOSTINT($ent); $result = $expeditionlinebatch->create($idline); if ($result < 0) { setEventMessages($expeditionlinebatch->error, $expeditionlinebatch->errors, 'errors'); $error++; } } } } // If module stock is enabled and the stock decrease is done on edition of this page /* if (!$error && GETPOST($ent, 'int') > 0 && isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_DISPATCH_ORDER)) { $mouv = new MouvementStock($db); $product = GETPOST($prod, 'int'); $entrepot = GETPOST($ent, 'int'); $qtymouv = price2num(GETPOST($qty, 'alpha'), 'MS') - $qtystart; $price = price2num(GETPOST($pu), 'MU'); $comment = GETPOST('comment'); $inventorycode = dol_print_date(dol_now(), 'dayhourlog'); $now = dol_now(); $eatby = ''; $sellby = ''; $batch = ''; if ($modebatch == "batch") { $eatby = $dDLUO; $sellby = $dDLC; $batch = $lot ; } if ($product > 0 && $qtymouv != 0) { // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on) $mouv->origin = $objectorder; $mouv->setOrigin($objectorder->element, $objectorder->id); // Method change if qty < 0 if (getDolGlobalString('SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qtymouv < 0) { $result = $mouv->reception($user, $product, $entrepot, $qtymouv*(-1), $price, $comment, $eatby, $sellby, $batch, '', 0, $inventorycode); } else { $result = $mouv->livraison($user, $product, $entrepot, $qtymouv, $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode); } if ($result < 0) { setEventMessages($mouv->error, $mouv->errors, 'errors'); $error++; } } } */ } } } } if ($error > 0) { $db->rollback(); setEventMessages($langs->trans("Error"), $errors, 'errors'); } else { $db->commit(); setEventMessages($langs->trans("ShipmentUpdated"), null); header("Location: ".DOL_URL_ROOT.'/expedition/dispatch.php?id='.$object->id); exit; } } elseif ($action == 'setdate_livraison' && $usercancreate) { $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year')); $object->fetch($id); $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } /* * View */ $now = dol_now(); $form = new Form($db); $formproduct = new FormProduct($db); $warehouse_static = new Entrepot($db); $title = $object->ref." - ".$langs->trans('ShipmentDistribution'); $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Expediciones|DE:Modul_Lieferungen'; $morejs = array('/expedition/js/lib_dispatch.js.php'); $typeobject = null; llxHeader('', $title, $help_url, '', 0, 0, $morejs, '', '', 'mod-expedition page-card_dispatch'); if ($object->id > 0 || !empty($object->ref)) { $lines = $object->lines; // This is an array of detail of line, on line per source order line found intolines[]->fk_elementdet, then each line may have sub data //var_dump($lines[0]->fk_elementdet); exit; $num_prod = count($lines); if (!empty($object->origin) && $object->origin_id > 0) { $object->origin = 'commande'; $typeobject = $object->origin; $origin = $object->origin; $object->fetch_origin(); // Load property $object->origin_object, $object->commande, $object->propal, ... } $soc = new Societe($db); $soc->fetch($object->socid); $author = new User($db); $author->fetch($object->user_author_id); $head = shipping_prepare_head($object); print dol_get_fiche_head($head, 'dispatch', $langs->trans("Shipment"), -1, $object->picto); $formconfirm = ''; // Confirmation to delete line if ($action == 'ask_deleteline') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); } // Call Hook formConfirm $parameters = array('lineid' => $lineid); // Note that $action and $object may be modified by hook $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); if (empty($reshook)) { $formconfirm .= $hookmanager->resPrint; } elseif ($reshook > 0) { $formconfirm = $hookmanager->resPrint; } // Print form confirm print $formconfirm; if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) { $objectsrc = new Commande($db); $objectsrc->fetch($object->origin_object->id); } if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) { $objectsrc = new Propal($db); $objectsrc->fetch($object->origin_object->id); } // Shipment card $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; // Ref customer shipment $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1); $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1); // Thirdparty $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); // Project if (isModEnabled('project')) { $langs->load("projects"); $morehtmlref .= '
'; if (0) { // Do not change on reception $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify' && $permissiontoadd) { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); } else { if (!empty($objectsrc) && !empty($objectsrc->fk_project)) { $proj = new Project($db); $proj->fetch($objectsrc->fk_project); $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } } } } $morehtmlref .= '
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; print ''; // Linked documents if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) { print ''; print '\n"; print ''; } if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) { print ''; print '\n"; print ''; } // Date creation print ''; print '\n"; print ''; // Delivery date planned print ''; print '
'; print $langs->trans("RefOrder").''; print $objectsrc->getNomUrl(1, 'commande'); print "
'; print $langs->trans("RefProposal").''; print $objectsrc->getNomUrl(1, 'expedition'); print "
'.$langs->trans("DateCreation").''.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."
'; print ''; if ($action != 'editdate_livraison') { print ''; } print '
'; print $langs->trans('DateDeliveryPlanned'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'
'; print '
'; if ($action == 'editdate_livraison') { print '
'; print ''; print ''; print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0); print ''; print '
'; } else { print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : ' '; } print '
'; print '
'; if (isModEnabled('barcode') || isModEnabled('productbatch')) { print ''.img_picto('', 'barcode', 'class="paddingrightonly"').$langs->trans("UpdateByScaning").''; } print ''.img_picto("", 'autofill', 'class="pictofixedwidth"').$langs->trans("RestoreWithCurrentQtySaved").''; // Link to clear qty print ''.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("ClearQtys").''; print '
'; print '
'; $disabled = 0; // This is used to disable or not the bulk selection of target warehouse. No reason to have it disabled so forced to 0. if ($object->statut == Expedition::STATUS_DRAFT) { require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct = new FormProduct($db); $formproduct->loadWarehouses(); $entrepot = new Entrepot($db); $listwarehouses = $entrepot->list_array(1); $nbfreeproduct = 0; // Nb of lines 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. print '
'; print ''; print ''; print ''; print '
'; print ''; // Get list of lines of the shipment $products_dispatched, with qty dispatched for each product id $products_dispatched = array(); $sql = "SELECT ed.fk_elementdet as rowid, sum(ed.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " WHERE ed.fk_expedition = ".((int) $object->id); $sql .= " GROUP BY ed.fk_elementdet"; $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, 'MS'); $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 = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, '' AS sref, l.qty as qty,"; $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse, p.barcode"; // 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."commandedet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; $sql .= " WHERE l.fk_commande = ".((int) $objectsrc->id); if (!getDolGlobalString('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, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product $sql .= " ORDER BY l.rang, p.ref, p.label"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $numline = 1; if ($num) { print ''; print ''; if (isModEnabled('productbatch')) { print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } } else { print ''; print ''; print ''; } print ''; if ($object->status == Expedition::STATUS_DRAFT) { print ''; } print ''; if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) { if (!isModEnabled("multicurrency") && 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"; } $conf->cache['product'] = array(); // Loop on each line of origin order while ($i < $num) { $objp = $db->fetch_object($resql); // On n'affiche pas les produits libres if (!$objp->fk_product > 0) { $nbfreeproduct++; } else { $alreadydispatched = isset($products_dispatched[$objp->rowid]) ? $products_dispatched[$objp->rowid] : 0; $remaintodispatch = price2num($objp->qty, 5); // Calculation of dispatched if ($remaintodispatch < 0 && !getDolGlobalString('SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN')) { $remaintodispatch = 0; } if ($remaintodispatch || !getDolGlobalString('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 ''; if (empty($conf->cache['product'][$objp->fk_product])) { $tmpproduct = new Product($db); $tmpproduct->fetch($objp->fk_product); $conf->cache['product'][$objp->fk_product] = $tmpproduct; } else { $tmpproduct = $conf->cache['product'][$objp->fk_product]; } $linktoprod = $tmpproduct->getNomUrl(1); $linktoprod .= ' - '.$objp->label."\n"; if (isModEnabled('productbatch')) { if ($objp->tobatch) { // Product print '"; print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } } else { // Product print '"; print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } } } else { print '"; } // Define unit price for PMP calculation $up_ht_disc = $objp->subprice; if (!empty($objp->remise_percent) && !getDolGlobalString('STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) { $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); } // Qty ordered print ''; // Already dispatched print ''; print ''; // Qty to dispatch print ''; // Dispatch column print ''; // Warehouse column $sql = "SELECT ed.rowid"; $sql .= ", cd.fk_product"; $sql .= ", ".$db->ifsql('eb.rowid IS NULL', 'ed.qty', 'eb.qty')." as qty"; $sql .= ", ed.fk_entrepot"; $sql .= ", eb.batch, eb.eatby, eb.sellby"; $sql .= " FROM ".$db->prefix()."expeditiondet as ed"; $sql .= " LEFT JOIN ".$db->prefix()."expeditiondet_batch as eb on ed.rowid = eb.fk_expeditiondet"; $sql .= " INNER JOIN ".$db->prefix()."commandedet as cd on ed.fk_origin_line = cd.rowid"; $sql .= " WHERE ed.fk_origin_line = ".(int) $objp->rowid; $sql .= " AND ed.fk_expedition = ".(int) $object->id; $sql .= " ORDER BY ed.rowid, ed.fk_elementdet"; $resultsql = $db->query($sql); $j = 0; if ($resultsql) { $numd = $db->num_rows($resultsql); while ($j < $numd) { $suffix = "_".$j."_".$i; $objd = $db->fetch_object($resultsql); if (isModEnabled('productbatch') && (!empty($objd->batch) || (is_null($objd->batch) && $tmpproduct->status_batch > 0))) { $type = 'batch'; // Enable hooks to append additional columns $parameters = array( // allows hook to distinguish between the rows with information and the rows with dispatch form input 'is_information_row' => true, 'j' => $j, 'suffix' => $suffix, 'objd' => $objd, ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } print $hookmanager->resPrint; print ''; print ''; print ''; print ''; print ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } print ''; // Supplier ref + Qty ordered + qty already dispatched } else { $type = 'dispatch'; $colspan = 6; $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan; $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan; // Enable hooks to append additional columns $parameters = array( // allows hook to distinguish between the rows with information and the rows with dispatch form input 'is_information_row' => true, 'j' => $j, 'suffix' => $suffix, 'objd' => $objd, ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } print $hookmanager->resPrint; print ''; print ''; print ''; print ''; } // Qty to dispatch print ''; print ''; // Warehouse print '\n"; // Enable hooks to append additional columns $parameters = array( 'is_information_row' => false, // this is a dispatch form row 'i' => $i, 'suffix' => $suffix, 'objp' => $objp, ); $reshook = $hookmanager->executeHooks( 'printFieldListValue', $parameters, $object, $action ); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } print $hookmanager->resPrint; print "\n"; $j++; $numline++; } $suffix = "_".$j."_".$i; } if ($j == 0) { if (isModEnabled('productbatch') && !empty($objp->tobatch)) { $type = 'batch'; // Enable hooks to append additional columns $parameters = array( // allows hook to distinguish between the rows with information and the rows with dispatch form input 'is_information_row' => true, 'j' => $j, 'suffix' => $suffix, '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 ''; if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { print ''; } if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { print ''; } print ''; // Supplier ref + Qty ordered + qty already dispatched } else { $type = 'dispatch'; $colspan = 6; $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan; $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan; // Enable hooks to append additional columns $parameters = array( // allows hook to distinguish between the rows with information and the rows with dispatch form input 'is_information_row' => true, 'j' => $j, 'suffix' => $suffix, '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 ''; } // Qty to dispatch print ''; print ''; // Warehouse print '\n"; // Enable hooks to append additional columns $parameters = array( 'is_information_row' => false, // this is a dispatch form row 'i' => $i, 'suffix' => $suffix, 'objp' => $objp, ); $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("SellByDate").''.$langs->trans("EatByDate").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyToShip"); // Qty to dispatch (sum for all lines of batch detail if there is) } else { print ''.$langs->trans("QtyDispatchedShort").''.$langs->trans("Details"); print ''.$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, '', 'minwidth100 maxwidth300', 1); } elseif (count($listwarehouses) == 1) { print '
'.$langs->trans("ForceTo").' '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1); } print '
'; print $linktoprod; print "'; print $linktoprod; print "'; print ''.$langs->trans("ProductDoesNotUseBatchSerial").''; print ''; print $linktoprod; print "'.$objp->qty.''.$alreadydispatched.''; print ''; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print ''; $dlcdatesuffix = !empty($objd->sellby) ? dol_stringtotime($objd->sellby) : dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year')); print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, ''); print ''; $dluodatesuffix = !empty($objd->eatby) ? dol_stringtotime($objd->eatby) : dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year')); print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, ''); print ' 
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').''; $suggestedvalue = (GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : $objd->qty); //var_dump($suggestedvalue);exit; print ''; print ''; if (isModEnabled('productbatch') && $objp->tobatch > 0) { $type = 'batch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } else { $type = 'dispatch'; print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"'); } print ''; if (count($listwarehouses) > 1) { print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix); } elseif (count($listwarehouses) == 1) { print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix); } else { $langs->load("errors"); print $langs->trans("ErrorNoWarehouseDefined"); } print "
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year')); print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, ''); print ''; $dluodatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year')); print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, ''); print ' 
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').''; $amounttosuggest = (GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : (!getDolGlobalString('SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO') ? $remaintodispatch : 0)); if (count($products_dispatched)) { // There is already existing lines into llx_expeditiondet, this means a plan for the shipment has already been started. // In such a case, we do not suggest new values, we suggest the value known. $amounttosuggest = (GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : (isset($products_dispatched[$objp->rowid]) ? $products_dispatched[$objp->rowid] : '')); } print ''; print ''; if (isModEnabled('productbatch') && $objp->tobatch > 0) { $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 ''; 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, array(), '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, array(), '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 ''; } print '
'; } // Message if nothing to dispatch if (!$nbproduct) { print "
\n"; if (!getDolGlobalString('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 '
'; } print dol_get_fiche_end(); // Popup for mass barcode scanning if ($action == 'updatebyscaning') { if ($permissiontoadd) { // Output the javascript to manage the scanner tool. print ''; } include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $formother = new FormOther($db); print $formother->getHTMLScannerForm("barcodescannerjs", 'all', 1); } // traitement entrepot par défaut print ''; } // End of page llxFooter(); $db->close();