1013 lines
38 KiB
JavaScript
1013 lines
38 KiB
JavaScript
var itemsTable = 'itemsTable';
|
|
var items = new Array();
|
|
var displayArray = new Array();
|
|
var validation = new Object();
|
|
var shipping_addresses = new Array();
|
|
var searchedProducts = new Array();
|
|
var ajax_url = "index.php?module=EcmStockDocOuts&action=javahelper&to_pdf=1";
|
|
|
|
//add mz
|
|
// oo vat stuff
|
|
var account_vat_payer = false;
|
|
var oo_active = false;
|
|
|
|
// draw table
|
|
function DrawHeaders() {
|
|
var html = '<link rel="stylesheet" type="text/css" href="modules/EcmQuotes/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) {
|
|
//if(column.label=='Ceny')hide=' style="display: none"';
|
|
//else
|
|
var hide = '';
|
|
html += '<td width="' + column.width + '%"' + hide + '>' + 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>';
|
|
// sort? why not!
|
|
/*
|
|
* html += 'Sortowanie: '; html += '<select id="sort_field"
|
|
* onChange="sortTable();"'; html += '<option value=""></option>'; html += '<option
|
|
* value="name">Nazwa</option>'; html += '<option value="code">Kod</option>';
|
|
* html += '<option value="category">Kategoria</option>'; html += '<option
|
|
* value="category">Kategoria</option>'; html += '<option
|
|
* value="price">Cena po<br>upuście</option>'; html += '<option
|
|
* value="total">Wartość</option>'; html += '</select>';
|
|
*/
|
|
$('#' + itemsTable).html(html);
|
|
}
|
|
|
|
function setAddresses() {
|
|
if (shipping_addresses.length == 0)
|
|
return;
|
|
var s = $("<select id=\"shipping_addresses\"/>");
|
|
var opt = '<option value=""></option>';
|
|
$.each(shipping_addresses, function (index, value) {
|
|
|
|
opt += '<option value="' + index + '">' + value.name + '</option>';
|
|
});
|
|
s.html(opt);
|
|
$("#addresses").html("");
|
|
$("#addresses").append(s);
|
|
//set on change
|
|
$("#shipping_addresses").change(function () {
|
|
putShippingAddress($("#shipping_addresses option:selected").val());
|
|
});
|
|
}
|
|
|
|
function putShippingAddress(number) {
|
|
if (number == '') {
|
|
$("#shipping_address_name").val("");
|
|
$("#shipping_address_street").val("");
|
|
$("#shipping_address_postalcode").val("");
|
|
$("#shipping_address_city").val("");
|
|
$("#shipping_address_country").val("");
|
|
$("#shipping_iln").val("");
|
|
$("#shipping_nip").val("");
|
|
} else {
|
|
$("#shipping_address_name").val(shipping_addresses[number].name);
|
|
$("#shipping_address_street").val(shipping_addresses[number].street);
|
|
$("#shipping_address_postalcode").val(shipping_addresses[number].postalcode);
|
|
$("#shipping_address_city").val(shipping_addresses[number].city);
|
|
$("#shipping_address_country").val(shipping_addresses[number].country);
|
|
$("#shipping_iln").val(shipping_addresses[number].iln);
|
|
$("#shipping_nip").val(shipping_addresses[number].nip);
|
|
}
|
|
}
|
|
|
|
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
|
|
});
|
|
}
|
|
|
|
//insert parent info in fields
|
|
function setParentInfo(data) {
|
|
//pricebooks
|
|
|
|
if ($("#new_number").val() == false) return; //if edit exists load only pricebooks
|
|
if (data.vat_payer == '1')
|
|
account_vat_payer = true;
|
|
else
|
|
account_vat_payer = false;
|
|
if (data.name)
|
|
$("#parent_name_copy").val(data.name);
|
|
if (data.parent_nip)
|
|
$("#parent_nip").val(data.parent_nip);
|
|
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.name)
|
|
$("#parent_name").val(data.name);
|
|
if (data.ecmpaymentcondition_id && data.ecmpaymentcondition_name) {
|
|
$("#ecmpaymentcondition_id").val(data.ecmpaymentcondition_id);
|
|
$("#ecmpaymentcondition_name").val(data.ecmpaymentcondition_name);
|
|
}
|
|
if (data.ecmdeliverycondition_id && data.ecmdeliverycondition_name) {
|
|
$("#ecmdeliverycondition_id").val(data.ecmdeliverycondition_id);
|
|
$("#ecmdeliverycondition_name").val(data.ecmdeliverycondition_name);
|
|
}
|
|
|
|
if (data.currency_id)
|
|
$("#currency_id option[value=\"" + data.currency_id + "\"]").attr('selected', 'selected');
|
|
$.each(validation, function (index, value) {
|
|
validation.index = false;
|
|
});
|
|
//validation
|
|
if (data.document_recipient_code == '1')
|
|
validation.recipient_code = true;
|
|
if (data.document_parent_order_no == '1')
|
|
validation.parent_order_no = true;
|
|
if (data.document_delivery_address == '1')
|
|
validation.delivery_address = true;
|
|
if (data.document_parent_iln == '1')
|
|
validation.parent_iln = true;
|
|
if (data.document_shipping_iln == '1')
|
|
validation.shipping_iln = true;
|
|
if (data.document_parent_nip == '1')
|
|
validation.parent_nip = true;
|
|
if (data.document_shipping_nip == '1')
|
|
validation.shipping_nip = true;
|
|
setAccountValidation();
|
|
|
|
//clear prevoius validation data
|
|
shipping_addresses.length = 0; //clear array
|
|
shipping_addresses = data.addresses;
|
|
setAddresses();
|
|
//hide loading
|
|
$(".loading_panel").css("display", "none");
|
|
}
|
|
|
|
/*
|
|
function unsetAllCheckboxes() {
|
|
$("#searchResultDiv input[type=checkbox]").each(function() {
|
|
$(this).prop("checked", false);
|
|
});
|
|
}
|
|
*/
|
|
function setAccountValidation() {
|
|
//first clear validation
|
|
removeFromValidate('EditView', 'parent_order_no');
|
|
removeFromValidate('EditView', 'parent_shipping_address_name');
|
|
removeFromValidate('EditView', 'parent_shipping_address_street');
|
|
removeFromValidate('EditView', 'parent_shipping_address_postalcode');
|
|
removeFromValidate('EditView', 'parent_shipping_address_city');
|
|
removeFromValidate('EditView', 'parent_iln');
|
|
removeFromValidate('EditView', 'shipping_iln');
|
|
|
|
//now add what we need
|
|
if (validation.parent_order_no == true)
|
|
addToValidate('EditView', 'parent_document_no', 'id', 'true', '');
|
|
if (validation.parent_order_no == true)
|
|
addToValidate('EditView', 'parent_document_no', 'id', 'true', '');
|
|
if (validation.delivery_address == true) {
|
|
addToValidate('EditView', 'shipping_address_name', 'id', 'true', '');
|
|
addToValidate('EditView', 'shipping_address_street', 'id', 'true', '');
|
|
addToValidate('EditView', 'shipping_address_postalcode', 'id', 'true', '');
|
|
addToValidate('EditView', 'shipping_address_city', 'id', 'true', '');
|
|
}
|
|
if (validation.parent_iln == true)
|
|
addToValidate('EditView', 'parent_iln', 'id', 'true', '');
|
|
if (validation.shipping_iln == true)
|
|
addToValidate('EditView', 'shipping_iln', 'id', 'true', '');
|
|
if (validation.parent_nip == true)
|
|
addToValidate('EditView', 'parent_nip', 'id', 'true', '');
|
|
if (validation.shipping_nip == true)
|
|
addToValidate('EditView', 'shipping_nip', 'id', 'true', '');
|
|
}
|
|
|
|
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;
|
|
});
|
|
for (var key in products) {
|
|
var params = {
|
|
job: 'getProduct',
|
|
id: key,
|
|
stockId: $("#stock_id :selected").val(),
|
|
};
|
|
$.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.unit_name = data.unit_name;
|
|
p.unit_id = data.unit_id;
|
|
p.stock_state = data.stock_state;
|
|
p.product_category_id = data.product_category_id;
|
|
p.product_precision = data.unit_precision;
|
|
p.unit_precision = data.unit_precision;
|
|
p.product_is_consignment = data.is_consignment;
|
|
p.ecmvat_id = data.vat_id;
|
|
p.ecmvat_name = data.vat_name;
|
|
p.ecmvat_value = data.vat_value;
|
|
p.product_is_oo = data.OO;
|
|
p.product_pieces_per_carton = data.pieces_per_carton;
|
|
p.un_code = data.un_code;
|
|
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,
|
|
stockId: $("#stock_out_id :selected").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.vat_id;
|
|
items[index].ecmvat_value = data.vat_value;
|
|
items[index].ecmvat_name = data.vat_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].product_is_consignment = data.is_consignment;
|
|
items[index].price_start = data.price_start;
|
|
items[index].recipient_code = data.recipient_code;
|
|
items[index].product_precision = data.unit_precision;
|
|
items[index].unit_precision = data.unit_precision;
|
|
items[index].product_is_oo = data.OO;
|
|
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 getItems(editview) {
|
|
var record = '';
|
|
if ($("#duplicate").val() == true)
|
|
record = $("input[name='return_id']").val();
|
|
else
|
|
record = $("input[name='record']").val();
|
|
if (isNaN(editview))
|
|
editview = true;
|
|
var params = {
|
|
job: 'getItems',
|
|
record: record,
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
success: function (data) {
|
|
items = data;
|
|
if (editview)
|
|
FillTable(items, false);
|
|
else {
|
|
FillTable(items, true);
|
|
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
|
for (var index = 0; index != count; index++) {
|
|
if (items[index].product_is_consignment) {
|
|
$('#product_code_' + index).parent().append($("<p>" + items[index].part_no + "</p>"));
|
|
}
|
|
}
|
|
}
|
|
$(".loading_panel").css("display", "none");
|
|
},
|
|
data: params
|
|
});
|
|
}
|
|
|
|
function getItemsFromEcmSale(editview) {
|
|
var record = '';
|
|
if ($("#duplicate").val() == true)
|
|
record = $("input[name='return_id']").val();
|
|
else
|
|
record = $("input[name='ecmsale_id']").val();
|
|
if (isNaN(editview))
|
|
editview = true;
|
|
var params = {
|
|
job: "getItemsFromEcmSale",
|
|
record: record,
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
success: function (data) {
|
|
items = data.filter(x => x.product_ks_group !== '3'); // remove services
|
|
window.console.log(items);
|
|
if (editview)
|
|
FillTable(items, false);
|
|
else
|
|
FillTable(items, true);
|
|
$(".loading_panel").css("display", "none");
|
|
},
|
|
data: params
|
|
});
|
|
}
|
|
|
|
function calculateTotal() {
|
|
var count = items.length;
|
|
var vats = new Array();
|
|
var all_subtotal = 0;
|
|
var all_total = 0;
|
|
var sum_vats = 0;
|
|
var sum_discounts = 0;
|
|
var sum_oo = 0;
|
|
var total_quantity = 0;
|
|
if (account_vat_payer == true) {
|
|
if (oo_active == false) {
|
|
oo_active = true;
|
|
manageOO();
|
|
}
|
|
} else {
|
|
if (oo_active == true) {
|
|
oo_active = false;
|
|
manageOO();
|
|
}
|
|
}
|
|
for (var index = 0; index != count; index++) {
|
|
subtotal = UnformatNumber($('#total_netto_' + index).val());
|
|
vat_val = UnformatNumber($('#total_vat_' + index).val());
|
|
total = subtotal + vat_val;
|
|
total_quantity += UnformatNumber($('#quantity_' + index).val());
|
|
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;
|
|
|
|
}
|
|
all_total = all_subtotal + sum_vats;
|
|
|
|
// 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) + ':' + ',';
|
|
}
|
|
}
|
|
html += '<tr><td class="positionsLabel">Ilość razem</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(total_quantity) + '"></td></tr>';
|
|
|
|
DrawSummary(html);
|
|
$('#total_vat').val(FormatNumber(sum_vats));
|
|
$('#total_quantity').val(FormatNumber(total_quantity));
|
|
$("#t_netto").val(FormatNumber(all_subtotal));
|
|
$("#t_brutto").val(FormatNumber(all_total));
|
|
$("#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;
|
|
//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 ($('#product_is_oo_' + index).val() != '1') continue;
|
|
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);
|
|
}
|
|
calculateTotal();
|
|
}
|
|
|
|
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 += 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 DrawDetailSummary() {
|
|
$("#result_table").html('');
|
|
html = '';
|
|
html += '<tr id="total_quantity_tr"> ';
|
|
html += '<td class="positionsLabel" style="border-top:0px;">Razem ilość</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="total_quantity" id="total_quantity"value=\''
|
|
+ FormatNumber($("#doc_total_quantity").val()) + '\'></td>';
|
|
html += '</tr>';
|
|
html += '<tr id="subtotal_tr">';
|
|
html += '<td class="positionsLabel" style="border-top:0px;">Suma dokumentu</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=\''
|
|
+ $("#doc_total").val() + '\'></td>';
|
|
html += '</tr>';
|
|
html += '<tr id="discount_tr">';
|
|
html += '<td class="positionsLabel">Suma operacji: wyjście</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=\''
|
|
+ $("#operations_out").val() + '\'></td>';
|
|
html += '</tr>';
|
|
$("#result_table").html(html);
|
|
}
|
|
|
|
function generateNumber() {
|
|
var params = {
|
|
job: 'generateNumber',
|
|
stock_id: $("#stock_id").val(),
|
|
date: $("#register_date").val(),
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
success: function (data) {
|
|
if (data == '-1') {
|
|
// try loading again
|
|
generateNumber();
|
|
} else {
|
|
$("#document_no").val(data.document_no);
|
|
$("#number").val(data.number);
|
|
$(".loading_panel").css("display", "none");
|
|
}
|
|
},
|
|
data: params
|
|
});
|
|
}
|
|
|
|
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 refreshStock(index) {
|
|
var params = {
|
|
job: 'getStockState',
|
|
id: $("#product_id_" + index).val(),
|
|
stockId: $("#stock_id").val(),
|
|
};
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
$("#stock_state_" + index).val(FormatNumber(data, $("#product_precision_" + index).val()));
|
|
},
|
|
data: params
|
|
});
|
|
}
|
|
|
|
function refreshAllStocks(ids) {
|
|
return new Promise((resolve) => {
|
|
var params = {
|
|
job: "getStockStates",
|
|
ids: ids.join("|"),
|
|
stockId: $("#stock_id").val(),
|
|
};
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
resolve(data);
|
|
},
|
|
data: params
|
|
});
|
|
});
|
|
}
|
|
|
|
function setRowDate(index) {
|
|
var qty = UnformatNumber($("#quantity_" + index).val());
|
|
items[index].quantity = qty;
|
|
}
|
|
|
|
async function checkProducts() {
|
|
$(".loading_panel").css("display", "block");
|
|
//var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
|
var count = items.length;
|
|
var ids = [];
|
|
for (var index = 0; index != count; index++) {
|
|
var id = $("#product_id_" + index).val();
|
|
if (id !== "") {
|
|
ids.push(id);
|
|
}
|
|
}
|
|
var states = [];
|
|
if (ids.length > 0) {
|
|
states = await refreshAllStocks(ids);
|
|
}
|
|
var error = false; // hope :)
|
|
for (var index = 0; index != count; index++) {
|
|
if ($("#product_id_" + index).val() != '') {
|
|
var prodId = $("#product_id_" + index).val();
|
|
var state = states.find(x => x.id === prodId);
|
|
if (state) {
|
|
$("#stock_state_" + index).val(FormatNumber(state.state, $("#product_precision_" + index).val()));
|
|
} else {
|
|
$("#stock_state_" + index).val(FormatNumber(0, $("#product_precision_" + index).val()));
|
|
}
|
|
//refreshStock(index);
|
|
var qty = UnformatNumber($("#quantity_" + 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;
|
|
}
|
|
var stock = UnformatNumber($("#stock_state_" + index).val());
|
|
if (qty > 0 && qty <= part_qty && qty <= stock) {
|
|
$("#quantity_" + index).css("color", "black");
|
|
} else {
|
|
error = true;
|
|
$("#quantity_" + index).css("color", "red");
|
|
}
|
|
}
|
|
}
|
|
$(".loading_panel").css("display", "none");
|
|
if (error) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function getComponents(index) {
|
|
$(".loading_panel").css("display", "block");
|
|
var product_id = items[index].product_id;
|
|
var qty = items[index].quantity;
|
|
//var price = items[index].price;
|
|
|
|
var params = {
|
|
job: 'getComponents',
|
|
product_id: product_id,
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
if (data.length > 0) {
|
|
items.splice(index, 1);
|
|
$.each(data, function (index, value) {
|
|
var p = new Object();
|
|
p.product_id = value.id;
|
|
p.name = value.name;
|
|
p.product_code = value.code;
|
|
p.unit_name = value.unit_name;
|
|
p.unit_id = value.unit_id;
|
|
p.quantity = qty * parseInt(value.quantity);
|
|
p.product_category_id = value.product_category_id;
|
|
|
|
if (p.product_category_id == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
|
|
return;
|
|
items.push(p);
|
|
});
|
|
}
|
|
;
|
|
},
|
|
data: params
|
|
});
|
|
FillTable(items);
|
|
$(".loading_panel").css("display", "none");
|
|
}
|
|
|
|
function getPricesInfo(index) {
|
|
$("#price_start_div_" + index).show('slow');
|
|
$("#price_start_div_" + index).html(
|
|
'<img src="modules/EcmQuotes/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('
|
|
+ value.price
|
|
+ '); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
|
+ index
|
|
+ ');"><b>'
|
|
+ value.name
|
|
+ ': '
|
|
+ FormatNumber(value.price)
|
|
+ '</b></li>';
|
|
} else {
|
|
if (value.visible == '1') {
|
|
html += '<li style="cursor:pointer;" onClick="$(\'#price_start_'
|
|
+ index
|
|
+ '\').val('
|
|
+ value.price
|
|
+ '); $(this).closest(\'div\').hide(\'slow\');calculateRow('
|
|
+ index
|
|
+ ');">'
|
|
+ value.name
|
|
+ ': ';
|
|
if (value.module == 'EcmPrices') {
|
|
html += '<font style="color:#7FFF00;">' + FormatNumber(value.price) + '</font>';
|
|
}
|
|
if (value.module == 'EcmInvoiceOuts') {
|
|
html += '<font style="color:#FF3333;">' + FormatNumber(value.price) + '</font>';
|
|
}
|
|
html + '</li>';
|
|
}
|
|
}
|
|
});
|
|
html += '</ul>';
|
|
},
|
|
data: params
|
|
});
|
|
$("#price_start_div_" + index).html(html);
|
|
}
|
|
|
|
function calculateRow(index) {
|
|
if (index == -1)
|
|
return;
|
|
// liczone według najlepszych zasad księgowości
|
|
var price_netto = UnformatNumber($('#price_netto_' + index).val());
|
|
var vat_value = $('#ecmvat_value_' + index).val();
|
|
var quantity = UnformatNumber($('#quantity_' + index).val());
|
|
var precision = UnformatNumber($('#product_precision_' + index).val());
|
|
|
|
var total_netto = price_netto * quantity;
|
|
// 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_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].ecmvat_id = $('#ecmvat_id_' + index).val();
|
|
items[index].ecmvat_name = $('#ecmvat_name_' + index).val();
|
|
items[index].ecmvat_value = vat_value;
|
|
|
|
// change name or language?
|
|
items[index].name = htmlEscape($('#name_' + index).val());
|
|
items[index].part_no = htmlEscape($('#part_no_' + index).val());
|
|
items[index].un_code = htmlEscape($('#un_code_' + index).val());
|
|
|
|
calculateTotal();
|
|
|
|
//update cartons
|
|
var pieces_per_carton = UnformatNumber($('#product_pieces_per_carton_' + index).val());
|
|
var cartons = 0;
|
|
if (pieces_per_carton > 0) {
|
|
cartons = Math.ceil(quantity / pieces_per_carton);
|
|
}
|
|
$('#product_cartons_' + index).val(FormatNumber(cartons, 2));
|
|
items[index].product_pieces_per_carton = toFixed(pieces_per_carton, 2);
|
|
items[index].product_cartons = toFixed(cartons, 2);
|
|
}
|
|
|
|
function updatePartNo(index) {
|
|
items[index].part_no = $('#part_no_' + index).val();
|
|
}
|
|
|
|
function updateUnCode(index) {
|
|
console.log('UN', index);
|
|
items[index].un_code = $('#un_code_' + index).val();
|
|
}
|
|
|
|
function getSearchInfo2(product_id, product_code) {
|
|
$("#search_info_div2_" + product_id).show().draggable();
|
|
var html = '<img style="cursor: pointer;" align="left" src="themes/Sugar/images/close_inline.gif" onClick="$(\'#search_info_div2_'
|
|
+ product_id
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<a href="index.php?module=EcmProducts&action=DetailView&record='
|
|
+ product_id + '" target="_blank">' + product_code + '</a><br><br>';
|
|
html += '<table><tr><td style="text-align:left;">Magazyn</td><td>Ilość</td></tr>';
|
|
var params = {
|
|
job: 'getStockArray',
|
|
product_id: product_id,
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
$.each(data, function (key, value) {
|
|
html += '<tr><td style="text-align:left;">' + key + '</td><td>' + FormatNumber(value)
|
|
+ '</td></tr>';
|
|
});
|
|
},
|
|
data: params
|
|
});
|
|
html += '</table>';
|
|
|
|
$("#search_info_div2_" + product_id).html(html);
|
|
}
|
|
|
|
function getSearchInfo(product_id, product_code) {
|
|
$("#search_info_div_" + product_id).show().draggable();
|
|
var html = '<img style="cursor: pointer;" align="left" src="themes/Sugar/images/close_inline.gif" onClick="$(\'#search_info_div_'
|
|
+ product_id
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<a href="index.php?module=EcmProducts&action=DetailView&record='
|
|
+ product_id + '" target="_blank">' + product_code + '</a><br><br>';
|
|
// get prices info
|
|
html += '<table><tr><td style="text-align:left;">Nazwa</td><td>Ilość</td><td>Cena</td><td>Data dok</td></tr>';
|
|
var params = {
|
|
job: 'getPricesInfo',
|
|
product_id: product_id,
|
|
pricebook_id: $("#pricebook_id :selected").val(),
|
|
account_id: $("#parent_id").val(),
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
$.each(data, function (key, value) {
|
|
if (value.name == 'pricebook')
|
|
html += $("#pricebook_id :selected").html() + ': '
|
|
+ FormatNumber(value.price) + '<br>';
|
|
if (value.name == $("#ecmprice_name").val())
|
|
html += '<b>' + value.name + ': '
|
|
+ FormatNumber(value.price) + '</b><br>';
|
|
else if (value.module == 'EcmStockDocIns') {
|
|
html += '<tr><td style="text-align:left;">' + value.name + '</td><td>' + value.quantity + '</td><td> <font style="color:#7FFF00;text-align:right;">' + FormatNumber(value.price) + '</font></td><td>' + value.register_date + '</td></tr>';
|
|
}
|
|
//html += value.name + ': ' + FormatNumber(value.price)
|
|
// + '<br>';
|
|
});
|
|
},
|
|
data: params
|
|
});
|
|
html += '</tr></table>';
|
|
|
|
$("#search_info_div_" + product_id).html(html);
|
|
}
|
|
|
|
function getSearchInfo3(product_id, product_code) {
|
|
$("#search_info_div3_" + product_id).show().draggable();
|
|
var html = '<img style="cursor: pointer;" align="left" src="themes/Sugar/images/close_inline.gif" onClick="$(\'#search_info_div3_'
|
|
+ product_id
|
|
+ '\').hide(\'slow\')"/>';
|
|
html += '<a href="index.php?module=EcmProducts&action=DetailView&record='
|
|
+ product_id + '" target="_blank">' + product_code + '</a><br><br>';
|
|
// get prices info
|
|
html += '<table><tr><td style="text-align:left;">Nazwa</td><td>Cena</td></tr>';
|
|
var params = {
|
|
job: 'getPricesInfo',
|
|
product_id: product_id,
|
|
pricebook_id: $("#pricebook_id :selected").val(),
|
|
account_id: $("#parent_id").val(),
|
|
};
|
|
$.ajax({
|
|
type: "POST",
|
|
url: ajax_url,
|
|
dataType: "json",
|
|
async: false,
|
|
success: function (data) {
|
|
$.each(data, function (key, value) {
|
|
if (value.name == 'pricebook')
|
|
html += $("#pricebook_id :selected").html() + ': '
|
|
+ FormatNumber(value.price) + '<br>';
|
|
if (value.name == $("#ecmprice_name").val())
|
|
html += '<b>' + value.name + ': '
|
|
+ FormatNumber(value.price) + '</b><br>';
|
|
else if (value.module == 'EcmPrices') {
|
|
html += '<tr><td style="text-align:left;">' + value.name + ':</td><td> <font style="color:#7FFF00;text-align:right;">' + FormatNumber(value.price) + '</font></td></tr>';
|
|
}
|
|
if (value.module == 'EcmInvoiceOuts') {
|
|
html += '<tr><td "text-align:left;">' + value.name + ':</td><td> <font style="color:#FF3333;text-align:right;">' + FormatNumber(value.price) + '</font></td></tr>';
|
|
}
|
|
//html += value.name + ': ' + FormatNumber(value.price)
|
|
// + '<br>';
|
|
});
|
|
},
|
|
data: params
|
|
});
|
|
html += '</table>';
|
|
|
|
$("#search_info_div3_" + product_id).html(html);
|
|
}
|
|
/*
|
|
$.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 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 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();
|
|
}
|
|
|
|
// sortable rows in main table
|
|
//$("#" + itemsTable + " tbody").sortable();
|