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 NextServiceDatePDFService { static GetNextServiceDatePrint(InvoicesData: any, CName: any, searchValue: any) { var dd = { info: { title: 'Next Service Date', }, 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: '' + CName + '', style: ['header'] }, { text: 'Next Service Date', alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData)); // }); return Data; } static getTableWidths() { // if (isHC) { // return [25, '*', '*', '*', '*']; // } else { return [20, '*', '*', '*', '*', '*', '*', '*', '*']; // } } static GetItemsTable(InvoiceData: any) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData) // 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 PhoneGetter(Customer: any) { if (!TrUtils.IsEmpty(Customer) && !TrUtils.IsEmpty(Customer.Cons) && !TrUtils.IsNull(Customer.Cons.Phones)) { return Customer.Cons.Phones.Main; } else { return ''; } } static BuildTableBodyForLaborAndParts(InvoiceData: any) { let body: any = this.GetHeaderNames(); // 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.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), 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); // } // } else { dataRow.push({ text: index + 1 }); dataRow.push({ text: invoice.Customer.DName }); dataRow.push({ text: this.PhoneGetter(invoice.Customer) }); dataRow.push({ text: invoice.RegNo }); dataRow.push({ text: invoice.Make + '' + invoice.Model + '' + invoice.Var }); // if(!isHC){ dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.DDate) }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.LSDate) }); dataRow.push({ text: invoice.LMileage }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.NSDate) }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total), alignment: 'right' }); // 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.UnAmt + invoice.Tax), 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() { 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: 'Customer Name', style: 'tableheader1', Field: 'Desc', alignment: 'left' }, { text: 'Mobile No', style: 'tableheader1', Field: 'MobileNo', alignment: 'left' }, { text: 'Reg. No', style: 'tableheader1', Field: 'Batch', alignment: 'left' }, { text: 'Vehicle', style: 'tableheader1', Field: 'Round', alignment: 'left' }, { text: 'Sale Date', style: 'tableheader1', Field: 'Total', alignment: 'left' }, { text: 'Last Service Date', style: 'tableheader1', Field: 'Total', alignment: 'left' }, { text: 'Last Mileage', style: 'tableheader1', Field: 'Total', alignment: 'left' }, { text: 'Next Service Date', style: 'tableheader1', Field: 'Total', alignment: 'left' } ] ]; // { 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; } }