Feature: Open bill using bill number
This commit is contained in:
37
bookie/src/app/sales/bill-number/bill-number.component.html
Normal file
37
bookie/src/app/sales/bill-number/bill-number.component.html
Normal file
@ -0,0 +1,37 @@
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex="15">
|
||||
<mat-select formControlName="billType">
|
||||
<mat-option value="0">KOT</mat-option>
|
||||
<mat-option value="1">Regular Bill</mat-option>
|
||||
<mat-option value="4">Staff</mat-option>
|
||||
<mat-option value="2">No Charge</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Bill Number</mat-label>
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
#billNumber
|
||||
placeholder="Bill Number"
|
||||
formControlName="billNumber"
|
||||
autocomplete="off"
|
||||
(focus)="billNumber.select()"
|
||||
cdkFocusInitial
|
||||
/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions>
|
||||
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||
<button mat-button (click)="accept()" color="primary">Ok</button>
|
||||
</mat-dialog-actions>
|
||||
@ -0,0 +1,26 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { BillNumberComponent } from './bill-number.component';
|
||||
|
||||
describe('QuantityComponent', () => {
|
||||
let component: BillNumberComponent;
|
||||
let fixture: ComponentFixture<BillNumberComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [BillNumberComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BillNumberComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
54
bookie/src/app/sales/bill-number/bill-number.component.ts
Normal file
54
bookie/src/app/sales/bill-number/bill-number.component.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bill-number',
|
||||
templateUrl: './bill-number.component.html',
|
||||
styleUrls: ['./bill-number.component.css'],
|
||||
})
|
||||
export class BillNumberComponent implements OnInit {
|
||||
form: FormGroup;
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<BillNumberComponent>, private fb: FormBuilder) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
billType: '',
|
||||
billNumber: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.form.setValue({
|
||||
billType: '1',
|
||||
billNumber: '',
|
||||
});
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
const formValue = this.form.value;
|
||||
const billNumber = parseInt(formValue.billNumber.replace('-', ''), 10);
|
||||
if (isNaN(billNumber)) {
|
||||
this.dialogRef.close(undefined);
|
||||
} else {
|
||||
let billId: string;
|
||||
switch (formValue.billType) {
|
||||
case '0': // KOT
|
||||
billId = 'K-' + billNumber;
|
||||
break;
|
||||
case '1': // Regular Bill
|
||||
billId = Math.floor(billNumber / 10000) + '-' + (billNumber % 10000);
|
||||
break;
|
||||
case '4': // Staff
|
||||
billId = 'ST-' + billNumber;
|
||||
break;
|
||||
case '2': // No Charge
|
||||
billId = 'NC-' + billNumber;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown Bill Type');
|
||||
}
|
||||
this.dialogRef.close(billId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user