Files
crm.e5.pl/modules/EcmProducts/helper.js

235 lines
6.6 KiB
JavaScript
Raw Normal View History

2024-04-27 09:23:34 +02:00
function insert_selected(U){
//alert(parent.opener.document.PositionList);
var arr=new Array();
var ajs=new Array();
var lv=document.getElementById('list_view');
var is=lv.getElementsByTagName('input');
var l=0;
var id;
for(var i=0;i<is.length;i++) {
if(is[i].type=='checkbox' && is[i].name=='mass[]' && is[i].checked==true) {
arr[l]=is[i].value;
id=associated_javascript_data[is[i].value];
ajs[l]=associated_javascript_data[is[i].value];
ajs[l].code=id['CODE'];
ajs[l].name=id['NAME'];
ajs[l].price=id['SELLING_PRICE'];
ajs[l].unit_id=id['UNIT_ID'];
ajs[l].vat_value=23;
ajs[l].ecmvat_value=23;
ajs[l].vat_name='23%';
ajs[l].ecmvat_name='23%';
ajs[l].vat_id='28079566-b825-e38f-9993-4ccc7b781de5';
ajs[l].ecmvat_id='28079566-b825-e38f-9993-4ccc7b781de5';
ajs[l].total=id['SELLING_PRICE'];
ajs[l].id=is[i].value;
l++;
}
}
var pl = ajs;
if(pl && pl != '') {
pl = eval(pl);
for(x in pl) {
var pl_row = pl[x];
// if(pl_row.vat_id)
U.addRow().setData(pl_row);
}
}
if(U.rowCount() == 0) U.addRow();
window.close();
}
function showdescription(id,title,desc,minus,object)
{
if(!minus)minus=0;
var sum=17-minus;
document.getElementById("desc").style.display="inline";
document.getElementById("desc-title").innerHTML=title;
document.getElementById("desc-desc").innerHTML=desc;
posy=findPosY(object)+sum;
posx=findPosX(object);
moveDiv(document.getElementById("desc"),posy,posx);
}
function hidedescription()
{
document.getElementById("desc").style.display="none";
}
function mintajaxget(url,tag)
{
var req=mint.Request();
req.Set('timeout',10000000);
req.Set('retryNum',0);
req.OnLoading=function(){$(tag).innerHTML='<img src="themes/default/images/loading.gif" border="0">';}
req.OnSuccess = function(){if($(tag).type=='text'){if(this.responseText!="")$(tag).value=this.responseText;}else{if(this.responseText!="")$(tag).innerHTML=this.responseText;}}
req.Send(url,tag);
}
function mintajaxpost(url,tag,form)
{
var req=mint.Request();
req.OnSuccess=function(){$(tag).innerHTML=this.responseText;}
req.OnLoading=function(){$(tag).innerHTML='<img src="themes/default/images/loading.gif" border="0">';}
req.SendForm(form);
}
function moveDiv(obj, mvTop, mvLeft) {
obj.style.position = "absolute";
obj.style.top = mvTop;
obj.style.left = mvLeft;
}
function getPos(inputElement) {
var coords = new Object();
coords.x = 0;
coords.y = 0;
try {
targetElement = inputElement;
if(targetElement.x && targetElement.y) {
coords.x = targetElement.x;
coords.y = targetElement.y;
} else {
if(targetElement.offsetParent) {
coords.x += targetElement.offsetLeft;
coords.y += targetElement.offsetTop;
while(targetElement = targetElement.offsetParent) {
coords.x += targetElement.offsetLeft;
coords.y += targetElement.offsetTop;
}
} else {
//alert("Could not find any reference for coordinate positioning.");
}
}
return coords;
} catch(error) {
//alert(error.msg);
return coords;
}
}
function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
//return getPos(obj).x;
}
function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
//return getPos(obj).y;
}
function showdiv(id,div,minusy,minusx)
{
document.getElementById(div).style.display="inline";
posy=findPosY(document.getElementById(id))-minusy;
posx=findPosX(document.getElementById(id))-minusx;
moveDiv(document.getElementById(div),posy,posx);
}
function hidediv(div)
{
document.getElementById(div).style.display="none";
}
function showprice(id,price,purchase_price,margin,remarks_pl,remarks_en,remarks_de,order_by,sorder,recipient_code)
{
document.getElementById('price').value=price;
document.getElementById('purchase_price').value=purchase_price;
document.getElementById('margin').value=margin;
document.getElementById('recipient_code').value=recipient_code;
document.getElementById('remarks_pl').value=remarks_pl;
document.getElementById('remarks_en').value=remarks_en;
document.getElementById('remarks_de').value=remarks_de;
document.getElementById('product_id').value=id;
document.getElementById('order_by').value=order_by;
document.getElementById('sorder').value=sorder;
document.getElementById('price-block').style.display="block";
}
function getPrice(id,type)
{
var purchase_price=document.getElementById('purchase_price_'+id).value;
var margin_rate=document.getElementById('margin_rate_'+id).value;
var list_price;
list_price=parseFloat(purchase_price)/(1-parseFloat(margin_rate)/100);
if(!isNaN(list_price))document.getElementById('list_price_'+id).value=roundNumber(list_price,2);
}
function getPricePricebook()
{
var purchase_price=document.getElementById('purchase_price').value;
var margin_rate=document.getElementById('margin').value;
var list_price;
margin_rate=margin_rate.replace(".","");
margin_rate=margin_rate.replace(",",".");
purchase_price=purchase_price.replace(".","");
purchase_price=purchase_price.replace(",",".");
list_price=parseFloat(purchase_price)/(1-parseFloat(margin_rate)/100);
if(!isNaN(list_price))document.getElementById('price').value=CurrencyFormatted(list_price);
}
function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += ',00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
s=s.replace(".",",");
return s;
}
function roundN(rnum,rlength)
{
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
return newnumber;
}
function roundNumber(num, dec)
{
if(!isNaN(num))return CurrencyFormatted(roundN(parseFloat(num),dec));
else return "";
}
function ShowHideBlock(id)
{
if(document.getElementById(id).style.display=="block")
{
document.getElementById(id).style.display="none"
}
else
{
document.getElementById(id).style.display="block"
}
}
function generateEAN() {
alert('Coming soon! :)');
}