Initial Commit

This commit is contained in:
2021-01-05 13:02:52 +05:30
commit ec992df1da
520 changed files with 38712 additions and 0 deletions

View File

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

View File

@ -0,0 +1,10 @@
export class DiscountReportItem {
name: string;
amount: number;
public constructor(init?: Partial<DiscountReportItem>) {
this.name = '';
this.amount = 0;
Object.assign(this, init);
}
}

View File

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

View File

@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { DiscountReport } from './discount-report';
import { DiscountReportService } from './discount-report.service';
@Injectable({
providedIn: 'root',
})
export class DiscountReportResolver implements Resolve<DiscountReport> {
constructor(private ser: DiscountReportService) {}
resolve(route: ActivatedRouteSnapshot): Observable<DiscountReport> {
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 { DiscountReportRoutingModule } from './discount-report-routing.module';
describe('DiscountReportRoutingModule', () => {
let discountReportRoutingModule: DiscountReportRoutingModule;
beforeEach(() => {
discountReportRoutingModule = new DiscountReportRoutingModule();
});
it('should create an instance', () => {
expect(discountReportRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,30 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '../auth/auth-guard.service';
import { DiscountReportResolver } from './discount-report-resolver.service';
import { DiscountReportComponent } from './discount-report.component';
const discountReportRoutes: Routes = [
{
path: '',
component: DiscountReportComponent,
canActivate: [AuthGuard],
data: {
permission: 'Discount Report',
},
resolve: {
info: DiscountReportResolver,
},
runGuardsAndResolvers: 'always',
},
];
@NgModule({
imports: [CommonModule, RouterModule.forChild(discountReportRoutes)],
exports: [RouterModule],
providers: [DiscountReportResolver],
})
export class DiscountReportRoutingModule {}

View File

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

View File

@ -0,0 +1,64 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Discount Report</mat-card-title>
<span class="spacer"></span>
<button mat-button mat-icon-button (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
<button mat-button mat-icon-button (click)="print()">
<mat-icon>print</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>
<!-- 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>
<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,26 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { DiscountReportComponent } from './discount-report.component';
describe('DiscountReportComponent', () => {
let component: DiscountReportComponent;
let fixture: ComponentFixture<DiscountReportComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [DiscountReportComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(DiscountReportComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,98 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { ToasterService } from '../core/toaster.service';
import { ToCsvService } from '../shared/to-csv.service';
import { DiscountReport } from './discount-report';
import { DiscountReportDataSource } from './discount-report-datasource';
import { DiscountReportService } from './discount-report.service';
@Component({
selector: 'app-discount-report',
templateUrl: './discount-report.component.html',
styleUrls: ['./discount-report.component.css'],
})
export class DiscountReportComponent implements OnInit {
info: DiscountReport = new DiscountReport();
dataSource: DiscountReportDataSource = new DiscountReportDataSource(this.info.amounts);
form: FormGroup;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'amount'];
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toCsv: ToCsvService,
private toaster: ToasterService,
private ser: DiscountReportService,
) {
// Create form
this.form = this.fb.group({
startDate: '',
finishDate: '',
});
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { info: DiscountReport };
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 DiscountReportDataSource(this.info.amounts);
});
}
show() {
const info = this.getInfo();
this.router.navigate(['discount-report'], {
queryParams: {
startDate: info.startDate,
finishDate: info.finishDate,
},
});
}
getInfo(): DiscountReport {
const formModel = this.form.value;
return new DiscountReport({
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
});
}
print() {
this.ser.print(this.info.startDate, this.info.finishDate).subscribe(
() => {
this.toaster.show('', 'Successfully Printed');
},
(error) => {
this.toaster.show('Error', error);
},
);
}
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', 'discount-report.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}

View File

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

View File

@ -0,0 +1,65 @@
import { A11yModule } from '@angular/cdk/a11y';
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 {
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 { DiscountReportRoutingModule } from './discount-report-routing.module';
import { DiscountReportComponent } from './discount-report.component';
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,
DiscountReportRoutingModule,
],
declarations: [DiscountReportComponent],
providers: [
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
],
})
export class DiscountReportModule {}

View File

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

View File

@ -0,0 +1,45 @@
import { HttpClient, HttpParams } 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 { DiscountReport } from './discount-report';
const url = '/api/discount-report';
const serviceName = 'DiscountReportService';
@Injectable({
providedIn: 'root',
})
export class DiscountReportService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(startDate: string | null, finishDate: string | null): Observable<DiscountReport> {
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 this.http
.get<DiscountReport>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'get'))) as Observable<DiscountReport>;
}
print(startDate: string | null, finishDate: string | null): Observable<boolean> {
const printUrl = `${url}/print`;
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 this.http
.get<boolean>(printUrl, options)
.pipe(catchError(this.log.handleError(serviceName, 'print'))) as Observable<boolean>;
}
}

View File

@ -0,0 +1,14 @@
import { DiscountReportItem } from './discount-report-item';
export class DiscountReport {
startDate: string;
finishDate: string;
amounts: DiscountReportItem[];
public constructor(init?: Partial<DiscountReport>) {
this.startDate = '';
this.finishDate = '';
this.amounts = [];
Object.assign(this, init);
}
}