2026-05-12 19:58:53 +03:30
|
|
|
import { Maybe } from '@/core';
|
|
|
|
|
import { NativeBridgeService } from '@/core/services';
|
2026-05-12 20:35:04 +03:30
|
|
|
import { ToastService } from '@/core/services/toast.service';
|
2026-05-17 10:59:15 +03:30
|
|
|
import { PosConfigPrintService } from '@/domains/pos/modules/configs/components/print/services/main.service';
|
2026-05-12 19:58:53 +03:30
|
|
|
import { PosInfoStore } from '@/domains/pos/store';
|
2026-05-26 12:06:43 +03:30
|
|
|
import {
|
|
|
|
|
CatalogInvoiceTypeTagComponent,
|
|
|
|
|
CatalogTaxProviderStatusTagComponent,
|
|
|
|
|
} from '@/shared/catalog';
|
2026-05-12 19:58:53 +03:30
|
|
|
import { AppCardComponent, KeyValueComponent } 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';
|
2026-05-17 10:59:15 +03:30
|
|
|
import { formatWithCurrency } from '@/utils';
|
2026-05-12 19:58:53 +03:30
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
computed,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
inject,
|
|
|
|
|
Input,
|
|
|
|
|
Output,
|
|
|
|
|
TemplateRef,
|
|
|
|
|
ViewChild,
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
import { UrlTree } from '@angular/router';
|
|
|
|
|
import { ButtonDirective } from 'primeng/button';
|
|
|
|
|
import { Divider } from 'primeng/divider';
|
|
|
|
|
import { TableModule } from 'primeng/table';
|
|
|
|
|
|
|
|
|
|
export type TSaleInvoiceSingleViewVariant = 'full' | 'customer' | 'pos';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'shared-sale-invoice-single-view',
|
|
|
|
|
templateUrl: './sale-invoice-single-view.component.html',
|
|
|
|
|
imports: [
|
|
|
|
|
AppCardComponent,
|
|
|
|
|
KeyValueComponent,
|
|
|
|
|
Divider,
|
|
|
|
|
ButtonDirective,
|
|
|
|
|
PageDataListComponent,
|
|
|
|
|
TableModule,
|
|
|
|
|
PageLoadingComponent,
|
|
|
|
|
UikitEmptyStateComponent,
|
|
|
|
|
PriceMaskDirective,
|
|
|
|
|
CatalogTaxProviderStatusTagComponent,
|
2026-05-26 12:06:43 +03:30
|
|
|
CatalogInvoiceTypeTagComponent,
|
2026-05-12 19:58:53 +03:30
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
export class SharedSaleInvoiceSingleViewComponent {
|
|
|
|
|
private readonly nativeBridge = inject(NativeBridgeService);
|
|
|
|
|
private readonly posInfoStore = inject(PosInfoStore);
|
2026-05-12 20:35:04 +03:30
|
|
|
private readonly toastService = inject(ToastService);
|
2026-05-17 10:59:15 +03:30
|
|
|
//TODO: below service Must be transform from pos to shared.
|
|
|
|
|
private readonly service = inject(PosConfigPrintService);
|
2026-05-12 19:58:53 +03:30
|
|
|
|
|
|
|
|
@Input({ required: true }) loading!: boolean;
|
|
|
|
|
@Input() invoice!: Maybe<ISaleInvoiceFullResponse>;
|
|
|
|
|
@Input() variant: TSaleInvoiceSingleViewVariant = 'full';
|
|
|
|
|
@Input() backRoute?: UrlTree | string | any[];
|
|
|
|
|
|
|
|
|
|
@Output() onRefresh = new EventEmitter<void>();
|
|
|
|
|
|
|
|
|
|
@ViewChild('totalAmount', { static: false }) totalAmount!: TemplateRef<any>;
|
|
|
|
|
|
|
|
|
|
readonly posName = computed(() => {
|
|
|
|
|
if (this.posInfoStore.entity()) {
|
|
|
|
|
const { name, businessActivity, complex } = this.posInfoStore.entity()!;
|
|
|
|
|
return `${name} (${businessActivity.name} - ${complex.name})`;
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-17 10:59:15 +03:30
|
|
|
preparePrint = async () => {
|
|
|
|
|
if (this.invoice) {
|
|
|
|
|
const mustPrintConfig = await this.service.get();
|
|
|
|
|
|
|
|
|
|
const defaultPrintItems = [
|
|
|
|
|
{
|
|
|
|
|
title: 'اطلاعات صورتحساب',
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
label: 'شماره منحصر به فرد مالیاتی',
|
|
|
|
|
value: 'this.invoice',
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'شماره صورتحساب',
|
|
|
|
|
value: this.invoice.code,
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'موضوع صورتحساب',
|
|
|
|
|
value: 'this.invoice',
|
|
|
|
|
show: mustPrintConfig.invoice_template ?? true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'نوع صورتحساب',
|
|
|
|
|
value: 'this.invoice',
|
|
|
|
|
show: mustPrintConfig.invoice_template,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'تاریخ و ساعت',
|
|
|
|
|
value: this.invoice.invoice_date,
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'وضعیت صورتحساب مالیاتی',
|
|
|
|
|
value: this.invoice.status.translate,
|
|
|
|
|
show: mustPrintConfig.show_payment_info ?? true,
|
|
|
|
|
},
|
|
|
|
|
].filter((item) => item.show),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: `اطلاعات فروشنده`,
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
label: 'عنوان فروشگاه',
|
|
|
|
|
value: this.invoice.pos.complex.business_activity.name,
|
|
|
|
|
show: mustPrintConfig.business_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'عنوان شعبه',
|
|
|
|
|
value: this.invoice.pos.complex.name,
|
|
|
|
|
show: mustPrintConfig.complex_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'عنوان پایانه فروش',
|
|
|
|
|
value: this.invoice.pos.name,
|
|
|
|
|
show: mustPrintConfig.pos_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'شماره اقتصادی',
|
|
|
|
|
value: 'this.invoice.pos.complex.business_activity.economic_code',
|
|
|
|
|
show: mustPrintConfig.economic_code,
|
|
|
|
|
},
|
|
|
|
|
].filter((item) => item.show),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: `اطلاعات خریدار`,
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
label: 'نام خریدار',
|
|
|
|
|
value:
|
|
|
|
|
(this.invoice.customer
|
|
|
|
|
? this.invoice.customer.type === 'LEGAL'
|
|
|
|
|
? this.invoice.customer.legal?.company_name
|
|
|
|
|
: `${this.invoice.customer.individual?.first_name} ${this.invoice.customer.individual?.last_name}`
|
|
|
|
|
: this.invoice.unknown_customer?.name) || '-',
|
|
|
|
|
show: mustPrintConfig.customer_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'شماره اقتصادی',
|
|
|
|
|
value:
|
|
|
|
|
(this.invoice.customer
|
|
|
|
|
? this.invoice.customer.type === 'LEGAL'
|
|
|
|
|
? this.invoice.customer.legal?.economic_code
|
|
|
|
|
: this.invoice.customer.individual?.economic_code || '-'
|
|
|
|
|
: '-') || '-',
|
|
|
|
|
show: mustPrintConfig.customer_economic_code,
|
|
|
|
|
},
|
|
|
|
|
].filter((item) => item.show),
|
|
|
|
|
},
|
|
|
|
|
].filter((item) => item.items.length);
|
|
|
|
|
|
|
|
|
|
if (mustPrintConfig.show_items) {
|
|
|
|
|
for (let item of this.invoice.items) {
|
|
|
|
|
defaultPrintItems.push({
|
|
|
|
|
title: 'جزییات صورتحساب',
|
2026-05-12 20:35:04 +03:30
|
|
|
items: [
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'شرح',
|
|
|
|
|
value: item.good.name,
|
|
|
|
|
show: mustPrintConfig.items?.name,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'شناسه کالا / خدمت',
|
|
|
|
|
value: item.sku_code,
|
|
|
|
|
show: mustPrintConfig.items?.sku,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'تعداد / مقدار',
|
|
|
|
|
value: `${item.quantity} ${item.measure_unit_text}`,
|
|
|
|
|
show: mustPrintConfig.items?.quantity,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'قیمت واحد',
|
|
|
|
|
value: formatWithCurrency(item.unit_price),
|
|
|
|
|
show: mustPrintConfig.items?.base_amount,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'اجرت',
|
|
|
|
|
value: formatWithCurrency(item.payload.wages),
|
|
|
|
|
show:
|
|
|
|
|
mustPrintConfig.items?.wage && item.good_snapshot.good.pricing_model === 'GOLD',
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'سود',
|
|
|
|
|
value: formatWithCurrency(item.payload.wages),
|
|
|
|
|
show:
|
|
|
|
|
mustPrintConfig.items?.profit && item.good_snapshot.good.pricing_model === 'GOLD',
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'حقالعمل',
|
|
|
|
|
value: formatWithCurrency(item.payload.commission),
|
|
|
|
|
show:
|
|
|
|
|
mustPrintConfig.items?.commission &&
|
|
|
|
|
item.good_snapshot.good.pricing_model === 'GOLD',
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'مالیات بر ارزش افزوده',
|
|
|
|
|
value: 'item.good.tax',
|
|
|
|
|
show: mustPrintConfig.items?.tax,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'تخفیف',
|
|
|
|
|
value: formatWithCurrency(item.discount),
|
|
|
|
|
show: mustPrintConfig.items?.discount,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'مبلغ کل',
|
|
|
|
|
value: formatWithCurrency(item.total_amount),
|
|
|
|
|
show: mustPrintConfig.items?.total_amount,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
],
|
2026-05-17 10:59:15 +03:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return defaultPrintItems;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
printInvoice = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const printItems = await this.preparePrint();
|
|
|
|
|
if (printItems) {
|
|
|
|
|
this.nativeBridge.print(printItems);
|
2026-05-12 20:35:04 +03:30
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return this.toastService.error({
|
|
|
|
|
text: 'چاپ صورتحساب با خطا مواجه شد. لطفا دوباره تلاش کنید.',
|
|
|
|
|
});
|
2026-05-12 19:58:53 +03:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
columns: IColumn[] = [
|
|
|
|
|
{
|
|
|
|
|
field: 'name',
|
|
|
|
|
header: 'عنوان',
|
|
|
|
|
type: 'nested',
|
|
|
|
|
nestedOption: {
|
2026-05-21 21:35:34 +03:30
|
|
|
path: 'good_snapshot.name',
|
2026-05-12 19:58:53 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'sku_code',
|
|
|
|
|
header: 'شناسه کالا',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'unit_price',
|
|
|
|
|
header: 'قیمت واحد',
|
|
|
|
|
type: 'price',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'quantity',
|
|
|
|
|
header: 'مقدار',
|
|
|
|
|
customDataModel(item) {
|
|
|
|
|
return `${item.quantity} ${item.measure_unit_text}`;
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-05-28 18:27:38 +03:30
|
|
|
{
|
|
|
|
|
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',
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-05-28 16:37:58 +03:30
|
|
|
{
|
|
|
|
|
field: 'discount_amount',
|
|
|
|
|
header: 'مبلغ تخفیف',
|
|
|
|
|
type: 'price',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
field: 'tax_amount',
|
|
|
|
|
header: 'مبلغ مالیات',
|
|
|
|
|
type: 'price',
|
|
|
|
|
},
|
2026-05-12 19:58:53 +03:30
|
|
|
{
|
|
|
|
|
field: 'total_amount',
|
2026-05-28 16:37:58 +03:30
|
|
|
header: 'مبلغ قابل پرداخت',
|
2026-05-12 19:58:53 +03:30
|
|
|
type: 'price',
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
|
this.onRefresh.emit();
|
|
|
|
|
}
|
|
|
|
|
}
|