import { SharedPDFService } from '../../../../shared/shared-pdf.service'; import { MyDate } from '../../../../utils/my-date'; import { TrUtils } from '../../../../utils/tr-utils'; declare var pdfMake: any; export class AnalysisPDFService { static GetAnalysisPDFPrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, IsSales: boolean, HeaerName: any, searchValue: any, HeaderText: any) { var dd = { info: { title: 'Analysis', }, header: function (currentPage: any, pageCount: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 7, fontSize: 8, marginTop: 2 }; }, pageMargins: [10, 15, 10, 15], content: [ { text: '' + EntityData.Entity.DName + '', style: ['header'] }, { text: HeaerName, alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, IsSales, HeaderText, EntityData.User.TZ, EntityData.Entity.Settings?.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, isPhar: boolean, isHC: boolean, IsSales: boolean, HeaderText: any, UserTimeZone: any, DecimalsNumber: number) { let Data: any = [] Data.push(this.GetItemsTable(InvoicesData, isPhar, isHC, IsSales, HeaderText, UserTimeZone, DecimalsNumber)); return Data; } static getTableWidths(isHC: any) { // if (isHC) { return [25, '*', '*', '*', '*', '*', '*', '*', '*', '*', '*']; // } else { // return [25, '*', 40, 40, 80]; // } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, IsSales: boolean, HeaderText: any, UserTimeZone: any, DecimalsNumber: number) { // InvoiceData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isHC), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, IsSales, HeaderText, UserTimeZone, 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 BuildTableBodyForLaborAndParts(InvoiceData: any, isPhar: boolean, isHC: boolean, IsSales: boolean, HeaderText: any, UserTimeZone: any, DecimalsNumber: number) { let body: any = this.GetHeaderNames(isPhar, isHC, HeaderText); InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1 }); if (HeaderText === 'Month') { dataRow.push({ text: MyDate.GetMonthName(invoice._id, UserTimeZone), style: ['headerstyle'], }); } else { dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice._id), style: ['headerstyle'], }); } dataRow.push({ text: invoice.Count, alignment: 'right' }); dataRow.push({ text: invoice.Qty, alignment: 'right' }); dataRow.push({ text: invoice.OfQty, alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.SubTotal, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Disc, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Tax, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Adjust, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Round, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); }); return body; } static GetHeaderNames(isPhar: boolean, isHC: boolean, HeaderText: any) { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: HeaderText, style: 'tableheader1', Field: 'Name' }, { text: 'Count', style: 'tableheader1', Field: 'Count', alignment: 'right' }, { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Offer Qty', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, { text: 'SubTotal', style: 'tableheader1', Field: 'SubTotal', alignment: 'right' }, { text: 'Discount', style: 'tableheader1', Field: 'Disc', alignment: 'right' }, { text: 'Tax', style: 'tableheader1', Field: 'Tax', alignment: 'right' }, { text: 'Adjustment', style: 'tableheader1', Field: 'Adjust', alignment: 'right' }, { text: 'Round off', style: 'tableheader1', Field: 'Round', alignment: 'right' }, { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' }]]; return HeadingNames; } }