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 PaymentsReportPDFService { static GetPaymentsReportPrint(InvoicesData: any, EntityData: any, HeaerName:any, ispur:boolean,isSale:boolean, searchValue:any) { var dd = { info: { title: 'PaymentReport', }, 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, ispur, isSale, EntityData.User.TZ, EntityData.Entity.Settings.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, ispur:boolean, isSale:boolean, UserTimeZone: any, DecimalsNumber: number) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData, ispur, isSale, UserTimeZone, DecimalsNumber)); // }); return Data; } static getTableWidths() { // if (isHC) { return [22, 50, '*', 90,80, 70]; // } else { // return [25, '*', 40, 40, 80]; // } } static GetItemsTable(InvoiceData: any, ispur:boolean, isSale:boolean, UserTimeZone: any, DecimalsNumber: number) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, ispur, isSale, UserTimeZone, DecimalsNumber) // body:[['fsdfsdf','asfafdas','asdasdas','asdasdasd','asddass']] }, 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; }, // hLineStyle: function (i, node) { // return (i === 0 || i === 1) ? { dash: { length: 5, space: 5 } } : null; // }, 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, ispur:boolean, isSale:boolean, UserTimeZone: any, DecimalsNumber: number) { let body: any = this.GetHeaderNames(ispur); InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1 }); dataRow.push({ text:invoice.Code, style: ['headerstyle'], }); dataRow.push({ text: isSale?invoice.CustName:invoice.Name }); dataRow.push({ text:isSale? MyDate.ConvertUTCDateTimeToReadable(invoice.Pay.Dt, UserTimeZone):MyDate.ConvertUTCDateTimeToReadable(invoice.Date, UserTimeZone) }); dataRow.push({ text: isSale?invoice.Pay.Type:invoice.PType }); dataRow.push({ text: isSale?TrUtils.FixPriceValue(invoice.Pay?.Amt, DecimalsNumber):TrUtils.FixPriceValue(invoice.Amt, DecimalsNumber), alignment: 'right' }); body.push(dataRow); }); return body; } static GetHeaderNames(ispur:boolean) { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Transaction #', style: 'tableheader1', Field: 'Code' }, { text: ispur?'Vendor Name':'Customer Name', style: 'tableheader1', Field: 'Name',alignment: 'left' }, // { text: ispur?'Bill No':'Invoice No', style: 'tableheader1', Field: 'InvCode' }, { text: 'Payment Date', style: 'tableheader1', Field: 'Date' }, { text: 'Payment Type', style: 'tableheader1', Field: 'Type' }, // { text: 'Offer Qty', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, // { text: 'Amount', style: 'tableheader1', Field: 'UnAmt', alignment: 'right' }, { text: 'Amount Paid', style: 'tableheader1', Field: 'Total', alignment: 'right' } // { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' } ]]; return HeadingNames; } }