fix(money,orders): wage/gram-debt parity, atomic document confirm, expert edit, made-to-order, QA fixes

- Rial wage and gram-debt arithmetic matched to the reference; order corrections keep debt in sync
- Document confirm/un-confirm is a compare-and-swap (no double-applied cache under concurrency)
- Settlement document and expert inputs validated (400 instead of 500)
- Expert: edit / activate-deactivate own customers, adjust raw weights only
- Made-to-order flow in the app, PreOrder.quantity migration
- Order grids: customer column, sort keys; panel select search; pre-order quantity save
- Rebuilt release artifacts

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mahmood
2026-10-29 18:09:02 +03:30
co-authored by Claude Sonnet 5.5
parent 959a272227
commit 6514b05d18
321 changed files with 6984 additions and 2170 deletions
@@ -108,6 +108,52 @@ export class AccountingHooksService {
}
}
/**
* F3 — may this order's lines or weights be corrected now? A document that is
* being sent, or is waiting for a person to look at it, cannot be reconciled
* with a change automatically, so the correction is refused until it is
* settled. Returns the reason, or null when the correction may go ahead.
*/
async orderDocumentBlocksEdit(tx: Tx, orderId: string): Promise<string | null> {
const c = await this.config.get();
if (c.provider === 'none' || !c.features.documents) return null;
const stuck = await tx.accountingOutbox.findFirst({
where: { provider: c.provider, kind: 'ORDER_DOCUMENT', entityId: orderId, status: { in: ['SENDING', 'NEEDS_REVIEW'] } },
select: { id: true },
});
return stuck
? 'سند حسابداری این سفارش در حال ارسال است یا منتظر بررسی؛ پس از روشن شدن وضعیتش دوباره تلاش کنید.'
: null;
}
/**
* F3 — the order's lines or weights were corrected after it was placed.
*
* A document still waiting (or failed and due for a retry) is built from the
* order at the moment it is sent, so it picks the correction up by itself.
* One already in the books no longer matches: it is withdrawn and a corrected
* one is queued behind the delete (the worker runs the older job first).
*/
async orderEdited(tx: Tx, orderId: string) {
const c = await this.config.get();
if (c.provider === 'none' || !c.features.documents) return;
const sent = await tx.accountingOutbox.findFirst({
where: { provider: c.provider, kind: 'ORDER_DOCUMENT', entityId: orderId, status: { in: ['SENT'] } },
select: { id: true },
});
if (!sent) return;
// Already withdrawn and re-queued by an earlier correction: that new job
// will read the latest figures too.
const requeued = await tx.accountingOutbox.findFirst({
where: { provider: c.provider, kind: 'ORDER_DOCUMENT', entityId: orderId, status: { in: ['PENDING'] } },
select: { id: true },
});
if (requeued) return;
await this.orderCancelled(tx, orderId);
await tx.accountingOutbox.create({ data: { provider: c.provider, kind: 'ORDER_DOCUMENT', entityId: orderId } });
this.worker.kickSoon();
}
/** F1 — an admin marked the customer VERIFIED. */
async customerVerified(tx: Tx, customerId: string) {
await this.enqueue(tx, 'customers', 'CUSTOMER_PUSH', customerId);