feat: update invoice components and add correction payment dialog
Production CI / validate-and-build (push) Failing after 1m1s
Production CI / validate-and-build (push) Failing after 1m1s
- Updated return form instructions for clarity. - Refined labels in sale invoice info card for consistency. - Enhanced sale invoice view with a correction payment dialog for increased user interaction. - Improved invoice print preparation utility for better data handling. - Adjusted paginator component for first and last page navigation. - Modified layout styles for better responsiveness and user experience. - Updated environment configurations for different setups.
This commit is contained in:
@@ -10,8 +10,8 @@ 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 { PriceMaskDirective } from '@/shared/directives';
|
||||
import { UikitEmptyStateComponent } from '@/uikit';
|
||||
import { formatJalali, formatWithCurrency } from '@/utils';
|
||||
import {
|
||||
Component,
|
||||
computed,
|
||||
@@ -28,12 +28,15 @@ import { Router } from '@angular/router';
|
||||
import { QRCodeComponent } from 'angularx-qrcode';
|
||||
import { Button, ButtonDirective } from 'primeng/button';
|
||||
import { Card } from 'primeng/card';
|
||||
import { Menu } from 'primeng/menu';
|
||||
import { TableModule } from 'primeng/table';
|
||||
import { Observable } from 'rxjs';
|
||||
import config from 'src/config';
|
||||
import { AppConfirmationService } from '../confirmationDialog/confirmation-dialog.service';
|
||||
import { InnerPagesHeaderComponent } from '../innerPagesHeader/inner-pages-header.component';
|
||||
import { SharedCorrectionFormComponent } from './correctionForm';
|
||||
import { CorrectionInvoiceFormValue, ICorrectionRequest, ReturnFromSaleFormValue } from './models';
|
||||
import { prepareInvoicePrintPayload } from './prepare-print.util';
|
||||
import { SharedReturnFormComponent } from './returnForm/form.component';
|
||||
import {
|
||||
SaleInvoiceSingleInfoCardComponent,
|
||||
@@ -64,6 +67,8 @@ type TActionMenuItem = {
|
||||
SaleInvoiceSingleInfoCardComponent,
|
||||
QRCodeComponent,
|
||||
Card,
|
||||
PriceMaskDirective,
|
||||
Menu,
|
||||
],
|
||||
})
|
||||
export class SharedSaleInvoiceSingleViewComponent {
|
||||
@@ -83,6 +88,7 @@ export class SharedSaleInvoiceSingleViewComponent {
|
||||
@Input() sendToTspLoading: boolean = false;
|
||||
@Input() resendToTspLoading: boolean = false;
|
||||
@Input() inquiryLoading: boolean = false;
|
||||
@Input() beforeCorrectionSubmit?: (data: ICorrectionRequest) => Promise<boolean> | boolean;
|
||||
|
||||
@Output() onRefresh = new EventEmitter<void>();
|
||||
@Output() onSendToTsp = new EventEmitter<Observable<any>>();
|
||||
@@ -97,6 +103,11 @@ export class SharedSaleInvoiceSingleViewComponent {
|
||||
showCorrectionForm = signal(false);
|
||||
showReturnFromSaleForm = signal(false);
|
||||
showQrCodeDialog = signal(false);
|
||||
showCorrectionPaymentDialog = signal(false);
|
||||
correctionRequiredPayment = signal(0);
|
||||
correctionPaymentAmount = signal(0);
|
||||
readonly isApplication = config.isPosApplication;
|
||||
private pendingCorrectionSubmitResolver: Maybe<(allowed: boolean) => void> = null;
|
||||
|
||||
publicInvoiceRoute = computed(() => {
|
||||
if (this.invoice) {
|
||||
@@ -227,164 +238,7 @@ export class SharedSaleInvoiceSingleViewComponent {
|
||||
preparePrint = async () => {
|
||||
if (this.invoice) {
|
||||
const mustPrintConfig = await this.service.getVisibleItems();
|
||||
|
||||
const defaultPrintItems = [
|
||||
{
|
||||
title: 'اطلاعات صورتحساب',
|
||||
items: [
|
||||
{
|
||||
label: 'شماره',
|
||||
value: this.invoice.invoice_number.toString(),
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
label: 'شماره منحصر به فرد مالیاتی',
|
||||
value: this.invoice.tax_id || '-',
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
label: 'نوع',
|
||||
value: this.invoice.type.translate,
|
||||
show: mustPrintConfig.invoice_template,
|
||||
},
|
||||
{
|
||||
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: 'وضعیت صدور',
|
||||
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: 'جزییات صورتحساب',
|
||||
items: [
|
||||
{
|
||||
label: 'شرح',
|
||||
value: item.good_snapshot.name,
|
||||
show: mustPrintConfig.item_name ?? true,
|
||||
},
|
||||
{
|
||||
label: 'شناسه کالا / خدمت',
|
||||
value: item.sku_code,
|
||||
show: mustPrintConfig.item_sku ?? true,
|
||||
},
|
||||
{
|
||||
label: 'تعداد / مقدار',
|
||||
value: `${item.quantity} ${item.measure_unit_text}`,
|
||||
show: mustPrintConfig.item_quantity ?? true,
|
||||
},
|
||||
{
|
||||
label: 'قیمت واحد',
|
||||
value: formatWithCurrency(item.unit_price),
|
||||
show: mustPrintConfig.item_base_amount ?? true,
|
||||
},
|
||||
{
|
||||
label: 'اجرت',
|
||||
value: formatWithCurrency(item.payload.wages),
|
||||
show:
|
||||
(mustPrintConfig.item_wage ?? true) &&
|
||||
item.good_snapshot.pricing_model === 'GOLD',
|
||||
},
|
||||
{
|
||||
label: 'سود',
|
||||
value: formatWithCurrency(item.payload.profit),
|
||||
show:
|
||||
(mustPrintConfig.item_profit ?? true) &&
|
||||
item.good_snapshot.pricing_model === 'GOLD',
|
||||
},
|
||||
{
|
||||
label: 'حقالعمل',
|
||||
value: formatWithCurrency(item.payload.commission),
|
||||
show:
|
||||
(mustPrintConfig.item_commission ?? true) &&
|
||||
item.good_snapshot.pricing_model === 'GOLD',
|
||||
},
|
||||
{
|
||||
label: 'مالیات بر ارزش افزوده',
|
||||
value: formatWithCurrency(item.tax_amount),
|
||||
show: mustPrintConfig.item_tax ?? true,
|
||||
},
|
||||
{
|
||||
label: 'تخفیف',
|
||||
value: formatWithCurrency(item.discount_amount),
|
||||
show: mustPrintConfig.item_discount ?? true,
|
||||
},
|
||||
{
|
||||
label: 'مبلغ کل',
|
||||
value: formatWithCurrency(item.total_amount),
|
||||
show: mustPrintConfig.item_total_amount ?? true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log(defaultPrintItems);
|
||||
|
||||
return defaultPrintItems;
|
||||
return prepareInvoicePrintPayload(this.invoice, mustPrintConfig, this.posName());
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -427,6 +281,53 @@ export class SharedSaleInvoiceSingleViewComponent {
|
||||
this.sendCorrection(this.mapCorrectionRequest(event));
|
||||
}
|
||||
|
||||
async beforeCorrectionSubmitHandler(event: CorrectionInvoiceFormValue): Promise<boolean> {
|
||||
const mapped = this.mapCorrectionRequest(event);
|
||||
const oldTotalAmount = Number(this.invoice?.total_amount || 0);
|
||||
const newTotalAmount = Number(mapped.total_amount || 0);
|
||||
|
||||
if (newTotalAmount <= oldTotalAmount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const requiredAmount = newTotalAmount - oldTotalAmount;
|
||||
this.correctionRequiredPayment.set(requiredAmount);
|
||||
this.correctionPaymentAmount.set(requiredAmount);
|
||||
this.showCorrectionPaymentDialog.set(true);
|
||||
|
||||
const allowByDialog = await new Promise<boolean>((resolve) => {
|
||||
this.pendingCorrectionSubmitResolver = resolve;
|
||||
});
|
||||
|
||||
if (!allowByDialog) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (await this.beforeCorrectionSubmit?.(mapped)) ?? true;
|
||||
}
|
||||
|
||||
onCorrectionPaymentAmountChange(event: Event) {
|
||||
const value = Number((event.target as HTMLInputElement)?.value || 0);
|
||||
this.correctionPaymentAmount.set(Number.isFinite(value) ? value : 0);
|
||||
}
|
||||
|
||||
confirmCorrectionPayment() {
|
||||
if (this.correctionPaymentAmount() < this.correctionRequiredPayment()) {
|
||||
this.toastService.warn({ text: 'مبلغ پرداختی باید حداقل برابر با افزایش مبلغ باشد.' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.showCorrectionPaymentDialog.set(false);
|
||||
this.pendingCorrectionSubmitResolver?.(true);
|
||||
this.pendingCorrectionSubmitResolver = null;
|
||||
}
|
||||
|
||||
cancelCorrectionPayment() {
|
||||
this.showCorrectionPaymentDialog.set(false);
|
||||
this.pendingCorrectionSubmitResolver?.(false);
|
||||
this.pendingCorrectionSubmitResolver = null;
|
||||
}
|
||||
|
||||
private mapReturnFromSaleRequest(event: ReturnFromSaleFormValue): IPosReturnFromSaleRequest {
|
||||
const invoiceItems = this.invoice?.items || [];
|
||||
const itemMap = new Map(invoiceItems.map((item) => [item.id, item]));
|
||||
|
||||
Reference in New Issue
Block a user