Moved the batch integrity report from settings to its own report in products with permission of product ledger.

It also automatically fixes the issue prices.
This commit is contained in:
2021-09-24 14:40:51 +05:30
parent b1557bef88
commit 6d0d95070b
27 changed files with 613 additions and 200 deletions
@@ -0,0 +1,16 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
import { BatchIntegrity } from './batch-integrity';
export class BatchIntegrityReportDatasource extends DataSource<BatchIntegrity> {
constructor(public data: BatchIntegrity[]) {
super();
}
connect(): Observable<BatchIntegrity[]> {
return observableOf(this.data);
}
disconnect() {}
}
@@ -0,0 +1,13 @@
import { BatchIntegrityReportRoutingModule } from './batch-integrity-report-routing.module';
describe('BatchIntegrityRoutingModule', () => {
let batchIntegrityRoutingModule: BatchIntegrityReportRoutingModule;
beforeEach(() => {
batchIntegrityRoutingModule = new BatchIntegrityReportRoutingModule();
});
it('should create an instance', () => {
expect(batchIntegrityRoutingModule).toBeTruthy();
});
});
@@ -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 { BatchIntegrityReportComponent } from './batch-integrity-report.component';
import { BatchIntegrityResolverService } from './batch-integrity-resolver.service';
const batchIntegrityRoutes: Routes = [
{
path: '',
component: BatchIntegrityReportComponent,
canActivate: [AuthGuard],
data: {
permission: 'Product Ledger',
},
resolve: {
info: BatchIntegrityResolverService,
},
runGuardsAndResolvers: 'always',
},
];
@NgModule({
imports: [CommonModule, RouterModule.forChild(batchIntegrityRoutes)],
exports: [RouterModule],
providers: [BatchIntegrityResolverService],
})
export class BatchIntegrityReportRoutingModule {}
@@ -0,0 +1,19 @@
.right {
display: flex;
justify-content: flex-end;
}
.my-margin {
margin: 0 12px;
}
.selected {
background: #fff3cd;
}
.unposted {
background: #f8d7da;
}
.mat-column-date,
.mat-column-voucherType {
max-width: 100px;
}
@@ -0,0 +1,34 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>BatchReport</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<mat-table [dataSource]="dataSource" aria-label="Elements">
<!-- Batch Column -->
<ng-container matColumnDef="batch">
<mat-header-cell *matHeaderCellDef>Batch</mat-header-cell>
<mat-cell *matCellDef="let row">
{{ row.product }} dated {{ row.date }} @ {{ row.price | currency: 'INR' }} is showing
{{ row.showing }} instead of {{ row.actual }}
</mat-cell>
</ng-container>
<!-- Details Column -->
<ng-container matColumnDef="details">
<mat-header-cell *matHeaderCellDef>Details</mat-header-cell>
<mat-cell *matCellDef="let row">
<ul>
<li *ngFor="let detail of row.details">
<a [routerLink]="detail.url">{{ detail.type }}</a> on {{ detail.date }} of
{{ detail.quantity }} @
{{ detail.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-card-content>
</mat-card>
@@ -0,0 +1,29 @@
import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { BatchIntegrityReportComponent } from './batch-integrity-report.component';
describe('BatchIntegrityComponent', () => {
let component: BatchIntegrityReportComponent;
let fixture: ComponentFixture<BatchIntegrityReportComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule, RouterTestingModule],
declarations: [BatchIntegrityReportComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(BatchIntegrityReportComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,30 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BatchIntegrity } from './batch-integrity';
import { BatchIntegrityReportDatasource } from './batch-integrity-report-datasource';
@Component({
selector: 'app-batch-integrity',
templateUrl: './batch-integrity-report.component.html',
styleUrls: ['./batch-integrity-report.component.css'],
})
export class BatchIntegrityReportComponent implements OnInit {
info: BatchIntegrity[] = [];
dataSource: BatchIntegrityReportDatasource = new BatchIntegrityReportDatasource(this.info);
displayedColumns = ['batch', 'details'];
constructor(private route: ActivatedRoute, private router: Router) {}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { info: BatchIntegrity[] };
this.info = data.info;
this.dataSource = new BatchIntegrityReportDatasource(this.info);
});
}
refresh() {
this.router.navigate([]);
}
}
@@ -0,0 +1,13 @@
import { BatchIntegrityReportModule } from './batch-integrity-report.module';
describe('BatchIntegrityModule', () => {
let batchIntegrityModule: BatchIntegrityReportModule;
beforeEach(() => {
batchIntegrityModule = new BatchIntegrityReportModule();
});
it('should create an instance', () => {
expect(batchIntegrityModule).toBeTruthy();
});
});
@@ -0,0 +1,73 @@
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 { 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 { MatExpansionModule } from '@angular/material/expansion';
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 { MatRadioModule } from '@angular/material/radio';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule } from '@angular/material/table';
import { SharedModule } from '../shared/shared.module';
import { BatchIntegrityReportRoutingModule } from './batch-integrity-report-routing.module';
import { BatchIntegrityReportComponent } from './batch-integrity-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,
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatRadioModule,
MatSortModule,
MatTableModule,
SharedModule,
BatchIntegrityReportRoutingModule,
MatExpansionModule,
MatDatepickerModule,
ReactiveFormsModule,
FlexLayoutModule,
],
declarations: [BatchIntegrityReportComponent],
providers: [
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
],
})
export class BatchIntegrityReportModule {}
@@ -0,0 +1,20 @@
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { BatchIntegrityReportService } from './batch-integrity-report.service';
describe('BatchIntegrityService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [BatchIntegrityReportService],
});
});
it('should be created', inject(
[BatchIntegrityReportService],
(service: BatchIntegrityReportService) => {
expect(service).toBeTruthy();
},
));
});
@@ -0,0 +1,27 @@
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 { BatchIntegrity } from './batch-integrity';
const url = '/api/batchIntegrity';
const serviceName = 'BatchIntegrityReportService';
@Injectable({
providedIn: 'root',
})
export class BatchIntegrityReportService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
batchIntegrity(): Observable<BatchIntegrity[]> {
const url = '/api/batch-integrity';
return this.http
.post<BatchIntegrity[]>(url, {})
.pipe(catchError(this.log.handleError(serviceName, 'batchIntegrity'))) as Observable<
BatchIntegrity[]
>;
}
}
@@ -0,0 +1,20 @@
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { BatchIntegrityResolverService } from './batch-integrity-resolver.service';
describe('BatchIntegrityResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [BatchIntegrityResolverService],
});
});
it('should be created', inject(
[BatchIntegrityResolverService],
(service: BatchIntegrityResolverService) => {
expect(service).toBeTruthy();
},
));
});
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { BatchIntegrity } from './batch-integrity';
import { BatchIntegrityReportService } from './batch-integrity-report.service';
@Injectable({
providedIn: 'root',
})
export class BatchIntegrityResolverService implements Resolve<BatchIntegrity[]> {
constructor(private ser: BatchIntegrityReportService) {}
resolve(route: ActivatedRouteSnapshot): Observable<BatchIntegrity[]> {
return this.ser.batchIntegrity();
}
}
@@ -0,0 +1,35 @@
export class BatchIntegrity {
product: string;
date: string;
price: number;
showing: number;
actual: number;
details: BatchDetail[];
public constructor(init?: Partial<BatchIntegrity>) {
this.product = '';
this.date = '';
this.price = 0;
this.showing = 0;
this.actual = 0;
this.details = [];
Object.assign(this, init);
}
}
export class BatchDetail {
date: string;
type: string;
url: string[];
quantity: number;
price: number;
public constructor(init?: Partial<BatchDetail>) {
this.date = '';
this.type = '';
this.url = [];
this.quantity = 0;
this.price = 0;
Object.assign(this, init);
}
}