Add per-customer quantity subtotals on CRM orders
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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': 'رمز عبور',
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;600&family=Vazirmatn:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'slips/css/style.css' %}?v=3">
|
||||
<link rel="stylesheet" href="{% static 'slips/css/style.css' %}?v=4">
|
||||
<script>
|
||||
(function () {
|
||||
var t = localStorage.getItem('slip_theme') || 'light';
|
||||
@@ -56,7 +56,7 @@
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<script src="{% static 'slips/js/i18n.js' %}?v=4"></script>
|
||||
<script src="{% static 'slips/js/i18n.js' %}?v=5"></script>
|
||||
{% block extra_scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -71,5 +71,5 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
<script src="{% static 'slips/js/crm_orders.js' %}?v=9"></script>
|
||||
<script src="{% static 'slips/js/crm_orders.js' %}?v=10"></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user