sale order
SAP-ERP Portal CI/CD / build (push) Successful in 3m57s

This commit is contained in:
John
2026-10-05 18:45:17 +05:30
parent e725a6571b
commit eead8f5ffd
129 changed files with 14252 additions and 452 deletions
+28 -3
View File
@@ -69,11 +69,13 @@ function fromRow(r, withRows) {
// List documents (headers only). Optional filters: company, tab, month, and
// an allow-set of tabs (per-user restriction — omit for no restriction).
async function list({ company, tab, month, allowTabs, top = 30, skip = 0 } = {}) {
async function list({ company, tab, month, monthFrom, monthTo, allowTabs, top = 30, skip = 0 } = {}) {
const where = []; const params = [];
if (company) { where.push(`COMPANY = ?`); params.push(company); }
if (tab) { where.push(`TAB = ?`); params.push(tab); }
if (month) { where.push(`MONTH = ?`); params.push(month); }
if (monthFrom) { where.push(`MONTH >= ?`); params.push(monthFrom); }
if (monthTo) { where.push(`MONTH <= ?`); params.push(monthTo); }
if (Array.isArray(allowTabs) && allowTabs.length) {
where.push(`TAB IN (${allowTabs.map(() => '?').join(',')})`);
allowTabs.forEach(t => params.push(t));
@@ -83,7 +85,16 @@ async function list({ company, tab, month, allowTabs, top = 30, skip = 0 } = {})
`SELECT * FROM ${TABLE} ${w} ORDER BY ID DESC OFFSET ${Math.max(0, skip | 0)} ROWS FETCH NEXT ${Math.min(100, top | 0)} ROWS ONLY`,
params
);
return rows.map(r => fromRow(r, false));
// Genuine total (same filter, no paging) — drives "Page X of Y" on the
// client instead of an open-ended "Page X". Wrapped so a COUNT failure
// never breaks the list itself — the page still loads, just without a total.
let total = null;
try {
const countRows = await exec(`SELECT COUNT(*) AS n FROM ${TABLE} ${w}`, params);
const n = Number(countRows?.[0]?.n);
total = isNaN(n) ? null : n;
} catch (e) { console.warn('[OEE-STORE] COUNT(*) failed — pager will show no total:', e.message); }
return { data: rows.map(r => fromRow(r, false)), total };
}
async function getById(id) {
@@ -91,6 +102,20 @@ async function getById(id) {
return rows.length ? fromRow(rows[0], true) : null;
}
// Every non-cancelled document (WITH its full row data) across a month
// range, for a report that needs to scan actual shift rows rather than just
// list documents — e.g. Downtime Analysis, which pulls every shift entry
// across every tab/machine for a date range. Unbounded (no top/skip): this
// is for server-side aggregation, not a paginated UI list.
async function listAllInRange({ company, monthFrom, monthTo } = {}) {
const where = [`(CANCELED = 0 OR CANCELED IS NULL)`]; const params = [];
if (company) { where.push(`COMPANY = ?`); params.push(company); }
if (monthFrom){ where.push(`MONTH >= ?`); params.push(monthFrom); }
if (monthTo) { where.push(`MONTH <= ?`); params.push(monthTo); }
const rows = await exec(`SELECT * FROM ${TABLE} WHERE ${where.join(' AND ')}`, params);
return rows.map(r => fromRow(r, true));
}
async function create({ company, tab, month, rows, remark, createdBy, createdById }) {
const now = new Date().toISOString().replace('T', ' ').replace('Z', '').substring(0, 23);
const idRows = await exec(
@@ -117,4 +142,4 @@ async function cancel(id) {
await exec(`UPDATE ${TABLE} SET CANCELED = 1, UPDATED_AT = SYSUTCDATETIME() WHERE ID = ?`, [parseInt(id)]);
}
module.exports = { bootstrap, list, getById, create, update, cancel };
module.exports = { bootstrap, list, getById, create, update, cancel, listAllInRange };