"use strict"; var luna_utils = {}; // let ddmmyyy = luna_utils.convert_from_yyyymmdd_to_ddmmyyy(yyyymmdd) luna_utils.convert_from_yyyymmdd_to_ddmmyyy = function(yyyymmdd) { let [year, month, day] = yyyymmdd.split('-'); day = day.padStart(2, '0'); month = month.padStart(2, '0'); return `${day}/${month}/${year}`; }; // let ddmmyyy__hhmmss = luna_utils.convert_from_yyyymmdd__hhmmss_to_ddmmyyy__hhmmss(yyyymmdd__hhmmss) luna_utils.convert_from_yyyymmdd__hhmmss_to_ddmmyyy__hhmmss = function(yyyymmdd__hhmmss) { let [yyyymmdd, hhmmss] = yyyymmdd__hhmmss.split(' '); const ddmmyyy = luna_utils.convert_from_yyyymmdd_to_ddmmyyy(yyyymmdd); return ddmmyyy + " " + hhmmss; }; luna_utils.show_solution = function(error_message, solution) { const response = { response_code: -1, response_message: error_message, solution: solution, }; if (luna_app.is_mobile_app) { dsplma.render_menu(false); dsplma.show_response_message(response); } else { luna_app.close_page(); luna_app.show_response_message(response); } }; luna_utils.get_solution = function(priv_id) { let sub_steps = []; if (priv_id == 10001) { sub_steps = [ 'Login to ERP as Administrator', 'Go to Control Panel -> Administration -> Assign Privilege Scope', 'Select Privilege Feed Attendance', 'Select Year ' + luna_utils.get_session_name(luna_datac.current_academic_session ) + '', 'Select User ' + luna_datac.login_id + '', 'Click Show button', 'Tick required Class(es)', 'Click Save button', ]; } if (priv_id == 5001) { sub_steps = [ 'Login to ERP as Administrator', 'Go to Control Panel -> Administration -> Assign Privilege Scope', 'Select Privilege Feed Marks', 'Select Year ' + luna_utils.get_session_name(luna_datac.current_academic_session ) + '', 'Select User ' + luna_datac.login_id + '', 'Select Class as applicable', 'Click Show button', 'Tick required Subject(s)', 'Click Save button', ]; } if (priv_id == 4059) { sub_steps = [ 'Login to ERP as Administrator', 'Go to Control Panel -> Administration -> Assign Privilege Scope', 'Select Privilege Student Module', 'Select Year ' + luna_utils.get_session_name(luna_datac.current_academic_session ) + '', 'Select User ' + luna_datac.login_id + '', 'Click Show button', 'Tick required Class(es)', 'Click Save button', ]; } let solution = [ {'heading' : 'Request your Administrator to do this:', 'sub_steps' : sub_steps}, {'heading' : 'After your Administrator completes the above steps, you need to log off and login again'}, ]; if (sub_steps.length == 0) { solution = []; } return solution; }; /* luna_utils.fetch = async function(url, options, success_function) { try { console.log('fetch_using_get. a1 ' + url); let response = await fetch(url); console.log('fetch_using_get. a2 ' + JSON.stringify(response)); let text = await response.text(); console.log('fetch_using_get. a3'); success_function(text); console.log('fetch_using_get. a4'); } catch(err) { console.log('fetch_using_get err'); console.log(err.message); console.log(err.name); // console.log(err.stack); console.log(JSON.stringify(err)); } }; luna_utils.fetch_using_get = function(url, options, success_function) { try { console.log('fetch_using_get a1 a' + url); fetch(url).then(function(response) { console.log('fetch_using_get a2'); response.text().then( function(text) { console.log('fetch_using_get a3'); success_function(text); console.log('fetch_using_get a4'); } ); }); console.log('fetch_using_get a1 b' + url); } catch(err) { console.log('fetch_using_get err'); console.log(JSON.stringify(err)); } }; */ luna_utils.log = function(input) { if (luna_app.is_mobile_app) { dsplma.log(input); } else { console.log(input); } }; luna_utils.get_current_time_hh_mm_ss = function() { const date = new Date(); let hours = date.getHours(); let minutes = date.getMinutes(); let seconds = date.getSeconds(); hours = hours > 9 ? hours : '0' + hours; minutes = minutes > 9 ? minutes : '0' + minutes; seconds = seconds > 9 ? seconds : '0' + seconds; return hours + ":" + minutes + ":" + seconds; }; luna_utils.process_luna_datac = function() { luna_datac.bank_fee_collection_modes = luna_utils.filter_JSON_Array(luna_datac.fee_collection_modes, 'fcm_type', 'BANK'); }; luna_utils.auto_correct_mobile_num_field = function($field) { try { let value = $field.val(); value = "" + value; let new_val = luna_utils.replaceAll(value, ' ', ''); new_val = luna_utils.replaceAll(new_val, '/', ','); if (new_val != value) { $field.val(new_val); value = new_val; } return value; } catch(err) { return 'ERR9484727'; // luna_utils.auto_correct_mobile_num_field2($field); } }; luna_utils.set_val = function(field_id, value, default_value) { value = typeof value == 'undefined' ? default_value : value; $("#" + field_id).val(value); }; luna_utils.get_current_month_num = function() { const d = new Date(); return 1 + d.getMonth(); }; luna_utils.get_response = function(___ca, data2send, success_function, options) { if (luna_app.is_mobile_app) { dsplma.sendMessageToServer(___ca, data2send, success_function); } else { let request_object = { ___ca : ___ca, data2send : data2send, success_function : success_function }; if (typeof options != 'undefined') { for (let attr in options) { request_object[attr] = options[attr]; } } luna_ws.get_response(request_object); } }; luna_utils.show_response_message = function(response) { if (luna_app.is_mobile_app) { return dsplma.show_response_message(response); } return luna_app.show_response_message(response); }; luna_utils.today_dd_mmm_yyyy = function() { const date = new Date(); const formattedDate = date.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', }).replace(/ /g, '-'); return formattedDate; }; luna_utils.fill_luna_dynamic_css = function() { var luna_dynamic_css = ''; var att_codes = luna_datac.att_codes; for (var x=0; x' + current_phone_number + ' '; } if (link_type == 'whatsapp') { links += '' + current_phone_number + ' '; } } } return links; }; luna_utils.array_union = function(array1, array2) { return Array.from(new Set(array1.concat(array2))); }; /* luna_utils.get_current_time_rounded_to_next_30_mins = function(hours_to_add, minutes_to_add) { hours_to_add = 1 * hours_to_add; minutes_to_add = 1 * minutes_to_add; let date = new Date(); let hours = date.getHours(); hours = hours + hours_to_add; let minutes = date.getMinutes(); minutes = minutes + minutes_to_add; if (minutes > 30) { minutes = 0; hours++; } else if (minutes > 0) { minutes = 30; } if (hours > 23) { hours = 0; } hours = hours.toString().length == 1 ? '0' + hours : hours; minutes = minutes.toString().length == 1 ? '0' + minutes : minutes; let pickup_time = hours + ':' + minutes; }; */ luna_utils.htmlentities = function(str) { return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); }; /* 156 Grm Gram 16 0 Gram GMS 1.000 157 KG Kilogram 28 Gram 1000.000 0 Gram KGS 1000.000 166 Q Quintal 248 Kilogram 100.000 0 Gram 100000.000 188 Bags Bags 402 0 Bags 1.000 4357 bag_psc Bag Pieces 403 Bags 2.000 0 Bags 2.000 luna_utils.convert_unit(3200, 156, 157, 0, 0, 0) // - 3.2 luna_utils.convert_unit(3.2, 157, 156, 0, 0, 0) // - 3200 luna_utils.convert_unit(3.2, 166, 157, 0, 0, 0) // - 320 luna_utils.convert_unit(3.2, 188, 156, 188, 156, 500) // - 1600 luna_utils.convert_unit(1600, 156, 188, 188, 156, 500) // - 3.2 luna_utils.convert_unit(1600, 156, 188, 188, 156, 500) // - 3.2 */ luna_utils.convert_unit = function(src_unit_qty, src_unit_id, dest_unit_id, alternate_unit_id, base_unit_id_of_product, alternate_unit_conversion_value) { let inv2_units = luna_datac.inv2_units; let src_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', src_unit_id); let dest_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', dest_unit_id); if (src_unit.base_unit_id == dest_unit.base_unit_id) { return (src_unit_qty * src_unit.conversion_value_with_base_unit) / dest_unit.conversion_value_with_base_unit; } let alternate_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', alternate_unit_id); if (src_unit.base_unit_id == base_unit_id_of_product) { return (src_unit_qty * src_unit.conversion_value_with_base_unit * alternate_unit_conversion_value * alternate_unit.conversion_value_with_base_unit) / dest_unit.conversion_value_with_base_unit; } else if (dest_unit.base_unit_id == base_unit_id_of_product) { return (src_unit_qty * src_unit.conversion_value_with_base_unit) / (alternate_unit_conversion_value * alternate_unit.conversion_value_with_base_unit) / dest_unit.conversion_value_with_base_unit; } return 0; }; luna_utils.copy_to_clipboard = function(text) { var $temp = $(''); $("body").append($temp); $temp.val(text).select(); document.execCommand("copy"); $temp.remove(); }; luna_utils.delete_icon = ''; luna_utils.crop_image_icon = ''; luna_utils.is_element_fully_visible_in_viewport = function(element_id) { if ($("#" + element_id).is(":visible")) { let el = document.getElementById(element_id); var rect = el.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom + 15 <= (window.innerHeight || document.documentElement.clientHeight) && /* or $(window).height() */ rect.right + 15 <= (window.innerWidth || document.documentElement.clientWidth) /* or $(window).width() */ ); } return false; }; luna_utils.clear_cache = function() { if (localStorage.last_login_date == luna_d.today()) { return; } const keys = Object.keys(localStorage); let key = ''; for (let x=0; x= 0; i--) { if (array[i] == element) { array.splice(i, 1); count++; } } return count; }; luna_utils.numeric_val_from_field = function(field_id, default_value_if_blank) { var val = $("#" + field_id).val(); return luna_utils.numeric_val(val, default_value_if_blank); }; luna_utils.numeric_val = function(val, default_value_if_blank) { val = typeof val == 'undefined' ? '' : val; val = "" + val; val = luna_utils.replaceAll(val, ',', ''); if (val == '') { return default_value_if_blank; } if (!$.isNumeric(val)) { return default_value_if_blank; } return 1 * val; }; luna_utils.get_sum2 = function(jquery_elements, sum_function) { var sum = 0; var text; jquery_elements.each(function () { text = $(this).text(); if (sum_function != undefined) { sum = eval(sum_function + '(sum, text)'); } else { text = luna_utils.replaceAll(text, ',', ''); if ($.isNumeric(text)) { sum += (1 * text); } } }); return sum; }; luna_utils.get_sum = function(jquery_selector, sum_function) { return luna_utils.get_sum2($(jquery_selector), sum_function); }; luna_utils.compare_string_ignore_case = function(a, b) { return a.localeCompare(b, undefined, {numeric: true, sensitivity: 'base'}); }; // Both strings should be of format mmm yyyy. Example : Aug 2023 luna_utils.compare_mmm_yyyy_strings = function(str1, str2) { str1 = str1.toUpperCase(); str2 = str2.toUpperCase(); str1 = str1.split(' '); str2 = str2.split(' '); const month1 = luna_utils.month_names_short.indexOf(str1[0]); const month2 = luna_utils.month_names_short.indexOf(str2[0]); return str2[1] - str1[1] || month2 - month1; }; luna_utils.compare_date_strings = function(a, b) { a = a.split('/'); b = b.split('/'); return b[2] - a[2] || b[1] - a[1] || b[0] - a[0]; }; luna_utils.get_unique_text_array = function(jquery_selector, max_text_length, is_input_element) { is_input_element = typeof is_input_element == 'undefined' ? false : is_input_element; var array = []; var values_with_count = []; var value; var index = -1; $(jquery_selector).each(function () { if (is_input_element) { value = $(this).val(); if ($(this).attr('filter_with_text') == 'true') { value = $(this).find('option[value="' + value + '"]').text(); } } else { value = $(this).text(); } if (max_text_length > 0) { value = value.substring(0, max_text_length); } index = array.indexOf(value); if (index == -1) { array.push(value); values_with_count.push({'value': value, count: 1}); } else { values_with_count[index].count = values_with_count[index].count + 1; } }); // array.sort(luna_utils.compare_string_ignore_case); let object = {}; object.values_without_count = array; object.values_with_count = values_with_count; return object; }; luna_utils.get_unique_values_with_count = function(two_d_array, column_name, max_text_length) { max_text_length = typeof max_text_length == 'undefined' ? 0 : max_text_length; var values_with_count = []; var values_without_count = []; var cell_text = ''; var index = -1; for (var x=0; x 0) { cell_text = cell_text.substring(0, max_text_length); } index = values_without_count.indexOf(cell_text); if (index != -1) { values_with_count[index].count++; continue; } values_without_count.push(cell_text); values_with_count.push({'value': cell_text, 'count': 1}); } let object = {}; object.values_without_count = values_without_count; object.values_with_count = values_with_count; return object; }; luna_utils.check_has_attributes = function(object, object_name, attributes_array) { var errors = 0; for (var x=0; x= thresh && u < units.length - 1); return bytes.toFixed(1)+' '+units[u]; }; luna_utils.countries = [ {'value':'India', 'text':'India'} ]; luna_utils.allowed_attachment_extensions = [ '.docx', '.xlsx', '.doc', '.pdf', '.xls', '.png', '.bmp', '.txt', '.jpg', '.jpeg', '.gif', ]; // Test case: luna_utils.round(10.17 * 150 * 0.09, 2) luna_utils.round = function(input, decimals) { let pow = Math.pow(10, decimals); input = 1 * input; return Math.round((input + 0.000001) * pow) / pow; }; luna_utils.search_2d_array = function(array, key, value) { for (var x=0; x" + display_text + ""); }; luna_utils.remove_other_options_from_dropdown = function(field_id, values2retain) { var values = []; $('#' + field_id + ' option').each(function() { values.push( $(this).attr('value') ); }); var x = 0; for (x=0; x 0) { cell_text = cell_text.substring(0, max_text_length); } if (remove_duplicates && one_d_array.indexOf(cell_text) != -1) { continue; } one_d_array.push(cell_text); } return one_d_array; }; luna_utils.delete_column = function(two_d_array, column_name) { for (var x=0; x 0) { if (index == (hash_split_array.length - 1)) { // reach through last element of hash_split_array then end the loop loop_num = 0; } matched_array = luna_utils.match_content_in_JSON_Array(temp_array, column_to_search, hash_split_array[index]); // if found with the first param - for example /#___ca=20068088 if (matched_array.length > 0) { temp_array = matched_array; // now the filtered arrays which has /#___ca=20068088 becomes the array to loop in if (matched_array.length == 1) { // if only one result found then return this array and end the loop result = temp_array[0]; loop_num = 0; } } index++; } } return result; }; // Returns an array with those records in json_array1, where matching record is present in json_array2 // Other attributes are not checked luna_utils.filter_json_array_with_json_array = function(json_array1, array1_column_to_search, json_array2, array2_column_to_search) { let matches = []; for (var x=0; x 1) { luna_app.show_error_message("Please select only one " + entity_name); return -1; } return $(selected_elements[0]).val(); }; luna_utils.ensure_at_least_one_cbx_selected = function(cbx_selector, entity_name) { var selected_cbx = $(cbx_selector); var ids = []; if (selected_cbx.length == 0) { // luna_app.show_error_message("Please select a " + entity_name); luna_app.show_error_message("No " + entity_name + " selected"); return ids; } for (var i=0; i 0) { // All checkbox should be checked only if there are any rows in the grid. $select_all_cbx.prop('checked', total_checkboxes == checked_checkboxes); } }); if ($cbx.length > 0) { $cbx.first().change(); } }; luna_utils.sortJsonArrayByKey = function(array, key, sort_direction) { if (typeof sort_direction == 'undefined') { var indexOfComma = key.indexOf(","); if (indexOfComma == -1) { sort_direction = 'ascending'; } else { let keys = key.split(","); sort_direction = ('ascending,').repeat(keys.length); } } return array.sort(function(stu1, stu2) { return luna_utils.sortJsonArrayElementsByKey(stu1, stu2, key, sort_direction); }); }; luna_utils.sortJsonArrayElementsByKey = function(object1, object2, key, sort_direction) { var indexOfComma = key.indexOf(","); var x = ""; var y = ""; let result = 0; if (indexOfComma === -1) { x = object1[key]; y = object2[key]; result = luna_utils.compare(x, y); if (result != 0 && sort_direction != 'ascending') { if (result == -1) { result = 1; } else { result = -1; } } return result; } let keys = key.split(","); let p = 0; let sort_direction_array = sort_direction.split(','); let prop1 = ''; let prop2 = ''; for (p=0; p y) { return 1; } return 0; }; luna_utils.formatNumberToIndian = function(num) { let numStr = num.toString(); let array = numStr.split('.'); let integerPart = array[0].toString(); let lastThree = integerPart.slice(-3); // Take the last three digits let otherNumbers = integerPart.slice(0, -3); // Remaining part of the number // Insert commas for the Indian format (every two digits after the first three) if (otherNumbers !== '') { lastThree = ',' + lastThree; } let decimal_part = array[1] ? '.' + array[1] : ''; return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree + decimal_part; }; luna_utils.format_number = function(number, digits_after_decimal) { number = 1 * number; digits_after_decimal = (digits_after_decimal < 1 || digits_after_decimal == undefined) ? 0 : digits_after_decimal; var formatted_number = number.toFixed(digits_after_decimal); formatted_number = luna_utils.formatNumberToIndian(formatted_number); return formatted_number; }; luna_utils.format_number_as = function(number, format_str) { if (format_str && $.isNumeric(number)) { // it is for verifying the alphabets var array = format_str.split('/'); if (array.length == 2 && array[0] == 'en-IN') { // Expected format is "en-IN/x" where x is an integer between 0 and 5 var digits_after_decimal = 1 * array[1]; if (digits_after_decimal >= 0 && digits_after_decimal <= 5) { return luna_utils.format_number(number, array[1]); } } } return number; }; luna_utils.scheduled_times = [ {'value' : '00:00', 'text' : '00:00 Midnight'}, {'value' : '00:30', 'text' : '00:30 AM'}, {'value' : '01:00', 'text' : '01:00 AM'}, {'value' : '01:30', 'text' : '01:30 AM'}, {'value' : '02:00', 'text' : '02:00 AM'}, {'value' : '02:30', 'text' : '02:30 AM'}, {'value' : '03:00', 'text' : '03:00 AM'}, {'value' : '03:30', 'text' : '03:30 AM'}, {'value' : '04:00', 'text' : '04:00 AM'}, {'value' : '04:30', 'text' : '04:30 AM'}, {'value' : '05:00', 'text' : '05:00 AM'}, {'value' : '05:30', 'text' : '05:30 AM'}, {'value' : '06:00', 'text' : '06:00 AM'}, {'value' : '06:30', 'text' : '06:30 AM'}, {'value' : '07:00', 'text' : '07:00 AM'}, {'value' : '07:30', 'text' : '07:30 AM'}, {'value' : '08:00', 'text' : '08:00 AM'}, {'value' : '08:30', 'text' : '08:30 AM'}, {'value' : '09:00', 'text' : '09:00 AM'}, {'value' : '09:30', 'text' : '09:30 AM'}, {'value' : '10:00', 'text' : '10:00 AM'}, {'value' : '10:30', 'text' : '10:30 AM'}, {'value' : '11:00', 'text' : '11:00 AM'}, {'value' : '11:30', 'text' : '11:30 AM'}, {'value' : '12:00', 'text' : '12:00 Noon'}, {'value' : '12:30', 'text' : '12:30 PM'}, {'value' : '13:00', 'text' : '01:00 PM'}, {'value' : '13:30', 'text' : '01:30 PM'}, {'value' : '14:00', 'text' : '02:00 PM'}, {'value' : '14:30', 'text' : '02:30 PM'}, {'value' : '15:00', 'text' : '03:00 PM'}, {'value' : '15:30', 'text' : '03:30 PM'}, {'value' : '16:00', 'text' : '04:00 PM'}, {'value' : '16:30', 'text' : '04:30 PM'}, {'value' : '17:00', 'text' : '05:00 PM'}, {'value' : '17:30', 'text' : '05:30 PM'}, {'value' : '18:00', 'text' : '06:00 PM'}, {'value' : '18:30', 'text' : '06:30 PM'}, {'value' : '19:00', 'text' : '07:00 PM'}, {'value' : '19:30', 'text' : '07:30 PM'}, {'value' : '20:00', 'text' : '08:00 PM'}, {'value' : '20:30', 'text' : '08:30 PM'}, {'value' : '21:00', 'text' : '09:00 PM'}, {'value' : '21:30', 'text' : '09:30 PM'}, {'value' : '22:00', 'text' : '10:00 PM'}, {'value' : '22:30', 'text' : '10:30 PM'}, {'value' : '23:00', 'text' : '11:00 PM'}, {'value' : '23:30', 'text' : '11:30 PM'}, ]; luna_utils.shop_app_delivery_times = [ {'value' : '09:00', 'text' : '09:00 AM'}, {'value' : '09:30', 'text' : '09:30 AM'}, {'value' : '10:00', 'text' : '10:00 AM'}, {'value' : '10:30', 'text' : '10:30 AM'}, {'value' : '11:00', 'text' : '11:00 AM'}, {'value' : '11:30', 'text' : '11:30 AM'}, {'value' : '12:00', 'text' : '12:00 Noon'}, {'value' : '12:30', 'text' : '12:30 PM'}, {'value' : '13:00', 'text' : '01:00 PM'}, {'value' : '13:30', 'text' : '01:30 PM'}, {'value' : '14:00', 'text' : '02:00 PM'}, {'value' : '14:30', 'text' : '02:30 PM'}, {'value' : '15:00', 'text' : '03:00 PM'}, {'value' : '15:30', 'text' : '03:30 PM'}, {'value' : '16:00', 'text' : '04:00 PM'}, {'value' : '16:30', 'text' : '04:30 PM'}, {'value' : '17:00', 'text' : '05:00 PM'}, {'value' : '17:30', 'text' : '05:30 PM'}, {'value' : '18:00', 'text' : '06:00 PM'}, {'value' : '18:30', 'text' : '06:30 PM'}, {'value' : '19:00', 'text' : '07:00 PM'}, {'value' : '19:30', 'text' : '07:30 PM'}, {'value' : '20:00', 'text' : '08:00 PM'}, {'value' : '20:30', 'text' : '08:30 PM'}, {'value' : '21:00', 'text' : '09:00 PM'}, ]; luna_utils.array_seperator = '~!#~'; luna_utils.has_scope_access = function(array_to_filter, col_to_filter_by, priv_id, year_id, object_id_to_check_access) { let access = luna_utils.filter_options_based_on_my_priv_scope(array_to_filter, col_to_filter_by, priv_id, year_id, true); // console.log("access = ", access); let record = luna_utils.filter_JSON_Array(access, col_to_filter_by, object_id_to_check_access); // console.log("record = ", record); // console.log("object_id_to_check_access = ", object_id_to_check_access); return record.length > 0; }; luna_utils.is_scope_filter_applicable = function(priv_id) { if (luna_datac.user_type_id < 30 || luna_utils.search_JSON_array(luna_datac.privileges_with_scope, 'priv_id', priv_id) == false) { return false; } return true; }; luna_utils.filter_subjects_based_on_my_feed_marks_scope = function() { // let subjects = luna_utils.filter_options_based_on_my_priv_scope(luna_datac.subjects, 'subject_id', 5001, year_id, true); }; // luna_utils.filter_options_based_on_my_priv_scope(luna_datac.classes, 'class_id', 2021, 'class_id', 2021) luna_utils.filter_options_based_on_my_priv_scope = function(array_to_filter, col_to_filter_by, priv_id, year_id, exit_if_no_records_found) { exit_if_no_records_found = typeof exit_if_no_records_found !== 'undefined' ? exit_if_no_records_found : true; let return_value = []; if (!luna_utils.is_scope_filter_applicable(priv_id)) { return array_to_filter; } if (luna_core.has_privilege(priv_id)) { let filtered_scope = luna_utils.filter_JSON_Array(luna_datac.my_priv_scope, 'priv_id', priv_id); if (year_id > 0) { filtered_scope = luna_utils.filter_JSON_Array(filtered_scope, 'year_id', year_id); } let values = luna_utils.array_column(filtered_scope, col_to_filter_by); return_value = luna_utils.filter_JSON_Array_with_array(array_to_filter, col_to_filter_by, values); } if (exit_if_no_records_found) { if (return_value.length == 0) { let solution = luna_utils.get_solution(priv_id); let error_message = "You do not have sufficient permission scope to perform this action."; if (!luna_core.has_privilege(priv_id)) { error_message = "You do not have sufficient permission to perform this action. Error P-" + priv_id + ". Please contact your Administrator / Customer Care."; solution = []; } luna_utils.show_solution(error_message, solution); return false; } } return return_value; }; luna_utils.luna_md5 = function(string) { return md5_lib.md5("luna "+string+" md5 ~!@#$%^&*()_=-+ "+string+" LUNA"); }; luna_utils.exportToJsonFile = function(json_data, file_name_with_extension) { let dataStr = JSON.stringify(json_data); dataStr = dataStr.replace(/\\/g,''); let linkElement = document.createElement('a'); linkElement.setAttribute('href', 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr)); linkElement.setAttribute('download', file_name_with_extension); linkElement.click(); }; luna_utils.get__filtered_party_ledgers = function(VOUCHER_TYPE_ID) { var party_ledgers = []; var temp_ledgers = []; VOUCHER_TYPE_ID = typeof VOUCHER_TYPE_ID == 'undefined' ? -1 : VOUCHER_TYPE_ID; temp_ledgers = luna_utils.filter_JSON_Array(luna_datac.acc_ledgers, 'ledger_group_template_id', luna_core.hc__ledger_template_cash_in_hand); party_ledgers = party_ledgers.concat(temp_ledgers); if (VOUCHER_TYPE_ID == -1 || VOUCHER_TYPE_ID == luna_core.hc__voucher_types__purchase_invoices || VOUCHER_TYPE_ID == luna_core.hc__voucher_types__purchase_returns) { temp_ledgers = luna_utils.filter_JSON_Array(luna_datac.acc_ledgers, 'ledger_group_template_id', luna_core.hc__ledger_template_sundry_creditors); // PURCHASE party_ledgers = party_ledgers.concat(temp_ledgers); } if (VOUCHER_TYPE_ID == -1 || VOUCHER_TYPE_ID == luna_core.hc__voucher_types__sale_invoices || VOUCHER_TYPE_ID == luna_core.hc__voucher_types__sale_returns) { temp_ledgers = luna_utils.filter_JSON_Array(luna_datac.acc_ledgers, 'ledger_group_template_id', luna_core.hc__ledger_template_sundry_debtors); // SALE party_ledgers = party_ledgers.concat(temp_ledgers); } temp_ledgers = luna_utils.filter_JSON_Array(luna_datac.acc_ledgers, 'show_in_purcase_and_sale_both', 1); party_ledgers = party_ledgers.concat(temp_ledgers); return party_ledgers; }; /* luna_utils.convert_unitx = function(src_unit_qty, src_unit_id, dest_unit_id, alternate_unit_id, base_unit_id_of_product, alternate_unit_conversion_value) { let inv2_units = luna_datac.inv2_units; let src_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', src_unit_id); let dest_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', dest_unit_id); if (src_unit.base_unit_id == dest_unit.base_unit_id) { return (src_unit_qty * src_unit.conversion_value_with_base_unit) / dest_unit.conversion_value_with_base_unit; } let alternate_unit = luna_utils.search_JSON_array(inv2_units, 'unit_id', alternate_unit_id); if (src_unit.base_unit_id == base_unit_id_of_product) { return ((src_unit_qty * src_unit.conversion_value_with_base_unit) * (alternate_unit_conversion_value * dest_unit.conversion_value_with_base_unit)) * alternate_unit.conversion_value_with_base_unit; } else if (dest_unit.base_unit_id == base_unit_id_of_product) { return ((src_unit_qty * src_unit.conversion_value_with_base_unit / alternate_unit_conversion_value) / alternate_unit.conversion_value_with_base_unit) / dest_unit.conversion_value_with_base_unit; } return 0; }; */ luna_utils.apply_form_field_settings = function(page_id) { if (luna_datac.sys_form_field_settings) { let sys_form_field_settings = luna_utils.filter_JSON_Array(luna_datac.sys_form_field_settings, 'page_id', page_id); if (sys_form_field_settings.length > 0) { let field_id = ''; let default_value = ''; for (let x=0; x
').removeClass(['border', 'border-dark']); body_element_id = 'body_content_div'; footer_element_id = 'button_content_div'; $("#" + footer_element_id).append(''); $("#__ng_Modal_dialog").removeClass('h-100').addClass('modal-dialog-centered'); } else { $("#__ng_Modal_dialog").removeClass('modal-xl').addClass('modal-dialog-centered d-flex mt-0'); $("#__ng_Modal_content_div").css("width", "500px"); $("#__ng_close_btn").addClass('btn-danger btn-md').removeClass(['btn-sm', 'btn-info']); $("#" + footer_element_id).addClass('justify-content-center border-0 p-3'); $("#__ng_close_btn_label").html('Cancel'); } $("#" + body_element_id).html('
\
\ \
\
\
' + confirmation_message + '
\
\
'); $("#" + header_element_id).hide(); $("#__ng_Modal_confirm_button").remove(); $("#" + footer_element_id).prepend(''); $("#" + modal_element_id).modal('show'); $('#' + footer_element_id).off('click'); // $('#' + modal_element_id).off('hidden.bs.modal'); // $('#' + modal_element_id).off('shown.bs.modal'); let handle_hidden_bs_modal_event = true; let handle_success_bs_modal_event = false; $("#" + footer_element_id).on('click', '#__ng_Modal_confirm_button', function(e) { handle_hidden_bs_modal_event = false; handle_success_bs_modal_event = true; $("#" + modal_element_id).modal('hide'); }); $("#" + footer_element_id).on('click', '#__ng_close_btn' ,function(e) { handle_hidden_bs_modal_event = true; /* handle_hidden_bs_modal_event = false; if (cancel_function) { cancel_function(e); } */ }); $("#" + modal_element_id).on('hidden.bs.modal', function(e) { if (confirm_function && handle_success_bs_modal_event) { confirm_function(e); handle_success_bs_modal_event = false; return; } if (cancel_function && handle_hidden_bs_modal_event) { cancel_function(e); handle_hidden_bs_modal_event = false; } }); $("#" + modal_element_id).on('shown.bs.modal', function() { $("#__ng_close_btn").focus(); }); }; luna_utils.get_current_file_id = function() { let FILE_ID = 0; // luna_app.get_hash_param_value('___ca', 0); if (luna_utils.is_sg_page()) { FILE_ID = luna_tf.get_report_id(); // returns the page id - r_id in case of SG } else { FILE_ID = $("#hot_t_id").val(); // same id stores the file_id for hot and hotm } return FILE_ID; }; luna_utils.is_sg_page = function() { if (!luna_app.is_mobile_app) { const CA_ID = luna_app.get_hash_param_value('___ca', 0); if (CA_ID == 20068088 || CA_ID == 20631258) { // sg or dashboard return true; } return $("div.sg_table_wrapper").length > 0; } return ($("div.sg_output_table_container_div").length > 0) || ($("#___ca_id").val() > 0); }; luna_utils.is_object_editor_page = function() { const CA_ID = luna_utils.get_param_value('___ca', 0); return CA_ID == '20846594' || $("#__is_object_editor__").length == 1; }; luna_utils.is_hot2_page = function() { if (!luna_app.is_mobile_app) { const CA_ID = luna_app.get_hash_param_value('___ca', 0); return CA_ID == 20741645; } return false; }; luna_utils.is_hot_3k = function() { if (luna_app.is_mobile_app) { return $("#hot_container_div").length > 0; } else { let force_hot3k = luna_utils.get_param_value('force_hot3k', 0); if (force_hot3k == 1) { $("#hot_switch_span").hide(); return $("#hot_container_div").length > 0; } let current_page_switch_type = $("#current_page_switch_type").val(); current_page_switch_type = typeof current_page_switch_type == 'undefined' ? '' : current_page_switch_type; if (current_page_switch_type == '') { if (luna_app.is_mobile_browser()) { return $("#hot_container_div").length > 0 || luna_utils.is_hot2_page(); } } else { return current_page_switch_type == 2; } } return false; }; luna_utils.is_mobile_browser = function() { // return $(window).width() < 768; var check = false; (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera); return check; }; luna_utils.add_lock_icon_event_listener = function(COLUMN_ID) { // Called from luna_hf.add_lock_icon $("#" + COLUMN_ID).on('change', function() { const FILE_ID = luna_utils.get_current_file_id(); if (luna_datac.um_locked_field_values && FILE_ID > 0) { let record = luna_utils.search_JSON_array_with_2_values(luna_datac.um_locked_field_values, 'file_id', FILE_ID, 'column_id', COLUMN_ID); if (record) { let current_value = $(this).val(); let icon_element = $("#field_lock_icon_" + COLUMN_ID); if (current_value != record.locked_value) { icon_element.addClass('different_from_locked_value'); } else { icon_element.removeClass('different_from_locked_value'); } } } }); }; luna_utils.field_lock_icon_clicked = function(COLUMN_ID) { // Sends lock setting to server const FILE_ID = luna_utils.get_current_file_id(); if (FILE_ID > 0) { let field_lock_icon = $("#field_lock_icon_" + COLUMN_ID); let delete_record = field_lock_icon.hasClass('unlocked') ? 0 : 1; if (delete_record == 1 && field_lock_icon.hasClass('different_from_locked_value')) { delete_record = 0; } let LOCKED_VALUE = ''; let data2send = 'COLUMN_ID=' + COLUMN_ID + '&FILE_ID=' + FILE_ID + '&delete_record=' + delete_record; if (delete_record == 0) { LOCKED_VALUE = $("#" + COLUMN_ID).val(); data2send += '&LOCKED_VALUE=' + LOCKED_VALUE; } luna_utils.get_response(10368605, data2send, function(response) { if (response.response_code == 1) { luna_app.show_success_message(response.response_message); field_lock_icon.removeClass('different_from_locked_value'); luna_datac.um_locked_field_values = response.um_locked_field_values; if (delete_record == 1) { luna_utils.set_unlock_icon(COLUMN_ID); // show unlock icon } else { luna_utils.set_lock_icon(COLUMN_ID); // show lock icon } } else { luna_app.show_error_message(response.response_message); } }); } else { luna_app.show_error_message('File ID not found. ' + luna_utils.please_contact_customer_care); } }; luna_utils.set_lock_icon = function(COLUMN_ID) { // show lock icon let icon_element = $("#field_lock_icon_" + COLUMN_ID); icon_element.removeClass(['unlocked', 'fa-unlock']); icon_element.addClass('fa-lock locked'); }; luna_utils.set_unlock_icon = function(COLUMN_ID) { // show unlock icon let icon_element = $("#field_lock_icon_" + COLUMN_ID); icon_element.addClass('unlocked fa-unlock'); icon_element.removeClass(['fa-lock', 'locked']); }; luna_utils.apply_locked_field_values = function(FILE_ID) { // gets called from sg.js inside luna_sg.populate_form_from_cache if (luna_datac.um_locked_field_values) { let records = luna_utils.filter_JSON_Array(luna_datac.um_locked_field_values, 'file_id', FILE_ID); let COLUMN_ID = ''; let LOCKED_VALUE = ''; if (records.length > 0) { for (let x=0; x 0) { // if multipleSelect - use setSelects method LOCKED_VALUE = LOCKED_VALUE.split(','); $("#" + COLUMN_ID).multipleSelect('setSelects', LOCKED_VALUE); } else { // not setting the value through val() method in case of multiselect - because setSelects does that $("#" + COLUMN_ID).val(LOCKED_VALUE); // updates the column value to locked value present in cache } if ($("#" + COLUMN_ID + '_chosen').length > 0) { // if chosen visible $("#" + COLUMN_ID).trigger('chosen:updated'); // updates the chosen dropdown } luna_utils.set_lock_icon(COLUMN_ID); // applies lock icon } } } }; luna_utils.last_scrollLeft = 0; luna_utils.window_scoll_timer = -1; luna_utils.stick_elements_to_left_while_scrolling = function() { // adding left to the elemets given - making the elements stick to left while scrollingx if (luna_utils.window_scoll_timer != -1) { window.clearTimeout(luna_utils.window_scoll_timer); } luna_utils.window_scoll_timer = window.setTimeout(function() { let new_scrollLeft = $(this).scrollLeft(); if (new_scrollLeft != luna_utils.last_scrollLeft) { $('.window_scroll_sticky_left_element').css('left', new_scrollLeft + 'px'); luna_utils.last_scrollLeft = new_scrollLeft; luna_utils.prevent_overscrolling_of_report(); } }, 20); }; luna_utils.prevent_overscrolling_of_report = function() { if ((luna_app.is_mobile_app || luna_app.is_mobile_browser()) && luna_utils.is_sg_page()) { if (!luna_app.is_mobile_app && luna_app.is_mobile_browser()) { if ($("#form1").is(":visible")) { let form_width = $("#form1 #uitable").outerWidth(); if (form_width > visualViewport.width) { $("#form1").closest('div.luna_primary_form_container.window_scroll_sticky_left_element').addClass('position-static'); } else { $("#form1").closest('div.luna_primary_form_container.window_scroll_sticky_left_element.position-static').removeClass('position-static'); } } } let table_id_suffix = luna_app.is_mobile_app ? '_' + dsplma_sgm.table_id_suffix : ''; let tf_table_width = $("#sg_output" + table_id_suffix).outerWidth(); if (tf_table_width > 0) { tf_table_width = luna_app.is_mobile_app ? (tf_table_width + 15) : tf_table_width + 5; // 15 & 5 are left padding off table if (window.scrollX + visualViewport.width > tf_table_width) { // if scrolled further than table width window.scrollTo(tf_table_width - visualViewport.width, window.scrollY); } } } }; luna_utils.register_main_listeners = function() { $(window).scroll(function() { luna_utils.stick_elements_to_left_while_scrolling(); // adding left to the elemets given - making the elements stick to left while scrolling if (luna_app.is_mobile_app) { dsplma_side_nav.isScrolledIntoView($("#app_body")); } }); $(document).on('click', 'i.field_lock_icon', function() { // Remove from here const COLUMN_ID = $(this).attr('id').split('field_lock_icon_')[1]; luna_utils.field_lock_icon_clicked(COLUMN_ID); }); $(document).bind('dblclick', function (e) { e.preventDefault(); }); $(document).on('blur', '[luna_capitalize=on]', function(e) { luna_utils.capitalize_field_value($(this).attr('id')); }); $(document).on('blur', '[auto_validate_as=mobile]', function(e) { luna_utils.auto_correct_mobile_num_field($(this)); }); $(document).on('submit', 'form:not([allow-submit])', function (event) { event.preventDefault(); }); /* add allowed_keys class to input fields add attribute allowed_chars to restrict finite set of allowed characters */ $(document).on('keypress', 'input.allowed_keys,textarea.allowed_keys', function (event) { // change event removed because key has been written and event fires afer that luna_v.allowed_keys_keypress(event, this); }); $(document).on('change', "[auto_validate_as='date']", function() { var $this = $(this); let old_date_value = $this.val(); let new_date_value = luna_d.parse_date(old_date_value); if (old_date_value != new_date_value) { $this.val(new_date_value).trigger('change'); } luna_wid.update_ndp_fields($this); }); if (luna_app.is_mobile_app) { $(document).on('click', 'a.luna_external_link', function(event) { dsplma.luna_external_link__clicked($(this).attr('href_url'), event); }); $(document).on('change keydown', function (e) { dsplma.hideStatusBar(); dsplma_s.extend_session(); }); $(document).on('click', "input, button", function (e) { dsplma.hideStatusBar(); // dsplma_s.extend_session(); }); } luna_utils.eye_uneye_icon(); // remove this , optimize }; luna_utils.image_not_available = function(img) { // $(img).remove(); }; luna_utils.eye_uneye_icon = function() { $(document).on('click', 'i.eye_icon', function() { let fieldID = $(this).attr('fieldID'); if ($(this).hasClass('fa-eye')) { $(this).removeClass('fa-eye').addClass('fa-eye-slash'); $("#" + fieldID).attr('type', 'password').focus(); } else { $(this).addClass('fa-eye').removeClass('fa-eye-slash'); $("#" + fieldID).attr('type', 'text').focus(); } }) }; luna_utils.discard_pasted_image = function(event, field_id) { luna_app.clear_statusBar(); let supports_multiple = $("#" + field_id)[0].hasAttribute('multiple'); let file_item_to_remove = $(event.target).closest('div.pasted_file_item'); let file_path = file_item_to_remove.find('a[orig_path]').attr('orig_path'); file_item_to_remove.remove(); let already_pasted_file_paths = []; if (supports_multiple) { already_pasted_file_paths = $("#" + field_id + '_PASTED_FILE_PATH').val(); already_pasted_file_paths = already_pasted_file_paths.split(','); luna_utils.remove_element_from_array(already_pasted_file_paths, file_path); $("#" + field_id + '_PASTED_FILE_PATH').val(already_pasted_file_paths.join(',')); } if (already_pasted_file_paths.length == 0 || !supports_multiple) { $("#rectangle_paste_box_" + field_id).show(); $("#" + field_id + '_PASTED_FILE_PATH').val(''); $("#" + field_id).show(); } }; luna_utils.reset_pasted_image = function(field_id) { if ($("#" + field_id + '_PASTED_FILE_PATH').length == 0) { return; } let pasted_file_path = $("#" + field_id + '_PASTED_FILE_PATH').val(); if (pasted_file_path == '') { return; } let supports_multiple = $("#" + field_id)[0].hasAttribute('multiple'); if (supports_multiple) { pasted_file_path = pasted_file_path.split(','); for (let x=0; x'); $("#" + field_id).on('change', function() { if ($(this).val() != '') { $("#rectangle_paste_box_" + field_id).hide(); $("#" + field_id + "_PASTED_FILE_PATH").val(''); } else { $("#rectangle_paste_box_" + field_id).show(); } }); $("#" + field_id).addClass('paste_icon_parent'); $(`
Click here and press Ctrl + V to paste
`).insertAfter("#" + field_id); $(document).off('paste'); $(document).on('paste', function(event) { if ($(event.target).hasClass('rectangle_paste_box')) { var clipboardData = (event.clipboardData || event.originalEvent.clipboardData).items; var data_url = clipboardData[0].getAsFile(); if (data_url != null) { // data_url is too big encoded data - so has to convert it into blob to set blob in formData which would then be sent to server var reader = new FileReader(); reader.onload = function(reader_event){ luna_app.showBusyUI(true); function dataURLtoBlob(dataUrl) { const parts = dataUrl.split(';base64,'); const contentType = parts[0].split(':')[1]; const raw = window.atob(parts[1]); const rawLength = raw.length; const uint8Array = new Uint8Array(rawLength); for (let i = 0; i < rawLength; ++i) { uint8Array[i] = raw.charCodeAt(i); } return new Blob([uint8Array], { type: contentType }); } var blob = dataURLtoBlob(reader_event.target.result); luna_app.showBusyUI(false); let rect_field_id = (event.target.id).replace('rectangle_paste_box_', ''); luna_utils.paste_command_executed(blob, data_url.name, rect_field_id, allowed_extenstions); } reader.readAsDataURL(data_url); } else { luna_app.show_error_message('Clipboard does not have any file to paste'); } } }); }; luna_utils.rename_pasted_image = function(event, field_id) { let file_item = $(event.target).closest('div.pasted_file_item'); let orig_path = file_item.find('a[orig_path]').attr('orig_path'); let file_path = orig_path.split('/').pop(); file_path = file_path.split("."); file_path.pop(); let file_name = file_path.join("."); let new_file_name = window.prompt("Rename File", file_name); if (new_file_name != '' && new_file_name != null && new_file_name != file_name) { let data2send = 'orig_path=' + orig_path + '&new_file_name=' + new_file_name; luna_utils.get_response(10185906, data2send, function(response) { if (response.response_code == 1) { let new_file_path = response.new_file_path; new_file_name = new_file_path.split('/').pop(); file_item.find('a[orig_path]').attr('orig_path', new_file_path).attr('href', luna_ws.WEBSERVICE_HOST + '/' + new_file_path).html(new_file_name); let supports_multiple = $("#" + field_id)[0].hasAttribute('multiple'); if (supports_multiple) { let already_pasted_file_paths = $("#" + field_id + '_PASTED_FILE_PATH').val(); if (already_pasted_file_paths == '') { $("#" + field_id + '_PASTED_FILE_PATH').val(new_file_path); } else { already_pasted_file_paths = already_pasted_file_paths.split(','); for (let x=0; x