2026-05-12 19:58:53 +03:30
|
|
|
import { Maybe } from '@/core';
|
|
|
|
|
import { NativeBridgeService } from '@/core/services';
|
2026-06-11 16:13:48 +03:30
|
|
|
import { NavigationService } from '@/core/services/navigation.service';
|
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-06-06 19:52:58 +03:30
|
|
|
import { IPosReturnFromSaleRequest } from '@/domains/pos/modules/saleInvoices/models/returnFromSale';
|
|
|
|
|
import { IPosOrderItem } from '@/domains/pos/modules/shop/models';
|
2026-05-12 19:58:53 +03:30
|
|
|
import { PosInfoStore } from '@/domains/pos/store';
|
2026-06-11 16:13:48 +03:30
|
|
|
import { TspProviderResponseStatus } from '@/shared/catalog';
|
|
|
|
|
import { SharedLightBottomsheetComponent } from '@/shared/components';
|
2026-05-12 19:58:53 +03:30
|
|
|
import { ISaleInvoiceFullResponse } from '@/shared/components/invoices/sale-invoice-full-response.model';
|
|
|
|
|
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
|
|
|
|
|
import { UikitEmptyStateComponent } from '@/uikit';
|
2026-06-11 16:13:48 +03:30
|
|
|
import { formatJalali, formatWithCurrency } from '@/utils';
|
2026-05-12 19:58:53 +03:30
|
|
|
import {
|
|
|
|
|
Component,
|
|
|
|
|
computed,
|
|
|
|
|
EventEmitter,
|
|
|
|
|
inject,
|
|
|
|
|
Input,
|
|
|
|
|
Output,
|
2026-05-30 19:05:23 +03:30
|
|
|
signal,
|
|
|
|
|
SimpleChanges,
|
2026-05-12 19:58:53 +03:30
|
|
|
TemplateRef,
|
|
|
|
|
ViewChild,
|
|
|
|
|
} from '@angular/core';
|
2026-06-11 16:13:48 +03:30
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { QRCodeComponent } from 'angularx-qrcode';
|
2026-06-08 13:35:58 +03:30
|
|
|
import { Button, ButtonDirective } from 'primeng/button';
|
|
|
|
|
import { Card } from 'primeng/card';
|
2026-05-12 19:58:53 +03:30
|
|
|
import { TableModule } from 'primeng/table';
|
2026-05-31 17:12:43 +03:30
|
|
|
import { Observable } from 'rxjs';
|
2026-05-30 19:05:23 +03:30
|
|
|
import { AppConfirmationService } from '../confirmationDialog/confirmation-dialog.service';
|
2026-06-08 13:35:58 +03:30
|
|
|
import { InnerPagesHeaderComponent } from '../innerPagesHeader/inner-pages-header.component';
|
2026-06-06 19:52:58 +03:30
|
|
|
import { SharedCorrectionFormComponent } from './correctionForm';
|
|
|
|
|
import { CorrectionInvoiceFormValue, ICorrectionRequest, ReturnFromSaleFormValue } from './models';
|
2026-06-01 13:53:42 +03:30
|
|
|
import { SharedReturnFormComponent } from './returnForm/form.component';
|
2026-06-11 16:13:48 +03:30
|
|
|
import {
|
|
|
|
|
SaleInvoiceSingleInfoCardComponent,
|
|
|
|
|
TSaleInvoiceSingleViewVariant,
|
|
|
|
|
} from './sale-invoice-single-info-card.component';
|
2026-05-12 19:58:53 +03:30
|
|
|
|
2026-06-08 13:35:58 +03:30
|
|
|
type TActionMenuItem = {
|
|
|
|
|
label: string;
|
|
|
|
|
icon: string;
|
|
|
|
|
command: () => void;
|
|
|
|
|
neededStatus?: TspProviderResponseStatus;
|
|
|
|
|
severity?: 'secondary' | 'info' | 'warn' | 'danger' | 'contrast';
|
|
|
|
|
};
|
2026-05-12 19:58:53 +03:30
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'shared-sale-invoice-single-view',
|
|
|
|
|
templateUrl: './sale-invoice-single-view.component.html',
|
|
|
|
|
imports: [
|
|
|
|
|
TableModule,
|
|
|
|
|
PageLoadingComponent,
|
|
|
|
|
UikitEmptyStateComponent,
|
2026-05-30 19:05:23 +03:30
|
|
|
Button,
|
2026-05-31 17:12:43 +03:30
|
|
|
SharedLightBottomsheetComponent,
|
2026-06-01 13:53:42 +03:30
|
|
|
SharedReturnFormComponent,
|
2026-06-06 19:52:58 +03:30
|
|
|
SharedCorrectionFormComponent,
|
2026-06-08 13:35:58 +03:30
|
|
|
ButtonDirective,
|
|
|
|
|
InnerPagesHeaderComponent,
|
2026-06-11 16:13:48 +03:30
|
|
|
SaleInvoiceSingleInfoCardComponent,
|
|
|
|
|
QRCodeComponent,
|
2026-06-08 13:35:58 +03:30
|
|
|
Card,
|
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-30 19:05:23 +03:30
|
|
|
private readonly confirmationService = inject(AppConfirmationService);
|
2026-06-11 16:13:48 +03:30
|
|
|
private readonly router = inject(Router);
|
|
|
|
|
private readonly navigationService = inject(NavigationService);
|
2026-05-12 19:58:53 +03:30
|
|
|
|
|
|
|
|
@Input({ required: true }) loading!: boolean;
|
|
|
|
|
@Input() invoice!: Maybe<ISaleInvoiceFullResponse>;
|
|
|
|
|
@Input() variant: TSaleInvoiceSingleViewVariant = 'full';
|
2026-06-11 16:13:48 +03:30
|
|
|
@Input() backRoute?: string;
|
2026-05-31 17:12:43 +03:30
|
|
|
@Input() sendToTspLoading: boolean = false;
|
|
|
|
|
@Input() resendToTspLoading: boolean = false;
|
|
|
|
|
@Input() inquiryLoading: boolean = false;
|
2026-05-12 19:58:53 +03:30
|
|
|
|
|
|
|
|
@Output() onRefresh = new EventEmitter<void>();
|
2026-05-31 17:12:43 +03:30
|
|
|
@Output() onSendToTsp = new EventEmitter<Observable<any>>();
|
2026-06-03 17:48:54 +03:30
|
|
|
@Output() onResendToTsp = new EventEmitter<Observable<any>>();
|
2026-05-31 17:12:43 +03:30
|
|
|
@Output() onInquiry = new EventEmitter<Observable<any>>();
|
2026-06-06 19:52:58 +03:30
|
|
|
@Output() onCorrection = new EventEmitter<ICorrectionRequest>();
|
|
|
|
|
@Output() onReturnFromSale = new EventEmitter<IPosReturnFromSaleRequest>();
|
2026-05-12 19:58:53 +03:30
|
|
|
|
|
|
|
|
@ViewChild('totalAmount', { static: false }) totalAmount!: TemplateRef<any>;
|
|
|
|
|
|
2026-06-08 13:35:58 +03:30
|
|
|
moreActionMenuItems = signal<TActionMenuItem[]>([]);
|
2026-06-01 13:53:42 +03:30
|
|
|
showCorrectionForm = signal(false);
|
2026-06-06 19:52:58 +03:30
|
|
|
showReturnFromSaleForm = signal(false);
|
2026-06-11 16:13:48 +03:30
|
|
|
showQrCodeDialog = signal(false);
|
|
|
|
|
|
|
|
|
|
publicInvoiceRoute = computed(() => {
|
|
|
|
|
if (this.invoice) {
|
|
|
|
|
return `${window.location.origin}/sale-invoices/${this.invoice.id}`;
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
});
|
2026-05-30 19:05:23 +03:30
|
|
|
|
2026-06-08 13:35:58 +03:30
|
|
|
showErrors = () => {};
|
|
|
|
|
inquiry = () => {
|
2026-05-31 17:12:43 +03:30
|
|
|
this.onInquiry.emit();
|
2026-06-08 13:35:58 +03:30
|
|
|
};
|
|
|
|
|
send = () => {
|
2026-05-31 17:12:43 +03:30
|
|
|
this.onSendToTsp.emit();
|
2026-06-08 13:35:58 +03:30
|
|
|
};
|
|
|
|
|
sendCorrection = (event: ICorrectionRequest) => {
|
2026-06-06 19:52:58 +03:30
|
|
|
this.onCorrection.emit(event);
|
2026-06-08 13:35:58 +03:30
|
|
|
};
|
|
|
|
|
resend = () => {
|
2026-06-03 17:48:54 +03:30
|
|
|
this.onResendToTsp.emit();
|
2026-06-08 13:35:58 +03:30
|
|
|
};
|
|
|
|
|
sendReturnFromSale = (event: IPosReturnFromSaleRequest) => {
|
2026-06-06 19:52:58 +03:30
|
|
|
this.onReturnFromSale.emit(event);
|
2026-06-08 13:35:58 +03:30
|
|
|
};
|
|
|
|
|
showCorrection = () => {
|
|
|
|
|
this.showCorrectionForm.set(true);
|
|
|
|
|
};
|
|
|
|
|
showReturnFromSale = () => {
|
|
|
|
|
this.showReturnFromSaleForm.set(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly actions: TActionMenuItem[] = [
|
|
|
|
|
{
|
|
|
|
|
label: 'ارسال مجدد صورتحساب',
|
|
|
|
|
icon: 'pi pi-send',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.SEND_FAILURE,
|
|
|
|
|
severity: 'info',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.resend(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'ارسال صورتحساب',
|
|
|
|
|
icon: 'pi pi-send',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.NOT_SEND,
|
|
|
|
|
severity: 'info',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.send(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'استعلام وضعیت',
|
|
|
|
|
icon: 'pi pi-info',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.FISCAL_QUEUED,
|
|
|
|
|
severity: 'info',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.inquiry(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'دلایل خطا',
|
|
|
|
|
icon: 'pi pi-question',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.FAILURE,
|
|
|
|
|
severity: 'danger',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.showErrors(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'ابطال',
|
|
|
|
|
icon: 'pi pi-eraser',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.SUCCESS,
|
|
|
|
|
severity: 'danger',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.showRevokeConfirmation(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'اصلاح',
|
|
|
|
|
icon: 'pi pi-file-edit',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.SUCCESS,
|
|
|
|
|
severity: 'warn',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.showCorrection(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'برگشت از فروش',
|
|
|
|
|
icon: 'pi pi-cart-minus',
|
|
|
|
|
neededStatus: TspProviderResponseStatus.SUCCESS,
|
|
|
|
|
severity: 'warn',
|
2026-06-09 13:31:48 +03:30
|
|
|
command: () => this.showReturnFromSale(),
|
2026-06-08 13:35:58 +03:30
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
get actionLoading() {
|
|
|
|
|
return this.sendToTspLoading || this.inquiryLoading || this.resendToTspLoading;
|
2026-06-06 19:52:58 +03:30
|
|
|
}
|
2026-06-08 13:35:58 +03:30
|
|
|
|
2026-06-01 13:53:42 +03:30
|
|
|
async showRevokeConfirmation() {
|
|
|
|
|
await this.confirmationService.ask({
|
2026-05-31 13:54:34 +03:30
|
|
|
header: `ابطال صورتحساب شماره ${this.invoice!.invoice_number}`,
|
|
|
|
|
message: `در صورت تایید ابطال صورتحساب شماره ${this.invoice!.invoice_number} بر روی دکمهی ابطال کلیک کنید.`,
|
2026-05-30 19:05:23 +03:30
|
|
|
acceptLabel: 'ابطال',
|
|
|
|
|
acceptButtonProps: {
|
|
|
|
|
severity: 'dangerdock',
|
|
|
|
|
},
|
2026-06-01 13:53:42 +03:30
|
|
|
variant: 'danger',
|
2026-05-30 19:05:23 +03:30
|
|
|
|
2026-06-01 13:53:42 +03:30
|
|
|
accept: async () => {
|
2026-05-30 19:05:23 +03:30
|
|
|
// this.deferredInstallPrompt.prompt();
|
|
|
|
|
// this.deferredInstallPrompt.userChoice.finally(() => {
|
|
|
|
|
// this.deferredInstallPrompt = null;
|
|
|
|
|
// this.canInstall.set(false);
|
|
|
|
|
// window.location.reload();
|
|
|
|
|
// });
|
|
|
|
|
// },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
|
if (changes['invoice'] && this.invoice) {
|
|
|
|
|
const invoiceStatus = this.invoice.status.value;
|
|
|
|
|
|
|
|
|
|
this.moreActionMenuItems.set(
|
2026-06-08 13:35:58 +03:30
|
|
|
this.actions.filter((action) => action.neededStatus === invoiceStatus)
|
2026-05-30 19:05:23 +03:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 19:58:53 +03:30
|
|
|
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) {
|
2026-06-11 16:13:48 +03:30
|
|
|
const mustPrintConfig = await this.service.getVisibleItems();
|
2026-05-17 10:59:15 +03:30
|
|
|
|
|
|
|
|
const defaultPrintItems = [
|
|
|
|
|
{
|
|
|
|
|
title: 'اطلاعات صورتحساب',
|
|
|
|
|
items: [
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'شماره',
|
|
|
|
|
value: this.invoice.invoice_number.toString(),
|
2026-05-17 10:59:15 +03:30
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'شماره منحصر به فرد مالیاتی',
|
|
|
|
|
value: this.invoice.tax_id || '-',
|
2026-05-17 10:59:15 +03:30
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'نوع',
|
|
|
|
|
value: this.invoice.type.translate,
|
|
|
|
|
show: mustPrintConfig.invoice_template,
|
2026-05-17 10:59:15 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'موضوع',
|
|
|
|
|
value: this.invoice.pos.complex.business_activity.guild.name,
|
|
|
|
|
show: mustPrintConfig.invoice_template ?? true,
|
2026-05-17 10:59:15 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'تاریخ',
|
|
|
|
|
value: formatJalali(this.invoice.invoice_date),
|
2026-05-17 10:59:15 +03:30
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'وضعیت صدور',
|
2026-05-17 10:59:15 +03:30
|
|
|
value: this.invoice.status.translate,
|
|
|
|
|
show: mustPrintConfig.show_payment_info ?? true,
|
|
|
|
|
},
|
|
|
|
|
].filter((item) => item.show),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: `اطلاعات فروشنده`,
|
|
|
|
|
items: [
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'فروشگاه',
|
2026-05-17 10:59:15 +03:30
|
|
|
value: this.invoice.pos.complex.business_activity.name,
|
|
|
|
|
show: mustPrintConfig.business_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'شعبه',
|
2026-05-17 10:59:15 +03:30
|
|
|
value: this.invoice.pos.complex.name,
|
|
|
|
|
show: mustPrintConfig.complex_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-06-11 16:13:48 +03:30
|
|
|
label: 'پایانه فروش',
|
2026-05-17 10:59:15 +03:30
|
|
|
value: this.invoice.pos.name,
|
|
|
|
|
show: mustPrintConfig.pos_name,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'شماره اقتصادی',
|
2026-06-11 16:13:48 +03:30
|
|
|
value: this.invoice.pos.complex.business_activity.economic_code,
|
2026-05-17 10:59:15 +03:30
|
|
|
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: 'شرح',
|
2026-06-11 16:13:48 +03:30
|
|
|
value: item.good_snapshot.name,
|
|
|
|
|
show: mustPrintConfig.item_name ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'شناسه کالا / خدمت',
|
|
|
|
|
value: item.sku_code,
|
2026-06-11 16:13:48 +03:30
|
|
|
show: mustPrintConfig.item_sku ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'تعداد / مقدار',
|
|
|
|
|
value: `${item.quantity} ${item.measure_unit_text}`,
|
2026-06-11 16:13:48 +03:30
|
|
|
show: mustPrintConfig.item_quantity ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'قیمت واحد',
|
|
|
|
|
value: formatWithCurrency(item.unit_price),
|
2026-06-11 16:13:48 +03:30
|
|
|
show: mustPrintConfig.item_base_amount ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'اجرت',
|
|
|
|
|
value: formatWithCurrency(item.payload.wages),
|
2026-06-11 16:13:48 +03:30
|
|
|
show:
|
|
|
|
|
(mustPrintConfig.item_wage ?? true) &&
|
|
|
|
|
item.good_snapshot.pricing_model === 'GOLD',
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'سود',
|
2026-06-11 16:13:48 +03:30
|
|
|
value: formatWithCurrency(item.payload.profit),
|
|
|
|
|
show:
|
|
|
|
|
(mustPrintConfig.item_profit ?? true) &&
|
|
|
|
|
item.good_snapshot.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:
|
2026-06-11 16:13:48 +03:30
|
|
|
(mustPrintConfig.item_commission ?? true) &&
|
|
|
|
|
item.good_snapshot.pricing_model === 'GOLD',
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'مالیات بر ارزش افزوده',
|
2026-06-11 16:13:48 +03:30
|
|
|
value: formatWithCurrency(item.tax_amount),
|
|
|
|
|
show: mustPrintConfig.item_tax ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'تخفیف',
|
2026-06-11 16:13:48 +03:30
|
|
|
value: formatWithCurrency(item.discount_amount),
|
|
|
|
|
show: mustPrintConfig.item_discount ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
{
|
2026-05-17 10:59:15 +03:30
|
|
|
label: 'مبلغ کل',
|
|
|
|
|
value: formatWithCurrency(item.total_amount),
|
2026-06-11 16:13:48 +03:30
|
|
|
show: mustPrintConfig.item_total_amount ?? true,
|
2026-05-12 20:35:04 +03:30
|
|
|
},
|
|
|
|
|
],
|
2026-05-17 10:59:15 +03:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-11 16:13:48 +03:30
|
|
|
|
|
|
|
|
console.log(defaultPrintItems);
|
|
|
|
|
|
2026-05-17 10:59:15 +03:30
|
|
|
return defaultPrintItems;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
printInvoice = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const printItems = await this.preparePrint();
|
2026-06-11 16:13:48 +03:30
|
|
|
|
2026-05-17 10:59:15 +03:30
|
|
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
|
this.onRefresh.emit();
|
|
|
|
|
}
|
2026-06-06 19:52:58 +03:30
|
|
|
|
|
|
|
|
private mapCorrectionRequest(event: CorrectionInvoiceFormValue): ICorrectionRequest {
|
|
|
|
|
const items = (event.items || []).map(({ id, pricing_model, ...item }) => item);
|
|
|
|
|
|
|
|
|
|
const total_amount = items.reduce((sum, item) => sum + Number(item.total_amount || 0), 0);
|
|
|
|
|
const discount_amount = items.reduce((sum, item) => sum + Number(item.discount_amount || 0), 0);
|
|
|
|
|
const tax_amount = items.reduce((sum, item) => sum + Number(item.tax_amount || 0), 0);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
invoice_date: event.invoice_date,
|
|
|
|
|
items,
|
|
|
|
|
total_amount,
|
|
|
|
|
discount_amount,
|
|
|
|
|
tax_amount,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
correctionSubmit(event: CorrectionInvoiceFormValue) {
|
|
|
|
|
this.sendCorrection(this.mapCorrectionRequest(event));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private mapReturnFromSaleRequest(event: ReturnFromSaleFormValue): IPosReturnFromSaleRequest {
|
|
|
|
|
const invoiceItems = this.invoice?.items || [];
|
|
|
|
|
const itemMap = new Map(invoiceItems.map((item) => [item.id, item]));
|
|
|
|
|
|
|
|
|
|
const items: IPosOrderItem[] = (event.items || [])
|
|
|
|
|
.map((item) => {
|
|
|
|
|
const source = itemMap.get(item.id);
|
|
|
|
|
if (!source) return null;
|
|
|
|
|
|
|
|
|
|
const quantity = Number(item.quantity || 0);
|
|
|
|
|
const unit_price = Number(source.unit_price || 0);
|
2026-06-11 16:13:48 +03:30
|
|
|
const discount_amount = Number(source.discount_amount || 0);
|
2026-06-06 19:52:58 +03:30
|
|
|
const base_total_amount = unit_price * quantity;
|
|
|
|
|
const total_amount = Number(source.total_amount || 0);
|
2026-06-11 16:13:48 +03:30
|
|
|
const tax_amount = Number(source.tax_amount || 0);
|
2026-06-06 19:52:58 +03:30
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
good_id: source.good_id,
|
|
|
|
|
service_id: source.service_id || undefined,
|
|
|
|
|
quantity,
|
|
|
|
|
unit_price,
|
|
|
|
|
discount_amount,
|
|
|
|
|
base_total_amount,
|
|
|
|
|
total_amount,
|
|
|
|
|
tax_amount,
|
|
|
|
|
measure_unit: source.good_snapshot.measure_unit,
|
|
|
|
|
payload: source.payload as any,
|
|
|
|
|
notes: source.notes,
|
|
|
|
|
image_url: source.good_snapshot.image_url,
|
|
|
|
|
} as IPosOrderItem;
|
|
|
|
|
})
|
|
|
|
|
.filter((item): item is IPosOrderItem => !!item);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
invoice_date: this.invoice?.invoice_date || '',
|
|
|
|
|
items,
|
|
|
|
|
total_amount: items.reduce((sum, item) => sum + Number(item.total_amount || 0), 0),
|
|
|
|
|
discount_amount: items.reduce((sum, item) => sum + Number(item.discount_amount || 0), 0),
|
|
|
|
|
tax_amount: items.reduce((sum, item) => sum + Number(item.tax_amount || 0), 0),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
returnSubmit(event: ReturnFromSaleFormValue) {
|
|
|
|
|
this.sendReturnFromSale(this.mapReturnFromSaleRequest(event));
|
|
|
|
|
}
|
2026-06-11 16:13:48 +03:30
|
|
|
|
|
|
|
|
backToPrevPage() {
|
|
|
|
|
this.navigationService.back(this.backRoute);
|
|
|
|
|
}
|
|
|
|
|
showQrCode() {
|
|
|
|
|
this.showQrCodeDialog.set(true);
|
|
|
|
|
}
|
2026-05-12 19:58:53 +03:30
|
|
|
}
|