Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -1,4 +1,10 @@
|
||||
export class CashierReportDisplayItem {
|
||||
name: string;
|
||||
amount: number;
|
||||
|
||||
public constructor(init?: Partial<CashierReportDisplayItem>) {
|
||||
this.name = '';
|
||||
this.amount = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,4 +3,12 @@ export class CashierReportPrintItem {
|
||||
billId: string;
|
||||
customer: string;
|
||||
amount: number;
|
||||
|
||||
public constructor(init?: Partial<CashierReportPrintItem>) {
|
||||
this.date = '';
|
||||
this.billId = '';
|
||||
this.customer = '';
|
||||
this.amount = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { CashierReportComponent } from './cashier-report.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('CashierReportComponent', () => {
|
||||
let component: CashierReportComponent;
|
||||
let fixture: ComponentFixture<CashierReportComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CashierReportComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CashierReportComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CashierReportComponent);
|
||||
|
||||
@ -17,10 +17,10 @@ import { CashierReportService } from './cashier-report.service';
|
||||
styleUrls: ['./cashier-report.component.css'],
|
||||
})
|
||||
export class CashierReportComponent implements OnInit {
|
||||
dataSource: CashierReportDataSource;
|
||||
activeCashiers: User[] = [];
|
||||
info: CashierReport = new CashierReport();
|
||||
dataSource: CashierReportDataSource = new CashierReportDataSource(this.info.amounts);
|
||||
form: FormGroup;
|
||||
activeCashiers: User[];
|
||||
info: CashierReport;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'amount'];
|
||||
@ -33,11 +33,17 @@ export class CashierReportComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: CashierReportService,
|
||||
) {
|
||||
this.createForm();
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
cashier: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { cashiers: User[]; info: CashierReport }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { cashiers: User[]; info: CashierReport };
|
||||
this.activeCashiers = data.cashiers;
|
||||
this.info = data.info;
|
||||
this.form.setValue({
|
||||
@ -64,7 +70,7 @@ export class CashierReportComponent implements OnInit {
|
||||
}
|
||||
|
||||
print() {
|
||||
this.ser.print(this.info.cashier.id, this.info.startDate, this.info.finishDate).subscribe(
|
||||
this.ser.print(this.info.cashier.id as string, this.info.startDate, this.info.finishDate).subscribe(
|
||||
() => {
|
||||
this.toaster.show('', 'Successfully Printed');
|
||||
},
|
||||
@ -74,23 +80,15 @@ export class CashierReportComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
cashier: '',
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): CashierReport {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return {
|
||||
return new CashierReport({
|
||||
cashier: new User({ id: formModel.cashier }),
|
||||
cashiers: this.info.cashiers,
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
|
||||
@ -17,7 +17,11 @@ const serviceName = 'CashierReportService';
|
||||
export class CashierReportService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
list(id: string, startDate: string, finishDate): Observable<CashierReport> {
|
||||
list(
|
||||
id: string | null,
|
||||
startDate: string | null,
|
||||
finishDate: string | null,
|
||||
): Observable<CashierReport> {
|
||||
const listUrl = id === null ? url : `${url}/${id}`;
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
@ -33,7 +37,7 @@ export class CashierReportService {
|
||||
);
|
||||
}
|
||||
|
||||
activeCashiers(startDate: string, finishDate): Observable<User[]> {
|
||||
activeCashiers(startDate: string | null, finishDate: string | null): Observable<User[]> {
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
@ -47,7 +51,7 @@ export class CashierReportService {
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'activeCashiers')));
|
||||
}
|
||||
|
||||
print(id: string, startDate: string, finishDate): Observable<boolean> {
|
||||
print(id: string, startDate: string | null, finishDate: string | null): Observable<boolean> {
|
||||
const printUrl = `${url}/print/${id}`;
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
|
||||
@ -8,6 +8,16 @@ export class CashierReport {
|
||||
finishDate: string;
|
||||
cashier: User;
|
||||
cashiers: string;
|
||||
amounts?: CashierReportDisplayItem[];
|
||||
info?: CashierReportPrintItem[];
|
||||
amounts: CashierReportDisplayItem[];
|
||||
info: CashierReportPrintItem[];
|
||||
|
||||
public constructor(init?: Partial<CashierReport>) {
|
||||
this.startDate = '';
|
||||
this.finishDate = '0';
|
||||
this.cashier = new User();
|
||||
this.cashiers = '';
|
||||
this.amounts = [];
|
||||
this.info = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user