feat: enhance inner pages header with back button functionality and emit event on back click

fix: update total price info handling in correction form and ensure accurate calculations

refactor: streamline sale invoice single view component by extracting info card into a separate component

style: adjust button sizes in payment forms for better UI consistency

feat: implement season picker navigation controls to prevent out-of-bounds selection

fix: improve price formatting utility to handle undefined values gracefully

chore: update environment configuration for API base URL

feat: add navigation service to manage routing history and back navigation
This commit is contained in:
2026-06-11 16:13:48 +03:30
parent 88f45eee38
commit b4cd4c05f2
28 changed files with 526 additions and 310 deletions
@@ -1,26 +1,17 @@
import { Maybe } from '@/core';
import { NativeBridgeService } from '@/core/services';
import { NavigationService } from '@/core/services/navigation.service';
import { ToastService } from '@/core/services/toast.service';
import { PosConfigPrintService } from '@/domains/pos/modules/configs/components/print/services/main.service';
import { IPosReturnFromSaleRequest } from '@/domains/pos/modules/saleInvoices/models/returnFromSale';
import { IPosOrderItem } from '@/domains/pos/modules/shop/models';
import { PosInfoStore } from '@/domains/pos/store';
import {
CatalogInvoiceTypeTagComponent,
CatalogTaxProviderStatusTagComponent,
TspProviderResponseStatus,
} from '@/shared/catalog';
import { CatalogInvoiceSettlementTypeTagComponent } from '@/shared/catalog/invoiceSettlementType';
import { KeyValueComponent, SharedLightBottomsheetComponent } from '@/shared/components';
import { TspProviderResponseStatus } from '@/shared/catalog';
import { SharedLightBottomsheetComponent } from '@/shared/components';
import { ISaleInvoiceFullResponse } from '@/shared/components/invoices/sale-invoice-full-response.model';
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import {
IColumn,
PageDataListComponent,
} from '@/shared/components/pageDataList/page-data-list.component';
import { PriceMaskDirective } from '@/shared/directives';
import { UikitEmptyStateComponent } from '@/uikit';
import { formatWithCurrency } from '@/utils';
import { formatJalali, formatWithCurrency } from '@/utils';
import {
Component,
computed,
@@ -33,12 +24,10 @@ import {
TemplateRef,
ViewChild,
} from '@angular/core';
import { UrlTree } from '@angular/router';
import { Router } from '@angular/router';
import { QRCodeComponent } from 'angularx-qrcode';
import { Button, ButtonDirective } from 'primeng/button';
import { Card } from 'primeng/card';
import { Dialog } from 'primeng/dialog';
import { Divider } from 'primeng/divider';
import { ProgressSpinner } from 'primeng/progressspinner';
import { TableModule } from 'primeng/table';
import { Observable } from 'rxjs';
import { AppConfirmationService } from '../confirmationDialog/confirmation-dialog.service';
@@ -46,8 +35,11 @@ import { InnerPagesHeaderComponent } from '../innerPagesHeader/inner-pages-heade
import { SharedCorrectionFormComponent } from './correctionForm';
import { CorrectionInvoiceFormValue, ICorrectionRequest, ReturnFromSaleFormValue } from './models';
import { SharedReturnFormComponent } from './returnForm/form.component';
import {
SaleInvoiceSingleInfoCardComponent,
TSaleInvoiceSingleViewVariant,
} from './sale-invoice-single-info-card.component';
export type TSaleInvoiceSingleViewVariant = 'full' | 'customer' | 'pos';
type TActionMenuItem = {
label: string;
icon: string;
@@ -60,24 +52,17 @@ type TActionMenuItem = {
selector: 'shared-sale-invoice-single-view',
templateUrl: './sale-invoice-single-view.component.html',
imports: [
KeyValueComponent,
Divider,
PageDataListComponent,
TableModule,
PageLoadingComponent,
UikitEmptyStateComponent,
PriceMaskDirective,
CatalogTaxProviderStatusTagComponent,
CatalogInvoiceTypeTagComponent,
Button,
CatalogInvoiceSettlementTypeTagComponent,
SharedLightBottomsheetComponent,
ProgressSpinner,
SharedReturnFormComponent,
SharedCorrectionFormComponent,
Dialog,
ButtonDirective,
InnerPagesHeaderComponent,
SaleInvoiceSingleInfoCardComponent,
QRCodeComponent,
Card,
],
})
@@ -88,11 +73,13 @@ export class SharedSaleInvoiceSingleViewComponent {
//TODO: below service Must be transform from pos to shared.
private readonly service = inject(PosConfigPrintService);
private readonly confirmationService = inject(AppConfirmationService);
private readonly router = inject(Router);
private readonly navigationService = inject(NavigationService);
@Input({ required: true }) loading!: boolean;
@Input() invoice!: Maybe<ISaleInvoiceFullResponse>;
@Input() variant: TSaleInvoiceSingleViewVariant = 'full';
@Input() backRoute?: UrlTree | string | any[];
@Input() backRoute?: string;
@Input() sendToTspLoading: boolean = false;
@Input() resendToTspLoading: boolean = false;
@Input() inquiryLoading: boolean = false;
@@ -109,6 +96,14 @@ export class SharedSaleInvoiceSingleViewComponent {
moreActionMenuItems = signal<TActionMenuItem[]>([]);
showCorrectionForm = signal(false);
showReturnFromSaleForm = signal(false);
showQrCodeDialog = signal(false);
publicInvoiceRoute = computed(() => {
if (this.invoice) {
return `${window.location.origin}/sale-invoices/${this.invoice.id}`;
}
return '';
});
showErrors = () => {};
inquiry = () => {
@@ -231,39 +226,39 @@ export class SharedSaleInvoiceSingleViewComponent {
preparePrint = async () => {
if (this.invoice) {
const mustPrintConfig = await this.service.get();
const mustPrintConfig = await this.service.getVisibleItems();
const defaultPrintItems = [
{
title: 'اطلاعات صورت‌حساب',
items: [
{
label: 'شماره',
value: this.invoice.invoice_number.toString(),
show: true,
},
{
label: 'شماره منحصر به فرد مالیاتی',
value: 'this.invoice',
value: this.invoice.tax_id || '-',
show: true,
},
{
label: 'شماره صورت‌حساب',
value: this.invoice.code,
show: true,
},
{
label: 'موضوع صورت‌حساب',
value: 'this.invoice',
show: mustPrintConfig.invoice_template ?? true,
},
{
label: 'نوع صورت‌حساب',
value: 'this.invoice',
label: 'نوع',
value: this.invoice.type.translate,
show: mustPrintConfig.invoice_template,
},
{
label: 'تاریخ و ساعت',
value: this.invoice.invoice_date,
label: 'موضوع',
value: this.invoice.pos.complex.business_activity.guild.name,
show: mustPrintConfig.invoice_template ?? true,
},
{
label: 'تاریخ',
value: formatJalali(this.invoice.invoice_date),
show: true,
},
{
label: 'وضعیت صورت‌حساب مالیاتی',
label: 'وضعیت صدور',
value: this.invoice.status.translate,
show: mustPrintConfig.show_payment_info ?? true,
},
@@ -273,23 +268,23 @@ export class SharedSaleInvoiceSingleViewComponent {
title: `اطلاعات فروشنده`,
items: [
{
label: 'عنوان فروشگاه',
label: 'فروشگاه',
value: this.invoice.pos.complex.business_activity.name,
show: mustPrintConfig.business_name,
},
{
label: 'عنوان شعبه',
label: 'شعبه',
value: this.invoice.pos.complex.name,
show: mustPrintConfig.complex_name,
},
{
label: 'عنوان پایانه‌ فروش',
label: 'پایانه‌ فروش',
value: this.invoice.pos.name,
show: mustPrintConfig.pos_name,
},
{
label: 'شماره اقتصادی',
value: 'this.invoice.pos.complex.business_activity.economic_code',
value: this.invoice.pos.complex.business_activity.economic_code,
show: mustPrintConfig.economic_code,
},
].filter((item) => item.show),
@@ -328,59 +323,67 @@ export class SharedSaleInvoiceSingleViewComponent {
items: [
{
label: 'شرح',
value: item.good.name,
show: mustPrintConfig.items?.name,
value: item.good_snapshot.name,
show: mustPrintConfig.item_name ?? true,
},
{
label: 'شناسه کالا / خدمت',
value: item.sku_code,
show: mustPrintConfig.items?.sku,
show: mustPrintConfig.item_sku ?? true,
},
{
label: 'تعداد / مقدار',
value: `${item.quantity} ${item.measure_unit_text}`,
show: mustPrintConfig.items?.quantity,
show: mustPrintConfig.item_quantity ?? true,
},
{
label: 'قیمت واحد',
value: formatWithCurrency(item.unit_price),
show: mustPrintConfig.items?.base_amount,
show: mustPrintConfig.item_base_amount ?? true,
},
{
label: 'اجرت',
value: formatWithCurrency(item.payload.wages),
show: mustPrintConfig.items?.wage && item.good_snapshot.pricing_model === 'GOLD',
show:
(mustPrintConfig.item_wage ?? true) &&
item.good_snapshot.pricing_model === 'GOLD',
},
{
label: 'سود',
value: formatWithCurrency(item.payload.wages),
show: mustPrintConfig.items?.profit && item.good_snapshot.pricing_model === 'GOLD',
value: formatWithCurrency(item.payload.profit),
show:
(mustPrintConfig.item_profit ?? true) &&
item.good_snapshot.pricing_model === 'GOLD',
},
{
label: 'حق‌العمل',
value: formatWithCurrency(item.payload.commission),
show:
mustPrintConfig.items?.commission && item.good_snapshot.pricing_model === 'GOLD',
(mustPrintConfig.item_commission ?? true) &&
item.good_snapshot.pricing_model === 'GOLD',
},
{
label: 'مالیات بر ارزش افزوده',
value: 'item.good.tax',
show: mustPrintConfig.items?.tax,
value: formatWithCurrency(item.tax_amount),
show: mustPrintConfig.item_tax ?? true,
},
{
label: 'تخفیف',
value: formatWithCurrency(item.discount),
show: mustPrintConfig.items?.discount,
value: formatWithCurrency(item.discount_amount),
show: mustPrintConfig.item_discount ?? true,
},
{
label: 'مبلغ کل',
value: formatWithCurrency(item.total_amount),
show: mustPrintConfig.items?.total_amount,
show: mustPrintConfig.item_total_amount ?? true,
},
],
});
}
}
console.log(defaultPrintItems);
return defaultPrintItems;
}
return null;
@@ -389,6 +392,7 @@ export class SharedSaleInvoiceSingleViewComponent {
printInvoice = async () => {
try {
const printItems = await this.preparePrint();
if (printItems) {
this.nativeBridge.print(printItems);
}
@@ -399,75 +403,6 @@ export class SharedSaleInvoiceSingleViewComponent {
}
};
columns: IColumn[] = [
{
field: 'name',
header: 'عنوان',
type: 'nested',
nestedOption: {
path: 'good_snapshot.name',
},
},
{
field: 'sku_code',
header: 'شناسه کالا',
},
{
field: 'unit_price',
header: 'قیمت واحد',
type: 'price',
},
{
field: 'quantity',
header: 'مقدار',
customDataModel(item) {
return `${item.quantity} ${item.measure_unit_text}`;
},
},
{
field: 'commission',
header: 'کارمزد',
type: 'nested',
nestedOption: {
path: 'payload.commission',
type: 'price',
},
},
{
field: 'wages',
header: 'اجرت',
type: 'nested',
nestedOption: {
path: 'payload.wages',
type: 'price',
},
},
{
field: 'profit',
header: 'سود',
type: 'nested',
nestedOption: {
path: 'payload.profit',
type: 'price',
},
},
{
field: 'discount_amount',
header: 'مبلغ تخفیف',
type: 'price',
},
{
field: 'tax_amount',
header: 'مبلغ مالیات',
type: 'price',
},
{
field: 'total_amount',
header: 'مبلغ قابل پرداخت',
type: 'price',
},
];
refresh() {
this.onRefresh.emit();
}
@@ -503,10 +438,10 @@ export class SharedSaleInvoiceSingleViewComponent {
const quantity = Number(item.quantity || 0);
const unit_price = Number(source.unit_price || 0);
const discount_amount = Number(source.discount || 0);
const discount_amount = Number(source.discount_amount || 0);
const base_total_amount = unit_price * quantity;
const total_amount = Number(source.total_amount || 0);
const tax_amount = Number(source.payload?.wages || 0);
const tax_amount = Number(source.tax_amount || 0);
return {
good_id: source.good_id,
@@ -537,4 +472,11 @@ export class SharedSaleInvoiceSingleViewComponent {
returnSubmit(event: ReturnFromSaleFormValue) {
this.sendReturnFromSale(this.mapReturnFromSaleRequest(event));
}
backToPrevPage() {
this.navigationService.back(this.backRoute);
}
showQrCode() {
this.showQrCodeDialog.set(true);
}
}