Product Group renamed to Menu Category

Extracted Product Group -> Group_type to a a new object called Sale Category.
Moved tax from product to Sale Category for uniform taxes on types of sales.
This commit is contained in:
Amritanshu
2019-06-20 13:15:23 +05:30
parent 16455fdcac
commit 05f8058a15
74 changed files with 1400 additions and 646 deletions

View File

@ -0,0 +1,3 @@
.example-card {
max-width: 400px;
}

View File

@ -0,0 +1,33 @@
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Sale Category</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex>
<mat-label>Name</mat-label>
<input matInput #nameElement placeholder="Name" formControlName="name">
</mat-form-field>
</div>
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
fxLayoutGap.lt-md="0px">
<mat-form-field fxFlex>
<mat-label>Tax</mat-label>
<mat-select placeholder="Tax" formControlName="tax">
<mat-option *ngFor="let t of taxes" [value]="t.id">
{{ t.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button [disabled]="item.isFixture" color="primary" (click)="save()">Save</button>
<button mat-raised-button [disabled]="item.isFixture" color="warn" (click)="confirmDelete()" *ngIf="!!item.id">Delete</button>
</mat-card-actions>
</mat-card>
</div>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {SaleCategoryDetailComponent} from './sale-category-detail.component';
describe('SaleCategoryDetailComponent', () => {
let component: SaleCategoryDetailComponent;
let fixture: ComponentFixture<SaleCategoryDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SaleCategoryDetailComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SaleCategoryDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,108 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from "@angular/material";
import { SaleCategoryService } from '../sale-category.service';
import { SaleCategory } from '../../core/sale-category';
import { ToasterService } from '../../core/toaster.service';
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
import { Tax } from "../../core/tax";
@Component({
selector: 'app-sale-category-detail',
templateUrl: './sale-category-detail.component.html',
styleUrls: ['./sale-category-detail.component.css']
})
export class SaleCategoryDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
form: FormGroup;
taxes: Tax[];
item: SaleCategory;
constructor(
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: SaleCategoryService
) {
this.createForm();
}
createForm() {
this.form = this.fb.group({
name: '',
tax: ''
});
}
ngOnInit() {
this.route.data
.subscribe((data: { item: SaleCategory, taxes: Tax[] }) => {
this.showItem(data.item);
this.taxes = data.taxes;
});
}
showItem(item: SaleCategory) {
this.item = item;
this.form.setValue({
name: this.item.name,
tax: this.item.tax.id ? this.item.tax.id : ''
});
}
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
}, 0);
}
save() {
this.ser.saveOrUpdate(this.getItem())
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/sale-categories');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
delete() {
this.ser.delete(this.item.id)
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/sale-categories');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Sale Category?', content: 'Are you sure? This cannot be undone.'}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.delete();
}
});
}
getItem(): SaleCategory {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.tax.id = formModel.tax;
return this.item;
}
}