Fix: import script to fit the new structure of voucher table (is_printed field removed, voucher_type != KOT is now assumed to be printed)
Fix: Take-away bill type is now removed Fix: Table overview now shows the right amounts Voucher Save and Update should now work Discounts now working (permissions are not checked)
This commit is contained in:
16
bookie/src/app/sales/discount/discount-datasource.ts
Normal file
16
bookie/src/app/sales/discount/discount-datasource.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
export class DiscountDataSource extends DataSource<{name: string, discount: number}> {
|
||||
|
||||
constructor(private data: {name: string, discount: number}[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<{name: string, discount: number}[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
||||
4
bookie/src/app/sales/discount/discount.component.css
Normal file
4
bookie/src/app/sales/discount/discount.component.css
Normal file
@ -0,0 +1,4 @@
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
30
bookie/src/app/sales/discount/discount.component.html
Normal file
30
bookie/src/app/sales/discount/discount.component.html
Normal file
@ -0,0 +1,30 @@
|
||||
<h2 mat-dialog-title>Discount</h2>
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="discounts">
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- Discount Column -->
|
||||
<ng-container matColumnDef="discount">
|
||||
<mat-header-cell *matHeaderCellDef class="center" fxFlex>Discount</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" class="center" [formGroupName]="i" fxFlex>
|
||||
<mat-form-field>
|
||||
<input matInput type="number" formControlName="discount" autocomplete="off">
|
||||
</mat-form-field>
|
||||
</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-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||
<button mat-button (click)="accept()" color="primary">Ok</button>
|
||||
</mat-dialog-actions>
|
||||
25
bookie/src/app/sales/discount/discount.component.spec.ts
Normal file
25
bookie/src/app/sales/discount/discount.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DiscountComponent } from './discount.component';
|
||||
|
||||
describe('DiscountComponent', () => {
|
||||
let component: DiscountComponent;
|
||||
let fixture: ComponentFixture<DiscountComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ DiscountComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DiscountComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
52
bookie/src/app/sales/discount/discount.component.ts
Normal file
52
bookie/src/app/sales/discount/discount.component.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
||||
import { Observable } from 'rxjs';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||
import { DiscountDataSource } from "./discount-datasource";
|
||||
|
||||
@Component({
|
||||
selector: 'app-modifiers',
|
||||
templateUrl: './discount.component.html',
|
||||
styleUrls: ['./discount.component.css']
|
||||
})
|
||||
export class DiscountComponent {
|
||||
list: any[];
|
||||
form: FormGroup;
|
||||
dataSource: DiscountDataSource;
|
||||
|
||||
displayedColumns = ['name', 'discount'];
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<DiscountComponent>,
|
||||
private fb: FormBuilder,
|
||||
@Inject(MAT_DIALOG_DATA) public data: Observable<any[]>
|
||||
) {
|
||||
this.createForm();
|
||||
this.data.subscribe((list: any[]) => {
|
||||
this.list = list;
|
||||
this.form.setControl('discounts', this.fb.array(
|
||||
this.list.map(
|
||||
x => this.fb.group({
|
||||
name: [x.name],
|
||||
discount: ["", [Validators.min(0), Validators.max(100)]]
|
||||
})
|
||||
)
|
||||
));
|
||||
this.dataSource = new DiscountDataSource(list);
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
discounts: ''
|
||||
});
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
const array = this.form.get('discounts') as FormArray;
|
||||
this.list.forEach((item, index) => {
|
||||
item.discount = Math.max(Math.min(array.controls[index].value.discount, 100), 0);
|
||||
});
|
||||
this.dialogRef.close(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user