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 ProductWithoutOwnerPDFService { static GetProductWithoutOwnerReport(ProductsData: any, EntityData: any, HeaderName: any, searchValue: any) { var dd = { info: { title: 'EndOwnerShipReport', }, 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 }, this.GetSearchValueDetails(searchValue), this.GetProductsDataTable(ProductsData), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetSearchValueDetails(searchValue: any) { if (!TrUtils.IsNull(searchValue)) { return SharedPDFService.GetSearchValueDetails(searchValue); } return {}; } static GetProductsDataTable(ProductsData: any) { let Data: any = [] // ProductsData.forEach((product: any) => { Data.push(this.GetProductsTable(ProductsData)); // }); return Data; } static getTableWidths() { return [25, '*', 55, 100, 50, 60, 50, 50]; } static GetProductsTable(ProductsData: any) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(), headerRows: 1, body: this.BuildTableBodyForwithoutOwnerProducts(ProductsData) }, 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 BuildTableBodyForwithoutOwnerProducts(ProductsData: any) { let body: any = this.GetHeaderNames(); ProductsData.forEach((product: any, index: any) => { let Vehicle: string = this.ProductValue(product); product.OwnershipStartDate = MyDate.ConvertUTCDateToReadable(product.OwnershipStartDate || product.OwnershipFrom); product.OwnershipEndDate = MyDate.ConvertUTCDateToReadable(product.OwnershipEndDate || product.OwnershipTo); let dataRow: any = []; dataRow.push({ text: index + 1 }); dataRow.push({ text: product.LastOwnerName || product.CustomerName, style: ['headerstyle'], }); dataRow.push({ text: product.LastOwnerPhone || product.Phone, alignment: 'center' }); // dataRow.push({ text: invoice.Qty, alignment: 'right' }); // dataRow.push({ text: invoice.OfQty, alignment: 'right' }); dataRow.push({ text: Vehicle, alignment: 'center' }); dataRow.push({ text: product.RegistrationNo, alignment: 'center' }); dataRow.push({ text: product.VIN, alignment: 'center' }); dataRow.push({ text: product.OwnershipStartDate, alignment: 'center' }); dataRow.push({ text: product.OwnershipEndDate, alignment: 'center' }); body.push(dataRow); }); return body; } static ProductValue(ProductInfo: any) { // if (!this.isOtherIndustry) { let prod: string = ''; if (!TrUtils.IsNull(ProductInfo.Model)) { prod = prod + ProductInfo.Model; } if (!TrUtils.IsNull(ProductInfo.Year)) { prod = prod + ' ' + ProductInfo.Year; } if (!TrUtils.IsNull(ProductInfo.Variant)) { prod = prod + ' ' + ProductInfo.Variant; } return prod; // } else { // return params.data.Model; // } } static GetHeaderNames() { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Customer Name', style: 'tableheader1', Field: 'Name' }, { text: 'Phone', style: 'tableheader1', Field: 'Phone', alignment: 'center' }, { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'center' }, { text: 'Regn No', style: 'tableheader1', Field: 'RegNo', alignment: 'center' }, { text: 'VIN', style: 'tableheader1', Field: 'VIN', alignment: 'center' }, { text: 'Ownership Start Date', style: 'tableheader1', Field: 'Start', alignment: 'center' }, { text: 'Ownership End Date', style: 'tableheader1', Field: 'End', alignment: 'center' }, ]]; return HeadingNames; } }