1112 lines
33 KiB
JavaScript
1112 lines
33 KiB
JavaScript
|
|
var ajax_url = "index.php?module=EcmInvoiceOuts&action=javahelper&to_pdf=1";
|
||
|
|
var itemsTable = 'itemsTable';
|
||
|
|
var items = new Array();
|
||
|
|
var displayArray = new Array();
|
||
|
|
var searchedProducts = new Array();
|
||
|
|
var module_function = 'EcmServiceNews';
|
||
|
|
var number_show = false;
|
||
|
|
var extraproductinfo_show = false;
|
||
|
|
var unit_show = true;
|
||
|
|
|
||
|
|
//oo vat stuff
|
||
|
|
var account_vat_payer = false;
|
||
|
|
var oo_active = false;
|
||
|
|
|
||
|
|
function hideOperations(){
|
||
|
|
removeFromValidate('EditView', 'operation_type');
|
||
|
|
var this2=$('#operation_type').hide();
|
||
|
|
$(this2).closest('td').prev().html('');
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculatePaymentDate() {
|
||
|
|
var date = $("#register_date").val();
|
||
|
|
var d = date.split(".");
|
||
|
|
date = d.join(".");
|
||
|
|
var params = {
|
||
|
|
job : 'calculatePaymentDate',
|
||
|
|
date : date,
|
||
|
|
days : $('#payment_date_days').val(),
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
$('#payment_date').val(data);
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateDateDiff() {
|
||
|
|
var date1 = $("#register_date").val();
|
||
|
|
var d = date1.split(".");
|
||
|
|
date1 = d.join(".");
|
||
|
|
var date2 = $("#payment_date").val();
|
||
|
|
var d = date2.split(".");
|
||
|
|
date2 = d.join(".");
|
||
|
|
var params = {
|
||
|
|
job : 'calculateDateDiff',
|
||
|
|
date1 : date1,
|
||
|
|
date2 : date2,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
$('#payment_date_days').val(data);
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getNBPCurrencyExchange(c_id) {
|
||
|
|
var date = $("#sell_date").val();
|
||
|
|
var d = date.split(".");
|
||
|
|
d[0]-=1;
|
||
|
|
date = d.join(".");
|
||
|
|
var params = {
|
||
|
|
job : 'getNBPCurrencyExchange',
|
||
|
|
c_id : c_id,
|
||
|
|
date : date,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if(data!=false){
|
||
|
|
$("#currency_value_nbp").val(FormatNumber(data.value,4));
|
||
|
|
$("#currency_table_tmp").val(data.name);
|
||
|
|
$("#currency_table").val(data.name);
|
||
|
|
} else {$("#currency_value_nbp").val(FormatNumber(0,4));}
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getCurrencyValues() {
|
||
|
|
var c_id = $("#currency_id :selected").val();
|
||
|
|
var date = $("#register_date").val();
|
||
|
|
var d = date.split(".");
|
||
|
|
d[0]-=1;
|
||
|
|
date = d.join(".");
|
||
|
|
var html = '';
|
||
|
|
var params = {
|
||
|
|
job : 'getCurrencyValues',
|
||
|
|
c_id : c_id,
|
||
|
|
date : date,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
$.each(data, function(index, value){
|
||
|
|
html+='<p style="cursor:pointer;" onClick="$(\'#currency_value_nbp\').val(\''+FormatNumber(value.value,4)+'\');$(\'#currency_table_tmp\').val(\''+value.name+'\');$(\'#currency_table\').val(\''+value.name+'\'); $(\'#cur_values\').hide();"> '+FormatNumber(value.value,4)+'  '+value.name+' </p>';
|
||
|
|
});
|
||
|
|
$("#cur_values").html(html);
|
||
|
|
$("#cur_values").show();
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPayer(id){
|
||
|
|
var account_id=$("#address_id :selected").val();
|
||
|
|
var params = {
|
||
|
|
job : 'getAddress',
|
||
|
|
account_id : account_id,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '-1') {
|
||
|
|
$("#parent_payer_address_name").val(data[0].description);
|
||
|
|
$("#parent_payer_address_street").val(data[0].street);
|
||
|
|
$("#parent_payer_address_postalcode").val(data[0].postalcode);
|
||
|
|
$("#parent_payer_address_city").val(data[0].city);
|
||
|
|
$("#parent_payer_address_country").val(data[0].country);
|
||
|
|
}
|
||
|
|
//$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getAddress(id){
|
||
|
|
var account_id=$("#address_id :selected").val();
|
||
|
|
var params = {
|
||
|
|
job : 'getAddress',
|
||
|
|
account_id : account_id,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '-1') {
|
||
|
|
$("#parent_shipping_address_name").val(data[0].description);
|
||
|
|
$("#parent_shipping_address_street").val(data[0].street);
|
||
|
|
$("#parent_shipping_address_postalcode").val(data[0].postalcode);
|
||
|
|
$("#parent_shipping_address_city").val(data[0].city);
|
||
|
|
$("#parent_shipping_address_country").val(data[0].country);
|
||
|
|
}
|
||
|
|
//$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function setAddressSend(result){
|
||
|
|
var p = new Object();
|
||
|
|
p.street=result.street;
|
||
|
|
alert(p.street);
|
||
|
|
}
|
||
|
|
|
||
|
|
function getAddresses(account_id) {
|
||
|
|
//show loading
|
||
|
|
var params = {
|
||
|
|
job : 'getAddresses',
|
||
|
|
account_id : account_id,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '')
|
||
|
|
$('#addresses').append(data);
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPayers(account_id) {
|
||
|
|
//show loading
|
||
|
|
var params = {
|
||
|
|
job : 'getPayers',
|
||
|
|
account_id : account_id,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
$('#payer').append(data);
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateRow(index) {
|
||
|
|
if (index == -1)
|
||
|
|
return;
|
||
|
|
|
||
|
|
// liczone według najlepszych zasad księgowości
|
||
|
|
var price_start = UnformatNumber($('#price_start_' + index).val());
|
||
|
|
var discount = UnformatNumber($('#discount_' + index).val());
|
||
|
|
var vat_value = $('#ecmvat_value_' + index).val();
|
||
|
|
var quantity = UnformatNumber($('#quantity_' + index).val());
|
||
|
|
var res = UnformatNumber($('#quantity_res_' + index).val());
|
||
|
|
var precision = UnformatNumber($('#product_precision_' + index).val());
|
||
|
|
var price_netto = 0;
|
||
|
|
|
||
|
|
//check invoice discount
|
||
|
|
discount = (discount - $('#discount_tmp').val()) + UnformatNumber($('#discount').val());
|
||
|
|
$('#discount_' + index).val(FormatNumber(discount));
|
||
|
|
|
||
|
|
if (discount > 0)
|
||
|
|
price_netto = price_start - (price_start * (discount / 100));
|
||
|
|
else
|
||
|
|
price_netto = price_start;
|
||
|
|
|
||
|
|
var total_netto = price_netto * quantity;
|
||
|
|
console.log(total_netto+' '+quantity+' '+vat_value+' '+price_netto);
|
||
|
|
// put data
|
||
|
|
$('#price_netto_' + index).val(FormatNumber(price_netto));
|
||
|
|
$('#total_netto_' + index).val(FormatNumber(total_netto));
|
||
|
|
$('#total_vat_' + index).val(FormatNumber((total_netto*vat_value)/100));
|
||
|
|
$('#price_brutto_' + index).val(FormatNumber(((price_netto*vat_value)/100)+price_netto));
|
||
|
|
$('#total_brutto_' + index).val(FormatNumber(((total_netto*vat_value)/100)+total_netto));
|
||
|
|
// put data to items array
|
||
|
|
items[index].price_start = toFixed(price_start, 2);
|
||
|
|
items[index].price_netto = toFixed(price_netto, 2);
|
||
|
|
items[index].price_brutto = toFixed(((price_netto*vat_value)/100)+price_netto, 2);
|
||
|
|
items[index].total_netto = toFixed(total_netto, 2);
|
||
|
|
items[index].total_brutto = toFixed(((total_netto*vat_value)/100)+total_netto, 2);
|
||
|
|
items[index].total_vat = toFixed(((total_netto*vat_value)/100), 2);
|
||
|
|
items[index].quantity = toFixed(quantity, precision),precision;
|
||
|
|
items[index].discount = toFixed(discount, 2);
|
||
|
|
items[index].ecmvat_id = $('#ecmvat_id_' + index).val();
|
||
|
|
items[index].ecmvat_name = $('#ecmvat_name_' + index).val();
|
||
|
|
items[index].ecmvat_value = vat_value;
|
||
|
|
|
||
|
|
// put other data
|
||
|
|
items[index].recipient_code = $('#recipient_code_' + index).val();
|
||
|
|
items[index].remarks = $('#remarks_' + index).val();
|
||
|
|
// change name or language?
|
||
|
|
items[index].name = $('#name_' + index).val();
|
||
|
|
items[index].unit_name = $('#unit_name_' + index).val();
|
||
|
|
//console.log(items[index]);
|
||
|
|
if ($("#type").val() == 'correct') {
|
||
|
|
calculateTotalCorrect();
|
||
|
|
} else {
|
||
|
|
calculateTotal();
|
||
|
|
}
|
||
|
|
|
||
|
|
//getMarginInfo(index);
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateTotal() {
|
||
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||
|
|
var vats = new Array();
|
||
|
|
var all_subtotal = 0;
|
||
|
|
var all_total = 0;
|
||
|
|
var sum_vats = 0;
|
||
|
|
var sum_discounts = 0;
|
||
|
|
var sum_oo = 0;
|
||
|
|
|
||
|
|
for (var index = 0; index != count; index++) {
|
||
|
|
subtotal = UnformatNumber($('#total_netto_' + index).val());
|
||
|
|
vat_val = UnformatNumber($('#total_vat_' + index).val());
|
||
|
|
total = subtotal + vat_val;
|
||
|
|
product_corrected = $('#product_corrected_' + index).val();
|
||
|
|
if (product_corrected == 'true')
|
||
|
|
continue;
|
||
|
|
|
||
|
|
all_subtotal += subtotal;
|
||
|
|
if ($('#product_is_oo_'+index).val() == '1')
|
||
|
|
sum_oo += subtotal
|
||
|
|
|
||
|
|
if (!($('#ecmvat_id_' + index).val() in vats)) {
|
||
|
|
vats[$('#ecmvat_id_' + index).val()] = new Object();
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value_name = $(
|
||
|
|
'#ecmvat_name_' + index).val(); // ex. 23
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].netto = subtotal;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value = vat_val;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].brutto = total;
|
||
|
|
} else {
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].netto += subtotal;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value += vat_val;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].brutto += total;
|
||
|
|
}
|
||
|
|
sum_vats += vat_val;
|
||
|
|
|
||
|
|
if (UnformatNumber($('#discount_' + index).val()) > 0)
|
||
|
|
sum_discounts += (UnformatNumber($('#price_start_' + index).val()) * UnformatNumber($(
|
||
|
|
'#quantity_' + index).val()))
|
||
|
|
* (UnformatNumber($('#discount_' + index).val()) / 100);
|
||
|
|
}
|
||
|
|
all_total = all_subtotal + sum_vats;
|
||
|
|
|
||
|
|
|
||
|
|
$("#disc").val(FormatNumber(sum_discounts));
|
||
|
|
// add vats
|
||
|
|
var html = '';
|
||
|
|
var vats_summary = '';
|
||
|
|
for ( var x in vats) {
|
||
|
|
if(vats[x].value_name!=''){
|
||
|
|
html += '<tr><td class="positionsLabel">' + vats[x].value_name + '</td>';
|
||
|
|
html += '<td class="positionsField"><input type="text" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;" name="vat" id="vat" value="'
|
||
|
|
+ FormatNumber(vats[x].value) + '"></td></tr>';
|
||
|
|
|
||
|
|
vats_summary += vats[x].value_name + ':' + toFixed(vats[x].netto, 2)
|
||
|
|
+ ':' + toFixed(vats[x].value, 2) + ':'
|
||
|
|
+ toFixed(vats[x].brutto, 2) + ':' + ',';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
DrawSummary(html);
|
||
|
|
$('#total_vat').val(FormatNumber(sum_vats));
|
||
|
|
$("#t_netto").val(FormatNumber(all_subtotal));
|
||
|
|
$("#t_brutto").val(FormatNumber(all_total));
|
||
|
|
$('#to_paid').text(FormatNumber(all_total));
|
||
|
|
var paid = UnformatNumber($('#paid_val').val());
|
||
|
|
var prepaid = UnformatNumber($('#prepaid').val());
|
||
|
|
$('#left').text(FormatNumber(all_total - paid - prepaid));
|
||
|
|
$("#vats_summary").val(vats_summary);
|
||
|
|
}
|
||
|
|
|
||
|
|
function manageOO() {
|
||
|
|
var count = items.length;
|
||
|
|
//parse OO object
|
||
|
|
if (typeof(OO) != 'object')
|
||
|
|
OO = JSON.parse(OO);
|
||
|
|
for (var index = 0; index != count; index++) {
|
||
|
|
|
||
|
|
if (oo_active == true) {
|
||
|
|
if ($('#product_is_oo_'+index).val() != '1') continue;
|
||
|
|
if ($('#pdf_type').val() != 'K') continue;
|
||
|
|
|
||
|
|
//save orginal vat
|
||
|
|
items[index].real_vat_id = items[index].ecmvat_id;
|
||
|
|
items[index].real_vat_name = items[index].ecmvat_name;
|
||
|
|
items[index].real_vat_value = items[index].ecmvat_value;
|
||
|
|
items[index].ecmvat_id = OO.id;
|
||
|
|
items[index].ecmvat_name = OO.name;
|
||
|
|
items[index].ecmvat_value = OO.value;
|
||
|
|
$('#ecmvat_id_'+index).val(OO.id);
|
||
|
|
$('#ecmvat_name_'+index).val(OO.name);
|
||
|
|
$('#ecmvat_value_'+index).val(OO.value);
|
||
|
|
} else {
|
||
|
|
if ($('#pdf_type').val() != 'K'){
|
||
|
|
items[index].real_vat_id='9b783d21-5548-6653-e1d6-49610eb3f9dd';
|
||
|
|
items[index].real_vat_name='0%';
|
||
|
|
items[index].real_vat_value='0.00';
|
||
|
|
items[index].ecmvat_id = items[index].real_vat_id;
|
||
|
|
items[index].ecmvat_name = items[index].real_vat_name;
|
||
|
|
items[index].ecmvat_value = items[index].real_vat_value;
|
||
|
|
$('#ecmvat_id_'+index).val(items[index].real_vat_id);
|
||
|
|
$('#ecmvat_name_'+index).val(items[index].real_vat_name);
|
||
|
|
$('#ecmvat_value_'+index).val(items[index].real_vat_value);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//calculateRow(index);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function calculateTotalCorrect() {
|
||
|
|
if ($("#is_correct").val() != true) return;
|
||
|
|
|
||
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||
|
|
var vats = new Array();
|
||
|
|
var total_netto = 0;
|
||
|
|
var total_brutto = 0;
|
||
|
|
var total_vat = 0;
|
||
|
|
var sum_discounts = 0;
|
||
|
|
|
||
|
|
for (var index = 0; index != count; index++) {
|
||
|
|
var product_corrected = $('#product_corrected_' + index).val();
|
||
|
|
if (product_corrected == 'true')
|
||
|
|
continue;
|
||
|
|
|
||
|
|
|
||
|
|
var subtotal = UnformatNumber($('#total_netto_' + index).val());
|
||
|
|
var total = UnformatNumber($('#total_brutto_' + index).val());
|
||
|
|
var vat_val = toFixed(subtotal
|
||
|
|
* ($('#ecmvat_value_' + index).val() / 100),2);
|
||
|
|
//old val (from next row)
|
||
|
|
var old_subtotal = UnformatNumber($('#total_netto_' + (index+1)).val());
|
||
|
|
var old_total = UnformatNumber($('#total_brutto_' + (index+1)).val());
|
||
|
|
var old_vat_val = toFixed(old_subtotal
|
||
|
|
* ($('#ecmvat_value_' + (index+1)).val() / 100),2);
|
||
|
|
//corrected
|
||
|
|
var vat_c = parseFloat(toFixed(vat_val - old_vat_val,2));
|
||
|
|
var subtotal_c = parseFloat(toFixed(subtotal - old_subtotal,2));
|
||
|
|
var total_c = parseFloat(toFixed(total - old_total,2));
|
||
|
|
|
||
|
|
total_netto += subtotal_c;
|
||
|
|
|
||
|
|
if (!$("#no_tax").is(":checked")) {
|
||
|
|
// font color to black
|
||
|
|
$("#ecmvat_name_" + index).css("color", "black");
|
||
|
|
if (!($('#ecmvat_id_' + index).val() in vats)) {
|
||
|
|
vats[$('#ecmvat_id_' + index).val()] = new Object();
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value_name = $(
|
||
|
|
'#ecmvat_name_' + index).val(); // ex. 23
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value = vat_c;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].subtotal = subtotal_c;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].total = total_c;
|
||
|
|
} else {
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].value += vat_c;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].subtotal += subtotal_c;
|
||
|
|
vats[$('#ecmvat_id_' + index).val()].total += total_c;
|
||
|
|
}
|
||
|
|
total_vat += vat_c;
|
||
|
|
total_brutto += total_c;
|
||
|
|
} else {
|
||
|
|
// set color to red
|
||
|
|
$("#ecmvat_name_" + index).css("color", "red");
|
||
|
|
}
|
||
|
|
|
||
|
|
if (UnformatNumber($('#discount_' + index).val()) > 0)
|
||
|
|
sum_discounts += (UnformatNumber($('#price_start_' + index).val()) * UnformatNumber($(
|
||
|
|
'#quantity_' + index).val()))
|
||
|
|
* (UnformatNumber($('#discount_' + index).val()) / 100);
|
||
|
|
}
|
||
|
|
|
||
|
|
var html = '';
|
||
|
|
var vats_summary = '';
|
||
|
|
for ( var x in vats) {
|
||
|
|
if(vats[x].value_name!=''){
|
||
|
|
html += '<tr><td class="positionsLabel">' + vats[x].value_name + '</td>';
|
||
|
|
html += '<td class="positionsField"><input type="text" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;" name="vat" id="vat" value="'
|
||
|
|
+ FormatNumber(vats[x].value) + '"></td></tr>';
|
||
|
|
|
||
|
|
vats_summary += vats[x].value_name + ':'
|
||
|
|
+ toFixed(vats[x].subtotal, 2) + ':'
|
||
|
|
+ toFixed(vats[x].value, 2) + ':'
|
||
|
|
+ toFixed(vats[x].total, 2) + ',';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
DrawSummary(html);
|
||
|
|
$('#total_vat').val(FormatNumber(total_vat));
|
||
|
|
|
||
|
|
$("#t_netto").val(FormatNumber(total_netto));
|
||
|
|
$("#t_brutto").val(FormatNumber(total_brutto));
|
||
|
|
$('#to_paid').text(FormatNumber(total_brutto));
|
||
|
|
|
||
|
|
var paid = UnformatNumber($('#paid_val').val());
|
||
|
|
var prepaid = UnformatNumber($('#prepaid').val());
|
||
|
|
$('#left').text(FormatNumber(total_brutto - paid - prepaid));
|
||
|
|
$("#disc").val(FormatNumber(sum_discounts));
|
||
|
|
|
||
|
|
$("#vats_summary").val(vats_summary);
|
||
|
|
}
|
||
|
|
|
||
|
|
// draw table
|
||
|
|
function DrawHeaders() {
|
||
|
|
var html = '<link rel="stylesheet" type="text/css" href="modules/EcmInvoiceOuts/MyTable.css" />';
|
||
|
|
html += '<div style="width:100%;border: 1px solid rgb(48,192,255);background-color:white;overflow:auto;" id="'
|
||
|
|
+ itemsTable + 'DIV">';
|
||
|
|
html += '<table class="positions" style="width:100%;" id="' + itemsTable
|
||
|
|
+ '_T">';
|
||
|
|
html += '<thead id="head">';
|
||
|
|
html += '<tr id="tr">';
|
||
|
|
// draw columns headers
|
||
|
|
$.each(columns, function(index, column) {
|
||
|
|
html += '<td width="' + column.width + '%">' + column.label + '</td>';
|
||
|
|
});
|
||
|
|
html += '</tr></thead><tbody></tbody></table>';
|
||
|
|
html += '</div><br>';
|
||
|
|
// totals table
|
||
|
|
html += '<table width="100%"" cellpadding="0" cellspacing="0" border="0">';
|
||
|
|
html += '<tr>';
|
||
|
|
html += '<td width="55%" class="dataLabel" valign="top">';
|
||
|
|
html += ' ';
|
||
|
|
html += '</td> <!--color:#b3b9cf;-->';
|
||
|
|
html += '<td width="40%" class="dataField" style="text-align: left;">';
|
||
|
|
html += '<br>';
|
||
|
|
html += '<table id="result_table" cellpadding="0" cellspacing="0" style="width:100%; height:100%; border: 1px solid rgb(48,192,255);">';
|
||
|
|
html += '</table>';
|
||
|
|
html += '</td>';
|
||
|
|
html += '<td width="5%" class="dataField" style="text-align: left;"> </td>';
|
||
|
|
html += '</tr>';
|
||
|
|
html += '</table>';
|
||
|
|
$('#' + itemsTable).html(html);
|
||
|
|
}
|
||
|
|
|
||
|
|
function DrawSummary(vats) {
|
||
|
|
$("#result_table").html('');
|
||
|
|
html = '';
|
||
|
|
html += '<tr id="subtotal_tr"> ';
|
||
|
|
html += '<td class="positionsLabel" style="border-top:0px;">Suma netto</td>';
|
||
|
|
html += '<td class="positionsField" style="border-top:0px;"><input type="text" style="border:0px;font-weight:900;width:100%;text-align:right;" readonly="readonly" name="t_netto" id="t_netto" value=\'\'></td>';
|
||
|
|
html += '</tr>';
|
||
|
|
html += '<tr id="discount_tr"> ';
|
||
|
|
html += '<td class="positionsLabel">Upust</td>';
|
||
|
|
html += '<td class="positionsField"><input type="text" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;" name="disc" id="disc" value=\'\'></td>';
|
||
|
|
html += '</tr>';
|
||
|
|
html+=vats;
|
||
|
|
html += '<tr id="total_tr"> ';
|
||
|
|
html += '<td class="positionsLabel">Suma brutto</td>';
|
||
|
|
html += '<td class="positionsField"><input type="text" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;" name="t_brutto" id="t_brutto" value=\'\'></td>';
|
||
|
|
html += '</tr>';
|
||
|
|
$("#result_table").html(html);
|
||
|
|
}
|
||
|
|
|
||
|
|
function SendMail(id,modulee,parent_id){
|
||
|
|
$(".loading_panel").css("display", "block");
|
||
|
|
var params = {
|
||
|
|
job : 'SendMail',
|
||
|
|
id : id,
|
||
|
|
modulee : modulee,
|
||
|
|
parent_id : parent_id,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '-1') {
|
||
|
|
|
||
|
|
$("#sendreturn").text('Email z fakturą został wysłany!');
|
||
|
|
$("#sendreturn").show();
|
||
|
|
} else {
|
||
|
|
$("#sendreturn").text('Email z fakturą nie został wysłany!');
|
||
|
|
$("#sendreturn").show();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
}
|
||
|
|
|
||
|
|
function addProducts() {
|
||
|
|
$(".loading_panel").css("display", "block");
|
||
|
|
clearEmpty();
|
||
|
|
var products = new Array();
|
||
|
|
$.each(searchedProducts, function(index, value) {
|
||
|
|
if ($('#prod_' + value).is(':checked'))
|
||
|
|
products[value] = true;
|
||
|
|
});
|
||
|
|
var pricebook = $("#pricebook_id :selected").val();
|
||
|
|
for ( var key in products) {
|
||
|
|
var params = {
|
||
|
|
job : 'getProduct',
|
||
|
|
id : key,
|
||
|
|
pricebook : pricebook,
|
||
|
|
account_id : $("#parent_id").val(),
|
||
|
|
//stock_id : $("#stock_id").val(),
|
||
|
|
language : 'pl_pl',
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '-1') {
|
||
|
|
var p = new Object();
|
||
|
|
p.product_id = data.id;
|
||
|
|
p.name = data.name;
|
||
|
|
p.product_code = data.code;
|
||
|
|
p.product_id = data.id;
|
||
|
|
p.ecmvat_id = data.ecmvat_id;
|
||
|
|
p.ecmvat_value = data.ecmvat_value;
|
||
|
|
p.ecmvat_name = data.ecmvat_name;
|
||
|
|
p.product_ean = data.ean;
|
||
|
|
p.product_ean2 = data.ean2;
|
||
|
|
p.unit_name = data.unit_name;
|
||
|
|
p.unit_id = data.unit_id;
|
||
|
|
p.price_start = data.price_start;
|
||
|
|
p.recipient_code = data.recipient_code;
|
||
|
|
p.unit_precision = data.unit_precision;
|
||
|
|
p.product_ks_group=data.ks_group;
|
||
|
|
p.product_is_consignment = data.is_consignment;
|
||
|
|
p.product_precision = data.unit_precision;
|
||
|
|
p.product_category_id=data.product_category_id;
|
||
|
|
p.stock_state_value = data.stock_state;
|
||
|
|
p.discount = UnformatNumber($('#discount').val());
|
||
|
|
p.product_is_oo = data.OO;
|
||
|
|
if ($("#searchInputPrice").val() != ''
|
||
|
|
&& !isNaN(parseFloat(UnformatNumber($(
|
||
|
|
"#searchInputPrice").val()))))
|
||
|
|
p.price_start = $("#searchInputPrice").val();
|
||
|
|
if ($("#searchInputQty").val() != ''
|
||
|
|
&& !isNaN(parseFloat(UnformatNumber($(
|
||
|
|
"#searchInputQty").val()))))
|
||
|
|
p.quantity = $("#searchInputQty").val();
|
||
|
|
items.push(p);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
AddSearchRecord();
|
||
|
|
|
||
|
|
FillTable(items);
|
||
|
|
checkProductIsConsignment();
|
||
|
|
// clear results
|
||
|
|
$('#searchResultDiv').html('');
|
||
|
|
searchedProducts = new Array();
|
||
|
|
$('#searchProductsInput').val('');
|
||
|
|
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
}
|
||
|
|
|
||
|
|
function AddProduct(index,record){
|
||
|
|
$(".loading_panel").css("display", "block");
|
||
|
|
var record;
|
||
|
|
var pricebook = $("#pricebook_id :selected").val();
|
||
|
|
var params = {
|
||
|
|
job : 'getProduct',
|
||
|
|
id : record,
|
||
|
|
pricebook : pricebook,
|
||
|
|
account_id : $("#parent_id").val(),
|
||
|
|
stock_id : $("#stock_id").val(),
|
||
|
|
language : $("#ecmlanguage").val(),
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
if (data != '-1') {
|
||
|
|
items[index].product_id = data.id;
|
||
|
|
items[index].name = data.name;
|
||
|
|
items[index].product_code = data.code;
|
||
|
|
items[index].product_id = data.id;
|
||
|
|
items[index].ecmvat_id = data.ecmvat_id;
|
||
|
|
items[index].ecmvat_value = data.ecmvat_value;
|
||
|
|
items[index].ecmvat_name = data.ecmvat_name;
|
||
|
|
items[index].product_ean = data.ean;
|
||
|
|
items[index].discount = data.discount;
|
||
|
|
items[index].product_ean2 = data.ean2;
|
||
|
|
items[index].unit_name = data.unit_name;
|
||
|
|
items[index].unit_id = data.unit_id;
|
||
|
|
items[index].price_start = data.price_start;
|
||
|
|
items[index].recipient_code = data.recipient_code;
|
||
|
|
items[index].product_is_consignment = data.is_consignment;
|
||
|
|
items[index].product_precision = data.unit_precision;
|
||
|
|
items[index].unit_precision = data.unit_precision;
|
||
|
|
items[index].product_ks_group=data.ks_group;
|
||
|
|
items[index].product_category_id=data.product_category_id;
|
||
|
|
items[index].stock_state_value=data.stock_state;
|
||
|
|
items[index].product_is_oo = data.OO;
|
||
|
|
items[index].discount = UnformatNumber($('#discount').val());
|
||
|
|
if ($("#searchInputPrice").val() != ''
|
||
|
|
&& !isNaN(parseFloat(UnformatNumber($(
|
||
|
|
"#searchInputPrice").val()))))
|
||
|
|
items[index].price_start = $("#searchInputPrice").val();
|
||
|
|
if ($("#searchInputQty").val() != ''
|
||
|
|
&& !isNaN(parseFloat(UnformatNumber($(
|
||
|
|
"#searchInputQty").val()))))
|
||
|
|
items[index].quantity = $("#searchInputQty").val();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
AddSearchRecord();
|
||
|
|
FillTable(items);
|
||
|
|
//checkProductIsConsignment();
|
||
|
|
$('#searchResultDiv').html('');
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
$("#quantity_"+index).focus().select();
|
||
|
|
}
|
||
|
|
|
||
|
|
function refreshStock(index) {
|
||
|
|
var params = {
|
||
|
|
job : 'getStockState',
|
||
|
|
id : $("#product_id_" + index).val(),
|
||
|
|
stock_id : $("#stock_id").val(),
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
$("#stock_state_value_" + index).val(FormatNumber(data,$("#product_precision_" + index).val()));
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function checkProducts() {
|
||
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||
|
|
var error = false; // hope :)
|
||
|
|
for (var index = 0; index != count; index++) {
|
||
|
|
if($("#product_id_" + index).val()!='' && ($("#product_ks_group_" + index).val()!='3' || $("#product_category_" + index).val()!='bf900339-6c7b-f278-2737-542023796730')){
|
||
|
|
refreshStock(index);
|
||
|
|
var qty = UnformatNumber($("#quantity_" + index).val());
|
||
|
|
var stock = UnformatNumber($("#stock_state_value_" + index).val());
|
||
|
|
var cat_id = $("#product_category_id_" + index).val();
|
||
|
|
var part_qty = $("#product_consignment_qty_" + index).val();
|
||
|
|
// refresh items array
|
||
|
|
items[index].quantity = qty;
|
||
|
|
if ($('#product_is_consignment_' + index).val() != '1') {
|
||
|
|
part_qty=qty;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (qty>0 && parseFloat(qty)<=parseFloat(part_qty) && parseFloat(qty)<=parseFloat(stock)){
|
||
|
|
|
||
|
|
$("#quantity_" + index).css("color", "black");
|
||
|
|
} else {
|
||
|
|
if(cat_id!='bf900339-6c7b-f278-2737-542023796730'){
|
||
|
|
error = true;
|
||
|
|
$("#quantity_" + index).css("color", "red");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (error)
|
||
|
|
return false;
|
||
|
|
else
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function getItems() {
|
||
|
|
var record = '';
|
||
|
|
if ($("input[name='duplicateSave']").val() == 'true')
|
||
|
|
record = $("input[name='duplicateId']").val();
|
||
|
|
else
|
||
|
|
record = $("input[name='record']").val();
|
||
|
|
console.log(record);
|
||
|
|
if(record==''){
|
||
|
|
return
|
||
|
|
}
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : 'index.php?module=EcmServiceNews&action=ajax&to_pdf=1',
|
||
|
|
dataType : "json",
|
||
|
|
success : function(data) {
|
||
|
|
$.each(data, function(k,v){
|
||
|
|
items.push(v);
|
||
|
|
});
|
||
|
|
AddSearchRecord();
|
||
|
|
FillTable(items, false);
|
||
|
|
},
|
||
|
|
data : {
|
||
|
|
job : 'getItems',
|
||
|
|
record : record,
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getItemsFromSale(editview) {
|
||
|
|
var record = '';
|
||
|
|
|
||
|
|
if ($("#is_sale").val() == true)
|
||
|
|
record = $("input[name='so_id']").val();
|
||
|
|
else
|
||
|
|
record = $("input[name='so_id']").val();
|
||
|
|
|
||
|
|
var type = '';
|
||
|
|
if ($("#is_correct").val() == true)
|
||
|
|
type=true;
|
||
|
|
else
|
||
|
|
type='';
|
||
|
|
|
||
|
|
if (isNaN(editview))
|
||
|
|
editview = true;
|
||
|
|
var params = {
|
||
|
|
job : 'getItemsFromSale',
|
||
|
|
record : record,
|
||
|
|
type : type,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
success : function(data) {
|
||
|
|
items = data;
|
||
|
|
if (editview)
|
||
|
|
FillTable(items, false);
|
||
|
|
else
|
||
|
|
FillTable(items, true);
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getItemsFromWZ(editview) {
|
||
|
|
var record = '';
|
||
|
|
|
||
|
|
if ($("#is_wz").val() == true)
|
||
|
|
record = $("input[name='wz_id']").val();
|
||
|
|
else
|
||
|
|
record = $("input[name='wz_id']").val();
|
||
|
|
|
||
|
|
var type = '';
|
||
|
|
if ($("#is_correct").val() == true)
|
||
|
|
type=true;
|
||
|
|
else
|
||
|
|
type='';
|
||
|
|
|
||
|
|
if (isNaN(editview))
|
||
|
|
editview = true;
|
||
|
|
var params = {
|
||
|
|
job : 'getItemsFromWZ',
|
||
|
|
record : record,
|
||
|
|
type : type,
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
success : function(data) {
|
||
|
|
items = data;
|
||
|
|
if (editview)
|
||
|
|
FillTable(items, false);
|
||
|
|
else
|
||
|
|
FillTable(items, true);
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function DrawDetailSummary() {
|
||
|
|
DrawSummary();
|
||
|
|
$("#t_netto").val(FormatNumber($("#total_netto").val()));
|
||
|
|
$("#t_brutto").val(FormatNumber($("#total_brutto").val()));
|
||
|
|
$("#disc").val(FormatNumber($("#discount").val()));
|
||
|
|
if ($("#no_tax").val() == '1') {
|
||
|
|
$("input[name^=ecmvat_name]").css("color", "red");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var html = '';/*
|
||
|
|
var vats = $("#vats_summary").val().split(",");
|
||
|
|
for (var i = 0; i < vats.length - 1; i++) {// last element is empty
|
||
|
|
var vat = vats[i].split(":");
|
||
|
|
html += '<tr><td class="positionsLabel">' + vat[0] + '</td>';
|
||
|
|
html += '<td class="positionsField"><input type="text" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;" name="vat" id="vat" value="'
|
||
|
|
+ FormatNumber(vat[2]) + '"></td></tr>';
|
||
|
|
|
||
|
|
}
|
||
|
|
$('#result_table > tbody > tr:eq(1)').after(html);*/
|
||
|
|
}
|
||
|
|
|
||
|
|
function changeLanguage() {
|
||
|
|
$(".loading_panel").css("display", "block");
|
||
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||
|
|
for (var index = 0; index != count; index++) {
|
||
|
|
var params = {
|
||
|
|
job : 'getTranslation',
|
||
|
|
product_id : $("#product_id_" + index).val(),
|
||
|
|
language : $("#ecmlanguage").val(),
|
||
|
|
unit_id : $("#unit_id_" + index).val(),
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
async : false,
|
||
|
|
dataType : "json",
|
||
|
|
success : function(data) {
|
||
|
|
$("#name_" + index).val(data.name);
|
||
|
|
$("#unit_name_" + index).val(data.unit_name);
|
||
|
|
calculateRow(index);
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPricesInfo(index) {
|
||
|
|
$("#price_start_div_" + index).show('slow');
|
||
|
|
$("#price_start_div_" + index).html('<img src="modules/EcmInvoiceOuts/images/loading.gif"/>');
|
||
|
|
|
||
|
|
var params = {
|
||
|
|
job : 'getPricesInfo',
|
||
|
|
product_id : $("#product_id_" + index).val(),
|
||
|
|
pricebook_id : $("#pricebook_id :selected").val(),
|
||
|
|
account_id : $("#parent_id").val(),
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type : "POST",
|
||
|
|
url : ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
async : false,
|
||
|
|
success : function(data) {
|
||
|
|
html = '<ul style="font-size: 7pt;">';
|
||
|
|
$.each(data,function(key, value) {
|
||
|
|
if (value.name == 'pricebook') {
|
||
|
|
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||
|
|
+ index
|
||
|
|
+ '\').val(\''
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||
|
|
+ index
|
||
|
|
+ ')"><u>'
|
||
|
|
+ $(
|
||
|
|
"#pricebook_id :selected")
|
||
|
|
.html()
|
||
|
|
+ ': '
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '</u></li>';
|
||
|
|
} else if (value.name == $("#ecmprice_name").val()) {
|
||
|
|
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||
|
|
+ index
|
||
|
|
+ '\').val(\''
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||
|
|
+ index
|
||
|
|
+ ');"><b>'
|
||
|
|
+ value.name
|
||
|
|
+ ': '
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '</b></li>';
|
||
|
|
} else {
|
||
|
|
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
||
|
|
+ index
|
||
|
|
+ '\').val(\''
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '\'); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
||
|
|
+ index
|
||
|
|
+ ');">'
|
||
|
|
+ value.name
|
||
|
|
+ ': '
|
||
|
|
+ FormatNumber(value.price)
|
||
|
|
+ '</li>';
|
||
|
|
}
|
||
|
|
});
|
||
|
|
html += '</ul>';
|
||
|
|
},
|
||
|
|
data : params
|
||
|
|
});
|
||
|
|
$("#price_start_div_" + index).html(html);
|
||
|
|
}
|
||
|
|
|
||
|
|
//sortable rows in main table
|
||
|
|
$("#"+itemsTable+" tbody").sortable();
|
||
|
|
//get parent info use ajax
|
||
|
|
function getParentInfo(parent_id, parent_type) {
|
||
|
|
var params = {
|
||
|
|
id : parent_id,
|
||
|
|
type : parent_type,
|
||
|
|
job : 'getParentInfo'
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type: "POST",
|
||
|
|
url: ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
success: function(data) {
|
||
|
|
if (data == '-1') {
|
||
|
|
alert('Błąd');
|
||
|
|
$("#parent_name").val('');
|
||
|
|
$("#parent_id").val('');
|
||
|
|
} else {
|
||
|
|
setParentInfo(data);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
data: params
|
||
|
|
});
|
||
|
|
getAddresses(parent_id);
|
||
|
|
getPayers(parent_id);
|
||
|
|
}
|
||
|
|
|
||
|
|
//insert parent info in fields
|
||
|
|
function setParentInfo(data) {
|
||
|
|
//pricebooks
|
||
|
|
createPricebookSelect(data.pricebooks);
|
||
|
|
if (data.ecmprice_id && data.ecmprice_name) {
|
||
|
|
$("#ecmprice_id").val(data.ecmprice_id);
|
||
|
|
$("#ecmprice_name").val(data.ecmprice_name);
|
||
|
|
}
|
||
|
|
if (data.vat_payer == '1')
|
||
|
|
account_vat_payer = true;
|
||
|
|
else
|
||
|
|
account_vat_payer = false;
|
||
|
|
getBankAccounts(data.invoice_bank_account);
|
||
|
|
if (data.invoice_type)
|
||
|
|
$("#pdf_type").val(data.invoice_type);
|
||
|
|
$('#bankaccount').val(data.invoice_bank_account);
|
||
|
|
//if ($("#new_number").val() == false) return; //if edit exists load only pricebooks
|
||
|
|
if (data.name)
|
||
|
|
$("#parent_name_copy").val(data.name);
|
||
|
|
if (data.parent_nip)
|
||
|
|
$("#parent_nip").val(data.parent_nip);
|
||
|
|
if (data.parent_index)
|
||
|
|
$('#parent_index_dbf').val(data.parent_index);
|
||
|
|
if (data.parent_address_street)
|
||
|
|
$("#parent_address_street").val(data.parent_address_street);
|
||
|
|
if (data.parent_address_city)
|
||
|
|
$("#parent_address_city").val(data.parent_address_city);
|
||
|
|
if (data.parent_address_postalcode)
|
||
|
|
$("#parent_address_postalcode").val(data.parent_address_postalcode);
|
||
|
|
if (data.parent_address_country)
|
||
|
|
$("#parent_address_country").val(data.parent_address_country);
|
||
|
|
if (data.invoice_type && data.invoice_type!='K')
|
||
|
|
$("#no_tax").attr('checked', true);
|
||
|
|
if (data.ecmpaymentcondition_id && data.ecmpaymentcondition_name) {
|
||
|
|
$("#ecmpaymentcondition_id").val(data.ecmpaymentcondition_id);
|
||
|
|
$("#ecmpaymentcondition_name").val(data.ecmpaymentcondition_name);
|
||
|
|
}
|
||
|
|
if (data.payment_date_days) {
|
||
|
|
$('#payment_date_days').val(data.payment_date_days);
|
||
|
|
$('#payment_date_days').trigger('change');
|
||
|
|
}
|
||
|
|
if (data.payment_method) {
|
||
|
|
$("#payment_method option[value=\""+data.payment_method+"\"]").attr('selected', 'selected');
|
||
|
|
}
|
||
|
|
if (data.currency_id) {
|
||
|
|
$("#currency_id option[value=\""+data.currency_id+"\"]").attr('selected', 'selected');
|
||
|
|
$("#currency_id").trigger('change');
|
||
|
|
}
|
||
|
|
//hide loading
|
||
|
|
$(".loading_panel").css("display", "none");
|
||
|
|
}
|
||
|
|
|
||
|
|
function createPricebookSelect(pricebooks) {
|
||
|
|
var s = $("<select id=\"pricebook_id\"/>");
|
||
|
|
var opt = '';
|
||
|
|
$.each(pricebooks, function(index, value) {
|
||
|
|
opt+='<option value="'+value.id+'">'+value.name+'</option>';
|
||
|
|
});
|
||
|
|
s.html(opt);
|
||
|
|
$("#pricebooks").append(s);
|
||
|
|
}
|
||
|
|
|
||
|
|
$.event.special.inputchange = {
|
||
|
|
setup: function() {
|
||
|
|
var self = this, val;
|
||
|
|
$.data(this, 'timer', window.setInterval(function() {
|
||
|
|
val = self.value;
|
||
|
|
if ( $.data( self, 'cache') != val ) {
|
||
|
|
$.data( self, 'cache', val );
|
||
|
|
$( self ).trigger( 'inputchange' );
|
||
|
|
}
|
||
|
|
}, 20));
|
||
|
|
},
|
||
|
|
teardown: function() {
|
||
|
|
window.clearInterval( $.data(this, 'timer') );
|
||
|
|
},
|
||
|
|
add: function() {
|
||
|
|
$.data(this, 'cache', this.value);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
function getCategoriesList() {
|
||
|
|
var params = {
|
||
|
|
job : 'getCategoriesList'
|
||
|
|
};
|
||
|
|
$.ajax({
|
||
|
|
type: "POST",
|
||
|
|
url: ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
success: function(data) {
|
||
|
|
var html = '<option value=""></option>';
|
||
|
|
$.each(data, function(index, value){
|
||
|
|
html+='<option value="'+value.id+'">'+value.name+'</option>';
|
||
|
|
$("#productSearchCategory").html(html);
|
||
|
|
});
|
||
|
|
},
|
||
|
|
data: params
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function createAccount() {
|
||
|
|
var parent_name = document.getElementById("parent_name");
|
||
|
|
var parent_id = document.getElementById("parent_id");
|
||
|
|
newAccount = window.open('index.php?module=Accounts&action=EditView&IamPopup=1', 'newAccount', 'toolbar=no,menubar=no,scrollbars=yes,scrollbars=1');
|
||
|
|
newAccount.parent_name = parent_name;
|
||
|
|
newAccount.parent_id = parent_id;
|
||
|
|
newAccount.focus();
|
||
|
|
}
|
||
|
|
|
||
|
|
function createProduct() {
|
||
|
|
var newProdId = document.getElementById("newProductId");
|
||
|
|
newProduct = window.open('index.php?module=EcmProducts&action=EditView&IamPopup=1', 'newProduct', 'toolbar=no,menubar=no,scrollbars=yes,scrollbars=1');
|
||
|
|
newProduct.newProdId = newProdId;
|
||
|
|
newProduct.focus();
|
||
|
|
}
|
||
|
|
|
||
|
|
function getBankAccounts(account_default_account) {
|
||
|
|
var params = {
|
||
|
|
job : 'getBankAccounts',
|
||
|
|
};
|
||
|
|
var html = '';
|
||
|
|
$.ajax({
|
||
|
|
type: "POST",
|
||
|
|
url: ajax_url,
|
||
|
|
dataType : "json",
|
||
|
|
success: function(data) {
|
||
|
|
$.each(data, function(index, value){
|
||
|
|
html+='<option value="'+value.NUMBER+'" onClick="$(\'#bankaccount\').val(\''+value.NUMBER+'\')"';
|
||
|
|
if (value.NUMBER == account_default_account) html+=' selected ';
|
||
|
|
html+='">'+value.NAME+' - '+value.NUMBER+'</option>';
|
||
|
|
});
|
||
|
|
$("#bankaccounts").html(html);
|
||
|
|
},
|
||
|
|
data: params
|
||
|
|
});
|
||
|
|
}
|