Allegro returns - KS document

This commit is contained in:
Michał Zieliński
2025-05-29 17:43:29 +02:00
parent 204334acd6
commit 35632037d7
14 changed files with 881 additions and 526 deletions

View File

@@ -7,24 +7,24 @@ var ajax_url = "index.php?module=EcmStockDocCorrects&action=javahelper&to_pdf=1"
//custom Fill Table
function calculateAll() {
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++) {
calculateRow(index);
}
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++) {
calculateRow(index);
}
}
function calculateRow(index) {
if (index == -1)
return;
items[index].quantity_consignment_id = $('#quantity_consignment_id_'+index).val();
items[index].quantity_consignment_doc = $('#quantity_consignment_doc_'+index).val();
if($('#type').val()!='8a6b804b-fac7-5cc2-de19-54c209116b19'){
items[index].quantity_consignment_id = $('#quantity_consignment_id_' + index).val();
items[index].quantity_consignment_doc = $('#quantity_consignment_doc_' + index).val();
if ($('#type').val() != '8a6b804b-fac7-5cc2-de19-54c209116b19') {
getConsignmentsDiv(index);
} else {
getInsertConsignmentsDiv(index);
}
// liczone według najlepszych zasad księgowości
var price = UnformatNumber($('#price_' + index).val());
var price_old = UnformatNumber($('#price_old_' + index).val());
@@ -33,7 +33,7 @@ function calculateRow(index) {
//alert(palet);
var total = price * quantity;
var total2 = price_old * quantity;
var total2 = price_old * quantity;
// put data
$('#product_total_' + index).val(FormatNumber(total));
@@ -46,66 +46,66 @@ var total2 = price_old * quantity;
items[index].name = $('#name_' + index).val();
items[index].unit_name = $('#unit_name_' + index).val();
if($('#type').val()=='6ed5b076-ddd1-9809-b236-54e5b2bcbd97'){
$('#onlyRemoveDif_'+index).remove();
$('#unit_name_'+index).parent().append('<div id="onlyRemoveDif_'+index+'"><p style="text-align:right">(Różnica: '+FormatNumber(total-total2)+')<input type="hidden" id="diff_this_'+index+'" value="'+FormatNumber(total-total2)+'"></p></div>');
}
if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
$('#onlyRemoveDif_' + index).remove();
$('#unit_name_' + index).parent().append('<div id="onlyRemoveDif_' + index + '"><p style="text-align:right">(Różnica: ' + FormatNumber(total - total2) + ')<input type="hidden" id="diff_this_' + index + '" value="' + FormatNumber(total - total2) + '"></p></div>');
}
// calculate total
calculateTotal();
}
function calculateTotal() {
if($('#type').val()=='6ed5b076-ddd1-9809-b236-54e5b2bcbd97'){
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
count = items.length;
var vats = new Array();
var all_subtotal = 0;
var all_total = 0;
var sum_vats = 0;
var sum_discounts = 0;
var weight_total=0;
for (var index = 0; index != count; index++) {
subtotal = UnformatNumber($('#diff_this_' + index).val());
if(!isNaN(subtotal)){
all_subtotal += subtotal;
if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
count = items.length;
var vats = new Array();
var all_subtotal = 0;
var all_total = 0;
var sum_vats = 0;
var sum_discounts = 0;
var weight_total = 0;
for (var index = 0; index != count; index++) {
subtotal = UnformatNumber($('#diff_this_' + index).val());
if (!isNaN(subtotal)) {
all_subtotal += subtotal;
}
}
all_total = all_subtotal;
}
all_total = all_subtotal;
DrawSummary();
DrawSummary();
$("#t_netto").val(FormatNumber(all_total));
} else {
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
count = items.length;
var vats = new Array();
var all_subtotal = 0;
var all_total = 0;
var sum_vats = 0;
var sum_discounts = 0;
var weight_total = 0;
for (var index = 0; index != count; index++) {
subtotal = UnformatNumber($('#product_total_' + index).val());
if (!isNaN(subtotal)) {
all_subtotal += subtotal;
}
$("#t_netto").val(FormatNumber(all_total));
} else {
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
count = items.length;
var vats = new Array();
var all_subtotal = 0;
var all_total = 0;
var sum_vats = 0;
var sum_discounts = 0;
var weight_total=0;
for (var index = 0; index != count; index++) {
subtotal = UnformatNumber($('#product_total_' + index).val());
if(!isNaN(subtotal)){
all_subtotal += subtotal;
}
all_total = all_subtotal;
DrawSummary();
$("#t_netto").val(FormatNumber(all_total));
}
all_total = all_subtotal;
DrawSummary();
$("#t_netto").val(FormatNumber(all_total));
}
}
function DrawSummary() {
$("#result_table").html('');
@@ -121,19 +121,19 @@ function DrawSummary() {
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">';
+ itemsTable + 'DIV">';
html += '<table class="positions" style="width:100%;" id="' + itemsTable
+ '_T">';
+ '_T">';
html += '<thead id="head">';
html += '<tr id="tr">';
// draw columns headers
$.each(columns, function(index, column) {
if(column.hide=='yes'){
hide='display:none;'
$.each(columns, function (index, column) {
if (column.hide == 'yes') {
hide = 'display:none;'
} else {
hide='';
hide = '';
}
html += '<td width="' + column.width + '%" style="'+hide+'">' + column.label + '</td>';
html += '<td width="' + column.width + '%" style="' + hide + '">' + column.label + '</td>';
});
html += '</tr></thead><tbody></tbody></table>';
html += '</div><br>';
@@ -255,23 +255,23 @@ function addProducts() {
$(".loading_panel").css("display", "block");
clearEmpty();
var products = new Array();
$.each(searchedProducts, function(index, value) {
$.each(searchedProducts, function (index, value) {
if ($('#prod_' + value).is(':checked'))
products[value] = true;
});
var stockId=$("#stock_id").val();
for ( var key in products) {
var stockId = $("#stock_id").val();
for (var key in products) {
var params = {
job : 'getProduct',
id : key,
stockId : stockId,
job: 'getProduct',
id: key,
stockId: stockId,
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
async : false,
success : function(data) {
type: "POST",
url: ajax_url,
dataType: "json",
async: false,
success: function (data) {
if (data != '-1') {
var p = new Object();
p.product_id = data.id;
@@ -285,18 +285,17 @@ function addProducts() {
p.ecmvat_name = data.ecmvat_name;
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_precision = data.unit_precision;
p.unit_precision = data.unit_precision;
p.product_is_consignment = data.is_consignment;
if ($("#searchInputQty").val() != ''
&& !isNaN(parseFloat(UnformatNumber($(
"#searchInputQty").val()))))
&& !isNaN(parseFloat(UnformatNumber($(
"#searchInputQty").val()))))
p.quantity = $("#searchInputQty").val();
items.push(p);
console.log(p);
}
},
data : params
data: params
});
}
AddSearchRecord();
@@ -310,61 +309,61 @@ function addProducts() {
$(".loading_panel").css("display", "none");
}
function AddProduct(index,record){
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_id").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].stock_state = data.stock_state;
items[index].product_precision = data.unit_precision;
items[index].unit_precision = data.unit_precision;
items[index].product_is_consignment = data.is_consignment;
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
});
var params = {
job: 'getProduct',
id: record,
stockId: $("#stock_id").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].stock_state = data.stock_state;
items[index].product_precision = data.unit_precision;
items[index].unit_precision = data.unit_precision;
items[index].product_is_consignment = data.is_consignment;
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);
calculateAll();
$('#searchResultDiv').html('');
$(".loading_panel").css("display", "none");
$("#quantity_"+index).focus().select();
$("#quantity_" + index).focus().select();
}
function getItems(editview) {
@@ -376,29 +375,29 @@ function getItems(editview) {
if (isNaN(editview))
editview = true;
var params = {
job : 'getItems',
record : record,
job: 'getItems',
record: record,
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
success : function(data) {
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
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++) {
if (items[index].product_consignment_doc) {
$('#product_code_'+index).parent().append($( "<p>"+items[index].product_consignment_doc+"</p>" ));
$('#product_code_' + index).parent().append($("<p>" + items[index].product_consignment_doc + "</p>"));
}
}
}
$(".loading_panel").css("display", "none");
},
data : params
data: params
});
}
@@ -408,22 +407,22 @@ function DrawDetailSummary() {
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>';
+ $("#doc_total").val() + '\'></td>';
html += '</tr>';
$("#result_table").html(html);
}
function generateNumber() {
var params = {
job : 'generateNumber',
job: 'generateNumber',
stock: $("#stock_id").val(),
date : $("#register_date").val(),
date: $("#register_date").val(),
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
success : function(data) {
type: "POST",
url: ajax_url,
dataType: "json",
success: function (data) {
if (data == '-1') {
// try loading again
generateNumber();
@@ -433,56 +432,96 @@ function generateNumber() {
$(".loading_panel").css("display", "none");
}
},
data : params
data: params
});
}
function getCategoriesList() {
var params = {
job : 'getCategoriesList'
job: 'getCategoriesList'
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
success : function(data) {
type: "POST",
url: ajax_url,
dataType: "json",
success: function (data) {
var html = '<option value=""></option>';
$.each(data, function(index, value) {
$.each(data, function (index, value) {
html += '<option value="' + value.id + '">' + value.name
+ '</option>';
+ '</option>';
$("#productSearchCategory").html(html);
});
},
data : params
data: params
});
}
function refreshStock(index) {
var params = {
job : 'getStockState',
id : $("#product_id_" + index).val(),
stockId : $("#stock_id").val(),
job: 'getStockState',
id: $("#product_id_" + index).val(),
stockId: $("#stock_id").val(),
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
async : false,
success : function(data) {
type: "POST",
url: ajax_url,
dataType: "json",
async: false,
success: function (data) {
$("#stock_state_" + index).val(FormatNumber(data));
},
data : params
data: params
});
}
function checkProducts() {
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
});
});
}
async function checkProducts() {
//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()!=''){
refreshStock(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 con_qty = $("#product_consignment_qty_" + index).val();
@@ -491,17 +530,17 @@ function checkProducts() {
var price_old = UnformatNumber($("#price_old_" + index).val());
// refresh items array
items[index].quantity = qty;
if ($('#product_is_consignment_' + index).val() != '1' && $('#product_consignment_id_' + index).val()=='' ) {
con_qty=stock;
if ($('#product_is_consignment_' + index).val() != '1' && $('#product_consignment_id_' + index).val() == '') {
con_qty = stock;
}
items[index].price = UnformatNumber($("#price_" + index).val());
// przecena
if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
if($('#product_consignment_id_' + index).val()==''){
error=true;
if ($('#product_consignment_id_' + index).val() == '') {
error = true;
alert("Można przecenić tylko konkretną pozycje!");
}
if(qty<=0 || qty<con_qty || price_new==price_old || price_new<=0){
if (qty <= 0 || qty < con_qty || price_new == price_old || price_new <= 0) {
error = true;
$("#quantity_" + index).css("color", "red");
@@ -510,10 +549,9 @@ function checkProducts() {
}
}
// korekta minus
console.log(qty+' '+con_qty+' '+Math.abs(qty));
if ($('#type').val() == '7bb903d0-c296-7d1b-6e50-54c209e30850') {
if(qty>=0 || Math.abs(qty)>con_qty){
if (qty >= 0 || Math.abs(qty) > con_qty) {
error = true;
$("#quantity_" + index).css("color", "red");
@@ -523,7 +561,7 @@ function checkProducts() {
}
// korekta plus
if ($('#type').val() == '8a6b804b-fac7-5cc2-de19-54c209116b19') {
if(qty<=0 || price_new<=0){
if (qty <= 0 || price_new <= 0) {
error = true;
$("#quantity_" + index).css("color", "red");
@@ -547,18 +585,18 @@ function getComponents(index) {
//var price = items[index].price;
var params = {
job : 'getComponents',
product_id : product_id,
job: 'getComponents',
product_id: product_id,
};
$.ajax({
type : "POST",
url : ajax_url,
dataType : "json",
async : false,
success : function(data) {
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) {
$.each(data, function (index, value) {
var p = new Object();
p.product_id = value.id;
p.name = value.name;
@@ -568,17 +606,17 @@ function getComponents(index) {
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')
if (p.product_category_id == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
return;
items.push(p);
});
};
},
data : params
data: params
});
FillTable(items);
//getConsignmentsDiv(index);
//getConsignmentsDiv(index);
$(".loading_panel").css("display", "none");
}