2024-04-27 09:23:34 +02:00
|
|
|
//START:
|
|
|
|
|
$(document).ready(
|
|
|
|
|
|
|
|
|
|
function() {
|
|
|
|
|
// confirm exit
|
|
|
|
|
window.onbeforeunload = confirmExit;
|
|
|
|
|
// prevent submit by enter press
|
|
|
|
|
lockEnter();
|
|
|
|
|
// parent info
|
|
|
|
|
$('#parent_id').on('inputchange', function() {
|
|
|
|
|
$(".loading_panel").css("display", "block");
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// categories
|
|
|
|
|
getCategoriesList();
|
|
|
|
|
// its vat free change
|
|
|
|
|
$("#no_tax").change(function() {
|
|
|
|
|
// calculate totals
|
|
|
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 -
|
|
|
|
|
// thead row
|
|
|
|
|
for (var index = 0; index != count; index++)
|
|
|
|
|
calculateRow(index);
|
|
|
|
|
});
|
|
|
|
|
$("#type").change(function() {
|
|
|
|
|
if ($("#type :selected").val() == 'normal') {
|
|
|
|
|
if($('#new_number').val()==1){
|
|
|
|
|
|
|
|
|
|
generateNumber();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
generateNumberCorrect();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#currency_id").change(function() {
|
|
|
|
|
getNBPCurrencyExchange($("#currency_id :selected").val());
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
var previousVal;
|
|
|
|
|
var pollInterval = setInterval(function() {
|
|
|
|
|
var val = $('#sell_date').val();
|
|
|
|
|
if (val !== previousVal) {
|
|
|
|
|
getNBPCurrencyExchange($("#currency_id :selected").val());
|
|
|
|
|
}
|
|
|
|
|
previousVal = val;
|
|
|
|
|
}, 500);
|
|
|
|
|
$("#ecmlanguage").change(
|
|
|
|
|
function() {
|
|
|
|
|
if ($("#pdf_type :selected").val() == 'U'
|
|
|
|
|
|| $("#pdf_type :selected").val() == 'E') {
|
|
|
|
|
changeVat();
|
|
|
|
|
calculateTotal();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#pdf_type").change(
|
|
|
|
|
function() {
|
|
|
|
|
if ($("#pdf_type :selected").val() == 'U'
|
|
|
|
|
|| $("#pdf_type :selected").val() == 'E') {
|
|
|
|
|
changeVat();
|
|
|
|
|
calculateTotal();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#ecmpaymentcondition_id").on('inputchange', function() {
|
|
|
|
|
$(".loading_panel").css("display", "block");
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
|
|
calculatePaymentDate($("#ecmpaymentcondition_id").val());
|
|
|
|
|
$(".loading_panel").css("display", "none");
|
|
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#paid_val').change(function() {
|
|
|
|
|
calculateTotal();
|
|
|
|
|
});
|
|
|
|
|
$('#prepaid').change(function() {
|
|
|
|
|
calculateTotal();
|
|
|
|
|
});
|
|
|
|
|
// searchProductInput change
|
|
|
|
|
$('#searchProductsInput').keyup(function() {
|
|
|
|
|
searchProducts();
|
|
|
|
|
});
|
|
|
|
|
DrawHeaders();
|
|
|
|
|
|
|
|
|
|
if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#is_correct").val() != true)
|
|
|
|
|
&& ($("#is_wz").val() != true)
|
|
|
|
|
&& ($("#is_sale").val() != true)
|
|
|
|
|
&& ($("#multiDiscountCorrectInvoice").val() != true)
|
|
|
|
|
&& ($("#is_return").val() != true)) {
|
|
|
|
|
generateNumber($("#stock :selected").val());
|
|
|
|
|
|
|
|
|
|
} else if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#is_correct").val() == true)) {
|
|
|
|
|
$('#searchProducts').hide();
|
|
|
|
|
generateNumberCorrect();
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
getItems();
|
|
|
|
|
} else if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#is_wz").val() == true)) {
|
|
|
|
|
|
|
|
|
|
generateNumber($("#stock :selected").val());
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
if($("#wz_zb_id").val()!=""){
|
|
|
|
|
|
|
|
|
|
getItemsZBFromWZ();
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
getItemsFromWZ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#is_sale").val() == true)) {
|
|
|
|
|
generateNumber($("#stock :selected").val());
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
getItemsFromSale();
|
|
|
|
|
if ($("#ecmpaymentcondition_id").val() != '')
|
|
|
|
|
calculatePaymentDate($("#ecmpaymentcondition_id").val());
|
|
|
|
|
|
|
|
|
|
} else if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#is_return").val() == true)) {
|
|
|
|
|
|
|
|
|
|
generateNumberCorrect();
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
getItemsFromReturn();
|
|
|
|
|
} else if (($("#new_number").val() == true)
|
|
|
|
|
&& ($("#multiDiscountCorrectInvoice").val() == true)) {
|
|
|
|
|
generateNumberCorrect();
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
getItemsFromMDCI();
|
|
|
|
|
} else {
|
|
|
|
|
$('#document_no').prop("readonly",false);
|
|
|
|
|
getParentInfo($("#parent_id").val(), 'Accounts');
|
|
|
|
|
getItems();
|
|
|
|
|
}
|
|
|
|
|
$(".loading_panel").css("display", "none");
|
|
|
|
|
// handle setItems
|
|
|
|
|
setITEMS = function() {
|
|
|
|
|
var formname = 'EditView';
|
|
|
|
|
if (check_form_(formname) == true) {
|
|
|
|
|
SetTab('ITEMS');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// handle save
|
|
|
|
|
var check_form_ = check_form;
|
|
|
|
|
check_form = function(formname) {
|
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
|
if (items.length == 0) {
|
|
|
|
|
alert("Brak produktów");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$(".loading_panel").css("display", "block");
|
|
|
|
|
// calculate totals
|
|
|
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
|
|
|
|
for (var index = 0; index != count; index++) {
|
|
|
|
|
calculateRow(index);
|
|
|
|
|
//total_vat must be != 0 if its country correct
|
|
|
|
|
if ($('#pdf_type').val()=='K' && items[index].ecmvat_name=='0%' && items[index].product_corrected != 'true') {
|
|
|
|
|
alert("Niedopuszczalna, zerowa stawka VAT na fakturze krajowej.");
|
|
|
|
|
$(".loading_panel").css("display", "none");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-08-21 21:01:51 +02:00
|
|
|
if (items[index].price_netto == 0) {
|
|
|
|
|
alert("Niedopuszczalna, zerowa cena netto.");
|
|
|
|
|
$(".loading_panel").css("display", "none");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-04-27 09:23:34 +02:00
|
|
|
}
|
|
|
|
|
$("#total_netto").val($("#t_netto").val());
|
|
|
|
|
$("#total_brutto").val($("#t_brutto").val());
|
|
|
|
|
$("#discount").val($("#disc").val());
|
|
|
|
|
$("#position_list").val(JSON.stringifyNoSecurity(items));
|
|
|
|
|
if (check_form_(formname) == false) {
|
|
|
|
|
console.log('check_form error');
|
|
|
|
|
window.onbeforeunload = confirmExit;
|
|
|
|
|
$(".loading_panel").css("display", "none");
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
function confirmExit() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function lockEnter() {
|
|
|
|
|
// prevent default
|
|
|
|
|
$(window).keydown(function(event) {
|
|
|
|
|
if (event.keyCode == 13 && $(":focus").prop('tagName') != 'TEXTAREA') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|