Feature: Product Sale Report printing.

This commit is contained in:
2021-06-27 08:08:20 +05:30
parent a1a1c10dff
commit 7247ac34f4
7 changed files with 114 additions and 2 deletions

View File

@ -2,3 +2,7 @@
display: flex;
justify-content: flex-end;
}
.spacer {
flex: 1 1 auto;
}

View File

@ -1,9 +1,13 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Product Sale Report</mat-card-title>
<span class="spacer"></span>
<button mat-button mat-icon-button (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
<button mat-button mat-icon-button (click)="print()">
<mat-icon>print</mat-icon>
</button>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">

View File

@ -3,10 +3,12 @@ import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { ToasterService } from '../core/toaster.service';
import { ToCsvService } from '../shared/to-csv.service';
import { ProductSaleReport } from './product-sale-report';
import { ProductSaleReportDataSource } from './product-sale-report-datasource';
import { ProductSaleReportService } from './product-sale-report.service';
@Component({
selector: 'app-product-sale-report',
@ -26,6 +28,8 @@ export class ProductSaleReportComponent implements OnInit {
private router: Router,
private fb: FormBuilder,
private toCsv: ToCsvService,
private toaster: ToasterService,
private ser: ProductSaleReportService,
) {
// Create form
this.form = this.fb.group({
@ -65,6 +69,17 @@ export class ProductSaleReportComponent implements OnInit {
});
}
print() {
this.ser.print(this.info.startDate, this.info.finishDate).subscribe(
() => {
this.toaster.show('', 'Successfully Printed');
},
(error) => {
this.toaster.show('Error', error);
},
);
}
exportCsv() {
const headers = {
Name: 'name',

View File

@ -28,4 +28,18 @@ export class ProductSaleReportService {
.get<ProductSaleReport>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'get'))) as Observable<ProductSaleReport>;
}
print(startDate: string | null, finishDate: string | null): Observable<boolean> {
const printUrl = `${url}/print`;
const options = { params: new HttpParams() };
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return this.http
.get<boolean>(printUrl, options)
.pipe(catchError(this.log.handleError(serviceName, 'print'))) as Observable<boolean>;
}
}