DB Normalization: Moved fractionUnits back to Product from SKU as it is better suited there.
Feature: Created the ProductSku schema for the product/sku autocomplete
This commit is contained in:
@ -9,6 +9,7 @@ import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'r
|
||||
import { Batch } from '../core/batch';
|
||||
import { Inventory } from '../core/inventory';
|
||||
import { Product } from '../core/product';
|
||||
import { ProductSku } from '../core/product-sku';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { MathService } from '../shared/math.service';
|
||||
|
||||
@ -18,9 +19,9 @@ import { MathService } from '../shared/math.service';
|
||||
styleUrls: ['./purchase-dialog.component.css'],
|
||||
})
|
||||
export class PurchaseDialogComponent implements OnInit {
|
||||
products: Observable<Product[]>;
|
||||
products: Observable<ProductSku[]>;
|
||||
form: FormGroup;
|
||||
product: Product = new Product();
|
||||
product: ProductSku = new ProductSku();
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<PurchaseDialogComponent>,
|
||||
@ -42,7 +43,7 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x, true))),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocompleteSku(x, true))),
|
||||
);
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ export class PurchaseDialogComponent implements OnInit {
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.product = event.option.value;
|
||||
(this.form.get('price') as FormControl).setValue(this.product.price);
|
||||
(this.form.get('price') as FormControl).setValue(this.product.costPrice);
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
|
||||
@ -17,6 +17,7 @@ import { Batch } from '../core/batch';
|
||||
import { DbFile } from '../core/db-file';
|
||||
import { Inventory } from '../core/inventory';
|
||||
import { Product } from '../core/product';
|
||||
import { ProductSku } from '../core/product-sku';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { User } from '../core/user';
|
||||
import { Voucher } from '../core/voucher';
|
||||
@ -43,13 +44,13 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
dataSource: PurchaseDataSource = new PurchaseDataSource(this.inventoryObservable);
|
||||
form: FormGroup;
|
||||
voucher: Voucher = new Voucher();
|
||||
product: Product | null = null;
|
||||
product: ProductSku | null = null;
|
||||
accBal: AccountBalance | null = null;
|
||||
|
||||
displayedColumns = ['product', 'quantity', 'rate', 'tax', 'discount', 'amount', 'action'];
|
||||
|
||||
accounts: Observable<Account[]>;
|
||||
products: Observable<Product[]>;
|
||||
products: Observable<ProductSku[]>;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -98,11 +99,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
switchMap((x) =>
|
||||
x === null
|
||||
? observableOf([])
|
||||
: this.productSer.autocomplete(
|
||||
: this.productSer.autocompleteSku(
|
||||
x,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||
this.form.value.account.id,
|
||||
),
|
||||
@ -198,7 +197,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
const price = this.product.isRateContracted
|
||||
? this.product.price
|
||||
? (this.product.costPrice as number)
|
||||
: this.math.parseAmount(formValue.price, 2);
|
||||
const tax = this.product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
|
||||
const discount = this.product.isRateContracted
|
||||
@ -208,7 +207,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
const oldFiltered = this.voucher.inventories.filter(
|
||||
(x) => x.batch?.sku.id === (this.product as Product).id,
|
||||
(x) => x.batch?.sku.id === (this.product as ProductSku).id,
|
||||
);
|
||||
if (oldFiltered.length) {
|
||||
this.toaster.show('Danger', 'Product already added');
|
||||
@ -365,10 +364,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
const product: Product = event.option.value;
|
||||
const product: ProductSku = event.option.value;
|
||||
const addRowForm: FormControl = this.form.get('addRow') as FormControl;
|
||||
this.product = product;
|
||||
(addRowForm.get('price') as FormControl).setValue(product.price);
|
||||
(addRowForm.get('price') as FormControl).setValue(product.costPrice);
|
||||
if (product.isRateContracted) {
|
||||
(addRowForm.get('price') as FormControl).disable();
|
||||
(addRowForm.get('tax') as FormControl).disable();
|
||||
|
||||
Reference in New Issue
Block a user