Update Product Prices built
This commit is contained in:
@ -40,7 +40,8 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'header-footer',
|
||||
loadChildren: () => import('./header-footer/header-footer.module').then((mod) => mod.HeaderFooterModule),
|
||||
loadChildren: () =>
|
||||
import('./header-footer/header-footer.module').then((mod) => mod.HeaderFooterModule),
|
||||
},
|
||||
{
|
||||
path: 'modifiers',
|
||||
@ -119,6 +120,13 @@ const routes: Routes = [
|
||||
path: 'tax-report',
|
||||
loadChildren: () => import('./tax-report/tax-report.module').then((mod) => mod.TaxReportModule),
|
||||
},
|
||||
{
|
||||
path: 'update-product-prices',
|
||||
loadChildren: () =>
|
||||
import('./update-product-prices/update-product-prices.module').then(
|
||||
(mod) => mod.UpdateProductPricesModule,
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
loadChildren: () => import('./users/users.module').then((mod) => mod.UsersModule),
|
||||
|
||||
@ -215,6 +215,15 @@
|
||||
>
|
||||
<h3 class="item-name">Product Updates Report</h3>
|
||||
</mat-card>
|
||||
<mat-card
|
||||
fxLayout="column"
|
||||
class="square-button"
|
||||
matRipple
|
||||
*ngIf="auth.user && auth.user.perms.indexOf('products') !== -1"
|
||||
[routerLink]="['/', 'update-product-prices']"
|
||||
>
|
||||
<h3 class="item-name">Update Product Prices</h3>
|
||||
</mat-card>
|
||||
</div>
|
||||
<footer class="footer">
|
||||
<p>Backend: v{{ auth.user?.ver }} / Frontend: v{{ version }} on {{ auth.device.name }}</p>
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
<button mat-button (click)="updateSortOrder()" [disabled]="!(filter | async)">
|
||||
Update Order
|
||||
</button>
|
||||
<!-- This should check filtered data and not data-->
|
||||
<button mat-button mat-icon-button (click)="exportCsv()" [disabled]="!((data | async).length)">
|
||||
<!-- This should check filtered data and not data-->
|
||||
<button mat-button mat-icon-button (click)="exportCsv()" [disabled]="!(data | async).length">
|
||||
<mat-icon>save_alt</mat-icon>
|
||||
</button>
|
||||
<a mat-button [routerLink]="['/products', 'new']">
|
||||
@ -95,7 +95,9 @@
|
||||
<!-- Yield Column -->
|
||||
<ng-container matColumnDef="quantity">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Quantity</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{ row.quantity | number: '1.2-2' }}</mat-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{
|
||||
row.quantity | number: '1.2-2'
|
||||
}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { UpdateProductPricesItem } from './update-product-prices-item';
|
||||
|
||||
export class UpdateProductPricesDataSource extends DataSource<UpdateProductPricesItem> {
|
||||
constructor(public data: UpdateProductPricesItem[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<UpdateProductPricesItem[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
export class UpdateProductPricesItem {
|
||||
id: string;
|
||||
name: string;
|
||||
oldPrice: number;
|
||||
newPrice: number;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UpdateProductPricesResolver } from './update-product-prices-resolver.service';
|
||||
|
||||
describe('UpdateProductPricesResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [UpdateProductPricesResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject(
|
||||
[UpdateProductPricesResolver],
|
||||
(service: UpdateProductPricesResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { UpdateProductPrices } from './update-product-prices';
|
||||
import { UpdateProductPricesService } from './update-product-prices.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UpdateProductPricesResolver implements Resolve<UpdateProductPrices> {
|
||||
constructor(private ser: UpdateProductPricesService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<UpdateProductPrices> {
|
||||
const startDate = route.queryParamMap.get('startDate') || null;
|
||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id, startDate, finishDate);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { UpdateProductPricesRoutingModule } from './update-product-prices-routing.module';
|
||||
|
||||
describe('UpdateProductPricesRoutingModule', () => {
|
||||
let pupdateProductPricesRoutingModule: UpdateProductPricesRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
pupdateProductPricesRoutingModule = new UpdateProductPricesRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(pupdateProductPricesRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,45 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { MenuCategoryListResolver } from '../menu-category/menu-category-list-resolver.service';
|
||||
|
||||
import { UpdateProductPricesResolver } from './update-product-prices-resolver.service';
|
||||
import { UpdateProductPricesComponent } from './update-product-prices.component';
|
||||
|
||||
const pupdateProductPricesRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: UpdateProductPricesComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
menuCategories: MenuCategoryListResolver,
|
||||
info: UpdateProductPricesResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: UpdateProductPricesComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products',
|
||||
},
|
||||
resolve: {
|
||||
menuCategories: MenuCategoryListResolver,
|
||||
info: UpdateProductPricesResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(pupdateProductPricesRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [UpdateProductPricesResolver],
|
||||
})
|
||||
export class UpdateProductPricesRoutingModule {}
|
||||
@ -0,0 +1,9 @@
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-right: 1em;
|
||||
margin-left: 1em;
|
||||
}
|
||||
.multi_lines_text {
|
||||
white-space: pre-line;
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product Update 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]="date"
|
||||
(focus)="date.open()"
|
||||
placeholder="Date"
|
||||
formControlName="date"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Section</mat-label>
|
||||
<mat-select placeholder="Section" formControlName="menuCategory">
|
||||
<mat-option *ngFor="let s of menuCategories" [value]="s.id">
|
||||
{{ s.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
|
||||
</div>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements" formArrayName="prices">
|
||||
<!-- 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>
|
||||
|
||||
<!-- Old Price Column -->
|
||||
<ng-container matColumnDef="oldPrice">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Old Price</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{
|
||||
row.oldPrice | currency: 'INR'
|
||||
}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- New Price Column -->
|
||||
<ng-container matColumnDef="newPrice">
|
||||
<mat-header-cell *matHeaderCellDef class="right">New Price</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex class="right">
|
||||
₹ <input matInput type="number" placeholder="Price" formControlName="newPrice" />
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UpdateProductPricesComponent } from './update-product-prices.component';
|
||||
|
||||
describe('UpdateProductPricesComponent', () => {
|
||||
let component: UpdateProductPricesComponent;
|
||||
let fixture: ComponentFixture<UpdateProductPricesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [UpdateProductPricesComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UpdateProductPricesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,126 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
|
||||
import { MenuCategory } from '../core/menu-category';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { ToCsvService } from '../shared/to-csv.service';
|
||||
|
||||
import { UpdateProductPrices } from './update-product-prices';
|
||||
import { UpdateProductPricesDataSource } from './update-product-prices-datasource';
|
||||
import { UpdateProductPricesService } from './update-product-prices.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-update-product-prices',
|
||||
templateUrl: './update-product-prices.component.html',
|
||||
styleUrls: ['./update-product-prices.component.css'],
|
||||
})
|
||||
export class UpdateProductPricesComponent implements OnInit {
|
||||
dataSource: UpdateProductPricesDataSource;
|
||||
form: FormGroup;
|
||||
menuCategories: MenuCategory[];
|
||||
info: UpdateProductPrices;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'oldPrice', 'newPrice'];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toCsv: ToCsvService,
|
||||
private toaster: ToasterService,
|
||||
private ser: UpdateProductPricesService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe(
|
||||
(data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
||||
this.menuCategories = data.menuCategories;
|
||||
this.loadData(data.info);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
loadData(info: UpdateProductPrices) {
|
||||
this.info = info;
|
||||
this.form.get('date').setValue(moment(this.info.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form
|
||||
.get('menuCategory')
|
||||
.setValue(this.info.menuCategoryId !== undefined ? this.info.menuCategoryId : '');
|
||||
this.form.setControl(
|
||||
'prices',
|
||||
this.fb.array(
|
||||
this.info.items.map((x) =>
|
||||
this.fb.group({
|
||||
newPrice: x.newPrice,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new UpdateProductPricesDataSource(this.info.items);
|
||||
}
|
||||
|
||||
show() {
|
||||
const info = this.getInfo();
|
||||
const route = ['update-product-prices'];
|
||||
if (info.menuCategoryId !== undefined) route.push(info.menuCategoryId);
|
||||
this.router.navigate(route, {
|
||||
queryParams: {
|
||||
date: info.date,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
menuCategory: '',
|
||||
prices: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): UpdateProductPrices {
|
||||
const formModel = this.form.value;
|
||||
const array = this.form.get('prices') as FormArray;
|
||||
this.info.items.forEach((item, index) => {
|
||||
item.newPrice = array.controls[index].value.newPrice;
|
||||
});
|
||||
|
||||
return {
|
||||
date: moment(formModel.date).format('DD-MMM-YYYY'),
|
||||
menuCategoryId: formModel.menuCategory,
|
||||
items: [...this.info.items],
|
||||
};
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const headers = {
|
||||
Details: 'details',
|
||||
};
|
||||
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', 'update-product-prices.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.save(this.getInfo()).subscribe(
|
||||
(result: UpdateProductPrices) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.loadData(result);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { UpdateProductPricesModule } from './update-product-prices.module';
|
||||
|
||||
describe('UpdateProductPricesModule', () => {
|
||||
let pupdateProductPricesModule: UpdateProductPricesModule;
|
||||
|
||||
beforeEach(() => {
|
||||
pupdateProductPricesModule = new UpdateProductPricesModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(pupdateProductPricesModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,67 @@
|
||||
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 { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { UpdateProductPricesRoutingModule } from './update-product-prices-routing.module';
|
||||
import { UpdateProductPricesComponent } from './update-product-prices.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,
|
||||
UpdateProductPricesRoutingModule,
|
||||
MatSelectModule,
|
||||
],
|
||||
declarations: [UpdateProductPricesComponent],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
|
||||
],
|
||||
})
|
||||
export class UpdateProductPricesModule {}
|
||||
@ -0,0 +1,18 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UpdateProductPricesService } from './update-product-prices.service';
|
||||
|
||||
describe('UpdateProductPricesService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [UpdateProductPricesService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject(
|
||||
[UpdateProductPricesService],
|
||||
(service: UpdateProductPricesService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
@ -0,0 +1,44 @@
|
||||
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 { Product } from '../core/product';
|
||||
|
||||
import { UpdateProductPrices } from './update-product-prices';
|
||||
|
||||
const url = '/api/update-product-prices';
|
||||
const serviceName = 'UpdateProductPricesService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UpdateProductPricesService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string, startDate: string, finishDate): Observable<UpdateProductPrices> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
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<UpdateProductPrices>>(
|
||||
this.http
|
||||
.get<UpdateProductPrices>(getUrl, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'get')))
|
||||
);
|
||||
}
|
||||
|
||||
save(item: UpdateProductPrices): Observable<UpdateProductPrices> {
|
||||
const saveUrl: string = item.menuCategoryId === null ? url : `${url}/${item.menuCategoryId}`;
|
||||
return <Observable<UpdateProductPrices>>(
|
||||
this.http
|
||||
.post<Product[]>(saveUrl, item)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
import { UpdateProductPricesItem } from './update-product-prices-item';
|
||||
|
||||
export class UpdateProductPrices {
|
||||
date: string;
|
||||
menuCategoryId?: string;
|
||||
items: UpdateProductPricesItem[];
|
||||
}
|
||||
Reference in New Issue
Block a user