From 93ebc80da3ec318ad292e5de2b324fdea15f3e2c Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Wed, 17 Jun 2026 14:57:44 +0330 Subject: [PATCH] feat: enhance sale invoice component with dynamic invoice ID handling and navigation improvements --- .../saleInvoices/views/single.component.ts | 24 ++++++++---- ...le-invoice-single-info-card.component.html | 8 ++-- ...sale-invoice-single-info-card.component.ts | 39 ++++++------------- .../sale-invoice-single-view.component.html | 28 ++++++------- .../sale-invoice-single-view.component.ts | 8 ++-- 5 files changed, 50 insertions(+), 57 deletions(-) diff --git a/src/app/domains/pos/modules/saleInvoices/views/single.component.ts b/src/app/domains/pos/modules/saleInvoices/views/single.component.ts index d8c231d..7cea943 100644 --- a/src/app/domains/pos/modules/saleInvoices/views/single.component.ts +++ b/src/app/domains/pos/modules/saleInvoices/views/single.component.ts @@ -1,10 +1,10 @@ import { ToastService } from '@/core/services/toast.service'; import taxProviderStatusTranslatorUtil from '@/shared/catalog/taxProviderStatus/tax-provider-status-translator.util'; import { SharedSaleInvoiceSingleViewComponent } from '@/shared/components/invoices/sale-invoice-single-view.component'; -import pageParamsUtils from '@/utils/page-params.utils'; import { Component, computed, inject, signal } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute } from '@angular/router'; -import { finalize } from 'rxjs'; +import { distinctUntilChanged, finalize, map } from 'rxjs'; import { posSaleInvoicesNamedRoutes } from '../constants'; import { IPosCorrectionRequest } from '../models/correction'; import { IPosReturnFromSaleRequest } from '../models/returnFromSale'; @@ -20,8 +20,20 @@ export class PosSaleInvoiceComponent { private readonly store = inject(PosSaleInvoiceStore); private readonly toastService = inject(ToastService); - pageParams = computed(() => pageParamsUtils(this.route)); - invoiceId = signal(this.pageParams()['invoiceId']); + invoiceId = signal(''); + + constructor() { + this.route.paramMap + .pipe( + map((params) => params.get('invoiceId') ?? ''), + distinctUntilChanged(), + takeUntilDestroyed() + ) + .subscribe((invoiceId) => { + this.invoiceId.set(invoiceId); + this.store.getData(invoiceId); + }); + } inquiryLoading = signal(false); sendToTspLoading = signal(false); @@ -133,8 +145,4 @@ export class PosSaleInvoiceComponent { this.store.updateStatus(res.status); }); } - - ngOnInit() { - this.store.getData(this.invoiceId()); - } } diff --git a/src/app/shared/components/invoices/sale-invoice-single-info-card.component.html b/src/app/shared/components/invoices/sale-invoice-single-info-card.component.html index 3dbd6ce..f9b33e4 100644 --- a/src/app/shared/components/invoices/sale-invoice-single-info-card.component.html +++ b/src/app/shared/components/invoices/sale-invoice-single-info-card.component.html @@ -4,18 +4,18 @@ @if (invoice.referenced_by) { این صورت‌حساب، مرجع صورت‌حساب شماره‌ی - + {{ invoice.referenced_by.invoice_number }} - + می‌باشد. } @if (invoice.reference_invoice) { صورت‌حساب مرجع به شماره‌ی - + {{ invoice.reference_invoice.invoice_number }} - + می‌باشد. } diff --git a/src/app/shared/components/invoices/sale-invoice-single-info-card.component.ts b/src/app/shared/components/invoices/sale-invoice-single-info-card.component.ts index dccacd0..4f3ea5c 100644 --- a/src/app/shared/components/invoices/sale-invoice-single-info-card.component.ts +++ b/src/app/shared/components/invoices/sale-invoice-single-info-card.component.ts @@ -5,8 +5,8 @@ import { } from '@/shared/catalog'; import { CatalogInvoiceSettlementTypeTagComponent } from '@/shared/catalog/invoiceSettlementType'; import { PriceMaskDirective } from '@/shared/directives'; -import { Component, computed, inject, Input } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { Component, inject, Input } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; import { Card } from 'primeng/card'; import { Divider } from 'primeng/divider'; import { Message } from 'primeng/message'; @@ -37,6 +37,7 @@ export class SaleInvoiceSingleInfoCardComponent { @Input() variant: TSaleInvoiceSingleViewVariant = 'full'; private readonly route = inject(ActivatedRoute); + private readonly router = inject(Router); columns: IColumn[] = [ { @@ -107,34 +108,18 @@ export class SaleInvoiceSingleInfoCardComponent { }, ]; - referenceInvoiceRoute = computed(() => { - const referenceInvoiceId = this.invoice?.reference_invoice?.id; + navigateToRelatedInvoice(invoiceId: string) { const pagePath = this.route.pathFromRoot .flatMap((route) => route.snapshot.url.map((segment) => segment.path)) .join('/'); - if (!pagePath || !referenceInvoiceId) { - return pagePath; + if (pagePath && invoiceId) { + const pathParts = pagePath.split('/').filter(Boolean); + pathParts[pathParts.length - 1] = invoiceId; + + this.router.navigateByUrl(`/${pathParts.join('/')}`, { + skipLocationChange: false, + }); } - - const pathParts = pagePath.split('/').filter(Boolean); - pathParts[pathParts.length - 1] = referenceInvoiceId; - - return `/${pathParts.join('/')}`; - }); - referenceByInvoiceRoute = computed(() => { - const referenceInvoiceId = this.invoice?.referenced_by?.id; - const pagePath = this.route.pathFromRoot - .flatMap((route) => route.snapshot.url.map((segment) => segment.path)) - .join('/'); - - if (!pagePath || !referenceInvoiceId) { - return pagePath; - } - - const pathParts = pagePath.split('/').filter(Boolean); - pathParts[pathParts.length - 1] = referenceInvoiceId; - - return `/${pathParts.join('/')}`; - }); + } } diff --git a/src/app/shared/components/invoices/sale-invoice-single-view.component.html b/src/app/shared/components/invoices/sale-invoice-single-view.component.html index 06a5c5f..5ad9118 100644 --- a/src/app/shared/components/invoices/sale-invoice-single-view.component.html +++ b/src/app/shared/components/invoices/sale-invoice-single-view.component.html @@ -7,7 +7,7 @@ - @if (!isApplication && canDoActionOnInvoice()) { + @if (!isApplication && canDoActionOnInvoice) { @@ -18,7 +18,7 @@ - @if (isApplication && moreActionMenuItems().length && canDoActionOnInvoice()) { + @if (isApplication && moreActionMenuItems().length && canDoActionOnInvoice) {
@for (action of moreActionMenuItems(); track action.label || $index) { @@ -35,7 +35,7 @@
} - @if (canDoActionOnInvoice()) { + @if (canDoActionOnInvoice) { } } -} - -
- - برای امکان دسترسی به صورت‌حساب به صورت آنلاین، کد QR را اسکن کنید. - - - - -
-
+ +
+ + برای امکان دسترسی به صورت‌حساب به صورت آنلاین، کد QR را اسکن کنید. + + + + +
+
+} diff --git a/src/app/shared/components/invoices/sale-invoice-single-view.component.ts b/src/app/shared/components/invoices/sale-invoice-single-view.component.ts index 8fbbe52..5cc16ba 100644 --- a/src/app/shared/components/invoices/sale-invoice-single-view.component.ts +++ b/src/app/shared/components/invoices/sale-invoice-single-view.component.ts @@ -115,16 +115,16 @@ export class SharedSaleInvoiceSingleViewComponent { private pendingCorrectionSubmitResolver: Maybe<(allowed: boolean, payment?: IPayment) => void> = null; - publicInvoiceRoute = computed(() => { + get publicInvoiceRoute() { if (this.invoice) { return `${window.location.origin}/sale-invoices/${this.invoice.id}`; } return ''; - }); + } - canDoActionOnInvoice = computed(() => { + get canDoActionOnInvoice() { return !this.invoice?.referenced_by; - }); + } showErrors = () => {}; inquiry = () => {