klnodekb/public/js/events.js

390 lines
14 KiB
JavaScript

var currCikk='';
// Ellenőrzi, szerepel e már az adott dokumentumszám (be lett már vételezve)
$( "#certSerial" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
$("#certSerial").css('background-color', 'green');
console.log('Már létező bizonylat');
});
// alert('CLK');
// Megnevezésben keres
$( "#findByTitle" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
//console.log('Jájj genyó!');
var ctrl=document.getElementById("findByTitle");
var data= {findBy: 'Name', content:ctrl.value};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/json",
dataType:'json',
url: '/warehouse/find',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
}).done (function (data) {
var dataList=document.getElementById("listCikk");
if (data.status === 200) {
while (dataList.childElementCount) {
dataList.removeChild(dataList.lastChild);
}
// Parse the JSON
var jsonOptions = data.data;
// alert(data.data);
// Loop over the JSON array.
jsonOptions.forEach(function(da) {
// Create a new <option> element.
var option = document.createElement('option');
// Set the value using the item in the JSON array.
option.value = da.itemNumber+' '+da.title;//item;
// Add the <option> element to the <datalist>.
dataList.appendChild(option);
});
}
});
});
// Beszállító keresése
// Megnevezésben keres
$( "#findClients" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
//console.log('Jájj genyó2!');
var ctrl=document.getElementById("findClients");
var data= {findBy: 'name', content:ctrl.value};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/json",
dataType:'json',
url: '/receipts/find',
success: function(data) {
console.log('success');
//console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
}).done (function (data) {
//var ls=document.getElementById("arc");
var dataList=document.getElementById("listClients");
if (data.status === 200) {
while (dataList.childElementCount) {
dataList.removeChild(dataList.lastChild);
}
// Parse the JSON
var jsonOptions = data.data;
// alert(data.data);
// Loop over the JSON array.
jsonOptions.forEach(function(da) {
// Create a new <option> element.
var option = document.createElement('option');
// Set the value using the item in the JSON array.
option.id=da._id;//item;
option.text=da.name;
// Add the <option> element to the <datalist>.
dataList.appendChild(option);
//ls.appendChild(option);
});
}
});
});
// Get back data from server
/*$( document ).ready(function() {
$.get("/warehouse/find", function(data) {
//alert(string)
//document.getElementById("findByBarCode").value=data.itemTitle;
})
});*/
$(document).on('change', '#manname', function(e) {
var client=JSON.parse(this.options[e.target.selectedIndex].value);
var clientId=client._id;//this.options[e.target.selectedIndex].value;
console.log(this.options[e.target.selectedIndex].value);
var target = document.getElementById( "manufacturerForm" );
target.action='uploadnew/'+clientId;
var manSname = document.getElementById( "manShortName" );
manSname.value=client.shortName;
var manDisc=document.getElementById("manufacturerDiscount");
manDisc.value=client.manufacturerDiscount;
console.log(target);
});
$(document).ready(function(){
$('.delete-component').on('click', function(e){
$target = $(e.currentTarget);
var $aid=$target.attr('data-aid');
var $wid=$target.attr('data-wid');
var $cid=$target.attr('data-cid');
$.ajax({
type: "DELETE",
url: "/components/delete/"+$wid+"/"+$aid+"/"+$cid,
success: function(response){
//console.log("Törölve!");
location.reload();
}
});
});
})
// Új raktár mentés gomb engedélyezése, ha a név hoszabb mint 3 karakter
$( "#warehouseName" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
var myLength = $("#warehouseName").val().length;
if (myLength>3)
{
$( "#btn_save" ).prop( "disabled", false );
}
else
{
$( "#btn_save" ).prop( "disabled", true );
}
});
//Bevételezés tétel keresése Cikkszám
$( "#findRecItemCikk" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
console.log("Enter");
}
console.log('Jájj genyó9!');
var wHouse=document.getElementById("findRecItemCikk");
var data= {findBy: 'varehouse', content:wHouse.value};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/json",
dataType:'json',
url: '/receipts/findItemCikk',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
}).done (function (data) {
var dataList=document.getElementById("listRecItemCikk");
if (data.status === 200) {
while (dataList.childElementCount) {
tlist.pop();
dataList.removeChild(dataList.lastChild);
}
// Parse the JSON
var jsonOptions = data.data;
// alert(data.data);
// Loop over the JSON array.
jsonOptions.forEach(function(da) {
// Create a new <option> element.
var option = document.createElement('option');
// Set the value using the item in the JSON array.
option.value = da.itemNumber;//item;
option.text=da.title;
tlist.push(da);
// Add the <option> element to the <datalist>.
dataList.appendChild(option);
});
}
});
});
var itemList=[];
var receiptData={};
// Bevételezés mentése
$( "#btn_save_rec" ).on('click',function() {
//alert( "Handler for .click() called." );
// Bevételezés fejléc
receiptData.warehouse=document.getElementById("warehousename").value;
receiptData.certSerial=document.getElementById("certSerial").value;
receiptData.client=document.getElementById("findClients").value;
receiptData.priceNet=document.getElementById("recNListPrice").value;
receiptData.priceBrut=document.getElementById("recBListPrice").value;
receiptData.Items=itemList;
console.log($('select[name=warehousename]').value);
//var data= {findBy: 'varehouse', content : receiptData.warehouse};
// Sending and receiving data in JSON format using POST method
//
var xhr = new XMLHttpRequest();
var url = "/receipts/receiptNewReceipt";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
console.log(json.data.eredmeny);
}
};
var data = JSON.stringify(receiptData);
xhr.send(data);
});
// Input box csak számok
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\./;
if (theEvent.code==='Enter')
{
// Kiválasztott tétel küldése a node-nak tárolásra az adatbázisban
var cikk=document.getElementById("findRecItemCikk");
var qty=document.getElementById("recQty").value;
var a=tlist.find(x => x.itemNumber === cikk.value);
a.stock=qty;
itemList.push(a);
var nAll=0;
itemList.forEach(item => {
nAll+=(item.netListPrice*item.stock);
});
if (itemList.length>0)
{
$( "#btn_save_rec" ).prop('disabled',true);
document.getElementById("btn_save_rec").disabled=false;
}
else
{
$( "#btn_save_rec" ).prop('disabled',false);
document.getElementById("btn_save_rec").disabled=true;
}
document.getElementById("ANListPrice").value=nAll.toLocaleString('hu-HU');
document.getElementById("ABListPrice").value=(nAll*1.27).toLocaleString('hu-HU');
var cikk=document.getElementById("findRecItemCikk").value;
/* var iName=document.getElementById("findRecItemName").value;
var nPrice=document.getElementById("recNListPrice").value;
var bPrice=document.getElementById("recBListPrice").value;*/
// var rows=$('#itemTable').rows.length+1;
//var trd=
$('#itemTable tbody').append('<tr><td>'+itemList.length+'</td><td>'+a.itemNumber+'</td><td>'+a.title+'</td><td align="right">'+a.netListPrice.toLocaleString('hu-HU')+'</td><td align="right">'+qty.toLocaleString('hu-HU')+'</td><td align="right">'+(a.stock*a.netListPrice).toLocaleString('hu-HU')+'</td></tr>');
document.getElementById("findRecItemCikk").focus();
// });
}
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
var tlist=[];
// Kiválasztott nevű tétel cikkszámának másolása a cikkszám mezőbe
$( "#findRecItemName" ).change(function(e) {
//alert( "Handler for .change() called." );
var cikk=document.getElementById("findRecItemCikk");
var iName=document.getElementById("findRecItemName");
var a=tlist.find(x => x.title === iName.value);
cikk.value=a.itemNumber;//arc.getAttribute("irc");
document.getElementById("recNListPrice").value=a.netListPrice.toLocaleString('hu-HU');
document.getElementById("recBListPrice").value=(a.netListPrice*1.27).toLocaleString('hu-HU');
document.getElementById("recQty").focus();
});
// Kiválasztott cikkszámú tétel nevének másolása a megnevezés mezőbe
$( "#findRecItemCikk" ).change(function(e) {
//alert( "Handler for .change() called." );
var cikk=document.getElementById("findRecItemCikk");
var iName=document.getElementById("findRecItemName");
var a=tlist.find(x => x.itemNumber === cikk.value);
if (a)
{
iName.value=a.title;//arc.getAttribute("irc");
document.getElementById("recNListPrice").value=a.netListPrice.toLocaleString('hu-HU');
document.getElementById("recBListPrice").value=(a.netListPrice*1.27).toLocaleString('hu-HU');
document.getElementById("recQty").focus();
}
});
//Bevételezés tétel keresése Név
$( "#findRecItemName" ).on('input',function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
console.log('Jájj genyó9!');
var wHouse=document.getElementById("findRecItemName");
var data= {findBy: 'varehouse', content:wHouse.value};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
/* data: {
blob: {wob:"1",job:"2", ar:[1,2,{a:'b'}]}
},*/
contentType: "application/json",
dataType:'json',
url: '/receipts/findItemName',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
},
error: function(error) {
console.log("some error in fetching the notifications");
}
}).done (function (data) {
var dataList=document.getElementById("listRecItemName");
if (data.status === 200) {
while (dataList.childElementCount) {
tlist.pop();
dataList.removeChild(dataList.lastChild);
}
// Parse the JSON
var jsonOptions = data.data;
// alert(data.data);
// Loop over the JSON array.
jsonOptions.forEach(function(da) {
// Create a new <option> element.
var option = document.createElement('option');
// Set the value using the item in the JSON array.
option.text = da.itemNumber;//item;
option.value=da.title;
tlist.push(da);
// Add the <option> element to the <datalist>.
dataList.appendChild(option);
});
}
});
});