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 CategoryWiseItemPDFService { static GetCategoryWiseItemSales(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, isSale: boolean, searchValue: any) { var dd = { info: { title: isSale ? 'CategoryWiseItem' : 'CategoryWiseService', }, 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.Dame + '', style: ['header'] }, { text: isSale ? 'Category Wise Item Sales' : 'Category Wise Service Sales', alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, isSale, EntityData.Settings?.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, isPhar: boolean, isHC: boolean, isSale: boolean, DecimalsNumber: number) { let Data: any = [] Data.push(this.GetItemsTable(InvoicesData, isPhar, isHC, isSale, DecimalsNumber)); return Data; } static getTableWidths(isHC: any) { // if (isHC) { // return [25, '*', '*', '*', '*']; // } else { return [22, '*', 25, 25, 50, 35, 40, 50, 60]; // } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, isSale: boolean, DecimalsNumber: number) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isHC), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, isSale, 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, isSale: boolean, DecimalsNumber: number) { let body: any = this.GetHeaderNames(isPhar, isHC, isSale); InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1 }); dataRow.push({ text: invoice.Name }); dataRow.push({ text: invoice.Count }); dataRow.push({ text: invoice.Qty }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.UnAmt, 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.NetAmt, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.AvgAmt, DecimalsNumber), alignment: 'right' }); body.push(dataRow); }); return body; } static GetHeaderNames(isPhar: boolean, isHC: boolean, isSale: boolean) { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Category', style: 'tableheader1', Field: 'Code' }, { text: 'Count', style: 'tableheader1', Field: 'CrDate' }, { text: 'Qty', style: 'tableheader1', Field: 'Name' }, { text: 'Unit Amount', style: 'tableheader1', Field: 'SubTotal', alignment: 'right' }, { text: 'Discount', style: 'tableheader1', Field: 'Disc', alignment: 'right' }, { text: 'Tax', style: 'tableheader1', Field: 'Tax', alignment: 'right' }, { text: 'Net Amount', style: 'tableheader1', Field: 'Adjust', alignment: 'right' }, { text: 'Avarage Amount', style: 'tableheader1', Field: 'Round', alignment: 'right' }, ]]; return HeadingNames; } }