Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {BehaviorSubject, Observable, of as observableOf} from 'rxjs';
|
||||
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
|
||||
import {IssueDataSource} from './issue-datasource';
|
||||
import {VoucherService} from '../core/voucher.service';
|
||||
import {Batch, Inventory, Voucher} from '../core/voucher';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { IssueDataSource } from './issue-datasource';
|
||||
import { VoucherService } from '../core/voucher.service';
|
||||
import { Batch, Inventory, Voucher } from '../core/voucher';
|
||||
import * as moment from 'moment';
|
||||
import {AuthService} from '../auth/auth.service';
|
||||
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import {ToasterService} from '../core/toaster.service';
|
||||
import {IssueDialogComponent} from './issue-dialog.component';
|
||||
import {BatchService} from '../core/batch.service';
|
||||
import {IssueGridService} from './issue-grid.service';
|
||||
import {CostCentre} from '../core/cost-centre';
|
||||
import {IssueGridDataSource} from './issue-grid-datasource';
|
||||
import {Hotkey, HotkeysService} from 'angular2-hotkeys';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { IssueDialogComponent } from './issue-dialog.component';
|
||||
import { BatchService } from '../core/batch.service';
|
||||
import { IssueGridService } from './issue-grid.service';
|
||||
import { CostCentre } from '../core/cost-centre';
|
||||
import { IssueGridDataSource } from './issue-grid-datasource';
|
||||
import { Hotkey, HotkeysService } from 'angular2-hotkeys';
|
||||
|
||||
@Component({
|
||||
selector: 'app-issue',
|
||||
templateUrl: './issue.component.html',
|
||||
styleUrls: ['./issue.component.css']
|
||||
styleUrls: ['./issue.component.css'],
|
||||
})
|
||||
export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
@ViewChild('batchElement', { static: true }) batchElement: ElementRef;
|
||||
@@ -51,7 +51,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private auth: AuthService,
|
||||
private ser: VoucherService,
|
||||
private batchSer: BatchService,
|
||||
private issueGridSer: IssueGridService
|
||||
private issueGridSer: IssueGridService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.listenToBatchAutocompleteChange();
|
||||
@@ -60,23 +60,34 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
ngOnInit() {
|
||||
this.gridDataSource = new IssueGridDataSource(this.gridObservable);
|
||||
this.route.data
|
||||
.subscribe((data: { voucher: Voucher, costCentres: CostCentre[] }) => {
|
||||
this.costCentres = data.costCentres;
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
|
||||
setTimeout(() => {
|
||||
this.dateElement.nativeElement.focus();
|
||||
}, 0);
|
||||
return false; // Prevent bubbling
|
||||
}, ['INPUT', 'SELECT', 'TEXTAREA']));
|
||||
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
|
||||
if (this.canSave()) {
|
||||
this.save();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
}, ['INPUT', 'SELECT', 'TEXTAREA']));
|
||||
this.route.data.subscribe((data: { voucher: Voucher; costCentres: CostCentre[] }) => {
|
||||
this.costCentres = data.costCentres;
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'f2',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
setTimeout(() => {
|
||||
this.dateElement.nativeElement.focus();
|
||||
}, 0);
|
||||
return false; // Prevent bubbling
|
||||
},
|
||||
['INPUT', 'SELECT', 'TEXTAREA'],
|
||||
),
|
||||
);
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'ctrl+s',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
if (this.canSave()) {
|
||||
this.save();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
},
|
||||
['INPUT', 'SELECT', 'TEXTAREA'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@@ -96,9 +107,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
|
||||
addRow: {
|
||||
batch: '',
|
||||
quantity: ''
|
||||
quantity: '',
|
||||
},
|
||||
narration: this.voucher.narration
|
||||
narration: this.voucher.narration,
|
||||
});
|
||||
this.dataSource = new IssueDataSource(this.inventoryObservable);
|
||||
this.updateView();
|
||||
@@ -112,12 +123,14 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
addRow() {
|
||||
const formValue = this.form.get('addRow').value;
|
||||
const quantity = +(formValue.quantity);
|
||||
const quantity = +formValue.quantity;
|
||||
const isConsumption = this.form.value.source === '7b845f95-dfef-fa4a-897c-f0baf15284a3';
|
||||
if (this.batch === null || quantity <= 0) {
|
||||
return;
|
||||
}
|
||||
const oldFiltered = this.voucher.inventories.filter((x) => x.product.id === this.batch.product.id);
|
||||
const oldFiltered = this.voucher.inventories.filter(
|
||||
(x) => x.product.id === this.batch.product.id,
|
||||
);
|
||||
const old = oldFiltered.length ? oldFiltered[0] : null;
|
||||
if (oldFiltered.length) {
|
||||
if (old.batch.id !== this.batch.id) {
|
||||
@@ -142,7 +155,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
discount: this.batch.discount,
|
||||
amount: quantity * this.batch.rate * (1 + this.batch.tax) * (1 - this.batch.discount),
|
||||
product: this.batch.product,
|
||||
batch: this.batch
|
||||
batch: this.batch,
|
||||
});
|
||||
}
|
||||
this.resetAddRow();
|
||||
@@ -152,7 +165,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
resetAddRow() {
|
||||
this.form.get('addRow').reset({
|
||||
batch: null,
|
||||
quantity: ''
|
||||
quantity: '',
|
||||
});
|
||||
this.batch = null;
|
||||
setTimeout(() => {
|
||||
@@ -162,14 +175,19 @@ 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 = Math.abs(
|
||||
this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0),
|
||||
);
|
||||
this.form.get('amount').setValue(amount);
|
||||
}
|
||||
|
||||
editRow(row: Inventory) {
|
||||
const dialogRef = this.dialog.open(IssueDialogComponent, {
|
||||
width: '750px',
|
||||
data: {inventory: Object.assign({}, row), date: moment(this.form.value.date).format('DD-MMM-YYYY')}
|
||||
data: {
|
||||
inventory: Object.assign({}, row),
|
||||
date: moment(this.form.value.date).format('DD-MMM-YYYY'),
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | Inventory) => {
|
||||
@@ -177,7 +195,10 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
const j = result as Inventory;
|
||||
if (j.product.id !== row.product.id && this.voucher.inventories.filter((x) => x.product.id === j.product.id).length) {
|
||||
if (
|
||||
j.product.id !== row.product.id &&
|
||||
this.voucher.inventories.filter((x) => x.product.id === j.product.id).length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
Object.assign(row, j);
|
||||
@@ -195,12 +216,12 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
date: '',
|
||||
source: '',
|
||||
destination: '',
|
||||
amount: {value: '', disabled: true},
|
||||
amount: { value: '', disabled: true },
|
||||
addRow: this.fb.group({
|
||||
batch: '',
|
||||
quantity: ''
|
||||
quantity: '',
|
||||
}),
|
||||
narration: ''
|
||||
narration: '',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -210,26 +231,28 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
} else if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
|
||||
return true;
|
||||
} else {
|
||||
return this.voucher.user.id === this.auth.user.id || this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1;
|
||||
return (
|
||||
this.voucher.user.id === this.auth.user.id ||
|
||||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
save() {
|
||||
const voucher: Voucher = this.getVoucher();
|
||||
this.ser.saveOrUpdate(voucher)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.ser.saveOrUpdate(voucher).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.router.navigate(['/issue', result.id]);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
newVoucher() {
|
||||
@@ -246,22 +269,21 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.voucher.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/issue'], {replaceUrl: true});
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.voucher.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/issue'], { replaceUrl: true });
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
@@ -273,33 +295,28 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
listenToBatchAutocompleteChange(): void {
|
||||
const control = this.form.get('addRow').get('batch');
|
||||
this.batches = control.valueChanges
|
||||
.pipe(
|
||||
startWith(null),
|
||||
map(x => (x !== null && x.length >= 1) ? x : null),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap(
|
||||
x => (x === null) ? observableOf([]) : this.batchSer.autocomplete(
|
||||
moment(this.form.value.date).format('DD-MMM-YYYY'), x
|
||||
)
|
||||
)
|
||||
);
|
||||
this.batches = control.valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) =>
|
||||
x === null
|
||||
? observableOf([])
|
||||
: this.batchSer.autocomplete(moment(this.form.value.date).format('DD-MMM-YYYY'), x),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
listenToDateChange(): void {
|
||||
this.form.get('date').valueChanges
|
||||
.pipe(
|
||||
map(x => moment(x).format('DD-MMM-YYYY'))
|
||||
)
|
||||
.subscribe(x => this.showGrid(x));
|
||||
this.form
|
||||
.get('date')
|
||||
.valueChanges.pipe(map((x) => moment(x).format('DD-MMM-YYYY')))
|
||||
.subscribe((x) => this.showGrid(x));
|
||||
}
|
||||
|
||||
showGrid(date: string) {
|
||||
this.issueGridSer.issueGrid(date)
|
||||
.subscribe(
|
||||
x => this.gridObservable.next(x)
|
||||
);
|
||||
this.issueGridSer.issueGrid(date).subscribe((x) => this.gridObservable.next(x));
|
||||
}
|
||||
|
||||
displayBatchName(batch?: Batch): string | undefined {
|
||||
@@ -313,5 +330,4 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
goToVoucher(id: string) {
|
||||
this.router.navigate(['/issue', id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user