Current Module
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 2021 Keshva
|
||||
*
|
||||
* @author Keshva <keshvathakur47@gmail.com>
|
||||
* @copyright 2021 Keshva
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
counterResetDate = $("#counter_reset_date").datepicker({dateFormat: 'yy-mm-dd'});
|
||||
$("#counter_reset_date").prop("readonly", true);
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_NUMBER}") > -1){displayFields("#random_number_length",true);}else{displayFields("#random_number_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_ALPHABETIC}") > -1){displayFields("#random_alphabetic_length",true);}else{displayFields("#random_alphabetic_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_ALPHANUMERIC}") > -1){displayFields("#random_alphanumeric_length",true);}else{displayFields("#random_alphanumeric_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1){
|
||||
displayFields("#counter_start_at",true);displayFields("#counter_increment_by",true);displayFields(".ResetCounterInterval:eq(0)",true);displayFields(".CounterResetNow:eq(0)",true);displayFields(".CounterReferenceLength:eq(0)",true);
|
||||
if($(".CounterReferenceLength input:checked").val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
if($(".ResetCounterInterval input:checked").val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($(".ResetCounterInterval input:checked").val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
if($(".CounterReferenceLength input:checked").val() == 1){
|
||||
nextCounterValue = displayReferenceLength($("#counter_reference_length option:selected").val(), counterActualValue);
|
||||
}else{
|
||||
nextCounterValue = counterActualValue;
|
||||
}
|
||||
$("#counter_start_at").parent().append("<p class=\'help-block\'>Next counter value: " + nextCounterValue + "</p>")
|
||||
}else{
|
||||
displayFields("#counter_start_at",false);displayFields("#counter_increment_by",false);displayFields(".ResetCounterInterval:eq(0)",false);displayFields(".CounterResetNow:eq(0)",false);displayFields(".CounterReferenceLength:eq(0)",false);displayFields("#counter_reset_number",false);displayFields("#counter_reset_date",false);displayFields("#counter_reference_length",false);
|
||||
}
|
||||
$("#reference_number_format").bind("keyup change", function(e) {
|
||||
if(this.value.indexOf("{RANDOM_NUMBER}") > -1){displayFields("#random_number_length",true);}else{displayFields("#random_number_length",false);}
|
||||
if(this.value.indexOf("{RANDOM_ALPHABETIC}") > -1){displayFields("#random_alphabetic_length",true);}else{displayFields("#random_alphabetic_length",false);}
|
||||
if(this.value.indexOf("{RANDOM_ALPHANUMERIC}") > -1){displayFields("#random_alphanumeric_length",true);}else{displayFields("#random_alphanumeric_length",false);}
|
||||
if(this.value.indexOf("{COUNTER}") > -1){
|
||||
displayFields("#counter_start_at",true);displayFields("#counter_increment_by",true);displayFields(".ResetCounterInterval:eq(0)",true);displayFields(".CounterResetNow:eq(0)",true);displayFields(".CounterReferenceLength:eq(0)",true);
|
||||
if($(".CounterReferenceLength input:checked").val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
if($(".ResetCounterInterval input:checked").val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($(".ResetCounterInterval input:checked").val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
}else{
|
||||
displayFields("#counter_start_at",false);displayFields("#counter_increment_by",false);displayFields(".ResetCounterInterval:eq(0)",false);displayFields(".CounterResetNow:eq(0)",false);displayFields(".CounterReferenceLength:eq(0)",false);displayFields("#counter_reset_number",false);displayFields("#counter_reset_date",false);displayFields("#counter_reference_length",false);
|
||||
}
|
||||
});
|
||||
$(".CounterReferenceLength input").click(function(){
|
||||
if($(this).is(":checked") && $(this).val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
});
|
||||
$(".ResetCounterInterval input").click(function(){
|
||||
if($(this).is(":checked") && $(this).val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($(this).is(":checked") && $(this).val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
});
|
||||
$("#counter_reference_length").bind("keyup change", function(){
|
||||
if(counterActualValue != ""){
|
||||
nextCounterValue = displayReferenceLength($(this).val(), counterActualValue);
|
||||
$("#counter_start_at").parent().find(".help-block:eq(1)").remove();
|
||||
$("#counter_start_at").parent().append("<p class=\'help-block\'>Next counter value: " + nextCounterValue + "</p>");
|
||||
}
|
||||
});
|
||||
$(".modrefchange").on("submit", function(){
|
||||
errorMessage = "";
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && (!isNumber($("#counter_start_at").val()) || $("#counter_start_at").val() == "" || !isNumber($("#counter_increment_by").val()) || $("#counter_increment_by").val() == "" || $("#counter_increment_by").val() < 1 || $("#counter_start_at").val() < 1)){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.numberReferenceFormatError;
|
||||
}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && ($(".ResetCounterInterval input:checked").val() == 3) && (!isNumber($("#counter_reset_number").val()) || $("#counter_reset_number").val() == "" || $("#counter_reset_number").val() < 1)){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.counterResetNumberError;
|
||||
}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && ($(".ResetCounterInterval input:checked").val() == 4) && ($("#counter_reset_date").val() == "" || $("#counter_reset_date").val() == 0 || (counterResetDate.datepicker( "getDate" ) <= new Date()))){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.counterResetDateError;
|
||||
}
|
||||
if($("#reference_number_format").val() == ""){
|
||||
errorMessage += translate.numberReferenceFormatEmptyError;
|
||||
}
|
||||
if(errorMessage.length > 0){
|
||||
alert(errorMessage);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
function displayFields(identification,isDisplay){
|
||||
if(isDisplay){
|
||||
$(identification).parents(".form-group").show();
|
||||
}else{
|
||||
$(identification).parents(".form-group").hide();
|
||||
}
|
||||
}
|
||||
function displayReferenceLength(counterReferenceLengthSelected, counterActualValue){
|
||||
nextCounterValue = "";
|
||||
if(counterReferenceLengthSelected > counterActualValue.toString().length){
|
||||
for (i = 0; i < (counterReferenceLengthSelected - counterActualValue.toString().length); i++){
|
||||
nextCounterValue += "0";
|
||||
}
|
||||
nextCounterValue += counterActualValue;
|
||||
}else{
|
||||
nextCounterValue += counterActualValue;
|
||||
}
|
||||
return nextCounterValue;
|
||||
}
|
||||
function isNumber(value) {
|
||||
if ((undefined === value) || (null === value)){
|
||||
return false;
|
||||
}
|
||||
if (typeof value == "number") {
|
||||
return true;
|
||||
}
|
||||
return !isNaN(value - 0);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 2021 Keshva
|
||||
*
|
||||
* @author Keshva <keshvathakur47@gmail.com>
|
||||
* @copyright 2021 Keshva
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
counterResetDate = $("#counter_reset_date").datepicker({dateFormat: 'yy-mm-dd'});
|
||||
$("#counter_reset_date").prop("readonly", true);
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_NUMBER}") > -1){displayFields("#random_number_length",true);}else{displayFields("#random_number_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_ALPHABETIC}") > -1){displayFields("#random_alphabetic_length",true);}else{displayFields("#random_alphabetic_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{RANDOM_ALPHANUMERIC}") > -1){displayFields("#random_alphanumeric_length",true);}else{displayFields("#random_alphanumeric_length",false);}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1){
|
||||
displayFields("#counter_start_at",true);displayFields("#counter_increment_by",true);displayFields("label[for='counter_reset_interval']:eq(0)",true);displayFields("label[for='counter_reset_now']:eq(0)",true);displayFields("label[for='counter_reference_length_in_use']:eq(0)",true);
|
||||
if($("label[for='counter_reference_length_in_use']:eq(0)").parent().find("input:checked").val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
if($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
if($("label[for='counter_reference_length_in_use']:eq(0)").parent().find("input:checked").val() == 1){
|
||||
nextCounterValue = displayReferenceLength($("#counter_reference_length option:selected").val(), counterActualValue);
|
||||
}else{
|
||||
nextCounterValue = counterActualValue;
|
||||
}
|
||||
$("#counter_start_at").parent().append("<p class=\'help-block\'>Next counter value: " + nextCounterValue + "</p>")
|
||||
}else{
|
||||
displayFields("#counter_start_at",false);displayFields("#counter_increment_by",false);displayFields("label[for='counter_reset_interval']:eq(0)",false);displayFields("label[for='counter_reset_now']:eq(0)",false);displayFields("label[for='counter_reference_length_in_use']:eq(0)",false);displayFields("#counter_reset_number",false);displayFields("#counter_reset_date",false);displayFields("#counter_reference_length",false);
|
||||
}
|
||||
$("#reference_number_format").bind("keyup change", function(e) {
|
||||
if(this.value.indexOf("{RANDOM_NUMBER}") > -1){displayFields("#random_number_length",true);}else{displayFields("#random_number_length",false);}
|
||||
if(this.value.indexOf("{RANDOM_ALPHABETIC}") > -1){displayFields("#random_alphabetic_length",true);}else{displayFields("#random_alphabetic_length",false);}
|
||||
if(this.value.indexOf("{RANDOM_ALPHANUMERIC}") > -1){displayFields("#random_alphanumeric_length",true);}else{displayFields("#random_alphanumeric_length",false);}
|
||||
if(this.value.indexOf("{COUNTER}") > -1){
|
||||
displayFields("#counter_start_at",true);displayFields("#counter_increment_by",true);displayFields("label[for='counter_reset_interval']:eq(0)",true);displayFields("label[for='counter_reset_now']:eq(0)",true);displayFields("label[for='counter_reference_length_in_use']:eq(0)",true);
|
||||
if($("label[for='counter_reference_length_in_use']:eq(0)").parent().find("input:checked").val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
if($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
}else{
|
||||
displayFields("#counter_start_at",false);displayFields("#counter_increment_by",false);displayFields("label[for='counter_reset_interval']:eq(0)",false);displayFields("label[for='counter_reset_now']:eq(0)",false);displayFields("label[for='counter_reference_length_in_use']:eq(0)",false);displayFields("#counter_reset_number",false);displayFields("#counter_reset_date",false);displayFields("#counter_reference_length",false);
|
||||
}
|
||||
});
|
||||
$("label[for='counter_reference_length_in_use']:eq(0)").parent().find("input").click(function(){
|
||||
if($(this).is(":checked") && $(this).val() == 1){displayFields("#counter_reference_length",true);}else{displayFields("#counter_reference_length",false);}
|
||||
});
|
||||
$("label[for='counter_reset_interval']:eq(0)").parent().find("input").click(function(){
|
||||
if($(this).is(":checked") && $(this).val() == 3){displayFields("#counter_reset_number",true);}else{displayFields("#counter_reset_number",false);}
|
||||
if($(this).is(":checked") && $(this).val() == 4){displayFields("#counter_reset_date",true);}else{displayFields("#counter_reset_date",false);}
|
||||
});
|
||||
$("#counter_reference_length").bind("keyup change", function(){
|
||||
if(counterActualValue != ""){
|
||||
nextCounterValue = displayReferenceLength($(this).val(), counterActualValue);
|
||||
$("#counter_start_at").parent().find(".help-block:eq(1)").remove();
|
||||
$("#counter_start_at").parent().append("<p class=\'help-block\'>Next counter value: " + nextCounterValue + "</p>");
|
||||
}
|
||||
});
|
||||
$(".modrefchange").on("submit", function(){
|
||||
|
||||
errorMessage = "";
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && (!isNumber($("#counter_start_at").val()) || $("#counter_start_at").val() == "" || !isNumber($("#counter_increment_by").val()) || $("#counter_increment_by").val() == "" || $("#counter_increment_by").val() < 1 || $("#counter_start_at").val() < 1)){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.numberReferenceFormatError;
|
||||
}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && ($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 3) && (!isNumber($("#counter_reset_number").val()) || $("#counter_reset_number").val() == "" || $("#counter_reset_number").val() < 1)){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.counterResetNumberError;
|
||||
}
|
||||
if($("#reference_number_format").val().indexOf("{COUNTER}") > -1 && ($("label[for='counter_reset_interval']:eq(0)").parent().find("input:checked").val() == 4) && ($("#counter_reset_date").val() == "" || $("#counter_reset_date").val() == 0 || (counterResetDate.datepicker( "getDate" ) <= new Date()))){
|
||||
if(errorMessage.length > 0){
|
||||
errorMessage += ", "
|
||||
}
|
||||
errorMessage += translate.counterResetDateError;
|
||||
}
|
||||
if($("#reference_number_format").val() == ""){
|
||||
errorMessage += translate.numberReferenceFormatEmptyError;
|
||||
}
|
||||
if(errorMessage.length > 0){
|
||||
alert(errorMessage);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
function displayFields(identification,isDisplay){
|
||||
if(isDisplay){
|
||||
$(identification).parents(".form-group").show();
|
||||
}else{
|
||||
$(identification).parents(".form-group").hide();
|
||||
}
|
||||
}
|
||||
function displayReferenceLength(counterReferenceLengthSelected, counterActualValue){
|
||||
nextCounterValue = "";
|
||||
if(counterReferenceLengthSelected > counterActualValue.toString().length){
|
||||
for (i = 0; i < (counterReferenceLengthSelected - counterActualValue.toString().length); i++){
|
||||
nextCounterValue += "0";
|
||||
}
|
||||
nextCounterValue += counterActualValue;
|
||||
}else{
|
||||
nextCounterValue += counterActualValue;
|
||||
}
|
||||
return nextCounterValue;
|
||||
}
|
||||
function isNumber(value) {
|
||||
if ((undefined === value) || (null === value)){
|
||||
return false;
|
||||
}
|
||||
if (typeof value == "number") {
|
||||
return true;
|
||||
}
|
||||
return !isNaN(value - 0);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 2021 Keshva
|
||||
*
|
||||
* @author Keshva <keshvathakur47@gmail.com>
|
||||
* @copyright 2021 Keshva
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
$(".modrefchange .panel-heading").height(63);
|
||||
$(".modrefchange .panel-heading").append("<br/>" + translate.config_title + ":");
|
||||
if ($(".modrefchange .form-group").length == 0) {
|
||||
$(".modrefchange .panel-footer").before("<div class='control-label' style='color:#CA6F6F; font-weight: bold; text-align: center;'>" + translate.missing_employees + "</div>");
|
||||
$(".modrefchange button[name='submitEditOrderPro']").remove();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@@ -0,0 +1,878 @@
|
||||
/*
|
||||
* 2021 Keshva
|
||||
*
|
||||
* @author Keshva <keshvathakur47@gmail.com>
|
||||
* @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 = '<td class="product_action text-right"><div class="btn-group"><button type="button" class="btn btn-default edit_product_change_link"><i class="icon-pencil"></i>' + trans.edit + '</button><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button><ul class="dropdown-menu" role="menu"><li><a href="#" class="delete_product_line"><i class="icon-trash"></i>' + trans.remove + '</a></li></ul></div><button type="button" class="btn btn-default submitProductChange" style="display: none;"><i class="icon-ok"></i>' + trans.update + '</button><button type="button" class="btn btn-default cancel_product_change_link" style="display: none;"><i class="icon-remove"></i>' + trans.cancel + '</button></td>';
|
||||
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('<button type="button" id="add_product" class="btn btn-default"><i class="icon-plus-sign"></i>' + trans.add_product + '</button>');
|
||||
// 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('<a id="orderResendMail" class="btn btn-default" href="javascript:void(0)"><i class="icon-send"></i>' + trans.resend_email + '</a>');
|
||||
}
|
||||
|
||||
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('<th></th>');
|
||||
$('#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('<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() {
|
||||
$('#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'});
|
||||
$('<td><span data-number="' + trCount + '" class="deletePayment pull-right btn btn-default"><i class="icon-trash"></i><span class="preLoading" style="display:none"></span></span></td>').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('<td><span data-number="' + statusesCount + '" class="deleteStatus pull-right btn btn-default"><i class="icon-trash"></i><span class="preLoading" style="display:none"></span></span></td>');
|
||||
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');
|
||||
$('<span class="product_name_edit" style="display:none;"><input type="text" name="product_name" class="edit_product_name" value="' + $(this).find('.productName').html() + '"></span>').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('<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><span class="icon-pencil"></span>');
|
||||
}
|
||||
|
||||
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><span class="icon-pencil"></span>');
|
||||
}
|
||||
|
||||
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'><span class='icon-check classicCheck'></span><span class='icon-remove'></span><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'><span class='icon-check shippingCostCheck'></span><span class='icon-remove'></span><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") {
|
||||
$('#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 = $('<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, 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();
|
||||
}
|
||||
@@ -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