ICS modules

This commit is contained in:
Thanakorn S
2026-03-21 14:58:15 +07:00
parent 2e558a55bb
commit a4f474b5df
45 changed files with 3110 additions and 597 deletions
+127 -1
View File
@@ -115,6 +115,111 @@ $(function () {
});
$('input.contact_search').each(function (i, el) {
var $el = $(el);
$el.autocomplete({
// Fetch data from server
source: function (request, response) {
// Abort previous request (prevent multiple firing)
if ($el.data('xhr')) {
$el.data('xhr').abort();
}
// Prepare payload
let q = prepare_form_data(0, true);
q['keyword'] = request.term;
let json = JSON.stringify(q);
// Send AJAX request
var xhr = $.ajax({
url: server_url + 'ics/api/engine/contact_search.php',
type: 'POST',
dataType: 'json',
data: { json: json },
// for CSRF validation
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function (res) {
var aca = [];
// Map result to autocomplete format
$.each(res.result, function (i, item) {
var temp = "";
temp += "<div class='contact-result-item' style='font-family:\"Poppins\",sans-serif;padding:4px 0;'>";
temp += "<div style='font-size:10px;text-transform:uppercase;color:#E66239;font-weight:600;line-height:1.2;'>";
temp += "Tax ID: " + (item.tax_id || 'N/A');
temp += "</div>";
temp += "<div style='font-size:13px;font-weight:500;color:#171717;margin-top:2px;'>";
temp += item.contact_name;
temp += "</div>";
temp += "</div>";
aca.push({
label: temp, // HTML dropdown
value: item.contact_name, // Default value
data: item // Full object
});
});
response(aca);
}
});
// Save request reference
$el.data('xhr', xhr);
},
minLength: 0,
delay: 300,
// When selecting item
select: function (e, ui) {
if (ui.item && ui.item.data) {
var contact = ui.item.data;
// Replace input value with SKU
$(this)
.val(contact.contact_name)
.attr("data-id", contact.id)
.attr("secondary", contact.contact_name);
console.log("Input updated with contact name:", contact.contact_name);
return false; // Prevent overwrite by default value
}
}
})
// Allow HTML rendering in dropdown
.data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li>")
.append($("<div>").html(item.label))
.appendTo(ul);
};
// Add this ↓
$el.on('blur', function () {
var secondary = $(this).attr('secondary');
console.log($(this).attr('data-id'))
if (secondary) {
$('input#contact').val($('input#contact').attr('secondary'));
}
});
});
});
@@ -198,7 +303,7 @@ function ajax_request(options) {
isAjaxProcessing = false;
return Promise.reject("validation_failed");
}
if(options.data){
Object.entries(options.data).forEach(([key, value]) => {
payloadJson[key] = value;
@@ -400,3 +505,24 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
/**
* Helper function to format date strings (assuming input is in ISO format)
*/
function format_date(iso_string) {
var split = iso_string.split(" ");
if (split.length === 2) {
var datePart = split[0].split("-");
}
return (datePart) ? `${datePart[2]}/${datePart[1]}/${datePart[0]} ${split[1]}` : iso_string;
}
function format_number(value, decimal) {
var n = Number(value);
if (isNaN(n)) return '--';
if (decimal !== undefined) n = n.toFixed(decimal);
var parts = n.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}