diff --git a/slips/static/slips/css/style.css b/slips/static/slips/css/style.css index 2711c6e..7bc370d 100644 --- a/slips/static/slips/css/style.css +++ b/slips/static/slips/css/style.css @@ -749,6 +749,13 @@ button.badge:hover { color: var(--text-primary); } +.data-table tr.subtotal-row td { + background: color-mix(in srgb, var(--bg-muted) 55%, transparent); + font-weight: 600; + color: var(--text-secondary); + border-top: 1px solid var(--border); +} + a.code-link { color: var(--accent); font-weight: 600; diff --git a/slips/static/slips/js/crm_orders.js b/slips/static/slips/js/crm_orders.js index 96a2903..69604f5 100644 --- a/slips/static/slips/js/crm_orders.js +++ b/slips/static/slips/js/crm_orders.js @@ -55,6 +55,12 @@ function checkRowMatches() { console.assert(!rowMatches(row, 'آلفا', 'zz'), 'both'); console.assert(rowMatches({ customer_name: ' ', product_code: 'A' }, '—', ''), 'blank company'); console.assert(suggestionValues(['شرکت بتا', 'شرکت آلفا', 'شرکت آلفا'], 'آلفا').join() === 'شرکت آلفا', 'suggest'); + const totals = qtyTotals([ + { note_quantity: '10', delivered_quantity: '4', remaining_quantity: '6' }, + { note_quantity: '2.5', delivered_quantity: '0', remaining_quantity: '2.5' }, + ]); + console.assert(totals.note === 12.5 && totals.delivered === 4 && totals.remaining === 8.5, 'qty totals'); + console.assert(formatQty(12.5) === '12.5' && formatQty(4) === '4', 'format qty'); } function groupedRows(rows) { @@ -72,6 +78,27 @@ function groupedRows(rows) { return list; } +function parseQty(raw) { + const n = Number(String(raw || '').trim().replace(/,/g, '')); + return Number.isFinite(n) ? n : 0; +} + +function formatQty(n) { + if (!Number.isFinite(n)) return ''; + return Number.isInteger(n) ? String(n) : String(parseFloat(n.toFixed(6))); +} + +function qtyTotals(items) { + return items.reduce( + (sum, row) => ({ + note: sum.note + parseQty(row.note_quantity), + delivered: sum.delivered + parseQty(row.delivered_quantity), + remaining: sum.remaining + parseQty(row.remaining_quantity), + }), + { note: 0, delivered: 0, remaining: 0 }, + ); +} + function cell(text, className, ltr) { const td = document.createElement('td'); if (className) td.className = className; @@ -192,6 +219,19 @@ function renderOrders(rows, markNew) { body.appendChild(tr); seenOrderKeys.add(key); }); + const totals = qtyTotals(items); + const foot = document.createElement('tr'); + foot.className = 'subtotal-row'; + const totalLabel = document.createElement('td'); + totalLabel.colSpan = 3; + totalLabel.textContent = t('subtotal'); + foot.append( + totalLabel, + cell(formatQty(totals.note), 'mono'), + cell(formatQty(totals.delivered), 'mono'), + cell(formatQty(totals.remaining), 'mono'), + ); + body.appendChild(foot); }); return added; } diff --git a/slips/static/slips/js/i18n.js b/slips/static/slips/js/i18n.js index 4095f8b..59321c1 100644 --- a/slips/static/slips/js/i18n.js +++ b/slips/static/slips/js/i18n.js @@ -57,6 +57,7 @@ const translations = { 'delivered_qty': 'Delivered', 'remaining_qty': 'Remaining', 'product_title': 'Title', + 'subtotal': 'Subtotal', 'crm_loading': 'Loading orders…', 'sg_username': 'Username', 'sg_password': 'Password', @@ -138,6 +139,7 @@ const translations = { 'delivered_qty': 'تحویل‌شده', 'remaining_qty': 'مانده', 'product_title': 'عنوان', + 'subtotal': 'جمع', 'crm_loading': 'در حال دریافت سفارش‌ها…', 'sg_username': 'نام کاربری', 'sg_password': 'رمز عبور', diff --git a/slips/templates/slips/base.html b/slips/templates/slips/base.html index ab43387..bc7b1e7 100644 --- a/slips/templates/slips/base.html +++ b/slips/templates/slips/base.html @@ -10,7 +10,7 @@ - + + {% block extra_scripts %}{% endblock %} diff --git a/slips/templates/slips/crm_orders.html b/slips/templates/slips/crm_orders.html index 23d5e6b..16e33af 100644 --- a/slips/templates/slips/crm_orders.html +++ b/slips/templates/slips/crm_orders.html @@ -71,5 +71,5 @@ {% endblock %} {% block extra_scripts %} - + {% endblock %}