import { SharedPDFService } from '../../../../shared/shared-pdf.service'; import { TrUtils } from '../../../../utils/tr-utils'; declare var pdfMake: any; export class ItemWiseMOSummaryPDF { static GetItemWiseMOSummaryPrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, HeaderName: any, searchValue: any) { var dd = { info: { title: 'ItemWiseMOSummary', }, 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.DName + '', style: ['header'] }, { text: HeaderName, alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, EntityData.Settings.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, isPhar: boolean, isHC: boolean, DecimalsNumber: number) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData, isPhar, isHC, DecimalsNumber)); // }); return Data; } static getTableWidths(isHC: any) { // if (isHC) { // return [25, '*', '*', '*', '*']; // } else { return [25, '*', '*']; // } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, DecimalsNumber: number) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isHC), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, 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, DecimalsNumber: number) { let body: any = this.GetHeaderNames(isPhar, isHC); InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1 }); // dataRow.push({ text: invoice.Code, style: ['headerstyle'], }); // dataRow.push({ text: TrUtils.ConvertDateToReadableFormat(invoice.CrDate), alignment: 'left' }); // dataRow.push({ text: invoice.Qty, alignment: 'right' }); // dataRow.push({ text: invoice.OfQty, alignment: 'right' }); // dataRow.push({ text: invoice.ShipToUser, alignment: 'left' }); dataRow.push({ text: invoice.Name, alignment: 'left' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Qty, DecimalsNumber), alignment: 'right' }); // dataRow.push({ text: invoice.ReName, alignment: 'left' }); // dataRow.push({ text: invoice.Sts, alignment: 'left' }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total ), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); }); return body; } static GetHeaderNames(isPhar: boolean, isHC: boolean) { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, // { text: 'Transaction #', style: 'tableheader1', Field: 'Code', alignment: 'left' }, // { text: 'Created Date', style: 'tableheader1', Field: 'CrDate', alignment: 'left' }, // { text: 'User Name', style: 'tableheader1', Field: 'ShipToUser', alignment: 'left' }, { text: 'Item Name', style: 'tableheader1', Field: 'Name', alignment: 'left' }, { text: 'Quantity', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, ]]; return HeadingNames; } }