Feature: Allow math expressions on all journal inputs and also round them properly.

Chore:
  Prettied index.html, main.ts and styles.css
  Updated Dependencies
This commit is contained in:
2020-10-07 18:41:17 +05:30
parent cefb3ebdcc
commit cfeef1795d
20 changed files with 202 additions and 120 deletions

View File

@ -1,9 +1,11 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import { FormBuilder, FormGroup } from '@angular/forms';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import { Observable, of as observableOf } from 'rxjs';
import { round } from 'mathjs';
import { MathService } from '../shared/math.service';
import { Product } from '../core/product';
import { ProductService } from '../product/product.service';
@ -21,6 +23,7 @@ export class PurchaseDialogComponent implements OnInit {
public dialogRef: MatDialogRef<PurchaseDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private fb: FormBuilder,
private math: MathService,
private productSer: ProductService,
) {
this.createForm();
@ -70,16 +73,16 @@ export class PurchaseDialogComponent implements OnInit {
accept(): void {
const formValue = this.form.value;
const quantity = +formValue.quantity;
const price = +formValue.price;
const tax = +formValue.tax;
const discount = +formValue.discount;
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);
this.data.inventory.product = this.product;
this.data.inventory.quantity = quantity;
this.data.inventory.rate = price;
this.data.inventory.tax = tax;
this.data.inventory.discount = discount;
this.data.inventory.amount = quantity * price * (1 + tax) * (1 - discount);
this.data.inventory.amount = round(quantity * price * (1 + tax) * (1 - discount), 2);
this.dialogRef.close(this.data.inventory);
}
}