فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

A01: require validated third-party cheque endorsee and atomic endorsement trail

davoodmehraban89 committed Oct 22, 2026 at 23:14 UTC 8e08e8653c8329add38bc36920ee199f820e8cf2
1 file changed +35 -2
src/core/RetailPostingService.js
+35 -2
@@ -582,6 +582,23 @@ class RetailPostingServiceImpl {
582 if(cheque.status!=='pending')throw Error('تنها چک در جریان قابل تعیین تکلیف است');
583 if(!['cleared','bounced','returned','spent'].includes(status))throw Error('وضعیت چک نامعتبر است');
584 if(status==='spent'&&cheque.direction!=='inbound')throw Error('فقط چک دریافتی قابل خرج‌کرد است');
585 + // Endorsing an incoming cheque pays a *different* counterparty.
586 + // The drawer still owns the cheque asset; the endorsee is the
587 + // payable we debit. Do not silently use the original drawer for both.
588 + let endorsee=null;
589 + if(status==='spent') {
590 + if(typeof options.endorseeContactId!=='string'||!options.endorseeContactId.trim()) {
591 + throw Error('برای واگذاری چک، انتخاب شخص دریافت‌کننده الزامی است');
592 + }
593 + if(options.endorseeContactId===cheque.contactId) {
594 + throw Error('دریافت‌کننده واگذاری باید با صادرکننده چک متفاوت باشد');
595 + }
596 + endorsee=sameCompany(await tx.get('contacts',options.endorseeContactId),
597 + company,'دریافت‌کننده واگذاری چک');
598 + if(options.explicitlyApproved!==true) {
599 + throw Error('واگذاری چک نیازمند تأیید صریح است');
600 + }
601 + }
602 // The actual cheque event is posted in an open period, which may be
603 // later than its contractual due date (including when that period closed).
604 // An explicitly blank date must fail rather than silently fall back.
@@ -604,12 +621,28 @@ class RetailPostingServiceImpl {
621 else if(status==='spent')target=leg(ctx,LEDGER_CODES.payable);
622 else target=leg(ctx,LEDGER_CODES[inbound?'receivable':'payable']);
623 const lines=inbound?
607 - [postLine(target,sum,0,ref),postLine(chequeAccount,0,sum,ref)]:
624 + [postLine(target,sum,0,endorsee?{contactId:endorsee.id}:ref),
625 + postLine(chequeAccount,0,sum,ref)]:
626 [postLine(chequeAccount,sum,0,ref),postLine(target,0,sum,ref)];
627 const journal=await this.journal(tx,ctx,'cheque_status',id,lines,'تغییر وضعیت چک '+status,2);
628 const updated={...cheque,status,statusVersion:2,
611 - statusJournalId:journal.id,statusBusinessDate:ctx.date,statusChangedAt:today()};
629 + statusJournalId:journal.id,statusBusinessDate:ctx.date,statusChangedAt:today(),
630 + ...(endorsee?{endorseeContactId:endorsee.id,endorseeContactName:endorsee.name,
631 + endorsementApprovedBy:actor(),endorsementApprovedAtUtc:today()}: {})};
632 await tx.put('cheques',updated);
633 + if(endorsee) {
634 + await tx.add('document_corrections',{
635 + id:uid('cor_'),companyId:company,sourceType:'cheque',sourceId:id,
636 + correctionType:'endorsement',resultType:'journal',resultId:journal.id,
637 + correlationId:journal.id,
638 + idempotencyKey:JSON.stringify([company,'cheque_endorsement',id,2]),
639 + actorId:actor(),occurredAtUtc:today(),businessDate:ctx.date,
640 + documentVersion:2,schemaVersion:1,actionCode:'third_party_cheque_endorsement',
641 + reasonCode:'supplier_settlement',originalDrawerContactId:cheque.contactId,
642 + endorseeContactId:endorsee.id,approvalMethod:'explicit_confirmation',
643 + approvedBy:actor(),approvedAtUtc:today(),amount:sum
644 + });
645 + }
646 if(status==='cleared'){
647 if(!bank)throw Error('بانک یا صندوق چک مشخص نیست');
648 await tx.put('treasury',{id:uid('tx_'),companyId:company,recordType:'transaction',