This commit is contained in:
2026-08-27 06:06:30 +00:00
parent 43204e8441
commit 311464e593
32 changed files with 98 additions and 117 deletions
@@ -68,7 +68,7 @@ export class BundleDetailComponent {
private snackBar = inject(MatSnackBar);
private ser = inject(BundleService);
private productSer = inject(ProductService);
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
menuCategories = computed(() => this.menuCategoriesResource.value() ?? []);
saleCategoriesResource = this.saleCategoryService.list();
saleCategories = computed(() => this.saleCategoriesResource.value() ?? []);
@@ -42,7 +42,7 @@ export class BundleListComponent {
private bundleService = inject(BundleService);
private toCsv = inject(ToCsvService);
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
listResource = this.bundleService.list();
menuCategoryFilter = signal<string>('');
+2 -3
View File
@@ -1,16 +1,15 @@
import { MenuCategory } from '../core/menu-category';
import { ProductQuery } from '../core/product-query';
import { SaleCategory } from '../core/sale-category';
export class BundleItem {
id?: string;
itemId: string;
sku: ProductQuery | undefined;
name: string;
salePrice: number;
quantity: number;
printInBill: boolean;
public constructor(init?: Partial<BundleItem>) {
this.itemId = '';
this.name = '';
this.salePrice = 0;
this.quantity = 0;
+4 -4
View File
@@ -20,9 +20,9 @@ export class CustomerService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Customer | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Customer | undefined> {
return httpResource<Customer>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -86,9 +86,9 @@ export class CustomerService {
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Customer>;
}
autocomplete(query: Signal<string | null> | string | null): HttpResourceRef<Customer[] | undefined> {
autocomplete(query: Signal<string | null>): HttpResourceRef<Customer[] | undefined> {
return httpResource<Customer[]>(() => {
const qVal = typeof query === 'function' ? query() : query;
const qVal = query();
return `${url}/query?q=${qVal ?? ''}`;
});
}
+2 -2
View File
@@ -16,9 +16,9 @@ export class DeviceService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Device | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Device | undefined> {
return httpResource<Device>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -20,21 +20,21 @@ export class GuestBookService {
private log = inject(ErrorLoggerService);
get(
id: Signal<string | null> | string | null,
type: Signal<GuestBookType> | GuestBookType | string = '',
id: Signal<string | null>,
type?: Signal<GuestBookType | string>,
): HttpResourceRef<GuestBook | undefined> {
return httpResource<GuestBook>(() => {
const idVal = typeof id === 'function' ? id() : id;
const typeVal = typeof type === 'function' ? type() : type;
const idVal = id();
const typeVal = type ? type() : '';
const options = { params: new HttpParams().set('t', typeVal) };
const getUrl: string = idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
return { url: getUrl, ...options };
});
}
list(date: Signal<string | null> | string | null): HttpResourceRef<GuestBookList | undefined> {
list(date: Signal<string | null>): HttpResourceRef<GuestBookList | undefined> {
return httpResource<GuestBookList>(() => {
const dateVal = typeof date === 'function' ? date() : date;
const dateVal = date();
const options = { params: new HttpParams().set('q', dateVal === null ? '' : dateVal) };
return { url: `${url}/list`, ...options };
});
@@ -19,20 +19,21 @@ export class MenuCategoryService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<MenuCategory | undefined> {
get(id: Signal<string | null>): HttpResourceRef<MenuCategory | undefined> {
return httpResource<MenuCategory>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
list(shouldHaveActiveProducts: boolean | undefined): HttpResourceRef<MenuCategory[] | undefined> {
list(shouldHaveActiveProducts?: Signal<boolean | undefined>): HttpResourceRef<MenuCategory[] | undefined> {
return httpResource<MenuCategory[]>(() => {
const options = { params: new HttpParams() };
if (shouldHaveActiveProducts) {
options.params = options.params.set('p', 'true');
let params = new HttpParams();
const active = shouldHaveActiveProducts ? shouldHaveActiveProducts() : undefined;
if (active) {
params = params.set('p', 'true');
}
return { url: `${url}/list`, ...options };
return { url: `${url}/list`, params };
});
}
@@ -19,9 +19,9 @@ export class ModifierCategoryService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<ModifierCategory | undefined> {
get(id: Signal<string | null>): HttpResourceRef<ModifierCategory | undefined> {
return httpResource<ModifierCategory>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
+2 -2
View File
@@ -18,9 +18,9 @@ export class ModifierService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Modifier | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Modifier | undefined> {
return httpResource<Modifier>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
+2 -2
View File
@@ -19,9 +19,9 @@ export class PrinterService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Printer | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Printer | undefined> {
return httpResource<Printer>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -69,7 +69,7 @@ export class ProductDetailComponent {
saleCategoriesResource = this.saleCategoryService.list();
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
itemResource = this.ser.get(this.id);
@@ -48,7 +48,7 @@ export class ProductListComponent {
private toCsv = inject(ToCsvService);
private ser = inject(ProductService);
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
listResource = this.ser.list();
+6 -6
View File
@@ -19,9 +19,9 @@ export class ProductService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Product | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Product | undefined> {
return httpResource<Product>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -30,16 +30,16 @@ export class ProductService {
return httpResource<Product[]>(() => `${url}/list`);
}
listOfSaleCategory(id: Signal<string | null> | string): HttpResourceRef<ProductQuery[] | undefined> {
listOfSaleCategory(id: Signal<string | null>): HttpResourceRef<ProductQuery[] | undefined> {
return httpResource<ProductQuery[]>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return `${url}/query?sc=${idVal ?? ''}`;
});
}
listIsActiveOfCategory(id: Signal<string | null> | string): HttpResourceRef<ProductQuery[] | undefined> {
listIsActiveOfCategory(id: Signal<string | null>): HttpResourceRef<ProductQuery[] | undefined> {
return httpResource<ProductQuery[]>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return `${url}/query?mc=${idVal ?? ''}`;
});
}
+2 -2
View File
@@ -19,9 +19,9 @@ export class RegimeService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<number | null> | number | null): HttpResourceRef<Regime | undefined> {
get(id: Signal<number | null>): HttpResourceRef<Regime | undefined> {
return httpResource<Regime>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined || isNaN(idVal) ? url : `${url}/${idVal}`;
});
}
+2 -2
View File
@@ -19,9 +19,9 @@ export class RoleService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Role | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Role | undefined> {
return httpResource<Role>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -19,9 +19,9 @@ export class SaleCategoryService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<SaleCategory | undefined> {
get(id: Signal<string | null>): HttpResourceRef<SaleCategory | undefined> {
return httpResource<SaleCategory>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { Customer } from '../../core/customer';
import { Table } from '../../core/table';
import { User } from '../../core/user';
import { GuestBook } from '../../guest-book/guest-book';
@@ -17,7 +18,7 @@ export class Bill {
kotId: string;
billId: string;
table: Table;
customer: { id: string; name: string } | null;
customer: Customer | null;
guest: GuestBook;
reason: string;
voucherType: VoucherType;
@@ -137,7 +137,7 @@ export class BillsComponent implements OnInit {
const dialogRef = this.dialog.open(ChooseCustomerComponent, {
maxWidth: '100%',
width: '50%',
data: this.bs.bill.customer?.id,
data: this.bs.bill.customer,
});
dialogRef.afterClosed().subscribe((result: boolean | Customer) => {
@@ -1,5 +1,5 @@
import { CdkScrollableModule } from '@angular/cdk/scrolling';
import { Component, inject, signal, computed, effect, debounced } from '@angular/core';
import { Component, inject, computed, debounced, linkedSignal, signal } from '@angular/core';
import { form, FormField } from '@angular/forms/signals';
import { MatAutocompleteSelectedEvent, MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
@@ -14,6 +14,7 @@ import { Customer } from '../../core/customer';
import { CustomerService } from '../../customers/customer.service';
export interface ChooseCustomerFormData {
id: string;
name: string;
phone: string;
address: string;
@@ -40,59 +41,36 @@ export interface ChooseCustomerFormData {
],
})
export class ChooseCustomerComponent {
data = inject(MAT_DIALOG_DATA);
data = inject<Customer | null>(MAT_DIALOG_DATA); // Customer ID
private ser = inject(CustomerService);
dialogRef = inject<MatDialogRef<ChooseCustomerComponent>>(MatDialogRef);
formModel = signal<ChooseCustomerFormData>({
name: '',
phone: '',
address: '',
printInBill: false,
discounts: [],
item = signal<Customer>(this.data ?? new Customer());
formModel = linkedSignal<Customer, ChooseCustomerFormData>({
source: () => this.item(),
computation: (data) => ({
id: data.id,
name: data.name,
phone: data.phone,
address: data.address ?? '',
printInBill: data.printInBill,
discounts: data.discounts.map((x) => ({
discount: x.discount ? x.discount * 100 : null,
})),
}),
});
form = form(this.formModel);
item: Customer = new Customer();
phoneSignal = computed(() => {
const p = this.formModel().phone;
return p === this.item.phone ? '' : p;
return this.formModel().phone;
});
debouncedPhone = debounced(this.phoneSignal, 150);
customersResource = this.ser.autocomplete(computed(() => this.debouncedPhone.value()));
customers = computed(() => {
if (!this.debouncedPhone.value()) return [];
return this.customersResource.value() ?? [];
});
constructor() {
const data = this.data;
if (data) {
const res = this.ser.get(data);
effect(() => {
const x = res.value();
if (x) {
this.showItem(x);
}
});
}
}
showItem(item: Customer) {
this.item = item;
this.formModel.set({
name: item.name,
phone: item.phone,
address: item.address ?? '',
printInBill: item.printInBill,
discounts: item.discounts.map((x) => ({
discount: x.discount ? x.discount * 100 : null,
})),
});
}
customersResource = this.ser.autocomplete(this.debouncedPhone.value);
customers = computed(() => { return this.customersResource.value() ?? [] });
save() {
const customer = this.getItem();
@@ -109,7 +87,7 @@ export class ChooseCustomerComponent {
selected(event: MatAutocompleteSelectedEvent): void {
const customer: Customer = event.option.value;
this.showItem(customer);
this.item.set(customer);
}
getItem(): Customer {
@@ -117,16 +95,15 @@ export class ChooseCustomerComponent {
const array = formModel.discounts;
return new Customer({
...this.item,
id: this.item.phone.trim() !== formModel.phone?.trim() ? '' : this.item.id,
id: formModel.id,
name: formModel.name ?? '',
phone: formModel.phone ?? '',
address: formModel.address ?? '',
printInBill: formModel.printInBill ?? false,
discounts: this.item.discounts.map((item, index) => {
discounts: formModel.discounts.map((item, index) => {
const array_item = array?.[index];
return {
...item,
...this.item().discounts?.[index],
discount:
array_item && array_item?.discount ? Math.max(Math.min(round(array_item.discount / 100, 5), 100), 0) : 0,
};
@@ -1,5 +1,5 @@
import { httpResource, HttpResourceRef } from '@angular/common/http';
import { Injectable, inject, Injector } from '@angular/core';
import { Injectable, inject, Injector, Signal } from '@angular/core';
import { DiscountItem } from './discount-item';
@@ -11,8 +11,11 @@ const url = '/api/customer-discounts';
export class CustomerDiscountsService {
private injector = inject(Injector);
list(id: string | undefined): HttpResourceRef<DiscountItem[] | undefined> {
return httpResource<DiscountItem[]>(() => (id === undefined ? url : `${url}/${id}`), {
list(id: Signal<string | undefined>): HttpResourceRef<DiscountItem[] | undefined> {
return httpResource<DiscountItem[]>(() => {
const idVal = id();
return idVal === undefined ? url : `${url}/${idVal}`;
}, {
injector: this.injector,
});
}
@@ -1,4 +1,4 @@
import { Component, inject, computed } from '@angular/core';
import { Component, inject, computed, signal } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
import { MatRippleModule } from '@angular/material/core';
import { MatDialog } from '@angular/material/dialog';
@@ -87,7 +87,7 @@ export class SalesHomeComponent {
if (this.discountAllowed()) {
const dialogRef = this.dialog.open(DiscountComponent, {
// width: '750px',
data: this.customerDiscountsService.list(this.bs.bill.customer?.id),
data: this.customerDiscountsService.list(signal(this.bs.bill.customer?.id)),
});
return dialogRef.afterClosed();
}
@@ -13,7 +13,7 @@ import { MenuCategoryService } from '../../menu-category/menu-category.service';
})
export class MenuCategoriesComponent {
private menuCategoryService = inject(MenuCategoryService);
listResource = this.menuCategoryService.list(undefined);
listResource = this.menuCategoryService.list();
list = computed(() => this.listResource.value() ?? []);
}
@@ -19,9 +19,9 @@ export class SectionPrinterService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<SectionPrinter[] | undefined> {
get(id: Signal<string | null>): HttpResourceRef<SectionPrinter[] | undefined> {
return httpResource<SectionPrinter[]>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
+2 -2
View File
@@ -19,9 +19,9 @@ export class SectionService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Section | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Section | undefined> {
return httpResource<Section>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -20,9 +20,9 @@ export class SettleOptionService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<SettleOption | undefined> {
get(id: Signal<string | null>): HttpResourceRef<SettleOption | undefined> {
return httpResource<SettleOption>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
+2 -2
View File
@@ -20,10 +20,10 @@ export class TableService {
private log = inject(ErrorLoggerService);
private injector = inject(Injector);
get(id: Signal<string | null> | string | null): HttpResourceRef<Table | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Table | undefined> {
return httpResource<Table>(
() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
},
{ injector: this.injector },
+2 -2
View File
@@ -19,9 +19,9 @@ export class TaxService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<Tax | undefined> {
get(id: Signal<string | null>): HttpResourceRef<Tax | undefined> {
return httpResource<Tax>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
@@ -76,7 +76,7 @@ export class TemporalProductDetailComponent {
saleCategoriesResource = this.saleCategoryService.list();
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
itemResource = this.ser.get(this.id);
@@ -42,7 +42,7 @@ export class TemporalProductListComponent {
private temporalProductService = inject(TemporalProductService);
saleCategoriesResource = this.saleCategoryService.list();
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
listResource = this.temporalProductService.list();
menuCategoryFilter = signal<string>('');
@@ -18,9 +18,9 @@ export class TemporalProductService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string): HttpResourceRef<TemporalProduct | undefined> {
get(id: Signal<string | null>): HttpResourceRef<TemporalProduct | undefined> {
return httpResource<TemporalProduct>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return `${url}/${idVal ?? ''}`;
});
}
@@ -53,7 +53,7 @@ export class UpdateProductPricesComponent {
infoResource = this.ser.get(this.id, this.date);
menuCategoriesResource = this.menuCategoryService.list(undefined);
menuCategoriesResource = this.menuCategoryService.list();
info = computed(() => this.infoResource.value() ?? new UpdateProductPrices());
dataSource = computed(() => this.info().items);
+2 -2
View File
@@ -19,9 +19,9 @@ export class UserService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: Signal<string | null> | string | null): HttpResourceRef<User | undefined> {
get(id: Signal<string | null>): HttpResourceRef<User | undefined> {
return httpResource<User>(() => {
const idVal = typeof id === 'function' ? id() : id;
const idVal = id();
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}