import { MyDate } from "../utils/my-date"; import { TrUtils } from "../utils/tr-utils"; export class ServiceHistoryPDFService { static GetPrint(ReOrderPointData: any, DatesDetails: any) { // console.log('ReOrderPointData', ReOrderPointData); let dd: any = { // info: { // title: this.GetFileName(ROPrintData), // }, info: { title: 'ExpiringDrugs', }, header: function (currentPage: any, pageCount: any, pageSize: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 25, fontSize: 8, marginTop: 2 }; }, pageMargins: [25, 15, 25, 15], pageSize: 'A4', content: [ { text: ReOrderPointData.Entity.CName, style: ['headerstyle'], alignment: 'center', fontSize: 20 }, { text: 'Service History', style: ['headerstyle'], alignment: 'center', fontSize: 12 }, this.GetHistoryTable(ReOrderPointData.WOHistory, ReOrderPointData.Entity.DecimalsNumber), this.GetSignatures(ReOrderPointData.Entity.CName, ReOrderPointData.Type, ReOrderPointData.For), ], styles: { headerstyle: { fontFamily: 'Calibri', fontSize: 9 }, Sign: { fontSize: 8, margin: [0, 30, 0, 5] }, forCompany: { // margin: [0, 10, 30, 0], marginRight: 5, marginTop: 10, fontSize: 9, alignment: 'right' }, tableheader: { bold: true, fontFamily: 'Calibri', margin: [0, 1, 0, 5], alignment: 'center' }, tableheader1: { bold: true, fontFamily: 'Calibri', margin: [0, 2, 0, 2], alignment: 'center' }, tableExample: { fontSize: 9 } } }; return dd; } static GetSignatures(CName: any, For: any, Type: any) { return { columns: [{ stack: [ this.CompanyName(CName), ] }], }; } static CompanyName(CName: any) { return { style: 'forCompany', text: ['For ', { text: CName, }], }; } static GetHistoryTable(WOHistory: any, DecimalsNumber: number) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: [100, 80, 80, '*', 100], headerRows: 1, body: this.BuildTableBodyForHistory(WOHistory, DecimalsNumber) }, layout: { hLineWidth: function (i:any, node:any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 1 : 0.5; }, vLineWidth: function (i:any, node:any) { return (i === 0 || i === node.table.widths.length) ? 1 : 0.5; }, hLineColor: function (i: any, node: any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 'gray' : 'lightgrey'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, } }; } static BuildTableBodyForHistory(WOHistory: any, DecimalsNumber: number) { let body: any = this.GetHeaderNames(); // let Total: number = 0; WOHistory.forEach((item: any, index: any) => { // Total = Total + (TrUtils.SetValueToZeroIfNull(item.Batch.Qty) * TrUtils.SetValueToZeroIfNull(item.Batch.Cost)); let dataRow: any = []; dataRow.push({ text: item.Code, }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(item.CrDate), alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: item.Prod.MIn, alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: item.TypeName, alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(item.Total, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); }); // let Row: any = [{ text: 'Total', alignment: 'right', colSpan: 5, bold: true, fontSize: 12 }, {}, {}, {}, {}, { text: TrUtils.FixPriceValue(Total, DecimalsNumber), fontSize: 12, alignment: 'right', bold: true }]; // body.push(Row); return body; } static GetHeaderNames() { let HeadingNames: any; HeadingNames = [[{ text: 'WO#', style: 'tableheader1', Field: 'Code', alignment: 'left', line: true }, { text: 'Created Date', style: 'tableheader1', Field: 'CrDate', alignment: 'center' }, { text: 'Mileage In', style: 'tableheader1', Field: 'Mileage', alignment: 'center' }, { text: 'Service Type', style: 'tableheader1', Field: 'Type', alignment: 'center' }, { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' } ]]; return HeadingNames; } }