feat: Enhance customer and inventory components with new features and improvements

This commit is contained in:
2025-12-15 18:00:45 +03:30
parent 17fa65407c
commit 108d192f88
24 changed files with 207 additions and 78 deletions
+30 -8
View File
@@ -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<IPosProductCategoriesResponse[]>;
activeProductCategory: Maybe<number>;
inOrderProducts: IPosInOrderProduct[];
selectedCustomer: Maybe<ICustomerResponse>;
}
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<ICustomerResponse>) {
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();
}
}