diff --git a/app.zip b/app.zip index 46fb58e..6d23753 100644 Binary files a/app.zip and b/app.zip differ diff --git a/app/assets/js/custom.js b/app/assets/js/custom.js index 0739c00..9c93227 100644 --- a/app/assets/js/custom.js +++ b/app/assets/js/custom.js @@ -401,12 +401,34 @@ function ajax_request(options) { isAjaxProcessing = false; $.LoadingOverlay("hide"); + // Errors re-thrown from .then() — pass through if (xhr instanceof Error) { throw xhr; } - console.error("AJAX Error:", xhr?.responseText); - bootbox.alert("Server error occurred."); + // Extract server's error message from JSON response + let serverMessage = xhr?.responseJSON?.message; + + // Fallback: parse responseText if responseJSON isn't set + if (!serverMessage && xhr?.responseText) { + try { + serverMessage = JSON.parse(xhr.responseText)?.message; + } catch (e) { + // Response wasn't JSON — real server crash or HTML error page + } + } + + if (serverMessage) { + // Known server-reported error (HTTP 4xx/5xx with JSON body) + bootbox.alert(serverMessage); + options.onError?.(xhr, serverMessage); + } else { + // Unknown error — network failure, PHP fatal, HTML error page + console.error("AJAX Error:", xhr?.status, xhr?.responseText); + bootbox.alert("Server error occurred."); + options.onError?.(xhr, null); + } + throw xhr; }); } @@ -422,6 +444,7 @@ function generate_pagination(table_id, total_records, records_per_page, current_ // 1. Find the table and thead const table = document.getElementById(table_id); let theme_class = ''; + let col_count = 1; if (table) { const thead = table.querySelector('thead'); @@ -433,16 +456,25 @@ function generate_pagination(table_id, total_records, records_per_page, current_ // 3. Convert "table-secondary" to "page-item-secondary" theme_class = bootstrap_theme.replace('table-', 'page-item-'); } + + // 4. Count
| Product | SKU | -Current Stock | -Min Stock | -Reorder Point | +Current Stock | +Min Stock | +Reorder Point | Status | Action | ${item['category']} | ${item['slug']} | ${item['description']} | -${item['product_count']} | +${item['product_count']} | ${(item['status']==1)?'Active':'Inactive'} | @@ -367,7 +368,10 @@ var body = ``; $.each(page_data, function(key, item) { - body += `
|---|---|---|---|---|---|---|---|---|---|---|
|
+ |
${item['product_name']} | ${item['sku']} | ${format_number(item['product_balance'],4)} |