window.onbeforeunload = function() { //removeDocumentReservations(document.getElementById("temp_id").value); //saveDocumentReservations(document.getElementById("temp_id").value); //alert("Wprowadzone zmiany nie zostały zapisane"); }; var selectGetValue = function(encoded) { if(typeof encoded == 'undefined') { encoded = false; } var data = []; for(var i in this.children) { var tmp = this.children[i]; if(typeof tmp == 'object') { if(true == tmp.selected) { data.push(tmp.value); } } } // console.log(data); return encoded ? JSON.stringifyNoSecurity(data) : data; } function NumberToUserFormatNumber(number,add) { if(!number) number = 0; number = parseFloat(number); var tmp = number.toFixed(OPT['dec_len']); var s1 = tmp.substring(0,tmp.length-1-OPT['dec_len']); var s2 = tmp.substring(tmp.length-OPT['dec_len'],tmp.length); var tmp = ''; for(var i=s1.length;i>0;i-=3) { tmp = ((i<=3)?"":OPT['sep_1000'])+s1.substring(i-3,i)+tmp; } s1 = tmp; return (s1+OPT['dec_sep']+s2).toString()+((add)?add:''); } function UserFormatNumberToNumber(ufn,add) { if(add) { var match = /add/g; ufn = ufn.replace(match,''); } var match = /Err/g; ufn = ufn.replace(match,''); if(!ufn) return parseFloat(0); var pos = ufn.indexOf(OPT['dec_sep']); var s1='', s2=''; if(pos==-1) { s1 = ufn; s2 = ''; } else { s1 = ufn.substring(0,pos); s2 = ufn.substring(pos+1,ufn.length); } /* if(OPT['sep_1000'] != "") for(var i=s1.length-4;i>=0;i-=4) if(s1.charAt(i) != OPT['sep_1000']) { return -1; } if(s1.charAt(0) == OPT['sep_1000']) return -1; */ var pos = -1; while((pos = s1.indexOf(OPT['sep_1000'])) != -1) s1 = s1.substring(0,pos)+s1.substring(pos+1,s1.length); //alert(s1); return parseFloat(s1+"."+s2); } function DateDiff(d1, d2) { return d1.getTime() - d2.getTime(); }; function DaysToMilliseconds(days) { return days * (1000 * 60 * 60 * 24); } function MillisecondsToDays(milliseconds) { return Math.round(milliseconds / (1000 * 60 * 60 * 24)); } function changer() { this.list = new Object(); this.add = function(object, type, do_function, start_value) { if (typeof(object) == "string") { object = document.getElementById(object); } if (!object) { return; } this.list[object.id] = new Object(); this.list[object.id].object = object; this.list[object.id].type = type; this.list[object.id].do_function = do_function; this.list[object.id].start_value = start_value; this.list[object.id].value = ''; }; this.getValue = function(element) { var value = null; if (element.object) { if (element.type == "innerHTML") { value = element.object.innerHTML; } if (element.type == "value") { value = element.object.value; } if (element.type == "checked") { value = element.object.checked; } } return value; }; this.interval = 1000; this.timer = null; this.startTimer = function() { var cc = this; this.timer = setInterval( function() { var list = cc.list; for (x in list) { if (list[x].start_value) { list[x].value = cc.getValue(list[x]); list[x].start_value = false; } else { var value = cc.getValue(list[x]); if (list[x].value !== value) { if (list[x].do_function) { list[x].do_function(list[x].object); } } list[x].value = value; } } }, this.interval ); }; this.stopTimer = function() { clearInterval(this.timer); this.timer = null; }; } function BlockProducts() { return true; 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 updatePositions() { var data = {}; for(var i = 0, iC = N.rowCount(); i < iC; i++) { var tmp = N.row(i); var rowData = tmp.getData(); if(false != rowData.i_code) { data[rowData.i_code] = rowData; } // tmp.parentNode.deleteRow(); // tmp.deleteRow(); } // console.clear(); // console.log(data); clearData(); // return true; var encoded = JSON.stringifyNoSecurity(data); // console.log(encoded); // return true; var types = document.getElementById('type').children; var type = ''; for(var i in types) { var tmp = types[i]; // console.log(tmp); if(true == tmp.selected) { type = tmp.value; break; } } url = 'index.php?module=EcmFkVatKinds&action=updatepositions&type=' + type + '&data=' + encoded; // console.log(url); var req = mint.Request(); req.OnSuccess = function() { console.log('responseText', this.responseText); document.getElementById('items_list').value = this.responseText.replace(/"/g, '\''); fillData(); return; }; req.Send(url); } function clearData() { // console.log(N.rowCount()); while(N.rowCount() > 0) { N.row(0).deleteRow(true); } /* for(var i = 0, iC = N.rowCount(); i < iC; i++) { var tmp = N.row(i); // console.log(tmp); // tmp.deleteRow(); // tmp.parentNode.deleteRow(); } */ // N.row(0).deleteRow(); // N.addRow(); } function saveDocumentReservations(temp_id, operation) { return true; url = 'index.php?module=EcmStockOperations&action=saveDocumentReservations&temp_doc_id=' + temp_id + '&to_pdf=1'; var req = mint.Request(); req.OnSuccess = function() { switch (operation) { case 'cancel': case 'list': default: //window.location = "index.php?module=EcmFkVatKinds&action=index"; break; } return; }; req.Send(url); } function removeDocumentReservations(temp_id, operation) { return true; url = 'index.php?module=EcmStockOperations&action=deleteDocumentReservations&temp_doc_id=' + temp_id + '&to_pdf=1'; var req = mint.Request(); req.OnSuccess = function() { switch (operation) { case 'cancel': case 'list': default: window.location = "index.php?module=EcmFkVatKinds&action=index"; break; } return; }; req.Send(url); } function getProductQuantity(rowIndex, operation) { return true; //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(); //console.log(data); data.stock = this.responseText; N.row(rowIndex).setData(data); if (!data.reserved) data.reserved = 0; if (operation == "saveReservation") { N.row(rowIndex).className = ''; saveReservation(rowIndex, false); //console.log(data); if (parseFloat(data.stock) >= data.rq) { N.row(rowIndex).addClass('greenRow'); } else { N.row(rowIndex).addClass('redRow'); } return; //console.log(data); //N.row(rowIndex).className=''; //if qty = 0 do clear reserved field if (data.rq == 0) { N.row(rowIndex).setData(); removeReservation(rowIndex); } if (data.quantity >= data.rq) { /* saveReservation(rowIndex, false); return; */ if (data.stock >= data.rq) { saveReservation(rowIndex, false); return; } if ((data.stock < data.rq) && (parseFloat(data.stock) + parseFloat(data.rq) > 0)) { // console.log(data.stock); // console.log(data.rq); // console.log(parseFloat(data.stock) + parseFloat(data.rq)); saveReservation(rowIndex, true, parseFloat(data.stock) + parseFloat(data.rq)); // orange row true; return; } if (data.quantity == 0) { data.reserved = 0; N.row(rowIndex).setData(); removeReservation(rowIndex); setTimeout(function() { getProductQuantity(rowIndex); }, 1000); return; } /* //stock > qty - all OK, can reserve if (data.stock>=data.quantity-data.reserved) { saveReservation(rowIndex, false); return; } if ((data.stock<(data.quantity-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.quantity-data.reserved)) { N.row(rowIndex).className = 'redRow'; return; } */ } //if (data.stock < data.rq || data.quantity > data.rq) { N.row(rowIndex).addClass('redRow');//className = 'redRow'; // return; //} } }; req.Send(url); } function saveReservation(rowIndex, orangeRow, qty) { return true; //console.log('saveReservation'); var data = N.row(rowIndex).getData(); //console.log(data); 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(4).getElementsByTagName('input')[0].value = NumberToUserFormatNumber(data.reserved); //cell(3).getElementById("reservation_info").innerHtml if (orangeRow == true) N.row(rowIndex).addClass('orangeRow'); //.className = 'orangeRow'; else N.row(rowIndex).addClass('greenRow'); //.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 selectedKind = null; //var selectingColor = "red"; //var selectingCellKind = "green"; var KindIndex = 0; for (var i = 0; i < td.length; i++) { if (td[i].className == "tabEditViewDF") { var TI = 0; if (td[i].parentNode.cells.item(1) == td[i]) TI = 101 + KindIndex; else TI = 102 + KindIndex; var nodes = td[i].getElementsByTagName("input"); for (var j = 0; j < nodes.length; j++) nodes[j].tabIndex = TI; var nodes = td[i].getElementsByTagName("select"); for (var j = 0; j < nodes.length; j++) nodes[j].tabIndex = TI; var nodes = td[i].getElementsByTagName("textarea"); for (var j = 0; j < nodes.length; j++) nodes[j].tabIndex = TI; if (td[i].parentNode.parentNode.parentNode !== selectedKind) { //if(selectingColor == "red") selectingColor = "blue"; else selectingColor = "red"; selectedKind = td[i].parentNode.parentNode.parentNode; KindIndex++; } } } } function doRequest(where, post, doFunction, error) { this.Display = function(result) { doFunction(result.responseText); } this.Fail = function(result) { if (error) alert(error); } YAHOO.util.Connect.asyncRequest( "POST", where, { success: this.Display, failure: this.Fail }, post ); } function changeValidateRequired(formname, name, required) { for (var i = 0; i < validate[formname].length; i++) if (validate[formname][i][0] == name) { validate[formname][i][2] = required; break; } } function set_focus() { return; document.getElementById("name").focus(); } function my_popup(module, field_array, met, call_back_function, form_name, customurl) { // console.log(module, field_array, met, call_back_function, form_name, customurl); // return; if (!call_back_function) { call_back_function = "set_return"; } if (!form_name) { form_name = "EditView"; } // module_name, // width, // height, // initial_filter, // close_popup, // hide_clear_button, // popup_request_data, // popup_mode, // create, // metadata, // customurl return open_popup( module, 900, 700, met, true, false, { "call_back_function": call_back_function, "form_name": form_name, "field_to_name_array": field_array }, false, false, false, customurl ); } function addEvent(object, eventName, do_function) { if (typeof(object) == "string") object = document.getElementById(object); if (!object) { alert("No object in function addEvent!"); return; } if (object.addEventListener) { object.addEventListener(eventName, do_function, false); } else { object.attachEvent("on" + eventName, do_function); } } function findPos(obj) { var nleft = 0; var ntop = 0; if (obj.offsetParent) { nleft = obj.offsetLeft ntop = obj.offsetTop while (obj = obj.offsetParent) { nleft += obj.offsetLeft ntop += obj.offsetTop } } return [nleft, ntop]; } function cursorEOT(isField) { isRange = isField.createTextRange(); isRange.move("textedit"); isRange.select(); testOverflow = isField.scrollTop; if (testOverflow != 0) { return true } else { return false } } function adjustRows(isField) { while (cursorEOT(isField)) { isField.rows++ } } function insertText(isField, isText) { isField.value = testText; isField.focus(); } var ERROR = false; var ItemListSave = function(json) { return ""; } var FkVatKindListSave = function(json) { return ""; } var IncomeListSave = function(json) { return ""; } function ShowLoadingView() { var slv = document.getElementById("ShowLoadingView"); if (!slv) { slv = document.createElement("div"); slv.id = "ShowLoadingView"; slv.className = "transparent_class_loading"; slv.style.width = "100%"; slv.style.height = "500%"; var sli = document.createElement("img"); sli.className = "transparent_class_loading_image"; sli.src = "themes/default/images/loading.gif"; slv.appendChild(sli); document.body.appendChild(slv); } slv.style.display = ""; } function HideLoadingView() { var slv = document.getElementById("ShowLoadingView"); if (slv) slv.style.display = "none"; } function ItemsList(json) { var data = ''; for(var i=0; i= 0) { removeHistoryRecord(idParts[1]); //paretLi.removeChild(idParts[1]); paretLi.style.display = 'none'; } //console.log(paretLi.parentNode.children ); // Hide no-results item if needed. if (paretLi.parentNode.children.length == 0) { // } return true; } function addHistoryRecord(date, owner, record) { var historyRecord = [ date, owner, record ]; var historyElement = document.forms.EditView.history; var historyValue = JSON.parse(historyElement.value); historyValue.unshift(historyRecord); historyElement.value = JSON.stringifyNoSecurity(historyValue); // Bof: Build list item. { var recordLi = document.createElement('li'); var dateP = document.createElement('p'); dateP.appendChild(document.createTextNode(date)); dateP.appendChild(document.createTextNode(', ')); dateP.appendChild(document.createTextNode(owner)); dateP.appendChild(document.createTextNode(':')); //var ownerP = document.createElement('p'); //ownerP.appendChild(document.createTextNode(owner)); var recordP = document.createElement('p'); recordP.appendChild(document.createTextNode(record)); recordLi.appendChild(dateP); //recordLi.appendChild(ownerP) recordLi.appendChild(recordP); } // Eof: Build list item. // Prepend new history record. var wrapperList = document.getElementById('history_wrapper').children[0]; // Hide no-results item if needed. if (wrapperList.children.length == 1 && wrapperList.children[0].getAttribute('class') == 'no-results') { wrapperList.children[0].style.display = 'none'; } wrapperList.insertBefore(recordLi, wrapperList.firstChild); return true; } function addHistory() { // Grab important form fields. var owner = document.forms.EditView.history_owner; var date = document.forms.EditView.history_date; var record = document.forms.EditView.history_record; // Check values. if (owner.value.length == 0 || date.value.length == 0 || record.value.length == 0) { alert('Wypełnij wszystkie pola.'); return false; } // Create row, update hidden history value. addHistoryRecord(date.value, owner.value, record.value); var date = new Date(); // Reset form. owner.value = ''; date.value = date.toString('d.m.Y'); record.value = ''; return true; } function SaveForm() { ShowLoadingView(); setTimeout(function() { if (OPT["checkbox_demo"] == 1 && document.forms.EditView.record.value == "") { alert(MOD.LBL_DEMO_VERSION_INFORMATION); return; } ERROR = false; //document.getElementById("position_list").value = ItemListSave(true); if (ERROR) { alert(MOD["LBL_SAVE_FORM_ERROR"]); HideLoadingView(); return false; } document.forms.EditView.action.value = "Save"; if (check_form("EditView")) { //var result = confirm(MOD.LBL_CONFIRM_QUESTION); //if(result) document.forms.EditView.status.value = (OPT["auto_commiting"]?"s30":"s20"); doRequest( "index.php", getFormPost("Save"), function(result) { /* console.log(result); HideLoadingView(); return; */ document.forms.EditView.record.value = result.substring(result.length - 36); if (OPT["setEmailTab"]) setEMAIL(true); else window.location = "index.php?module=" + document.forms.EditView.module.value + "&action=DetailView&record=" + document.forms.EditView.record.value; }, MOD["LBL_NOT_SAVED"] ); } else { alert(MOD["LBL_NOT_SAVED"]); HideLoadingView(); return false; } }, 200); } function ItemListClear() { while (N.rowCount() > 0) N.row(0).deleteRow(); } function getFormPost(action) { if (!action) action = "previewPDF"; var pd = "to_pdf=1" + "&module=EcmFkVatKinds&action=" + action + "&record=" + document.forms.EditView.record.value; pd += "&cache=fromJava" + ItemListSave(true) + FkVatKindListSave(true) + IncomeListSave(true); // pd += '&history=' + document.forms.EditView.history.value; var pd2 = new Object(); pd2["module"] = "EcmFkVatKinds"; pd2["action"] = action; pd2["record"] = document.forms.EditView.record.value; pd2["to_pdf"] = "1"; pd2["cache"] = "fromJava"; //pd2['history'] = document.forms.EditView.history.value; // document.forms.EditView.position_list.value = ""; document.forms["EditView"].action.value = action; var tmp; for (var i = 0; i < document.forms["EditView"].elements.length; i++) { tmp = document.forms["EditView"].elements[i]; if (tmp.name != "") { if (tmp.type == "checkbox") pd2[document.forms["EditView"].elements[i].name] = (document.forms["EditView"].elements[i].checked ? "1" : "0"); else pd2[document.forms["EditView"].elements[i].name] = document.forms["EditView"].elements[i].value; } } pd += "&otherFormData=" + JSON.stringifyNoSecurity(pd2); return pd; } function sendFormPostToPdf(type, panel) { var tab = '_'; if (type != null) { tab += type.toUpperCase(); } ERROR = false; document.getElementById("position_list").value = ItemListSave(true); document.getElementById("fkvatkinds_list").value = FkVatKindListSave(true); document.getElementById("income_list").value = IncomeListSave(true); if (ERROR) { alert("There are some errors on list"); return false; } doRequest( "index.php", getFormPost("previewPDF"), function(result) { //console.log(result); //return; if (SHOW_PDF_IN_DIV == 1) { HideLoadingView(); EcmPreviewPDF( "index.php?module=EcmFkVatKinds&action=previewPDF&to_pdf=1&from=EcmFkVats&type=" + type, { zoom: 75 } ); } else { SetTab((panel ? "panel_" : "") + "PREVIEW" + tab); document.getElementById("previewPDF" + tab).innerHTML = ''; } } ); } preview_pdf = function() { var dateFrom = document.getElementById('date_from') ? document.getElementById('date_from').value : ''; var dateTo = document.getElementById('date_to') ? document.getElementById('date_to').value : ''; console.clear(); console.log(dateFrom, dateTo); document.getElementById('preview_type').getValue = selectGetValue; var type = document.getElementById('preview_type').getValue(); var doc_checked = document.getElementById('doc_checked'); var checked = true; if(doc_checked) { checked = doc_checked.checked; } // console.log(type); // return; // var record = '6a2fb28b-284e-f5aa-c439-51ff49f85b12'; var record = document.getElementById('record').value; doRequest( "index.php", getFormPost("previewPDF"), function(result) { //console.log(result); //return; if (SHOW_PDF_IN_DIV == 1) { HideLoadingView(); var url = "index.php?module=EcmFkVatKinds&action=previewPDF&to_pdf=1&from=EcmFkVats&record=" + record + "&type=" + type + "&date_from=" + dateFrom + "&date_to=" + dateTo + '&doc_checked=' + (checked ? 'true' : 'false') ; // console.log(url); EcmPreviewPDF( url, { zoom: 75 } ); } else { document.getElementById("previewPDF").innerHTML = ''; } } ); //document.getElementById('previewPDF').innerHTML = ''; } function canConfirm() { if (document.forms.EditView.status.value == "accepted" && !OPT.user.confirm_quotes) { alert("This option is disabled for You."); document.forms.EditView.status.value = ((OPT.old_status) ? OPT.old_status : ""); } OPT.old_status = document.forms.EditView.status.value; } function CheckDiscount(noAlert) { var discount = 0; return 0; } var AjaxSearch1Items; var AjaxSearch2Items; var AjaxSearch3Items; var parentFL; var productFL; var contactFL;