Added downoad to Raw Material Cost and fixed quantity not showing

This commit is contained in:
tanshu 2018-06-10 16:38:46 +05:30
parent 8996516978
commit a811a121cc
2 changed files with 28 additions and 1 deletions

View File

@ -1,6 +1,9 @@
<mat-card> <mat-card>
<mat-card-title-group> <mat-card-title-group>
<mat-card-title>Raw Material Cost</mat-card-title> <mat-card-title>Raw Material Cost</mat-card-title>
<button mat-button mat-icon-button *ngIf="dataSource.data.length" (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
</mat-card-title-group> </mat-card-title-group>
<mat-card-content> <mat-card-content>
<form [formGroup]="form" fxLayout="column"> <form [formGroup]="form" fxLayout="column">
@ -66,7 +69,7 @@
<!-- Quantity Column --> <!-- Quantity Column -->
<ng-container matColumnDef="quantity"> <ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right">Quantity Quantity</mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header class="right">Quantity Quantity</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.quantityQuantity | number:'1.2-2'}}</mat-cell> <mat-cell *matCellDef="let row" class="right">{{row.quantity | number:'1.2-2'}}</mat-cell>
<mat-footer-cell *matFooterCellDef></mat-footer-cell> <mat-footer-cell *matFooterCellDef></mat-footer-cell>
</ng-container> </ng-container>

View File

@ -78,4 +78,28 @@ export class RawMaterialCostComponent implements OnInit {
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'), finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
}; };
} }
exportCsv() {
const data: string[] = [];
if (this.info.id) {
data.push(
'Name, Group, Quantity, Net, Gross',
...this.dataSource.data.map(x => x.name + ', ' + x.group + ', ' + x.quantity + ', ' + x.net + ', ' + x.gross)
);
} else {
data.push(
'Name, Issue, Sale, RMC',
...this.dataSource.data.map(x => x.name + ', ' + x.issue + ', ' + x.sale + ', ' + x.rmc),
this.info.footer.name + ', ' + this.info.footer.issue + ', ' + this.info.footer.sale + ', ' + this.info.footer.rmc
);
}
const csvData = new Blob([data.join('\n')], {type: 'text/csv;charset=utf-8;'});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'raw-material-cost.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
} }