2021-09-27 04:01:58 +00:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
|
|
|
|
import { StockKeepingUnit } from '../../core/product';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-journal-dialog',
|
|
|
|
templateUrl: './product-detail-dialog.component.html',
|
|
|
|
styleUrls: ['./product-detail-dialog.component.css'],
|
|
|
|
})
|
|
|
|
export class ProductDetailDialogComponent implements OnInit {
|
|
|
|
form: FormGroup;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<ProductDetailDialogComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA)
|
|
|
|
public data: { item: StockKeepingUnit; isSold: boolean; isPurchased: boolean },
|
|
|
|
private fb: FormBuilder,
|
|
|
|
) {
|
|
|
|
this.form = this.fb.group({
|
|
|
|
units: '',
|
|
|
|
fraction: '',
|
|
|
|
productYield: '',
|
2021-11-02 08:20:35 +00:00
|
|
|
costPrice: '',
|
2021-09-27 04:01:58 +00:00
|
|
|
salePrice: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.form.setValue({
|
|
|
|
units: this.data.item.units,
|
|
|
|
fraction: '' + this.data.item.fraction,
|
|
|
|
productYield: '' + this.data.item.productYield,
|
2021-11-02 08:20:35 +00:00
|
|
|
costPrice: '' + this.data.item.costPrice,
|
2021-09-27 04:01:58 +00:00
|
|
|
salePrice: '' + this.data.item.salePrice,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
accept(): void {
|
|
|
|
const formValue = this.form.value;
|
|
|
|
const fraction = +formValue.fraction;
|
|
|
|
if (fraction < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const productYield = +formValue.productYield;
|
|
|
|
if (productYield < 0 || productYield > 1) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-02 08:20:35 +00:00
|
|
|
const costPrice = +formValue.costPrice;
|
|
|
|
if (costPrice < 0) {
|
2021-09-27 04:01:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const salePrice = +formValue.salePrice;
|
|
|
|
if (salePrice < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.data.item.units = formValue.units;
|
|
|
|
this.data.item.fraction = fraction;
|
|
|
|
this.data.item.productYield = productYield;
|
2021-11-02 08:20:35 +00:00
|
|
|
this.data.item.costPrice = costPrice;
|
2021-09-27 04:01:58 +00:00
|
|
|
this.data.item.salePrice = salePrice;
|
|
|
|
this.dialogRef.close(this.data.item);
|
|
|
|
}
|
|
|
|
}
|