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 ItemWiseMODetailsPDF { static GetItemWiseMODetailsPrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, HeaderName: any, searchValue: any) { var dd = { info: { title: 'ItemWiseMO', }, 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], pageOrientation: 'landscape', 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) { return [25, 50, 50,50, 100, '*',100, 40, 50, 40,100]; } 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: MyDate.ConvertUTCDateToReadable(invoice.CrDate), alignment: 'left' }); // dataRow.push({ text: invoice.Qty, alignment: 'right' }); // dataRow.push({ text: invoice.OfQty, alignment: 'right' }); dataRow.push({ text: invoice.BL?.VNo, alignment: 'left' }); dataRow.push({ text: invoice.ShipToUser, alignment: 'left' }); dataRow.push({ text: invoice.Name, alignment: 'left' }); dataRow.push({ text: invoice.MPN, 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: invoice.Notes, 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: 'Vehicle No', style: 'tableheader1', Field: 'VNo', alignment: 'left' }, { text: 'User Name', style: 'tableheader1', Field: 'ShipToUser', alignment: 'left' }, { text: 'Item Name', style: 'tableheader1', Field: 'Name', alignment: 'left' }, { text: 'MPN', style: 'tableheader1', Field: 'MPN', alignment: 'left' }, { text: 'Quantity', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Reason Name', style: 'tableheader1', Field: 'ReName', alignment: 'left' }, { text: 'Status', style: 'tableheader1', Field: 'Sts', alignment: 'left' }, { text: 'Notes', style: 'tableheader1', Field: 'Notes', alignment: 'left' }, // { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' } ]]; return HeadingNames; } }