Renamed Report permissions to make more sense

Removed the void and reprints report and added it to the bill settlement report
updated the import to add a new sql to be executed later to update the settlements and report permission names
Export works on all reports
This commit is contained in:
Amritanshu
2019-08-25 15:08:59 +05:30
parent 05860fb0b9
commit 6d0f30503a
98 changed files with 527 additions and 1079 deletions

View File

@ -0,0 +1,18 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
import { TaxReportItem } from './tax-report';
export class TaxReportDatasource extends DataSource<TaxReportItem> {
constructor(public data: TaxReportItem[]) {
super();
}
connect(): Observable<TaxReportItem[]> {
return observableOf(this.data);
}
disconnect() {
}
}

View File

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

View File

@ -0,0 +1,20 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/internal/Observable';
import {TaxReport} from './tax-report';
import {TaxReportService} from './tax-report.service';
@Injectable({
providedIn: 'root'
})
export class TaxReportResolver implements Resolve<TaxReport> {
constructor(private ser: TaxReportService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<TaxReport> {
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return this.ser.get(startDate, finishDate);
}
}

View File

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

View File

@ -0,0 +1,37 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { TaxReportResolver } from './tax-report-resolver.service';
import { AuthGuard } from '../auth/auth-guard.service';
import { TaxReportComponent } from './tax-report.component';
const taxReportRoutes: Routes = [
{
path: '',
component: TaxReportComponent,
canActivate: [AuthGuard],
data: {
permission: 'Tax Report'
},
resolve: {
info: TaxReportResolver
},
runGuardsAndResolvers: 'always'
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(taxReportRoutes)
],
exports: [
RouterModule
],
providers: [
TaxReportResolver
]
})
export class TaxReportRoutingModule {
}

View File

@ -0,0 +1,4 @@
.right {
display: flex;
justify-content: flex-end;
}

View File

@ -0,0 +1,57 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Tax Report</mat-card-title>
<button mat-button mat-icon-button (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
fxLayoutAlign="space-around start">
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
formControlName="startDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
formControlName="finishDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
<mat-datepicker #finishDate></mat-datepicker>
</mat-form-field>
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
</div>
</form>
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
</ng-container>
<!-- Tax Rate Column -->
<ng-container matColumnDef="taxRate">
<mat-header-cell *matHeaderCellDef class="right">Rate</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.taxRate | percent:'1.2-2'}}</mat-cell>
</ng-container>
<!-- Sale Amount Column -->
<ng-container matColumnDef="saleAmount">
<mat-header-cell *matHeaderCellDef class="right">Sale</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.saleAmount | currency:'INR'}}</mat-cell>
</ng-container>
<!-- Tax Amount Column -->
<ng-container matColumnDef="taxAmount">
<mat-header-cell *matHeaderCellDef class="right">Tax</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</mat-card-content>
</mat-card>

View File

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

View File

@ -0,0 +1,84 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { TaxReportDatasource } from './tax-report-datasource';
import { TaxReport } from './tax-report';
import { ToCsvService } from '../shared/to-csv.service';
@Component({
selector: 'app-tax-report',
templateUrl: './tax-report.component.html',
styleUrls: ['./tax-report.component.css']
})
export class TaxReportComponent implements OnInit {
dataSource: TaxReportDatasource;
form: FormGroup;
info: TaxReport;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'taxRate', 'saleAmount', 'taxAmount'];
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toCsv: ToCsvService
) {
this.createForm();
}
ngOnInit() {
this.route.data
.subscribe((data: { info: TaxReport }) => {
this.info = data.info;
this.form.setValue({
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
});
this.dataSource = new TaxReportDatasource(this.info.amounts);
});
}
show() {
const info = this.getInfo();
this.router.navigate(['tax-report'], {
queryParams: {
startDate: info.startDate,
finishDate: info.finishDate
}
});
}
createForm() {
this.form = this.fb.group({
startDate: '',
finishDate: ''
});
}
getInfo(): TaxReport {
const formModel = this.form.value;
return {
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY')
};
}
exportCsv() {
const headers = {
Name: 'name',
Amount: 'amount'
};
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'tax-report.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}

View File

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

View File

@ -0,0 +1,61 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
import { SharedModule} from '../shared/shared.module';
import { ReactiveFormsModule } from '@angular/forms';
import { CdkTableModule } from '@angular/cdk/table';
import { TaxReportRoutingModule } from './tax-report-routing.module';
import { TaxReportComponent } from './tax-report.component';
import { MomentDateAdapter } from '@angular/material-moment-adapter';
import { A11yModule } from '@angular/cdk/a11y';
import { FlexLayoutModule } 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,
FlexLayoutModule,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatTableModule,
ReactiveFormsModule,
SharedModule,
TaxReportRoutingModule
],
declarations: [
TaxReportComponent
],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
]
})
export class TaxReportModule {
}

View File

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

View File

@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { TaxReport } from './tax-report';
import { ErrorLoggerService } from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/tax-report';
const serviceName = 'TaxReportService';
@Injectable({
providedIn: 'root'
})
export class TaxReportService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(startDate: string, finishDate): Observable<TaxReport> {
const options = {params: new HttpParams()};
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return <Observable<TaxReport>>this.http.get<TaxReport>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'get'))
);
}
}

View File

@ -0,0 +1,12 @@
export class TaxReportItem {
name: string;
taxRate: number;
saleAmount: number;
amount: number;
}
export class TaxReport {
startDate: string;
finishDate: string;
amounts?: TaxReportItem[];
}