working dispatchcard reception
This commit is contained in:
parent
3760f06961
commit
ca815ff9c6
@ -46,6 +46,13 @@ function reception_prepare_head(Reception $object)
|
||||
$head[$h][2] = 'reception';
|
||||
$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)) {
|
||||
$objectsrc = $object;
|
||||
if ($object->origin == 'supplier_order' && $object->origin_id > 0) {
|
||||
|
||||
@ -2110,9 +2110,10 @@ class CommandeFournisseur extends CommonOrder
|
||||
* @param string $batch Lot number
|
||||
* @param int $fk_commandefourndet Id of supplier order line
|
||||
* @param int $notrigger 1 = notrigger
|
||||
* @param int $fk_reception Id of reception to link
|
||||
* @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;
|
||||
|
||||
@ -2142,9 +2143,9 @@ class CommandeFournisseur extends CommonOrder
|
||||
$this->db->begin();
|
||||
|
||||
$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 .= ($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 .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::dispatchProduct", LOG_DEBUG);
|
||||
|
||||
@ -65,39 +65,36 @@ if (empty($dolibarr_nocache)) {
|
||||
* @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
|
||||
*/
|
||||
function addDispatchLine(index, type, mode)
|
||||
{
|
||||
function addDispatchLine(index, type, mode) {
|
||||
mode = mode || 'qtymissing'
|
||||
|
||||
console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode);
|
||||
var $row0 = $("tr[name='"+type+'_0_'+index+"']");
|
||||
console.log("fourn/js/lib_dispatch.js.php Split line type=" + type + " index=" + index + " mode=" + mode);
|
||||
var $row0 = $("tr[name='" + type + '_0_' + index + "']");
|
||||
var $dpopt = $row0.find('.hasDatepicker').first().datepicker('option', 'all'); // get current datepicker options to apply the same to the cloned datepickers
|
||||
var $row = $row0.clone(true); // clone first batch line to jQuery object
|
||||
var nbrTrs = $("tr[name^='"+type+"_'][name$='_"+index+"']").length; // position of line for batch
|
||||
var qtyOrdered = parseFloat($("#qty_ordered_0_"+index).val()); // Qty ordered is same for all rows
|
||||
var qty = parseFloat($("#qty_"+(nbrTrs - 1)+"_"+index).val());
|
||||
var qtyDispatched;
|
||||
var nbrTrs = $("tr[name^='" + type + "_'][name$='_" + index + "']").length; // position of line for batch
|
||||
var qtyOrdered = parseFloat($("#qty_ordered_0_" + index).val()); // Qty ordered is same for all rows
|
||||
var qty = parseFloat($("#qty_" + (nbrTrs - 1) + "_" + index).val());
|
||||
var qtyDispatched;
|
||||
|
||||
if (mode === 'lessone')
|
||||
{
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_"+index).val()) + 1;
|
||||
if (mode === 'lessone') {
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_"+index).val()) + qty;
|
||||
else {
|
||||
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 (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_"+index).val()) + 1;
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()) + 1;
|
||||
mode = 'lessone';
|
||||
}
|
||||
}
|
||||
console.log("qtyDispatched="+qtyDispatched+" qtyOrdered="+qtyOrdered);
|
||||
console.log("qtyDispatched=" + qtyDispatched + " qtyOrdered=" + qtyOrdered);
|
||||
|
||||
if (qtyDispatched >= qtyOrdered || qtyOrdered <= 1) {
|
||||
window.alert("Remain quantity to dispatch is too low to be split");
|
||||
} else if (qtyDispatched < qtyOrdered) {
|
||||
//replace tr suffix nbr
|
||||
$row.html($row.html().replace(/_0_/g,"_"+nbrTrs+"_"));
|
||||
$row.html($row.html().replace(/_0_/g, "_" + nbrTrs + "_"));
|
||||
|
||||
// jquery's deep clone is incompatible with date pickers (the clone shares data with the original)
|
||||
// so we destroy and rebuild the new date pickers
|
||||
@ -111,57 +108,63 @@ function addDispatchLine(index, type, mode)
|
||||
}, 0);
|
||||
|
||||
//create new select2 to avoid duplicate id of cloned one
|
||||
$row.find("select[name='"+'entrepot_'+nbrTrs+'_'+index+"']").select2();
|
||||
$row.find("select[name='" + 'entrepot_' + nbrTrs + '_' + index + "']").select2();
|
||||
// TODO find solution to copy selected option to new select
|
||||
// TODO find solution to keep new tr's after page refresh
|
||||
//clear value
|
||||
$row.find("input[name^='qty']").val('');
|
||||
//change name of new row
|
||||
$row.attr('name',type+'_'+nbrTrs+'_'+index);
|
||||
$row.attr('name', type + '_' + nbrTrs + '_' + index);
|
||||
//insert new row before last row
|
||||
$("tr[name^='"+type+"_'][name$='_"+index+"']:last").after($row);
|
||||
$("tr[name^='" + type + "_'][name$='_" + index + "']:last").after($row);
|
||||
|
||||
//remove cloned select2 with duplicate id.
|
||||
$("#s2id_entrepot_"+nbrTrs+'_'+index).detach(); // old way to find duplicated select2 component
|
||||
$(".csswarehouse_"+nbrTrs+"_"+index+":first-child").parent("span.selection").parent(".select2").detach();
|
||||
$("#s2id_entrepot_" + nbrTrs + '_' + index).detach(); // old way to find duplicated select2 component
|
||||
$(".csswarehouse_" + nbrTrs + "_" + index + ":first-child").parent("span.selection").parent(".select2").detach();
|
||||
|
||||
/* Suffix of lines are: _ trs.length _ index */
|
||||
$("#qty_"+nbrTrs+"_"+index).focus();
|
||||
$("#qty_dispatched_0_"+index).val(qtyDispatched);
|
||||
$("#qty_" + nbrTrs + "_" + index).focus();
|
||||
$("#qty_dispatched_0_" + index).val(qtyDispatched);
|
||||
|
||||
//hide all buttons then show only the last one
|
||||
$("tr[name^='"+type+"_'][name$='_"+index+"'] .splitbutton").hide();
|
||||
$("tr[name^='"+type+"_'][name$='_"+index+"']:last .splitbutton").show();
|
||||
$("tr[name^='" + type + "_'][name$='_" + index + "'] .splitbutton").hide();
|
||||
$("tr[name^='" + type + "_'][name$='_" + index + "']:last .splitbutton").show();
|
||||
|
||||
$("#reset_"+(nbrTrs)+"_"+index).click(function(){
|
||||
$("#reset_" + (nbrTrs) + "_" + index).click(function () {
|
||||
id = $(this).attr("id");
|
||||
id = id.split("reset_");
|
||||
idrow = id[1];
|
||||
idlast = $("tr[name^='"+type+"_'][name$='_"+index+"']:last .qtydispatchinput").attr("id");
|
||||
if (idlast == $("#qty_"+idrow).attr("id")) {
|
||||
console.log("Remove trigger for tr name = "+type+"_"+idrow);
|
||||
$('tr[name="'+type+'_'+idrow+'"').remove();
|
||||
$("tr[name^='"+type+"_'][name$='_"+index+"']:last .splitbutton").show();
|
||||
idlast = $("tr[name^='" + type + "_'][name$='_" + index + "']:last .qtydispatchinput").attr("id");
|
||||
if (idlast == $("#qty_" + idrow).attr("id")) {
|
||||
console.log("Remove trigger for tr name = " + type + "_" + idrow);
|
||||
$('tr[name="' + type + '_' + idrow + '"').remove();
|
||||
$("tr[name^='" + type + "_'][name$='_" + index + "']:last .splitbutton").show();
|
||||
} else {
|
||||
console.log("Reset trigger for id = #qty_"+idrow);
|
||||
$("#qty_"+idrow).val("");
|
||||
console.log("Reset trigger for id = #qty_" + idrow);
|
||||
$("#qty_" + idrow).val("");
|
||||
}
|
||||
});;
|
||||
});
|
||||
|
||||
if (mode === 'lessone')
|
||||
{
|
||||
qty = 1; // keep 1 in old line
|
||||
$("#qty_"+(nbrTrs-1)+"_"+index).val(qty);
|
||||
}
|
||||
$("#qty_"+nbrTrs+"_"+index).val(qtyOrdered - qtyDispatched);
|
||||
if (mode === 'lessone')
|
||||
{
|
||||
qty = 1; // keep 1 in old line
|
||||
$("#qty_"+(nbrTrs-1)+"_"+index).val(qty);
|
||||
}
|
||||
$("#qty_" + nbrTrs + "_" + index).val(qtyOrdered - qtyDispatched);
|
||||
// Store arbitrary data for dispatch qty input field change event
|
||||
$("#qty_"+(nbrTrs-1)+"_"+index).data('qty', qty);
|
||||
$("#qty_"+(nbrTrs-1)+"_"+index).data('type', type);
|
||||
$("#qty_"+(nbrTrs-1)+"_"+index).data('index', index);
|
||||
$("#qty_" + (nbrTrs - 1) + "_" + index).data('qty', qty);
|
||||
$("#qty_" + (nbrTrs - 1) + "_" + index).data('type', type);
|
||||
$("#qty_" + (nbrTrs - 1) + "_" + index).data('index', index);
|
||||
// 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)
|
||||
$("#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,26 +178,28 @@ function addDispatchLine(index, type, mode)
|
||||
* element requires arbitrary data qty (value before change), type (type of dispatch) and index (index of product line)
|
||||
*/
|
||||
|
||||
function onChangeDispatchLineQty() {
|
||||
var index = $(this).data('index'),
|
||||
type = $(this).data('type'),
|
||||
qty = parseFloat($(this).data('qty')),
|
||||
function onChangeDispatchLineQty(element) {
|
||||
var type = $(element).data('type'),
|
||||
qty = parseFloat($(element).data('expected')),
|
||||
changedQty, nbrTrs, dispatchingQty, qtyOrdered, qtyDispatched;
|
||||
id = $(element).attr("id");
|
||||
id = id.split("_");
|
||||
index = id[2];
|
||||
|
||||
if (index >= 0 && type && qty >= 0) {
|
||||
nbrTrs = $("tr[name^='"+type+"_'][name$='_"+index+"']").length;
|
||||
qtyChanged = parseFloat($(this).val()) - qty; // qty changed
|
||||
qtyDispatching = parseFloat($("#qty_"+(nbrTrs-1)+"_"+index).val()); // qty currently being dispatched
|
||||
qtyOrdered = parseFloat($("#qty_ordered_0_"+index).val()); // qty ordered
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_"+index).val()); // qty already dispatched
|
||||
nbrTrs = $("tr[name^='" + type + "_'][name$='_" + index + "']").length;
|
||||
qtyChanged = parseFloat($(element).val()) - qty; // qty changed
|
||||
qtyDispatching = parseFloat($(element).val()); // qty currently being dispatched
|
||||
qtyOrdered = parseFloat($("#qty_ordered_0_" + index).val()); // qty ordered
|
||||
qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()); // qty already dispatched
|
||||
|
||||
console.log("onChangeDispatchLineQty qtyChanged: " + qtyChanged + " qtyDispatching: " + qtyDispatching + " qtyOrdered: " + qtyOrdered + " qtyDispatched: "+ qtyDispatched);
|
||||
console.log("onChangeDispatchLineQty qtyChanged: " + qtyChanged + " qtyDispatching: " + qtyDispatching + " qtyOrdered: " + qtyOrdered + " qtyDispatched: " + qtyDispatched);
|
||||
|
||||
if ((qtyChanged) <= (qtyOrdered - (qtyDispatched + qtyDispatching))) {
|
||||
$("#qty_dispatched_0_"+index).val(qtyDispatched + qtyChanged);
|
||||
$("#qty_dispatched_0_" + index).val(qtyDispatched + qtyChanged);
|
||||
} else {
|
||||
$(this).val($(this).data('qty'));
|
||||
$(element).val($(element).data('expected'));
|
||||
}
|
||||
$(this).data('qty', $(this).val());
|
||||
$(element).data('expected', $(element).val());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,4 +51,6 @@ NoMorePredefinedProductToDispatch=No more predefined products to dispatch
|
||||
ReceptionExist=A reception exists
|
||||
ReceptionBackToDraftInDolibarr=Reception %s back to draft
|
||||
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
|
||||
1135
htdocs/reception/dispatch.php
Normal file
1135
htdocs/reception/dispatch.php
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user