fdsa
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { SelectionModel } from '@angular/cdk/collections';
|
||||
import { Injectable, inject, signal, computed } from '@angular/core';
|
||||
import { Injectable, Injector, computed, inject, signal } from '@angular/core';
|
||||
import { toObservable } from '@angular/core/rxjs-interop';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { throwError, Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { filter, take, tap } from 'rxjs/operators';
|
||||
|
||||
import { ModifierCategory } from '../core/modifier-category';
|
||||
import { ProductQuery } from '../core/product-query';
|
||||
@@ -29,6 +30,7 @@ export class BillService {
|
||||
private math = inject(MathService);
|
||||
private ser = inject(VoucherService);
|
||||
private modifierCategoryService = inject(ModifierCategoryService);
|
||||
private injector = inject(Injector);
|
||||
|
||||
public data = signal<Kot[]>([]);
|
||||
public bill: Bill = new Bill();
|
||||
@@ -152,11 +154,17 @@ export class BillService {
|
||||
}
|
||||
}
|
||||
newKot.inventories.push(item);
|
||||
this.modifierCategoryService.listForSku(sku.id as string).subscribe((result) => {
|
||||
if (result.reduce((a: number, c: ModifierCategory) => a + c.minimum, 0)) {
|
||||
this.showModifier(item);
|
||||
}
|
||||
});
|
||||
const modRes = this.modifierCategoryService.listForSku(signal(sku.id as string));
|
||||
toObservable(modRes.value, { injector: this.injector })
|
||||
.pipe(
|
||||
filter((result): result is ModifierCategory[] => !!result),
|
||||
take(1),
|
||||
)
|
||||
.subscribe((result) => {
|
||||
if (result.reduce((a: number, c: ModifierCategory) => a + c.minimum, 0)) {
|
||||
this.showModifier(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.displayBill();
|
||||
}
|
||||
@@ -171,7 +179,7 @@ export class BillService {
|
||||
maxWidth: 'none',
|
||||
maxHeight: 'none',
|
||||
data: {
|
||||
list: this.modifierCategoryService.listForSku(item.sku.id as string),
|
||||
list: this.modifierCategoryService.listForSku(signal(item.sku.id as string)),
|
||||
selected: Object.assign([], item.modifiers),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||
import { Component, inject, signal, computed } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { HttpResourceRef } from '@angular/common/http';
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { MatBadgeModule } from '@angular/material/badge';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
@@ -8,7 +8,6 @@ import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatRippleModule } from '@angular/material/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Modifier } from '../../core/modifier';
|
||||
import { ModifierCategory } from '../../core/modifier-category';
|
||||
@@ -30,11 +29,11 @@ import { ModifierCategory } from '../../core/modifier-category';
|
||||
})
|
||||
export class ModifiersComponent {
|
||||
data = inject<{
|
||||
list: Observable<ModifierCategory[]>;
|
||||
list: HttpResourceRef<ModifierCategory[] | undefined>;
|
||||
selected: Modifier[];
|
||||
}>(MAT_DIALOG_DATA);
|
||||
|
||||
list = toSignal(this.data.list, { initialValue: [] });
|
||||
list = computed(() => this.data.list.value() ?? []);
|
||||
selected = signal<Modifier[]>(this.data.selected ? [...this.data.selected] : []);
|
||||
selectedIds = computed(() => this.selected().map((e) => e.id));
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { CdkScrollableModule } from '@angular/cdk/scrolling';
|
||||
import { CurrencyPipe } from '@angular/common';
|
||||
import { Component, inject, signal, computed } from '@angular/core';
|
||||
import { form, FormField } from '@angular/forms/signals';
|
||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
||||
import { FormField, form } from '@angular/forms/signals';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
|
||||
import { ReceivePaymentItem } from '../../core/receive-payment-item';
|
||||
import { SettleOption } from '../../core/settle-option';
|
||||
import { SettleOptionService } from '../../settle-option/settle-option.service';
|
||||
import { VoucherType } from '../bills/voucher-type';
|
||||
|
||||
@@ -45,6 +43,9 @@ export class ReceivePaymentComponent {
|
||||
amount: number;
|
||||
}>(MAT_DIALOG_DATA);
|
||||
|
||||
typeSignal = signal<VoucherType | undefined>(this.data.type);
|
||||
settleOptionsResource = this.ser.listForType(this.typeSignal);
|
||||
|
||||
choices = signal<ReceivePaymentItem[]>([]);
|
||||
choicesWithAmount = computed(() => {
|
||||
const amounts = this.formModel().amounts;
|
||||
@@ -77,25 +78,23 @@ export class ReceivePaymentComponent {
|
||||
this.amount = data.amount;
|
||||
this.displayReason.set(false);
|
||||
this.displayTable.set(false);
|
||||
this.ser
|
||||
.listForType(data.type)
|
||||
.pipe(
|
||||
tap((x: SettleOption[]) => this.displayReason.set(x.reduce((o, n) => o || n.hasReason, this.displayReason()))),
|
||||
tap((x: SettleOption[]) => this.displayTable.set(x.length > 1)),
|
||||
map((x: SettleOption[]) =>
|
||||
x.map((y) => ({ ...y, amount: !this.displayTable() ? this.amount : 0 }) as ReceivePaymentItem),
|
||||
),
|
||||
)
|
||||
.subscribe((x) => {
|
||||
this.choices.set(x);
|
||||
this.formModel.update((f) => ({
|
||||
...f,
|
||||
amounts: x.map((y) => ({
|
||||
name: y.name,
|
||||
amount: y.amount === 0 ? 0 : this.amount,
|
||||
})),
|
||||
}));
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
const x = this.settleOptionsResource.value();
|
||||
if (!x) return;
|
||||
this.displayReason.set(x.reduce((o, n) => o || n.hasReason, false));
|
||||
this.displayTable.set(x.length > 1);
|
||||
const isTable = x.length > 1;
|
||||
const choices = x.map((y) => ({ ...y, amount: !isTable ? this.amount : 0 }) as ReceivePaymentItem);
|
||||
this.choices.set(choices);
|
||||
this.formModel.update((f) => ({
|
||||
...f,
|
||||
amounts: x.map((y) => ({
|
||||
name: y.name,
|
||||
amount: !isTable ? this.amount : 0,
|
||||
})),
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
select(reason: string) {
|
||||
|
||||
Reference in New Issue
Block a user