Files
crm.twinpol.com/modules/EcmInvoiceOuts/javascript/EcmInvoiceOuts4.js
2025-05-12 15:45:17 +00:00

328 lines
9.8 KiB
JavaScript
Executable File

//START:
$(document).ready(
function() {
//set sizes
addToValidate('EditView','bankaccount','bankaccount',true,'Proszę wybrać konto dla przelewu');
$("#stock").on("change",stockChange);
$("#parent_name").attr("size", "70");
$("#parent_name_copy").attr("size", "70");
$("#parent_shipping_address_name").attr("size", "70");
$("#parent_payer_address_name").attr("size", "70");
$("#payment_date_days").css("width", "40");
$("#discount").css("width", "40");
$("#discount").val("0");
$("#payment_method").css("width", "100");
$("#payment_method_paid").css("width", "100");
//change parent select button
$("#btn_clr_parent_name").children().attr("src","themes/default/images/id-ff-add.png" );
$("#btn_clr_parent_name").attr("title","Dodaj" );
$("#btn_clr_parent_name").click(createAccount);
// confirm exit
window.onbeforeunload = confirmExit;
// prevent submit by enter press
lockEnter();
// parent info
var previousVal;
var pollInterval = setInterval(function() {
var val = $('#parent_id').val();
if (val !== previousVal) {
if ($('#parent_id').val() == '') return;
$(".loading_panel").css("display", "block");
setTimeout(function() {
getParentInfo($("#parent_id").val(), 'Accounts');
}, 1000);
}
previousVal = val;
}, 500);
//newProduct
var previousVal2;
var prodInterval = setInterval(function() {
var val = $('#newProductId').val();
if (val !== previousVal2) {
if ($('#newProductId').val() == '') return;
$(".loading_panel").css("display", "block");
setTimeout(function() {
AddProduct(items.length-1, val);
}, 500);
}
previousVal2 = val;
}, 500);
// parent info
var previousVal3;
var prodInterval = setInterval(function() {
var val = $('#sell_date').val();
if (val !== previousVal3) {
if ($("#currency_id :selected").val() != 'PLN')
getNBPCurrencyExchange($("#currency_id :selected").val());
}
previousVal3 = val;
}, 500);
// 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);
});
$("#stock").change(function() {
$("#stock_id").val(($("#stock :selected").val()));
if($("#is_correct").val() != true){
// EcmDocumentNumberGenerator_getNormalNumber('document_no', 'EcmInvoiceOuts', $("#stock :selected").val());
} else {
// EcmDocumentNumberGenerator_getCorrectNumber('document_no', 'EcmInvoiceOuts', $("#stock :selected").val());
}
});
$("#currency_id").change(function() {
if ($('#currency_id').val() != 'PLN') {
$('#curr_trigger').show();
getNBPCurrencyExchange($("#currency_id :selected").val());
} else {
$('#curr_trigger').hide();
$('#currency_value_nbp').val("");
$('#currency_table_tmp').val("");
$('#currency_table').val("");
}
});
$('#paid_val').change(function() {
calculateTotal();
});
$('#prepaid').blur(function() {
$("#prepaid").val(FormatNumber($("#prepaid").val()));
calculateTotal();
});
$('#pdf_type').change(function () {
manageOO();
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 -
// thead row
for (var index = 0; index != count; index++){
calculateRow(index);
}
calculateTotal();
});
$('#prepaid').click(function() {
// remove 1000 sep
var val = $('#prepaid').val();
while (val.indexOf('.') != -1)
val = val.replace('.', '');
$('#prepaid').val(val);
});
$('#currency_value_nbp').blur(function() {
$("#currency_value_nbp").val(FormatNumber($("#currency_value_nbp").val(),4));
calculateTotal();
});
$('#currency_value_nbp').click(function() {
// remove 1000 sep
var val = $('#currency_value_nbp').val();
while (val.indexOf('.') != -1)
val = val.replace('.', '');
$('#currency_value_nbp').val(val);
});
$("#discount").blur(function() {
if (UnformatNumber($('#discount').val()) > 100) $('#discount').val('100');
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++)
calculateRow(index);
$('#discount_tmp').val(UnformatNumber($('#discount').val()));
});
//payment date functions
$('#payment_date_days').css('height', '18');
$('#payment_date_days').change(function() {
calculatePaymentDate();
});
$('#payment_date_days').change(function() {
calculatePaymentDate();
});
var previousVal5;
var pollInterval5 = setInterval(function() {
var val = $('#register_date').val();
if (val !== previousVal5) {
setTimeout(function() {
calculatePaymentDate();
}, 1000);
}
previousVal5 = val;
}, 1000);
// parent info
var previousVal4;
var pollInterval4 = setInterval(function() {
var val = $('#payment_date').val();
if (val !== previousVal4) {
setTimeout(function() {
calculateDateDiff();
}, 1000);
}
previousVal4 = val;
}, 1000);
// searchProductInput change
$('#searchProductsInput').keyup(function() {
searchProducts();
});
DrawHeaders();
if (($("#new_number").val() == true)
&& ($("#duplicate").val() != true) && ($("#is_correct").val() != true) && ($("#is_wz").val() != true) && ($("#is_sale").val() != true)) {
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmInvoiceOuts');
hideOperations();
} else if (($("#new_number").val() == true)
&& ($("#duplicate").val() == true)) {
getParentInfo($("#parent_id").val(),
'Accounts');
getItems();
hideOperations();
} else if (($("#new_number").val() == true)
&& ($("#is_correct").val() == true)) {
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmInvoiceOuts');
getParentInfo($("#parent_id").val(),
'Accounts');
getItems();
$("#type").val("correct");
$("#sell_date").attr("disabled", true);
$('#sell_date_trigger').hide();
}else if (($("#new_number").val() == true)
&& ($("#is_wz").val() == true)) {
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmInvoiceOuts');
getItemsFromWZ();
hideOperations();
} else if (($("#new_number").val() == true)
&& ($("#is_sale").val() == true)) {
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmInvoiceOuts');
//getParentInfo($("#parent_id").val(),'Accounts');
getItemsFromSale();
hideOperations();
if($("#ecmpaymentcondition_id").val()!='')calculatePaymentDate($("#ecmpaymentcondition_id").val());
} else {
$('#document_no').attr('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');
$('#pdf_type').trigger('change');
}
};
// wyszukiwanie start
$('#searchProductsInput').keyup(function() {
// stronicowanie od 1 strony przy zmianie szukanego produktu
$('#searchStart').val(0);
searchProducts();
});
if($('#type').val()=='normal'){
AddSearchRecord();
}
});
function stockChange(){
$.ajax({
type: "POST",
url: "index.php?module=EcmInvoiceOuts&action=javahelper&to_pdf=1",
dataType : "json",
success: function(data) {
if(data != false){
$("#bankaccount").val(data);
$('#bankaccounts').val(data);
}
},
data: {
job: 'getStockBankAccountId',
stock_id: $(this).val(),
parent_id: $("#parent_id").val(),
}
});
}
// handle save
var check_form_ = check_form;
check_form = function(formname,event) {
// zapobiega zapisywaniu dokumentu firefox bug, w przypadku nacisniecia enter w polu z autocomplete
if(event.clientY==0 && event.clientX==0){
return false;
}
if (UnformatNumber($('#left').text())==0) {}
else {
if ($('#payment_date_days').val() == '0' || $('#payment_method :selected').val() == '') {
alert('Nie wybrano warunków zapłaty.');
return false;
}
}
var consigns = checkConsignmentsValues();
if (consigns != true) {
setITEMS('ITEMS');
alert('Brak wymaganych informacji o partiach produktu.');
return false;
}
window.onbeforeunload = null;
if (items.length == 0 || items[0].product_id=='') {
alert("Brak produktów");
return false;
}
$(".loading_panel").css("display", "block");
// calculate totals
clearEmpty();
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++)
calculateRow(index);
$("#total_netto").val($("#t_netto").val());
//$("#total_brutto").val($("#left").text());
//$("#discount").val($("#disc").val());
$("#position_list").val(JSON.stringifyNoSecurity(items));
if ($("#is_wz").val() != true) {
if($('#is_correct').val()!='1'){
if(checkProducts()==false){
$(".loading_panel").css("display", "none");
alert("Brak wystarczającej ilości magazynowej do wystawienia dokumentu!");
return false;
}
}
}
$("#type").attr("disabled", false);
$("#sell_date").attr("disabled", false);
if (check_form_(formname) == false) {
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;
}
});
}