4102 lines
148 KiB
JavaScript
4102 lines
148 KiB
JavaScript
/* Items */
|
|
addEvent(
|
|
window,
|
|
'load',
|
|
function () {
|
|
var CHANGER = new changer();
|
|
CHANGER.interval = 500;
|
|
|
|
set_focus();
|
|
|
|
//initialize table
|
|
N = new MyTable('itemsTable');
|
|
|
|
N.divParent = document.getElementById('itemsTableDIV');
|
|
|
|
var from_popup_return = false;
|
|
|
|
function returnedData(popup_reply_data) {
|
|
from_popup_return = true;
|
|
|
|
var form_name = popup_reply_data.form_name;
|
|
var name_to_value_array = popup_reply_data.name_to_value_array;
|
|
|
|
for (var the_key in name_to_value_array) {
|
|
if(the_key == 'toJSON') {
|
|
//
|
|
}
|
|
else {
|
|
var displayValue=name_to_value_array[the_key].replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
|
|
|
|
var e = document.getElementById(the_key);
|
|
|
|
if(e) {
|
|
e.value = displayValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
// if(N.selectedRow)
|
|
// N.selectedRow.calculateTotal();
|
|
};
|
|
|
|
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.style.height = OPT['row_item_height'];
|
|
|
|
row.ondblclick = function() {
|
|
|
|
this.newPos = !this.newPos;
|
|
/*
|
|
var img = this.cells.item(1).getElementsByTagName('img');
|
|
|
|
if(!this.newPos)
|
|
img[0].src = "modules/EcmServices/images/insertrow.gif";
|
|
else
|
|
img[0].src = "modules/EcmServices/images/editset.gif";
|
|
*/
|
|
|
|
for(var i=0; i<this.myTable.colCount(); i++)
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
|
|
row.onSelect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height_selected'];
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
}
|
|
|
|
row.onDeselect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height'];
|
|
this.cells.item(i).change(false);
|
|
}
|
|
}
|
|
|
|
row.calculateTotal = function() {
|
|
var data = new Object();
|
|
|
|
this.cells.item(3).getData(data,true);
|
|
this.cells.item(5).getData(data,true);
|
|
this.cells.item(6).getData(data,true);
|
|
|
|
if (data.quantity && data.price) {
|
|
data.price2 = data.price - data.price * data.discount / 100;
|
|
data.total = data.quantity*data.price2;
|
|
}
|
|
else {
|
|
data.total = 0;
|
|
data.price2 = 0;
|
|
}
|
|
|
|
this.cells.item(7).setData(data);
|
|
this.cells.item(10).setData(data);
|
|
|
|
calculateTotalItems();
|
|
}
|
|
}
|
|
|
|
var itd = document.getElementById('itemsTableDIV');
|
|
|
|
itd.onscroll = function() {
|
|
if(!AjaxSearch1Items.AjaxSearchFrozen)
|
|
if(N.selectedCell && N.selectedCell.LeftPosition && N.selectedCell.TopPosition) {
|
|
var top = N.selectedCell.TopPosition+N.selectedCell.offsetHeight;
|
|
|
|
if(((N.selectedCell.offsetTop+N.selectedCell.offsetHeight-this.scrollTop) > (this.offsetHeight+5)) || ((N.selectedCell.offsetTop-this.scrollTop) < (-10)))
|
|
AjaxSearch1Items.div.style.display = 'none';
|
|
else
|
|
AjaxSearch1Items.div.style.display = '';
|
|
|
|
AjaxSearch1Items.div.style.top = top - this.scrollTop;
|
|
}
|
|
}
|
|
|
|
N.onCreateCell = function(cell) {
|
|
var i = cell.index;
|
|
|
|
cell.change = function(select) {
|
|
//
|
|
};
|
|
|
|
cell.style.height = OPT['row_item_height'];
|
|
|
|
cell.onDeselect2 = function() {
|
|
var data = this.parentNode.getData();
|
|
|
|
if(!data.id || data.id == '') {
|
|
var data2 = new Object();
|
|
this.parentNode.setData(data2);
|
|
}
|
|
}
|
|
|
|
// Index.
|
|
if(i == 0) {
|
|
cell.setData = function(data) {
|
|
if(data.index) cell.firstChild.value = data.index;
|
|
};
|
|
|
|
cell.getData = function(data) {
|
|
data.index = cell.firstChild.value;
|
|
}
|
|
|
|
cell.select = function() {
|
|
this.selectNext();
|
|
}
|
|
|
|
var edit = document.createElement('input');
|
|
edit.setAttribute('type','text');
|
|
edit.setAttribute('readOnly','readonly');
|
|
edit.setAttribute('tabIndex',1);
|
|
edit.className = 'inputs';
|
|
cell.appendChild(edit);
|
|
}
|
|
|
|
// Code.
|
|
if(i == 1) {
|
|
cell.change = function(select) {
|
|
var cn = this.getElementsByTagName('input');
|
|
var c;
|
|
|
|
if(select) {
|
|
c = cn[0];
|
|
c.name = 'code_p';
|
|
c.id = 'code_p';
|
|
c.className = 'inputs'; // sqsEnabled';
|
|
c = cn[1];
|
|
c.name = 'id_p';
|
|
c.id = 'id_p';
|
|
c = cn[2];
|
|
c.name = 'category_id_p';
|
|
c.id = 'category_id_p';
|
|
c = cn[3];
|
|
c.name = 'currency_id_p';
|
|
c.id = 'currency_id_p';
|
|
c = cn[4];
|
|
c.name = 'currency_symbol_p';
|
|
c.id = 'currency_symbol_p';
|
|
c = cn[5];
|
|
c.name = 'temp_item_id_p';
|
|
c.id = 'temp_item_id_p';
|
|
c = cn[6];
|
|
c.name = 'temp_date_p';
|
|
c.id = 'temp_date_p';
|
|
c = cn[7];
|
|
c.name = 'type_p';
|
|
c.id = 'type_p';
|
|
}
|
|
else {
|
|
c = cn[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = 'inputs';
|
|
c = cn[1];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[2];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[3];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[4];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[5];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[6];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[7];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
|
|
}
|
|
|
|
cell.onSelect = function() {
|
|
var xy = findPos(this);
|
|
this.TopPosition = xy[1];
|
|
this.LeftPosition = xy[0];
|
|
var top = xy[1]+this.offsetHeight;
|
|
var itd = document.getElementById('itemsTableDIV');
|
|
|
|
AjaxSearch1Items.setInputCode(this.getElementsByTagName('input')[0]);
|
|
|
|
if(!AjaxSearch1Items.AjaxSearchFrozen) {
|
|
AjaxSearch1Items.div.style.left = xy[0];
|
|
AjaxSearch1Items.div.TopPosition = top;
|
|
AjaxSearch1Items.div.style.top = top-itd.scrollTop;
|
|
}
|
|
this.ajax_search = false;
|
|
this.parentNode.noHideASP = false;
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch1Items.div.style.display = 'none';
|
|
|
|
this.ajax_search = false;
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
data.code = cn[0].value;
|
|
data.id = cn[1].value;
|
|
data.category_id = cn[2].value;
|
|
data.currency_id = cn[3].value;
|
|
data.currency_symbol = cn[4].value;
|
|
data.temp_item_id = cn[5].value;
|
|
data.temp_date = cn[6].value;
|
|
data.type = cn[7].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
cn[0].value = ((data.code)?data.code:'');
|
|
cn[1].value = ((data.id)?data.id:'');
|
|
//cn[2].value = ((data.unit_id)?data.unit_id:OPT['default_unit']);
|
|
cn[2].value = ((data.category_id)?data.category_id:OPT['default_category']);
|
|
cn[3].value = ((data.currency_id)?data.currency_id:OPT['default_currency_id']);
|
|
cn[4].value = ((data.currency_symbol)?data.currency_symbol:OPT['default_category']);
|
|
cn[5].value = ((data.temp_item_id)?data.temp_item_id:'');
|
|
cn[6].value = ((data.temp_date)?data.temp_date:'');
|
|
cn[7].value = ((data.type)?data.type:'');
|
|
}
|
|
|
|
cell.onKeyDownEvent = function(ev,input) {
|
|
var keynum;
|
|
|
|
if(window.event)
|
|
keynum = ev.keyCode; else keynum = ev.which;
|
|
|
|
if(keynum != 13 && keynum != 9)
|
|
this.ajax_search = true;
|
|
|
|
if(this.ajax_search == true) {
|
|
AjaxSearch1Items.div.style.display = '';
|
|
setTimeout(
|
|
function() {
|
|
AjaxSearch1Items.inputSearch.value=input.value;
|
|
AjaxSearch1Items.inputSearchOnKeyDown(keynum,"clear");
|
|
},
|
|
50
|
|
);
|
|
}
|
|
|
|
if(input.value == '' && keynum == 40) {
|
|
setSelectionRange(AjaxSearch1Items.inputSearch);
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 13 || keynum == 9) {
|
|
if(input.value == '')
|
|
return false;
|
|
|
|
if(this.ajax_search != true && this.parentNode.myTable.selectedCell && this.parentNode.myTable.selectedCell.index == 1)
|
|
this.selectNext();
|
|
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 27) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
//return input.parentNode.myTable.KeyPressed(ev,input.parentNode,null,true);
|
|
}
|
|
|
|
var edit = '<input type="text" onFocus="this.parentNode.select();" tabindex="1" class="inputs" style="height:16px;" autocomplete="off" onKeyDown="return this.parentNode.onKeyDownEvent(event,this);"><br>';
|
|
cell.innerHTML = edit;
|
|
cell.align = 'right';
|
|
|
|
var id = document.createElement('input');
|
|
id.setAttribute('type','hidden');
|
|
cell.appendChild(id);
|
|
|
|
/*
|
|
var unit_id = document.createElement('input');
|
|
unit_id.setAttribute('type','hidden');
|
|
unit_id.setAttribute('value',OPT['default_unit']);
|
|
cell.appendChild(unit_id);
|
|
|
|
var vat_id = document.createElement('input');
|
|
vat_id.setAttribute('type','hidden');
|
|
vat_id.setAttribute('value',OPT['default_vat']);
|
|
cell.appendChild(vat_id);
|
|
*/
|
|
|
|
var category_id = document.createElement('input');
|
|
category_id.setAttribute('type','hidden');
|
|
category_id.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(category_id);
|
|
|
|
var currency_id = document.createElement('input');
|
|
currency_id.setAttribute('type','hidden');
|
|
currency_id.setAttribute('value',OPT['default_currency']);
|
|
cell.appendChild(currency_id);
|
|
|
|
var currency_symbol = document.createElement('input');
|
|
currency_symbol.setAttribute('type','hidden');
|
|
currency_symbol.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(currency_symbol);
|
|
|
|
var temp_item_id = document.createElement('input');
|
|
temp_item_id.setAttribute('type','hidden');
|
|
temp_item_id.setAttribute('value','');
|
|
cell.appendChild(temp_item_id);
|
|
|
|
var temp_date = document.createElement('input');
|
|
temp_date.setAttribute('type','hidden');
|
|
temp_date.setAttribute('value','');
|
|
cell.appendChild(temp_date);
|
|
|
|
var type = document.createElement('input');
|
|
type.setAttribute('type','hidden');
|
|
type.setAttribute('value','');
|
|
cell.appendChild(type);
|
|
|
|
//cell.appendChild(document.createTextNode("\n"));
|
|
var img = document.createElement('img');
|
|
|
|
img.setAttribute('alt',MOD['LBL_IMG_SEARCH']);
|
|
img.setAttribute('src','modules/EcmServices/images/search.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch1Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = my_popup(
|
|
'EcmProducts',
|
|
{
|
|
'id':'id_p',
|
|
'index_dbf':'code_p',
|
|
|
|
'name':'name_p',
|
|
|
|
'currency_id':'currency_id_p',
|
|
'currency_symbol':'currency_symbol_p',
|
|
|
|
//'tax':'vat_name_p',
|
|
|
|
'unit_name':'unit_id_p',
|
|
'unit_name':'unit_name_p',
|
|
|
|
'vat_id':'vat_id_p',
|
|
'vat_name':'vat_name_p',
|
|
'vat_value':'vat_value_p'
|
|
}
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
}
|
|
|
|
// Search image button.
|
|
cell.appendChild(img);
|
|
|
|
cell.appendChild(document.createTextNode(" "));
|
|
|
|
var img = document.createElement('img');
|
|
|
|
img.setAttribute('alt',MOD['LBL_IMG_NEW']);
|
|
img.setAttribute('src','modules/EcmQuotes/images/add_position.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch1Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = window.open(
|
|
"index.php?module=EcmServices&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName=productFL&createModule=EcmProducts",
|
|
"New" ,
|
|
"resizable=yes,scrollbars=no,status=no,height=700,width=900"
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
};
|
|
|
|
|
|
// Add image button.
|
|
cell.appendChild(img);
|
|
}
|
|
|
|
// Name.
|
|
if(i == 2) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'name_p';
|
|
c.id = 'name_p'; //c.className = 'sqsEnabled';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = '';
|
|
}
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
data.name = cn[0].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
cn[0].value = ((data.name)?data.name:'');
|
|
}
|
|
|
|
var textarea = '<textarea tabindex="1" onFocus="this.parentNode.select();" style="width:100%;height:100%;" class="inputs" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,null,true);"></textarea>';
|
|
cell.innerHTML = textarea;
|
|
}
|
|
|
|
// Quantity.
|
|
if(i == 3) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'quantity_p';
|
|
c.id = 'quantity_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;
|
|
//if(!noAlert)
|
|
//alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')');
|
|
data.quantity = 0;
|
|
this.firstChild.style.color = 'red';
|
|
} else {
|
|
data.quantity = tmp;
|
|
this.firstChild.style.color = 'black';
|
|
}
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.quantity)
|
|
this.firstChild.value = NumberToUserFormatNumber(data.quantity);
|
|
else
|
|
this.firstChild.value = NumberToUserFormatNumber(1);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.quantity = data.quantity;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" autocomplete="off" class="inputs" style="text-align:right;" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(1)+'">';
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Rezerwacja.
|
|
if(i == 4) {
|
|
var old_qty;
|
|
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'rq_p';
|
|
c.id = 'rq_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.rq = 0;
|
|
this.firstChild.style.color = 'red';
|
|
} else {
|
|
data.rq = tmp;
|
|
this.firstChild.style.color = 'black';
|
|
}
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.rq)
|
|
this.firstChild.value = NumberToUserFormatNumber(data.rq);
|
|
else
|
|
this.firstChild.value = NumberToUserFormatNumber(0);
|
|
|
|
//getProductQuantity(this.parentNode.index);
|
|
}
|
|
|
|
/*
|
|
cell.onSelect = function() {
|
|
console.log("onSelect " + this.parentNode.index);
|
|
|
|
//refresh state
|
|
data = cell.parentNode.getData();
|
|
old_qty = data.quantity;
|
|
|
|
if (data.type == 'service')
|
|
return;
|
|
|
|
getProductQuantity(this.parentNode.index, "saveReservation");
|
|
|
|
|
|
//getProductQuantity(
|
|
// cell.parentNode.getElementsByTagName("input")[19],
|
|
// data.id,
|
|
// document.getElementById("stock_id").value,
|
|
// data.stock,
|
|
// cell.parentNode
|
|
// );
|
|
|
|
|
|
setTimeout(
|
|
function () {
|
|
data = cell.parentNode.getData();
|
|
cell.parentNode.setData(data);
|
|
},
|
|
1500
|
|
);
|
|
}
|
|
*/
|
|
|
|
/*
|
|
cell.onDeselect = function() {
|
|
console.log("onDeselect " + this.parentNode.index);
|
|
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.quantity = data.quantity;
|
|
this.setData(data);
|
|
}
|
|
|
|
var dat = cell.parentNode.getData();
|
|
|
|
if (dat.type == 'service')
|
|
return;
|
|
|
|
if (data.rq < 0) {
|
|
data.rq=0;
|
|
this.setData(data);
|
|
|
|
return;
|
|
}
|
|
|
|
if (data.rq > 0) {
|
|
data = cell.parentNode.getData();
|
|
|
|
getProductQuantity(this.parentNode.index, "saveReservation");
|
|
|
|
//getProductQuantity(
|
|
// cell.parentNode.getElementsByTagName("input")[19],
|
|
// data.id,
|
|
// document.getElementById("stock_id").value,data.stock,
|
|
// cell.parentNode
|
|
// );
|
|
|
|
setTimeout(function() {
|
|
data.stock=cell.parentNode.getElementsByTagName("input")[19].value;
|
|
cell.parentNode.setData(data);
|
|
|
|
if ((data.rq-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
|
|
saveReservation(
|
|
document.getElementById("stock_id").value,
|
|
data.id,
|
|
data.rq,
|
|
document.getElementById("temp_id").value,
|
|
data.temp_item_id,
|
|
data.temp_date,
|
|
cell.parentNode
|
|
);
|
|
|
|
//refresh state
|
|
|
|
getProductQuantity(
|
|
cell.parentNode.getElementsByTagName("input")[19],
|
|
data.id,
|
|
document.getElementById("stock_id").value,data.stock
|
|
);
|
|
|
|
setTimeout(
|
|
function() {
|
|
data.stock = cell.parentNode.getElementsByTagName("input")[19].value;
|
|
cell.parentNode.setData(data);
|
|
},
|
|
500
|
|
);
|
|
},
|
|
500
|
|
);
|
|
}
|
|
}
|
|
*/
|
|
|
|
cell.onDeselect = function() {
|
|
//console.log("onDeselect " + this.parentNode.index);
|
|
|
|
var data = N.row(this.parentNode.index).getData();
|
|
N.row(this.parentNode.index).setData(data);
|
|
|
|
if (old_qty == data.rq)
|
|
return;
|
|
|
|
removeReservation(this.parentNode.index);
|
|
getProductQuantity(this.parentNode.index, 'saveReservation');
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" autocomplete="off" class="inputs" style="text-align:center;" value="' + NumberToUserFormatNumber(0) + '">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Price.
|
|
if(i == 5) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'price_p';
|
|
c.id = 'price_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;
|
|
|
|
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);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.price = data.price;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" class="inputs" style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0)+'">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Discount.
|
|
if(i == 6) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'discount_p';
|
|
c.id = 'discount_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;
|
|
|
|
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.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.discount = data.discount;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
//cell.selectNext = function() { var row = this.parentNode.selectNext(); row.select(); row.cells.item(0).select(); };
|
|
var edit = '<input type="text" tabindex="1" class="inputs" style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0,'%')+'">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Price2.
|
|
if(i == 7) {
|
|
//cell.select = function() { };
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
data.price2 = UserFormatNumberToNumber(cn[0].value);
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
if(data.price2)
|
|
cn[0].value = NumberToUserFormatNumber(data.price2);
|
|
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);
|
|
}
|
|
|
|
// Vat.
|
|
if(i == 8) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'vat_name_p';
|
|
c.id = 'vat_name_p';
|
|
c = this.childNodes[1];
|
|
c.name = 'vat_value_p';
|
|
c.id = 'vat_value_p';
|
|
c = this.childNodes[2];
|
|
c.name = 'vat_id_p';
|
|
c.id = 'vat_id_p';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = this.childNodes[1];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = this.childNodes[2];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
}
|
|
|
|
cell.getData = function(data,noAlert) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
data.vat_value = cn[1].value;
|
|
data.vat_id = cn[2].value;
|
|
|
|
//if(VAT[cn[2].value])
|
|
// data.vat_name = VAT[cn[2].value].name;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.vat_value)
|
|
this.getElementsByTagName('input')[1].value = data.vat_value; //0->1, 1->2, 2->0
|
|
|
|
if(data.vat_id)
|
|
this.getElementsByTagName('input')[2].value = data.vat_id;
|
|
|
|
if(data.vat_name)
|
|
this.getElementsByTagName('input')[0].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 div=document.createElement('div');
|
|
div.setAttribute('style','display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;');
|
|
|
|
var key;
|
|
|
|
for(key in VAT){
|
|
if(VAT[key]){
|
|
var option=document.createElement('a');
|
|
option.setAttribute('id',VAT[key].id);
|
|
option.setAttribute('name',VAT[key].name);
|
|
|
|
option.onclick = function(){
|
|
cell.getElementsByTagName('input')[0].value=this.name;
|
|
cell.getElementsByTagName('input')[1].value=VAT[this.id].value;
|
|
cell.getElementsByTagName('input')[2].value=this.id;
|
|
div.style.display='none';
|
|
}
|
|
|
|
option.innerHTML=VAT[key].name+'<br>';
|
|
option.setAttribute('style','cursor:pointer;');
|
|
div.appendChild(option);
|
|
}
|
|
}
|
|
|
|
var img=document.createElement('img');
|
|
|
|
img.setAttribute('src','modules/EcmInvoiceOuts/images/edit_position.gif');
|
|
img.setAttribute('style','cursor:pointer;display:inline;');
|
|
|
|
img.onclick=function(){
|
|
if(div.style.display=='none')div.style.display='block';
|
|
else div.style.display='none';
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" class="inputs" readonly style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0,"%")+'"><input type="hidden"><input type="hidden"><br>';
|
|
|
|
cell.innerHTML = edit;
|
|
cell.appendChild(div);
|
|
cell.appendChild(img);
|
|
}
|
|
|
|
// Unit.
|
|
if(i == 9) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'unit_name_p';
|
|
c.id = 'unit_name_p';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
}
|
|
|
|
//cell.select = function() { };
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
data.unit_name = cn[0].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
if(data.unit_name)
|
|
cn[0].value = data.unit_name;
|
|
else
|
|
cn[0].value ='';
|
|
}
|
|
|
|
var edit = document.createElement('input');
|
|
|
|
edit.setAttribute('type','text');
|
|
edit.setAttribute('value','');
|
|
edit.setAttribute('readOnly','readonly');
|
|
edit.className = 'inputs';
|
|
edit.style.textAlign = "right";
|
|
cell.appendChild(edit);
|
|
}
|
|
|
|
// Total.
|
|
if(i == 10) {
|
|
//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);
|
|
}
|
|
|
|
// Stock.
|
|
if(i == 11) {
|
|
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.setAttribute('readOnly', 'readonly');
|
|
stock.className = 'inputs';
|
|
stock.style.textAlign = "right";
|
|
stock.cell = cell;
|
|
|
|
cell.appendChild(stock);
|
|
}
|
|
|
|
// Options.
|
|
if(i == 12) {
|
|
var img;
|
|
|
|
//insert
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt', MOD['LBL_INSERT_NEW_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/insertrow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.myTable.addRow(this.parentNode.parentNode.index+1);
|
|
};
|
|
|
|
//delete
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_DELETE_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/deleterow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
removeReservation(cell);
|
|
this.parentNode.parentNode.deleteRow();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createElement('br'));
|
|
|
|
//move up
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_UP']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowup.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveUp();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
|
|
//move down
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_DOWN']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowdown.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveDown();
|
|
}
|
|
|
|
cell.appendChild(img);
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
calculateTotalItems = function() {
|
|
var vats = new Object();
|
|
var subtotal = 0;
|
|
var total = 0;
|
|
|
|
for(var i=0; i<N.rowCount(); i++) {
|
|
var data = N.row(i).getData();
|
|
|
|
if(OPT.to_is_vat_free == 0) {
|
|
if(data.vat_id && data.name != '') {
|
|
if(typeof(vats[data.vat_id]) != "object") {
|
|
vats[data.vat_id] = new Object();
|
|
vats[data.vat_id]['vat'] = 0;
|
|
}
|
|
vats[data.vat_id]['vat'] += data.total;
|
|
}
|
|
}
|
|
subtotal += data.total;
|
|
}
|
|
|
|
total = subtotal;
|
|
|
|
var rt = document.getElementById('position_result_table');
|
|
|
|
for(var i = 1; i<rt.rows.length-1; i++) {
|
|
if(!vats[rt.rows.item(i).id]) {
|
|
rt.deleteRow(i);
|
|
--i;
|
|
} else
|
|
vats[rt.rows.item(i).id]['node'] = rt.rows.item(i);
|
|
}
|
|
|
|
for(var x in vats) {
|
|
if(VAT[x]){
|
|
vats[x]['vat'] = vats[x]['vat']*(parseFloat(VAT[x].value)/100);
|
|
total += vats[x]['vat'];
|
|
var txL = MOD['LBL_VAT']+' ('+VAT[x].name+')';
|
|
var txF = NumberToUserFormatNumber(vats[x]['vat']);
|
|
}
|
|
|
|
if(vats[x]['node']) {
|
|
vats[x]['node'].id = x;
|
|
vats[x]['node'].cells.item(0).innerHTML = txL;
|
|
vats[x]['node'].cells.item(1).innerHTML = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
} 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 = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
}
|
|
}
|
|
|
|
var total2 = total;
|
|
|
|
total2 = ((OPT['type'] == "correct")?'-':'')+NumberToUserFormatNumber(total2).toString();
|
|
total = ((OPT['type'] == "correct")?'-':'')+NumberToUserFormatNumber(total).toString();
|
|
|
|
document.getElementById('articles_subtotal').value = NumberToUserFormatNumber(subtotal);
|
|
|
|
if(document.getElementById('articles_total'))
|
|
document.getElementById('articles_total').value = total2;
|
|
}
|
|
|
|
ItemListSave = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i < N.rowCount(); i++) {
|
|
data = data + '&p_' + i.toString() + '=' + JSON.stringifyNoSecurity(N.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
ItemsList = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i<N.rowCount(); i++) {
|
|
data = data + '||||' + JSON.stringifyNoSecurity(N.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
if(typeof sqs_objects != 'undefined'){
|
|
sqs_objects["code_p"] = {
|
|
"method":"get_product_array",
|
|
"modules":["EcmProducts"],
|
|
"field_list":["index_dbf", "id", "name", "currency_id"],
|
|
"populate_list":["code_p", "id_p", "name_p", "currency_id_p"],
|
|
"conditions":[{
|
|
"name":"index_dbf",
|
|
"op":"like_custom",
|
|
"end":"%",
|
|
"value":""
|
|
}],
|
|
"limit":"30",
|
|
"order":"index_dbf",
|
|
"no_match_text":"No Match"
|
|
};
|
|
|
|
sqs_objects["name_p"] = {
|
|
"method":"get_product_array",
|
|
"modules":["EcmProducts"],
|
|
"field_list":["date_entered", "name", "id", "index_dbf", "currency_id"],
|
|
"populate_list":["name_p", "name_p", "id_p", "code_p", "currency_id_p"],
|
|
"conditions":[{
|
|
"name":"name",
|
|
"op":"like_custom",
|
|
"end":"%",
|
|
"value":""
|
|
}],
|
|
"limit":"30",
|
|
"order":"name",
|
|
"no_match_text":"No Match"
|
|
};
|
|
}
|
|
|
|
function generateNumber() {
|
|
var url = 'to_pdf=1&generate=1&module=EcmServices&action=generateNumber&type=normal&template_id='+document.getElementById('template_id').value;//+'&record='+document.forms.EditView.record.value;
|
|
|
|
//if(document.getElementById('template_id').value == '') { alert('There are no DocumentTemplates in data base!'); return;}
|
|
doRequest(
|
|
'index.php',
|
|
url,
|
|
function(result){
|
|
var arr = eval(result)[0];
|
|
document.getElementById('number').value = arr.number;
|
|
document.getElementById('document_no').value = arr.document_no;
|
|
},
|
|
''
|
|
);
|
|
};
|
|
|
|
calculateTotalItems();
|
|
|
|
if(OPT['new_number']) {
|
|
generateNumber();
|
|
document.getElementById('ITEMS_menu').style.display='none';
|
|
document.getElementById('SERVICES_menu').style.display='none';
|
|
//save PW
|
|
document.getElementById('stock_doc_inside_in').value = '1';
|
|
}
|
|
if(document.getElementById('template_id').value != '')
|
|
document.getElementById('template_id').onchange();
|
|
|
|
addEvent(
|
|
'template_id',
|
|
'change',
|
|
generateNumber
|
|
);
|
|
|
|
addEvent(
|
|
document.forms.EditView.status,
|
|
'change',
|
|
canConfirm
|
|
);
|
|
|
|
/*
|
|
if(!OPT.user.access.send_email) {
|
|
setEMAIL = function() {
|
|
alert(MOD['LBL_ACCESS_UNAVAIBLE_DELETE_EMAIL']);
|
|
};
|
|
} else {
|
|
setEMAIL = function(noCheck) {
|
|
if(CheckDiscount() != -1) {
|
|
calculateTotalItems();
|
|
OPT['setEmailTab'] = 0;
|
|
var view = true;
|
|
if(!noCheck) {
|
|
var record = document.forms.EditView.record.value;
|
|
if(record == '') {
|
|
alert('Quote is not saved!');
|
|
view = false;
|
|
}
|
|
else {
|
|
if(confirm('Save quote changes?')) {
|
|
OPT['setEmailTab'] = 1;
|
|
view = false;
|
|
SaveForm();
|
|
}
|
|
}
|
|
}
|
|
if(view) {
|
|
SetTab('EMAIL');
|
|
document.getElementById('emailTAB').innerHTML = "<iframe id=\'emailIFRAME\' style='border:none;width:100%;height:670px;' frameborder='no' src='index.php?module=EcmServices&action=Emails&to_pdf=1&bodyclass=tabForm&type=out&pTypeTo="+document.getElementById('parent_type').value+"&pIdTo="+document.getElementById('parent_id').value+"&pTypeFrom=Users&pIdFrom="+document.getElementById('assigned_user_id').value+""e_id="+document.forms.EditView.record.value+"&record="+document.forms.EditView.email_id.value+"'>Yours browser not accept iframes!</iframe>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
CHANGER.add(
|
|
'to_is_vat_free',
|
|
'checked',
|
|
function(obj){
|
|
obj.value = (obj.checked) ? 1 : 0;
|
|
OPT['to_is_vat_free'] = obj.value;
|
|
calculateTotalItems();
|
|
},
|
|
false
|
|
);
|
|
|
|
/*
|
|
CHANGER.add(
|
|
'parent_id',
|
|
'value',
|
|
function() {
|
|
alert('zmiana parent');
|
|
},
|
|
true
|
|
);
|
|
*/
|
|
|
|
function setToAddrEmail(str) {
|
|
if(str && str != '')
|
|
str = eval(str);
|
|
else
|
|
str = '';
|
|
|
|
if(typeof(str) == "object")
|
|
str = str[0];
|
|
else
|
|
str = '';
|
|
|
|
if(document.getElementById('parent_type').value == 'Accounts') {
|
|
//= document.getElementById('to_addrs_field'); if(tmp) tmp.value = (str=='')?'':(((str.name)?str.name:'')+' <'+((str.email1)?str.email1:'')+'>; ');
|
|
tmp = document.getElementById('parent_address_street');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_street)?str.billing_address_street:'';
|
|
|
|
tmp = document.getElementById('parent_address_city');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_city)?str.billing_address_city:'';
|
|
|
|
tmp = document.getElementById('parent_address_postalcode');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_postalcode)?str.billing_address_postalcode:'';
|
|
|
|
tmp = document.getElementById('parent_address_country');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_country)?str.billing_address_country:'';
|
|
|
|
//tmp = document.getElementById('to_nip'); if(tmp) tmp.value = (str.sic_code)?str.sic_code:'';
|
|
tmp = document.getElementById('to_vatid');
|
|
if(tmp)
|
|
tmp.value = (str.nip)?str.nip:'';
|
|
|
|
tmp = document.getElementById('to_is_vat_free');
|
|
if(tmp)
|
|
tmp.checked = (str.is_vat_free == 1) ? true : false;
|
|
|
|
document.getElementById('parent_name_copy').value = document.getElementById('parent_name').value;
|
|
|
|
tmp = document.getElementById('ecmlanguage');
|
|
|
|
if(tmp && str.ecmlanguage) {
|
|
if(tmp.value != str.ecmlanguage) {
|
|
tmp.value = str.ecmlanguage;
|
|
setTexts();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function ChangeAccessFunction(obj,type) {
|
|
var objs = obj.getElementsByTagName('input');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
if(objs[i].id != 'parent_name' && objs[i].id != 'parent_id' && objs[i].name != 'btn_parent_name' && objs[i].name != 'btn_clr_parent_name' && objs[i].name != 'btn_create_parent_name')
|
|
objs[i].disabled = type;
|
|
|
|
var objs = obj.getElementsByTagName('textarea');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
objs[i].disabled = type;
|
|
|
|
var objs = obj.getElementsByTagName('select');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
if(objs[i].id != 'parent_type')
|
|
objs[i].disabled = type;
|
|
|
|
if(type == 'disabled')
|
|
TabsMainBlock = true;
|
|
else
|
|
TabsMainBlock = false;
|
|
|
|
}
|
|
|
|
//create Product
|
|
productFL = new FormLoader();
|
|
productFL.load('EcmServices','Parents','productFL');
|
|
|
|
productFL.onResponseData = function(data) {
|
|
data.price = data.selling_price;
|
|
data.quantity = '1';
|
|
N.selectedRow.setData(data);
|
|
N.selectedRow.calculateTotal();
|
|
};
|
|
|
|
function ParentIdChange(obj) {
|
|
var list = '';
|
|
|
|
if(document.getElementById('parent_type').value == 'Accounts') {
|
|
list = 'gdModule=Accounts&gdData=nip|name|email1|billing_address_street|billing_address_city|billing_address_postalcode|billing_address_country|sic_code|vatid|is_vat_free|ecmlanguage';
|
|
}
|
|
|
|
if(document.getElementById('parent_type').value == 'Contacts') {
|
|
list = 'gdModule=Contacts&gdData=full_name|email1|primary_address_street|primary_address_city|primary_address_postalcode|primary_address_country';
|
|
}
|
|
|
|
if(obj.value == '') {
|
|
setToAddrEmail('');
|
|
var block = document.getElementById('blockAllFields');
|
|
|
|
if(block) {
|
|
//
|
|
} else {
|
|
var main = document.getElementById('main');
|
|
ChangeAccessFunction(main,'disabled');
|
|
}
|
|
} else {
|
|
doRequest('index.php','module=EcmServices&action=getData&'+list+'&gdId='+obj.value+'&to_pdf=1',setToAddrEmail);
|
|
var main = document.getElementById('main');
|
|
ChangeAccessFunction(main,'');
|
|
}
|
|
}
|
|
|
|
CHANGER.add(
|
|
'parent_id',
|
|
'value',
|
|
ParentIdChange,
|
|
OPT['check_parent_id']
|
|
);
|
|
|
|
CHANGER.add(
|
|
'contact_id',
|
|
'value',
|
|
function(obj) {
|
|
if(obj.value == '') {
|
|
document.forms.EditView.parent_contact_name.value = '';
|
|
document.forms.EditView.parent_contact_title.value = '';
|
|
} else {
|
|
doRequest('index.php','module=EcmServices&action=getData&gdModule=Contacts&gdData=full_name|title&gdId='+obj.value+'&to_pdf=1', function(str) {
|
|
if(str && str != '') str = eval(str); else str = '';
|
|
if(typeof(str) == "object") str = str[0]; else str = '';
|
|
document.forms.EditView.parent_contact_name.value = str.full_name;
|
|
document.forms.EditView.parent_contact_title.value = str.title;
|
|
});
|
|
}
|
|
},
|
|
false
|
|
);
|
|
|
|
if(document.getElementById('parent_id').value == '')
|
|
ParentIdChange(document.getElementById('parent_id'));
|
|
|
|
var setTexts = function(no_confirm_question) {
|
|
var resp = true;
|
|
|
|
if(!no_confirm_question)
|
|
resp = confirm(MOD.LBL_ALERT_ECMLANGUAGE_CHANGE);
|
|
|
|
if(resp) {
|
|
var pt = document.getElementById('parent_type');
|
|
var el = document.getElementById('ecmlanguage');
|
|
document.forms.EditView.header_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['header_text'];
|
|
document.forms.EditView.footer_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['footer_text'];
|
|
document.forms.EditView.ads_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['ads_text'];
|
|
}
|
|
}
|
|
|
|
YAHOO.util.Event.addListener(document.getElementById('ecmlanguage'),'change',function(){
|
|
setTexts();
|
|
});
|
|
|
|
/*
|
|
CHANGER.add(
|
|
'parent_type',
|
|
'value',
|
|
function(obj) {
|
|
setTexts();
|
|
},
|
|
true
|
|
);
|
|
|
|
CHANGER.add(
|
|
'ecmlanguage',
|
|
'value',
|
|
function(obj) {
|
|
setTexts();
|
|
},
|
|
true
|
|
);
|
|
*/
|
|
|
|
//quick view
|
|
var main = document.getElementById('main');
|
|
if(main) {
|
|
var h2 = main.getElementsByTagName('h2')[0];
|
|
if(h2) {
|
|
h2.style.display = 'inline';
|
|
var span = document.createElement('span');
|
|
span.innerHTML = ' <span id="document_no_h"></span> - <span id="parent_name_h"></span> - <span id="parent_contact_name_h"></span> - <span id="parent_address_street_h"></span> <span id="parent_address_postalcode_h"></span> <span id="parent_address_city_h"></span> <span id="parent_address_country_h"></span> - <span id="total_h"></span>'
|
|
h2.parentNode.appendChild(span);
|
|
}
|
|
}
|
|
|
|
CHANGER.add(
|
|
'document_no',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('document_no_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_contact_name',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_contact_name_h').innerHTML = obj.value;
|
|
},false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_street',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_street_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_postalcode',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_postalcode_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_city',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_city_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_country',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_country_h').innerHTML = obj.value;
|
|
},
|
|
false);
|
|
|
|
CHANGER.add(
|
|
'total',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('total_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.startTimer();
|
|
|
|
if(document.forms.EditView.record.value == '')
|
|
setTexts(true);
|
|
|
|
if (OPT['save_temp_reservations'] == true) {
|
|
//update all products reservation & quantity
|
|
for (var i = 0; i < N.rowCount(); i++) {
|
|
getProductQuantity(i, "saveReservation");
|
|
}
|
|
}
|
|
|
|
AjaxSearch1Items = new AjaxSearch1(document.getElementById('ITEMS'), true);
|
|
|
|
SetTabIndexs();
|
|
document.PositionList = N;
|
|
document.VAT1 = VAT;
|
|
|
|
document.getElementById("stock_id").onchange= function() {
|
|
//if (document.getElementById("stock_id").value!="")
|
|
// this.disabled=true;
|
|
|
|
if(document.getElementById("stock_id").value!="" && document.getElementById("parent_id").value!=""){
|
|
TabsMainBlock = false;
|
|
} else {
|
|
TabsMainBlock = true;
|
|
}
|
|
};
|
|
}
|
|
);
|
|
/* /Items */
|
|
|
|
/* Services */
|
|
addEvent(
|
|
window,
|
|
'load',
|
|
function () {
|
|
var CHANGER = new changer();
|
|
CHANGER.interval = 500;
|
|
|
|
set_focus();
|
|
|
|
//initialize table
|
|
N2 = new MyTable('servicesTable');
|
|
|
|
N2.divParent = document.getElementById('servicesTableDIV');
|
|
|
|
var from_popup_return = false;
|
|
|
|
function returnedData(popup_reply_data) {
|
|
from_popup_return = true;
|
|
|
|
var form_name = popup_reply_data.form_name;
|
|
var name_to_value_array = popup_reply_data.name_to_value_array;
|
|
|
|
for (var the_key in name_to_value_array) {
|
|
if(the_key == 'toJSON') {
|
|
//
|
|
} else {
|
|
var displayValue=name_to_value_array[the_key].replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
|
|
|
|
var e = document.getElementById(the_key);
|
|
|
|
if(e) {
|
|
e.value = displayValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
// if(N2.selectedRow)
|
|
// N2.selectedRow.calculateTotal();
|
|
};
|
|
|
|
N2.onRefreshRowIndex = function(row) {
|
|
var data = new Object();
|
|
data['index'] = (row.index+1).toString();
|
|
row.cells.item(0).setData(data);
|
|
}
|
|
|
|
N2.onCreateRow = function(row) {
|
|
row.newPos = false;
|
|
//row.style.height = OPT['row_item_height'];
|
|
|
|
row.ondblclick = function() {
|
|
|
|
this.newPos = !this.newPos;
|
|
/*
|
|
var img = this.cells.item(1).getElementsByTagName('img');
|
|
|
|
if(!this.newPos)
|
|
img[0].src = "modules/EcmServices/images/insertrow.gif";
|
|
else
|
|
img[0].src = "modules/EcmServices/images/editset.gif";
|
|
*/
|
|
|
|
for(var i=0; i<this.myTable.colCount(); i++)
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
|
|
row.onSelect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height_selected'];
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
}
|
|
|
|
row.onDeselect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height'];
|
|
this.cells.item(i).change(false);
|
|
}
|
|
}
|
|
|
|
row.calculateTotal = function() {
|
|
var data = new Object();
|
|
|
|
this.cells.item(3).getData(data,true);
|
|
this.cells.item(4).getData(data,true);
|
|
this.cells.item(5).getData(data,true);
|
|
|
|
if (data.quantity && data.price) {
|
|
data.price2 = data.price - data.price * data.discount / 100;
|
|
data.total = data.quantity*data.price2;
|
|
}
|
|
else {
|
|
data.total = 0;
|
|
data.price2 = 0;
|
|
}
|
|
|
|
this.cells.item(6).setData(data);
|
|
this.cells.item(8).setData(data);
|
|
|
|
calculateTotalServices();
|
|
}
|
|
}
|
|
|
|
var itd = document.getElementById('servicesTableDIV');
|
|
|
|
itd.onscroll = function() {
|
|
if(!AjaxSearch2Items.AjaxSearchFrozen)
|
|
if(N2.selectedCell && N2.selectedCell.LeftPosition && N2.selectedCell.TopPosition) {
|
|
var top = N2.selectedCell.TopPosition+N2.selectedCell.offsetHeight;
|
|
|
|
if(((N2.selectedCell.offsetTop+N2.selectedCell.offsetHeight-this.scrollTop) > (this.offsetHeight+5)) || ((N2.selectedCell.offsetTop-this.scrollTop) < (-10)))
|
|
AjaxSearch2Items.div.style.display = 'none';
|
|
else
|
|
AjaxSearch2Items.div.style.display = '';
|
|
|
|
AjaxSearch2Items.div.style.top = top - this.scrollTop;
|
|
}
|
|
}
|
|
|
|
N2.onCreateCell = function(cell) {
|
|
var i = cell.index;
|
|
|
|
cell.change = function(select) {
|
|
//
|
|
};
|
|
|
|
cell.style.height = OPT['row_item_height'];
|
|
|
|
cell.onDeselect2 = function() {
|
|
var data = this.parentNode.getData();
|
|
|
|
if(!data.id || data.id == '') {
|
|
var data2 = new Object();
|
|
this.parentNode.setData(data2);
|
|
}
|
|
}
|
|
|
|
// Index.
|
|
if(i == 0) {
|
|
cell.setData = function(data) {
|
|
if(data.index) cell.firstChild.value = data.index;
|
|
};
|
|
|
|
cell.getData = function(data) {
|
|
data.index = cell.firstChild.value;
|
|
}
|
|
|
|
cell.select = function() {
|
|
this.selectNext();
|
|
}
|
|
|
|
var edit = document.createElement('input');
|
|
edit.setAttribute('type','text');
|
|
edit.setAttribute('readOnly','readonly');
|
|
edit.setAttribute('tabIndex',1);
|
|
edit.className = 'inputs';
|
|
cell.appendChild(edit);
|
|
}
|
|
|
|
// Code.
|
|
if(i == 1) {
|
|
cell.change = function(select) {
|
|
var cn = this.getElementsByTagName('input');
|
|
var c;
|
|
|
|
if(select) {
|
|
c = cn[0];
|
|
c.name = 'code_p';
|
|
c.id = 'code_p';
|
|
c.className = 'inputs'; // sqsEnabled';
|
|
c = cn[1];
|
|
c.name = 'id_p';
|
|
c.id = 'id_p';
|
|
c = cn[2];
|
|
c.name = 'category_id_p';
|
|
c.id = 'category_id_p';
|
|
c = cn[3];
|
|
c.name = 'currency_id_p';
|
|
c.id = 'currency_id_p';
|
|
c = cn[4];
|
|
c.name = 'currency_symbol_p';
|
|
c.id = 'currency_symbol_p';
|
|
c = cn[5];
|
|
c.name = 'temp_item_id_p';
|
|
c.id = 'temp_item_id_p';
|
|
c = cn[6];
|
|
c.name = 'temp_date_p';
|
|
c.id = 'temp_date_p';
|
|
c = cn[7];
|
|
c.name = 'type_p';
|
|
c.id = 'type_p';
|
|
}
|
|
else {
|
|
c = cn[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = 'inputs';
|
|
c = cn[1];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[2];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[3];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[4];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[5];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[6];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[7];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
|
|
}
|
|
|
|
cell.onSelect = function() {
|
|
var xy = findPos(this);
|
|
this.TopPosition = xy[1];
|
|
this.LeftPosition = xy[0];
|
|
var top = xy[1]+this.offsetHeight;
|
|
var itd = document.getElementById('servicesTableDIV');
|
|
|
|
AjaxSearch2Items.setInputCode(this.getElementsByTagName('input')[0]);
|
|
|
|
if(!AjaxSearch2Items.AjaxSearchFrozen) {
|
|
AjaxSearch2Items.div.style.left = xy[0];
|
|
AjaxSearch2Items.div.TopPosition = top;
|
|
AjaxSearch2Items.div.style.top = top-itd.scrollTop;
|
|
}
|
|
this.ajax_search = false;
|
|
this.parentNode.noHideASP = false;
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch2Items.div.style.display = 'none';
|
|
|
|
this.ajax_search = false;
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
data.code = cn[0].value;
|
|
data.id = cn[1].value;
|
|
data.category_id = cn[2].value;
|
|
data.currency_id = cn[3].value;
|
|
data.currency_symbol = cn[4].value;
|
|
data.temp_item_id = cn[5].value;
|
|
data.temp_date = cn[6].value;
|
|
data.type = cn[7].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
cn[0].value = ((data.code)?data.code:'');
|
|
cn[1].value = ((data.id)?data.id:'');
|
|
//cn[2].value = ((data.unit_id)?data.unit_id:OPT['default_unit']);
|
|
cn[2].value = ((data.category_id)?data.category_id:OPT['default_category']);
|
|
cn[3].value = ((data.currency_id)?data.currency_id:OPT['default_currency_id']);
|
|
cn[4].value = ((data.currency_symbol)?data.currency_symbol:OPT['default_category']);
|
|
cn[5].value = ((data.temp_item_id)?data.temp_item_id:'');
|
|
cn[6].value = ((data.temp_date)?data.temp_date:'');
|
|
cn[7].value = ((data.type)?data.type:'');
|
|
}
|
|
|
|
cell.onKeyDownEvent = function(ev,input) {
|
|
var keynum;
|
|
|
|
if(window.event)
|
|
keynum = ev.keyCode; else keynum = ev.which;
|
|
|
|
if(keynum != 13 && keynum != 9)
|
|
this.ajax_search = true;
|
|
|
|
if(this.ajax_search == true) {
|
|
AjaxSearch2Items.div.style.display = '';
|
|
|
|
setTimeout(
|
|
function() {
|
|
AjaxSearch2Items.inputSearch.value = input.value;
|
|
AjaxSearch2Items.inputSearchOnKeyDown(keynum, "clear");
|
|
},
|
|
50
|
|
);
|
|
}
|
|
|
|
if(input.value == '' && keynum == 40) {
|
|
setSelectionRange(AjaxSearch2Items.inputSearch);
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 13 || keynum == 9) {
|
|
if(input.value == '')
|
|
return false;
|
|
|
|
if(this.ajax_search != true && this.parentNode.myTable.selectedCell && this.parentNode.myTable.selectedCell.index == 1)
|
|
this.selectNext();
|
|
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 27) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
//return input.parentNode.myTable.KeyPressed(ev,input.parentNode,null,true);
|
|
}
|
|
|
|
var edit = '<input type="text" onFocus="this.parentNode.select();" tabindex="1" class="inputs" style="height:16px;" autocomplete="off" onKeyDown="return this.parentNode.onKeyDownEvent(event,this);"><br>';
|
|
cell.innerHTML = edit;
|
|
cell.align = 'right';
|
|
|
|
var id = document.createElement('input');
|
|
id.setAttribute('type','hidden');
|
|
cell.appendChild(id);
|
|
|
|
/*
|
|
var unit_id = document.createElement('input');
|
|
unit_id.setAttribute('type','hidden');
|
|
unit_id.setAttribute('value',OPT['default_unit']);
|
|
cell.appendChild(unit_id);
|
|
|
|
var vat_id = document.createElement('input');
|
|
vat_id.setAttribute('type','hidden');
|
|
vat_id.setAttribute('value',OPT['default_vat']);
|
|
cell.appendChild(vat_id);
|
|
*/
|
|
|
|
var category_id = document.createElement('input');
|
|
category_id.setAttribute('type','hidden');
|
|
category_id.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(category_id);
|
|
|
|
var currency_id = document.createElement('input');
|
|
currency_id.setAttribute('type','hidden');
|
|
currency_id.setAttribute('value',OPT['default_currency']);
|
|
cell.appendChild(currency_id);
|
|
|
|
var currency_symbol = document.createElement('input');
|
|
currency_symbol.setAttribute('type','hidden');
|
|
currency_symbol.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(currency_symbol);
|
|
|
|
var temp_item_id = document.createElement('input');
|
|
temp_item_id.setAttribute('type','hidden');
|
|
temp_item_id.setAttribute('value','');
|
|
cell.appendChild(temp_item_id);
|
|
|
|
var temp_date = document.createElement('input');
|
|
temp_date.setAttribute('type','hidden');
|
|
temp_date.setAttribute('value','');
|
|
cell.appendChild(temp_date);
|
|
|
|
var type = document.createElement('input');
|
|
type.setAttribute('type','hidden');
|
|
type.setAttribute('value','');
|
|
cell.appendChild(type);
|
|
|
|
//cell.appendChild(document.createTextNode("\n"));
|
|
var img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_IMG_SEARCH']);
|
|
img.setAttribute('src','modules/EcmServices/images/search.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch2Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = my_popup(
|
|
'EcmProducts',
|
|
{
|
|
'id':'id_p',
|
|
'index_dbf':'code_p',
|
|
|
|
'name':'name_p',
|
|
|
|
'currency_id':'currency_id_p',
|
|
'currency_symbol':'currency_symbol_p',
|
|
|
|
//'tax':'vat_name_p',
|
|
|
|
'unit_name':'unit_id_p',
|
|
'unit_name':'unit_name_p',
|
|
|
|
'vat_id':'vat_id_p',
|
|
'vat_name':'vat_name_p',
|
|
'vat_value':'vat_value_p'
|
|
}
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
}
|
|
|
|
// Search image button.
|
|
cell.appendChild(img);
|
|
|
|
cell.appendChild(document.createTextNode(" "));
|
|
|
|
var img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_IMG_NEW']);
|
|
img.setAttribute('src','modules/EcmQuotes/images/add_position.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch2Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = window.open(
|
|
"index.php?module=EcmServices&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName=productFL&createModule=EcmProducts",
|
|
"New" ,
|
|
"resizable=yes,scrollbars=no,status=no,height=700,width=900"
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
};
|
|
|
|
// Add image button.
|
|
cell.appendChild(img);
|
|
}
|
|
|
|
// Name.
|
|
if(i == 2) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'name_p';
|
|
c.id = 'name_p'; //c.className = 'sqsEnabled';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = '';
|
|
}
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
data.name = cn[0].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
cn[0].value = ((data.name)?data.name:'');
|
|
}
|
|
|
|
var textarea = '<textarea tabindex="1" onFocus="this.parentNode.select();" style="width:100%;height:100%;" class="inputs" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,null,true);"></textarea>';
|
|
cell.innerHTML = textarea;
|
|
}
|
|
|
|
// Quantity.
|
|
if(i == 3) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'quantity_p';
|
|
c.id = 'quantity_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;
|
|
//if(!noAlert)
|
|
//alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')');
|
|
data.quantity = 0;
|
|
this.firstChild.style.color = 'red';
|
|
} else {
|
|
data.quantity = tmp;
|
|
this.firstChild.style.color = 'black';
|
|
}
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.quantity)
|
|
this.firstChild.value = NumberToUserFormatNumber(data.quantity);
|
|
else
|
|
this.firstChild.value = NumberToUserFormatNumber(1);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.quantity = data.quantity;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" autocomplete="off" class="inputs" style="text-align:right;" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(1)+'">';
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Rezerwacja.
|
|
/*
|
|
if(i == 4) {
|
|
var old_qty;
|
|
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'rq_p';
|
|
c.id = 'rq_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.rq = 0;
|
|
this.firstChild.style.color = 'red';
|
|
} else {
|
|
data.rq = tmp;
|
|
this.firstChild.style.color = 'black';
|
|
}
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.rq)
|
|
this.firstChild.value = NumberToUserFormatNumber(data.rq);
|
|
else
|
|
this.firstChild.value = NumberToUserFormatNumber(0);
|
|
}
|
|
|
|
cell.onSelect = function() {
|
|
//refresh state
|
|
data = cell.parentNode.getData();
|
|
old_qty = data.quantity;
|
|
|
|
if (data.type == 'service')
|
|
return;
|
|
|
|
getProductQuantity(cell.parentNode.getElementsByTagName("input")[19],data.id,document.getElementById("stock_id").value,data.stock, cell.parentNode);
|
|
|
|
setTimeout(
|
|
function () {
|
|
data = cell.parentNode.getData();
|
|
cell.parentNode.setData(data);
|
|
},
|
|
1500
|
|
);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.quantity = data.quantity;
|
|
this.setData(data);
|
|
}
|
|
|
|
var dat = cell.parentNode.getData();
|
|
|
|
if (dat.type == 'service')
|
|
return;
|
|
|
|
if (data.rq<0) {
|
|
data.rq=0;
|
|
this.setData(data);
|
|
|
|
return;
|
|
}
|
|
|
|
if (data.rq>0) {
|
|
data = cell.parentNode.getData();
|
|
getProductQuantity(cell.parentNode.getElementsByTagName("input")[19],data.id,document.getElementById("stock_id").value,data.stock, cell.parentNode);
|
|
setTimeout(function() {
|
|
data.stock=cell.parentNode.getElementsByTagName("input")[19].value;
|
|
cell.parentNode.setData(data);
|
|
|
|
if ((data.rq-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
|
|
|
|
saveReservation(document.getElementById("stock_id").value,data.id,data.rq,document.getElementById("temp_id").value,data.temp_item_id,data.temp_date,cell.parentNode);
|
|
|
|
//refresh state
|
|
|
|
getProductQuantity(cell.parentNode.getElementsByTagName("input")[19],data.id,document.getElementById("stock_id").value,data.stock);
|
|
setTimeout(
|
|
function() {
|
|
data.stock = cell.parentNode.getElementsByTagName("input")[19].value;
|
|
cell.parentNode.setData(data);
|
|
},
|
|
500
|
|
);
|
|
},
|
|
500
|
|
);
|
|
}
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" autocomplete="off" class="inputs" style="text-align:right;" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0)+'">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
*/
|
|
|
|
// Price.
|
|
if(i == 4) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'price_p';
|
|
c.id = 'price_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;
|
|
|
|
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);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.price = data.price;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" class="inputs" style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0)+'">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Discount.
|
|
if(i == 5) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'discount_p';
|
|
c.id = 'discount_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;
|
|
|
|
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.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.discount = data.discount;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
//cell.selectNext = function() { var row = this.parentNode.selectNext(); row.select(); row.cells.item(0).select(); };
|
|
var edit = '<input type="text" tabindex="1" class="inputs" style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0,'%')+'">';
|
|
|
|
cell.innerHTML = edit;
|
|
}
|
|
|
|
// Price2.
|
|
if(i == 6) {
|
|
//cell.select = function() { };
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
data.price2 = UserFormatNumberToNumber(cn[0].value);
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
if(data.price2)
|
|
cn[0].value = NumberToUserFormatNumber(data.price2);
|
|
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);
|
|
}
|
|
|
|
// Vat.
|
|
if(i == 7) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'vat_name_p';
|
|
c.id = 'vat_name_p';
|
|
c = this.childNodes[1];
|
|
c.name = 'vat_value_p';
|
|
c.id = 'vat_value_p';
|
|
c = this.childNodes[2];
|
|
c.name = 'vat_id_p';
|
|
c.id = 'vat_id_p';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = this.childNodes[1];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = this.childNodes[2];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
}
|
|
|
|
cell.getData = function(data,noAlert) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
data.vat_value = cn[1].value;
|
|
data.vat_id = cn[2].value;
|
|
|
|
//if(VAT[cn[2].value])
|
|
// data.vat_name = VAT[cn[2].value].name;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.vat_value)
|
|
this.getElementsByTagName('input')[1].value = data.vat_value; //0->1, 1->2, 2->0
|
|
|
|
if(data.vat_id)
|
|
this.getElementsByTagName('input')[2].value = data.vat_id;
|
|
|
|
if(data.vat_name)
|
|
this.getElementsByTagName('input')[0].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 div=document.createElement('div');
|
|
div.setAttribute('style','display:none;float:right;text-align:right;border: 1px #cccccc solid;padding:3px;');
|
|
|
|
var key;
|
|
|
|
for(key in VAT){
|
|
if(VAT[key]){
|
|
var option=document.createElement('a');
|
|
option.setAttribute('id',VAT[key].id);
|
|
option.setAttribute('name',VAT[key].name);
|
|
|
|
option.onclick = function(){
|
|
cell.getElementsByTagName('input')[0].value=this.name;
|
|
cell.getElementsByTagName('input')[1].value=VAT[this.id].value;
|
|
cell.getElementsByTagName('input')[2].value=this.id;
|
|
div.style.display='none';
|
|
}
|
|
|
|
option.innerHTML=VAT[key].name+'<br>';
|
|
option.setAttribute('style','cursor:pointer;');
|
|
div.appendChild(option);
|
|
}
|
|
}
|
|
|
|
var img=document.createElement('img');
|
|
|
|
img.setAttribute('src','modules/EcmInvoiceOuts/images/edit_position.gif');
|
|
img.setAttribute('style','cursor:pointer;display:inline;');
|
|
|
|
img.onclick=function(){
|
|
if(div.style.display=='none')div.style.display='block';
|
|
else div.style.display='none';
|
|
}
|
|
|
|
var edit = '<input type="text" tabindex="1" class="inputs" readonly style="text-align:right;" autocomplete="off" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(0,"%")+'"><input type="hidden"><input type="hidden"><br>';
|
|
|
|
cell.innerHTML = edit;
|
|
cell.appendChild(div);
|
|
cell.appendChild(img);
|
|
}
|
|
|
|
// Unit.
|
|
/*
|
|
if(i == 9) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'unit_name_p';
|
|
c.id = 'unit_name_p';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
}
|
|
|
|
//cell.select = function() { };
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
data.unit_name = cn[0].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
if(data.unit_name)
|
|
cn[0].value = data.unit_name;
|
|
else
|
|
cn[0].value ='';
|
|
}
|
|
|
|
var edit = document.createElement('input');
|
|
|
|
edit.setAttribute('type','text');
|
|
edit.setAttribute('value','');
|
|
edit.setAttribute('readOnly','readonly');
|
|
edit.className = 'inputs';
|
|
edit.style.textAlign = "right";
|
|
cell.appendChild(edit);
|
|
}
|
|
*/
|
|
|
|
// Total.
|
|
if(i == 8) {
|
|
//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);
|
|
}
|
|
|
|
// Stock.
|
|
/*
|
|
if(i == 11) {
|
|
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.setAttribute('readOnly', 'readonly');
|
|
stock.className = 'inputs';
|
|
stock.style.textAlign = "right";
|
|
stock.cell = cell;
|
|
cell.appendChild(stock);
|
|
}
|
|
*/
|
|
|
|
// Options.
|
|
if(i == 9) {
|
|
var img;
|
|
|
|
//insert
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt', MOD['LBL_INSERT_NEW_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/insertrow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.myTable.addRow(this.parentNode.parentNode.index+1);
|
|
};
|
|
|
|
//delete
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_DELETE_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/deleterow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
removeReservation(cell);
|
|
this.parentNode.parentNode.deleteRow();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createElement('br'));
|
|
|
|
//move up
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_UP']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowup.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveUp();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
|
|
//move down
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_DOWN']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowdown.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveDown();
|
|
}
|
|
|
|
cell.appendChild(img);
|
|
}
|
|
}
|
|
|
|
N2.onSetCellData = function(row,cell,data) {
|
|
if(cell.innerHTML == '')
|
|
cell.innerHTML = ' ';
|
|
}
|
|
|
|
var pl = document.getElementById('services_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
|
|
N2.addRow().setData(pl_row);
|
|
}
|
|
} catch(err) {
|
|
pl = null;
|
|
};
|
|
}
|
|
|
|
if(N2.rowCount() == 0)
|
|
N2.addRow();
|
|
|
|
calculateTotalServices = function() {
|
|
var vats = new Object();
|
|
var subtotal = 0;
|
|
var total = 0;
|
|
|
|
for(var i=0; i < N2.rowCount(); i++) {
|
|
var data = N2.row(i).getData();
|
|
|
|
if(OPT.to_is_vat_free == 0) {
|
|
if(data.vat_id && data.name != '') {
|
|
if(typeof(vats[data.vat_id]) != "object") {
|
|
vats[data.vat_id] = new Object();
|
|
vats[data.vat_id]['vat'] = 0;
|
|
}
|
|
vats[data.vat_id]['vat'] += data.total;
|
|
}
|
|
}
|
|
subtotal += data.total;
|
|
}
|
|
|
|
total = subtotal;
|
|
|
|
var rt = document.getElementById('services_result_table');
|
|
|
|
for(var i = 1; i<rt.rows.length-1; i++) {
|
|
if(!vats[rt.rows.item(i).id]) {
|
|
rt.deleteRow(i);
|
|
--i;
|
|
} else
|
|
vats[rt.rows.item(i).id]['node'] = rt.rows.item(i);
|
|
}
|
|
|
|
for(var x in vats) {
|
|
if(VAT[x]){
|
|
vats[x]['vat'] = vats[x]['vat']*(parseFloat(VAT[x].value)/100);
|
|
total += vats[x]['vat'];
|
|
var txL = MOD['LBL_VAT']+' ('+VAT[x].name+')';
|
|
var txF = NumberToUserFormatNumber(vats[x]['vat']);
|
|
}
|
|
|
|
if(vats[x]['node']) {
|
|
vats[x]['node'].id = x;
|
|
vats[x]['node'].cells.item(0).innerHTML = txL;
|
|
vats[x]['node'].cells.item(1).innerHTML = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
} 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 = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
}
|
|
}
|
|
|
|
var total2 = total;
|
|
|
|
total2 = ((OPT['type'] == "correct")?'-':'') + NumberToUserFormatNumber(total2).toString();
|
|
total = ((OPT['type'] == "correct")?'-':'') + NumberToUserFormatNumber(total).toString();
|
|
|
|
document.getElementById('services_subtotal').value = NumberToUserFormatNumber(subtotal);
|
|
|
|
if(document.getElementById('services_total'))
|
|
document.getElementById('services_total').value = total2;
|
|
}
|
|
|
|
ServiceListSave = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i < N2.rowCount(); i++) {
|
|
data = data + '&s_' + i.toString() + '=' + JSON.stringifyNoSecurity(N2.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
ServiceList = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i < N2.rowCount(); i++) {
|
|
data = data + '||||' + JSON.stringifyNoSecurity(N2.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
if(typeof sqs_objects != 'undefined'){
|
|
sqs_objects["code_p"] = {
|
|
"method":"get_product_array",
|
|
"modules":["EcmProducts"],
|
|
"field_list":["index_dbf", "id", "name", "currency_id"],
|
|
"populate_list":["code_p", "id_p", "name_p", "currency_id_p"],
|
|
"conditions":[{
|
|
"name":"index_dbf",
|
|
"op":"like_custom",
|
|
"end":"%",
|
|
"value":""
|
|
}],
|
|
"limit":"30",
|
|
"order":"index_dbf",
|
|
"no_match_text":"No Match"
|
|
};
|
|
|
|
sqs_objects["name_p"] = {
|
|
"method":"get_product_array",
|
|
"modules":["EcmProducts"],
|
|
"field_list":["date_entered", "name", "id", "index_dbf", "currency_id"],
|
|
"populate_list":["name_p", "name_p", "id_p", "code_p", "currency_id_p"],
|
|
"conditions":[{
|
|
"name":"name",
|
|
"op":"like_custom",
|
|
"end":"%",
|
|
"value":""
|
|
}],
|
|
"limit":"30",
|
|
"order":"name",
|
|
"no_match_text":"No Match"
|
|
};
|
|
}
|
|
|
|
function generateNumber() {
|
|
var url = 'to_pdf=1&generate=1&module=EcmServices&action=generateNumber&type=normal&template_id='+document.getElementById('template_id').value;//+'&record='+document.forms.EditView.record.value;
|
|
|
|
//if(document.getElementById('template_id').value == '') { alert('There are no DocumentTemplates in data base!'); return;}
|
|
doRequest(
|
|
'index.php',
|
|
url,
|
|
function(result){
|
|
var arr = eval(result)[0];
|
|
document.getElementById('number').value = arr.number;
|
|
document.getElementById('document_no').value = arr.document_no;
|
|
},
|
|
''
|
|
);
|
|
};
|
|
|
|
calculateTotalServices();
|
|
|
|
if(OPT['new_number'])
|
|
generateNumber();
|
|
|
|
if(document.getElementById('template_id').value != '')
|
|
document.getElementById('template_id').onchange();
|
|
|
|
addEvent(
|
|
'template_id',
|
|
'change',
|
|
generateNumber
|
|
);
|
|
|
|
addEvent(
|
|
document.forms.EditView.status,
|
|
'change',
|
|
canConfirm
|
|
);
|
|
|
|
/*
|
|
if(!OPT.user.access.send_email) {
|
|
setEMAIL = function() {
|
|
alert(MOD['LBL_ACCESS_UNAVAIBLE_DELETE_EMAIL']);
|
|
};
|
|
} else {
|
|
setEMAIL = function(noCheck) {
|
|
if(CheckDiscount() != -1) {
|
|
calculateTotalServices();
|
|
OPT['setEmailTab'] = 0;
|
|
var view = true;
|
|
if(!noCheck) {
|
|
var record = document.forms.EditView.record.value;
|
|
if(record == '') {
|
|
alert('Quote is not saved!');
|
|
view = false;
|
|
}
|
|
else {
|
|
if(confirm('Save quote changes?')) {
|
|
OPT['setEmailTab'] = 1;
|
|
view = false;
|
|
SaveForm();
|
|
}
|
|
}
|
|
}
|
|
if(view) {
|
|
SetTab('EMAIL');
|
|
document.getElementById('emailTAB').innerHTML = "<iframe id=\'emailIFRAME\' style='border:none;width:100%;height:670px;' frameborder='no' src='index.php?module=EcmServices&action=Emails&to_pdf=1&bodyclass=tabForm&type=out&pTypeTo="+document.getElementById('parent_type').value+"&pIdTo="+document.getElementById('parent_id').value+"&pTypeFrom=Users&pIdFrom="+document.getElementById('assigned_user_id').value+""e_id="+document.forms.EditView.record.value+"&record="+document.forms.EditView.email_id.value+"'>Yours browser not accept iframes!</iframe>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
|
|
CHANGER.add(
|
|
'to_is_vat_free',
|
|
'checked',
|
|
function(obj){
|
|
obj.value = (obj.checked) ? 1 : 0;
|
|
OPT['to_is_vat_free'] = obj.value;
|
|
calculateTotalServices();
|
|
},
|
|
false
|
|
);
|
|
|
|
/*
|
|
CHANGER.add(
|
|
'parent_id',
|
|
'value',
|
|
function() {
|
|
alert('zmiana parent');
|
|
},
|
|
true
|
|
);
|
|
*/
|
|
|
|
function setToAddrEmail(str) {
|
|
if(str && str != '')
|
|
str = eval(str);
|
|
else
|
|
str = '';
|
|
|
|
if(typeof(str) == "object")
|
|
str = str[0];
|
|
else
|
|
str = '';
|
|
|
|
if(document.getElementById('parent_type').value == 'Accounts') {
|
|
//= document.getElementById('to_addrs_field'); if(tmp) tmp.value = (str=='')?'':(((str.name)?str.name:'')+' <'+((str.email1)?str.email1:'')+'>; ');
|
|
tmp = document.getElementById('parent_address_street');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_street)?str.billing_address_street:'';
|
|
|
|
tmp = document.getElementById('parent_address_city');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_city)?str.billing_address_city:'';
|
|
|
|
tmp = document.getElementById('parent_address_postalcode');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_postalcode)?str.billing_address_postalcode:'';
|
|
|
|
tmp = document.getElementById('parent_address_country');
|
|
if(tmp)
|
|
tmp.value = (str.billing_address_country)?str.billing_address_country:'';
|
|
|
|
//tmp = document.getElementById('to_nip'); if(tmp) tmp.value = (str.sic_code)?str.sic_code:'';
|
|
tmp = document.getElementById('to_vatid');
|
|
if(tmp)
|
|
tmp.value = (str.nip)?str.nip:'';
|
|
|
|
tmp = document.getElementById('to_is_vat_free');
|
|
if(tmp)
|
|
tmp.checked = (str.is_vat_free == 1) ? true : false;
|
|
|
|
document.getElementById('parent_name_copy').value = document.getElementById('parent_name').value;
|
|
|
|
tmp = document.getElementById('ecmlanguage');
|
|
|
|
if(tmp && str.ecmlanguage) {
|
|
if(tmp.value != str.ecmlanguage) {
|
|
tmp.value = str.ecmlanguage;
|
|
setTexts();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function ChangeAccessFunction(obj,type) {
|
|
var objs = obj.getElementsByTagName('input');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
if(objs[i].id != 'parent_name' && objs[i].id != 'parent_id' && objs[i].name != 'btn_parent_name' && objs[i].name != 'btn_clr_parent_name' && objs[i].name != 'btn_create_parent_name')
|
|
objs[i].disabled = type;
|
|
|
|
var objs = obj.getElementsByTagName('textarea');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
objs[i].disabled = type;
|
|
|
|
var objs = obj.getElementsByTagName('select');
|
|
|
|
for(var i=0; i<objs.length; i++)
|
|
if(objs[i].id != 'parent_type')
|
|
objs[i].disabled = type;
|
|
|
|
if(type == 'disabled')
|
|
TabsMainBlock = true;
|
|
else
|
|
TabsMainBlock = false;
|
|
|
|
}
|
|
|
|
//create Product
|
|
productFL = new FormLoader();
|
|
productFL.load('EcmServices','Parents','productFL');
|
|
|
|
productFL.onResponseData = function(data) {
|
|
data.price = data.selling_price;
|
|
data.quantity = '1';
|
|
N2.selectedRow.setData(data);
|
|
N2.selectedRow.calculateTotal();
|
|
};
|
|
|
|
function ParentIdChange(obj) {
|
|
var list = '';
|
|
|
|
if(document.getElementById('parent_type').value == 'Accounts') {
|
|
list = 'gdModule=Accounts&gdData=nip|name|email1|billing_address_street|billing_address_city|billing_address_postalcode|billing_address_country|sic_code|vatid|is_vat_free|ecmlanguage';
|
|
}
|
|
|
|
if(document.getElementById('parent_type').value == 'Contacts') {
|
|
list = 'gdModule=Contacts&gdData=full_name|email1|primary_address_street|primary_address_city|primary_address_postalcode|primary_address_country';
|
|
}
|
|
|
|
if(obj.value == '') {
|
|
setToAddrEmail('');
|
|
var block = document.getElementById('blockAllFields');
|
|
|
|
if(block) {
|
|
//
|
|
} else {
|
|
var main = document.getElementById('main');
|
|
ChangeAccessFunction(main,'disabled');
|
|
}
|
|
} else {
|
|
doRequest('index.php','module=EcmServices&action=getData&'+list+'&gdId='+obj.value+'&to_pdf=1',setToAddrEmail);
|
|
var main = document.getElementById('main');
|
|
ChangeAccessFunction(main,'');
|
|
}
|
|
}
|
|
|
|
CHANGER.add(
|
|
'parent_id',
|
|
'value',
|
|
ParentIdChange,
|
|
OPT['check_parent_id']
|
|
);
|
|
|
|
CHANGER.add(
|
|
'contact_id',
|
|
'value',
|
|
function(obj) {
|
|
if(obj.value == '') {
|
|
document.forms.EditView.parent_contact_name.value = '';
|
|
document.forms.EditView.parent_contact_title.value = '';
|
|
} else {
|
|
doRequest('index.php','module=EcmServices&action=getData&gdModule=Contacts&gdData=full_name|title&gdId='+obj.value+'&to_pdf=1', function(str) {
|
|
if(str && str != '') str = eval(str); else str = '';
|
|
if(typeof(str) == "object") str = str[0]; else str = '';
|
|
document.forms.EditView.parent_contact_name.value = str.full_name;
|
|
document.forms.EditView.parent_contact_title.value = str.title;
|
|
});
|
|
}
|
|
},
|
|
false
|
|
);
|
|
|
|
if(document.getElementById('parent_id').value == '')
|
|
ParentIdChange(document.getElementById('parent_id'));
|
|
|
|
var setTexts = function(no_confirm_question) {
|
|
var resp = true;
|
|
|
|
if(!no_confirm_question)
|
|
resp = confirm(MOD.LBL_ALERT_ECMLANGUAGE_CHANGE);
|
|
|
|
if(resp) {
|
|
var pt = document.getElementById('parent_type');
|
|
var el = document.getElementById('ecmlanguage');
|
|
document.forms.EditView.header_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['header_text'];
|
|
document.forms.EditView.footer_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['footer_text'];
|
|
document.forms.EditView.ads_text.value = OPT['ecmlanguage'][el.value]['texts'][pt.value]['ads_text'];
|
|
}
|
|
}
|
|
|
|
YAHOO.util.Event.addListener(document.getElementById('ecmlanguage'),'change',function(){
|
|
setTexts();
|
|
});
|
|
|
|
/*
|
|
CHANGER.add(
|
|
'parent_type',
|
|
'value',
|
|
function(obj) {
|
|
setTexts();
|
|
},
|
|
true
|
|
);
|
|
|
|
CHANGER.add(
|
|
'ecmlanguage',
|
|
'value',
|
|
function(obj) {
|
|
setTexts();
|
|
},
|
|
true
|
|
);
|
|
*/
|
|
|
|
//quick view
|
|
var main = document.getElementById('main');
|
|
if(main) {
|
|
var h2 = main.getElementsByTagName('h2')[0];
|
|
if(h2) {
|
|
h2.style.display = 'inline';
|
|
var span = document.createElement('span');
|
|
span.innerHTML = ' <span id="document_no_h"></span> - <span id="parent_name_h"></span> - <span id="parent_contact_name_h"></span> - <span id="parent_address_street_h"></span> <span id="parent_address_postalcode_h"></span> <span id="parent_address_city_h"></span> <span id="parent_address_country_h"></span> - <span id="total_h"></span>'
|
|
h2.parentNode.appendChild(span);
|
|
}
|
|
}
|
|
|
|
CHANGER.add(
|
|
'document_no',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('document_no_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_contact_name',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_contact_name_h').innerHTML = obj.value;
|
|
},false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_street',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_street_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_postalcode',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_postalcode_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_city',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_city_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.add(
|
|
'parent_address_country',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('parent_address_country_h').innerHTML = obj.value;
|
|
},
|
|
false);
|
|
|
|
CHANGER.add(
|
|
'total',
|
|
'value',
|
|
function(obj){
|
|
document.getElementById('total_h').innerHTML = obj.value;
|
|
},
|
|
false
|
|
);
|
|
|
|
CHANGER.startTimer();
|
|
|
|
if(document.forms.EditView.record.value == '')
|
|
setTexts(true);
|
|
|
|
AjaxSearch2Items = new AjaxSearch2(document.getElementById('SERVICES'), true);
|
|
|
|
SetTabIndexs();
|
|
document.PositionList = N;
|
|
document.VAT1 = VAT;
|
|
|
|
|
|
document.getElementById("stock_id").onchange= function() {
|
|
//if (document.getElementById("stock_id").value!="")
|
|
// this.disabled=true;
|
|
|
|
if(document.getElementById("stock_id").value!="" && document.getElementById("parent_id").value!=""){
|
|
TabsMainBlock = false;
|
|
} else {
|
|
TabsMainBlock = true;
|
|
}
|
|
};
|
|
}
|
|
);
|
|
/* /Services */
|
|
|
|
/* Income */
|
|
addEvent(
|
|
window,
|
|
'load',
|
|
function () {
|
|
var CHANGER = new changer();
|
|
CHANGER.interval = 500;
|
|
|
|
set_focus();
|
|
|
|
//initialize table
|
|
N3 = new MyTable('incomeTable');
|
|
|
|
N3.divParent = document.getElementById('incomeTableDIV');
|
|
|
|
var from_popup_return = false;
|
|
|
|
function returnedData(popup_reply_data) {
|
|
from_popup_return = true;
|
|
|
|
var form_name = popup_reply_data.form_name;
|
|
var name_to_value_array = popup_reply_data.name_to_value_array;
|
|
|
|
for (var the_key in name_to_value_array) {
|
|
if(the_key == 'toJSON') {
|
|
//
|
|
} else {
|
|
var displayValue=name_to_value_array[the_key].replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
|
|
|
|
var e = document.getElementById(the_key);
|
|
|
|
if(e) {
|
|
e.value = displayValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
// if(N3.selectedRow)
|
|
// N3.selectedRow.calculateTotal();
|
|
};
|
|
|
|
N3.onRefreshRowIndex = function(row) {
|
|
var data = new Object();
|
|
data['index'] = (row.index+1).toString();
|
|
row.cells.item(0).setData(data);
|
|
}
|
|
|
|
N3.onCreateRow = function(row) {
|
|
row.newPos = false;
|
|
//row.style.height = OPT['row_item_height'];
|
|
|
|
row.ondblclick = function() {
|
|
|
|
this.newPos = !this.newPos;
|
|
/*
|
|
var img = this.cells.item(1).getElementsByTagName('img');
|
|
|
|
if(!this.newPos)
|
|
img[0].src = "modules/EcmServices/images/insertrow.gif";
|
|
else
|
|
img[0].src = "modules/EcmServices/images/editset.gif";
|
|
*/
|
|
|
|
for(var i=0; i<this.myTable.colCount(); i++)
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
|
|
row.onSelect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height_selected'];
|
|
this.cells.item(i).change(!this.newPos);
|
|
}
|
|
}
|
|
|
|
row.onDeselect = function() {
|
|
for(var i=0; i<this.myTable.colCount(); i++) {
|
|
this.cells.item(i).style.height = OPT['row_item_height'];
|
|
this.cells.item(i).change(false);
|
|
}
|
|
}
|
|
|
|
row.calculateTotal = function() {
|
|
return;
|
|
/*
|
|
var data = new Object();
|
|
|
|
this.cells.item(3).getData(data,true);
|
|
this.cells.item(4).getData(data,true);
|
|
this.cells.item(5).getData(data,true);
|
|
|
|
if (data.quantity && data.price) {
|
|
data.price2 = data.price - data.price * data.discount / 100;
|
|
data.total = data.quantity*data.price2;
|
|
}
|
|
else {
|
|
data.total = 0;
|
|
data.price2 = 0;
|
|
}
|
|
|
|
this.cells.item(6).setData(data);
|
|
this.cells.item(8).setData(data);
|
|
|
|
//calculateTotalIncome();
|
|
*/
|
|
}
|
|
}
|
|
|
|
var itd = document.getElementById('incomeTableDIV');
|
|
|
|
itd.onscroll = function() {
|
|
if(!AjaxSearch3Items.AjaxSearchFrozen)
|
|
if(N3.selectedCell && N3.selectedCell.LeftPosition && N3.selectedCell.TopPosition) {
|
|
var top = N3.selectedCell.TopPosition+N3.selectedCell.offsetHeight;
|
|
|
|
if(((N3.selectedCell.offsetTop+N3.selectedCell.offsetHeight-this.scrollTop) > (this.offsetHeight+5)) || ((N3.selectedCell.offsetTop-this.scrollTop) < (-10)))
|
|
AjaxSearch3Items.div.style.display = 'none';
|
|
else
|
|
AjaxSearch3Items.div.style.display = '';
|
|
|
|
AjaxSearch3Items.div.style.top = top - this.scrollTop;
|
|
}
|
|
}
|
|
|
|
N3.onCreateCell = function(cell) {
|
|
var i = cell.index;
|
|
|
|
cell.change = function(select) {
|
|
//
|
|
};
|
|
|
|
cell.style.height = OPT['row_item_height'];
|
|
|
|
cell.onDeselect2 = function() {
|
|
var data = this.parentNode.getData();
|
|
|
|
if(!data.id || data.id == '') {
|
|
var data2 = new Object();
|
|
this.parentNode.setData(data2);
|
|
}
|
|
}
|
|
|
|
// Index.
|
|
if(i == 0) {
|
|
cell.setData = function(data) {
|
|
if(data.index) cell.firstChild.value = data.index;
|
|
};
|
|
|
|
cell.getData = function(data) {
|
|
data.index = cell.firstChild.value;
|
|
}
|
|
|
|
cell.select = function() {
|
|
this.selectNext();
|
|
}
|
|
|
|
var edit = document.createElement('input');
|
|
edit.setAttribute('type','text');
|
|
edit.setAttribute('readOnly','readonly');
|
|
edit.setAttribute('tabIndex',1);
|
|
edit.className = 'inputs';
|
|
cell.appendChild(edit);
|
|
}
|
|
|
|
// Code.
|
|
if(i == 1) {
|
|
cell.change = function(select) {
|
|
var cn = this.getElementsByTagName('input');
|
|
var c;
|
|
|
|
if(select) {
|
|
c = cn[0];
|
|
c.name = 'code_p';
|
|
c.id = 'code_p';
|
|
c.className = 'inputs'; // sqsEnabled';
|
|
c = cn[1];
|
|
c.name = 'id_p';
|
|
c.id = 'id_p';
|
|
c = cn[2];
|
|
c.name = 'category_id_p';
|
|
c.id = 'category_id_p';
|
|
c = cn[3];
|
|
c.name = 'currency_id_p';
|
|
c.id = 'currency_id_p';
|
|
c = cn[4];
|
|
c.name = 'currency_symbol_p';
|
|
c.id = 'currency_symbol_p';
|
|
c = cn[5];
|
|
c.name = 'temp_item_id_p';
|
|
c.id = 'temp_item_id_p';
|
|
c = cn[6];
|
|
c.name = 'temp_date_p';
|
|
c.id = 'temp_date_p';
|
|
c = cn[7];
|
|
c.name = 'type_p';
|
|
c.id = 'type_p';
|
|
}
|
|
else {
|
|
c = cn[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = 'inputs';
|
|
c = cn[1];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[2];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[3];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[4];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[5];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[6];
|
|
c.name = '';
|
|
c.id = '';
|
|
c = cn[7];
|
|
c.name = '';
|
|
c.id = '';
|
|
}
|
|
|
|
}
|
|
|
|
cell.onSelect = function() {
|
|
var xy = findPos(this);
|
|
this.TopPosition = xy[1];
|
|
this.LeftPosition = xy[0];
|
|
var top = xy[1]+this.offsetHeight;
|
|
var itd = document.getElementById('incomeTableDIV');
|
|
|
|
AjaxSearch3Items.setInputCode(this.getElementsByTagName('input')[0]);
|
|
|
|
if(!AjaxSearch3Items.AjaxSearchFrozen) {
|
|
AjaxSearch3Items.div.style.left = xy[0];
|
|
AjaxSearch3Items.div.TopPosition = top;
|
|
AjaxSearch3Items.div.style.top = top-itd.scrollTop;
|
|
}
|
|
this.ajax_search = false;
|
|
this.parentNode.noHideASP = false;
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch3Items.div.style.display = 'none';
|
|
|
|
this.ajax_search = false;
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
data.code = cn[0].value;
|
|
data.id = cn[1].value;
|
|
data.category_id = cn[2].value;
|
|
data.currency_id = cn[3].value;
|
|
data.currency_symbol = cn[4].value;
|
|
data.temp_item_id = cn[5].value;
|
|
data.temp_date = cn[6].value;
|
|
data.type = cn[7].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('input');
|
|
|
|
cn[0].value = ((data.code)?data.code:'');
|
|
cn[1].value = ((data.id)?data.id:'');
|
|
//cn[2].value = ((data.unit_id)?data.unit_id:OPT['default_unit']);
|
|
cn[2].value = ((data.category_id)?data.category_id:OPT['default_category']);
|
|
cn[3].value = ((data.currency_id)?data.currency_id:OPT['default_currency_id']);
|
|
cn[4].value = ((data.currency_symbol)?data.currency_symbol:OPT['default_category']);
|
|
cn[5].value = ((data.temp_item_id)?data.temp_item_id:'');
|
|
cn[6].value = ((data.temp_date)?data.temp_date:'');
|
|
cn[7].value = ((data.type)?data.type:'');
|
|
}
|
|
|
|
if (OPT['new_number']!=true)
|
|
cell.onKeyDownEvent = function (ev, input) {}
|
|
else
|
|
cell.onKeyDownEvent = function(ev,input) {
|
|
var keynum;
|
|
|
|
if(window.event)
|
|
keynum = ev.keyCode; else keynum = ev.which;
|
|
|
|
if(keynum != 13 && keynum != 9)
|
|
this.ajax_search = true;
|
|
|
|
if(this.ajax_search == true) {
|
|
AjaxSearch3Items.div.style.display = '';
|
|
|
|
setTimeout(
|
|
function() {
|
|
AjaxSearch3Items.inputSearch.value=input.value;
|
|
AjaxSearch3Items.inputSearchOnKeyDown(keynum,"clear");
|
|
},
|
|
50
|
|
);
|
|
}
|
|
|
|
if(input.value == '' && keynum == 40) {
|
|
setSelectionRange(AjaxSearch3Items.inputSearch);
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 13 || keynum == 9) {
|
|
if(input.value == '')
|
|
return false;
|
|
|
|
if(this.ajax_search != true && this.parentNode.myTable.selectedCell && this.parentNode.myTable.selectedCell.index == 1)
|
|
this.selectNext();
|
|
|
|
return false;
|
|
}
|
|
|
|
if(keynum == 27) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
//return input.parentNode.myTable.KeyPressed(ev,input.parentNode,null,true);
|
|
}
|
|
|
|
var ro ='';
|
|
if (OPT['new_number']!=true) ro ='readonly';
|
|
var edit = '<input type="text" onFocus="this.parentNode.select();" tabindex="1" class="inputs" style="height:16px;" autocomplete="off" onKeyDown="return this.parentNode.onKeyDownEvent(event,this);" '+ro+'><br>';
|
|
cell.innerHTML = edit;
|
|
cell.align = 'right';
|
|
|
|
var id = document.createElement('input');
|
|
id.setAttribute('type','hidden');
|
|
cell.appendChild(id);
|
|
|
|
/*
|
|
var unit_id = document.createElement('input');
|
|
unit_id.setAttribute('type','hidden');
|
|
unit_id.setAttribute('value',OPT['default_unit']);
|
|
cell.appendChild(unit_id);
|
|
|
|
var vat_id = document.createElement('input');
|
|
vat_id.setAttribute('type','hidden');
|
|
vat_id.setAttribute('value',OPT['default_vat']);
|
|
cell.appendChild(vat_id);
|
|
*/
|
|
|
|
var category_id = document.createElement('input');
|
|
category_id.setAttribute('type','hidden');
|
|
category_id.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(category_id);
|
|
|
|
var currency_id = document.createElement('input');
|
|
currency_id.setAttribute('type','hidden');
|
|
currency_id.setAttribute('value',OPT['default_currency']);
|
|
cell.appendChild(currency_id);
|
|
|
|
var currency_symbol = document.createElement('input');
|
|
currency_symbol.setAttribute('type','hidden');
|
|
currency_symbol.setAttribute('value',OPT['default_category']);
|
|
cell.appendChild(currency_symbol);
|
|
|
|
var temp_item_id = document.createElement('input');
|
|
temp_item_id.setAttribute('type','hidden');
|
|
temp_item_id.setAttribute('value','');
|
|
cell.appendChild(temp_item_id);
|
|
|
|
var temp_date = document.createElement('input');
|
|
temp_date.setAttribute('type','hidden');
|
|
temp_date.setAttribute('value','');
|
|
cell.appendChild(temp_date);
|
|
|
|
var type = document.createElement('input');
|
|
type.setAttribute('type','hidden');
|
|
type.setAttribute('value','');
|
|
cell.appendChild(type);
|
|
|
|
//cell.appendChild(document.createTextNode("\n"));
|
|
var img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_IMG_SEARCH']);
|
|
img.setAttribute('src','modules/EcmServices/images/search.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch3Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = my_popup(
|
|
'EcmProducts',
|
|
{
|
|
'id':'id_p',
|
|
'index_dbf':'code_p',
|
|
|
|
'name':'name_p',
|
|
|
|
'currency_id':'currency_id_p',
|
|
'currency_symbol':'currency_symbol_p',
|
|
|
|
//'tax':'vat_name_p',
|
|
|
|
'unit_name':'unit_id_p',
|
|
'unit_name':'unit_name_p',
|
|
|
|
'vat_id':'vat_id_p',
|
|
'vat_name':'vat_name_p',
|
|
'vat_value':'vat_value_p'
|
|
}
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
}
|
|
|
|
// Search image button.
|
|
if (OPT['new_number']==true) {
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
}
|
|
var img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_IMG_NEW']);
|
|
img.setAttribute('src','modules/EcmQuotes/images/add_position.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
try {
|
|
this.parentNode.select();
|
|
} catch(e) {}
|
|
|
|
if(!this.parentNode.noHideASP)
|
|
AjaxSearch3Items.div.style.display = 'none';
|
|
|
|
this.parentNode.ajax_search = false;
|
|
|
|
var ecmpopup = window.open(
|
|
"index.php?module=EcmServices&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName=productFL&createModule=EcmProducts",
|
|
"New" ,
|
|
"resizable=yes,scrollbars=no,status=no,height=700,width=900"
|
|
);
|
|
|
|
setTimeout(
|
|
function(){
|
|
ecmpopup.focus();
|
|
},
|
|
200
|
|
);
|
|
};
|
|
|
|
// Add image button.
|
|
if (OPT['new_number']==true)
|
|
cell.appendChild(img);
|
|
}
|
|
|
|
// Name.
|
|
if(i == 2) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'name_p';
|
|
c.id = 'name_p'; //c.className = 'sqsEnabled';
|
|
}
|
|
else {
|
|
c = this.childNodes[0];
|
|
c.name = '';
|
|
c.id = '';
|
|
c.className = '';
|
|
}
|
|
}
|
|
|
|
cell.getData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
data.name = cn[0].value;
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
var cn = this.getElementsByTagName('textarea');
|
|
cn[0].value = ((data.name)?data.name:'');
|
|
}
|
|
|
|
var ro ='';
|
|
if (OPT['new_number']!=true) ro ='readonly';
|
|
var textarea = '<textarea tabindex="1" onFocus="this.parentNode.select();" style="width:100%;height:100%;" class="inputs" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,null,true);" '+ro+'></textarea>';
|
|
cell.innerHTML = textarea;
|
|
}
|
|
|
|
// Quantity.
|
|
if(i == 3) {
|
|
cell.change = function(select) {
|
|
var c;
|
|
|
|
if(select) {
|
|
c = this.childNodes[0];
|
|
c.name = 'quantity_p';
|
|
c.id = 'quantity_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;
|
|
//if(!noAlert)
|
|
//alert(MOD['LBL_FORMAT_NUMBER_ERROR']+' ('+this.firstChild.value+')');
|
|
data.quantity = 0;
|
|
this.firstChild.style.color = 'red';
|
|
} else {
|
|
data.quantity = tmp;
|
|
this.firstChild.style.color = 'black';
|
|
}
|
|
}
|
|
|
|
cell.setData = function(data) {
|
|
if(data.quantity)
|
|
this.firstChild.value = NumberToUserFormatNumber(data.quantity);
|
|
else
|
|
this.firstChild.value = NumberToUserFormatNumber(1);
|
|
}
|
|
|
|
cell.onDeselect = function() {
|
|
ERROR = false;
|
|
var data = new Object();
|
|
this.getData(data);
|
|
|
|
if(!ERROR) {
|
|
data.quantity = data.quantity;
|
|
this.setData(data);
|
|
}
|
|
}
|
|
|
|
var ro ='';
|
|
if (OPT['new_number']!=true) ro ='readonly';
|
|
var edit = '<input type="text" tabindex="1" autocomplete="off" class="inputs" style="text-align:right;" onKeyDown="return this.parentNode.myTable.KeyPressed(event,this.parentNode,\'decimalNumber\');" value="'+NumberToUserFormatNumber(1)+'" '+ro+'>';
|
|
cell.innerHTML = edit;
|
|
}
|
|
// Options.
|
|
if(i == 4) {
|
|
var img;
|
|
|
|
//insert
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt', MOD['LBL_INSERT_NEW_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/insertrow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.myTable.addRow(this.parentNode.parentNode.index+1);
|
|
};
|
|
|
|
//delete
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_DELETE_ROW']);
|
|
img.setAttribute('src','modules/EcmServices/images/deleterow.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
removeReservation(cell);
|
|
this.parentNode.parentNode.deleteRow();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createElement('br'));
|
|
|
|
//move up
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_UP']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowup.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveUp();
|
|
};
|
|
|
|
cell.appendChild(img);
|
|
cell.appendChild(document.createTextNode(" "));
|
|
|
|
//move down
|
|
img = document.createElement('img');
|
|
img.setAttribute('alt',MOD['LBL_MOVE_ROW_DOWN']);
|
|
img.setAttribute('src','modules/EcmServices/images/moverowdown.gif');
|
|
img.style.cursor = 'pointer';
|
|
|
|
img.onclick = function() {
|
|
this.parentNode.parentNode.moveDown();
|
|
}
|
|
|
|
cell.appendChild(img);
|
|
}
|
|
}
|
|
|
|
N3.onSetCellData = function(row,cell,data) {
|
|
if(cell.innerHTML == '')
|
|
cell.innerHTML = ' ';
|
|
}
|
|
|
|
var pl = document.getElementById('income_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
|
|
N3.addRow().setData(pl_row);
|
|
}
|
|
} catch(err) {
|
|
pl = null;
|
|
};
|
|
}
|
|
|
|
if(N3.rowCount() == 0)
|
|
N3.addRow();
|
|
|
|
calculateTotalIncome = function() {
|
|
return;
|
|
/*
|
|
var vats = new Object();
|
|
var subtotal = 0;
|
|
var total = 0;
|
|
|
|
for(var i=0; i < N3.rowCount(); i++) {
|
|
var data = N3.row(i).getData();
|
|
|
|
if(OPT.to_is_vat_free == 0) {
|
|
if(data.vat_id && data.name != '') {
|
|
if(typeof(vats[data.vat_id]) != "object") {
|
|
vats[data.vat_id] = new Object();
|
|
vats[data.vat_id]['vat'] = 0;
|
|
}
|
|
vats[data.vat_id]['vat'] += data.total;
|
|
}
|
|
}
|
|
subtotal += data.total;
|
|
}
|
|
|
|
total = subtotal;
|
|
|
|
var rt = document.getElementById('position_result_table');
|
|
|
|
for(var i = 1; i<rt.rows.length-1; i++) {
|
|
if(!vats[rt.rows.item(i).id]) {
|
|
rt.deleteRow(i);
|
|
--i;
|
|
} else
|
|
vats[rt.rows.item(i).id]['node'] = rt.rows.item(i);
|
|
}
|
|
|
|
for(var x in vats) {
|
|
if(VAT[x]){
|
|
vats[x]['vat'] = vats[x]['vat']*(parseFloat(VAT[x].value)/100);
|
|
total += vats[x]['vat'];
|
|
var txL = MOD['LBL_VAT']+' ('+VAT[x].name+')';
|
|
var txF = NumberToUserFormatNumber(vats[x]['vat']);
|
|
}
|
|
|
|
if(vats[x]['node']) {
|
|
vats[x]['node'].id = x;
|
|
vats[x]['node'].cells.item(0).innerHTML = txL;
|
|
vats[x]['node'].cells.item(1).innerHTML = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
} 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 = "<input type='text' readonly='readonly' style='border:0px;font-weight:900;width:100%;text-align:right;' value='"+txF+"'>";
|
|
}
|
|
}
|
|
|
|
var total2 = total;
|
|
|
|
total2 = ((OPT['type'] == "correct")?'-':'') + NumberToUserFormatNumber(total2).toString();
|
|
total = ((OPT['type'] == "correct")?'-':'') + NumberToUserFormatNumber(total).toString();
|
|
|
|
document.getElementById('income_subtotal').value = NumberToUserFormatNumber(subtotal);
|
|
|
|
if(document.getElementById('income_total'))
|
|
document.getElementById('income_total').value = total2;
|
|
*/
|
|
}
|
|
|
|
IncomeListSave = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i < N3.rowCount(); i++) {
|
|
data = data + '&i_' + i.toString() + '=' + JSON.stringifyNoSecurity(N3.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
ItemsList = function(json) {
|
|
var data = '';
|
|
|
|
for(var i=0; i < N3.rowCount(); i++) {
|
|
data = data + '||||' + JSON.stringifyNoSecurity(N3.row(i).getData());
|
|
}
|
|
|
|
return data;
|
|
}
|
|
});
|
|
/* /Income */
|
|
|
|
/* PDF */
|
|
addEvent(
|
|
window,
|
|
'load',
|
|
function () {
|
|
|
|
AjaxSearch3Items = new AjaxSearch3(document.getElementById('INCOME'), true);
|
|
|
|
setPREVIEW_INCOME = function() {
|
|
if(CheckDiscount() != -1) {
|
|
/*
|
|
calculateTotalIncome();
|
|
calculateTotalItems();
|
|
calculateTotalServices();
|
|
*/
|
|
|
|
sendFormPostToPdf('income');
|
|
}
|
|
}
|
|
|
|
setPREVIEW_VAL = function() {
|
|
if(CheckDiscount() != -1) {
|
|
//calculateTotalIncome();
|
|
calculateTotalItems();
|
|
calculateTotalServices();
|
|
|
|
sendFormPostToPdf('val');
|
|
}
|
|
}
|
|
|
|
setPREVIEW_QTY = function() {
|
|
if(CheckDiscount() != -1) {
|
|
//calculateTotalIncome();
|
|
calculateTotalItems();
|
|
calculateTotalServices();
|
|
|
|
sendFormPostToPdf('qty');
|
|
}
|
|
}
|
|
|
|
setPREVIEW_WARRANTY = function() {
|
|
if(CheckDiscount() != -1) {
|
|
//calculateTotalIncome();
|
|
calculateTotalItems();
|
|
calculateTotalServices();
|
|
|
|
sendFormPostToPdf('warranty');
|
|
}
|
|
}
|
|
}
|
|
);
|
|
/* /PDF */ |