From 108d192f88bee7dec3fd64a85178f410e7b21ddf Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Mon, 15 Dec 2025 18:00:45 +0330 Subject: [PATCH] feat: Enhance customer and inventory components with new features and improvements --- .../customers/components/form.component.html | 9 ++++- .../components/select/select.component.html | 19 +++++++++- .../components/select/select.component.ts | 4 +- .../customers/services/main.service.ts | 18 +++++++-- .../movementList/movement-list.component.html | 4 +- .../transfer/transfer-form.component.html | 9 +---- .../transfer/transfer-form.component.ts | 3 +- .../inventories/views/single.component.ts | 3 +- .../order/order-card.component.html | 19 ++++++++-- .../components/order/order-card.component.ts | 22 +++++++++-- .../order/price-info-card.component.html | 15 ++++++-- .../modules/pos/constants/apiRoutes/index.ts | 1 + src/app/modules/pos/models/types.ts | 4 +- src/app/modules/pos/services/main.service.ts | 5 +++ src/app/modules/pos/store/index.ts | 38 +++++++++++++++---- .../components/form.component.html | 2 +- .../purchase-receipt-product-row.component.ts | 7 ++-- .../purchase-receipt-template.component.html | 24 ++++++------ .../purchase-receipt-template.component.ts | 38 +++++++++++-------- .../movementReferenceTypes/tag.component.ts | 4 +- .../catalog/movementReferenceTypes/utils.ts | 12 +++++- .../components/abstract-select.component.ts | 19 +++++++--- .../components/cardex/cardex.component.html | 4 +- .../uikit/datepicker/datepicker.component.ts | 2 + 24 files changed, 207 insertions(+), 78 deletions(-) diff --git a/src/app/modules/customers/components/form.component.html b/src/app/modules/customers/components/form.component.html index 4375497..d1a237c 100644 --- a/src/app/modules/customers/components/form.component.html +++ b/src/app/modules/customers/components/form.component.html @@ -1,4 +1,11 @@ - +
diff --git a/src/app/modules/customers/components/select/select.component.html b/src/app/modules/customers/components/select/select.component.html index cbff2b9..f5aa411 100644 --- a/src/app/modules/customers/components/select/select.component.html +++ b/src/app/modules/customers/components/select/select.component.html @@ -1,7 +1,8 @@ + @if (canInsert) { + +
+ +
+
+ }
+
diff --git a/src/app/modules/customers/components/select/select.component.ts b/src/app/modules/customers/components/select/select.component.ts index 707025e..be4a5eb 100644 --- a/src/app/modules/customers/components/select/select.component.ts +++ b/src/app/modules/customers/components/select/select.component.ts @@ -2,14 +2,16 @@ import { AbstractSelectComponent } from '@/shared/components'; import { UikitFieldComponent } from '@/uikit'; import { Component } from '@angular/core'; import { ReactiveFormsModule } from '@angular/forms'; +import { Button } from 'primeng/button'; import { Select } from 'primeng/select'; import { ICustomerResponse } from '../../models'; import { CustomersService } from '../../services/main.service'; +import { CustomerFormComponent } from '../form.component'; @Component({ selector: 'customers-select-field', templateUrl: './select.component.html', - imports: [ReactiveFormsModule, Select, UikitFieldComponent], + imports: [ReactiveFormsModule, Select, UikitFieldComponent, Button, CustomerFormComponent], }) export class CustomersSelectComponent extends AbstractSelectComponent { constructor(private service: CustomersService) { diff --git a/src/app/modules/customers/services/main.service.ts b/src/app/modules/customers/services/main.service.ts index 64bdc77..4313768 100644 --- a/src/app/modules/customers/services/main.service.ts +++ b/src/app/modules/customers/services/main.service.ts @@ -1,7 +1,8 @@ import { IPaginatedResponse } from '@/core/models/service.model'; +import { getFullName } from '@/utils'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { map, Observable } from 'rxjs'; import { CUSTOMERS_API_ROUTES } from '../constants'; import { ICustomerRawResponse, ICustomerRequest, ICustomerResponse } from '../models'; @@ -12,11 +13,22 @@ export class CustomersService { private apiRoutes = CUSTOMERS_API_ROUTES; getAll(): Observable> { - return this.http.get>(this.apiRoutes.list()); + return this.http.get>(this.apiRoutes.list()).pipe( + map((res) => { + return { + meta: res.meta, + data: res.data.map((item) => ({ ...item, fullName: getFullName(item) })), + }; + }), + ); } getSingle(customerId: string): Observable { - return this.http.get(this.apiRoutes.single(customerId)); + return this.http.get(this.apiRoutes.single(customerId)).pipe( + map((res) => { + return { ...res, fullName: getFullName(res) }; + }), + ); } create(data: ICustomerRequest): Observable { diff --git a/src/app/modules/inventories/components/movementList/movement-list.component.html b/src/app/modules/inventories/components/movementList/movement-list.component.html index 5e708a5..c2d2f63 100644 --- a/src/app/modules/inventories/components/movementList/movement-list.component.html +++ b/src/app/modules/inventories/components/movementList/movement-list.component.html @@ -32,7 +32,9 @@ /> {{ movement.receiptId }} - + + + {{ movement.count }} {{ movement.info.quantity }} diff --git a/src/app/modules/inventories/components/transfer/transfer-form.component.html b/src/app/modules/inventories/components/transfer/transfer-form.component.html index e441942..1b8b46d 100644 --- a/src/app/modules/inventories/components/transfer/transfer-form.component.html +++ b/src/app/modules/inventories/components/transfer/transfer-form.component.html @@ -95,7 +95,6 @@ @if (!form.controls.fromInventory.value) {
لطفا انبار مبدا را انتخاب کنید
} @else { - {{ form.controls.items.value.length }} @@ -107,13 +106,7 @@ {{ item.controls.product.value?.name }} - + diff --git a/src/app/modules/inventories/components/transfer/transfer-form.component.ts b/src/app/modules/inventories/components/transfer/transfer-form.component.ts index bfaa1d7..4a89393 100644 --- a/src/app/modules/inventories/components/transfer/transfer-form.component.ts +++ b/src/app/modules/inventories/components/transfer/transfer-form.component.ts @@ -1,6 +1,6 @@ import { Maybe } from '@/core'; import { InputComponent } from '@/shared/components'; -import { UikitFieldComponent } from '@/uikit'; +import { UikitCounterComponent, UikitFieldComponent } from '@/uikit'; import { Component, inject, signal } from '@angular/core'; import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; import { ButtonDirective } from 'primeng/button'; @@ -32,6 +32,7 @@ import { InventoriesSelectComponent } from '../select/select.component'; TableModule, InputText, ButtonDirective, + UikitCounterComponent, ], }) export class InventoriesTransferFormComponent { diff --git a/src/app/modules/inventories/views/single.component.ts b/src/app/modules/inventories/views/single.component.ts index 5921fbf..036f543 100644 --- a/src/app/modules/inventories/views/single.component.ts +++ b/src/app/modules/inventories/views/single.component.ts @@ -2,6 +2,7 @@ import { Maybe } from '@/core'; import { KeyValueComponent } from '@/shared/components'; import { DetailsInfoCardComponent } from '@/shared/components/detailsInfoCard/details-info-card.component'; import { PriceMaskDirective } from '@/shared/directives'; +import { formatWithCurrency } from '@/utils'; import { Component, inject, signal } from '@angular/core'; import { ActivatedRoute, RouterLink } from '@angular/router'; import { Button, ButtonDirective } from 'primeng/button'; @@ -83,7 +84,7 @@ export class InventoryComponent { { icon: 'pi pi-dollar', label: 'ارزش کلی کالاهای موجود', - value: this.data()?.availableProductsCost, + value: formatWithCurrency(this.data()?.availableProductsCost || 0), }, ]; } diff --git a/src/app/modules/pos/components/order/order-card.component.html b/src/app/modules/pos/components/order/order-card.component.html index d57ccd9..92491cd 100644 --- a/src/app/modules/pos/components/order/order-card.component.html +++ b/src/app/modules/pos/components/order/order-card.component.html @@ -1,6 +1,11 @@
- +

@@ -61,7 +66,7 @@
@@ -76,7 +81,15 @@
- +
diff --git a/src/app/modules/pos/components/order/order-card.component.ts b/src/app/modules/pos/components/order/order-card.component.ts index 80657fc..e7908ad 100644 --- a/src/app/modules/pos/components/order/order-card.component.ts +++ b/src/app/modules/pos/components/order/order-card.component.ts @@ -1,4 +1,6 @@ +import { Maybe } from '@/core'; import { CustomersSelectComponent } from '@/modules/customers/components/select/select.component'; +import { ICustomerResponse } from '@/modules/customers/models'; import { PriceMaskDirective } from '@/shared/directives'; import { UikitCounterComponent } from '@/uikit'; import { Component, computed, signal } from '@angular/core'; @@ -25,13 +27,15 @@ import { POSOrderPriceInfoCardComponent } from './price-info-card.component'; ], }) export class PosOrderCardComponent { - constructor(private store: POSStore) {} + constructor(private store: POSStore) { + this.selectedCustomer.set(this.store.selectedCustomer()); + } placeholderImage = images.placeholders.default; inOrderProducts = computed(() => this.store.inOrderProducts()); - value = signal(0); + selectedCustomer = signal>(null); removeProductFromOrder(productId: number) { this.store.removeFromInOrderProducts(productId); @@ -41,8 +45,10 @@ export class PosOrderCardComponent { this.store.updateInOrderProductQuantity(productId, quantity); } - updateInOrderProductFee(productId: number, $event: Event, prevFee: string) { - const fee = $event.target ? String(($event.target as HTMLInputElement).ariaValueNow) : prevFee; + updateInOrderProductFee(productId: number, $event: Event, prevFee: number) { + const fee = $event.target + ? parseFloat(($event.target as HTMLInputElement).ariaValueNow || prevFee.toString()) + : prevFee; this.store.updateInOrderProductFee(productId, fee); } @@ -50,4 +56,12 @@ export class PosOrderCardComponent { clearOrderList() { this.store.resetInOrderProducts(); } + + updateCustomer(customer: Maybe) { + this.store.setSelectedCustomer(customer); + } + + submit() { + this.store.submitOrder(); + } } diff --git a/src/app/modules/pos/components/order/price-info-card.component.html b/src/app/modules/pos/components/order/price-info-card.component.html index e5533f4..7c60e0a 100644 --- a/src/app/modules/pos/components/order/price-info-card.component.html +++ b/src/app/modules/pos/components/order/price-info-card.component.html @@ -1,15 +1,22 @@
-
+
جمع قیمت - + @if (priceInfo().totalAmount == priceInfo().totalBaseAmount) { + + } @else { +
+ + +
+ }
-
+
مالیات (۱۰٪)

-
+
مجموع کل
diff --git a/src/app/modules/pos/constants/apiRoutes/index.ts b/src/app/modules/pos/constants/apiRoutes/index.ts index 1eb2500..47ea822 100644 --- a/src/app/modules/pos/constants/apiRoutes/index.ts +++ b/src/app/modules/pos/constants/apiRoutes/index.ts @@ -4,4 +4,5 @@ export const POS_API_ROUTES = { info: () => `${baseUrl}`, stock: () => `${baseUrl}/stock`, productCategories: () => `${baseUrl}/product-categories`, + submitOrder: () => `${baseUrl}/orders/create`, }; diff --git a/src/app/modules/pos/models/types.ts b/src/app/modules/pos/models/types.ts index 6c98c71..d177780 100644 --- a/src/app/modules/pos/models/types.ts +++ b/src/app/modules/pos/models/types.ts @@ -13,8 +13,8 @@ interface ICategorySummary { export interface IPosOrderItem { productId: number; - quantity: number; - fee: string; + count: number; + fee: number; } export interface IPosInOrderProduct extends IPosOrderItem { diff --git a/src/app/modules/pos/services/main.service.ts b/src/app/modules/pos/services/main.service.ts index 36587a7..dd824ef 100644 --- a/src/app/modules/pos/services/main.service.ts +++ b/src/app/modules/pos/services/main.service.ts @@ -6,6 +6,7 @@ import { POS_API_ROUTES } from '../constants'; import { IPosInfoRawResponse, IPosInfoResponse, + IPosOrderRequest, IPosProductCategoriesRawResponse, IPosProductCategoriesResponse, IPosStockRawResponse, @@ -31,4 +32,8 @@ export class PosService { this.apiRoutes.productCategories(), ); } + + submitOrder(payload: IPosOrderRequest): Observable { + return this.http.post(this.apiRoutes.submitOrder(), payload); + } } diff --git a/src/app/modules/pos/store/index.ts b/src/app/modules/pos/store/index.ts index fb750a7..87e3f60 100644 --- a/src/app/modules/pos/store/index.ts +++ b/src/app/modules/pos/store/index.ts @@ -1,4 +1,5 @@ import { Maybe } from '@/core'; +import { ICustomerResponse } from '@/modules/customers/models'; import { computed, Injectable, signal } from '@angular/core'; import { map } from 'rxjs'; import { IPosInfoResponse, IPosProductCategoriesResponse, IPosStockResponse } from '../models'; @@ -14,6 +15,7 @@ interface IPosState { productCategories: Maybe; activeProductCategory: Maybe; inOrderProducts: IPosInOrderProduct[]; + selectedCustomer: Maybe; } export const INITIAL_POS_STATE: IPosState = { @@ -25,6 +27,7 @@ export const INITIAL_POS_STATE: IPosState = { productCategories: null, activeProductCategory: null, inOrderProducts: [], + selectedCustomer: null, }; @Injectable({ providedIn: 'any' }) @@ -41,6 +44,7 @@ export class POSStore { readonly productCategories = computed(() => this.state$().productCategories); readonly getProductCategoriesLoading = computed(() => this.state$().getProductCategoriesLoading); readonly activeProductCategory = computed(() => this.state$().activeProductCategory); + readonly selectedCustomer = computed(() => this.state$().selectedCustomer); readonly activatedCategoryProducts = computed(() => { if (this.activeProductCategory() === 0) { return this.state$().stock; @@ -52,14 +56,14 @@ export class POSStore { readonly orderPricingInfo = computed(() => { const totalAmount = this.inOrderProducts().reduce( - (acc, curr) => acc + parseFloat(curr.fee) * curr.quantity, + (acc, curr) => acc + curr.fee * curr.count, 0, ); const taxAmount = totalAmount * 0.1; return { - totalItems: this.inOrderProducts().reduce((acc, curr) => acc + curr.quantity, 0), + totalItems: this.inOrderProducts().reduce((acc, curr) => acc + curr.count, 0), totalBaseAmount: this.inOrderProducts().reduce( - (acc, curr) => acc + parseFloat(curr.product.salePrice) * curr.quantity, + (acc, curr) => acc + parseFloat(curr.product.salePrice) * curr.count, 0, ), totalAmount, @@ -156,7 +160,7 @@ export class POSStore { if (this.state$().inOrderProducts.some((p) => p.productId === productId)) { this.updateInOrderProductQuantity( productId, - this.state$().inOrderProducts.find((p) => p.productId === productId)!.quantity + 1, + this.state$().inOrderProducts.find((p) => p.productId === productId)!.count + 1, ); } else { this.setState({ @@ -165,8 +169,8 @@ export class POSStore { { product, productId: product.id, - quantity: 1, - fee: product.salePrice, + count: 1, + fee: parseFloat(product.salePrice), maxQuantity: productStock.quantity, }, ], @@ -190,7 +194,7 @@ export class POSStore { } else { const updatedProducts = inOrderProducts.map((p) => { if (p.productId === productId) { - return { ...p, quantity: Math.min(quantity, p.maxQuantity) }; + return { ...p, count: Math.min(quantity, p.maxQuantity) }; } return p; }); @@ -198,7 +202,7 @@ export class POSStore { } } - updateInOrderProductFee(productId: number, fee: string) { + updateInOrderProductFee(productId: number, fee: number) { const inOrderProducts = this.state$().inOrderProducts; if (inOrderProducts.some((p) => p.productId === productId)) { @@ -215,4 +219,22 @@ export class POSStore { resetInOrderProducts() { this.setState({ inOrderProducts: [] }); } + + setSelectedCustomer(customer: Maybe) { + console.log(customer); + + this.setState({ selectedCustomer: customer }); + } + + submitOrder() { + const orderPayload = { + customerId: this.selectedCustomer()?.id, + items: this.inOrderProducts()?.map((item) => ({ + productId: item.productId, + count: item.count, + fee: item.fee, + })), + }; + this.service.submitOrder(orderPayload).subscribe(); + } } diff --git a/src/app/modules/productBrands/components/form.component.html b/src/app/modules/productBrands/components/form.component.html index ba05b4a..3b16286 100644 --- a/src/app/modules/productBrands/components/form.component.html +++ b/src/app/modules/productBrands/components/form.component.html @@ -2,7 +2,7 @@ header="فرم برند کالا" [(visible)]="visible" [modal]="true" - [style]="{ width: '500px' }" + [style]="{ width: '500px', zIndex: '10000' }" [closable]="true" appendTo="body" > diff --git a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-product-row.component.ts b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-product-row.component.ts index e8988b5..dc2ec7c 100644 --- a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-product-row.component.ts +++ b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-product-row.component.ts @@ -28,19 +28,20 @@ export class PurchaseReceiptProductRowComponent { @Output() onRemove = new EventEmitter(); - editMode = signal(false); + editMode = signal(true); constructor() {} ngOnInit() { + this.purchaseItemControl?.controls.product.valueChanges.subscribe((res) => { + this.purchaseItemControl?.controls.fee.setValue(Number(res?.salePrice) || 0); + }); this.purchaseItemControl?.controls.count.valueChanges.subscribe(() => { this.updateTotal(); }); this.purchaseItemControl?.controls.fee.valueChanges.subscribe(() => { this.updateTotal(); }); - - console.log('purchase item control', this.purchaseItemControl); } updateTotal() { diff --git a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.html b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.html index ef347a8..4055caa 100644 --- a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.html +++ b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.html @@ -6,9 +6,9 @@
- انبار: + + انبار: + {{ form.controls.inventory.value?.name || "وارد نشده" }} @@ -24,9 +24,9 @@
- تامین کننده: + + تامین کننده: + {{ form.controls.supplier.value?.fullname || "وارد نشده" }} @@ -46,9 +46,9 @@
- شماره رسید: + + شماره رسید: + {{ form.controls.code.value || "وارد نشده" }} @@ -59,9 +59,9 @@
- تاریخ رسید: + + تاریخ رسید: + {{ form.controls.buyAt.value || "وارد نشده" }} diff --git a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.ts b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.ts index 0395fd0..08aafe3 100644 --- a/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.ts +++ b/src/app/modules/purchases/components/receiptTemplate/purchase-receipt-template.component.ts @@ -12,6 +12,7 @@ import { UikitFlatpickrJalaliComponent } from '@/uikit'; import { CommonModule } from '@angular/common'; import { Component, inject, Input, signal } from '@angular/core'; import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; +import dayjs from 'dayjs'; import { ButtonDirective } from 'primeng/button'; import { Card } from 'primeng/card'; import { TableModule } from 'primeng/table'; @@ -91,22 +92,22 @@ export class PurchaseReceiptTemplateComponent { ] as IColumn[]; form = this.fb.group({ - totalAmount: [300000, [Validators.required, Validators.min(0)]], - code: ['122132', [Validators.required]], + totalAmount: [0, [Validators.required, Validators.min(0)]], + code: ['', [Validators.required]], isSettled: [false], - buyAt: ['2025-12-01', Validators.required], + buyAt: [dayjs().calendar('jalali').format('YYYY/MM/DD'), Validators.required], description: [''], products: this.fb.array([ this.fb.group({ - product: [{ id: 1 } as Maybe, [Validators.required]], - count: [2, [Validators.required, Validators.min(1)]], - fee: [150000, [Validators.required, Validators.min(0)]], + product: [null as Maybe, [Validators.required]], + count: [0, [Validators.required, Validators.min(1)]], + fee: [0, [Validators.required, Validators.min(0)]], description: [''], - total: [300000, [Validators.required, Validators.min(0)]], + total: [0, [Validators.required, Validators.min(0)]], }), ]), - inventory: [{ id: 2 } as Maybe, [Validators.required]], - supplier: [{ id: 1 } as Maybe, [Validators.required]], + inventory: [null as Maybe, [Validators.required]], + supplier: [null as Maybe, [Validators.required]], }); constructor( @@ -114,6 +115,8 @@ export class PurchaseReceiptTemplateComponent { private toastService: ToastService, ) { this.form.controls.products.valueChanges.subscribe((products) => { + console.log('first'); + let totalAmount = 0; products.forEach((p: any) => { totalAmount += p.total || 0; @@ -126,14 +129,17 @@ export class PurchaseReceiptTemplateComponent { ngOnInit() { this.formIsSubmitted.set(false); + this.form.controls.products.controls.pop(); if (this.product) { - this.form.controls.products.at(0).setValue({ - product: this.product, - count: 0, - fee: 0, - description: '', - total: 0, - }); + this.form.controls.products.setValue([ + { + product: this.product, + count: 0, + fee: 0, + description: '', + total: 0, + }, + ]); } } diff --git a/src/app/shared/catalog/movementReferenceTypes/tag.component.ts b/src/app/shared/catalog/movementReferenceTypes/tag.component.ts index f5df8d0..c2c4302 100644 --- a/src/app/shared/catalog/movementReferenceTypes/tag.component.ts +++ b/src/app/shared/catalog/movementReferenceTypes/tag.component.ts @@ -1,5 +1,6 @@ import { Component, Input } from '@angular/core'; import { Tag } from 'primeng/tag'; +import { MovementType } from '../movementTypes'; import { MovementReferenceType } from './types'; import { getMovementReferenceTypeColor, getMovementReferenceTypeText } from './utils'; @@ -10,10 +11,11 @@ import { getMovementReferenceTypeColor, getMovementReferenceTypeText } from './u }) export class CatalogMovementReferenceTagComponent { @Input() type!: MovementReferenceType; + @Input() movementType?: MovementType; constructor() {} get text() { - return getMovementReferenceTypeText(this.type); + return getMovementReferenceTypeText(this.type, this.movementType); } get color() { return getMovementReferenceTypeColor(this.type); diff --git a/src/app/shared/catalog/movementReferenceTypes/utils.ts b/src/app/shared/catalog/movementReferenceTypes/utils.ts index a5178b6..efbc0d8 100644 --- a/src/app/shared/catalog/movementReferenceTypes/utils.ts +++ b/src/app/shared/catalog/movementReferenceTypes/utils.ts @@ -1,7 +1,11 @@ import { TagSeverity } from '@/core/models/tag'; +import { MovementType } from '../movementTypes'; import { MovementReferenceType } from './types'; -export const getMovementReferenceTypeText = (movementType: MovementReferenceType): string => { +export const getMovementReferenceTypeText = ( + movementType: MovementReferenceType, + type?: MovementType, +): string => { switch (movementType) { case MovementReferenceType.PURCHASE: return 'خرید'; @@ -10,6 +14,12 @@ export const getMovementReferenceTypeText = (movementType: MovementReferenceType case MovementReferenceType.ADJUSTMENT: return 'تعدیل'; case MovementReferenceType.INVENTORY_TRANSFER: + if (type === MovementType.IN) { + return 'دریافت از انبار دیگر'; + } else { + return 'ارسال به انبار دیگر'; + } + default: return 'انتقال بین انبارها'; } }; diff --git a/src/app/shared/components/abstract-select.component.ts b/src/app/shared/components/abstract-select.component.ts index e1bff96..422a2ec 100644 --- a/src/app/shared/components/abstract-select.component.ts +++ b/src/app/shared/components/abstract-select.component.ts @@ -1,5 +1,5 @@ import { Maybe } from '@/core'; -import { Component, Input, signal } from '@angular/core'; +import { Component, Input, model, signal } from '@angular/core'; import { FormControl } from '@angular/forms'; export interface ISelectItem { @@ -12,7 +12,7 @@ export interface ISelectItem { template: '', }) export abstract class AbstractSelectComponent { - @Input() control!: FormControl>; + @Input() control = new FormControl>(null); @Input() canInsert: boolean = false; @Input() showLabel: boolean = true; @Input() showErrors: boolean = true; @@ -22,20 +22,29 @@ export abstract class AbstractSelectComponent { loading = signal(false); items = signal>(null); isOpenFormDialog = signal(false); + value = model>(null); + + constructor() { + if (this.value()) { + this.control.setValue(this.value()); + } + + this.control.valueChanges.subscribe((val) => { + this.value.set(val as Maybe); + }); + } abstract getData(): void; - // abstract getLabel(): string; refresh() { this.getData(); } onOpenForm() { - // Override in subclass if needed + this.isOpenFormDialog.set(true); } get selectOptionValue() { - if (!this.control) return undefined; if (this.isFullDataOptionValue) { return undefined; } diff --git a/src/app/shared/components/cardex/cardex.component.html b/src/app/shared/components/cardex/cardex.component.html index 851c4d3..9a2c61f 100644 --- a/src/app/shared/components/cardex/cardex.component.html +++ b/src/app/shared/components/cardex/cardex.component.html @@ -33,7 +33,9 @@ {{ i + 1 }} - + + + {{ item.referenceId || "-" }} {{ item.supplier?.name || "-" }} {{ item.inventory.name || "-" }} diff --git a/src/app/uikit/datepicker/datepicker.component.ts b/src/app/uikit/datepicker/datepicker.component.ts index d9433fd..5c63462 100644 --- a/src/app/uikit/datepicker/datepicker.component.ts +++ b/src/app/uikit/datepicker/datepicker.component.ts @@ -10,6 +10,7 @@ import { ViewChild, } from '@angular/core'; import { FormControl, ReactiveFormsModule } from '@angular/forms'; +import dayjs from 'dayjs'; import flatpickr from 'flatpickr-wrap'; import { BaseOptions } from 'flatpickr-wrap/dist/types/options'; import { InputTextModule } from 'primeng/inputtext'; @@ -40,6 +41,7 @@ export class UikitFlatpickrJalaliComponent implements OnInit { ngOnInit(): void { this.fpInstance = flatpickr(this.wrapperRef.nativeElement, { ...this.options, + now: dayjs().calendar('jalali').format('YYYY/MM/DD'), altInputClass: 'p-inputtext w-full', onChange: (selectedDates: Date[], dateStr: string) => { this.valueChange.emit(dateStr);