window.onbeforeunload = function() { removeDocumentReservations(document.getElementById("temp_id").value); alert("Wprowadzone zmiany nie zostały zapisane"); } function BlockProducts(){ var tab = document.getElementById("tbody"); var tr = tab.getElementsByTagName("tr"); var qty; var total; for(var i=0; i < tr.length; i++){ var inp=tr[i].getElementsByTagName("input"); var img=tr[i].getElementsByTagName("img"); var tx=tr[i].getElementsByTagName("textarea"); //console.log(inp); if (inp[2].value!='') { inp[1].setAttribute('readonly', 'readonly'); inp[1].setAttribute('onkeydown', ''); img[2].setAttribute('style', 'display:none'); //img[1].setAttribute('style', 'display:none'); } //if(inp[8].value==1)deleteEmptyComponents(inp[11].value); } return true; } function removeDocumentReservations(temp_id, operation) { url = 'index.php?module=EcmStockOperations&action=deleteDocumentReservations&temp_doc_id='+temp_id+'&to_pdf=1'; var req = mint.Request(); req.OnSuccess = function() { if (operation) { if (operation=='cancel') window.location="index.php?module=EcmStockDocOuts&action=index"; if (operation=='list') window.location="index.php?module=EcmStockDocOuts&action=index"; } } req.Send(url); } function getProductQuantity2(input,product_id, stock_id,old_qty, row){ url="index.php?module=EcmStockStates&action=getProductQuantity&stock_id="+stock_id+"&product_id="+product_id+"&to_pdf=1"; var req=mint.Request(); req.OnLoading=function() { input.innerHTML="loading"; } req.OnSuccess = function() { if (row) { if (parseFloat(this.responseText) != old_qty) { row.className="orangeRow"; setTimeout(function() { row.className="selectedRow"; }, 1500); } } input.value=this.responseText; } req.Send(url); } function getProductQuantity(rowIndex, operation) { //console.log('getProductQuantity'); var stock_id = document.getElementById("stock_id").value; var product_id = N.row(rowIndex).getData().id; url='index.php?module=EcmStockStates&action=getProductQuantity&stock_id=' + stock_id + '&product_id=' + product_id + '&to_pdf=1'; console.log(url); var req = mint.Request(); req.OnSuccess = function() { //console.log("getProductQuantity:OnSuccess"); //return; var data = N.row(rowIndex).getData(); data.stock = this.responseText; N.row(rowIndex).setData(data); if (!data.reserved) data.reserved = 0; if (operation == "saveReservation") { N.row(rowIndex).className=''; //if qty = 0 do clear reserved field if (data.rq == 0) { N.row(rowIndex).setData(); removeReservation(rowIndex); setTimeout( function() { getProductQuantity(rowIndex); }, 1000 ); return; } //stock > qty - all OK, can reserve if (data.stock >= data.reserved) { saveReservation(rowIndex, false); return; } if ((data.stock < data.reserved) && (parseFloat(data.stock) + parseFloat(data.reserved) > 0)) { saveReservation(rowIndex, true, parseFloat(data.stock)+parseFloat(data.reserved)); //orange row true; return; } //stock <= qty + res, sand reserve, do nothing if (data.stock < data.reserved) { N.row(rowIndex).className = 'redRow'; return; } } } req.Send(url); } function saveReservation2(rowIndex, orangeRow, qty){ //block change RW stock //document.getElementById("stock_id").disabled=true; //document.getElementById("pw_stock_id").disabled=true; var data = N.row(rowIndex).getData(); var product_id = data.id; var temp_item_id = data.temp_item_id; var quantity; if (qty) quantity = qty; else quantity = data.quantity; console.log(data.name+" qty: "+quantity); var date = document.getElementById("temp_date").value; var stock_id = document.getElementById("stock_id").value; var temp_doc_id = document.getElementById("temp_id").value; var url='index.php?module=EcmStockOperations&action=saveReservation&stock_id='+stock_id+'&product_id='+product_id+'&temp_doc_id='+temp_doc_id+'&temp_item_id='+temp_item_id+'&date='+date+'&quantity='+quantity+'&to_pdf=1'; var req=mint.Request(); req.OnSuccess = function(){ var data = N.row(rowIndex).getData(); data.reserved = quantity; N.row(rowIndex).setData(data); //N.row(rowIndex).cell(3).getElementById("reservation_info").innerHtml="("+data.reserved+")"; N.row(rowIndex).cells.item(3).getElementsByTagName('p')[0].innerHTML = NumberToUserFormatNumber(data.reserved); //cell(3).getElementById("reservation_info").innerHtml if (orangeRow==true) N.row(rowIndex).className = 'orangeRow'; else N.row(rowIndex).className = 'greenRow'; getProductQuantity(rowIndex, ''); } req.Send(url); } function saveReservation(rowIndex, orangeRow, qty){ //block change RW stock. Why ? //document.getElementById("stock_id").disabled = true; //document.getElementById("pw_stock_id").disabled = true; var data = N.row(rowIndex).getData(); var product_id = data.id; var temp_item_id = data.temp_item_id; var quantity; if (qty) quantity = qty; else quantity = data.rq; var date = document.getElementById("temp_date").value; var stock_id = document.getElementById("stock_id").value; var temp_doc_id = document.getElementById("temp_id").value; var url='index.php?module=EcmStockOperations&action=saveReservation&stock_id='+stock_id+'&product_id='+product_id+'&temp_doc_id='+temp_doc_id+'&temp_item_id='+temp_item_id+'&date='+date+'&quantity='+quantity+'&to_pdf=1'; //console.log(url); var req=mint.Request(); req.OnSuccess = function(){ //console.log("saveReservation:OnSuccess"); var data = N.row(rowIndex).getData(); data.reserved = quantity; N.row(rowIndex).setData(data); //N.row(rowIndex).cell(3).getElementById("reservation_info").innerHtml="("+data.reserved+")"; N.row(rowIndex).cells.item(3).getElementsByTagName('p')[0].innerHTML = NumberToUserFormatNumber(data.reserved); //cell(3).getElementById("reservation_info").innerHtml if (orangeRow == true) N.row(rowIndex).className = 'orangeRow'; else N.row(rowIndex).className = 'greenRow'; getProductQuantity(rowIndex, ''); } req.Send(url); } function removeReservation(index) { //Console.log('removeReservation'); var data = N.row(index).getData(); var temp_item_id = data.temp_item_id; url='index.php?module=EcmStockOperations&action=deleteReservation&temp_item_id='+temp_item_id+'&to_pdf=1'; //console.log('removeReservation: ' + url); var req=mint.Request(); req.OnSuccess = function() { //console.log('removeReservation OnSuccess'); } req.Send(url); } function SetTabIndexs() { var main = document.getElementById("main"); var td = main.getElementsByTagName("td"); var selectedTable = null; //var selectingColor = "red"; //var selectingCellTable = "green"; var TableIndex = 0; for(var i=0; i