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; i0) N.row(0).deleteRow(); } function CheckDiscount(noAlert) { var discount = 0; var tmp = UserFormatNumberToNumber(document.getElementById('discount').value); if(tmp == -1) { if(!noAlert) alert(MOD['LBL_DISCOUNT_ERROR']+' ('+document.getElementById('discount').value+')'); discount = -1; document.getElementById('discount').style.color = 'red'; } else { discount = tmp; document.getElementById('discount').value = NumberToUserFormatNumber(discount); document.getElementById('discount').style.color = 'black'; } return discount; } function sendToConfirmEcmStockDocIn(record) { if(typeof(record) == "string") { var status = "s20"; doRequest( 'index.php', 'module=EcmStockDocIns&action=SetStatus&to_pdf=1&status='+status+'&record='+record, function(results) { var obj = eval(results); if(obj[0]) obj = obj[0]; if(typeof(obj) == "object") { if(document.forms.DetailView.record.value == obj['record']) { document.getElementById('statusEcmStockDocIn').innerHTML = obj['status']['text']; if(obj['status']['code'] == "s20") { document.forms.DetailView.send_to_confirm.style.display = 'none'; document.forms.DetailView.edit_button.style.display = 'none'; var c = document.getElementById('confirmingEcmStockDocIn'); if(c) c.style.display = ''; } if(obj['status']['code'] == "s30") { document.forms.DetailView.send_to_confirm.style.display = 'none'; document.forms.DetailView.edit_button.style.display = 'none'; document.getElementById('confirmingEcmStockDocIn').style.display = 'none'; document.forms.DetailView.quote_to_sale.style.display = ''; document.forms.DetailView.quote_to_invoice.style.display = ''; } } alert(obj['message']); } } ); } } function AcceptEcmStockDocIn(record) { if(typeof(record) == "string") { var status = "s30"; doRequest( 'index.php', 'module=EcmStockDocIns&action=SetStatus&to_pdf=1&status='+status+'&record='+record, function(results) { var obj = eval(results); if(obj[0]) obj = obj[0]; if(typeof(obj) == "object") { if(document.forms.DetailView.record.value == obj['record']) { document.getElementById('statusEcmStockDocIn').innerHTML = obj['status']['text']; if(obj['status']['code'] == "s30") { document.forms.DetailView.send_to_confirm.style.display = 'none'; document.forms.DetailView.edit_button.style.display = 'none'; document.getElementById('confirmingEcmStockDocIn').style.display = 'none'; document.forms.DetailView.quote_to_sale.style.display = ''; document.forms.DetailView.quote_to_invoice.style.display = ''; } } alert(obj['message']); } } ); } } function RejectEcmStockDocIn(record) { if(typeof(record) == "string") { var status = "s40"; doRequest( 'index.php', 'module=EcmStockDocIns&action=SetStatus&to_pdf=1&status='+status+'&record='+record, function(results) { var obj = eval(results); if(obj[0]) obj = obj[0]; if(typeof(obj) == "object") { if(document.forms.DetailView.record.value == obj['record']) { document.getElementById('statusEcmStockDocIn').innerHTML = obj['status']['text']; if(obj['status']['code'] == "s40") { document.getElementById('confirmingEcmStockDocIn').style.display = 'none'; document.forms.DetailView.edit_button.style.display = ''; } } alert(obj['message']); } } ); } } addEvent( window, 'load', function () { //initialize table N = new MyTable('itemsTable'); N.onRefreshRowIndex = function(row) { var data = new Object(); data['index'] = (row.index+1).toString(); row.cells.item(0).setData(data); } N.onCreateRow = function(row) { row.newPos = false; row.ondblclick = function() { this.newPos = !this.newPos; var img = this.cells.item(1).getElementsByTagName('img'); if(!this.newPos) img[0].src = "modules/EcmStockDocIns/images/edit.gif"; else img[0].src = "modules/EcmStockDocIns/images/editset.gif"; for(var i=0; i'; cell.innerHTML = edit; } if(i == 4) { cell.getData = function(data,noAlert) { data.unit_name = this.firstChild.value; } cell.setData = function(data) { this.firstChild.value = data.unit_name; } var edit = ''; cell.innerHTML = edit; } if(i == 5) { cell.getData = function(data,noAlert) { var tmp = UserFormatNumberToNumber(this.firstChild.value); if(tmp == -1) { ERROR = true; if(!noAlert) alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')'); data.invoice_price = 0; this.firstChild.style.color = 'red'; } else { data.invoice_price = tmp; this.firstChild.style.color = 'black'; } } cell.setData = function(data) { if(data.invoice_price) this.firstChild.value = NumberToUserFormatNumber(data.invoice_price); else this.firstChild.value = NumberToUserFormatNumber(0); } var edit = ''; cell.innerHTML = edit; } if(i == 6) { cell.getData = function(data,noAlert) { var tmp = UserFormatNumberToNumber(this.firstChild.value); if(tmp == -1) { ERROR = true; if(!noAlert) alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')'); data.price = 0; this.firstChild.style.color = 'red'; } else { data.price = tmp; this.firstChild.style.color = 'black'; } } cell.setData = function(data) { if(data.price) this.firstChild.value = NumberToUserFormatNumber(data.price); else this.firstChild.value = NumberToUserFormatNumber(0); } var edit = ''; cell.innerHTML = edit; } if(i == 7) { cell.getData = function(data,noAlert) { var cn = this.getElementsByTagName('input'); data.vat_value = cn[0].value; data.vat_id = cn[1].value; if(VAT[cn[1].value])data.vat_name = VAT[cn[1].value].name; } cell.setData = function(data) { if(data.vat_value) this.getElementsByTagName('input')[0].value = data.vat_value; if(data.vat_id) this.getElementsByTagName('input')[1].value = data.vat_id; if(data.vat_name) this.getElementsByTagName('input')[2].value = data.vat_name; } cell.onDeselect = function() { ERROR = false; var data = new Object(); this.getData(data); if(!ERROR) { data.vat_id = data.vat_id; this.setData(data); } } var inp=document.createElement('input'); inp.setAttribute('type','hidden'); cell.appendChild(inp); var inp=document.createElement('input'); inp.setAttribute('type','hidden'); cell.appendChild(inp); var inp; inp = document.createElement('input'); inp.setAttribute('type','text'); inp.className = 'inputs'; inp.style.textAlign = "right"; inp.cell = cell; cell.appendChild(inp); } if(i == 8) { cell.getData = function(data,noAlert) { var tmp = UserFormatNumberToNumber(this.firstChild.value,'%'); if(tmp == -1) { ERROR = true; if(!noAlert) alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')'); data.discount = 0; this.firstChild.style.color = 'red'; } else { data.discount = tmp; this.firstChild.style.color = 'black'; } } cell.setData = function(data) { if(data.discount) this.firstChild.value = NumberToUserFormatNumber(data.discount,'%'); else this.firstChild.value = NumberToUserFormatNumber(0,'%'); } cell.selectNext = function() { var row = this.parentNode.selectNext(); row.select(); row.cells.item(0).select(); }; var edit = ''; cell.innerHTML = edit; } if(i == 9) { //cell.select = function() { }; cell.getData = function(data) { var cn = this.getElementsByTagName('input'); data.total = UserFormatNumberToNumber(cn[0].value); } cell.setData = function(data) { var cn = this.getElementsByTagName('input'); if(data.total) cn[0].value = NumberToUserFormatNumber(data.total); else cn[0].value = NumberToUserFormatNumber(0); } var edit = document.createElement('input'); edit.setAttribute('type','text'); edit.setAttribute('value',NumberToUserFormatNumber(0)); edit.setAttribute('readOnly','readonly'); edit.className = 'inputs'; edit.style.textAlign = "right"; cell.appendChild(edit); } if(i == 10) { cell.getData = function(data) { var cn = this.getElementsByTagName('input'); data.weight_netto = cn[0].value; } cell.setData = function(data) { var cn = this.getElementsByTagName('input'); if(data.weight_netto) cn[0].value = data.weight_netto; } var textarea = ''; cell.innerHTML = textarea; } if(i == 11) { cell.getData = function(data) { var cn = this.getElementsByTagName('textarea'); data.part_no = cn[0].value; } cell.setData = function(data) { var cn = this.getElementsByTagName('textarea'); if(data.part_no) cn[0].value = data.part_no; } var textarea = ''; cell.innerHTML = textarea; } if(i == 12) { cell.getData = function(data) { var cn = this.getElementsByTagName('textarea'); data.part_date = cn[0].value; } cell.setData = function(data) { var cn = this.getElementsByTagName('textarea'); if(data.part_date) cn[0].value = data.part_date; } var textarea = ''; cell.innerHTML = textarea; } if(i == 13) { cell.getData = function(data) { var cn = this.getElementsByTagName('input'); data.duty = UserFormatNumberToNumber(cn[2].value); } cell.setData = function(data) { var cn = this.getElementsByTagName('input'); if (data.duty) cn[2].value=data.duty+'%'; else cn[2]=UserFormatNumberToNumber(0)+'%'; } var edit = document.createElement('input'); edit.setAttribute('type','text'); edit.setAttribute('value',MOD['LBL_EDITTABLE_NO_ADD_FIELDS']); edit.setAttribute('readOnly','readonly'); edit.style.display='none'; if (OPT['kind']=='other') edit.style.display='inline'; edit.className = 'inputs'; cell.appendChild(edit); var edit = document.createElement('input'); edit.setAttribute('type','text'); edit.setAttribute('value',MOD['LBL_EDITTABLE_DUTY']); edit.setAttribute('readOnly','readonly'); edit.style.display='none'; if (OPT['kind']=='import') edit.style.display='inline'; edit.className = 'inputs'; cell.appendChild(edit); var edit = document.createElement('input'); edit.setAttribute('type','text'); edit.setAttribute('value',''); edit.setAttribute('readOnly','readonly'); edit.style.display='none'; if (OPT['kind']=='import') edit.style.display='inline'; edit.className = 'inputs'; cell.appendChild(edit); } } 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) { if(typeof(pl[x].code) != "undefined") { var pl_row = pl[x]; N.addRow().setData(pl_row); } } } catch(err) { pl = null; }; } if(N.rowCount() == 0) N.addRow(); calculateTotal = function() { //calculatePurchasePrices(); var vats = new Object(); var subtotal = 0; var total = 0; //var cbm_total = 0; for(var i=0; i"; } else { rt.insertRow(1); rt.rows.item(1).id = x; rt.rows.item(1).insertCell(0); rt.rows.item(1).cells.item(0).className = 'positionsLabel'; rt.rows.item(1).cells.item(0).innerHTML = txL; rt.rows.item(1).insertCell(1); rt.rows.item(1).cells.item(1).className = 'positionsField'; rt.rows.item(1).cells.item(1).innerHTML = ""; } } var total2 = total; var discount; // if((discount = CheckDiscount(true)) == -1) discount = 0; //var discount2 = total2*discount/100; //total = total2-discount2; total = total2; //discount2 = NumberToUserFormatNumber(discount2).toString(); total2 = ((OPT['type'] == "correct")?'-':'')+NumberToUserFormatNumber(total2).toString(); total = ((OPT['type'] == "correct")?'-':'')+NumberToUserFormatNumber(total).toString(); document.getElementById('subtotal').value = NumberToUserFormatNumber(subtotal); if(document.getElementById('total_2')) document.getElementById('total_2').value = total2; //rt.rows.item(rt.rows.length-2).cells.item(0).innerHTML = MOD['LBL_DISCOUNT']+' ('+NumberToUserFormatNumber(discount,'%')+')'; //document.getElementById('discount_2').value = discount2; document.getElementById('total').value = total; //document.getElementById('cbm_total').value = cbm_total; } calculateTotal(); cutc; setPREVIEW = function() { alert('tt'); var toolb=1; if(STATUS=="registered")toolb=0; if(SHOW_PDF_IN_DIV==1){ //HideLoadingView(); //SetTab('preview_PREVIEW'); EcmPreviewPDF('index.php?module=EcmStockDocIns&action=previewPDF&to_pdf=1&method=I&record='+document.forms.DetailView.record.value,{zoom:75,toolbar:toolb}); } else{ //SetTab('panel_PREVIEW'); document.getElementById('previewPDF').innerHTML = ''; } } if(!OPT.user.access.send_email) setEMAIL = function() { alert(MOD['LBL_ACCESS_UNAVAIBLE_DELETE_EMAIL']); }; else setEMAIL = function(noCheck) { SetTab('panel_EMAIL'); document.getElementById('emailTAB').innerHTML = ''; } setInterval(function() { doRequest('index.php',"module=EcmStockDocIns&action=subpanels&to_pdf=1&record="+document.forms.DetailView.record.value, function(result) { if(result != '') document.getElementById('subpanels_div').innerHTML = result; } ); }, 10000 ); //quick view var main = document.getElementById('main'); if(main) { var h2 = main.getElementsByTagName('h2')[0]; if(h2) { h2.style.display = 'inline'; var quickInfoH2 = document.getElementById('quickInfoH2'); if(quickInfoH2) { h2.parentNode.appendChild(quickInfoH2); quickInfoH2.style.display = ''; } } } if(OPT['setTab'] && OPT['setTab'] != '') { if(OPT['setTab'] == 'EMAIL') setEMAIL(); } //setPREVIEW(); } );