Current Module
This commit is contained in:
@@ -0,0 +1,814 @@
|
||||
/*
|
||||
* 2021 Keshva
|
||||
*
|
||||
* @author Keshva <keshvathakur47@gmail.com>
|
||||
* @copyright 2021 Keshva
|
||||
*/
|
||||
|
||||
var priceDisplayPrecision = 2;
|
||||
var isPopoverActive = false;
|
||||
var isStoring = false;
|
||||
var lastChangedShippingCostType = 'taxExcl';
|
||||
|
||||
$(document).ready(function() {
|
||||
if (typeof id_order === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
displayResendMailButton();
|
||||
initOrderDateAndNumber();
|
||||
initDocumentsTable();
|
||||
initOrderNote();//treba spravit
|
||||
initShipping();
|
||||
initOrderPayment();
|
||||
initDeleteStatuses();
|
||||
initProductLine();
|
||||
initEvents();
|
||||
|
||||
$(document).on("ajaxComplete", function(event, xhr, settings) {
|
||||
setTimeout(function() {
|
||||
initDocumentsTable();
|
||||
initShipping();
|
||||
initDeleteStatuses();
|
||||
initProductLine();
|
||||
}, 1000)
|
||||
});
|
||||
|
||||
// updateInvoice(invoices);
|
||||
});
|
||||
|
||||
function displayResendMailButton() {
|
||||
if ($("#orderResendMail").length == 0) {
|
||||
$("#order-view-page .order-actions .order-actions-print").after('<a id="orderResendMail" onclick="ajaxResendMailToCustomer()" class="btn btn-default" href="javascript:void(0)"><i class="material-icons" aria-hidden="true">print</i>' + trans.resend_email + '</a>');
|
||||
}
|
||||
}
|
||||
|
||||
function initOrderDateAndNumber() {
|
||||
//datum objednavky
|
||||
titleRowParentPath = '#main-div ';
|
||||
if ($('#main-div .title-row').length == 0) {
|
||||
titleRowParentPath = '';
|
||||
}
|
||||
$(titleRowParentPath + '.title-row:eq(0) p:eq(1) .text-muted').contents().unwrap();
|
||||
generatePopover($(titleRowParentPath + '.title-row:eq(0) p:eq(1)'), 0, null, 'OrderDate', {'type' : 'datetime'});
|
||||
|
||||
//cislo objednavky
|
||||
generatePopover($(titleRowParentPath + '.title-row:eq(0) h1 strong:eq(1)'), 0, null, 'OrderNumber', {'type': 'input'});
|
||||
}
|
||||
|
||||
// tabulka dokumentov - faktura, dodaci list, dobropisy
|
||||
function initDocumentsTable() {
|
||||
$('#orderDocumentsTabContent table tbody tr td a[href]').each(function() {
|
||||
if ($(this).attr('href').indexOf('generateInvoicePDF') >= 0 && !$(this).parents('tr:eq(0)').hasClass('trInvoice')) {
|
||||
$(this).parents('tr:eq(0)').addClass('trInvoice');
|
||||
}
|
||||
if ($(this).attr('href').indexOf('generateDeliverySlipPDF') >= 0 && !$(this).parents('tr:eq(0)').hasClass('trDeliverySlip')) {
|
||||
$(this).parents('tr:eq(0)').addClass('trDeliverySlip');
|
||||
}
|
||||
if ($(this).attr('href').indexOf('generateOrderSlipPDF') >= 0 && !$(this).parents('tr:eq(0)').hasClass('trOrderSlip')) {
|
||||
$(this).parents('tr:eq(0)').addClass('trOrderSlip');
|
||||
}
|
||||
});
|
||||
if ($('#orderDocumentsTabContent table thead tr .removeDocument').length == 0) {
|
||||
$('#orderDocumentsTabContent table thead tr').append('<th class="removeDocument"></th>');
|
||||
}
|
||||
$('#orderDocumentsTabContent table tbody tr').each(function() {
|
||||
if ($(this).hasClass('trInvoice') && $(this).find('.show-popover').length == 0) {
|
||||
//prvy stlpec na fakture - datum faktury
|
||||
generatePopover($(this).find('td:eq(0)'), queryString($(this).find('a').attr('href')).id_order_invoice, null, 'InvoiceDate', {'type' : 'date'});
|
||||
//treti stlpec na fakture - cislo faktury
|
||||
generatePopover($(this).find('td:eq(2)'), queryString($(this).find('a').attr('href')).id_order_invoice, $(this).find('td:eq(2)').find('a'), 'InvoiceNumber', {'type' : 'input'});
|
||||
addRemoveButtonOnDocument($(this), 'Invoice', queryString($(this).find('a').attr('href')).id_order_invoice);
|
||||
}
|
||||
else if ($(this).hasClass('trDeliverySlip') && $(this).find('.show-popover').length == 0) {
|
||||
//prvy stlpec na dodacom liste - datum dodacieho listu
|
||||
generatePopover($(this).find('td:eq(0)'), queryString($(this).find('a').attr('href')).id_order_invoice, null, 'DeliveryDate', {'type' : 'date'});
|
||||
//treti stlpec na dodacom liste - cislo dodacieho listu
|
||||
setDocumentReference(queryString($(this).find('a').attr('href')).id_order_invoice, $(this).find('td:eq(2)').find('a'), 'delivery_slip');
|
||||
generatePopover($(this).find('td:eq(2)'), queryString($(this).find('a').attr('href')).id_order_invoice, $(this).find('td:eq(2)').find('a'), 'DeliveryNumber', {'type' : 'input'});
|
||||
addRemoveButtonOnDocument($(this), 'DeliverySlip', queryString($(this).find('a').attr('href')).id_order_invoice);
|
||||
} else if ($(this).hasClass('trOrderSlip') && $(this).find('.show-popover').length == 0) {
|
||||
orderSlipID = parseInt(queryString($(this).find('a').attr('href')).id_order_slip);
|
||||
//prvy stlpec na dobropise - datum dobropisu
|
||||
generatePopover($(this).find('td:eq(0)'), orderSlipID, null, 'CreditslipDate', {'type' : 'date'});
|
||||
//treti stlpec na dobropise - cislo dobropisu
|
||||
setDocumentReference(orderSlipID, $(this).find('td:eq(2)').find('a'), 'credit_slip');
|
||||
generatePopover($(this).find('td:eq(2)'), orderSlipID, $(this).find('td:eq(2)').find('a'), 'CreditslipNumber', {'type' : 'input'});
|
||||
addRemoveButtonOnDocument($(this), 'CreditSlip', orderSlipID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// sekcia order note
|
||||
function initOrderNote() {
|
||||
$('#orderProductsOriginalPosition').after('<div class="panel"><div class="panel-heading"><i class="icon-edit"></i>' + trans.orderNoteTitle + '</div><form id="order_note" class="form-horizontal" action="#"><div class="form-group"><div class="col-lg-12"><textarea name="orderNoteContent" id="orderNoteContent" class="textarea-autosize rte autoload_rte" style="overflow: hidden; overflow-wrap: break-word; resize: none; height: 48px;"></textarea></div></div><div class="row"><div class="col-lg-12"><span style="top: 6px; position: relative">' + trans.orderNoteInInvoice + '<input style="margin-left: 5px;" name="orderNoteOnInvoice" id="orderNoteOnInvoice" type="checkbox"></span><a id="submitOrderNote" class="btn btn-default pull-right" style="float: right;"><i class="icon-save"></i><span style="margin-left: 4px;">' + trans.save + '</span></a></div><div class="col-lg-12" style="height: 12px"><span id="orderNoteStatus" style="top: 7px; position: relative; float: right; display:none;">' + trans.orderNoteStored + '</span></div></div></form></div>');
|
||||
$('#orderNoteContent').html(orderNote.note);
|
||||
$('#orderNoteOnInvoice').prop('checked', parseInt(orderNote.show_on_invoice) == 1);
|
||||
tinySetup({
|
||||
editor_selector :"autoload_rte"
|
||||
});
|
||||
}
|
||||
|
||||
// tabulka shipping
|
||||
// novy zaznam do db tabulky order_carrier sa pridava len pokial sa pridava novy produkt do objednavky
|
||||
// viac ako jeden zaznam v zobrazenej tabulke ma len vtedy ked je v db tabulke order_carrier viac zaznamov s roznym id_carrier
|
||||
// situacia ze je viac ako jeden zaznam sa moze stat ked:
|
||||
// 1. je vytvoreny nejaky sposob dopravy s nejakym id na ktorom bola vytvorena objednavka
|
||||
// 2. tento sposob dopravy sa vymaze ale v db tabulke orders stale figuruje v stlpci id_carrier pri tejto objednavke
|
||||
// 3. vytvori sa novy produkt cez objednavku, ktoremu sa nastavuje aktualny id_carrier ktory je na objednavke
|
||||
// 4. tento id_carrier sa ale nenajde lebo je vymazany a tym padom sa vytvori novy zaznam v order_carrier s inym id_carrier (uz su tam dva zaznami, odidva s roznym id_carrier)
|
||||
// 5. keby sposob dopravy nebol vymazany, tiez by sa vytvoril novy zaznam v order_carrier, ale s tym istym id_carrier, cize by to bolo v poriadku
|
||||
// Sposoby platby su troska blbo robene lebo ked sa hocico zmeni cez admin na sposobe dopravy, tak sa sa premaze aj id sposobu dopravy (id_carrier) a da sa mu nove
|
||||
function initShipping() {
|
||||
$('#orderShippingTabContent tbody tr').each(function() {
|
||||
trObject = $(this);
|
||||
if (trObject.find('.show-popover').length == 0) {
|
||||
orderCarrierID = trObject.find('.js-update-shipping-btn').attr('data-order-carrier-id');
|
||||
generatePopover(trObject.find('td:eq(0)'), orderCarrierID, null, 'ShippingDate', {'type' : 'datetime'});
|
||||
$(shipping.values).each(function(index, object) {
|
||||
if (parseInt(object.id_order_carrier) == parseInt(orderCarrierID)) {
|
||||
generateShippingCostPopover(trObject.find('td:eq(4)'), orderCarrierID, {"priceTaxIncl" : object.shipping_cost_tax_incl, "priceTaxExcl" : object.shipping_cost_tax_excl, "tax" : shipping.tax});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initOrderPayment() {
|
||||
trCount = 0;
|
||||
$("#view_order_payments_block table tbody tr:not(.d-none,.d-print-none)").each(function() {
|
||||
trObject = $(this);
|
||||
generatePopover(trObject.find('td:eq(0)'), trCount, null, 'PaymentDate', {'type' : 'datetime'});
|
||||
generatePopover(trObject.find('td:eq(1)'), trCount, null, 'PaymentMethod', {'type' : 'input'});
|
||||
generatePopover(trObject.find('td:eq(2)'), trCount, null, 'PaymentTransactionID', {'type' : 'input'});
|
||||
generatePopover(trObject.find('td:eq(3)'), trCount, null, 'PaymentAmount', {'type' : 'input', 'output' : 'price'});
|
||||
$('<td><span data-number="' + trCount + '" class="deletePayment pull-right btn btn-default"><i class="material-icons icon-trash">delete</i><span class="preLoading" style="display:none"></span></span></td>').insertAfter(trObject.find('td:last'));
|
||||
trCount++;
|
||||
});
|
||||
}
|
||||
|
||||
function initDeleteStatuses() {
|
||||
statusesCount = $('#historyTabContent table:eq(0) tbody tr').length;
|
||||
if (statusesCount > 1) {
|
||||
$('#historyTabContent table:eq(0) tbody tr').each(function() {
|
||||
if ($(this).find('.deleteStatus').length == 0) {
|
||||
$(this).append('<td><span data-number="' + statusesCount + '" class="deleteStatus pull-right btn btn-default"><i class="material-icons icon-trash">delete</i><span class="preLoading" style="display:none"></span></span></td>');
|
||||
statusesCount--;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initProductLine() {
|
||||
$("#orderProductsTable tbody tr.cellProduct").each(function() {
|
||||
if ($(this).find('.cellProductName').find('.show-popover').length == 0) {
|
||||
generatePopover($(this).find('.cellProductName'), $(this).find('.js-order-product-edit-btn').attr('data-order-detail-id'), $(this).find('.cellProductName .productName'), 'ProductName', {'type' : 'input'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initEvents() {
|
||||
$(document).on("click", ".icon-pencil", function() {
|
||||
hidePopovers($(this).siblings('.show-popover'));
|
||||
$(this).siblings('.show-popover').popover({
|
||||
'sanitize': false
|
||||
});
|
||||
$(this).siblings('.show-popover').popover('show');
|
||||
//hodnota data-value-exception-path urcuje, ci je hodnota pola v surodencovi .show-popover, alebo az pod nim v elemente "a"
|
||||
if ($(this).siblings('.show-popover').find('.productName').length > 0) {
|
||||
$(this).siblings('.show-popover').find('.productName').addClass('setValuePlace');
|
||||
} else if ($(this).siblings('.show-popover').attr('data-value-exception-path') == 'true') {
|
||||
$(this).siblings('.show-popover').find('a').addClass('setValuePlace');
|
||||
} else {
|
||||
//setValuePlace sa zadava kvoli tomu aby po zbehnuti ajaxu, vedel system nastavit hodnotu kam treba v html
|
||||
//po zapisani hodnoty do setValuePlace sa tato trieda vymaze
|
||||
$(this).siblings('.show-popover').addClass('setValuePlace');
|
||||
}
|
||||
$(this).siblings('.show-popover').addClass('hasPopover');
|
||||
if ($(this).siblings('.show-popover').attr('data-type') == 'date' || $(this).siblings('.show-popover').attr('data-type') == 'datetime') {
|
||||
setDatepicker($(this).siblings('.show-popover').attr('data-type'));
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '.deleteStatus', function (e) {
|
||||
ajaxDeleteOrderStatusOrPaymentOrDocument($(this), "Status");
|
||||
});
|
||||
|
||||
$(document).on('click', '.deletePayment', function (e) {
|
||||
ajaxDeleteOrderStatusOrPaymentOrDocument($(this), "Payment");
|
||||
});
|
||||
|
||||
$(document).on('click', '.deleteDocument', function (e) {
|
||||
ajaxDeleteOrderStatusOrPaymentOrDocument($(this), $(this).attr("data-type"));
|
||||
});
|
||||
|
||||
$(document).on('click', '#submitOrderNote', function (e) {
|
||||
ajaxSetOrderNote();
|
||||
});
|
||||
|
||||
$(document).on('click', '#orderResendMail', function (e) {
|
||||
ajaxResendMailToCustomer();
|
||||
});
|
||||
|
||||
$(document).on('click', '.classicCheck', function (e) {
|
||||
ajaxReferenceSetData($(this).parents('.newValue:eq(0)'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.shippingCostCheck', function (e) {
|
||||
ajaxShippingCostSetData($(this).parents('.shippingCost'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.icon-remove', function (e) {
|
||||
hidePopovers(null);
|
||||
});
|
||||
|
||||
$(document).on("keyup change", ".shippingCostIncl input", function() {
|
||||
this.value = this.value.replace(/[^0-9\.,]/g,'');
|
||||
recalculateShippingCost($(this).parents('.shippingCost'), 'priceTaxIncl');
|
||||
});
|
||||
$(document).on("keyup change", ".shippingCostExcl input", function() {
|
||||
this.value = this.value.replace(/[^0-9\.,]/g,'');
|
||||
recalculateShippingCost($(this).parents('.shippingCost'), 'priceTaxExcl');
|
||||
});
|
||||
$(document).on("keyup change", ".shippingCostTax input", function() {
|
||||
this.value = this.value.replace(/[^0-9\.,]/g,'');
|
||||
recalculateShippingCost($(this).parents('.shippingCost'), 'tax');
|
||||
});
|
||||
|
||||
$(document).on("keyup change", ".newValue[data-name='setPaymentAmount'] input", function() {
|
||||
this.value = this.value.replace(/[^0-9\.,]/g,'');
|
||||
});
|
||||
|
||||
if (psVersionLess1607) {
|
||||
$('.edit_product_change_link').bind('click', function() {
|
||||
$(this).parents('tr:eq(0)').find('.product_name_show').hide();
|
||||
$(this).parents('tr:eq(0)').find('.product_name_edit').show();
|
||||
});
|
||||
$('.cancel_product_change_link, .submitProductChange').bind('click', function() {
|
||||
$(this).parents('tr:eq(0)').find('.product_name_show').show();
|
||||
$(this).parents('tr:eq(0)').find('.product_name_edit').hide();
|
||||
});
|
||||
} else {
|
||||
$(document).on('click', '.edit_product_change_link', function(){
|
||||
$(this).parents('tr:eq(0)').find('.product_name_show').hide();
|
||||
$(this).parents('tr:eq(0)').find('.product_name_edit').show();
|
||||
});
|
||||
$(document).on('click', '.cancel_product_change_link, .submitProductChange', function(){
|
||||
$(this).parents('tr:eq(0)').find('.product_name_show').show();
|
||||
$(this).parents('tr:eq(0)').find('.product_name_edit').hide();
|
||||
});
|
||||
}
|
||||
|
||||
//aby zmizol popover ked sa klikne mimo neho
|
||||
$(document).on('click', function (e) {
|
||||
//pokial sa neklikne na datepicker tlacidlo, alebo na ikonu pera
|
||||
if (!$(e.target).hasClass('ui-icon') && !$(e.target).hasClass('icon-pencil') && !$(e.target).hasClass('ui-state-default')) {
|
||||
$('.hasPopover').each(function () {
|
||||
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
|
||||
$(this).popover('hide');
|
||||
$(document).find('.setValuePlace').removeClass('setValuePlace');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function generatePopover(object, id, objectValuePath, action, typeValues) {
|
||||
object.html('<span data-html="true" data-placement="top" data-value-exception-path="' + (objectValuePath != null ? 'true' : 'false') + '" data-type="' + typeValues.type + '" data-content="' + getPopoverContent((objectValuePath != null ? objectValuePath : object), action, typeValues, id) + '" class="show-popover set' + action + id + 'Class">' + object.html() + '</span><i class="material-icons icon-pencil">edit</i>');
|
||||
}
|
||||
|
||||
function generateShippingCostPopover(object, id, shippingCost) {
|
||||
object.html('<span data-html="true" data-placement="top" data-content="' + getShippingCostPopoverContent(object, id, shippingCost) + '" class="show-popover">' + object.html() + '</span><i class="material-icons icon-pencil">edit</i>');
|
||||
}
|
||||
|
||||
function addRemoveButtonOnDocument(object, type, idDocument) {
|
||||
object.append('<td style="text-align:center"><span data-number="' + idDocument + '" data-type="' + type + '" class="deleteDocument pull-right btn btn-default"><i class="material-icons icon-trash">delete</i><span class="preLoading" style="display:none"></span></span></td>');
|
||||
}
|
||||
|
||||
// function addRemoveButtonOnDocument(object, type, substringCutIn) {
|
||||
// idDocument = object.attr('id').substring(substringCutIn, object.attr('id').length);
|
||||
// object.append('<td><span data-number="' + idDocument + '" data-type="' + type + '" class="deleteDocument pull-right btn btn-default"><i class="icon-trash"></i><span class="preLoading" style="display:none"></span></span></td>');
|
||||
// }
|
||||
|
||||
function getPopoverContent(valueObject, name, typeValues, id) {
|
||||
popoverContent = "<div class='newValue' data-name='set" + name + "' data-type='" + typeValues.type + "' " + (typeof typeValues.output !== typeof undefined ? "data-output='" + typeValues.output + "'" : "") + " data-id='" + id + "'>";
|
||||
if (typeValues.type == 'select') {
|
||||
popoverContent += "<select class='popoverInput'>";
|
||||
$(typeValues.values).each(function(index, value) {
|
||||
popoverContent += "<option " + (value.selected ? 'selected' : '') + " value='" + value.id_carrier + "'>" + value.name + "</option>";
|
||||
});
|
||||
popoverContent += "</select>";
|
||||
} else {
|
||||
if (typeof typeValues.output !== typeof undefined && typeValues.type == 'input') {
|
||||
if (typeValues.output == 'price') {
|
||||
value = formatedNumberToFloat(valueObject.html().trim(), currency.format, currency.sign);
|
||||
}
|
||||
} else {
|
||||
value = valueObject.html().trim();
|
||||
}
|
||||
popoverContent += "<input class='popoverInput' placeholder='" + valueObject.html().trim() + "' value='" + value + "'/>";
|
||||
}
|
||||
popoverContent += "<div class='popover-buttons'><i class='material-icons icon-check classicCheck'>done</i><i class='material-icons icon-remove'>clear</i><span class='spinner'></span></div>";
|
||||
popoverContent += "</div><div class='operationStatus'></div>";
|
||||
return popoverContent;
|
||||
}
|
||||
|
||||
function hidePopovers(object) {
|
||||
$('.hasPopover').each(function () {
|
||||
if (!$(this).is(object)) {
|
||||
$(this).popover('hide');
|
||||
$(document).find('.setValuePlace').removeClass('setValuePlace');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setDocumentReference(id, placeToSet, documentType) {
|
||||
$(documents).each(function(key, value) {
|
||||
if (value.document_type == documentType && value.id_document == id) {
|
||||
placeToSet.html(value.reference);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getShippingCostPopoverContent(valueObject, id, shippingCost) {
|
||||
popoverContent = "<div class='shippingCost' data-id='" + id + "'>";
|
||||
|
||||
popoverContent += "<div class='shippingCostExcl shippingCostBlock'>";
|
||||
popoverContent += "<div class='shippingPriceLabel'><label>" + trans.tax_excl_price + ":</label></div>";
|
||||
popoverContent += "<input class='popoverInput' value='" + Number((parseFloat(shippingCost.priceTaxExcl)).toFixed(3)) + "' placeholder='" + Number((parseFloat(shippingCost.priceTaxExcl)).toFixed(3)) + " (" + trans.tax_excl + ")'/>";
|
||||
popoverContent += "</div>";
|
||||
|
||||
popoverContent += "<div class='shippingCostIncl shippingCostBlock'>";
|
||||
popoverContent += "<div class='shippingPriceLabel'><label>" + trans.tax_incl_price + ":</label></div>";
|
||||
popoverContent += "<input class='popoverInput' value='" + Number((parseFloat(shippingCost.priceTaxIncl)).toFixed(3)) + "' placeholder='" + Number((parseFloat(shippingCost.priceTaxIncl)).toFixed(3)) + " (" + trans.tax_incl + ")'/>";
|
||||
popoverContent += "<div class='popover-buttons'><i class='material-icons icon-check shippingCostCheck'>done</i><i class='material-icons icon-remove'>clear</i><span class='spinner'></span></div>";
|
||||
popoverContent += "</div>";
|
||||
|
||||
popoverContent += "<div class='shippingCostTax shippingCostBlock'>";
|
||||
popoverContent += "<div class='shippingPriceLabel'><label>" + trans.tax + " (%):</label></div>";
|
||||
popoverContent += "<input class='popoverInput' value='" + Number((parseFloat(shippingCost.tax)).toFixed(3)) + "' placeholder='" + Number((parseFloat(shippingCost.tax)).toFixed(3)) + "% (" + trans.tax + ")'/>";
|
||||
popoverContent += "</div>";
|
||||
|
||||
popoverContent += "</div><div class='operationStatus'></div>";
|
||||
return popoverContent;
|
||||
}
|
||||
|
||||
function setDatepicker(type) {
|
||||
if (type == 'date') {
|
||||
$(".popoverInput").datepicker();
|
||||
} else {
|
||||
$(".popoverInput").timepicker();
|
||||
}
|
||||
$(".popoverInput").prop('readonly', true);
|
||||
$(".ui-datepicker").css("z-index","9999999999");
|
||||
}
|
||||
|
||||
function calculateDocumentsTableCellWidth() {
|
||||
tdMaxLenght = 0;
|
||||
$('#documents table:eq(0) tbody tr').each(function() {
|
||||
if ($(this).find('td:eq(2) a').length > 0) {
|
||||
if ($(this).find('td:eq(2) a').html().trim().length > tdMaxLenght) {
|
||||
tdMaxLenght = $(this).find('td:eq(2) a').html().trim().length;
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#documents table:eq(0) tbody tr:eq(0) td:eq(2)').width((tdMaxLenght * 7) + 25);
|
||||
}
|
||||
|
||||
function ajaxSetReferenceFinalMessage(sourceObject, message) {
|
||||
objectWidth = sourceObject.width();
|
||||
sourceObject.fadeOut("slow", function() {
|
||||
sourceObject.empty();
|
||||
sourceObject.parent().find('.operationStatus').width(objectWidth);
|
||||
sourceObject.parent().find('.operationStatus').append('<p>' + message + '</p>');
|
||||
sourceObject.parent().find('.operationStatus').fadeIn("slow");
|
||||
setTimeout(function() {
|
||||
hidePopovers(null);
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
function afterAjaxMessage(messageText, messageType, type) {
|
||||
message = '<div class="' + type + 'Message alert alert-' + messageType + '">';
|
||||
message += '<button type="button" class="close" data-dismiss="alert">×</button>';
|
||||
message += messageText;
|
||||
message += '</div>';
|
||||
if (type == "Status") {
|
||||
$('#historyTabContent').prepend(message);
|
||||
} else if (type == "Payment") {
|
||||
$('#view_order_payments_block .card-body').prepend(message);
|
||||
} else if (type == "Mail") {
|
||||
$('#order-view-page').prepend(message);
|
||||
}
|
||||
}
|
||||
|
||||
function removeDocumentLine(documentID, type) {
|
||||
if (type == "Invoice") {
|
||||
$("#documents #invoice_" + documentID).remove();
|
||||
$("#documents #invoiceNote" + documentID).remove();
|
||||
$("#documents #delivery_" + documentID).remove();
|
||||
} else if (type == "DeliverySlip") {
|
||||
$("#documents #delivery_" + documentID).remove();
|
||||
} else {
|
||||
$("#documents #orderslip_" + documentID).remove();
|
||||
}
|
||||
}
|
||||
|
||||
// funkcia ktora odstrani vsetky 3 selektovniky pre vyber faktur, pokial sa vymaze posledna faktura
|
||||
// sluzi na to, aby nezostal po vymazani poslednej faktury prazdny selektovnik
|
||||
function removeInvoicesSelects() {
|
||||
if ($('#payment_invoice').length > 0) {
|
||||
$('#payment_invoice').each(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
if ($('.edit_product_invoice').length > 0) {
|
||||
$('.edit_product_invoice').each(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxReferenceSetData(sourceObject) {
|
||||
if (!isStoring && sourceObject.find(".popoverInput").val() != "") {
|
||||
if (sourceObject.attr('data-type') == 'date' || sourceObject.attr('data-type') == 'datetime') {
|
||||
value = formatDateTimeToMysql(sourceObject.find(".popoverInput").datepicker('getDate'), sourceObject.attr('data-type'));
|
||||
} else {
|
||||
value = sourceObject.find(".popoverInput").val();
|
||||
if (typeof sourceObject.attr('data-output') !== typeof undefined && sourceObject.attr('data-type') == 'input') {
|
||||
if (sourceObject.attr('data-output') == 'price') {
|
||||
value = value.replace(/,/g, '.');
|
||||
}
|
||||
}
|
||||
}
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
adminThemeDir: adminThemeDir,
|
||||
action: sourceObject.attr('data-name'),
|
||||
id: sourceObject.attr('data-id'),
|
||||
value: value
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
sourceObject.find('.icon-remove').css("visibility", "hidden");
|
||||
sourceObject.find('.spinner').show();
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if (!res.errors) {
|
||||
if (sourceObject.attr('data-name') == 'setShippingCarrier') {
|
||||
// pokial je vykonavana zmana typy shippingu tak sa moze premenit cena za celkovy shipping objednavky (zlucit shippingi) aj cena za objednavku
|
||||
// treba tym padom pregenerovat tabulku shipping aj celkovu cenu objednavky
|
||||
// funkcie updateAmounts a updateShipping su nativne PS funkcie z js/admin/orders.js
|
||||
shipping = {"values" : res.shipping, "tax" : res.order.carrier_tax_rate};
|
||||
} else {
|
||||
|
||||
//v pripade ze sa nastavuje cislo faktury, treba pregenerovat dokumenty ktore sa vykresluju v tabulke dokumentov
|
||||
if (sourceObject.attr('data-name') == 'setInvoiceNumber') {
|
||||
documents = $.parseJSON(res.documents);
|
||||
}
|
||||
|
||||
//pokial je poslasny zo servera res.value, zobrazime na vystupe tuto hodnotu
|
||||
if (typeof res.value !== typeof undefined) {
|
||||
value = res.value;
|
||||
}
|
||||
|
||||
//pregenerujeme paceholder a value na inpute popoveru
|
||||
content = $('.' + sourceObject.attr('data-name') + sourceObject.attr('data-id') + 'Class').attr('data-content');
|
||||
object = $('<div/>').html(content).contents();
|
||||
$(object).find('input').attr('placeholder', value);
|
||||
//pokial je urceny data-output, znamena to ze je potrebne zobrazit hodnotu v zadanom formate - napr "price"
|
||||
if (typeof sourceObject.attr('data-output') !== typeof undefined && sourceObject.attr('data-type') == 'input') {
|
||||
if (sourceObject.attr('data-output') == 'price') {
|
||||
value = formatedNumberToFloat(value, currency.format, currency.sign).replace(/,/g, '');
|
||||
}
|
||||
}
|
||||
$(object).find('input').attr('value', value);
|
||||
$('.' + sourceObject.attr('data-name') + sourceObject.attr('data-id') + 'Class').attr('data-content', $(object).prop('outerHTML') + '<div class="operationStatus"></div>');
|
||||
|
||||
//pokial je urceny data-output, znamena to ze je potrebne zobrazit hodnotu v zadanom formate - napr "price"
|
||||
if (typeof sourceObject.attr('data-output') !== typeof undefined && sourceObject.attr('data-type') == 'input') {
|
||||
if (sourceObject.attr('data-output') == 'price') {
|
||||
value = formatCurrency(parseFloat(value), currency.format, currency.sign);
|
||||
}
|
||||
}
|
||||
//nastavime hodnotu do bunky pri ktorej bolo pero
|
||||
$(".setValuePlace").html((sourceObject.attr('data-type') == 'select' ? sourceObject.find(".popoverInput option[value=" + value + "]").html() : value));
|
||||
}
|
||||
ajaxSetReferenceFinalMessage(sourceObject, res.result);
|
||||
} else {
|
||||
alert(res.result);
|
||||
setTimeout(function() {
|
||||
hidePopovers(null);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
alert(trans.can_not_be_stored);
|
||||
setTimeout(function() {
|
||||
hidePopovers(null);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
isStoring = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxShippingCostSetData(sourceObject) {
|
||||
if (!isStoring) {
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
adminThemeDir: adminThemeDir,
|
||||
action: 'setShippingCostData',
|
||||
id_order_carrier: sourceObject.attr('data-id'),
|
||||
priceTaxIncl: parseFloat(sourceObject.find('.shippingCostIncl input').val().replace(/,/g, '.')),
|
||||
priceTaxExcl: parseFloat(sourceObject.find('.shippingCostExcl input').val().replace(/,/g, '.')),
|
||||
tax: parseFloat(sourceObject.find('.shippingCostTax input').val())
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
sourceObject.find('.icon-remove').css("visibility", "hidden");
|
||||
sourceObject.find('.spinner').show();
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if (!res.errors) {
|
||||
// treba pregenerovat celkovu cenu objednavky aj shipping tabulku
|
||||
// funkcie updateAmounts a updateShipping su nativne PS funkcie z js/admin/orders.js
|
||||
shipping = {"values" : res.shipping, "tax" : res.order.carrier_tax_rate};
|
||||
location.reload();
|
||||
} else {
|
||||
alert(res.result);
|
||||
setTimeout(function() {
|
||||
hidePopovers(null);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
alert(trans.can_not_be_stored);
|
||||
setTimeout(function() {
|
||||
hidePopovers(null);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
isStoring = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxDeleteOrderStatusOrPaymentOrDocument(sourceObject, type) {
|
||||
sourceObject.find('.icon-trash').css('visibility', 'hidden');
|
||||
sourceObject.find('.preLoading').show();
|
||||
if (!isStoring) {
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
action: "delete" + type,
|
||||
number: sourceObject.attr('data-number'),
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
$('.' + type + 'Message').remove();
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if (!res.errors) {
|
||||
sourceObject.parents('tr:eq(0)').remove();
|
||||
if (type == "Status") {
|
||||
if ($('#status table:eq(0) tbody tr').length <= 1) {
|
||||
$('.deleteStatus').each(function(){
|
||||
$(this).parent().remove();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
removeDocumentLine(sourceObject.attr('data-number'), type);
|
||||
$("#tabOrder li:eq(1) span").html(res.documentsCount);
|
||||
}
|
||||
afterAjaxMessage(res.result, 'success', type);
|
||||
} else {
|
||||
sourceObject.find('.icon-trash').css('visibility', 'visible');
|
||||
afterAjaxMessage(res.result, 'danger', type);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
sourceObject.find('.icon-trash').css('visibility', 'visible');
|
||||
if (type == "Status") {
|
||||
afterAjaxMessage(trans.order_status_removed, 'danger', type);
|
||||
} else if (type == "Payment") {
|
||||
afterAjaxMessage(trans.payment_removed, 'danger', type);
|
||||
} else {
|
||||
afterAjaxMessage(trans.document_removed, 'danger', type);
|
||||
}
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
sourceObject.find('.preLoading').hide();
|
||||
isStoring = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxResendMailToCustomer() {
|
||||
if (!isStoring) {
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
action: "resendEmail"
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
$('.MailMessage').remove();
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if (!res.errors) {
|
||||
afterAjaxMessage(res.result, 'success', 'Mail');
|
||||
} else {
|
||||
afterAjaxMessage(res.result, 'danger', 'Mail');
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
afterAjaxMessage(trans.mail_can_not_be_send, 'danger', 'Mail');
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
isStoring = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxChangeProductName(idOrderDetail, productName) {
|
||||
if (!isStoring) {
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
product_id_order_detail: idOrderDetail,
|
||||
product_name: productName,
|
||||
action: "changeProductName"
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
isStoring = false;
|
||||
});
|
||||
return ajaxCall;
|
||||
}
|
||||
}
|
||||
|
||||
function ajaxSetOrderNote() {
|
||||
if (!isStoring) {
|
||||
ajaxCall = $.ajax({
|
||||
type: "POST",
|
||||
url: editOrderAjaxLink,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data : {
|
||||
ajax: true,
|
||||
id_order: id_order,
|
||||
note: tinyMCE.get("orderNoteContent").getContent(),
|
||||
show_on_invoice: (($('#orderNoteOnInvoice:checkbox:checked').length > 0) ? 1 : 0),
|
||||
action: "setOrderNote"
|
||||
},
|
||||
beforeSend: function()
|
||||
{
|
||||
isStoring = true;
|
||||
},
|
||||
success : function(res)
|
||||
{
|
||||
if (!res.errors) {
|
||||
$("#orderNoteStatus").css('color','green').html(res.result).fadeIn(1000).delay(1500).fadeOut(1000);
|
||||
} else {
|
||||
$("#orderNoteStatus").css('color','red').html(trans.orderNoteNotStored).fadeIn(1000).delay(1500).fadeOut(1000);
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
$("#orderNoteStatus").css('color','red').html(trans.orderNoteNotStored).fadeIn(1000).delay(1500).fadeOut(1000);
|
||||
}
|
||||
});
|
||||
ajaxCall.always(function() {
|
||||
isStoring = false;
|
||||
});
|
||||
return ajaxCall;
|
||||
}
|
||||
}
|
||||
|
||||
function recalculateShippingCost(object, settedValueType) {
|
||||
if (object.find(".shippingCostTax input").val().length == 0) {
|
||||
shippingTax = 0;
|
||||
} else {
|
||||
shippingTax = parseFloat(object.find(".shippingCostTax input").val().replace(/,/g, '.'));
|
||||
}
|
||||
if (settedValueType == 'priceTaxIncl') {
|
||||
calculateShippingCostTaxExcl(object, shippingTax);
|
||||
lastChangedShippingCostType = 'taxIncl';
|
||||
} else if (settedValueType == 'priceTaxExcl') {
|
||||
calculateShippingCostTaxIncl(object, shippingTax);
|
||||
lastChangedShippingCostType = 'taxExcl';
|
||||
} else if (settedValueType == 'tax') {
|
||||
if (lastChangedShippingCostType == 'taxExcl') {
|
||||
calculateShippingCostTaxIncl(object, shippingTax);
|
||||
} else {
|
||||
calculateShippingCostTaxExcl(object, shippingTax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateShippingCostTaxIncl(object, shippingTax) {
|
||||
if (object.find(".shippingCostExcl input").val().length > 0) {
|
||||
shippingCostExcl = parseFloat(object.find(".shippingCostExcl input").val().replace(/,/g, '.'));
|
||||
shippingCostIncl = shippingCostExcl *= (1 + shippingTax / 100);
|
||||
object.find(".shippingCostIncl input").val(Number((shippingCostIncl).toFixed(3)));
|
||||
} else {
|
||||
object.find(".shippingCostIncl input").val('');
|
||||
}
|
||||
}
|
||||
|
||||
function calculateShippingCostTaxExcl(object, shippingTax) {
|
||||
if (object.find(".shippingCostIncl input").val().length > 0) {
|
||||
shippingCostIncl = parseFloat(object.find(".shippingCostIncl input").val().replace(/,/g, '.'));
|
||||
shippingCostExcl = shippingCostIncl / (1 + shippingTax / 100);
|
||||
object.find(".shippingCostExcl input").val(Number((shippingCostExcl).toFixed(3)));
|
||||
} else {
|
||||
object.find(".shippingCostExcl input").val('');
|
||||
}
|
||||
}
|
||||
|
||||
function resetStatusIDs() {
|
||||
statusesCount = $('#status table:eq(0) tbody tr').length;
|
||||
if (statusesCount > 1) {
|
||||
$('#status table:eq(0) tbody tr').each(function() {
|
||||
$(this).find('.deleteStatus').attr('data-number', statusesCount);
|
||||
statusesCount--;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function formatDateTimeToMysql(value, type) {
|
||||
return value.getFullYear() + "-" + twoDigits(1 + value.getMonth()) + "-" + twoDigits(value.getDate()) + (type == 'datetime' ? " " + twoDigits(value.getHours()) + ":" + twoDigits(value.getMinutes()) + ":" + twoDigits(value.getSeconds()) : "");
|
||||
}
|
||||
|
||||
function twoDigits(d) {
|
||||
if (0 <= d && d < 10) return "0" + d.toString();
|
||||
if (-10 < d && d < 0) return "-0" + (-1*d).toString();
|
||||
return d.toString();
|
||||
}
|
||||
|
||||
function queryString(string) {
|
||||
var query_string = {};
|
||||
var query = string;
|
||||
var vars = query.split("&");
|
||||
for (var i=0;i<vars.length;i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (typeof query_string[pair[0]] === "undefined") {
|
||||
query_string[pair[0]] = decodeURIComponent(pair[1]);
|
||||
} else if (typeof query_string[pair[0]] === "string") {
|
||||
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
|
||||
query_string[pair[0]] = arr;
|
||||
} else {
|
||||
query_string[pair[0]].push(decodeURIComponent(pair[1]));
|
||||
}
|
||||
}
|
||||
return query_string;
|
||||
}
|
||||
Reference in New Issue
Block a user