@if (contentRendered) {
}
diff --git a/src/app/shared/components/index.ts b/src/app/shared/components/index.ts
index 7d49b9d..aef9f0e 100644
--- a/src/app/shared/components/index.ts
+++ b/src/app/shared/components/index.ts
@@ -9,6 +9,7 @@ export * from './fields';
export * from './inlineConfirmation/inline-confirmation.component';
export * from './inlineEdit/inline-edit.component';
export * from './input/input.component';
+export * from './invoices/payment';
export * from './key-value.component/key-value.component';
export * from './passwordInput/password-input.component';
export * from './posPayment';
diff --git a/src/app/domains/pos/modules/shop/components/payment/form-dialog.component.html b/src/app/shared/components/invoices/payment/form-dialog.component.html
similarity index 90%
rename from src/app/domains/pos/modules/shop/components/payment/form-dialog.component.html
rename to src/app/shared/components/invoices/payment/form-dialog.component.html
index 50f7312..5126282 100644
--- a/src/app/domains/pos/modules/shop/components/payment/form-dialog.component.html
+++ b/src/app/shared/components/invoices/payment/form-dialog.component.html
@@ -7,13 +7,13 @@
(onHide)="close()">
}
+
+
diff --git a/src/app/shared/components/invoices/returnForm/form.component.ts b/src/app/shared/components/invoices/returnForm/form.component.ts
index 810ea4c..bb83181 100644
--- a/src/app/shared/components/invoices/returnForm/form.component.ts
+++ b/src/app/shared/components/invoices/returnForm/form.component.ts
@@ -1,4 +1,5 @@
import { Maybe } from '@/core';
+import { POSOrderPriceInfoCardComponent } from '@/domains/pos/modules/shop/components/order/price-info-card.component';
import { AbstractForm } from '@/shared/abstractClasses';
import { formatDate, GREGORIAN_DATE_FORMATS } from '@/utils';
import { Component, computed, Input, signal, SimpleChanges } from '@angular/core';
@@ -32,6 +33,7 @@ type BackFromSaleFormValue = {
ReactiveFormsModule,
FieldInvoiceDateComponent,
SharedReturnFormItemComponent,
+ POSOrderPriceInfoCardComponent,
],
})
export class SharedReturnFormComponent extends AbstractForm<
@@ -54,11 +56,33 @@ export class SharedReturnFormComponent extends AbstractForm<
return this.form.controls.items;
}
+ canRemoveItem() {
+ return this.items.length > 1;
+ }
+
+ removeItem(index: number) {
+ if (!this.canRemoveItem()) {
+ this.toastService.warn({ text: 'حداقل یک آیتم باید باقی بماند.' });
+ return;
+ }
+
+ this.items.removeAt(index);
+ this.form.controls.items.updateValueAndValidity();
+ this.recalculateTotalPriceInfo();
+ }
+
preparedCalculation = signal
>(null);
+ totalPriceInfo = {
+ totalBaseAmount: 0,
+ discountAmount: 0,
+ taxAmount: 0,
+ totalAmount: 0,
+ };
init() {
this.initForm();
this.prepareCalculation();
+ this.recalculateTotalPriceInfo();
}
prepareCalculation() {
@@ -85,6 +109,38 @@ export class SharedReturnFormComponent extends AbstractForm<
})
);
});
+
+ this.items.valueChanges.subscribe(() => {
+ this.recalculateTotalPriceInfo();
+ });
+ }
+
+ private recalculateTotalPriceInfo() {
+ const initialMap = new Map((this.initialValues || []).map((item) => [String(item.id), item]));
+ const currentItems = this.items.getRawValue();
+
+ this.totalPriceInfo = currentItems.reduce(
+ (acc, current) => {
+ const source = initialMap.get(String(current.id || ''));
+ if (!source) return acc;
+
+ const maxQuantity = Number(current.maxQuantity || 0);
+ const quantity = Number(current.quantity || 0);
+ const ratio = maxQuantity > 0 ? quantity / maxQuantity : 0;
+
+ acc.totalBaseAmount += Number(source.unit_price || 0) * quantity;
+ acc.discountAmount += Number(source.discount_amount || 0) * ratio;
+ acc.taxAmount += Number(source.tax_amount || 0) * ratio;
+ acc.totalAmount += Number(source.total_amount || 0) * ratio;
+ return acc;
+ },
+ {
+ totalBaseAmount: 0,
+ discountAmount: 0,
+ taxAmount: 0,
+ totalAmount: 0,
+ }
+ );
}
override ngOnInit(): void {
@@ -98,15 +154,17 @@ export class SharedReturnFormComponent extends AbstractForm<
}
override submitForm() {
- const payload = this.items.getRawValue().map((item) => ({
+ const rawItems = this.items.getRawValue();
+ const payload = rawItems.map((item) => ({
id: item.id || '',
quantity: Number(item.quantity || 0),
maxQuantity: Number(item.maxQuantity || 0),
}));
- const hasChanges = payload.some(
- (item, index) => item.quantity !== Number(this.initialValues?.[index]?.quantity || 0)
+ const initialMap = new Map(
+ (this.initialValues || []).map((item) => [String(item.id), Number(item.quantity || 0)])
);
+ const hasChanges = payload.some((item) => item.quantity !== Number(initialMap.get(item.id) || 0));
if (!hasChanges) {
this.toastService.warn({
diff --git a/src/app/shared/components/invoices/returnForm/item-form.component.html b/src/app/shared/components/invoices/returnForm/item-form.component.html
index add84dd..4f4de26 100644
--- a/src/app/shared/components/invoices/returnForm/item-form.component.html
+++ b/src/app/shared/components/invoices/returnForm/item-form.component.html
@@ -1,13 +1,34 @@
-
-
- {{ index + 1 }}- {{ good.name }}
-
-
+
+
+
![]()
+
+
+
+ {{ good.name }}
+
+
+
+
مقدار: {{ maxQuantity || 0 }} {{ good.measure_unit.name }}
+
+
+
diff --git a/src/app/shared/components/invoices/returnForm/item-form.component.ts b/src/app/shared/components/invoices/returnForm/item-form.component.ts
index d834079..47607a4 100644
--- a/src/app/shared/components/invoices/returnForm/item-form.component.ts
+++ b/src/app/shared/components/invoices/returnForm/item-form.component.ts
@@ -1,7 +1,7 @@
import { Maybe } from '@/core';
-import { Component, Input, signal, SimpleChanges } from '@angular/core';
+import { Component, EventEmitter, Input, Output, signal, SimpleChanges } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
-import { Divider } from 'primeng/divider';
+import { ButtonDirective } from 'primeng/button';
import { InputComponent } from '../../input/input.component';
import { Goodsnapshot } from '../sale-invoice-full-response.model';
@@ -20,12 +20,15 @@ type BackFromSaleFormValue = {
@Component({
selector: 'shared-return-form-item',
templateUrl: './item-form.component.html',
- imports: [InputComponent, ReactiveFormsModule, Divider],
+ imports: [InputComponent, ReactiveFormsModule, ButtonDirective],
})
export class SharedReturnFormItemComponent {
@Input({ required: true }) control!: FormControl
;
@Input({ required: true }) good!: Goodsnapshot;
@Input({ required: true }) index!: number;
+ @Input() canRemove = true;
+ @Input() maxQuantity: number | null = null;
+ @Output() onRemove = new EventEmitter();
preparedCalculation = signal>(null);
@@ -42,4 +45,8 @@ export class SharedReturnFormItemComponent {
this.prepareCalculation();
}
}
+
+ remove() {
+ this.onRemove.emit();
+ }
}
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 5268448..b9d68b2 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
@@ -60,26 +60,12 @@
-
-
-
مبلغ اصلاحی افزایش یافته است. لطفاً مبلغ پرداختی را ثبت کنید.
-
-
حداقل مبلغ موردنیاز
-
-
-
-
-
-
-
-
-
-
-
-
+
}
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 b376181..6ceec44 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
@@ -4,13 +4,13 @@ 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 { IPayment, IPosOrderItem } from '@/domains/pos/modules/shop/models';
import { PosInfoStore } from '@/domains/pos/store';
import { TspProviderResponseStatus } from '@/shared/catalog';
import { SharedLightBottomsheetComponent } from '@/shared/components';
+import { PosPaymentFormDialogComponent } from '@/shared/components/invoices/payment';
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 {
Component,
@@ -67,8 +67,8 @@ type TActionMenuItem = {
SaleInvoiceSingleInfoCardComponent,
QRCodeComponent,
Card,
- PriceMaskDirective,
Menu,
+ PosPaymentFormDialogComponent,
],
})
export class SharedSaleInvoiceSingleViewComponent {
@@ -105,7 +105,6 @@ export class SharedSaleInvoiceSingleViewComponent {
showQrCodeDialog = signal(false);
showCorrectionPaymentDialog = signal(false);
correctionRequiredPayment = signal(0);
- correctionPaymentAmount = signal(0);
readonly isApplication = config.isPosApplication;
private pendingCorrectionSubmitResolver: Maybe<(allowed: boolean) => void> = null;
@@ -292,7 +291,6 @@ export class SharedSaleInvoiceSingleViewComponent {
const requiredAmount = newTotalAmount - oldTotalAmount;
this.correctionRequiredPayment.set(requiredAmount);
- this.correctionPaymentAmount.set(requiredAmount);
this.showCorrectionPaymentDialog.set(true);
const allowByDialog = await new Promise((resolve) => {
@@ -306,17 +304,10 @@ export class SharedSaleInvoiceSingleViewComponent {
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;
- }
-
+ confirmCorrectionPayment(_event: {
+ payment: IPayment;
+ settlementType: 'CASH' | 'CREDIT' | 'MIXED';
+ }) {
this.showCorrectionPaymentDialog.set(false);
this.pendingCorrectionSubmitResolver?.(true);
this.pendingCorrectionSubmitResolver = null;