DB Integrity checks for batch integrity and also updates quantities when it can.

This commit is contained in:
2021-09-21 09:54:11 +05:30
parent 6212eead20
commit b1557bef88
5 changed files with 206 additions and 15 deletions

View File

@ -0,0 +1,44 @@
export class BatchDate {
product: string;
batchDate: string;
voucherDate: string;
type: string;
public constructor(init?: Partial<BatchDate>) {
this.product = '';
this.batchDate = '';
this.voucherDate = '';
this.type = '';
Object.assign(this, init);
}
}
export class BatchDetail {
date: string;
type: string;
quantity: number;
public constructor(init?: Partial<BatchDetail>) {
this.date = '';
this.type = '';
this.quantity = 0;
Object.assign(this, init);
}
}
export class IntegrityBatch {
product: string;
date: string;
showing: number;
actual: number;
details: BatchDetail[];
public constructor(init?: Partial<IntegrityBatch>) {
this.product = '';
this.date = '';
this.showing = 0;
this.actual = 0;
this.details = [];
Object.assign(this, init);
}
}

View File

@ -303,9 +303,50 @@
<mat-tab label="Integrity Check">
<mat-card>
<mat-card-content>
<button mat-raised-button color="warn" (click)="checkIntegrity()" fxFlex="100">
Integrity Check
</button>
<div
fxLayout="row"
fxLayoutAlign="space-around start"
fxLayout.lt-md="column"
fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"
>
<button mat-raised-button color="warn" (click)="checkIntegrity()" fxFlex="100">
Integrity Check
</button>
</div>
<div
fxLayout="row"
fxLayoutAlign="space-around start"
fxLayout.lt-md="column"
fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"
>
<ul>
<li *ngFor="let batch of batches">
Batch of {{ batch.product }} dated {{ batch.date }} is showing
{{ batch.showing }} instead of {{ batch.actual }}
<ul>
<li *ngFor="let detail of batch.details">
{{ detail.type }} of {{ detail.quantity }} on {{ detail.date }}
</li>
</ul>
</li>
</ul>
</div>
<div
fxLayout="row"
fxLayoutAlign="space-around start"
fxLayout.lt-md="column"
fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"
>
<ul>
<li *ngFor="let batch of batchDates">
{{ batch.type }} of {{ batch.product }} dated {{ batch.batchDate }} on
{{ batch.voucherDate }}
</li>
</ul>
</div>
</mat-card-content>
</mat-card>
</mat-tab>

View File

@ -15,6 +15,7 @@ import { ToasterService } from '../core/toaster.service';
import { ProductService } from '../product/product.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { BatchDate, IntegrityBatch } from './integrity-batch';
import { LockDataSource } from './lock-datasource';
import { LockInfo } from './lock-info';
import { SettingsService } from './settings.service';
@ -44,6 +45,8 @@ export class SettingsComponent implements OnInit {
product: Product = new Product();
products: Observable<Product[]>;
batches: IntegrityBatch[] = [];
batchDates: BatchDate[] = [];
maintenance: { enabled: boolean; user: string };
displayedColumns = ['index', 'validity', 'voucherTypes', 'accountTypes', 'lock', 'action'];
@ -290,7 +293,9 @@ export class SettingsComponent implements OnInit {
checkIntegrity() {
this.ser.checkDatabaseIntegrity().subscribe(
() => {
(x) => {
this.batches = x.batches;
this.batchDates = x.batchDates;
this.toaster.show('Success', 'Database checked, it is fine!');
},
(error) => {

View File

@ -6,6 +6,7 @@ import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { Product } from '../core/product';
import { BatchDate, IntegrityBatch } from './integrity-batch';
import { LockInfo } from './lock-info';
const serviceName = 'SettingsService';
@ -82,12 +83,21 @@ export class SettingsService {
}>;
}
checkDatabaseIntegrity(): Observable<{ attendanceCount: number }> {
checkDatabaseIntegrity(): Observable<{
attendanceCount: number;
batches: IntegrityBatch[];
batchDates: BatchDate[];
}> {
const url = '/api/db-integrity';
return this.http
.post<{ attendanceCount: number }>(url, {})
.post<{ attendanceCount: number; batches: IntegrityBatch[]; batchDates: BatchDate[] }>(
url,
{},
)
.pipe(catchError(this.log.handleError(serviceName, 'checkDatabaseIntegrity'))) as Observable<{
attendanceCount: number;
batches: IntegrityBatch[];
batchDates: BatchDate[];
}>;
}
}