Added feature: Split bill by Sales Category if no item is selected.
This commit is contained in:
4
bookie/src/app/sales/split-bill/split-bill.component.css
Normal file
4
bookie/src/app/sales/split-bill/split-bill.component.css
Normal file
@ -0,0 +1,4 @@
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
23
bookie/src/app/sales/split-bill/split-bill.component.html
Normal file
23
bookie/src/app/sales/split-bill/split-bill.component.html
Normal file
@ -0,0 +1,23 @@
|
||||
<h2 mat-dialog-title>Select Sale Categories</h2>
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div formArrayName="saleCategories">
|
||||
<div
|
||||
fxLayout="row"
|
||||
*ngFor="let sc of list; index as i"
|
||||
[formGroupName]="i"
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-checkbox formControlName="saleCategory" fxFlex>{{ sc.name }}</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</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>
|
||||
26
bookie/src/app/sales/split-bill/split-bill.component.spec.ts
Normal file
26
bookie/src/app/sales/split-bill/split-bill.component.spec.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { SplitBillComponent } from './split-bill.component';
|
||||
|
||||
describe('SplitBillComponent', () => {
|
||||
let component: SplitBillComponent;
|
||||
let fixture: ComponentFixture<SplitBillComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SplitBillComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SplitBillComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
46
bookie/src/app/sales/split-bill/split-bill.component.ts
Normal file
46
bookie/src/app/sales/split-bill/split-bill.component.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-split-bill',
|
||||
templateUrl: './split-bill.component.html',
|
||||
styleUrls: ['./split-bill.component.css'],
|
||||
})
|
||||
export class SplitBillComponent {
|
||||
list: { id: string; name: string; selected: boolean }[] = [];
|
||||
form: FormGroup;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<SplitBillComponent>,
|
||||
private fb: FormBuilder,
|
||||
@Inject(MAT_DIALOG_DATA)
|
||||
public data: Observable<{ id: string; name: string; selected: boolean }[]>,
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
saleCategories: this.fb.array([]),
|
||||
});
|
||||
this.data.subscribe((list: { id: string; name: string; selected: boolean }[]) => {
|
||||
this.list = list;
|
||||
this.form.setControl(
|
||||
'saleCategories',
|
||||
this.fb.array(
|
||||
this.list.map((x) =>
|
||||
this.fb.group({
|
||||
saleCategory: x.selected,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
accept(): void {
|
||||
const array = this.form.get('saleCategories') as FormArray;
|
||||
this.list.forEach((item, index) => {
|
||||
item.selected = array.controls[index].value.saleCategory;
|
||||
});
|
||||
this.dialogRef.close(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user