Rate Contract is checked during save and update of Purchase at the backend
This commit is contained in:
@ -15,6 +15,7 @@ export class Product {
|
||||
isPurchased: boolean;
|
||||
isSold: boolean;
|
||||
productGroup?: ProductGroup;
|
||||
isRateContracted?: boolean;
|
||||
|
||||
public constructor(init?: Partial<Product>) {
|
||||
this.code = 0;
|
||||
|
||||
@ -51,8 +51,16 @@ export class ProductService {
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Product>;
|
||||
}
|
||||
|
||||
autocomplete(query: string, extended: boolean = false): Observable<Product[]> {
|
||||
autocomplete(
|
||||
query: string,
|
||||
extended: boolean = false,
|
||||
date?: string,
|
||||
vendorId?: string,
|
||||
): Observable<Product[]> {
|
||||
const options = { params: new HttpParams().set('q', query).set('e', extended.toString()) };
|
||||
if (!!vendorId && !!date) {
|
||||
options.params = options.params.set('v', vendorId as string).set('d', date as string);
|
||||
}
|
||||
return this.http
|
||||
.get<Product[]>(`${url}/query`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<Product[]>;
|
||||
|
||||
@ -94,7 +94,16 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
|
||||
switchMap((x) =>
|
||||
x === null
|
||||
? observableOf([])
|
||||
: this.productSer.autocomplete(
|
||||
x,
|
||||
false,
|
||||
moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||
this.form.value.account.id,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -182,10 +191,17 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
addRow() {
|
||||
const formValue = (this.form.get('addRow') as FormControl).value;
|
||||
const quantity = this.math.parseAmount(formValue.quantity, 2);
|
||||
const price = this.math.parseAmount(formValue.price, 2);
|
||||
const tax = this.math.parseAmount(formValue.tax, 5);
|
||||
const discount = this.math.parseAmount(formValue.discount, 5);
|
||||
if (this.product === null || quantity <= 0 || price <= 0) {
|
||||
if (this.product === null || quantity <= 0) {
|
||||
return;
|
||||
}
|
||||
const price = this.product.isRateContracted
|
||||
? this.product.price
|
||||
: this.math.parseAmount(formValue.price, 2);
|
||||
const tax = this.product.isRateContracted ? 0 : this.math.parseAmount(formValue.tax, 5);
|
||||
const discount = this.product.isRateContracted
|
||||
? 0
|
||||
: this.math.parseAmount(formValue.discount, 5);
|
||||
if (price <= 0 || tax < 0 || discount < 0) {
|
||||
return;
|
||||
}
|
||||
const oldFiltered = this.voucher.inventories.filter(
|
||||
@ -219,6 +235,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
discount: '',
|
||||
});
|
||||
this.product = null;
|
||||
((this.form.get('addRow') as FormControl).get('price') as FormControl).enable();
|
||||
((this.form.get('addRow') as FormControl).get('tax') as FormControl).enable();
|
||||
((this.form.get('addRow') as FormControl).get('discount') as FormControl).enable();
|
||||
setTimeout(() => {
|
||||
if (this.productElement) {
|
||||
this.productElement.nativeElement.focus();
|
||||
@ -344,9 +363,22 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
const product = event.option.value;
|
||||
const product: Product = event.option.value;
|
||||
this.product = product;
|
||||
((this.form.get('addRow') as FormControl).get('price') as FormControl).setValue(product.price);
|
||||
if (product.isRateContracted) {
|
||||
((this.form.get('addRow') as FormControl).get('price') as FormControl).disable();
|
||||
((this.form.get('addRow') as FormControl).get('tax') as FormControl).disable();
|
||||
((this.form.get('addRow') as FormControl).get('discount') as FormControl).disable();
|
||||
((this.form.get('addRow') as FormControl).get('tax') as FormControl).setValue('RC');
|
||||
((this.form.get('addRow') as FormControl).get('discount') as FormControl).setValue('RC');
|
||||
} else {
|
||||
((this.form.get('addRow') as FormControl).get('price') as FormControl).enable();
|
||||
((this.form.get('addRow') as FormControl).get('tax') as FormControl).enable();
|
||||
((this.form.get('addRow') as FormControl).get('discount') as FormControl).enable();
|
||||
((this.form.get('addRow') as FormControl).get('tax') as FormControl).setValue('');
|
||||
((this.form.get('addRow') as FormControl).get('discount') as FormControl).setValue('');
|
||||
}
|
||||
}
|
||||
|
||||
zoomImage(file: DbFile) {
|
||||
|
||||
Reference in New Issue
Block a user