window.onbeforeunload = function() { removeDocumentReservations(document.getElementById("temp_id").value); alert('Wprowadzone zmiany nie zostały zapisane'); } function removeDocumentReservations(temp_id, operation) { //alert(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=EcmInvoiceOuts&action=index"; if (operation=='list') window.location="index.php?module=EcmInvoiceOuts&action=index"; } } req.Send(url); } function getProductQuantity(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() { console.log(old_qty); 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 saveReservation(stock_id,product_id,quantity,temp_doc_id,temp_item_id,date, row){ 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(){ row.className='greenRow'; setTimeout(function() {row.className='selectedRow';}, 1500); } req.Send(url); } function removeReservation(cell) { var temp_item_id = cell.parentNode.getData().temp_item_id; url='index.php?module=EcmStockOperations&action=deleteReservation&temp_item_id='+temp_item_id+'&to_pdf=1'; var req=mint.Request(); req.OnSuccess = function(){} req.Send(url); } function createEcmInvoiceOut() { var selected_prod = false; for(var i=0; i0) { data = cell.parentNode.getData(); getProductQuantity(cell.parentNode.getElementsByTagName("input")[10],data.id,document.getElementById("stock_id").value,data.stock, cell.parentNode); setTimeout(function() { data.stock=cell.parentNode.getElementsByTagName("input")[10].value; cell.parentNode.setData(data); if ((data.quantity-old_qty) > data.stock) { cell.parentNode.setData(data); cell.parentNode.className='redRow'; setTimeout(function() {cell.parentNode.className='selectedRow';}, 1500); return; } //remove current temp reservation removeReservation(cell); // save temp reservation if (data.quantity-data.service_rq > 0) saveReservation(document.getElementById("stock_id").value,data.id,data.quantity-data.service_rq,document.getElementById("temp_id").value,data.temp_item_id,data.temp_date,cell.parentNode); //refresh state getProductQuantity(cell.parentNode.getElementsByTagName("input")[10],data.id,document.getElementById("stock_id").value,data.stock); setTimeout(function() { data.stock = cell.parentNode.getElementsByTagName("input")[10].value; cell.parentNode.setData(data); }, 500); },500); } } var edit = ''; cell.innerHTML = edit; } //realizacja zamówienia if(i == 4) { cell.change = function(select) { var c; if(select) { c = this.childNodes[0]; c.name = 'service_qty_p'; c.id = 'service_qty_p'; } else { c = this.childNodes[0]; c.name = ''; c.id = ''; } } cell.getData = function(data,noAlert) { var tmp = UserFormatNumberToNumber(this.firstChild.value); if(tmp == -1) { ERROR = true; data.service_qty = 0; this.firstChild.style.color = 'red'; } else { data.service_qty = tmp; this.firstChild.style.color = 'black'; } } cell.setData = function(data) { if(data.service_qty) this.firstChild.value = NumberToUserFormatNumber(data.service_qty); else this.firstChild.value = NumberToUserFormatNumber(0); } cell.onDeselect = function() { ERROR = false; var data = new Object(); this.getData(data); if(!ERROR) { data.quantity = data.quantity; this.setData(data); } } var edit = ''; cell.innerHTML = edit; } //magazyn if(i == 5) { cell.change = function(select) { var c; if(select) { c = this.childNodes[0]; c.name = 'stock_p'; c.id = 'stock_p'; } else { c = this.childNodes[0]; c.name = ''; c.id = ''; } } cell.getData = function(data,noAlert) { var tmp = UserFormatNumberToNumber(this.firstChild.value); if(tmp == -1) { ERROR = true; data.stock = 0; this.firstChild.style.color = 'red'; } else { data.stock = tmp; this.firstChild.style.color = 'black'; } } cell.setData = function(data) { var dat = cell.parentNode.getData(); if (dat.type=='service') {this.firstChild.value='usługa'; return;} if(data.stock) this.firstChild.value = NumberToUserFormatNumber(data.stock); else this.firstChild.value = NumberToUserFormatNumber(0); } cell.onDeselect = function() { ERROR = false; var data = new Object(); this.getData(data); if(!ERROR) { data.stock = data.stock; this.setData(data); } } var stock; stock = document.createElement('input'); stock.setAttribute('type','text'); stock.className = 'inputs'; stock.style.textAlign = "right"; stock.cell = cell; cell.appendChild(stock); } } N.onSetCellData = function(row,cell,data) { if(cell.innerHTML == '') cell.innerHTML = ' '; } var pl = document.getElementById('position_list').value; if(pl && pl != '') { try { pl = eval(pl); for(x in pl) { var pl_row = pl[x]; if(!pl[x].code || pl[x].code == '') {} else N.addRow().setData(pl_row); } } catch(err) { pl = null; }; } if(N.rowCount() == 0) N.addRow(); ItemsList = function(json) { var data = ''; for(var i=0; i