Added: Rate Contract Module. To implement: Checking this during purchase.
This commit is contained in:
@ -68,6 +68,11 @@ const appRoutes: Routes = [
|
||||
(mod) => mod.EmployeeFunctionsModule,
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'rate-contracts',
|
||||
loadChildren: () =>
|
||||
import('./rate-contract/rate-contract.module').then((mod) => mod.RateContractModule),
|
||||
},
|
||||
{
|
||||
path: 'roles',
|
||||
loadChildren: () => import('./role/role.module').then((mod) => mod.RoleModule),
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
<a mat-menu-item routerLink="/purchases">Purchases</a>
|
||||
<a mat-menu-item routerLink="/closing-stock">Closing Stock</a>
|
||||
<a mat-menu-item routerLink="/stock-movement">Stock Movement</a>
|
||||
<a mat-menu-item routerLink="/rate-contracts">Rate Contracts</a>
|
||||
</mat-menu>
|
||||
<button mat-button [matMenuTriggerFor]="productReportMenu">Product Reports</button>
|
||||
|
||||
|
||||
13
overlord/src/app/rate-contract/rate-contact.module.spec.ts
Normal file
13
overlord/src/app/rate-contract/rate-contact.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { RateContractModule } from './rate-contract.module';
|
||||
|
||||
describe('RateContractModule', () => {
|
||||
let rateContractModule: RateContractModule;
|
||||
|
||||
beforeEach(() => {
|
||||
rateContractModule = new RateContractModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(rateContractModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { RateContractItem } from '../rate-contract-item';
|
||||
|
||||
export class RateContractDetailDatasource extends DataSource<RateContractItem> {
|
||||
constructor(private data: Observable<RateContractItem[]>) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<RateContractItem[]> {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
.example-card {
|
||||
max-width: 400px;
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Rate Contract</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"
|
||||
placeholder="Date"
|
||||
formControlName="date"
|
||||
autocomplete="off"
|
||||
#dateElement
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="60">
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
placeholder="Account"
|
||||
#accountElement
|
||||
[matAutocomplete]="autoA"
|
||||
formControlName="account"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-autocomplete
|
||||
#autoA="matAutocomplete"
|
||||
autoActiveFirstOption
|
||||
[displayWith]="displayFn"
|
||||
(optionSelected)="accountSelected($event)"
|
||||
>
|
||||
<mat-option *ngFor="let account of accounts | async" [value]="account">{{
|
||||
account.name
|
||||
}}</mat-option>
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
fxLayoutAlign="space-around start"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="validFrom"
|
||||
placeholder="Valid From"
|
||||
formControlName="validFrom"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="validFrom"></mat-datepicker-toggle>
|
||||
<mat-datepicker #validFrom></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="validTill"
|
||||
placeholder="Valid Till"
|
||||
formControlName="validTill"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="validTill"></mat-datepicker-toggle>
|
||||
<mat-datepicker #validTill></mat-datepicker>
|
||||
</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="60">
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
placeholder="Product"
|
||||
#productElement
|
||||
[matAutocomplete]="autoP"
|
||||
formControlName="product"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-autocomplete
|
||||
#autoP="matAutocomplete"
|
||||
autoActiveFirstOption
|
||||
[displayWith]="displayFn"
|
||||
(optionSelected)="productSelected($event)"
|
||||
>
|
||||
<mat-option *ngFor="let product of products | async" [value]="product">{{
|
||||
product.name
|
||||
}}</mat-option>
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="20">
|
||||
<mat-label>Price</mat-label>
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
placeholder="Price"
|
||||
formControlName="price"
|
||||
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>
|
||||
|
||||
<!-- Price Column -->
|
||||
<ng-container matColumnDef="price">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Price</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{
|
||||
row.price | 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 tabindex="-1" 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
|
||||
matAutosizeMinRows="5"
|
||||
placeholder="Narration"
|
||||
formControlName="narration"
|
||||
></textarea>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()">Delete</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
@ -0,0 +1,29 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { RateContractDetailComponent } from './rate-contract-detail.component';
|
||||
|
||||
describe('RateContractDetailComponent', () => {
|
||||
let component: RateContractDetailComponent;
|
||||
let fixture: ComponentFixture<RateContractDetailComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ReactiveFormsModule, RouterTestingModule],
|
||||
declarations: [RateContractDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RateContractDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,219 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Account } from '../../core/account';
|
||||
import { AccountService } from '../../core/account.service';
|
||||
import { Product } from '../../core/product';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ProductService } from '../../product/product.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { MathService } from '../../shared/math.service';
|
||||
import { RateContract } from '../rate-contract';
|
||||
import { RateContractItem } from '../rate-contract-item';
|
||||
import { RateContractService } from '../rate-contract.service';
|
||||
|
||||
import { RateContractDetailDatasource } from './rate-contract-detail-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-rate-contract-detail',
|
||||
templateUrl: './rate-contract-detail.component.html',
|
||||
styleUrls: ['./rate-contract-detail.component.css'],
|
||||
})
|
||||
export class RateContractDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('accountElement', { static: true }) accountElement?: ElementRef;
|
||||
@ViewChild('productElement', { static: true }) productElement?: ElementRef;
|
||||
public itemsObservable = new BehaviorSubject<RateContractItem[]>([]);
|
||||
dataSource: RateContractDetailDatasource = new RateContractDetailDatasource(this.itemsObservable);
|
||||
form: FormGroup;
|
||||
item: RateContract = new RateContract();
|
||||
|
||||
product: Product | null = null;
|
||||
|
||||
displayedColumns = ['product', 'price', 'action'];
|
||||
|
||||
accounts: Observable<Account[]>;
|
||||
products: Observable<Product[]>;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private math: MathService,
|
||||
private ser: RateContractService,
|
||||
private productSer: ProductService,
|
||||
private accountSer: AccountService,
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
account: '',
|
||||
validFrom: '',
|
||||
validTill: '',
|
||||
addRow: this.fb.group({
|
||||
product: '',
|
||||
price: '',
|
||||
}),
|
||||
narration: '',
|
||||
});
|
||||
this.accounts = (this.form.get('account') as FormControl).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
// Listen to Product Autocomplete Change
|
||||
this.products = (
|
||||
(this.form.get('addRow') as FormControl).get('product') as FormControl
|
||||
).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: RateContract };
|
||||
this.loadItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
loadItem(item: RateContract) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
date: moment(this.item.date, 'DD-MMM-YYYY').toDate(),
|
||||
validFrom: moment(this.item.validFrom, 'DD-MMM-YYYY').toDate(),
|
||||
validTill: moment(this.item.validTill, 'DD-MMM-YYYY').toDate(),
|
||||
account: this.item.vendor,
|
||||
addRow: {
|
||||
product: '',
|
||||
price: '',
|
||||
},
|
||||
narration: this.item.narration,
|
||||
});
|
||||
this.dataSource = new RateContractDetailDatasource(this.itemsObservable);
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
if (this.accountElement) {
|
||||
this.accountElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
addRow() {
|
||||
const formValue = (this.form.get('addRow') as FormControl).value;
|
||||
const price = this.math.parseAmount(formValue.price, 2);
|
||||
if (this.product === null || price <= 0) {
|
||||
return;
|
||||
}
|
||||
const oldFiltered = this.item.items.filter(
|
||||
(x) => x.product.id === (this.product as Product).id,
|
||||
);
|
||||
if (oldFiltered.length) {
|
||||
this.toaster.show('Danger', 'Product already added');
|
||||
return;
|
||||
}
|
||||
this.item.items.push(
|
||||
new RateContractItem({
|
||||
price,
|
||||
product: this.product,
|
||||
}),
|
||||
);
|
||||
this.resetAddRow();
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
resetAddRow() {
|
||||
(this.form.get('addRow') as FormControl).reset({
|
||||
product: null,
|
||||
price: '',
|
||||
});
|
||||
this.product = null;
|
||||
setTimeout(() => {
|
||||
if (this.productElement) {
|
||||
this.productElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(item?: Account | Product): string {
|
||||
return item ? item.name : '';
|
||||
}
|
||||
|
||||
updateView() {
|
||||
this.itemsObservable.next(this.item.items);
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
(this.form.get('account') as FormControl).setValue(event.option.value);
|
||||
}
|
||||
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.product = event.option.value;
|
||||
}
|
||||
|
||||
deleteRow(row: RateContractItem) {
|
||||
this.item.items.splice(this.item.items.indexOf(row), 1);
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/rate-contracts');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/rate-contracts');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: 'Delete RateContract?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): RateContract {
|
||||
const formModel = this.form.value;
|
||||
this.item.date = moment(formModel.date).format('DD-MMM-YYYY');
|
||||
this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY');
|
||||
this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY');
|
||||
this.item.vendor = formModel.account;
|
||||
this.item.narration = formModel.narration;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
13
overlord/src/app/rate-contract/rate-contract-item.ts
Normal file
13
overlord/src/app/rate-contract/rate-contract-item.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Product } from '../core/product';
|
||||
|
||||
export class RateContractItem {
|
||||
id: string | undefined;
|
||||
product: Product;
|
||||
price: number;
|
||||
|
||||
public constructor(init?: Partial<RateContractItem>) {
|
||||
this.product = new Product();
|
||||
this.price = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { RateContractListResolver } from './rate-contract-list-resolver.service';
|
||||
|
||||
describe('RateContractListResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule, RouterTestingModule],
|
||||
providers: [RateContractListResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject(
|
||||
[RateContractListResolver],
|
||||
(service: RateContractListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { RateContract } from './rate-contract';
|
||||
import { RateContractService } from './rate-contract.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RateContractListResolver implements Resolve<RateContract[]> {
|
||||
constructor(private ser: RateContractService) {}
|
||||
|
||||
resolve(): Observable<RateContract[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
||||
import { MatSort, Sort } from '@angular/material/sort';
|
||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { RateContract } from '../rate-contract';
|
||||
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
const compare = (a: string | number, b: string | number, isAsc: boolean) =>
|
||||
(a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
export class RateContractListDatasource extends DataSource<RateContract> {
|
||||
constructor(
|
||||
public data: RateContract[],
|
||||
private paginator?: MatPaginator,
|
||||
private sort?: MatSort,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<RateContract[]> {
|
||||
const dataMutations: (
|
||||
| Observable<RateContract[]>
|
||||
| EventEmitter<PageEvent>
|
||||
| EventEmitter<Sort>
|
||||
)[] = [observableOf(this.data)];
|
||||
if (this.paginator) {
|
||||
dataMutations.push((this.paginator as MatPaginator).page);
|
||||
}
|
||||
if (this.sort) {
|
||||
dataMutations.push((this.sort as MatSort).sortChange);
|
||||
}
|
||||
|
||||
// Set the paginators length
|
||||
if (this.paginator) {
|
||||
this.paginator.length = this.data.length;
|
||||
}
|
||||
|
||||
return merge(...dataMutations).pipe(
|
||||
map(() => this.getPagedData(this.getSortedData([...this.data]))),
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
|
||||
private getPagedData(data: RateContract[]) {
|
||||
if (this.paginator === undefined) {
|
||||
return data;
|
||||
}
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: RateContract[]) {
|
||||
if (this.sort === undefined) {
|
||||
return data;
|
||||
}
|
||||
if (!this.sort.active || this.sort.direction === '') {
|
||||
return data;
|
||||
}
|
||||
|
||||
const sort = this.sort as MatSort;
|
||||
return data.sort((a, b) => {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch (sort.active) {
|
||||
case 'vendor':
|
||||
return compare(a.vendor.name, b.vendor.name, isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Rate Contracts</mat-card-title>
|
||||
<a mat-button [routerLink]="['/rate-contracts', 'new']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||
<!-- Vendor Column -->
|
||||
<ng-container matColumnDef="vendor">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Vendor</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/rate-contracts', row.id]"
|
||||
>{{ row.vendor.name }} // {{ row.date }}</a
|
||||
></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Validity Column -->
|
||||
<ng-container matColumnDef="validity">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Validity</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"> {{ row.validFrom }} - {{ row.validTill }} </mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Products Column -->
|
||||
<ng-container matColumnDef="products">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Products</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<ul>
|
||||
<li *ngFor="let item of row.items">
|
||||
{{ item.product.name }} @ {{ item.price | currency: 'INR' }}
|
||||
</li>
|
||||
</ul>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator
|
||||
#paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]"
|
||||
>
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,24 @@
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { RateContractListComponent } from './rate-contract-list.component';
|
||||
|
||||
describe('RateContractListComponent', () => {
|
||||
let component: RateContractListComponent;
|
||||
let fixture: ComponentFixture<RateContractListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [RouterTestingModule],
|
||||
declarations: [RateContractListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(RateContractListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,33 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { RateContract } from '../rate-contract';
|
||||
|
||||
import { RateContractListDatasource } from './rate-contract-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-rate-contract-list',
|
||||
templateUrl: './rate-contract-list.component.html',
|
||||
styleUrls: ['./rate-contract-list.component.css'],
|
||||
})
|
||||
export class RateContractListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort?: MatSort;
|
||||
list: RateContract[] = [];
|
||||
dataSource: RateContractListDatasource = new RateContractListDatasource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['vendor', 'validity', 'products'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: RateContract[] };
|
||||
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new RateContractListDatasource(this.list, this.paginator, this.sort);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { RateContractResolver } from './rate-contract-resolver.service';
|
||||
|
||||
describe('RateContractResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule, RouterTestingModule],
|
||||
providers: [RateContractResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([RateContractResolver], (service: RateContractResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { RateContract } from './rate-contract';
|
||||
import { RateContractService } from './rate-contract.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RateContractResolver implements Resolve<RateContract> {
|
||||
constructor(private ser: RateContractService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<RateContract> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { RateContractRoutingModule } from './rate-contract-routing.module';
|
||||
|
||||
describe('RateContractRoutingModule', () => {
|
||||
let rateContractRoutingModule: RateContractRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
rateContractRoutingModule = new RateContractRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(rateContractRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,53 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { RateContractDetailComponent } from './rate-contract-detail/rate-contract-detail.component';
|
||||
import { RateContractListResolver } from './rate-contract-list-resolver.service';
|
||||
import { RateContractListComponent } from './rate-contract-list/rate-contract-list.component';
|
||||
import { RateContractResolver } from './rate-contract-resolver.service';
|
||||
|
||||
const rateContractRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: RateContractListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Rate Contracts',
|
||||
},
|
||||
resolve: {
|
||||
list: RateContractListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: RateContractDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Rate Contracts',
|
||||
},
|
||||
resolve: {
|
||||
item: RateContractResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: RateContractDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Rate Contracts',
|
||||
},
|
||||
resolve: {
|
||||
item: RateContractResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(rateContractRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [RateContractListResolver, RateContractResolver],
|
||||
})
|
||||
export class RateContractRoutingModule {}
|
||||
71
overlord/src/app/rate-contract/rate-contract.module.ts
Normal file
71
overlord/src/app/rate-contract/rate-contract.module.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import {
|
||||
DateAdapter,
|
||||
MAT_DATE_FORMATS,
|
||||
MAT_DATE_LOCALE,
|
||||
MatNativeDateModule,
|
||||
} from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { RateContractDetailComponent } from './rate-contract-detail/rate-contract-detail.component';
|
||||
import { RateContractListComponent } from './rate-contract-list/rate-contract-list.component';
|
||||
import { RateContractRoutingModule } from './rate-contract-routing.module';
|
||||
|
||||
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: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDividerModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSortModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
RateContractRoutingModule,
|
||||
MatDatepickerModule,
|
||||
MatAutocompleteModule,
|
||||
],
|
||||
declarations: [RateContractListComponent, RateContractDetailComponent],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
|
||||
],
|
||||
})
|
||||
export class RateContractModule {}
|
||||
17
overlord/src/app/rate-contract/rate-contract.service.spec.ts
Normal file
17
overlord/src/app/rate-contract/rate-contract.service.spec.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RateContractService } from './rate-contract.service';
|
||||
|
||||
describe('RateContractService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientModule],
|
||||
providers: [RateContractService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([RateContractService], (service: RateContractService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
58
overlord/src/app/rate-contract/rate-contract.service.ts
Normal file
58
overlord/src/app/rate-contract/rate-contract.service.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
import { RateContract } from './rate-contract';
|
||||
|
||||
const url = '/api/rate-contracts';
|
||||
const serviceName = 'RateContractService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RateContractService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string | null): Observable<RateContract> {
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<RateContract>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`)),
|
||||
) as Observable<RateContract>;
|
||||
}
|
||||
|
||||
list(): Observable<RateContract[]> {
|
||||
return this.http
|
||||
.get<RateContract[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<RateContract[]>;
|
||||
}
|
||||
|
||||
save(rateContract: RateContract): Observable<RateContract> {
|
||||
return this.http
|
||||
.post<RateContract>(`${url}`, rateContract)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<RateContract>;
|
||||
}
|
||||
|
||||
update(rateContract: RateContract): Observable<RateContract> {
|
||||
return this.http
|
||||
.put<RateContract>(`${url}/${rateContract.id}`, rateContract)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<RateContract>;
|
||||
}
|
||||
|
||||
saveOrUpdate(rateContract: RateContract): Observable<RateContract> {
|
||||
if (!rateContract.id) {
|
||||
return this.save(rateContract);
|
||||
}
|
||||
return this.update(rateContract);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<RateContract> {
|
||||
return this.http
|
||||
.delete<RateContract>(`${url}/${id}`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<RateContract>;
|
||||
}
|
||||
}
|
||||
30
overlord/src/app/rate-contract/rate-contract.ts
Normal file
30
overlord/src/app/rate-contract/rate-contract.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Account } from '../core/account';
|
||||
import { User } from '../core/user';
|
||||
|
||||
import { RateContractItem } from './rate-contract-item';
|
||||
|
||||
export class RateContract {
|
||||
id: string | undefined;
|
||||
date: string;
|
||||
vendor: Account;
|
||||
validFrom: string;
|
||||
validTill: string;
|
||||
narration: string;
|
||||
creationDate: string;
|
||||
lastEditDate: string;
|
||||
user: User;
|
||||
items: RateContractItem[];
|
||||
|
||||
public constructor(init?: Partial<RateContract>) {
|
||||
this.date = '';
|
||||
this.vendor = new Account();
|
||||
this.validFrom = '';
|
||||
this.validTill = '';
|
||||
this.narration = '';
|
||||
this.creationDate = '';
|
||||
this.lastEditDate = '';
|
||||
this.user = new User();
|
||||
this.items = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user