import { Add } from "../../shared/math-operations"; import { SharedPDFService } from "../../shared/shared-pdf.service"; import { PrintSharedService } from "../../shared/shared-print.service"; import { MyDate } from "../../utils/my-date"; import { TrUtils } from "../../utils/tr-utils"; export function GetInvoicePrint(invoicePdfData: any, numberofCopies: any, withPass: boolean, size: any = null, moreDiscDetails: boolean, orientation: 'portrait' | 'landscape' = 'portrait') { const isotherIndustry = false; var contents = []; if (TrUtils.IsNull(numberofCopies) || numberofCopies.length === 0 || numberofCopies.length === 1) { contents.push( CommonHeaderDetails(invoicePdfData, null, isotherIndustry, orientation), PreparesparePartsTable(invoicePdfData, orientation), CommonTotalDetails(invoicePdfData, null, numberofCopies, withPass, moreDiscDetails, orientation) ); } else { numberofCopies.forEach((text: any, index: any) => { contents.push( CommonHeaderDetails(invoicePdfData, text, isotherIndustry, orientation), PreparesparePartsTable(invoicePdfData, orientation), CommonTotalDetails(invoicePdfData, index, numberofCopies, withPass, moreDiscDetails, orientation) ); }); } var dd = { watermark: GetWatermark(invoicePdfData), info: { title: GetFileName(invoicePdfData), }, background: function (currentPage: any, pageSize: any) { if (size !== 'full') { pageSize.height = pageSize.height - 435.945; } return SharedPDFService.GetWatermarkImage(invoicePdfData.Image, pageSize, invoicePdfData.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: GetMarginsBasedOnPaperSize(size, orientation), pageOrientation: orientation, pageSize: 'A4', content: contents, styles: SharedPDFService.GetStyles() }; return dd; } export function GetMarginsBasedOnPaperSize(size: any, orientation: 'portrait' | 'landscape' = 'portrait') { if (orientation === 'landscape') { return [10, 15, 10, 15]; } if (size === 'full') { return [10, 15, 10, 15]; } else { return [10, 15, 10, 15]; } } export function GetWatermark(invoicePdfData: any) { if (invoicePdfData.IsProforma && invoicePdfData.Entity.Wmark) { return { text: 'Not a final invoice', opacity: 0.2 }; } else { return ''; } } export function GetFileName(invoicePdfData: any) { let fileName: string = invoicePdfData.HeaderName; if (!TrUtils.IsNull(invoicePdfData.Product) && !TrUtils.IsEmpty(invoicePdfData.Product.RegNo)) { fileName = fileName + '-' + invoicePdfData.Product.RegNo; } return fileName; } export function CommonHeaderDetails(invoicePdfData: any, text: any, isotherIndustry: boolean, orientation: 'portrait' | 'landscape' = 'portrait') { const headerDetails = [ GetMainHeaderDetails(invoicePdfData.Entity, invoicePdfData.HeaderName, invoicePdfData.Image, invoicePdfData.HColor, invoicePdfData.AColor, text, orientation), SharedPDFService.GetNewCustomerAndVehicleDetails(invoicePdfData._id, invoicePdfData.CrDate, invoicePdfData.PrDate, invoicePdfData.MOut, invoicePdfData.MIn, invoicePdfData.Product, invoicePdfData.PrintType, invoicePdfData.For, invoicePdfData.SurName, invoicePdfData.SurPhone, invoicePdfData.Type, invoicePdfData.SurEmail, invoicePdfData.InsComp, invoicePdfData.PolNo, invoicePdfData.PolType, invoicePdfData.Customer, invoicePdfData.IsProforma, invoicePdfData.Settings, invoicePdfData.Location, isotherIndustry, invoicePdfData.BL, invoicePdfData.ROCode, invoicePdfData.TypeName, invoicePdfData.AdmNo, invoicePdfData.DoS, invoicePdfData.Entity.PrCustBar, orientation), SharedPDFService.GetOwnerDetails(invoicePdfData.Cust, invoicePdfData.Type, invoicePdfData.For), CustomerAndVehicleDetailsAfterLine(orientation), // SharedPDFService.GetDisplayTable(), ]; return headerDetails; } export function GetMainHeaderDetails(Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any, orientation: 'portrait' | 'landscape' = 'portrait') { return [ SharedPDFService.GetNewMainHeader(Entity, Image, AColor, HColor, text, orientation), SharedPDFService.GetPrintType(HeaderName), HeaderAfterLine(orientation) ]; } export function HeaderAfterLine(orientation: 'portrait' | 'landscape' = 'portrait') { const lineWidth = orientation === 'landscape' ? 820 : 575; return { canvas: [ { type: 'line', x1: 0, y1: 0, x2: lineWidth, y2: 0, lineWidth: 0.5 } ], margin: [0, 2, 0, 2] }; } export function CustomerAndVehicleDetailsAfterLine(orientation: 'portrait' | 'landscape' = 'portrait') { const lineWidth = orientation === 'landscape' ? 820 : 575; return { canvas: [ { type: 'line', x1: 0, y1: 0, x2: lineWidth, y2: 0, lineWidth: 0.5 } ], margin: [0, 2, 0, 2] }; } export function PreparesparePartsTable(invoicePdfData: any, orientation: 'portrait' | 'landscape' = 'portrait') { let List: any = []; const printPartNo = invoicePdfData.Entity.MPN; if (invoicePdfData.Entity.Body === 1) { for (let i = 0; i < invoicePdfData.PrintInfo.length; i++) { if (TrUtils.IsNull(invoicePdfData.PrintInfo[i].Text)) { invoicePdfData.PrintInfo[i].Text = ''; } if (!TrUtils.IsEmpty(invoicePdfData.PrintInfo[i].Text)) { List.push(invoicePdfData.PrintInfo[i].Text); } List.push( GetLaborPartsTableForView(TrUtils.Stringify(invoicePdfData.PrintInfo[i].Items), TrUtils.Stringify(invoicePdfData.PrintInfo[i].Ops), printPartNo, orientation) ); } } else { if (invoicePdfData.Entity.Body === 2) { for (let i = 0; i < invoicePdfData.PrintInfo.length; i++) { if (TrUtils.IsNull(invoicePdfData.PrintInfo[i].Text)) { invoicePdfData.PrintInfo[i].Text = ''; } if (!TrUtils.IsEmpty(invoicePdfData.PrintInfo[i].Text)) { List.push(invoicePdfData.PrintInfo[i].Text); } List.push( WithOutDiscountFieldTable(TrUtils.Stringify(invoicePdfData.PrintInfo[i].Items), TrUtils.Stringify(invoicePdfData.PrintInfo[i].Ops), invoicePdfData.ShowTaxColumn, printPartNo, invoicePdfData.Entity.Body, invoicePdfData.ShowIGST, invoicePdfData.ConsolidateGST, invoicePdfData.ShowDiscountColumn, invoicePdfData.Entity.DecimalsNumber, invoicePdfData, orientation) ); } } else { if (invoicePdfData.Summary) { List.push( GetLaborPartsTableForView(invoicePdfData.Items, invoicePdfData.Ops, printPartNo, orientation) ); } else { for (let i = 0; i < invoicePdfData.PrintInfo.length; i++) { if (TrUtils.IsNull(invoicePdfData.PrintInfo[i].Text)) { invoicePdfData.PrintInfo[i].Text = ''; } if (!TrUtils.IsEmpty(invoicePdfData.PrintInfo[i].Text)) { List.push(invoicePdfData.PrintInfo[i].Text); } List.push( GetWithOutDiscAndTaxFieldHeader(TrUtils.Stringify(invoicePdfData.PrintInfo[i].Items), TrUtils.Stringify(invoicePdfData.PrintInfo[i].Ops), invoicePdfData.ShowTaxColumn, printPartNo, invoicePdfData.Entity.Body, invoicePdfData.ShowIGST, invoicePdfData.ConsolidateGST, invoicePdfData.ShowDiscountColumn, invoicePdfData.Entity.DecimalsNumber, invoicePdfData, orientation) ); } } } } return List; } export function GetLaborPartsTableForView(Parts: any, Ops: any, PrintPartNo: any, orientation: 'portrait' | 'landscape' = 'portrait') { if (Parts.length !== 0 || Ops.length !== 0) { if (PrintPartNo) { const widths = orientation === 'landscape' ? [15, 30, 140, 40, 35, 35, 25, 25, 35, 30, 50] : [25, 30, 170, 85, 15, 20, 50, 30, 30, 50]; return { style: 'tableExample', table: { widths: widths, body: buildTableForCustomerLabor(Parts, Ops, PrintPartNo, false, orientation) }, layout: PrintSharedService.LayOutStyleanother() }; } else { const widths = orientation === 'landscape' ? [15, 180, 40, 35, 35, 25, 25, 35, 30, 50] : [25, 200, 55, 25, 55, 55, 40, 15, 50]; return { style: 'tableExample', table: { widths: widths, body: buildTableForCustomerLabor(Parts, Ops, PrintPartNo, false, orientation) }, layout: PrintSharedService.LayOutStyleanother() }; } } else { let a: any = ''; return a; } } export function WithOutDiscountFieldTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, invoicePdfData: any, orientation: 'portrait' | 'landscape' = 'portrait') { if (Parts.length !== 0 || Ops.length !== 0) { if (PrintPartNo) { const widths = orientation === 'landscape' ? GetLandscapeTaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn) : [25, 60, 155, 30, 50, 60, 30, 50]; return { style: 'tableExample', marginLeft: 20, table: { widths: widths, headerRows: orientation === 'landscape' ? 2 : 1, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: PrintSharedService.LayOutStyleanother() }; } else { const widths = orientation === 'landscape' ? GetLandscapeTaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn) : [25, 215, 25, 50, 60, 45, 50]; return { style: 'tableExample', marginLeft: 20, table: { widths: widths, headerRows: orientation === 'landscape' ? 2 : 1, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: PrintSharedService.LayOutStyleanother() }; } } else { let a: any = ''; return a; } } function calculatePartsTotals(ConsolidateGST: boolean, Parts: any, DecimalsNumber: number) { 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) => { Qty = Add(Qty, TrUtils.FixedTo(part.Qty, DecimalsNumber)); CGSTAMT = Add(CGSTAMT, TrUtils.FixedTo(part.CGSTAmt, DecimalsNumber)); SGSTAMT = Add(SGSTAMT, TrUtils.FixedTo(part.SGSTAmt, DecimalsNumber)); IGSTAMT = Add(IGSTAMT, TrUtils.FixedTo(part.IGSTAmt, DecimalsNumber)); Taxable = ConsolidateGST ? Add(FinalTotal, TrUtils.FixedTo(part.AfterPartTax, DecimalsNumber)) : Add(Taxable, TrUtils.FixedTo(part.AfterPartDisc, DecimalsNumber)); FinalTotal = Add(FinalTotal, TrUtils.FixedTo(part.AfterPartTax, DecimalsNumber)); }); return { Qty, CGSTAMT, SGSTAMT, IGSTAMT, Taxable, FinalTotal }; } function calculateLaborTotals(ConsolidateGST: boolean, Labor: any, DecimalsNumber: number) { let CGSTAMT: number = 0; let SGSTAMT: number = 0; let IGSTAMT: number = 0; let Taxable: number = 0; let FinalTotal: number = 0; Labor.forEach((operation: any) => { CGSTAMT = Add(CGSTAMT, TrUtils.FixedTo(operation.CGSTAmt, DecimalsNumber)); SGSTAMT = Add(SGSTAMT, TrUtils.FixedTo(operation.SGSTAmt, DecimalsNumber)); IGSTAMT = Add(IGSTAMT, TrUtils.FixedTo(operation.IGSTAmt, DecimalsNumber)); Taxable = ConsolidateGST ? Add(FinalTotal, TrUtils.FixedTo(operation.AfterLaborTax, DecimalsNumber)) : Add(Taxable, TrUtils.FixedTo(operation.AfterLaborDisc, DecimalsNumber)); FinalTotal = Add(FinalTotal, TrUtils.FixedTo(operation.AfterLaborTax, DecimalsNumber)); }); return { CGSTAMT, SGSTAMT, IGSTAMT, Taxable, FinalTotal }; } function addPartsHeaderAndTotalRows(Parts: any, partsLabel: string, partsTotalLabel: string, ShowTaxColumn: any, DecimalsNumber: number, ConsolidateGST: boolean) { const totals = calculatePartsTotals(ConsolidateGST, Parts, DecimalsNumber); let dpartadding1: any = {}; dpartadding1.SNo = ''; dpartadding1.Desc = partsTotalLabel; dpartadding1.QtyAndUoM = TrUtils.FixedTo(totals.Qty, DecimalsNumber); dpartadding1.bold = true; dpartadding1.UnPr = TrUtils.FixedTo(totals.Taxable, DecimalsNumber); dpartadding1.SGSTAmt = TrUtils.FixedTo(totals.SGSTAMT, DecimalsNumber); dpartadding1.IGSTAmt = TrUtils.FixedTo(totals.IGSTAMT, DecimalsNumber); dpartadding1.CGSTAmt = TrUtils.FixedTo(totals.CGSTAMT, DecimalsNumber); dpartadding1.TCode = ShowTaxColumn ? 114 : undefined; dpartadding1.LineTotal = TrUtils.FixPriceValue(totals.FinalTotal, DecimalsNumber); Parts.push({ SNo: '' }); Parts.push(dpartadding1); let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = partsLabel; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.LineTotal = ''; Parts.unshift(dummypartadding1); } function addLaborHeaderAndTotalRows(Labor: any, laborLabel: string, laborTotalLabel: string, ShowTaxColumn: any, DecimalsNumber: number, ConsolidateGST: boolean) { const totals = calculateLaborTotals(ConsolidateGST, Labor, DecimalsNumber); let dpartadding1: any = {}; dpartadding1.SNo = ''; dpartadding1.Desc = laborTotalLabel; dpartadding1.UnPr = TrUtils.FixedTo(totals.Taxable, DecimalsNumber); dpartadding1.SGSTAmt = TrUtils.FixedTo(totals.SGSTAMT, DecimalsNumber); dpartadding1.IGSTAmt = TrUtils.FixedTo(totals.IGSTAMT, DecimalsNumber); dpartadding1.CGSTAmt = TrUtils.FixedTo(totals.CGSTAMT, DecimalsNumber); dpartadding1.TCode = ShowTaxColumn ? 114 : undefined; dpartadding1.bold = true; dpartadding1.LineTotal = TrUtils.FixPriceValue(totals.FinalTotal, DecimalsNumber); Labor.push({ SNo: '' }); Labor.push(dpartadding1); let dummypartadding1: any = {}; dummypartadding1.SNo = ''; dummypartadding1.Desc = laborLabel; dummypartadding1.Qty = ''; dummypartadding1.UnPr = ''; dummypartadding1.LineTotal = ''; Labor.unshift(dummypartadding1); } function buildItemRow(item: any, columns: any, column: any, itemLabel: string) { const hasValue = !TrUtils.IsFixedZero(item[column.Field]) && !TrUtils.IsNull(item[column.Field]) || (column.text === 'Line Total'); if (hasValue) { if (item[column.Field] === itemLabel) { return { text: item[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(item.TCode))) { item[column.Field] = ''; return { text: item[column.Field].toString(), alignment: 'center' }; } else { if (column.text === 'Line Total' || column.Field === 'UnPr' || column.Field === 'MRP' || column.Field === 'Batch' || column.Field === 'ExDate' || 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' || column.Field === 'Price') { if (column.Field === 'Disc') { if (column.type === 'percentage') { if (!TrUtils.IsEmpty(item[column.Field])) { return { text: item[column.Field].toString(), noWrap: true, alignment: 'center' }; } else { return { text: '', noWrap: true }; } } else { if (!TrUtils.IsNull(item[column.Field])) { return { text: item[column.Field].toString(), alignment: 'right', noWrap: true }; } else { return { text: '', noWrap: true }; } } } else { if (column.Field === 'Batch') { if (!TrUtils.IsNull(item[column.Field])) { return { text: item[column.Field].BN, nowrap: true }; } else { return { text: '', noWrap: true }; } } else if (column.Field === 'ExDate') { if (!TrUtils.IsNull(item['Batch'])) { return { text: MyDate.ConvertUTCDateToReadableExDate(item['Batch'].ExDt), nowrap: true }; } else { return { text: '', noWrap: true }; } } else { if (!TrUtils.IsNull(item[column.Field])) { return { text: item[column.Field].toString(), bold: item.bold, alignment: 'right', nowrap: true }; } else { return { text: '', noWrap: true }; } } } } else { if (column.Field === 'Desc') { let DescData: any = []; DescData.push({ text: item[column.Field].toString(), bold: item.bold }); if (!TrUtils.IsEmpty(item['EDesc'])) { DescData.push({ text: item['EDesc'].toString(), color: 'grey' }); } // DescData.push({ text: item['MPN'] ? 'MPN: ' + item['MPN'] : '', color: 'grey', italics: true, marginTop: 2 }); // const isItemRow = itemLabel === 'Items'; // const hasBatchOrMrp = !TrUtils.IsNull(item['Batch']?.BN) || !TrUtils.IsNull(item['Batch']?.ExDt) || !TrUtils.IsNull(item['MRP']); // if (isItemRow && hasBatchOrMrp) { // const exDate = !TrUtils.IsNull(item['Batch']?.ExDt) ? MyDate.ConvertUTCDateToReadableExDate(item['Batch']?.ExDt) : ''; // DescData.push({ // marginTop: 5, // text: [ // { text: 'B.No: ', bold: true }, // { text: (item['Batch']?.BN || '') + '' }, // { text: ' | Ex.Dt: ', bold: true }, // { text: exDate + '' }, // { text: ' | MRP: ', bold: true }, // { text: (TrUtils.IsNull(item['MRP']) ? '' : item['MRP']) + '' } // ] // }); // } return { stack: DescData }; } else { return { text: item[column.Field].toString(), bold: item.bold }; } } } } } else { if (TrUtils.IsNull(item[column.Field])) { item[column.Field] = ''; } return { text: item[column.Field].toString(), alignment: 'center' }; } } function buildTableRows(items: any, columns: any, itemLabel: string, body: any) { let SNo: number = 1; items.forEach((item: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (column.Field === 'SNo' && (TrUtils.IsFixedZero(item[column.Field]) || TrUtils.IsNull(item[column.Field])) && item[column.Field] !== itemLabel) { item[column.Field] = SNo; SNo = SNo + 1; } dataRow.push(buildItemRow(item, columns, column, itemLabel)); }); body.push(dataRow); }); } export function BuildTableBodyForLaborAndParts(Parts: any, Labor: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, orientation: 'portrait' | 'landscape' = 'portrait') { var body: any = []; let columns: any = orientation === 'landscape' ? GetLandscapeWithOutDiscountFieldHeader(PrintPartNo, ShowTaxColumn, Body, ShowIGST, ShowDiscountColumn) : PrintSharedService.GetWithOutDiscountFieldHeader(PrintPartNo, ShowTaxColumn, Body, ShowIGST, ShowDiscountColumn); for (let i = 0; i < columns.length; i++) { body.push(columns[i]); } columns = columns[1]; const partsLabel = 'Items'; const partsTotalLabel = 'Items Total'; const laborLabel = 'Service'; const laborTotalLabel = 'Service Total'; if (Parts.length !== 0) { addPartsHeaderAndTotalRows(Parts, partsLabel, partsTotalLabel, ShowTaxColumn, DecimalsNumber, ConsolidateGST); } buildTableRows(Parts, columns, partsLabel, body); if (Labor.length !== 0) { addLaborHeaderAndTotalRows(Labor, laborLabel, laborTotalLabel, ShowTaxColumn, DecimalsNumber, ConsolidateGST); } if (Body === 2) { for (let i = 0; i < Labor.length; i++) { Labor[i].UnPr = ''; } } buildTableRows(Labor, columns, laborLabel, body); return body; } export function GetWithOutDiscAndTaxFieldHeader(Parts: any, Ops: any, ShowTaxColumn: any, PrintPartNo: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, invoicePdfData: any, orientation: 'portrait' | 'landscape' = 'portrait') { if (Parts.length !== 0 || Ops.length !== 0) { if (ShowTaxColumn) { return TaxDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation); } else { if (ConsolidateGST) { return ConsolidateDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation); } else { return NoTaxDataTable(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation); } } } else { let a: any = ''; return a; } } export function TaxDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, orientation: 'portrait' | 'landscape' = 'portrait') { const layoutStyle = PrintSharedService.LayOutStyle(); const widths = orientation === 'landscape' ? GetLandscapeTaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn) : PrintSharedService.TaxTableWidths(PrintPartNo, ShowIGST, ShowDiscountColumn); return { style: 'tableExample', marginTop: orientation === 'landscape' ? -6 : 7, table: { widths: widths, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: layoutStyle }; } export function ConsolidateDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, orientation: 'portrait' | 'landscape' = 'portrait') { const layoutStyle = PrintSharedService.LayOutStyle(); if (PrintPartNo) { const widths = orientation === 'landscape' ? [15, 50, 180, 40, 35, 35, 25, 25, 35, 30, 50] : [25, 70, 263, 25, 60, 80, 10, 40]; return { style: 'tableExample', marginTop:7, table: { widths: widths, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: layoutStyle }; } else { const widths = orientation === 'landscape' ? [15, 220, 40, 35, 35, 25, 25, 35, 30, 50] : [25, 295, 50, 80, 80, 10, 40]; return { style: 'tableExample', marginTop:7, table: { widths: widths, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: layoutStyle }; } } export function NoTaxDataTable(Parts: any, Ops: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ConsolidateGST: any, ShowDiscountColumn: any, DecimalsNumber: number, orientation: 'portrait' | 'landscape' = 'portrait') { const layoutStyle = PrintSharedService.LayOutStyle(); const widths = orientation === 'landscape' ? (PrintPartNo ? [15, 50, 180, 40, 35, 35, 25, 25, 35, 30, 50] : [15, 220, 40, 35, 35, 25, 25, 35, 30, 50]) : PrintSharedService.WidthForInsuranceOrNot(ShowDiscountColumn, PrintPartNo); return { style: 'tableExample', marginTop:7, table: { widths: widths, body: BuildTableBodyForLaborAndParts(Parts, Ops, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ConsolidateGST, ShowDiscountColumn, DecimalsNumber, orientation) }, layout: layoutStyle }; } export function buildTableForCustomerLabor(Parts: any, Ops: any, PrintPartNo: any, customerorInsurance: any, orientation: 'portrait' | 'landscape' = 'portrait') { var body: any = []; let columns: any; columns = orientation === 'landscape' ? getLandscapeSummaryHeaders(PrintPartNo) : getSummaryHeaders(PrintPartNo); body.push(columns); const partsLabel = 'Items'; const laborLabel = 'Service'; let snoRef = { value: 1 }; if (Parts.length !== 0) { addSummaryHeaderRow(Parts, partsLabel, PrintPartNo); } buildSummaryRows(Parts, columns, partsLabel, body, snoRef); snoRef.value = 1; if (Ops.length !== 0) { addSummaryHeaderRow(Ops, laborLabel, PrintPartNo); } buildSummaryRows(Ops, columns, laborLabel, body, snoRef); return body; } function addSummaryHeaderRow(items: any, label: string, PrintPartNo: boolean) { let headerRow: any = {}; headerRow.SNo = ''; headerRow.Desc = label; headerRow.Qty = ''; headerRow.UnPr = ''; headerRow.Price = ''; headerRow.DiscountedPrice = ''; headerRow.LineTotal = ''; headerRow.QtyAndUoM = ''; headerRow.HSN = ''; if (PrintPartNo) { headerRow.MPN = ''; } items.unshift(headerRow); } function buildSummaryItemCell(item: any, column: any, itemLabel: string) { const hasValue = !TrUtils.IsFixedZero(item[column.Field]) && !TrUtils.IsNull(item[column.Field]) || column.text === 'Line Total'; if (hasValue) { if (item[column.Field] === itemLabel) { return { text: item[column.Field].toString(), marginLeft: 50, style: 'InlineHeader' }; } else { 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') { return { text: item[column.Field].toString(), alignment: 'right', noWrap: true }; } else { return { text: item[column.Field].toString(), alignment: 'right', nowrap: true }; } } else { if (column.Field === 'Desc') { let DescData: any = []; DescData.push(item[column.Field].toString()); if (!TrUtils.IsEmpty(item['EDesc'])) { DescData.push({ text: item['EDesc'].toString(), color: 'grey' }); } return { stack: DescData }; } else { return { text: item[column.Field].toString() }; } } } } else { if (TrUtils.IsNull(item[column.Field])) { item[column.Field] = ''; } return { text: item[column.Field].toString(), alignment: 'center' }; } } function buildSummaryRows(items: any, columns: any, itemLabel: string, body: any, snoRef: {value: number}) { items.forEach((item: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (column.Field === 'SNo' && (TrUtils.IsFixedZero(item[column.Field]) || TrUtils.IsNull(item[column.Field])) && item[column.Field] !== itemLabel) { item[column.Field] = snoRef.value; snoRef.value = snoRef.value + 1; } dataRow.push(buildSummaryItemCell(item, column, itemLabel)); }); body.push(dataRow); }); } export function 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: '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; } export function CommonTotalDetails(invoicePdfData: any, index: any, numberofCopies: any, withPass: boolean, moreDiscDetails: boolean, orientation: 'portrait' | 'landscape' = 'portrait') { const taxSummaryData = invoicePdfData.TaxSummary || invoicePdfData.CustTaxGroupDataByPerc; let CommonDetails = [ SharedPDFService.GetFinalTotalDetails1(invoicePdfData, invoicePdfData.CustLaborTotalAfterDisc, invoicePdfData.CustLaborDiscTotal, invoicePdfData.CustLaborCGST, invoicePdfData.CustLaborSGST, invoicePdfData.CustLaborIGST, invoicePdfData.CustPartIGST, invoicePdfData.ShowIGST, invoicePdfData.ShowTaxColumn, invoicePdfData.CustPartsTotalAfterDisc, invoicePdfData.CustPartsDiscTotal, invoicePdfData.CustPartCGST, invoicePdfData.CustPartSGST, taxSummaryData, invoicePdfData.ShowAccParts, invoicePdfData.CustLaborAfterTax, invoicePdfData.CustPartAfterTax, invoicePdfData.FixedDisc, invoicePdfData.For, invoicePdfData.FixedTotal, invoicePdfData.CustTotalRoundedBy, invoicePdfData.CustRoundedTotal, invoicePdfData.ShowTaxColumn, invoicePdfData.ShowTaxColumn, TrUtils.isTaxable(invoicePdfData.Settings?.Tax), invoicePdfData.CustLaborITax, invoicePdfData.CustPartITax, invoicePdfData.Consolidate, invoicePdfData.From, invoicePdfData.Adj, taxSummaryData, invoicePdfData.STotal, false, moreDiscDetails), GetNumberInWords(invoicePdfData.CustRoundedTotal), SharedPDFService.InvoiceDueStatus(invoicePdfData.Type, invoicePdfData.Paid, invoicePdfData.Due, invoicePdfData.Sts, invoicePdfData.isCountersale, invoicePdfData.Entity.DecimalsNumber), SharedPDFService.GetTemsAndConditions(invoicePdfData.Entity.Terms), GetBanckdetailswithQRCode(invoicePdfData), SharedPDFService.GetNewUnderLine(orientation), SharedPDFService.GetInvSignatures(invoicePdfData.Entity.CName, invoicePdfData.isCountersale), SharedPDFService.GetNewUnderLine1(withPass, orientation), GetGatePass(withPass, invoicePdfData) ]; if (invoicePdfData.Type !== 'Invoice') { CommonDetails.splice(2, 0, SharedPDFService.GetNewUnderLine(orientation)); } if (!TrUtils.IsNull(numberofCopies) && numberofCopies.length !== 0 && (index !== (numberofCopies.length - 1))) { CommonDetails.push({ text: '', pageBreak: 'after' }) } return CommonDetails; } export function GetBanckdetailswithQRCode(invoicePdfData: any) { return { columns: [ SharedPDFService.GetBankDetials(invoicePdfData.Entity.Bank, invoicePdfData.Entity.PrBank, invoicePdfData.Entity.UPIPhone), SharedPDFService.GetEntityDetails(invoicePdfData.Entity) ] }; } export function GetNumberInWords(TotalAmount: any) { var rupee = SharedPDFService.convertNumberToWords(TotalAmount); return { columns: [{ text: 'In Words :', fontSize: 9, width: 45 }, { text: rupee, bold: true, fontSize: 9, width: '*' }] }; } export function GetGatePass(isGatepass: boolean, invoicePdfData: any) { if (isGatepass) { return { columns: [{ id: '567', text: [{ text: '', id: '1234' }], stack: [ { columns: [{ text: '' }, { text: 'Gate Pass', bold: true, fontSize: 9, alignment: 'center', marginTop: 5 }, { text: 'Date: ' + MyDate.ConvertUTCDateToReadable(MyDate.GetDateTimeNowInUTC(invoicePdfData.Entity.User.TZ)), marginTop: 5, fontSize: 9, alignment: 'right' }] }, { text: invoicePdfData.Entity.CName, alignment: 'center', bold: true, fontSize: 12, marginTop: 5, marginBottom: 5 }, { marginTop: 5, columns: [ { text: '', width: 60 }, GetCustomerDetails(invoicePdfData, false), GetVehicleDetails(invoicePdfData.Product, false) ] }, { text: 'Vehicle has been received from workshop and work done as per my satisfaction.', fontSize: 7, marginTop: 10, marginLeft: 60 }, { columns: [SharedPDFService.CustomerSignature(), { text: '' }, SharedPDFService.Accountantsignature()] } ] }], }; } else { return SharedPDFService.emptyObject(); } } export function GetCustomerDetails(invoicePdfData: any, isOtherIndustry: boolean) { let CustomerData = [ { name: 'Customer Name', value: invoicePdfData.Customer.Name }, { name: 'Service Advisor', value: invoicePdfData.Name }, ]; return SharedPDFService.GetVehicleDataTable(CustomerData); } export function 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); } export function GetLandscapeWithOutDiscountFieldHeader(PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ShowDiscountColumn: any) { let headersNames: any; if (PrintPartNo) { headersNames = [[ { text: 'S.No.', rowSpan: 2, style: 'tableheader', lineHeight: 0.5 }, { text: 'Part No', rowSpan: 2, style: 'tableheader', lineHeight: 0.5 }, { text: 'Description', rowSpan: 2, style: 'tableheader', alignment: 'center', lineHeight: 0.5 }, { text: 'HSN/SAC', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Batch No', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Expiry', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Qty', style: 'tableheader', rowSpan: 2, lineHeight: 0.5 }, { text: 'Off Qty', style: 'tableheader', rowSpan: 2, lineHeight: 1 }, { text: 'MRP', style: 'tableheader', rowSpan: 2, lineHeight: 0.5, alignment: 'center' }, { text: 'Unit Price', style: 'tableheader', rowSpan: 2, lineHeight: 0.5, alignment: 'center' }, { text: 'Line Total', rowSpan: 2, lineHeight: 0.5, style: 'tableheader' } ], [ { text: '', Field: 'SNo', lineHeight: 0.5 }, { text: '', Field: 'MPN', lineHeight: 0.5 }, { text: '', Field: 'Desc', lineHeight: 0.5 }, { text: 'HSN/SAC', Field: 'HSN', lineHeight: 0.5 }, { text: '', Field: 'Batch', lineHeight: 0.5 }, { text: 'Expiry', Field: 'ExDate', lineHeight: 0.5 }, { text: '', Field: 'QtyAndUoM', lineHeight: 0.5 }, { text: '', Field: 'OfQty', lineHeight: 0.5 }, { text: '', Field: 'MRP', lineHeight: 0.5 }, { text: '', Field: 'UnPr', lineHeight: 0.5 }, { text: 'Line Total', Field: 'LineTotal', lineHeight: 0.5 } ]]; let Count: number = 10; if (ShowDiscountColumn) { headersNames[0].splice(Count, 0, { text: 'Discount', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: '%', alignment: 'center', style: 'tableheader', Field: 'Perc', type: 'percentage', lineHeight: 0.5 }); headersNames[1].splice(Count + 1, 0, { text: 'Rs', alignment: 'center', style: 'tableheader', Field: 'Disc', type: 'amount', lineHeight: 0.5 }); Count = 12; } if (ShowIGST) { headersNames[0].splice(Count, 0, { text: 'IGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'IGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 1, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'IGSTAmt', type: 'amount', lineHeight: 0.5 }); } else { headersNames[0].splice(Count, 0, { text: 'CGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'CGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 1, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'CGSTAmt', type: 'amount', lineHeight: 0.7 }); headersNames[0].splice(Count + 2, 0, { text: 'SGST/UTGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 3, 0, {}); headersNames[1].splice(Count + 2, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'SGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 3, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'SGSTAmt', type: 'amount', lineHeight: 0.5 }); } } else { headersNames = [[ { text: 'S.No.', rowSpan: 2, style: 'tableheader', lineHeight: 0.6 }, { text: 'Description', rowSpan: 2, style: 'tableheader', alignment: 'center', lineHeight: 0.6 }, { text: 'HSN/SAC', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Batch No', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Expiry', rowSpan: 2, style: 'tableheader', lineHeight: 1 }, { text: 'Qty', style: 'tableheader', rowSpan: 2, lineHeight: 0.6 }, { text: 'Off Qty', style: 'tableheader', rowSpan: 2, lineHeight: 1 }, { text: 'MRP', style: 'tableheader', rowSpan: 2, lineHeight: 0.5, alignment: 'center' }, { text: 'Unit Price', style: 'tableheader', rowSpan: 2, alignment: 'center', lineHeight: 0.6 }, { text: 'Line Total', rowSpan: 2, style: 'tableheader', lineHeight: 0.6 } ], [ { text: '', Field: 'SNo', lineHeight: 0.5 }, { text: '', Field: 'Desc', lineHeight: 0.5 }, { text: 'HSN/SAC', Field: 'HSN', lineHeight: 0.5 }, { text: '', Field: 'Batch', lineHeight: 0.5 }, { text: 'Expiry', Field: 'ExDate', lineHeight: 0.5 }, { text: '', Field: 'QtyAndUoM', lineHeight: 0.5 }, { text: '', Field: 'OfQty', lineHeight: 0.5 }, { text: '', Field: 'MRP', lineHeight: 0.5 }, { text: '', Field: 'UnPr', lineHeight: 0.5 }, { text: 'Line Total', Field: 'LineTotal', lineHeight: 0.5 } ]]; let Count: number = 9; if (ShowDiscountColumn) { headersNames[0].splice(Count, 0, { text: 'Discount', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: '%', alignment: 'center', style: 'tableheader', Field: 'Perc', type: 'percentage', lineHeight: 0.5 }); headersNames[1].splice(Count + 1, 0, { text: 'Rs', alignment: 'center', style: 'tableheader', Field: 'Disc', type: 'amount', lineHeight: 0.5 }); Count = 11; } if (ShowIGST) { headersNames[0].splice(Count, 0, { text: 'IGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'IGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 1, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'IGSTAmt', type: 'amount', lineHeight: 0.5 }); } else { headersNames[0].splice(Count, 0, { text: 'CGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 1, 0, {}); headersNames[1].splice(Count, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'CGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 1, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'CGSTAmt', type: 'amount', lineHeight: 0.5 }); headersNames[0].splice(Count + 2, 0, { text: 'SGST/UTGST', style: 'tableheader', colSpan: 2, alignment: 'center', lineHeight: 0.8 }); headersNames[0].splice(Count + 3, 0, {}); headersNames[1].splice(Count + 2, 0, { text: 'Rate %', alignment: 'center', style: 'tableheader', Field: 'SGSTPerc', type: 'percentage', lineHeight: 0.8 }); headersNames[1].splice(Count + 3, 0, { text: 'Amount', alignment: 'center', style: 'tableheader', Field: 'SGSTAmt', type: 'amount', lineHeight: 0.5 }); } } return headersNames; } export function getLandscapeSummaryHeaders(PrintPartNo: any) { var columns: any = []; columns.push({ text: 'S.No', fontSize: 7, alignment: 'center', bold: true }); if (PrintPartNo) { columns.push({ text: 'Part No', fontSize: 7, alignment: 'left', bold: true }); } columns.push({ text: 'Description', fontSize: 7, alignment: 'left', bold: true }); columns.push({ text: 'HSN/SAC', fontSize: 7, alignment: 'center', bold: true }); columns.push({ text: 'Batch No', fontSize: 7, alignment: 'center', bold: true }); columns.push({ text: 'Expiry', fontSize: 7, alignment: 'center', bold: true }); columns.push({ text: 'Qty', fontSize: 7, alignment: 'center', bold: true }); columns.push({ text: 'Off Qty', fontSize: 7, alignment: 'center', bold: true }); columns.push({ text: 'MRP', fontSize: 7, alignment: 'right', bold: true }); columns.push({ text: 'Unit Price', fontSize: 7, alignment: 'right', bold: true }); columns.push({ text: 'Line Total', fontSize: 7, alignment: 'right', bold: true }); return columns; } export function GetLandscapeTaxTableWidths(PrintPartNo: any, ShowIGST: any, ShowDiscountColumn: any) { if (PrintPartNo) { if (ShowIGST) { if (ShowDiscountColumn) { return [24, 50, '*', 50, 35, 35, 30, 25, 40, 40, 20, 35, 20, 35, 51]; } else { return [24, 50, '*', 50, 35, 35, 30, 25, 40, 40, 20, 35, 51]; } } else { if (ShowDiscountColumn) { return [24, 45, '*', 50, 35, 35, 30, 22, 40, 40, 20, 34, 20, 32, 20, 32, 48]; } else { return [24, 45, '*', 50, 35, 35, 30, 22, 40, 40, 20, 32, 20, 32, 54]; } } } else { if (ShowIGST) { if (ShowDiscountColumn) { return [24, '*', 50, 41, 35, 30, 25, 40, 40, 20, 35, 20, 35, 41]; } else { return [24, '*', 50, 50, 35, 30, 25, 40, 40, 20, 40, 50]; } } else { if (ShowDiscountColumn) { return [24, '*', 50, 45, 35, 30, 22, 40, 40, 20, 34, 20, 35, 20, 35, 45]; } else { return [24, '*', 50, 50, 35, 30, 22, 40, 40, 20, 35, 20, 35, 50]; } } } }