/* * 2021 Keshva * * @author Keshva * @copyright 2021 Keshva */ var isPopoverActive = false; var isStoring = false; var lastChangedShippingCostType = 'taxExcl'; $(document).ready(function() { // pretazenie funkcie, ktora sa vola po pridani noveho produktu // pokial je uz produkt doruceny, tak nepridava moznost jeho updatu a prida input pre editaciu nazvu produktu if (typeof addViewOrderDetailRow !== 'undefined') { var origAddViewOrderDetailRow = addViewOrderDetailRow; addViewOrderDetailRow = function(str) { origAddViewOrderDetailRow(str); displayAddProduct(false); initProductLine(); } } //pretazenie funkcie, ktora sa vola po zeditovani produktu if (typeof refreshProductLineView !== 'undefined') { var origRefreshProductLineView = refreshProductLineView; refreshProductLineView = function(param1, param2) { idOrderDetail = $(param2).find('.edit_product_id_order_detail').val(); productName = $(".edit_product_id_order_detail[value=" + idOrderDetail + "]").parents('.product-line-row:eq(0)').find('.edit_product_name').val(); //premenovanie produktu cez ajax a nasledne zobrazenie riadku produktu s novym nazvom, ak sa ho podari ulozit $.when(ajaxChangeProductName(idOrderDetail, productName)).then(function(ajaxChangeProductNameReturn) { if (!ajaxChangeProductNameReturn.errors) { param2 = $(param2).clone(); param2.find('.productName').html(productName); } origRefreshProductLineView(param1, param2); initProductLine(); }); } } // pretazenie funkcie len za ucelom opatovneho vykreslenia ceruziek pre update tabulky shipping if (typeof updateShipping !== 'undefined') { var origUpdateShipping = updateShipping; updateShipping = function(str){ origUpdateShipping(str); initShipping(); } } //pretazenie funkcie len za ucelom opatovneho vykreslenia ceruziek pre update tabulky documents if (typeof updateDocuments !== 'undefined') { var origUpdateDocuments = updateDocuments; updateDocuments = function(str) { origUpdateDocuments(str); initDocumentsTable(); } } displayAddProduct(true); displayResendMailButton(); initOrderDateAndNumber(); initDocumentsTable(); initOrderNote(); initShipping(); initOrderPayment(); initDeleteStatuses(); initProductLine(); initEvents(); updateInvoice(invoices); }); function displayAddProduct(isInit) { if (hasBeenDelivered) { editProduct = '
'; if (isInit) { // pokial ide o prve nacitanie stranky pridame do kazdeho riadku produktu editaciu produktu $(editProduct).insertAfter(".product-line-row .partial_refund_fields"); $(".order_action").prepend(''); // funkcia init() je nativna PS funkcia z js/admin/orders.js init(); } else { // pokial nejde o inicializaciu ale o nasledne vykreslenie po pridani produktu, pridame button na pridanie produktu len k poslednemu zaznamu $(editProduct).insertAfter($(".product-line-row").last().find(".partial_refund_fields")); } } } function displayResendMailButton() { $("#tabOrder").parents(".panel:eq(0)").find(".well:eq(0)").append('' + trans.resend_email + ''); } function initOrderDateAndNumber() { //datum objednavky generatePopover($('.kpi-content:eq(0) .value'), 0, null, 'OrderDate', {'type' : 'datetime'}); //cislo objednavky generatePopover($('.panel-heading .badge:eq(0)'), 0, null, 'OrderNumber', {'type' : 'input'}); } // tabulka dokumentov - faktura, dodaci list, dobropisy function initDocumentsTable() { if (!$('#documents table:eq(0) tbody tr td:eq(0)').hasClass('list-empty')) { $('#documents table:eq(0) thead tr').append(''); $('#documents table:eq(0) tbody tr').each(function() { if ($(this).attr('id').substring(0, 8) == 'invoice_') { //prvy stlpec na fakture - datum faktury generatePopover($(this).find('td:eq(0)'), $(this).attr('id').substring(8, $(this).attr('id').length), null, 'InvoiceDate', {'type' : 'date'}); //treti stlpec na fakture - cislo faktury generatePopover($(this).find('td:eq(2)'), $(this).attr('id').substring(8, $(this).attr('id').length), $(this).find('td:eq(2)').find('a'), 'InvoiceNumber', {'type' : 'input'}); addRemoveButtonOnDocument($(this), 'Invoice', 8); } else if ($(this).attr('id').substring(0, 9) == 'delivery_') { //prvy stlpec na dodacom liste - datum dodacieho listu generatePopover($(this).find('td:eq(0)'), $(this).attr('id').substring(9, $(this).attr('id').length), null, 'DeliveryDate', {'type' : 'date'}); //treti stlpec na dodacom liste - cislo dodacieho listu setDocumentReference($(this).attr('id').substring(9, $(this).attr('id').length), $(this).find('td:eq(2)').find('a'), 'delivery_slip'); generatePopover($(this).find('td:eq(2)'), $(this).attr('id').substring(9, $(this).attr('id').length), $(this).find('td:eq(2)').find('a'), 'DeliveryNumber', {'type' : 'input'}); addRemoveButtonOnDocument($(this), 'DeliverySlip', 9); } else if ($(this).attr('id').substring(0, 10) == 'orderslip_') { orderSlipID = parseInt($(this).attr('id').replace("orderslip_", "")); //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', 10); } }); calculateDocumentsTableCellWidth(); } } // sekcia order note function initOrderNote() { $('#documents').parents('.panel:eq(0)').after('
' + trans.orderNoteTitle + '
' + trans.orderNoteInInvoice + '' + trans.save + '
'); $('#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() { $('#shipping_table tbody tr').each(function(){ trObject = $(this); if (psVersion17) { orderCarrierID = trObject.find('.edit_shipping_link').attr('data-id-order-carrier'); } else { orderCarrierID = trObject.find('.shipping_number_edit input[name=id_order_carrier]').val(); } generatePopover(trObject.find('td:eq(0)'), orderCarrierID, null, 'ShippingDate', {'type' : 'datetime'}); carrriersToSelect = []; $(carriers).each(function(indexCarr, objectCarr) { selectedOrderCarrier = false; $(shipping.values).each(function(indexShip, objectShip) { if (parseInt(objectCarr.id_carrier) == parseInt(objectShip.id_carrier) && orderCarrierID == parseInt(objectShip.id_order_carrier)) { selectedOrderCarrier = true; } }); carrriersToSelect.push({"id_carrier" : objectCarr.id_carrier, "name" : objectCarr.name, "selected" : selectedOrderCarrier}); }); generatePopover(trObject.find('td:eq(2)'), orderCarrierID, null, 'ShippingCarrier', {'type' : 'select', 'values' : carrriersToSelect}); $(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}); } }); //zakomentovanie tracking number - robilo problemy, pretoze ked dakomu vygenerovalo tracking number po objednavke z roznymi znakmi tak mne to rozbilo funcionalitu //menenie tracking number je uz spravene v preste //generatePopover(trObject.find('td:eq(5) span'), orderCarrierID, null, 'ShippingTrackingNumber', {'type' : 'input'}); //trObject.find('.edit_shipping_number_link').hide(); }); } function initOrderPayment() { trCount = 0; $("#formAddPayment table tbody tr").each(function() { trObject = $(this); if (typeof trObject.attr('class') === typeof undefined && trObject.find('.list-empty').length == 0) { 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'}); $('').insertBefore(trObject.find('.actions')); trCount++; } }); } function initDeleteStatuses() { statusesCount = $('#status table:eq(0) tbody tr').length; if (statusesCount > 1) { $('#status table:eq(0) tbody tr').each(function() { $(this).append(''); statusesCount--; }); } } function initProductLine() { $("#orderProducts tbody tr").each(function() { if ($(this).find('td:eq(1) .product_name_edit').length == 0) { $(this).find('td:eq(1) a').addClass('product_name_show'); $('').insertAfter($(this).find('td:eq(1) a')); } }); } function initEvents() { $(document).on("click", ".icon-pencil", function() { hidePopovers($(this).siblings('.show-popover')); $(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').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('' + object.html() + ''); } function generateShippingCostPopover(object, id, shippingCost) { object.html('' + object.html() + ''); } function addRemoveButtonOnDocument(object, type, substringCutIn) { idDocument = object.attr('id').substring(substringCutIn, object.attr('id').length); object.append(''); } function getPopoverContent(valueObject, name, typeValues, id) { popoverContent = "
"; if (typeValues.type == 'select') { popoverContent += ""; } 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 += ""; } popoverContent += "
"; popoverContent += "
"; 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 = "
"; popoverContent += "
"; popoverContent += "
"; popoverContent += ""; popoverContent += "
"; popoverContent += "
"; popoverContent += "
"; popoverContent += ""; popoverContent += "
"; popoverContent += "
"; popoverContent += "
"; popoverContent += "
"; popoverContent += ""; popoverContent += "
"; popoverContent += "
"; 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('

' + message + '

'); sourceObject.parent().find('.operationStatus').fadeIn("slow"); setTimeout(function() { hidePopovers(null); }, 1000); }); } function afterAjaxMessage(messageText, messageType, type) { message = '
'; message += ''; message += messageText; message += '
'; if (type == "Status") { $('#status').prepend(message); } else if (type == "Payment") { $('#formAddPayment').prepend(message); } else if (type == "Mail") { $("#tabOrder").parents(".panel:eq(0)").find(".well:eq(0)").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 updateAmounts(res.order); shipping = {"values" : res.shipping, "tax" : res.order.carrier_tax_rate}; updateShipping(res.shipping_html); } 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); updateInvoice(res.invoices); } //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 = $('
').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') + '
'); //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, currency_blank); } } //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); // toto pregeneruje tabulku s dokumentami aby pero nebolo pod nazvami // TODO dat iba ked pojde o dokumenty calculateDocumentsTableCellWidth(); } 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 updateAmounts(res.order); shipping = {"values" : res.shipping, "tax" : res.order.carrier_tax_rate}; updateShipping(res.shipping_html); } 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 { resetStatusIDs(); } } else if (type == "Payment") { resetPaymentIDs(); } else { if (type == 'Invoice') { updateInvoice(res.invoices); if (res.invoices.length == 0) { removeInvoicesSelects(); } } 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 resetPaymentIDs() { trCount = 0; $("#formAddPayment table tbody tr").each(function() { trObject = $(this); if (typeof trObject.attr('class') === typeof undefined && trObject.find('.list-empty').length == 0) { trObject.find('td:eq(0) .show-popover').attr('data-content', getPopoverContent(trObject.find('td:eq(0) span'), 'PaymentDate', {'type' : 'datetime'}, trCount)); trObject.find('td:eq(1) .show-popover').attr('data-content', getPopoverContent(trObject.find('td:eq(1) span'), 'PaymentMethod', {'type' : 'input'}, trCount)); trObject.find('td:eq(2) .show-popover').attr('data-content', getPopoverContent(trObject.find('td:eq(2) span'), 'PaymentTransactionID', {'type' : 'input'}, trCount)); trObject.find('td:eq(3) .show-popover').attr('data-content', getPopoverContent(trObject.find('td:eq(3) span'), 'PaymentAmount', {'type' : 'input', 'output' : 'price'}, trCount)); trObject.find('.deletePayment').attr('data-number', trCount); trCount++; } }); } 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(); }