Feature: Added product Stock Keeping Units to prevent duplicate products. A lot of refactoring because of this.
Removed: Reset Stock as it was never used and don't think it is even needed with this new batch system. Fix: Incentive update was not working
This commit is contained in:
1 parent
4f907e965b
commit
1647d356c9
71 files changed
+1272
-904
No files matched your search
@@ -232,74 +232,6 @@
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</mat-tab>
|
||||
<mat-tab label="Reset Stock">
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<form
|
||||
[formGroup]="resetStockForm"
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex="20">
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="resetDate"
|
||||
(focus)="resetDate.open()"
|
||||
placeholder="Reset Date"
|
||||
formControlName="resetDate"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="resetDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #resetDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="20">
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="stockDate"
|
||||
(focus)="stockDate.open()"
|
||||
placeholder="Stock Date"
|
||||
formControlName="stockDate"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="stockDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #stockDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="40">
|
||||
<mat-label>Product</mat-label>
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
placeholder="Product"
|
||||
[matAutocomplete]="auto"
|
||||
formControlName="product"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-autocomplete
|
||||
#auto="matAutocomplete"
|
||||
autoActiveFirstOption
|
||||
[displayWith]="displayFn"
|
||||
(optionSelected)="selectedProduct($event)"
|
||||
>
|
||||
<mat-option *ngFor="let product of products | async" [value]="product">{{
|
||||
product.name
|
||||
}}</mat-option>
|
||||
</mat-autocomplete>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="10">
|
||||
<mat-label>Quantity</mat-label>
|
||||
<input matInput placehnewer="Quantity" formControlName="quantity" autocomplete="off" />
|
||||
</mat-form-field>
|
||||
|
||||
<button mat-raised-button color="warn" (click)="confirmResetStock()" fxFlex="10">
|
||||
Rebase
|
||||
</button>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</mat-tab>
|
||||
<mat-tab label="Maintenance Mode">
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, 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 { BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { AccountType } from '../core/account-type';
|
||||
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 { LockDataSource } from './lock-datasource';
|
||||
@@ -40,10 +36,6 @@ export class SettingsComponent implements OnInit {
|
||||
|
||||
rebaseDataForm: FormGroup;
|
||||
|
||||
resetStockForm: FormGroup;
|
||||
product: Product = new Product();
|
||||
products: Observable<Product[]>;
|
||||
|
||||
maintenance: { enabled: boolean; user: string };
|
||||
|
||||
displayedColumns = ['index', 'validity', 'voucherTypes', 'accountTypes', 'lock', 'action'];
|
||||
@@ -58,7 +50,6 @@ export class SettingsComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
public auth: AuthService,
|
||||
private ser: SettingsService,
|
||||
private productSer: ProductService,
|
||||
) {
|
||||
const startDate = moment().date(1);
|
||||
const finishDate = moment().date(startDate.daysInMonth());
|
||||
@@ -82,21 +73,7 @@ export class SettingsComponent implements OnInit {
|
||||
date: moment(),
|
||||
});
|
||||
|
||||
this.resetStockForm = this.fb.group({
|
||||
resetDate: moment(),
|
||||
stockDate: moment(),
|
||||
product: null,
|
||||
quantity: 0,
|
||||
});
|
||||
this.listenToLockForm();
|
||||
// Listen to Product Changes
|
||||
this.products = (this.resetStockForm.get('product') as FormControl).valueChanges.pipe(
|
||||
startWith(''),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocomplete(x))),
|
||||
);
|
||||
this.maintenance = { enabled: false, user: '' };
|
||||
this.version = environment.version;
|
||||
}
|
||||
@@ -246,48 +223,6 @@ export class SettingsComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
displayFn(product?: Product): string {
|
||||
return product ? product.name : '';
|
||||
}
|
||||
|
||||
selectedProduct(event: MatAutocompleteSelectedEvent): void {
|
||||
this.product = event.option.value;
|
||||
}
|
||||
|
||||
confirmResetStock(): void {
|
||||
const resetDate = moment((this.resetStockForm.get('resetDate') as FormControl).value).format(
|
||||
'DD-MMM-YYYY',
|
||||
);
|
||||
const stockDate = moment((this.resetStockForm.get('stockDate') as FormControl).value).format(
|
||||
'DD-MMM-YYYY',
|
||||
);
|
||||
const quantity = +(this.resetStockForm.get('quantity') as FormControl).value;
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {
|
||||
title: 'Reset the stock of?',
|
||||
content: `Are you sure you want to reset the stock of ${this.product.name}? This action is destructive and cannot be undone.`,
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.resetStock(resetDate, stockDate, this.product, quantity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetStock(resetDate: string, stockDate: string, product: Product, quantity: number) {
|
||||
this.ser.resetStock(resetDate, stockDate, product, quantity).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', 'Stock has been reset!');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
toggleMaintenance() {
|
||||
this.ser.setMaintenance(!this.maintenance.enabled).subscribe((x) => {
|
||||
this.maintenance = x;
|
||||
|
||||
@@ -41,18 +41,6 @@ export class SettingsService {
|
||||
>;
|
||||
}
|
||||
|
||||
resetStock(
|
||||
resetDate: string,
|
||||
stockDate: string,
|
||||
product: Product,
|
||||
quantity: number,
|
||||
): Observable<boolean> {
|
||||
const url = '/api/reset-stock';
|
||||
return this.http
|
||||
.post<boolean>(`${url}/${product.id}`, { stockDate, resetDate, quantity })
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'resetStock'))) as Observable<boolean>;
|
||||
}
|
||||
|
||||
rebaseDatabase(date: string): Observable<Record<string, never>> {
|
||||
const url = '/api/rebase';
|
||||
return this.http
|
||||
|
||||
Reference in new issue
Block a user