+ با وضعیت «قطعی» یا «تسویهشده»، موجودی انبار و سند حسابداری بهروزرسانی میشود. +
+ )} )} @@ -370,7 +423,15 @@ function InvoiceSection({ config }: { config: TradeConfig }) { message={`فاکتور شماره ${toFa(toDelete?.number ?? 0)} حذف شود؟`} onCancel={() => setToDelete(null)} onConfirm={() => { - if (toDelete) removeInvoice(toDelete.id) + if (toDelete) { + const effects = invoiceDeleteEffects(toDelete, data) + if (effects.removeVoucherId) removeVoucher(effects.removeVoucherId) + for (const product of effects.products) { + const original = data.products.find((p) => p.id === product.id) + if (original && original.stock !== product.stock) upsertProduct(product) + } + removeInvoice(toDelete.id) + } setToDelete(null) }} /> @@ -387,8 +448,8 @@ function PartySection({ config }: { config: TradeConfig }) { const partyKind = config.kind === 'sale' ? 'customer' : 'supplier' const parties = useMemo( - () => data.parties.filter((party) => party.kind === partyKind), - [data.parties, partyKind], + () => (config.kind === 'sale' ? customers(data.parties) : suppliers(data.parties)), + [data.parties, config.kind], ) const createDraft = (): Party => ({ diff --git a/src/components/layout/Layout.tsx b/src/components/layout/Layout.tsx index 9a8cc4a..4bfa6e9 100644 --- a/src/components/layout/Layout.tsx +++ b/src/components/layout/Layout.tsx @@ -5,6 +5,7 @@ import { navItems } from './navigation' import { useConnection } from '../../connection/ConnectionContext' import { useStore } from '../../store/AppStore' import { ConnectionRequired } from '../business/ConnectionRequired' +import { GlobalPartySync } from '../../parties/GlobalPartySync' import { Button, Card } from '../ui' function DataGate({ children }: { children: React.ReactNode }) { @@ -51,6 +52,15 @@ function DataGate({ children }: { children: React.ReactNode }) { return <>{children}> } +function DataGateInner({ children }: { children: React.ReactNode }) { + return ( + <> +