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

@ -4,6 +4,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormBuilder, FormGroup } from '@angular/forms';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import { Observable, of as observableOf } from 'rxjs';
import { MathService } from '../shared/math.service';
import { Batch } from '../core/voucher';
import { BatchService } from '../core/batch.service';
@ -21,6 +22,7 @@ export class IssueDialogComponent implements OnInit {
public dialogRef: MatDialogRef<IssueDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private fb: FormBuilder,
private math: MathService,
private batchSer: BatchService,
) {
this.createForm();
@ -65,7 +67,7 @@ export class IssueDialogComponent implements OnInit {
accept(): void {
const formValue = this.form.value;
const quantity = +formValue.quantity;
const quantity = this.math.parseAmount(formValue.quantity, 2);
this.data.inventory.batch = this.batch;
this.data.inventory.product = this.batch.product;
this.data.inventory.quantity = quantity;

View File

@ -9,6 +9,8 @@ import { IssueDataSource } from './issue-datasource';
import { VoucherService } from '../core/voucher.service';
import { Batch, Inventory, Voucher } from '../core/voucher';
import * as moment from 'moment';
import { round } from 'mathjs';
import { MathService } from '../shared/math.service';
import { AuthService } from '../auth/auth.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { ToasterService } from '../core/toaster.service';
@ -49,6 +51,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
private hotkeys: HotkeysService,
private toaster: ToasterService,
private auth: AuthService,
private math: MathService,
private ser: VoucherService,
private batchSer: BatchService,
private issueGridSer: IssueGridService,
@ -123,7 +126,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
addRow() {
const formValue = this.form.get('addRow').value;
const quantity = +formValue.quantity;
const quantity = this.math.parseAmount(formValue.quantity, 2);
const isConsumption = this.form.value.source === '7b845f95-dfef-fa4a-897c-f0baf15284a3';
if (this.batch === null || quantity <= 0) {
return;
@ -175,8 +178,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
updateView() {
this.inventoryObservable.next(this.voucher.inventories);
const amount = Math.abs(
this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0),
const amount = round(
Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
2,
);
this.form.get('amount').setValue(amount);
}