Moved to Angular 6.0

----

Pending
* Table width for the points column in incentive
* Linting
* keyboard navigation where it was used earlier
* can remove the unused totals calculated serverside in productledger
* spinner and loading bars
* Activate Guard for Employee Function tabs
* Progress for Fingerprint uploads
* deleted reconcile and receipe features as they were not being used
* focus the right control on component load
This commit is contained in:
tanshu
2018-05-25 19:19:00 +05:30
parent b3cb01da02
commit 6be1dd5a3a
1380 changed files with 23914 additions and 18722 deletions

View File

@ -0,0 +1,18 @@
import {DataSource} from '@angular/cdk/collections';
import {Observable} from 'rxjs';
import {Inventory, Journal} from '../journal/voucher';
export class IssueDataSource extends DataSource<Inventory> {
constructor(private data: Observable<Inventory[]>) {
super();
}
connect(): Observable<Inventory[]> {
return this.data;
}
disconnect() {
}
}

View File

@ -0,0 +1,25 @@
<h1 mat-dialog-title>Edit Issue Entry</h1>
<div mat-dialog-content>
<form [formGroup]="form">
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="65">
<input type="text" matInput placeholder="Product" #batchElement [matAutocomplete]="autoB"
formControlName="batch" autocomplete="off">
<mat-autocomplete #autoB="matAutocomplete" autoActiveFirstOption [displayWith]="displayBatchName"
(optionSelected)="batchSelected($event)">
<mat-option *ngFor="let batch of batches | async" [value]="batch">{{batch.name}}</mat-option>
</mat-autocomplete>
</mat-form-field>
<mat-form-field fxFlex="35">
<mat-label>Quantity</mat-label>
<input type="text" matInput placeholder="Quantity" formControlName="quantity" autocomplete="off">
</mat-form-field>
</div>
</form>
</div>
<div mat-dialog-actions>
<button mat-button [mat-dialog-close]="false" cdkFocusInitial>Cancel</button>
<button mat-button (click)="accept()" color="primary">Ok</button>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IssueDialogComponent } from './issue-dialog.component';
describe('IssueDialogComponent', () => {
let component: IssueDialogComponent;
let fixture: ComponentFixture<IssueDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ IssueDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(IssueDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,74 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatAutocompleteSelectedEvent, MatDialogRef} from '@angular/material';
import {FormBuilder, FormGroup} from '@angular/forms';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {Observable, of as observableOf} from 'rxjs';
import {Batch} from '../journal/voucher';
import {BatchService} from '../purchase-return/batch.service';
@Component({
selector: 'app-issue-dialog',
templateUrl: './issue-dialog.component.html',
styleUrls: ['./issue-dialog.component.css']
})
export class IssueDialogComponent implements OnInit {
batches: Observable<Batch[]>;
form: FormGroup;
batch: Batch;
constructor(
public dialogRef: MatDialogRef<IssueDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private fb: FormBuilder,
private batchSer: BatchService) {
this.createForm();
this.listenToBatchAutocompleteChange();
}
ngOnInit() {
this.form.setValue({
batch: this.data.inventory.batch,
quantity: this.data.inventory.quantity
});
this.batch = this.data.inventory.batch;
}
createForm() {
this.form = this.fb.group({
batch: '',
quantity: ''
});
}
listenToBatchAutocompleteChange(): void {
const control = this.form.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(this.data.date, x)));
}
displayBatchName(batch?: Batch): string | undefined {
return batch ? batch.name : undefined;
}
batchSelected(event: MatAutocompleteSelectedEvent): void {
this.batch = event.option.value;
}
accept(): void {
const formValue = this.form.value;
const quantity = +(formValue.quantity);
this.data.inventory.batch = this.batch;
this.data.inventory.product = this.batch.product;
this.data.inventory.quantity = quantity;
this.data.inventory.rate = this.batch.rate;
this.data.inventory.tax = this.batch.tax;
this.data.inventory.discount = this.batch.discount;
this.data.inventory.amount = quantity * this.batch.rate * (1 + this.batch.tax) * (1 - this.batch.discount);
this.dialogRef.close(this.data.inventory);
}
}

View File

@ -0,0 +1,17 @@
import {DataSource} from '@angular/cdk/collections';
import {Observable} from 'rxjs';
export class IssueGridDataSource extends DataSource<any> {
constructor(private data: Observable<any[]>) {
super();
}
connect(): Observable<any[]> {
return this.data;
}
disconnect() {
}
}

View File

@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';
import { IssueGridService } from './issue-grid.service';
describe('IssueGridService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [IssueGridService]
});
});
it('should be created', inject([IssueGridService], (service: IssueGridService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,24 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http';
import {ErrorLoggerService} from '../core/error-logger.service';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
const url = '/api/IssueGrid';
const serviceName = 'BatchService';
@Injectable({
providedIn: 'root'
})
export class IssueGridService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
issueGrid(date: string): Observable<any[]> {
return <Observable<any[]>>this.http.get<any[]>(`${url}/${date}`)
.pipe(
catchError(this.log.handleError(serviceName, 'autocomplete'))
);
}
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {IssueResolver} from './issue-resolver.service';
describe('IssueResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [IssueResolver]
});
});
it('should be created', inject([IssueResolver], (service: IssueResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,23 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/internal/Observable';
import {Voucher} from '../journal/voucher';
import {VoucherService} from '../journal/voucher.service';
@Injectable({
providedIn: 'root'
})
export class IssueResolver implements Resolve<Voucher> {
constructor(private ser: VoucherService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Voucher> {
const id = route.paramMap.get('id');
if (id === null) {
return this.ser.getOfType('Issue');
} else {
return this.ser.get(id);
}
}
}

View File

@ -0,0 +1,13 @@
import {IssueRoutingModule} from './issue-routing.module';
describe('IssueRoutingModule', () => {
let issueRoutingModule: IssueRoutingModule;
beforeEach(() => {
issueRoutingModule = new IssueRoutingModule();
});
it('should create an instance', () => {
expect(issueRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,52 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {IssueResolver} from './issue-resolver.service';
import {AuthGuard} from '../auth/auth-guard.service';
import {IssueComponent} from './issue.component';
import {CostCentreListResolver} from '../cost-centre/cost-centre-list-resolver.service';
const issueRoutes: Routes = [
{
path: 'Issue',
component: IssueComponent,
canActivate: [AuthGuard],
data: {
permission: 'Issue'
},
resolve: {
voucher: IssueResolver,
costCentres: CostCentreListResolver
},
runGuardsAndResolvers: 'always'
},
{
path: 'Issue/:id',
component: IssueComponent,
canActivate: [AuthGuard],
data: {
permission: 'Issue'
},
resolve: {
voucher: IssueResolver,
costCentres: CostCentreListResolver
},
runGuardsAndResolvers: 'always'
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(issueRoutes)
],
exports: [
RouterModule
],
providers: [
IssueResolver
]
})
export class IssueRoutingModule {
}

View File

@ -0,0 +1,32 @@
.right {
display: flex;
justify-content: flex-end;
}
.selected {
background: #fff3cd
}
.unposted {
background: #f8d7da
}
.center {
display: flex;
justify-content: center;
}
.img-container {
position: relative;
}
.img-container .overlay {
display: none;
}
.img-container:hover > .overlay {
display: inline-block;
position: absolute;
left: 60px;
top: 0;
}

View File

@ -0,0 +1,159 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Issue</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date"
autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker>
</mat-form-field>
<mat-form-field fxFlex="40">
<mat-select formControlName="sourceCostCentre">
<mat-option *ngFor="let costCentre of costCentres" [value]="costCentre.id">
{{ costCentre.name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex="40">
<mat-select formControlName="destinationCostCentre">
<mat-option *ngFor="let costCentre of costCentres" [value]="costCentre.id">
{{ costCentre.name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex="20">
<mat-label>Amount</mat-label>
<span matPrefix></span>
<input type="text" matInput formControlName="amount">
</mat-form-field>
</div>
<div formGroupName="addRow" fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column"
fxLayoutGap="20px" fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex="55">
<input type="text" matInput placeholder="Product" #batchElement [matAutocomplete]="autoB"
formControlName="batch" autocomplete="off">
<mat-autocomplete #autoB="matAutocomplete" autoActiveFirstOption [displayWith]="displayBatchName"
(optionSelected)="batchSelected($event)">
<mat-option *ngFor="let batch of batches | async" [value]="batch">{{batch.name}}</mat-option>
</mat-autocomplete>
</mat-form-field>
<mat-form-field fxFlex="25">
<mat-label>Quantity</mat-label>
<input type="text" matInput placeholder="Quantity" formControlName="quantity" autocomplete="off">
</mat-form-field>
<button mat-raised-button color="primary" (click)="addRow()" fxFlex="20">Add</button>
</div>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
<!-- Product Column -->
<ng-container matColumnDef="product">
<mat-header-cell *matHeaderCellDef>Product</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.product.name}}</mat-cell>
</ng-container>
<!-- Batch Column -->
<ng-container matColumnDef="batch">
<mat-header-cell *matHeaderCellDef>Batch</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.batch.name}}</mat-cell>
</ng-container>
<!-- Quantity Column -->
<ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef class="right">Quantity</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.quantity | number:'1.2-2'}}</mat-cell>
</ng-container>
<!-- Rate Column -->
<ng-container matColumnDef="rate">
<mat-header-cell *matHeaderCellDef class="right">Rate</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.rate | currency:'INR'}}</mat-cell>
</ng-container>
<!-- Amount Column -->
<ng-container matColumnDef="amount">
<mat-header-cell *matHeaderCellDef class="right">Amount</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
</ng-container>
<!-- Action Column -->
<ng-container matColumnDef="action">
<mat-header-cell *matHeaderCellDef class="center">Action</mat-header-cell>
<mat-cell *matCellDef="let row" class="center">
<button mat-icon-button (click)="editRow(row)">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button color="warn" (click)="deleteRow(row)">
<mat-icon>delete</mat-icon>
</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-form-field>
<mat-label>Narration</mat-label>
<textarea matInput placeholder="Narration" formControlName="narration"></textarea>
</mat-form-field>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click)="save()" [disabled]="!canSave()">
{{(voucher.id) ? 'Update' : 'Save'}}
</button>
<button mat-raised-button color="warn" (click)="newVoucher()" *ngIf="voucher.id">
New Entry
</button>
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="voucher.id" [disabled]="!canSave()">
Delete
</button>
</mat-card-actions>
<mat-card-subtitle *ngIf="voucher.id">
Created on <strong>{{voucher.creationDate | localTime}}</strong> and
Last Edited on <strong>{{voucher.lastEditDate | localTime}}</strong>
by <strong>{{voucher.user.name}}</strong>. {{(voucher.poster) ? 'Posted by ' + voucher.poster : ''}}
</mat-card-subtitle>
<mat-card-title>Other issues for the day</mat-card-title>
<mat-card-footer>
<mat-table #table [dataSource]="gridDataSource" matSort aria-label="Elements">
<!-- Source Column -->
<ng-container matColumnDef="source">
<mat-header-cell *matHeaderCellDef class="right">Source</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.source}}</mat-cell>
</ng-container>
<!-- Destination Column -->
<ng-container matColumnDef="destination">
<mat-header-cell *matHeaderCellDef class="right">Destination</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.destination}}</mat-cell>
</ng-container>
<!-- Amount Column -->
<ng-container matColumnDef="gridAmount">
<mat-header-cell *matHeaderCellDef class="right">Amount</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
</ng-container>
<!-- Load Column -->
<ng-container matColumnDef="load">
<mat-header-cell *matHeaderCellDef class="center">Load</mat-header-cell>
<mat-cell *matCellDef="let row" class="center">
<button mat-icon-button (click)="goToVoucher(row.id)">
<mat-icon>restore</mat-icon>
</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="gridColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: gridColumns;"></mat-row>
</mat-table>
</mat-card-footer>
</mat-card>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {IssueComponent} from './issue.component';
describe('IssueComponent', () => {
let component: IssueComponent;
let fixture: ComponentFixture<IssueComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [IssueComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(IssueComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,302 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {MatAutocompleteSelectedEvent, MatDialog} from '@angular/material';
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 '../journal/voucher.service';
import {Batch, Inventory, Journal, Voucher} from '../journal/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 '../purchase-return/batch.service';
import {IssueGridService} from './issue-grid.service';
import {CostCentre} from '../cost-centre/cost-centre';
import {IssueGridDataSource} from './issue-grid-datasource';
@Component({
selector: 'app-issue',
templateUrl: './issue.component.html',
styleUrls: ['./issue.component.css']
})
export class IssueComponent implements OnInit, AfterViewInit {
@ViewChild('batchElement') batchElement: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
public gridObservable = new BehaviorSubject<any[]>([]);
dataSource: IssueDataSource;
gridDataSource: IssueGridDataSource;
form: FormGroup;
sourceJournal: Journal;
destinationJournal: Journal;
voucher: Voucher;
costCentres: CostCentre[];
batch: Batch;
displayedColumns = ['product', 'batch', 'quantity', 'rate', 'amount', 'action'];
gridColumns = ['source', 'destination', 'gridAmount', 'load'];
batches: Observable<Batch[]>;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private dialog: MatDialog,
private toaster: ToasterService,
private auth: AuthService,
private ser: VoucherService,
private batchSer: BatchService,
private issueGridSer: IssueGridService
) {
this.createForm();
this.listenToBatchAutocompleteChange();
this.listenToDateChange();
}
ngOnInit() {
this.gridDataSource = new IssueGridDataSource(this.gridObservable);
this.route.data
.subscribe((data: { voucher: Voucher, costCentres: CostCentre[] }) => {
this.costCentres = data.costCentres;
this.loadVoucher(data.voucher);
});
}
ngAfterViewInit() {
this.focusBatch();
}
loadVoucher(voucher: Voucher) {
this.voucher = voucher;
this.sourceJournal = this.voucher.journals.filter(x => x.debit === -1)[0];
this.destinationJournal = this.voucher.journals.filter(x => x.debit === 1)[0];
this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
sourceCostCentre: this.sourceJournal.costCentre.id,
destinationCostCentre: this.destinationJournal.costCentre.id,
amount: this.sourceJournal.amount,
addRow: {
batch: '',
quantity: ''
},
narration: this.voucher.narration
});
this.dataSource = new IssueDataSource(this.inventoryObservable);
this.updateView();
}
focusBatch() {
setTimeout(() => {
this.batchElement.nativeElement.focus();
}, 0);
}
addRow() {
const formValue = this.form.get('addRow').value;
const quantity = +(formValue.quantity);
const isConsumption = this.voucher.journals
.filter(
x => x.debit === -1
)[0].costCentre.id === '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 old = oldFiltered.length ? oldFiltered[0] : null;
if (oldFiltered.length) {
if (old.batch.id !== this.batch.id) {
this.toaster.show('Danger', 'Product with a different batch already added');
return;
}
if (isConsumption && old.quantity + quantity > this.batch.quantityRemaining) {
this.toaster.show('Danger', 'Quantity issued cannot be more than quantity available');
return;
}
old.quantity += quantity;
} else {
if (isConsumption && quantity > this.batch.quantityRemaining) {
this.toaster.show('Danger', 'Quantity issued cannot be more than quantity available');
return;
}
this.voucher.inventories.push({
id: null,
quantity: quantity,
rate: this.batch.rate,
tax: this.batch.tax,
discount: this.batch.discount,
amount: quantity * this.batch.rate * (1 + this.batch.tax) * (1 - this.batch.discount),
product: this.batch.product,
batch: this.batch
});
}
this.resetAddRow();
this.updateView();
}
resetAddRow() {
this.form.get('addRow').reset({
batch: null,
quantity: ''
});
this.batch = null;
setTimeout(() => {
this.batchElement.nativeElement.focus();
}, 0);
}
updateView() {
this.inventoryObservable.next(this.voucher.inventories);
const amount = Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0));
this.sourceJournal.amount = amount;
this.destinationJournal.amount = amount;
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')}
});
dialogRef.afterClosed().subscribe((result: boolean | Inventory) => {
if (!result) {
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) {
return;
}
Object.assign(row, j);
this.updateView();
});
}
deleteRow(row: Inventory) {
this.voucher.inventories.splice(this.voucher.inventories.indexOf(row), 1);
this.updateView();
}
createForm() {
this.form = this.fb.group({
date: '',
sourceCostCentre: '',
destinationCostCentre: '',
amount: {value: '', disabled: true},
addRow: this.fb.group({
batch: '',
quantity: ''
}),
narration: ''
});
}
canSave() {
if (!this.voucher.id) {
return true;
} 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;
}
}
save() {
this.ser.save(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', '');
this.router.navigate(['/Issue', result.id]);
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
newVoucher() {
this.router.navigate(['/Issue']);
}
getVoucher(): Voucher {
const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.sourceJournal.costCentre.id = formModel.sourceCostCentre;
this.destinationJournal.costCentre.id = formModel.destinationCostCentre;
this.voucher.narration = formModel.narration;
return this.voucher;
}
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.error);
}
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.'}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.delete();
}
});
}
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
)
)
);
}
listenToDateChange(): void {
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)
);
}
displayBatchName(batch?: Batch): string | undefined {
return batch ? batch.name : undefined;
}
batchSelected(event: MatAutocompleteSelectedEvent): void {
this.batch = event.option.value;
}
goToVoucher(id: string) {
this.router.navigate(['/Issue', id]);
}
}

View File

@ -0,0 +1,13 @@
import {IssueModule} from './issue.module';
describe('IssueModule', () => {
let issueModule: IssueModule;
beforeEach(() => {
issueModule = new IssueModule();
});
it('should create an instance', () => {
expect(issueModule).toBeTruthy();
});
});

View File

@ -0,0 +1,84 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {
DateAdapter,
MAT_DATE_FORMATS,
MAT_DATE_LOCALE,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatDialogModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSelectModule,
MatSortModule,
MatTableModule
} from '@angular/material';
import {SharedModule} from '../shared/shared.module';
import {ReactiveFormsModule} from '@angular/forms';
import {CdkTableModule} from '@angular/cdk/table';
import {IssueRoutingModule} from './issue-routing.module';
import {IssueComponent} from './issue.component';
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {A11yModule} from '@angular/cdk/a11y';
import {IssueDialogComponent} from './issue-dialog.component';
import {FlexLayoutModule, FlexModule} from '@angular/flex-layout';
export const MY_FORMATS = {
parse: {
dateInput: 'DD-MMM-YYYY',
},
display: {
dateInput: 'DD-MMM-YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'DD-MMM-YYYY',
monthYearA11yLabel: 'MMM YYYY',
},
};
@NgModule({
imports: [
A11yModule,
CommonModule,
CdkTableModule,
FlexModule,
FlexLayoutModule,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDatepickerModule,
MatDialogModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSelectModule,
MatSortModule,
MatTableModule,
ReactiveFormsModule,
SharedModule,
IssueRoutingModule
],
declarations: [
IssueComponent,
IssueDialogComponent
],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
],
entryComponents: [
IssueDialogComponent
]
})
export class IssueModule {
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {VoucherService} from './issue.service';
describe('IssueService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [VoucherService]
});
});
it('should be created', inject([VoucherService], (service: VoucherService) => {
expect(service).toBeTruthy();
}));
});