import { SharedPDFService } from "../../../../shared/shared-pdf.service"; import { TrUtils } from "../../../../utils/tr-utils"; // import { MyDate } from '../utils/my-date'; declare var pdfMake: any; export class SalesByCustomerPDFService { static GetSaleByCustPrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, IsSales:boolean, HeaerName:any, searchValue:any) { var dd = { info: { title: 'CustomerWiseSalesSummary', }, 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: HeaerName, alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, IsSales, EntityData.Settings?.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, isPhar: boolean, isHC: boolean, IsSales:boolean, DecimalsNumber: number) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData, isPhar, isHC, IsSales, DecimalsNumber)); // }); return Data; } static getTableWidths(isHC: any) { // if (isHC) { return [22, '*', 25, 50, 40, 40, 40, 30, 50]; // } else { // return [25, '*', 40, 40, 80]; // } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, IsSales:boolean, DecimalsNumber: number) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isHC), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, IsSales, 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, isPhar: boolean, isHC: boolean, IsSales:boolean, DecimalsNumber: number) { let body: any = this.GetHeaderNames(isPhar, isHC); InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1 }); if(IsSales){ dataRow.push({ text:invoice.CustName, style: ['headerstyle'], }); }else{ dataRow.push({ text:invoice.VendName, style: ['headerstyle'], }); } dataRow.push({ text: invoice.Count, 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) { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Name', style: 'tableheader1', Field: 'Name' }, { text: 'Count', style: 'tableheader1', Field: 'Count', 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: 'Adjust', style: 'tableheader1', Field: 'Adjust', alignment: 'right' }, { text: 'Round', style: 'tableheader1', Field: 'Round', alignment: 'right' }, { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' }]]; return HeadingNames; } }