feat: implement stock keeping unit management form and list components

- Added StockKeepingUnitFormComponent for creating and editing stock keeping units.
- Introduced StockKeepingUnitsComponent for listing stock keeping units with pagination.
- Integrated form fields for code, name, VAT, and SKU type in the stock keeping unit form.
- Created API routes for stock keeping units with CRUD operations.
- Updated input components to handle numeric and price types with Persian/Arabic digit normalization.
- Enhanced key-value component to support tag display instead of badge.
- Adjusted layout styles for sidebar menu.
- Added AGENT.md for repository-specific coding guidelines and practices.
- Implemented good management form with file upload and category selection.
This commit is contained in:
2026-05-06 22:01:20 +03:30
parent 54d00e19ae
commit b2a1eb8e5b
87 changed files with 882 additions and 434 deletions
@@ -1,5 +1,7 @@
<ng-template #topbarStart>
<p-button (click)="toggleMenu()" icon="pi pi-bars" outlined size="large" />
<p-button (click)="refresh()" icon="pi pi-bars" outlined size="large" />
<p-button (click)="doPay()" icon="pi pi-bars" outlined size="large" />
</ng-template>
<ng-template #topbarCenter>
@@ -20,7 +22,7 @@
<ng-template #topbarEnd>
<div class="">
<p-menu #menu [model]="profileMenuItems" [popup]="true" />
<p-button (click)="menu.toggle($event)" icon="pi pi-user" text severity="contrast" size="large" />
<p-button (click)="menu.toggle($event)" icon="pi pi-user" text outlined size="large" />
</div>
</ng-template>
@@ -1,4 +1,6 @@
import { AuthService } from '@/core';
import { NativeBridgeService } from '@/core/services';
import { ToastService } from '@/core/services/toast.service';
import { LayoutService } from '@/layout/service/layout.service';
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import {
@@ -36,6 +38,10 @@ import { PosMainMenuSidebarComponent } from './mainMenuSidebar/main-menu-sidebar
})
export class PosLayoutComponent implements AfterViewInit {
constructor() {}
private readonly nativeBridgeService = inject(NativeBridgeService);
private readonly toastService = inject(ToastService);
@ViewChild('topbarStart', { static: true }) topbarStart!: TemplateRef<any>;
@ViewChild('topbarCenter', { static: true }) topbarCenter!: TemplateRef<any>;
@ViewChild('topbarEnd', { static: true }) topbarEnd!: TemplateRef<any>;
@@ -95,6 +101,13 @@ export class PosLayoutComponent implements AfterViewInit {
this.getData();
}
doPay() {
this.nativeBridgeService.pay({
amount: 1000,
id: '1',
});
}
ngOnInit() {
this.layoutService.changeIsFullPage(true);
this.getData();
@@ -107,8 +120,13 @@ export class PosLayoutComponent implements AfterViewInit {
}
ngOnDestroy() {
this.layoutService.changeIsFullPage(false);
this.layoutService.setTopbarStartSlot(null);
this.layoutService.setTopbarCenterSlot(null);
this.layoutService.setTopbarEndSlot(null);
}
refresh() {
window.location.reload();
}
}
@@ -1,4 +1,5 @@
import { Maybe } from '@/core';
import { NativeBridgeService } from '@/core/services';
import { ToastService } from '@/core/services/toast.service';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent, KeyValueComponent } from '@/shared/components';
@@ -37,6 +38,7 @@ export class PosPaymentFormDialogComponent
{
private readonly store = inject(PosLandingStore);
private readonly paymentBridge = inject(PosPaymentBridgeAbstract);
private readonly nativeBridgeService = inject(NativeBridgeService);
private readonly toastServices = inject(ToastService);
readonly totalAmount = computed(() => this.store.orderPricingInfo().totalAmount);
@@ -203,15 +205,6 @@ export class PosPaymentFormDialogComponent
override showSuccessMessage = false;
override ngOnInit() {
this.restorePaymentCallback = this.paymentBridge.registerPaymentResultListener((payload) => {
const parsedAmount = this.extractAmountFromPaymentResult(payload);
if (parsedAmount !== null) {
this.payedInTerminal.update((items) => [...items, parsedAmount]);
}
});
}
ngOnDestroy() {
this.restorePaymentCallback?.();
}
@@ -230,48 +223,70 @@ export class PosPaymentFormDialogComponent
terminals: (rawPayment.terminals || []).map((value) => Number(value || 0)),
};
if (payment.terminals.some((terminal) => terminal > 0) && this.paymentBridge.isEnabled()) {
for (let terminal of payment.terminals) {
this.toastServices.info({ text: 'در حال پردازش پرداخت با دستگاه...', life: 3000 });
if (terminal <= 0) continue;
this.toastServices.info({ text: ' دستگاه...', life: 3000 });
// @ts-ignore
window.AndroidBridge?.pay(terminal, '0');
const payResult = this.paymentBridge.pay({
amount: terminal,
id: '0',
});
if (!payResult.success) {
return this.toastServices.warn({
text: payResult.error || 'پرداخت با دستگاه انجام نشد. لطفا دوباره تلاش کنید.',
});
}
}
}
this.store.setPayment(payment);
this.store
.submitOrder()
.pipe(
catchError((err) => {
return throwError(() => err);
}),
)
.subscribe((res) => {
if (this.paymentBridge.isEnabled()) {
this.paymentBridge.print({
invoiceId: res?.id,
code: res?.code,
const terminalPaymentIsDone = this.checkTerminalPayments();
if (terminalPaymentIsDone) {
this.store
.submitOrder()
.pipe(
catchError((err) => {
return throwError(() => err);
}),
)
.subscribe((res) => {
this.close();
this.onSubmit.emit();
this.toastServices.success({
text: 'فاکتور شما با موفقیت ایجاد شد',
});
}
this.close();
this.onSubmit.emit();
this.toastServices.success({
text: 'فاکتور شما با موفقیت ایجاد شد',
});
});
}
}
private checkTerminalPayments(): boolean {
this.form.controls.terminals.controls = this.form.controls.terminals.controls.filter(
(control) => control.value,
);
const terminalPayments = this.form.controls.terminals.controls.map(
(terminal) => terminal.value!,
);
this.selectedPayByTerminalStep.set(terminalPayments.length);
if (terminalPayments.length) {
if (this.nativeBridgeService.isEnabled()) {
for (let i in terminalPayments) {
const terminal = terminalPayments[i];
this.toastServices.info({ text: 'در حال پردازش پرداخت با دستگاه...', life: 3000 });
this.payByTerminal(parseInt(i), terminal);
break;
}
} else {
this.toastServices.error({
text: 'امکان ارتباط با دستگاه پرداخت میسر نیست.',
});
return false;
}
return false;
}
return true;
}
private payByTerminal(id: number, amount: number) {
const payResult = this.nativeBridgeService.pay({
amount,
id: id.toString(),
});
// if (!payResult.success) {
// return this.toastServices.warn({
// text: payResult.error || 'پرداخت با دستگاه انجام نشد. لطفا دوباره تلاش کنید.',
// });
// }
}
override onSuccess(response: IPayment): void {}
@@ -1,11 +1,4 @@
import { INativeBridgeResult, INativePayRequest, INativePrintRequest } from '@/core/services/native-bridge.service';
export abstract class PosPaymentBridgeAbstract {
abstract isEnabled(): boolean;
abstract canPay(): boolean;
abstract canPrint(): boolean;
abstract pay(request: INativePayRequest): INativeBridgeResult;
abstract print(request: INativePrintRequest): INativeBridgeResult;
abstract registerPaymentResultListener(handler: (payload: unknown) => void): () => void;
abstract emitPaymentResultForTest(payload: unknown): void;
}
@@ -1,62 +1,36 @@
import { NativeBridgeService } from '@/core/services';
import {
INativeBridgeResult,
INativePayRequest,
INativePrintRequest,
} from '@/core/services/native-bridge.service';
import { Injectable, inject } from '@angular/core';
import { Injectable } from '@angular/core';
import { PosPaymentBridgeAbstract } from './payment-bridge.abstract';
@Injectable({ providedIn: 'root' })
export class PosPaymentBridgeService extends PosPaymentBridgeAbstract {
private readonly nativeBridge = inject(NativeBridgeService);
isEnabled(): boolean {
return this.nativeBridge.isEnabled();
}
canPay(): boolean {
return this.nativeBridge.canPay();
}
canPrint(): boolean {
return this.nativeBridge.canPrint();
}
pay(request: INativePayRequest): INativeBridgeResult {
return this.nativeBridge.pay(request);
}
print(request: INativePrintRequest): INativeBridgeResult {
return this.nativeBridge.print(request);
}
registerPaymentResultListener(handler: (payload: unknown) => void): () => void {
const w = window as unknown as {
onPaymentResult?: (payload: unknown) => void;
AndroidBridge?: {
WebV: {
onPaymentResult?: (payload: unknown) => void;
AndroidBridge?: {
onPaymentResult?: (payload: unknown) => void;
};
};
};
const previousGlobal = w.onPaymentResult;
const previousBridge = w.AndroidBridge?.onPaymentResult;
const previousGlobal = w.WebV.onPaymentResult;
const previousBridge = w.WebV.AndroidBridge?.onPaymentResult;
w.onPaymentResult = handler;
if (w.AndroidBridge) {
w.AndroidBridge.onPaymentResult = handler;
w.WebV.onPaymentResult = handler;
if (w.WebV.AndroidBridge) {
w.WebV.AndroidBridge.onPaymentResult = handler;
}
return () => {
w.onPaymentResult = previousGlobal;
if (w.AndroidBridge) {
w.AndroidBridge.onPaymentResult = previousBridge;
w.WebV.onPaymentResult = previousGlobal;
if (w.WebV.AndroidBridge) {
w.WebV.AndroidBridge.onPaymentResult = previousBridge;
}
};
}
emitPaymentResultForTest(payload: unknown): void {
const w = window as unknown as { onPaymentResult?: (payload: unknown) => void };
w.onPaymentResult?.(payload);
const w = window as unknown as { WebV: { onPaymentResult?: (payload: unknown) => void } };
w.WebV.onPaymentResult?.(payload);
}
}