فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
A01: atomically trace return-linked cash settlements as corrections
davoodmehraban89 committed
Oct 20, 2026 at 17:24 UTC
603c43e3f5c9c30fb1fabc6d96d07a4f09f9970b
1 file changed
+19
src/core/RetailPostingService.js
+19
@@ -454,6 +454,25 @@ class RetailPostingServiceImpl {
454
status:paid===related.grandTotal?'paid':'partial'});
455
await tx.put('settlements',{id:uid('set_'),companyId:ctx.companyId,
456
invoiceId:related.id,transactionId:id,amount:sum,date:ctx.date,ownerUserId:actor()});
457
+ // A01: returning goods and handing back (or recovering) money are
458
+ // distinct corrections. Trace every cash settlement back to its posted
459
+ // return without rewriting either the original invoice or earlier cash
460
+ // entries. This insert shares the treasury/journal/audit transaction.
461
+ if (related.kind==='sale_return' || related.kind==='purchase_return') {
462
+ await tx.add('document_corrections',{
463
+ id:uid('cor_'),companyId:ctx.companyId,
464
+ sourceType:'invoice',sourceId:related.id,
465
+ correctionType:'settlement_refund',
466
+ resultType:'treasury',resultId:id,
467
+ correlationId:journal.id,
468
+ idempotencyKey:JSON.stringify([ctx.companyId,'settlement_refund',id]),
469
+ actorId:actor(),occurredAtUtc:today(),businessDate:ctx.date,
470
+ documentVersion:1,schemaVersion:1,
471
+ reasonCode:related.kind==='sale_return'
472
+ ? 'customer_credit_refund' : 'supplier_credit_recovery',
473
+ amount:sum
474
+ });
475
+ }
476
}
477
return transaction;
478
}