Renamed void_reason to reason so that we can store the employee name in case of Staff and NC reason in case of NC bills.

Settling NC and Staff bills now asks for Staff name / NC reason
This commit is contained in:
Amritanshu
2019-08-25 23:22:50 +05:30
parent 6d0f30503a
commit a12f093828
18 changed files with 171 additions and 97 deletions

View File

@ -206,8 +206,8 @@ export class BillService {
return this.bill.voucherType;
}
receivePayment(amounts: { id: string; name: string; amount: number }[]): Observable<boolean> {
return this.ser.receivePayment(this.bill.id, amounts, true);
receivePayment(amounts: { id: number; name: string; amount: number }[], name: string): Observable<boolean> {
return this.ser.receivePayment(this.bill.id, amounts, name, true);
}
moveTable(table: Table): Observable<boolean> {

View File

@ -79,10 +79,10 @@ export class VoucherService {
}
}
receivePayment(id: string, amounts: { id: string; name: string; amount: number }[], updateTable: boolean): Observable<boolean> {
receivePayment(id: string, amounts: { id: number; name: string; amount: number }[], name: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(
`${url}/${id}`, amounts, options
`${url}/${id}`, {name: name, amounts: amounts}, options
).pipe(
catchError(this.log.handleError(serviceName, 'receivePayment'))
);

View File

@ -15,7 +15,7 @@ import { TableService } from '../../tables/table.service';
import { Table } from '../../core/table';
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
import { VoidReasonComponent } from '../void-reason/void-reason.component';
import { ReasonComponent } from '../reason/reason.component';
@Component({
selector: 'app-sales-home',
@ -184,28 +184,71 @@ export class SalesHomeComponent implements OnInit {
return true;
}
receivePaymentWithReason(type:string, amount: number): Observable<boolean> {
const types = {
NO_CHARGE: [
{
id: 4,
name: 'No Charge',
amount: amount
}
],
STAFF: [
{
id: 10,
name: 'Staff Account',
amount: amount
}
]
};
return this.dialog.open(ReasonComponent, {
// width: '750px'
data: {title: (type === "NO_CHARGE") ? "NC for whom" : "Staff name"}
}).afterClosed().pipe(
switchMap((value: boolean | string) => {
if (!!value) {
return this.bs.receivePayment(types[type], value as string)
} else {
return throwError("Cancelled");
}
})
);
}
receiveRegularPayment (type: string, amount: number): Observable<boolean> {
return this.dialog.open(ReceivePaymentComponent, {
// width: '750px',
data: {
type: type,
amount: amount
}
}).afterClosed().pipe(
switchMap((value: boolean | {id: number, name: string, amount: number}[]) => {
if (!!value) {
return this.bs.receivePayment(value as { id: number, name: string, amount: number }[], '')
} else {
return throwError("Cancelled");
}
})
);
}
receivePayment() {
if (!this.receivePaymentAllowed()) {
return;
}
const amount = this.bs.amountVal();
const type = this.bs.type();
const dialogRef = this.dialog.open(ReceivePaymentComponent, {
// width: '750px',
data: {
type: type,
amount: amount
}
});
dialogRef.afterClosed().subscribe((result: boolean | { id: string, name: string, amount: number }[]) => {
if (!!result) {
this.bs.receivePayment(result as { id: string, name: string, amount: number }[]).subscribe(() => {
let obs: any;
if (type === 'NO_CHARGE' || type === 'STAFF') {
obs = this.receivePaymentWithReason(type, amount);
} else {
obs = this.receiveRegularPayment(type, amount);
}
obs.subscribe(() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
});
}
});
}
moveTableAllowed(): boolean {
if (!this.auth.hasPermission('Move Table') && !this.auth.hasPermission('Merge Tables')) {
@ -269,8 +312,20 @@ export class SalesHomeComponent implements OnInit {
if (!this.voidBillAllowed()) {
return;
}
this.dialog.open(VoidReasonComponent, {
this.dialog.open(ReasonComponent, {
// width: '750px'
data: {
title: 'Void Reason',
reasons: [
'Discount',
'Printing fault',
'Item changed',
'Quantity reduced',
'Costing bill for party',
'Cashier mistake',
'Management free sale',
]
}
}).afterClosed().pipe(
switchMap((x: boolean | string) => {
if (!!x) {

View File

@ -1,7 +1,7 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
export class VoidReasonDatasource extends DataSource<string> {
export class ReasonDatasource extends DataSource<string> {
constructor(private data: string[]) {
super();

View File

@ -0,0 +1,25 @@
<h2 mat-dialog-title>{{ title }}</h2>
<mat-dialog-content>
<form [formGroup]="form">
<mat-table [dataSource]="dataSource">
<!-- Reason Column -->
<ng-container matColumnDef="reason">
<mat-cell *matCellDef="let row" (click)="select(row)">{{row}}</mat-cell>
<mat-footer-cell *matFooterCellDef>
<mat-form-field fxFlex>
<mat-label>Reason</mat-label>
<input type="text" matInput #son placeholder="Reason" formControlName="son" autocomplete="off"
(focus)="select($event.target.value) && son.select()" (input)="select($event.target.value)">
</mat-form-field>
</mat-footer-cell>
</ng-container>
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.selected]="row === selected"></mat-row>
<mat-footer-row *matFooterRowDef="displayedColumns"></mat-footer-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" [disabled]="!selected">Ok</button>
</mat-dialog-actions>

View File

@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { VoidReasonComponent } from './void-reason.component';
import { ReasonComponent } from './reason.component';
describe('VoidReasonComponent', () => {
let component: VoidReasonComponent;
let fixture: ComponentFixture<VoidReasonComponent>;
let component: ReasonComponent;
let fixture: ComponentFixture<ReasonComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ VoidReasonComponent ]
declarations: [ ReasonComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(VoidReasonComponent);
fixture = TestBed.createComponent(ReasonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

View File

@ -0,0 +1,41 @@
import { Component, ElementRef, Inject, ViewChild } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { ReasonDatasource } from './reason-datasource';
import { FormBuilder, FormGroup } from "@angular/forms";
@Component({
selector: 'app-reason',
templateUrl: './reason.component.html',
styleUrls: ['./reason.component.css']
})
export class ReasonComponent {
@ViewChild('son', { static: true }) son: ElementRef;
form: FormGroup;
dataSource: ReasonDatasource;
title: string;
selected: string;
reasons: string[];
displayedColumns = ['reason'];
constructor(
public dialogRef: MatDialogRef<ReasonComponent>,
@Inject(MAT_DIALOG_DATA) private data:{ title: string, reasons: string[]},
private fb: FormBuilder
) {
this.reasons = data.reasons || [];
this.title = data.title;
this.form = this.fb.group({
son: ''
});
this.dataSource = new ReasonDatasource(this.reasons);
}
select(reason: string) {
this.selected = reason.trim();
return true;
}
accept(): void {
this.dialogRef.close(this.selected);
}
}

View File

@ -30,7 +30,7 @@ import { DiscountComponent } from './discount/discount.component';
import { BillTypeComponent } from './bill-type/bill-type.component';
import { ReceivePaymentComponent } from './receive-payment/receive-payment.component';
import { TablesDialogComponent } from './tables-dialog/tables-dialog.component';
import { VoidReasonComponent } from './void-reason/void-reason.component';
import { ReasonComponent } from './reason/reason.component';
@NgModule({
providers: [
@ -48,7 +48,7 @@ import { VoidReasonComponent } from './void-reason/void-reason.component';
RunningTablesComponent,
SalesHomeComponent,
TablesDialogComponent,
VoidReasonComponent
ReasonComponent
],
imports: [
CommonModule,
@ -78,7 +78,7 @@ import { VoidReasonComponent } from './void-reason/void-reason.component';
QuantityComponent,
ReceivePaymentComponent,
TablesDialogComponent,
VoidReasonComponent
ReasonComponent
]
})
export class SalesModule { }

View File

@ -1,16 +0,0 @@
<h2 mat-dialog-title>Reason</h2>
<mat-dialog-content>
<mat-table [dataSource]="dataSource">
<!-- Name Column -->
<ng-container matColumnDef="reason">
<mat-cell *matCellDef="let row" (click)="select(row)">{{row}}</mat-cell>
</ng-container>
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.selected]="row === selected"></mat-row>
</mat-table>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button [mat-dialog-close]="false">Cancel</button>
<button mat-button (click)="accept()" color="primary" [disabled]="!selected">Ok</button>
</mat-dialog-actions>

View File

@ -1,38 +0,0 @@
import { Component } from '@angular/core';
import { MatDialogRef } from '@angular/material';
import { VoidReasonDatasource } from './void-reason-datasource';
@Component({
selector: 'app-void-reason',
templateUrl: './void-reason.component.html',
styleUrls: ['./void-reason.component.css']
})
export class VoidReasonComponent {
dataSource: VoidReasonDatasource;
selected: string;
reasons = [
'Discount',
'Printing fault',
'Item changed',
'Quantity reduced',
'Costing bill for party',
'Cashier mistake',
'Management free sale',
'Other'
];
displayedColumns = ['reason'];
constructor(
public dialogRef: MatDialogRef<VoidReasonComponent>
) {
this.dataSource = new VoidReasonDatasource(this.reasons);
}
select(reason: string) {
this.selected = reason;
}
accept(): void {
this.dialogRef.close(this.selected);
}
}