working dispatchcard reception

This commit is contained in:
hystepik 2023-04-27 14:56:27 +02:00
parent 3760f06961
commit ca815ff9c6
5 changed files with 1213 additions and 63 deletions

View File

@ -46,6 +46,13 @@ function reception_prepare_head(Reception $object)
$head[$h][2] = 'reception'; $head[$h][2] = 'reception';
$h++; $h++;
if ($object->statut == Reception::STATUS_DRAFT) {
$head[$h][0] = DOL_URL_ROOT."/reception/dispatch.php?id=".$object->id;
$head[$h][1] = $langs->trans("DispatchCard");
$head[$h][2] = 'dispatch';
$h++;
}
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
$objectsrc = $object; $objectsrc = $object;
if ($object->origin == 'supplier_order' && $object->origin_id > 0) { if ($object->origin == 'supplier_order' && $object->origin_id > 0) {

View File

@ -2110,9 +2110,10 @@ class CommandeFournisseur extends CommonOrder
* @param string $batch Lot number * @param string $batch Lot number
* @param int $fk_commandefourndet Id of supplier order line * @param int $fk_commandefourndet Id of supplier order line
* @param int $notrigger 1 = notrigger * @param int $notrigger 1 = notrigger
* @param int $fk_reception Id of reception to link
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment = '', $eatby = '', $sellby = '', $batch = '', $fk_commandefourndet = 0, $notrigger = 0) public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment = '', $eatby = '', $sellby = '', $batch = '', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
{ {
global $conf, $langs; global $conf, $langs;
@ -2142,9 +2143,9 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
$sql .= " (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch) VALUES"; $sql .= " (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
$sql .= " ('".$this->id."','".$product."','".$qty."',".($entrepot > 0 ? "'".$entrepot."'" : "null").",'".$user->id."','".$this->db->idate($now)."','".$fk_commandefourndet."', ".$dispatchstatus.", '".$this->db->escape($comment)."', "; $sql .= " ('".$this->id."','".$product."','".$qty."',".($entrepot > 0 ? "'".$entrepot."'" : "null").",'".$user->id."','".$this->db->idate($now)."','".$fk_commandefourndet."', ".$dispatchstatus.", '".$this->db->escape($comment)."', ";
$sql .= ($eatby ? "'".$this->db->idate($eatby)."'" : "null").", ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", ".($batch ? "'".$this->db->escape($batch)."'" : "null"); $sql .= ($eatby ? "'".$this->db->idate($eatby)."'" : "null").", ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", ".($batch ? "'".$this->db->escape($batch)."'" : "null").", ".($fk_reception > 0 ? "'".$fk_reception."'" : "null");
$sql .= ")"; $sql .= ")";
dol_syslog(get_class($this)."::dispatchProduct", LOG_DEBUG); dol_syslog(get_class($this)."::dispatchProduct", LOG_DEBUG);

View File

@ -65,8 +65,7 @@ if (empty($dolibarr_nocache)) {
* @param type string type of dispatch (batch = batch dispatch, dispatch = non batch dispatch) * @param type string type of dispatch (batch = batch dispatch, dispatch = non batch dispatch)
* @param mode string 'qtymissing' will create new line with qty missing, 'lessone' will keep 1 in old line and the rest in new one * @param mode string 'qtymissing' will create new line with qty missing, 'lessone' will keep 1 in old line and the rest in new one
*/ */
function addDispatchLine(index, type, mode) function addDispatchLine(index, type, mode) {
{
mode = mode || 'qtymissing' mode = mode || 'qtymissing'
console.log("fourn/js/lib_dispatch.js.php Split line type=" + type + " index=" + index + " mode=" + mode); console.log("fourn/js/lib_dispatch.js.php Split line type=" + type + " index=" + index + " mode=" + mode);
@ -78,12 +77,10 @@ function addDispatchLine(index, type, mode)
var qty = parseFloat($("#qty_" + (nbrTrs - 1) + "_" + index).val()); var qty = parseFloat($("#qty_" + (nbrTrs - 1) + "_" + index).val());
var qtyDispatched; var qtyDispatched;
if (mode === 'lessone') if (mode === 'lessone') {
{
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + 1; qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + 1;
} }
else else {
{
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + qty; qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + qty;
// If user did not reduced the qty to dispatch on old line, we keep only 1 on old line and the rest on new line // If user did not reduced the qty to dispatch on old line, we keep only 1 on old line and the rest on new line
if (qtyDispatched == qtyOrdered && qtyDispatched > 1) { if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
@ -146,7 +143,7 @@ function addDispatchLine(index, type, mode)
console.log("Reset trigger for id = #qty_" + idrow); console.log("Reset trigger for id = #qty_" + idrow);
$("#qty_" + idrow).val(""); $("#qty_" + idrow).val("");
} }
});; });
if (mode === 'lessone') if (mode === 'lessone')
{ {
@ -159,9 +156,15 @@ function addDispatchLine(index, type, mode)
$("#qty_" + (nbrTrs - 1) + "_" + index).data('type', type); $("#qty_" + (nbrTrs - 1) + "_" + index).data('type', type);
$("#qty_" + (nbrTrs - 1) + "_" + index).data('index', index); $("#qty_" + (nbrTrs - 1) + "_" + index).data('index', index);
// Update dispatched qty when value dispatch qty input field changed // Update dispatched qty when value dispatch qty input field changed
$("#qty_"+(nbrTrs-1)+"_"+index).change(this.onChangeDispatchLineQty); //$("#qty_" + (nbrTrs - 1) + "_" + index).change(this.onChangeDispatchLineQty);
//set focus on lot of new line (if it exists) //set focus on lot of new line (if it exists)
$("#lot_number_" + (nbrTrs) + "_" + index).focus(); $("#lot_number_" + (nbrTrs) + "_" + index).focus();
//Clean bad values
$("tr[name^='" + type + "_'][name$='_" + index + "']:last").data("remove", "remove");
$("#lot_number_" + (nbrTrs) + "_" + index).val("")
$("#idline_" + (nbrTrs) + "_" + index).val("-1")
$("#qty_" + (nbrTrs) + "_" + index).data('expected', "0");
$("#lot_number_" + (nbrTrs) + "_" + index).removeAttr("disabled");
} }
} }
@ -175,16 +178,18 @@ function addDispatchLine(index, type, mode)
* element requires arbitrary data qty (value before change), type (type of dispatch) and index (index of product line) * element requires arbitrary data qty (value before change), type (type of dispatch) and index (index of product line)
*/ */
function onChangeDispatchLineQty() { function onChangeDispatchLineQty(element) {
var index = $(this).data('index'), var type = $(element).data('type'),
type = $(this).data('type'), qty = parseFloat($(element).data('expected')),
qty = parseFloat($(this).data('qty')),
changedQty, nbrTrs, dispatchingQty, qtyOrdered, qtyDispatched; changedQty, nbrTrs, dispatchingQty, qtyOrdered, qtyDispatched;
id = $(element).attr("id");
id = id.split("_");
index = id[2];
if (index >= 0 && type && qty >= 0) { if (index >= 0 && type && qty >= 0) {
nbrTrs = $("tr[name^='" + type + "_'][name$='_" + index + "']").length; nbrTrs = $("tr[name^='" + type + "_'][name$='_" + index + "']").length;
qtyChanged = parseFloat($(this).val()) - qty; // qty changed qtyChanged = parseFloat($(element).val()) - qty; // qty changed
qtyDispatching = parseFloat($("#qty_"+(nbrTrs-1)+"_"+index).val()); // qty currently being dispatched qtyDispatching = parseFloat($(element).val()); // qty currently being dispatched
qtyOrdered = parseFloat($("#qty_ordered_0_" + index).val()); // qty ordered qtyOrdered = parseFloat($("#qty_ordered_0_" + index).val()); // qty ordered
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()); // qty already dispatched qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()); // qty already dispatched
@ -193,8 +198,8 @@ function onChangeDispatchLineQty() {
if ((qtyChanged) <= (qtyOrdered - (qtyDispatched + qtyDispatching))) { if ((qtyChanged) <= (qtyOrdered - (qtyDispatched + qtyDispatching))) {
$("#qty_dispatched_0_" + index).val(qtyDispatched + qtyChanged); $("#qty_dispatched_0_" + index).val(qtyDispatched + qtyChanged);
} else { } else {
$(this).val($(this).data('qty')); $(element).val($(element).data('expected'));
} }
$(this).data('qty', $(this).val()); $(element).data('expected', $(element).val());
} }
} }

View File

@ -52,3 +52,5 @@ ReceptionExist=A reception exists
ReceptionBackToDraftInDolibarr=Reception %s back to draft ReceptionBackToDraftInDolibarr=Reception %s back to draft
ReceptionClassifyClosedInDolibarr=Reception %s classified Closed ReceptionClassifyClosedInDolibarr=Reception %s classified Closed
ReceptionUnClassifyCloseddInDolibarr=Reception %s re-open ReceptionUnClassifyCloseddInDolibarr=Reception %s re-open
ResetQtyToDispatch=Reset all quantities to dispatch
ReceptionUpdated=Reception sucessfully updated

File diff suppressed because it is too large Load Diff