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 RepairOrdersReportsPDFService { static GetRepairOrdersReportstPrint(InvoicesData: any, EntityData: any, HeaerName:any, searchValue:any) { var dd = { info: { title: 'RepairOrders', }, 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], pageOrientation: 'landscape', content: [ { text: '' + EntityData.DName + '', style: ['header'] }, { text: HeaerName, alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, EntityData.Settings.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, DecimalsNumber: number) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData, DecimalsNumber)); // }); return Data; } static getTableWidths() { // if (isHC) { return [25, 50, 50, 40,'*', 50,50,50,'*','*','*','*','*','*',50]; // } else { // return [25, '*', 40, 40, 80]; // } } static GetItemsTable(InvoiceData: any, DecimalsNumber: number) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, 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, DecimalsNumber: number) { 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 }); // if(IsSales){ dataRow.push({ text:invoice.Code, style: ['headerstyle'], }); // }else{ // dataRow.push({ text:invoice.VendName, style: ['headerstyle'], }); // } dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.CrDate) }); // dataRow.push({ text: invoice.SubTotal, alignment: 'right' }); // // if(!isHC){ // dataRow.push({ text: invoice.OfQty, alignment: 'right' }); dataRow.push({ text: invoice.Sts }); dataRow.push({ text: invoice.CBillTo.Name }); dataRow.push({ text: invoice.CBillTo.Ph }); dataRow.push({ text: invoice.Prod.RegNo }); dataRow.push({ text: invoice.Prod.VIN }); dataRow.push({ text: invoice.Prod.Model }); dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.Prod.DDate) }); dataRow.push({ text: invoice.Prod.MIn }); dataRow.push({ text: invoice.WOType.Name }); dataRow.push({ text: invoice.Name }); dataRow.push({ text: invoice.TeNa }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total, DecimalsNumber), 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.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); // } // } }); // }); return body; } static GetHeaderNames() { let HeadingNames: any; HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'RO No', style: 'tableheader1', Field: 'Code' }, { text: 'RO Date', style: 'tableheader1', Field: 'Date' }, { text: 'RO Status', style: 'tableheader1', Field: 'Sts' }, // { text: 'Offer Qty', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, // { text: 'Amount', style: 'tableheader1', Field: 'UnAmt', alignment: 'right' }, { text: 'Customer Name', style: 'tableheader1', Field: 'Name',alignment: 'left' }, { text: 'Phone', style: 'tableheader1', Field: 'Phone' }, { text: 'Reg. No', style: 'tableheader1', Field: 'RegNo' }, { text: 'VIN', style: 'tableheader1', Field: 'VIN' }, { text: 'Model', style: 'tableheader1', Field: 'Model'}, { text: 'Sale Date', style: 'tableheader1', Field: 'DDate' }, { text: 'Mileage In', style: 'tableheader1', Field: 'MIn' }, { text: 'Work Type', style: 'tableheader1', Field: 'WType' }, { text: 'Service Advisor', style: 'tableheader1', Field: 'SA'}, { text: 'Technician', style: 'tableheader1', Field: 'Tech' }, { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' }, ]]; return HeadingNames; } }