Compare commits

..

2 Commits

5 changed files with 52 additions and 3 deletions

View File

@@ -749,6 +749,13 @@ button.badge:hover {
color: var(--text-primary); 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 { a.code-link {
color: var(--accent); color: var(--accent);
font-weight: 600; font-weight: 600;

View File

@@ -55,6 +55,12 @@ function checkRowMatches() {
console.assert(!rowMatches(row, 'آلفا', 'zz'), 'both'); console.assert(!rowMatches(row, 'آلفا', 'zz'), 'both');
console.assert(rowMatches({ customer_name: ' ', product_code: 'A' }, '—', ''), 'blank company'); console.assert(rowMatches({ customer_name: ' ', product_code: 'A' }, '—', ''), 'blank company');
console.assert(suggestionValues(['شرکت بتا', 'شرکت آلفا', 'شرکت آلفا'], 'آلفا').join() === 'شرکت آلفا', 'suggest'); 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) { function groupedRows(rows) {
@@ -72,6 +78,27 @@ function groupedRows(rows) {
return list; 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) { function cell(text, className, ltr) {
const td = document.createElement('td'); const td = document.createElement('td');
if (className) td.className = className; if (className) td.className = className;
@@ -192,6 +219,19 @@ function renderOrders(rows, markNew) {
body.appendChild(tr); body.appendChild(tr);
seenOrderKeys.add(key); 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; return added;
} }

View File

@@ -57,6 +57,7 @@ const translations = {
'delivered_qty': 'Delivered', 'delivered_qty': 'Delivered',
'remaining_qty': 'Remaining', 'remaining_qty': 'Remaining',
'product_title': 'Title', 'product_title': 'Title',
'subtotal': 'Subtotal',
'crm_loading': 'Loading orders…', 'crm_loading': 'Loading orders…',
'sg_username': 'Username', 'sg_username': 'Username',
'sg_password': 'Password', 'sg_password': 'Password',
@@ -138,6 +139,7 @@ const translations = {
'delivered_qty': 'تحویل‌شده', 'delivered_qty': 'تحویل‌شده',
'remaining_qty': 'مانده', 'remaining_qty': 'مانده',
'product_title': 'عنوان', 'product_title': 'عنوان',
'subtotal': 'جمع',
'crm_loading': 'در حال دریافت سفارش‌ها…', 'crm_loading': 'در حال دریافت سفارش‌ها…',
'sg_username': 'نام کاربری', 'sg_username': 'نام کاربری',
'sg_password': 'رمز عبور', 'sg_password': 'رمز عبور',

View File

@@ -10,7 +10,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <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 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> <script>
(function () { (function () {
var t = localStorage.getItem('slip_theme') || 'light'; var t = localStorage.getItem('slip_theme') || 'light';
@@ -56,7 +56,7 @@
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </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 %} {% block extra_scripts %}{% endblock %}
</body> </body>
</html> </html>

View File

@@ -71,5 +71,5 @@
{% endblock %} {% endblock %}
{% block extra_scripts %} {% 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 %} {% endblock %}