Compare commits
3 Commits
45ef55e13e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0314e87c3f | |||
| 32331d4cf8 | |||
| a85979731f |
@ -85,3 +85,20 @@ export function formatMoney(dirams, lang = 'en') {
|
||||
const s = n.toFixed(2);
|
||||
return lang === 'tg' ? s.replace('.', ',') : s;
|
||||
}
|
||||
|
||||
export function formatTs(utcStr) {
|
||||
if (!utcStr) return '';
|
||||
|
||||
const normalized = String(utcStr).trim().replace(' ', 'T');
|
||||
const utcDate = new Date(`${normalized}Z`);
|
||||
if (Number.isNaN(utcDate.getTime())) return utcStr;
|
||||
|
||||
const tajikDate = new Date(utcDate.getTime() + 5 * 60 * 60 * 1000);
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
|
||||
return [
|
||||
pad(tajikDate.getUTCDate()),
|
||||
pad(tajikDate.getUTCMonth() + 1),
|
||||
tajikDate.getUTCFullYear()
|
||||
].join('.') + ` ${pad(tajikDate.getUTCHours())}:${pad(tajikDate.getUTCMinutes())}`;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { getDb } from './db.js';
|
||||
|
||||
// All time windows are computed in local time using SQLite's `datetime('now', 'localtime')`.
|
||||
// All time windows are computed in Tajikistan time (UTC+5) while timestamps are stored as UTC.
|
||||
// Cost of goods (COG) and profit are computed against each part's current cost_price —
|
||||
// the schema does not snapshot cost at sale time, so historical cost changes are not
|
||||
// reflected. Custom (non-inventory) lines contribute to sale revenue but have zero COG.
|
||||
@ -29,9 +29,9 @@ function windowStats(dateClause) {
|
||||
export function salesSummary() {
|
||||
return {
|
||||
all_time: windowStats(''),
|
||||
today: windowStats(`date(saved_at, 'localtime') = date('now', 'localtime')`),
|
||||
week: windowStats(`date(saved_at, 'localtime') >= date('now', 'localtime', '-6 days')`),
|
||||
month: windowStats(`strftime('%Y-%m', saved_at, 'localtime') = strftime('%Y-%m', 'now', 'localtime')`)
|
||||
today: windowStats(`date(saved_at, '+5 hours') = date('now', '+5 hours')`),
|
||||
week: windowStats(`date(saved_at, '+5 hours') >= date('now', '+5 hours', '-6 days')`),
|
||||
month: windowStats(`strftime('%Y-%m', saved_at, '+5 hours') = strftime('%Y-%m', 'now', '+5 hours')`)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { locale, t, localized } from '$lib/i18n/store.js';
|
||||
import { locale, t, localized, formatTs } from '$lib/i18n/store.js';
|
||||
|
||||
export let data;
|
||||
$: lang = $locale;
|
||||
@ -48,7 +48,7 @@
|
||||
<tbody>
|
||||
{#each movements as m}
|
||||
<tr>
|
||||
<td>{m.created_at}</td>
|
||||
<td>{formatTs(m.created_at)}</td>
|
||||
<td><span class="pill">{$t('movements.type_' + m.movement_type)}</span></td>
|
||||
<td><a href="/parts/{m.part_id}">{localized(m, 'name', lang)}</a></td>
|
||||
<td class="num">{m.quantity}</td>
|
||||
|
||||
@ -1,16 +1,10 @@
|
||||
<script>
|
||||
import { locale, t, localized, formatMoney } from '$lib/i18n/store.js';
|
||||
import { locale, t, localized, formatMoney, formatTs } from '$lib/i18n/store.js';
|
||||
|
||||
export let data;
|
||||
$: lang = $locale;
|
||||
$: ({ sales, topParts, inventory, recentSales } = data);
|
||||
|
||||
function formatWhen(iso) {
|
||||
if (!iso) return '';
|
||||
const d = new Date(iso.replace(' ', 'T') + 'Z');
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<h2>{$t('reports.sales_heading')}</h2>
|
||||
@ -122,7 +116,7 @@
|
||||
<tbody>
|
||||
{#each recentSales as s}
|
||||
<tr>
|
||||
<td>{formatWhen(s.saved_at)}</td>
|
||||
<td>{formatTs(s.saved_at)}</td>
|
||||
<td class="num">{s.line_count}</td>
|
||||
<td class="num">
|
||||
{formatMoney(s.sale_dirams, lang)}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { locale, t, localized, formatMoney } from '$lib/i18n/store.js';
|
||||
import { locale, t, localized, formatMoney, formatTs } from '$lib/i18n/store.js';
|
||||
|
||||
export let data;
|
||||
$: lang = $locale;
|
||||
@ -15,7 +15,7 @@
|
||||
<header class="head">
|
||||
<div>
|
||||
<h1>{$t('invoices.saved_title')} #{invoice.id}</h1>
|
||||
<p class="muted">{invoice.saved_at}</p>
|
||||
<p class="muted">{formatTs(invoice.saved_at)}</p>
|
||||
</div>
|
||||
<a href="/invoices/new" class="print-hide back">← {$t('invoices.new_another')}</a>
|
||||
</header>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { enhance } from '$app/forms';
|
||||
import { locale, t, localized, formatMoney } from '$lib/i18n/store.js';
|
||||
import { locale, t, localized, formatMoney, formatTs } from '$lib/i18n/store.js';
|
||||
|
||||
export let data;
|
||||
export let form;
|
||||
@ -117,8 +117,8 @@
|
||||
{$t('parts.reorder_level')}: {part.reorder_level}
|
||||
</div>
|
||||
<hr />
|
||||
<div class="muted small">{$t('common.created')}: {part.created_at}</div>
|
||||
<div class="muted small">{$t('common.updated')}: {part.updated_at}</div>
|
||||
<div class="muted small">{$t('common.created')}: {formatTs(part.created_at)}</div>
|
||||
<div class="muted small">{$t('common.updated')}: {formatTs(part.updated_at)}</div>
|
||||
</div>
|
||||
|
||||
<h2>{$t('parts.recent_movements')}</h2>
|
||||
@ -137,7 +137,7 @@
|
||||
<tbody>
|
||||
{#each movements as m}
|
||||
<tr>
|
||||
<td>{m.created_at}</td>
|
||||
<td>{formatTs(m.created_at)}</td>
|
||||
<td><span class="pill">{$t('movements.type_' + m.movement_type)}</span></td>
|
||||
<td class="num">{m.quantity > 0 ? '+' : ''}{m.quantity}</td>
|
||||
<td class="num">{m.unit_price != null ? formatMoney(m.unit_price, lang) : $t('common.none')}</td>
|
||||
|
||||
Reference in New Issue
Block a user