Add JS files
This commit is contained in:
187
modules/EcmStockDocOuts/javascript/EcmStockDocOuts.js
Executable file
187
modules/EcmStockDocOuts/javascript/EcmStockDocOuts.js
Executable file
@@ -0,0 +1,187 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function () {
|
||||
$("#parent_name").attr("size", "70");
|
||||
$("#parent_name_copy").attr("size", "70");
|
||||
//change parent select button
|
||||
$("#btn_clr_parent_name").children().attr("src", "themes/default/images/id-ff-add.png");
|
||||
$("#btn_clr_parent_name").attr("title", "Dodaj");
|
||||
$("#btn_clr_parent_name").click(createAccount);
|
||||
|
||||
// parent info
|
||||
|
||||
var previousVal;
|
||||
var pollInterval = setInterval(function () {
|
||||
var val = $('#parent_id').val();
|
||||
if (val !== previousVal) {
|
||||
if ($('#parent_id').val() == '') return;
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function () {
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
}
|
||||
previousVal = val;
|
||||
}, 500);
|
||||
|
||||
|
||||
//newProduct
|
||||
var previousVal2;
|
||||
var prodInterval = setInterval(function () {
|
||||
var val = $('#newProductId').val();
|
||||
if (val !== previousVal2) {
|
||||
if ($('#newProductId').val() == '') return;
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function () {
|
||||
AddProduct(items.length - 1, val);
|
||||
}, 500);
|
||||
}
|
||||
previousVal2 = val;
|
||||
}, 500);
|
||||
var checkgen;
|
||||
// confirm exit
|
||||
window.onbeforeunload = confirmExit;
|
||||
// prevent submit by enter press
|
||||
lockEnter();
|
||||
// categories
|
||||
getCategoriesList();
|
||||
$('#parent_id').on('inputchange',
|
||||
function () {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function () {
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
});
|
||||
$("#stock").change(function () {
|
||||
$("#stock_id").val(($("#stock :selected").val()));
|
||||
});
|
||||
DrawHeaders();
|
||||
|
||||
$("#assigned_user_name").prop("disabled", true);
|
||||
|
||||
$("#btn_assigned_user_name").hide();
|
||||
$("#btn_clr_assigned_user_name").hide();
|
||||
$(".loading_panel").css("display", "none");
|
||||
|
||||
if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() != true) && ($("#ecmsale").val() != true)) {
|
||||
var ecp = $("#ecommerce_products").val();
|
||||
if (ecp && ecp.length > 0) {
|
||||
loadECommerceProducts(ecp);
|
||||
}
|
||||
checkgen = 1;
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() == true)) {
|
||||
checkgen = 1;
|
||||
getItems();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#ecmsale").val() == true)) {
|
||||
checkgen = 1;
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
|
||||
getItemsFromEcmSale();
|
||||
|
||||
} else {
|
||||
checkgen = 0;
|
||||
}
|
||||
|
||||
if (checkgen == 1) {
|
||||
$("#stock").change(function () {
|
||||
$("#stock_id").val(($("#stock :selected").val()));
|
||||
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocOuts');
|
||||
checkProducts();
|
||||
});
|
||||
}
|
||||
if ($("#stock_id").val() != '') {
|
||||
$("#stock_id").val(($("#stock :selected").val()));
|
||||
if (checkgen == 1) {
|
||||
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocOuts');
|
||||
}
|
||||
}
|
||||
// handle setItems
|
||||
setITEMS = function () {
|
||||
var formname = 'EditView';
|
||||
if (check_form_(formname) == true) {
|
||||
SetTab('ITEMS');
|
||||
//checkProducts();
|
||||
//disable stock change
|
||||
$("#stock").prop("disabled", true);
|
||||
}
|
||||
};
|
||||
// wyszukiwanie start
|
||||
$('#searchProductsInput').keyup(function () {
|
||||
// stronicowanie od 1 strony przy zmianie szukanego produktu
|
||||
$('#searchStart').val(0);
|
||||
searchProducts();
|
||||
});
|
||||
AddSearchRecord();
|
||||
});
|
||||
|
||||
function loadECommerceProducts(ecp) {
|
||||
var products = JSON.parse(ecp);
|
||||
items = products;
|
||||
FillTable(products);
|
||||
}
|
||||
// handle save
|
||||
async function saveDocument() {
|
||||
if (!check_form_('EditView')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (items.filter(x => x.product_id !=='').length === 0) {
|
||||
alert("Brak produktów");
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
items[i].part_no = $("#part_no_" + i).val();
|
||||
items[i].un_code = $("#un_code_" + i).val();
|
||||
}
|
||||
|
||||
$(".loading_panel").css("display", "block");
|
||||
await sleep(50);
|
||||
if (!await checkProducts()) {
|
||||
alert("Brak produktów na stanie");
|
||||
return;
|
||||
}
|
||||
//save
|
||||
$(".loading_panel").css("display", "block");
|
||||
await sleep(50);
|
||||
$("#register_date").prop("disabled", false);
|
||||
$("#assigned_user_name").prop("disabled", false);
|
||||
$('#EditView input[name="action"]').val('Save');
|
||||
clearEmpty();
|
||||
$("#position_list").val(JSON.stringifyNoSecurity(items));
|
||||
window.onbeforeunload = null;
|
||||
$.ajax({
|
||||
url: 'index.php?to_pdf=1',
|
||||
method: 'POST',
|
||||
data: $('#EditView').serialize(),
|
||||
success: function(data) {
|
||||
window.location.replace("index.php?module=EcmStockDocOuts&action=DetailView&record="+data);
|
||||
},
|
||||
error: function(error) {
|
||||
alert("Błąd zapisu!");
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
var check_form_ = check_form;
|
||||
|
||||
function confirmExit() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function lockEnter() {
|
||||
// prevent default
|
||||
$(window).keydown(function (event) {
|
||||
if (event.keyCode == 13 && $(":focus").prop('tagName') != 'TEXTAREA') {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user