import { SharedPDFService } from "../../shared/shared-pdf.service"; import { PrintSharedService } from "../../shared/shared-print.service"; import { TrUtils } from "../../utils/tr-utils"; export class HCInvoiceprintService { FontSize: number = 8; static GetInvoicePrint(ROPrintData: any, numberofCopies: any, isotherIndustry: boolean, withPass: boolean, isAuto: boolean, size: any, moreDiscDetails: boolean) { ROPrintData.Entity.IsProforma = ROPrintData.IsProforma; var contents = []; if (TrUtils.IsNull(numberofCopies) || numberofCopies.length === 0) { contents.push( this.CommonHeaderDetails(ROPrintData, null, isotherIndustry), this.PreparesparePartsTable(ROPrintData, isAuto), this.CommonTotalDetails(ROPrintData, null, numberofCopies, withPass, isAuto, moreDiscDetails) ); } else { numberofCopies.forEach((text: any, index: any) => { contents.push( this.CommonHeaderDetails(ROPrintData, text, isotherIndustry), this.PreparesparePartsTable(ROPrintData, isAuto), this.CommonTotalDetails(ROPrintData, index, numberofCopies, withPass, isAuto, moreDiscDetails) ); }); } var dd = { watermark: this.GetWatermark(ROPrintData), info: { title: this.GetFileName(ROPrintData), }, background: function (currentPage: any, pageSize: any) { if (size !== 'full') { pageSize.height = pageSize.height - 435.945; } return SharedPDFService.GetWatermarkImage(ROPrintData.Image, pageSize, ROPrintData.Entity.Wmark); }, header: function (currentPage: any, pageCount: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 7, fontSize: 8, marginTop: 2 }; }, pageBreakBefore: function (currentNode: any, followingNodesOnPage: any, nodesOnNextPage: any, previousNodesOnPage: any) { return currentNode.startPosition.top >= 700 && !TrUtils.IsNull(currentNode?.id) && currentNode?.id === '567'; }, // pageMargins: [10, 15, 10, 15], pageMargins: this.GetMarginsBasedOnPaperSize(size), pageSize: 'A4', content: contents, styles: SharedPDFService.GetStyles() }; return dd; } static GetMarginsBasedOnPaperSize(size: any) { if (size === 'full') { return [25, 15, 15, 15]; } else { return [25, 15, 15, 435.945]; } } static GetWatermark(ROPrintData: any) { if (ROPrintData.IsProforma && ROPrintData.Entity.Wmark) { return { text: 'Not a final invoice', opacity: 0.2 }; } else { return ''; } } static GetFileName(ROPrintData: any) { let fileName: string = ROPrintData.HeaderName; if (!TrUtils.IsNull(ROPrintData.Product) && !TrUtils.IsEmpty(ROPrintData.Product.RegNo)) { fileName = fileName + '-' + ROPrintData.Product.RegNo; } return fileName; } static CommonHeaderDetails(ROPrintData: any, text: any, isotherIndustry: boolean) { return [ this.GetMainHeaderDetails(ROPrintData.Entity, ROPrintData.HeaderName, ROPrintData.Image, ROPrintData.HColor, ROPrintData.AColor, text), SharedPDFService.GetCustomerAndVehicleDetails(ROPrintData._id, ROPrintData.CrDate, ROPrintData.PrDate, ROPrintData.MOut, ROPrintData.MIn, ROPrintData.Product, ROPrintData.PrintType, ROPrintData.For, ROPrintData.SurName, ROPrintData.SurPhone, ROPrintData.Type, ROPrintData.SurEmail, ROPrintData.InsComp, ROPrintData.PolNo, ROPrintData.PolType, ROPrintData.Customer, ROPrintData.IsProforma, null, ROPrintData.Location, isotherIndustry, ROPrintData.BL, ROPrintData.ROCode, ROPrintData.TypeName, ROPrintData.AdmNo, ROPrintData.DoS, ROPrintData.Entity.PrCustBar), SharedPDFService.GetOwnerDetails(ROPrintData.Cust, ROPrintData.Type, ROPrintData.For), this.CustomerAndVehicleDetailsAfterLine(), SharedPDFService.GetDisplayTable(), ]; } static CustomerAndVehicleDetailsAfterLine() { return { canvas: [ { type: 'line', lineColor: 'grey', x1: 0, y1: 0, x2: 555, y2: 0, lineWidth: 1.5 } ] }; } static GetMainHeaderDetails(Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any) { return [ // SharedPDFService.MainHeading(Entity.CName, Entity.Header, Image, HColor, text), SharedPDFService.GetMainHeader(Entity, Image, AColor, HColor, text), this.GetPrintType(HeaderName, Entity.RegNo), this.HeaderAfterLine() ]; } static HeaderAfterLine() { return { canvas: [ { type: 'line', lineColor: 'grey', x1: 0, y1: 0, x2: 555, y2: 0, lineWidth: 1.5 } ] }; } static GetPrintType(type: any, RegNo: any) { return { // marginLeft: 10, columns: [{ text: '', width: 120 }, { text: type, alignment: 'center', style: 'Receiptheader1' }, { text: 'Regn.No : ' + RegNo, alignment: 'right', width: 140, fontSize: 7 } ] }; } static PreparesparePartsTable(ROPrintData: any, isAuto: boolean) { let List: any = []; if (ROPrintData.Entity.Body === 1) { for (let i = 0; i < ROPrintData.PrintInfo.length; i++) { if (TrUtils.IsNull(ROPrintData.PrintInfo[i].Text)) { ROPrintData.PrintInfo[i].Text = ''; } List.push(ROPrintData.PrintInfo[i].Text, this.GetLaborPartsTableForView(TrUtils.Stringify(ROPrintData.PrintInfo[i].Items), TrUtils.Stringify(ROPrintData.PrintInfo[i].Ops), false) ); } } else { if (ROPrintData.Entity.Body === 2) { for (let i = 0; i < ROPrintData.PrintInfo.length; i++) { if (TrUtils.IsNull(ROPrintData.PrintInfo[i].Text)) { ROPrintData.PrintInfo[i].Text = ''; } List.push(ROPrintData.PrintInfo[i].Text, this.WithOutDiscountFieldTable(TrUtils.Stringify(ROPrintData.PrintInfo[i].Items), TrUtils.Stringify(ROPrintData.PrintInfo[i].Ops), ROPrintData.ShowTaxColumn, false, ROPrintData.Entity.Body, ROPrintData.ShowIGST, ROPrintData.ConsolidateGST, ROPrintData.ShowDiscountColumn, isAuto, ROPrintData.Entity.DecimalsNumber) ); } } else { if (ROPrintData.Summary) { List.push('', this.GetLaborPartsTableForView(ROPrintData.Items, ROPrintData.Ops, false) ); } else { for (let i = 0; i < ROPrintData.PrintInfo.length; i++) { if (TrUtils.IsNull(ROPrintData.PrintInfo[i].Text)) { ROPrintData.PrintInfo[i].Text = ''; } List.push(ROPrintData.PrintInfo[i].Text, this.GetWithOutDiscAndTaxFieldHeader(TrUtils.Stringify(ROPrintData.PrintInfo[i].Items), TrUtils.Stringify(ROPrintData.PrintInfo[i].Ops), ROPrintData.ShowTaxColumn, false, ROPrintData.Entity.Body, ROPrintData.ShowIGST, ROPrintData.ConsolidateGST, ROPrintData.ShowDiscountColumn, isAuto, ROPrintData.Entity.DecimalsNumber) ); } } } } return List; } static GetLaborPartsTableForView(Parts: any, Ops: any, PrintPartNo: any) { if (Parts.length !== 0 || Ops.length !== 0) { if (PrintPartNo) { return { style: 'tableExample', // marginLeft: 20, table: { widths: [25, 30, 170, 85, 15, 20, 50, 30, 30, 50], // headerRows: 2, body: this.buildTableForCustomerLabor(Parts, Ops, PrintPartNo, false) }, layout: PrintSharedService.LayOutStyleanother() }; } else { return { style: 'tableExample', // marginLeft: 20, table: { widths: [25, 200, 55, 25, 55, 55, 40, 15, 50], // headerRows: 2, body: this.buildTableForCustomerLabor(Parts, Ops, PrintPartNo, false) }, layout: PrintSharedService.LayOutStyleanother() }; } } else { let a: any = ''; return a; } } static WithOutDiscountFieldTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { if (Parts.length !== 0 || Ops.length !== 0) { if (PrintPartNo) { return { style: 'tableExample', marginLeft: 20, table: { widths: [25, 60, 155, 30, 50, 60, 30, 50], headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyleanother() }; } else { return { style: 'tableExample', marginLeft: 20, table: { widths: [25, 215, 25, 50, 60, 45, 50], headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyleanother() }; } } else { let a: any = ''; return a; } } static BuildTableBodyForLaborAndParts(Parts: any, Labor: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { var body: any = []; let columns: any = PrintSharedService.GetWithOutDiscountFieldHeader(PrintPartNo, ShowTaxColumn, Body, ShowIGST, ShowDiscountColumn); // if (ShowTaxColumn) { for (let i = 0; i < columns.length; i++) { body.push(columns[i]); } columns = columns[1]; // } else { // body.push(columns); // } let DummyOps: any = []; if (Parts.length !== 0) { // console.log('Parts', Parts); if (isAuto) { let Qty: number = 0; let CGSTAMT: number = 0; let SGSTAMT: number = 0; let IGSTAMT: number = 0; let Taxable: number = 0; let FinalTotal: number = 0; Parts.forEach((part: any) => { // console.log('part', part); Qty = Qty + part.Qty; CGSTAMT = CGSTAMT + part.CGSTAmt; SGSTAMT = SGSTAMT + part.SGSTAmt; IGSTAMT = IGSTAMT + part.IGSTAmt; Taxable = Taxable + part.AfterPartDisc; FinalTotal = FinalTotal + part.AfterPartTax; }); let dpartadding1: any = {}; dpartadding1.SNo = ''; dpartadding1.Desc = 'Medications Total'; dpartadding1.QtyAndUoM = TrUtils.FixedTo(Qty, DecimalsNumber); dpartadding1.bold = true; dpartadding1.UnPr = TrUtils.FixedTo(Taxable, DecimalsNumber); dpartadding1.SGSTAmt = TrUtils.FixedTo(SGSTAMT, DecimalsNumber); dpartadding1.IGSTAmt = TrUtils.FixedTo(IGSTAMT, DecimalsNumber); dpartadding1.CGSTAmt = TrUtils.FixedTo(CGSTAMT, DecimalsNumber); dpartadding1.TCode = ShowTaxColumn ? 114 : undefined; dpartadding1.LineTotal = TrUtils.FixPriceValue(FinalTotal, DecimalsNumber); Parts.push({ SNo: '' }); Parts.push(dpartadding1); } let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = ' '; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.LineTotal = ''; // Parts.unshift(dummypartadding1); } let SNo: number = 1; Parts.forEach((part: any) => { var dataRow: any = []; columns.forEach((column: any) => { if ( (!TrUtils.IsNull(part[column.Field])) || (column.text === 'Line Total')) { // if (part[column.Field] === 'Medications') { // dataRow.push({ text: part[column.Field].toString(), marginLeft: 50, style: 'InlineHeader' }); // } else { if (((column.Field === 'CGSTAmt' || column.Field === 'SGSTAmt' || column.Field === 'CGSTPerc' || column.Field === 'SGSTPerc' || column.Field === 'IGSTAmt' || column.Field === 'IGSTPerc') && TrUtils.CheckInvalidSelect(part.TCode))) { part[column.Field] = ''; dataRow.push({ text: part[column.Field].toString(), alignment: 'center' }); } else { if (column.text === 'Line Total' || column.Field === 'UnPr' || column.Field === 'HSN' || column.Field === 'QtyAndUoM' || column.text === 'Tax' || column.Field === 'Disc' || column.Field === 'Perc' || column.Field === 'CGSTAmt' || column.Field === 'SGSTAmt' || column.Field === 'CGSTPerc' || column.Field === 'SGSTPerc' || column.Field === 'IGSTAmt' || column.Field === 'IGSTPerc') { if (column.Field === 'Disc') { if (column.type === 'percentage') { if (!TrUtils.IsEmpty(part[column.Field])) { dataRow.push({ text: part[column.Field].toString(), noWrap: true, alignment: 'right' }); } else { dataRow.push({ text: '', noWrap: true }); } } else { if (!TrUtils.IsNull(part[column.Field])) { dataRow.push({ text: TrUtils.FixPriceValue(part[column.Field]).toString(), alignment: 'right', noWrap: true }); } else { dataRow.push({ text: '', noWrap: true }); } } } else { if (!TrUtils.IsNull(part[column.Field])) { dataRow.push({ text: part[column.Field].toString(), bold: part.bold, alignment: 'right', nowrap: true }); } else { dataRow.push({ text: '', noWrap: true }); } } } else { // dataRow.push(part[column.Field].toString()); if (column.Field === 'Desc') { let DescData: any = []; DescData.push({ text: part[column.Field].toString(), bold: part.bold }); if (!TrUtils.IsEmpty(part['EDesc'])) { DescData.push({ text: part['EDesc'].toString(), color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: part[column.Field].toString() }); } } } // } } else { if (column.Field === 'SNo') { part[column.Field] = SNo; SNo = SNo + 1; } else { if (TrUtils.IsNull(part[column.Field])) { part[column.Field] = ''; } } dataRow.push({ text: part[column.Field].toString(), alignment: 'center' }); } }); body.push(dataRow); }); SNo = 1; if (Labor.length !== 0 && Parts.length !== 0) { // let Qty: number = 0; if (isAuto) { let CGSTAMT: number = 0; let SGSTAMT: number = 0; let IGSTAMT: number = 0; let Taxable: number = 0; let FinalTotal: number = 0; Labor.forEach((operation: any) => { // console.log('operation', operation); // Qty = Qty + operation.Qty; CGSTAMT = CGSTAMT + operation.CGSTAmt; SGSTAMT = SGSTAMT + operation.SGSTAmt; IGSTAMT = IGSTAMT + operation.IGSTAmt; Taxable = Taxable + operation.AfterLaborDisc; FinalTotal = FinalTotal + operation.AfterLaborTax; }); let dpartadding1: any = {}; dpartadding1.SNo = ''; dpartadding1.Desc = 'Procedures Total'; // dpartadding1.QtyAndUoM = Qty; dpartadding1.UnPr = TrUtils.FixedTo(Taxable, DecimalsNumber); dpartadding1.SGSTAmt = TrUtils.FixedTo(SGSTAMT, DecimalsNumber); dpartadding1.IGSTAmt = TrUtils.FixedTo(IGSTAMT, DecimalsNumber); dpartadding1.CGSTAmt = TrUtils.FixedTo(CGSTAMT, DecimalsNumber); dpartadding1.TCode = ShowTaxColumn ? 114 : undefined; dpartadding1.bold = true; dpartadding1.LineTotal = TrUtils.FixPriceValue(FinalTotal, DecimalsNumber); Labor.push({ SNo: '' }); Labor.push(dpartadding1); } let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = ' '; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.LineTotal = ''; Labor.unshift(dummypartadding1); // DummyOps.unshift(dummypartadding1); } if (Body === 2) { for (let i = 0; i < Labor.length; i++) { Labor[i].UnPr = ''; } } Labor.forEach((Ops: any) => { var dataRow: any = []; columns.forEach((column: any) => { if ((!TrUtils.IsNull(Ops[column.Field])) || (column.text === 'Line Total')) { if (Ops[column.Field] === 'Procedures') { dataRow.push({ text: Ops[column.Field].toString(), marginLeft: 50, style: 'InlineHeader' }); } else { if (((column.Field === 'CGSTAmt' || column.Field === 'SGSTAmt' || column.Field === 'CGSTPerc' || column.Field === 'SGSTPerc' || column.Field === 'IGSTAmt' || column.Field === 'IGSTPerc') && TrUtils.CheckInvalidSelect(Ops.TCode))) { Ops[column.Field] = ''; dataRow.push({ text: Ops[column.Field].toString(), alignment: 'center' }); } else { if (column.text === 'Line Total' || column.Field === 'Price' || column.Field === 'HSN' || column.text === 'Tax' || column.Field === 'UnPr' || column.Field === 'QtyAndUoM' || column.Field === 'Disc' || column.Field === 'Perc' || column.Field === 'CGSTAmt' || column.Field === 'SGSTAmt' || column.Field === 'CGSTPerc' || column.Field === 'SGSTPerc' || column.Field === 'IGSTAmt' || column.Field === 'IGSTPerc') { if (column.Field === 'Disc') { if (column.type === 'percentage') { if (!TrUtils.IsEmpty(Ops[column.Field])) { dataRow.push({ text: Ops[column.Field].toString(), alignment: 'right', noWrap: true }); } else { dataRow.push({ text: '', noWrap: true }); } } else { if (!TrUtils.IsNull(Ops[column.Field])) { dataRow.push({ text: TrUtils.FixPriceValue(Ops[column.Field]).toString(), alignment: 'right', noWrap: true }); } else { dataRow.push({ text: '', noWrap: true }); } } } else { if (!TrUtils.IsNull(Ops[column.Field])) { dataRow.push({ text: Ops[column.Field].toString(), alignment: 'right', nowrap: true, bold: Ops.bold }); } else { dataRow.push({ text: '', noWrap: true }); } } } else { if (column.Field === 'Desc') { let DescData: any = []; DescData.push({ text: Ops[column.Field].toString(), bold: Ops.bold }); if (!TrUtils.IsEmpty(Ops['EDesc'])) { DescData.push({ text: Ops['EDesc'].toString(), color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: Ops[column.Field].toString(), bold: Ops.bold }); } } } } } else { if (column.Field === 'SNo') { Ops[column.Field] = SNo; SNo = SNo + 1; } else { if (TrUtils.IsNull(Ops[column.Field])) { Ops[column.Field] = ''; } } dataRow.push({ text: Ops[column.Field].toString(), alignment: 'center' }); } }); body.push(dataRow); }); return body; } static GetWithOutDiscAndTaxFieldHeader(Parts: any, Ops: any, ShowTaxColumn: any, PrintPartNo: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { if (Parts.length !== 0 || Ops.length !== 0) { if (ShowTaxColumn) { return this.TaxDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber); } else { if (ConsolidateGST) { return this.ConsolidateDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber); } else { return this.NoTaxDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber); } } } else { let a: any = ''; return a; } } static TaxTableWidths(PrintPartNo: any, ShowIGST: any, ShowDiscountColumn: any) { if (PrintPartNo) { if (ShowIGST) { if (ShowDiscountColumn) { return [22, 50, 143, 35, 25, 40, 17, 35, 17, 35, 45]; } else { return [22, 50, 207, 37, 25, 40, 17, 35, 51]; } } else { if (ShowDiscountColumn) { return [22, 40, 90, 35, 22, 40, 17, 34, 17, 32, 17, 32, 48]; } else { return [22, 50, 135, 40, 22, 40, 17, 32, 17, 32, 54]; } } } else { if (ShowIGST) { if (ShowDiscountColumn) { return [22, 200, 40, 25, 40, 17, 35, 17, 35, 41]; } else { return [22, 255, 40, 25, 40, 20, 40, 50]; } } else { if (ShowDiscountColumn) { return [22, 135, 34, 22, 40, 17, 34, 17, 35, 17, 35, 45]; } else { return [22, 195, 35, 22, 40, 17, 35, 17, 35, 50]; } } } } static TaxDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { if (PrintPartNo) { if (ShowIGST) { return { style: 'tableExample', table: { widths: this.TaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn), // headerRows: 2, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } else { return { style: 'tableExample', table: { widths: this.TaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn), // headerRows: 2, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } } else { if (ShowIGST) { return { style: 'tableExample', table: { widths: this.TaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn), // headerRows: 2, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } else { return { style: 'tableExample', table: { widths: this.TaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn), // headerRows: 2, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } } } static ConsolidateDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { if (PrintPartNo) { return { style: 'tableExample', table: { widths: [25, 70, 263, 25, 60, 80, 10, 40], // headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } else { return { style: 'tableExample', table: { widths: [25, 295, 50, 80, 80, 10, 40], // headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } } static NoTaxDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, isAuto: boolean, DecimalsNumber: number) { if (PrintPartNo) { return { style: 'tableExample', table: { widths: PrintSharedService.WidthForInsuranceOrNot(ShowDiscountColumn, PrintPartNo), // headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } else { return { style: 'tableExample', table: { widths: PrintSharedService.WidthForInsuranceOrNot(ShowDiscountColumn, PrintPartNo), // headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, isAuto, DecimalsNumber) }, layout: PrintSharedService.LayOutStyle1() }; } } static buildTableForCustomerLabor(Parts: any, Ops: any, PrintPartNo: any, customerorInsurance: any) { var body: any = []; let columns: any; columns = this.getSummaryHeaders(PrintPartNo); body.push(columns); if (Parts.length !== 0) { let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = ' '; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.Price = ''; dummypartadding1.DiscountedPrice = ''; dummypartadding1.LineTotal = ''; dummypartadding1.QtyAndUoM = ''; dummypartadding1.HSN = ''; dummypartadding1.MPN = ''; // Parts.unshift(dummypartadding1); } let SNo: number = 1; Parts.forEach((part: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (!TrUtils.IsNull(part[column.Field]) || column.text === 'Line Total') { // if (part[column.Field] === 'Medications') { // dataRow.push({ text: part[column.Field].toString(), marginLeft: 50, style: 'InlineHeader' }); // } else { // tslint:disable-next-line:max-line-length if (column.text === 'Line Total' || column.Field === 'QtyAndUoM' || column.Field === 'CustPrice' || column.Field === 'InsPrice' || column.Field === 'DiscountedPrice' || column.Field === 'TaxAmount' || column.Field === 'UnPr') { if (column.Field === 'Disc Amt') { dataRow.push({ text: part[column.Field].toString(), alignment: 'right', noWrap: true }); } else { dataRow.push({ text: part[column.Field].toString(), alignment: 'right', nowrap: true }); } } else { if (column.Field === 'Desc') { let DescData: any = []; DescData.push(part[column.Field].toString()); if (!TrUtils.IsEmpty(part['EDesc'])) { DescData.push({ text: part['EDesc'].toString(), color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: part[column.Field].toString() }); } } // } } else { if (column.Field === 'SNo') { part[column.Field] = SNo; SNo = SNo + 1; } else { if (TrUtils.IsNull(part[column.Field])) { part[column.Field] = ''; } } dataRow.push({ text: part[column.Field].toString(), alignment: 'center' }); } }); body.push(dataRow); }); SNo = 1; if (Ops.length !== 0 && Parts.length !== 0) { let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = ' '; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.Price = ''; dummypartadding1.DiscountedPrice = ''; dummypartadding1.LineTotal = ''; dummypartadding1.QtyAndUoM = ''; dummypartadding1.HSN = ''; Ops.unshift(dummypartadding1); } Ops.forEach((labor: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (!TrUtils.IsNull(labor[column.Field]) || column.text === 'Line Total') { if (labor[column.Field] === 'Procedures') { dataRow.push({ text: labor[column.Field].toString(), marginLeft: 50, style: 'InlineHeader' }); } else { if (column.text === 'Line Total' || column.Field === 'QtyAndUoM' || column.Field === 'DiscountedPrice' || column.Field === 'TaxAmount' || column.Field === 'UnPr' || column.Field === 'CustPrice' || column.Field === 'InsPrice') { if (column.Field === 'Disc Amt') { dataRow.push({ text: labor[column.Field].toString(), alignment: 'right', noWrap: true }); } else { dataRow.push({ text: labor[column.Field].toString(), alignment: 'right', nowrap: true }); } } else { // dataRow.push({ text: labor[column.Field].toString() }); if (column.Field === 'Desc') { let DescData: any = []; DescData.push(labor[column.Field].toString()); if (!TrUtils.IsEmpty(labor['EDesc'])) { DescData.push({ text: labor['EDesc'].toString(), color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: labor[column.Field].toString() }); } } } } else { if (column.Field === 'SNo') { labor[column.Field] = SNo; SNo = SNo + 1; } else { if (TrUtils.IsNull(labor[column.Field])) { labor[column.Field] = ''; } } dataRow.push({ text: labor[column.Field].toString(), alignment: 'center' }); } }); body.push(dataRow); }); return body; } static getSummaryHeaders(permission: boolean) { let headersNames: any = [{ text: 'Description', style: 'tableheader', Field: 'Desc' }, { text: 'HSN / SAC', style: 'tableheader', Field: 'SAC' }, { text: 'Qty', style: 'tableheader', Field: 'QtyAndUoM' }, // { text: 'Rate / Unit', style: 'tableheader', Field: 'UnPr' }, { text: 'Ins. Amt', style: 'tableheader', Field: 'AssPr' }, { text: 'Cust. Amt', style: 'tableheader', Field: 'Pr' }, { text: 'Disc.(Rs)', style: 'tableheader', Field: 'DiscountedPrice' }, { text: 'Tax %', style: 'tableheader', Field: 'TaxAmount' }, { text: 'Line Total', style: 'tableheader', Field: 'LineTotal' }]; if (permission) { let sno = { text: 'S.No.', style: 'tableheader', Field: 'SNo' }; let MPN = { text: 'Part No', style: 'tableheader', Field: 'MPN' }; headersNames.unshift(sno, MPN); } else { let sno = { text: 'S.No.', style: 'tableheader', Field: 'SNo' }; headersNames.unshift(sno); } return headersNames; } static CommonTotalDetails(ROPrintData: any, index: any, numberofCopies: any, withPass: boolean, isAuto: boolean, moreDiscDetails: boolean) { // console.log('ROPrintData', ROPrintData); let CommonDetails = [ SharedPDFService.GetFinalTotalDetails1(ROPrintData, ROPrintData.CustLaborTotalAfterDisc, ROPrintData.CustLaborDiscTotal, ROPrintData.CustLaborCGST, ROPrintData.CustLaborSGST, ROPrintData.CustLaborIGST, ROPrintData.CustPartIGST, ROPrintData.ShowIGST, ROPrintData.ShowTaxColumn, ROPrintData.CustPartsTotalAfterDisc, ROPrintData.CustPartsDiscTotal, ROPrintData.CustPartCGST, ROPrintData.CustPartSGST, ROPrintData.CustTaxGroupDataByPerc, ROPrintData.ShowAccParts, ROPrintData.CustLaborAfterTax, ROPrintData.CustPartAfterTax, ROPrintData.FixedDisc, ROPrintData.For, ROPrintData.FixedTotal, ROPrintData.CustTotalRoundedBy, ROPrintData.CustRoundedTotal, ROPrintData.ShowTaxColumn, ROPrintData.ShowTaxColumn, TrUtils.isTaxable(ROPrintData.Settings.Tax), ROPrintData.CustLaborITax, ROPrintData.CustPartITax, ROPrintData.Consolidate, ROPrintData.From, ROPrintData.Adj, ROPrintData.TaxSummary, ROPrintData.STotal, isAuto, moreDiscDetails), this.GetNumberInWords(ROPrintData.CustRoundedTotal), this.InvoiceDueStatus(ROPrintData.Type, ROPrintData.Paid, ROPrintData.Due, ROPrintData.Sts, ROPrintData.isCountersale, ROPrintData.Entity.DecimalsNumber), SharedPDFService.GetTemsAndConditions(ROPrintData.Entity.Terms), SharedPDFService.GetBankDetials(ROPrintData.Entity.Bank, ROPrintData.Entity.PrBank, ROPrintData.Entity.UPIPhone), // SharedPDFService.GetUnderLine(), SharedPDFService.GetHCInvSignatures(ROPrintData.Entity.CName, ROPrintData.isCountersale), // this.PageBrake(ROPrintData, withPass), // SharedPDFService.GetUnderLine1(withPass), // this.GetGatePass(withPass, ROPrintData) ]; if (ROPrintData.Type !== 'Invoice') { CommonDetails.splice(2, 0, SharedPDFService.GetUnderLine()); } if (!TrUtils.IsNull(numberofCopies) && numberofCopies.length !== 0 && (index !== (numberofCopies.length - 1))) { CommonDetails.push({ text: '', pageBreak: 'after' }) } return CommonDetails; } static InvoiceDueStatus(Type: any, Paid: any, Due: any, Status: any, isCounter: boolean, DecimalsNumber: number) { if (Type === 'Invoice' && !isCounter) { return { // lineHeight: 0.7, fontSize: 9, marginTop: 3, marginBottom: 5, table: { widths: ['*', 'auto'], body: [[{ text: 'Paid : Rs.' + TrUtils.FixPriceValue(Paid, DecimalsNumber), marginLeft: 20 }, { text: 'Due : Rs.' + TrUtils.FixPriceValue(Due, DecimalsNumber), marginRight: 20 }]] }, layout: SharedPDFService.LayOutLineStyle(), }; } else { return SharedPDFService.emptyObject(); } } static GetNumberInWords(TotalAmount: any) { var rupee = SharedPDFService.convertNumberToWords(TotalAmount); // console.log('rupee', rupee); return { columns: [{ text: 'In Words :', fontSize: 7, width: 35 }, { text: rupee, fontSize: 7, width: '*' }] } } static GetCustomerDetails(ROPrintData: any, isOtherIndustry: boolean) { let CustomerData = [ { name: 'Customer Name', value: ROPrintData.Customer.Name }, { name: 'Service Advisor', value: ROPrintData.Name }, ]; return SharedPDFService.GetVehicleDataTable(CustomerData); } static GetVehicleDetails(Vehicle: any, isOtherIndustry: boolean) { let vehicleData: any; vehicleData = [ ]; if (isOtherIndustry) { vehicleData.push({ name: 'Serial No', value: SharedPDFService.CheckAndSetString(Vehicle.SNo) }); } let a: any = [ { name: 'Vehicle Model', value: SharedPDFService.CheckAndSetString(Vehicle.Model) }, ]; if (!isOtherIndustry) { a.unshift({ name: 'Regn. No', value: SharedPDFService.CheckAndSetString(Vehicle.RegNo) }); if (!TrUtils.IsEmpty(Vehicle.VIN)) { a.unshift({ name: 'Chassis No', value: SharedPDFService.CheckAndSetString(Vehicle.VIN) }); } } for (let i = 0; i < a.length; i++) { vehicleData.push(a[i]); } return SharedPDFService.GetVehicleDataTable(vehicleData); } }