cost/price/margin

This commit is contained in:
Thanakorn S
2026-05-06 09:37:28 +07:00
parent 6501d326ca
commit d8131a01b7
10 changed files with 130 additions and 27 deletions
+24 -3
View File
@@ -139,6 +139,8 @@
<th class="text-end">Stock In</th>
<th class="text-end">Stock Out</th>
<th>UOM</th>
<th class="text-end">Price / Cost</th>
<th class="text-end">Margin</th>
<th class="text-end">Running Total</th>
</tr>
</thead>
@@ -291,7 +293,7 @@
.addClass(net >= 0 ? 'text-success' : 'text-danger');
if (!d.skus || d.skus.length === 0) {
$('#tbl_body').html('<tr><td colspan="9" class="text-center py-5 text-muted">No movement data found.</td></tr>');
$('#tbl_body').html('<tr><td colspan="12" class="text-center py-5 text-muted">No movement data found.</td></tr>');
return;
}
@@ -391,7 +393,7 @@
// SKU header row
var header = `<tr class="table-secondary">
<td colspan="10" class="py-2 fw-semibold">
<td colspan="12" class="py-2 fw-semibold">
<code>${d.sku}</code>
<span class="text-muted fw-normal ms-2">${d.product_name}</span>
<span class="badge bg-light text-secondary border ms-2 small">${d.uom || 'pcs'}</span>
@@ -407,6 +409,8 @@
<td class="py-2 text-end text-success">${bf_in_val}</td>
<td class="py-2 text-end text-danger">${bf_out_val}</td>
<td class="py-2 text-muted small">${d.uom || 'pcs'}</td>
<td class="py-2"></td>
<td class="py-2"></td>
<td class="py-2 text-end fw-semibold ${bf_bal_cls}">${fmt(bf.balance)}</td>
</tr>`;
@@ -414,13 +418,28 @@
var body = '';
if (rows.length === 0) {
body = `<tr>
<td colspan="9" class="text-center py-2 text-muted fst-italic">No transactions in range.</td>
<td colspan="12" class="text-center py-2 text-muted fst-italic">No transactions in range.</td>
</tr>`;
} else {
$.each(rows, function(i, row) {
var in_val = row.stock_in > 0 ? fmt(row.stock_in) : '<span class="text-muted">—</span>';
var out_val = row.stock_out > 0 ? fmt(row.stock_out) : '<span class="text-muted">—</span>';
var rt_cls = row.running_total >= 0 ? 'text-success' : 'text-danger';
var price_cell = '<span class="text-muted">—</span>';
if (row.stock_in > 0 && parseFloat(row.price) > 0) {
price_cell = `<span class="text-success">${fmt(row.price)}</span>`;
} else if (row.stock_out > 0 && parseFloat(row.price) > 0) {
price_cell = `<div>${fmt(row.price)}</div>
<small class="text-muted">${fmt(row.unit_cost)}</small>`;
}
var margin_cell = '<span class="text-muted">—</span>';
if (row.margin !== null && row.margin !== undefined) {
var m_cls = row.margin >= 0 ? 'text-success' : 'text-danger';
margin_cell = `<span class="${m_cls} fw-semibold">${parseFloat(row.margin).toFixed(1)}%</span>`;
}
body += `<tr>
<td class="py-2">${row.date}</td>
<td class="py-2">${type_badge[row.type] || row.type}</td>
@@ -431,6 +450,8 @@
<td class="py-2 text-end text-success">${in_val}</td>
<td class="py-2 text-end text-danger">${out_val}</td>
<td class="py-2 text-muted small">${d.uom || 'pcs'}</td>
<td class="py-2 text-end">${price_cell}</td>
<td class="py-2 text-end">${margin_cell}</td>
<td class="py-2 text-end fw-semibold ${rt_cls}">${fmt(row.running_total)}</td>
</tr>`;
});