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 CustomerBalancesService { static GetCustomerBalancesPrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean) { var dd = { info: { title: 'CustomerBalances', }, 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: 'Customer Balances', alignment: 'center', fontSize: 15, bold: true }, { text: 'As of ' + MyDate.GetTodayReadable(EntityData.User.TZ), alignment: 'center', fontSize: 10 }, // SharedPDFService.HeaderAfterLine(), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, EntityData.Entity.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(invoice, isPhar, isHC, DecimalsNumber)); }); return Data; } static getTableWidths(isHC: any) { if (isHC) { return [25, '*', '*', '*', '*']; } else { return [25, 60, 70, '*',70, 80, 50, 50]; } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, DecimalsNumber: number) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isHC), headerRows: 2, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, DecimalsNumber) // body:[['fsdfsdf','asfafdas','asdasdas','asdasdasd','asddass']] }, layout: { hLineWidth: function (i:any, node:any) { return (i === 0 || i === 1 || i === 2 || i === node.table.body.length - 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 === 2 || i === node.table.body.length - 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); let Row: any = [{ text: InvoiceData.Name, alignment: 'left', colSpan: isHC ? 5 : 8, bold: true, fontSize: 12 }, {}, {}, {}, {}]; if (!isHC) { Row.push({}); Row.push({}); Row.push({}); } body.unshift(Row); // InvoicesData.forEach((InvoiceData: any) => { InvoiceData.Invoices.forEach((invoice: any, index: any) => { let dataRow: any = []; if (isHC) { dataRow.push({ text: index + 1 }); dataRow.push({ text: invoice.Code }); if (!isHC) { dataRow.push({ text: invoice.Prod?.RegNo }); dataRow.push({ text: TrUtils.IsNull(invoice.Prod) ? '' : invoice.Prod?.Model + ' ' + invoice.Prod?.Var }); } // dataRow.push({ text: invoice.BFrom.Name, alignment: 'left', style: ['headerstyle'], }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.CrDate), alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Due, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); if (InvoiceData.Invoices.length === (index + 1)) { let Row: any = [{ text: 'Total Due ', alignment: 'right', colSpan: isHC ? 4 : 6, bold: true, fontSize: 9 }, {}, {}, {}, { text: TrUtils.FixPriceValue(InvoiceData.Balance, DecimalsNumber), fontSize: 9, alignment: 'right', bold: true }]; if (!isHC) { Row.splice(2, 0, {}, {}); // Row.push({}); } body.push(Row); } } else { dataRow.push({ text: index + 1 }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.CrDate), alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: invoice.Code }); dataRow.push({ text: invoice.BillTo?.Name }); // if(!isHC){ dataRow.push({ text: invoice.Prod?.RegNo }); dataRow.push({ text: invoice.Name }); dataRow.push({ text: invoice.WCode }); // dataRow.push({ text: TrUtils.IsNull(invoice.Prod) ? '' : invoice.Prod?.Model + ' ' + invoice.Prod?.Var }); // } // dataRow.push({ text: invoice.BFrom.Name, alignment: 'left', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Due), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); // if (InvoiceData.Invoices.length === (index + 1)) { // let Row: any = [{ text: 'Total Due ', alignment: 'right', colSpan: isHC?4:6, bold: true, fontSize: 9 }, {}, {}, {}, { text: TrUtils.FixPriceValue(InvoiceData.Balance), fontSize: 9, alignment: 'right', bold: true }]; // if(!isHC){ // Row.splice(2, 0,{},{}); // // Row.push({}); // } // body.push(Row); // } } }); // }); return body; } static GetHeaderNames(isPhar: boolean, isHC: boolean) { let HeadingNames: any; if (isHC) { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: isPhar ? 'Counter Sale Number' : 'Invoice Number', style: 'tableheader1', Field: 'BNo', alignment: 'left' }, { text: 'Create Date', style: 'tableheader1', Field: 'CrDate' }, { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' }, { text: 'Due', style: 'tableheader1', Field: 'Due', alignment: 'right' }]]; if (!isHC) { HeadingNames[0].splice(2, 0, { text: 'Reg No', style: 'tableheader1', Field: 'Reg No', alignment: 'left' } , { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // HeadingNames.splice(3, 0, { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); } } else { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Date', style: 'tableheader1', Field: 'CrDate' }, { text: isPhar ? 'Counter Sale Number' : 'Invoice No', style: 'tableheader1', Field: 'BNo', alignment: 'left' }, { text: 'Customer', style: 'tableheader1', Field: 'Cust' }, { text: 'Vehicle Reg No', style: 'tableheader1', Field: 'RegNo' }, { text: 'Advisor Name', style: 'tableheader1', Field: 'Name' }, { text: 'RO No', style: 'tableheader1', Field: 'WCode' }, { text: 'Amount', style: 'tableheader1', Field: 'Total', alignment: 'right' }]]; // { text: 'Due', style: 'tableheader1', Field: 'Due', alignment: 'right' }]]; // if (!isHC) { // HeadingNames[0].splice(2, 0, { text: 'Reg No', style: 'tableheader1', Field: 'Reg No', alignment: 'left' } // , { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // // HeadingNames.splice(3, 0, { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // } } return HeadingNames; } }