import { PayTypeEnum } from "../../enums/enums"; import { Add } from "../../shared/math-operations"; import { SharedPDFService } from "../../shared/shared-pdf.service"; import { MyDate } from "../../utils/my-date"; import { TrUtils } from "../../utils/tr-utils"; export class InvoicePortraitPrintService { static TableHeaders: number = 9; static GetPrint(InvoicePDFData: any, size: string, printOptions: any, moreDiscDetails: boolean) { // console.log('InvoicePDFData', InvoicePDFData); if (TrUtils.IsNull(InvoicePDFData.Name)) { InvoicePDFData.Name = ''; } let dd: any = { info: { title: 'TAX INVOICE', }, 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, pageSize: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 25, fontSize: 8, marginTop: 2 }; }, pageMargins: this.GetMarginsBasedOnPaperSize(size), pageSize: 'A4', content: [ this.GetMainHeaderInfo(InvoicePDFData), { style: 'tableExample', table: { widths: [200, '*', 'auto'], body: this.GetCustomerAndBankDetails(InvoicePDFData) }, layout: this.HeaderLayOut() }, this.GetItemsTable(InvoicePDFData.Ops, InvoicePDFData.Items, InvoicePDFData.ShowTaxColumn, InvoicePDFData.SType, printOptions, size, InvoicePDFData.Entity.DecimalsNumber), [this.TotalDetails(InvoicePDFData, moreDiscDetails, InvoicePDFData.Entity.DecimalsNumber)], [this.GetNumberInWords(InvoicePDFData.CustRoundedTotal)], [this.InvoiceDueStatus(InvoicePDFData.Type, InvoicePDFData.Paid, InvoicePDFData.Due, InvoicePDFData.Sts, InvoicePDFData.isCountersale, InvoicePDFData.Entity.DecimalsNumber) ], { style: 'tableExample', table: { widths: ['*', 'auto'], body: this.GetSignatures(InvoicePDFData.Entity.CName, InvoicePDFData.CustRoundedTotal) }, layout: 'noBorders' }, // this.GetSignatures(InvoicePDFData.Entity.CName, InvoicePDFData.CustRoundedTotal), ], styles: { headerstyle: { fontFamily: 'Calibri', fontSize: 9 }, Sign: { fontSize: 8, margin: [0, 15, 0, 5] }, forCompany: { // margin: [0, 10, 30, 0], marginRight: 5, marginTop: 10, fontSize: 9, alignment: 'right' }, forCompany1: { margin: [0, 5, 15, 0], fontSize: 8 }, tableheader: { bold: true, fontFamily: 'Calibri', margin: [0, 1, 0, 5], alignment: 'center' }, tableheader1: { bold: true, fontFamily: 'Calibri', margin: [0, 2, 0, 2], alignment: 'center' }, tableExample: { fontSize: 9 }, tableExample1: { fontSize: 8 } } }; return dd; } static LayOutStyle() { return { hLineColor: function (i: any, node: any) { return (i === 0 || i === 1 || i === 2 || i === node.table.body.length) ? 'gray' : 'white'; }, vLineColor: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 'gray' : 'white'; } }; } static InvoiceDueStatus(Type: any, Paid: any, Due: any, Status: any, isCounter: boolean, DecimalsNumber: number) { if (Type === 'Invoice' && !isCounter) { return { // lineHeight: 0.7, fontSize: this.TableHeaders, marginTop: 3, marginBottom: 5, table: { widths: ['*', 'auto'], body: [[{ text: 'Paid : ' + TrUtils.FixPriceValue(Paid, DecimalsNumber), marginLeft: 20 }, { text: 'Due : ' + TrUtils.FixPriceValue(Due, DecimalsNumber), marginRight: 20 }]] }, layout: SharedPDFService.LayOutLineStyle(), }; } else { return this.emptyObject(); } } static GetMainHeaderInfo(InvoicePDFData: any) { if (!TrUtils.IsNull(InvoicePDFData.Image)) { return { columns: [{ image: InvoicePDFData.Image, width: 60, height: 60, marginBottom: 5 }, { stack: [ { text: InvoicePDFData.Entity.CName, style: ['headerstyle'], alignment: 'left', fontSize: 15 }, { text: this.GetAddress(InvoicePDFData.Entity), alignment: 'left', style: ['headerstyle'] }, { columns: this.GetHeaderInfo(InvoicePDFData, 0) }, { text: InvoicePDFData.HeaderName, alignment: 'left', style: ['Receiptheader1'], marginTop: 5 } ] } ], columnGap: 10 } } else { return { stack: [ { text: InvoicePDFData.Entity.CName, style: ['headerstyle'], alignment: 'center', fontSize: 15 }, { text: this.GetAddress(InvoicePDFData.Entity), alignment: 'center', style: ['headerstyle'] }, { columns: this.GetHeaderInfo(InvoicePDFData, 5) }, { text: InvoicePDFData.HeaderName, alignment: 'center', style: ['Receiptheader1'] } ] } } } static GetCustomerAndBankDetails(InvoicePDFData: any) { let CustDetails: any = []; CustDetails.push([{ marginLeft: 3, stack: [ this.GetCustomerDetails(InvoicePDFData.Customer, InvoicePDFData.Type, null, null, 'Customer Name & Address') ] }, { marginLeft: 5, marginRight: 5, stack: [this.GetCustomerGSTIN(InvoicePDFData.Customer), this.GetCustomerDLNo(InvoicePDFData.Customer)] }, { marginRight: 5, stack: [{ text: 'Invoice No : ' + InvoicePDFData._id, style: ['headerstyle'] }, { text: 'Date : ' + InvoicePDFData.CrDate, style: ['headerstyle'] }] }]); if (InvoicePDFData.Entity.PrBank) { CustDetails.push([{ text: 'Note: OUR BANK A/C: ' + InvoicePDFData.Entity.Bank.ACNo + ', IFSC CODE: ' + InvoicePDFData.Entity.Bank.IFSC + ', Account Holder Name: ' + InvoicePDFData.Entity.Bank.ACName + ', BANK NAME: ' + InvoicePDFData.Entity.Bank.Name, colSpan: 3, fontSize: 8 }]); } return CustDetails; } static GetAddress1(Customer: any) { var Address = this.GetFormatAddress(Customer); if (Address.length !== 5) { return Address; } else { let a: any = ''; return a; } } static GetFormatAddress(CustomerObj: any) { var Addressnew = ''; if (!TrUtils.IsNull(CustomerObj.Adrs)) { CustomerObj.Adrs.forEach((Adrs: any, index: any) => { Addressnew = Addressnew + Adrs; if (CustomerObj.Adrs.length > (index + 1)) { Addressnew = Addressnew + ', ' } }); } return Addressnew; } static GetCustomerDetails(Customer: any, Type: any, Vehicle: any, Settings: any, CustHeader: string) { if (TrUtils.IsNull(Customer)) { return this.emptyObject(); } let Data: any = [{ text: CustHeader + ':', style: 'hed', bold: true }, { text: Customer.Name, marginTop: 2 }, { text: this.GetAddress1(Customer), marginTop: 3, fontSize: 7 }, this.GetCustPhoneNumber(Customer, Type), this.GetCustomerName(Customer.CustName)] return { style: 'colum1', stack: Data }; } static GetFormatContact(CustomerObj: any) { var contactnew = ''; if (!TrUtils.IsNull(CustomerObj.Cons)) { CustomerObj.Cons.forEach((Contact: any) => { contactnew = contactnew + '(' + Contact.Type + '):' + Contact.No + '\n'; }); } return contactnew; } static GetCustPhoneNumber(Customer: any, Type: any) { if (Type !== 'Technician Copy') { var contact = this.GetFormatContact(Customer); if (contact.length !== 0) { return { columns: [{ text: 'Phone', width: 27, style: 'hed' }, contact] }; } else { return this.emptyObject(); } } else { return this.emptyObject(); } } static emptyObject() { let a: any = {}; return a; } static GetCustomerName(Customer: any) { if (!TrUtils.IsEmpty(Customer)) { let GSTIN = { columns: [{ text: 'Customer Name :', width: 65, bold: true }, { text: Customer }] }; return GSTIN; } else { return this.emptyObject(); } } static GetCustomerGSTIN(Customer: any) { if (!TrUtils.IsEmpty(Customer.GSTIN)) { let GSTIN = { columns: [{ text: 'GSTIN :', width: 33, style: 'hed' }, { text: Customer.GSTIN, marginTop: 1.5 }] }; return GSTIN; } else { return this.emptyObject(); } } static GetCustomerDLNo(Customer: any) { if (!TrUtils.IsEmpty(Customer.DLNo)) { let GSTIN = { columns: [{ text: 'DL No :', width: 33, style: 'hed' }, { text: Customer.DLNo, marginTop: 1.5 }] }; return GSTIN; } else { return this.emptyObject(); } } static HeaderLayOut() { return { hLineWidth: function (i: any, node: any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 1 : 0; }, vLineWidth: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 1 : 0; }, hLineColor: function (i: any, node: any) { return 'gray'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, }; } static GetHeaderInfo(InvoicePDFData: any, marginleft: number) { let TaxInfo: any = []; if (!TrUtils.IsEmpty(InvoicePDFData.Entity.GSTIN)) { TaxInfo.push({ text: 'GSTIN : ' + InvoicePDFData.Entity.GSTIN, marginTop: 2, marginLeft: marginleft, alignment: 'left', fontSize: 9, width: 'auto' }, ); } if (!TrUtils.IsEmpty(InvoicePDFData.Entity.DLNo)) { TaxInfo.push({ text: 'D.L.NO : ' + InvoicePDFData.Entity.DLNo, marginTop: 2, marginLeft: 5, alignment: 'left', fontSize: 9, width: '*' }, ); } TaxInfo.push(this.GetBillofSupplyName(InvoicePDFData.Settings)); return TaxInfo; } static GetMarginsBasedOnPaperSize(size: any) { if (size === 'full') { return [20, 15, 20, 15]; } else { return [20, 15, 20, 435.945]; } } static GrandTotalTable(data: any) { var body: any = []; data.forEach((row: any) => { if (!TrUtils.IsFixedZero(row.value) || row.name === 'Total') { var dataRow: any = []; dataRow.push({ text: (row.name).toString(), noWrap: true }); dataRow.push(':'); if (row.name === 'Final Total') { dataRow.push({ text: (row.value).toString(), noWrap: true, bold: true, fontSize: 12, alignment: 'right' }); } else if (!TrUtils.IsNull(row.value)) { dataRow.push({ text: (row.value).toString(), noWrap: true, alignment: 'right' }); } else { dataRow.push({ text: '', noWrap: true, alignment: 'right' }); } body.push(dataRow); } }); return body; } static GetBillofSupplyName(Settings: any) { return { text: Settings.Tax === 'BS' ? ' Bill of Supply' : null, alignment: 'center', marginLeft: 15, marginTop: 2, marginBottom: 3, fontSize: 9, width: 'auto' }; } static GetDiscountOverall(InvoicePDFData: any) { return TrUtils.FixPriceValue(Number(InvoicePDFData.FixedDisc)); } static CustomerAndVehicleDetailsAfterLine(size: any) { let length: any = 575; if (size === 'A3') { length = 820; } else if (size === 'Custom') { length = 575; } return { canvas: [ { type: 'line', lineColor: 'gray', x1: 0, y1: 0, x2: 540, y2: 0, lineWidth: 1 } ] }; } // static GetSignatures(CName: any, Total:any) { // return { // columns: [{ // stack: [ // { columns: [this.GetNumberInWords(Total), this.CompanyName(CName)] } // ] // }], // }; // } static GetSignatures(CName: any, Total: any) { return [['', this.CompanyName(CName)]]; } static CompanyName(CName: any) { return { style: 'forCompany1', text: ['For ', { text: CName, bold: 'true' }], }; } static Authorizedsignature() { return { style: 'Sign', text: ['Authorized Signatory'], }; } static CustomerSignature() { return { style: 'Sign', text: ['Customer Signature'], marginLeft: 90 }; } static GetItemsTable(Services: any, Items: any, ShowTaxColumn: boolean, SType: any, printOptions: any, size: any, DecimalsNumber: number) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.GetWidths(ShowTaxColumn, printOptions), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Services, Items, ShowTaxColumn, SType, printOptions, size, DecimalsNumber) }, layout: { hLineWidth: function (i: any, node: any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 1 : 0; }, vLineWidth: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 1 : 0.5; }, hLineColor: function (i: any, node: any) { return 'gray'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, } }; } static GetWidths(ShowTaxColumn: any, printOptions: any) { if (ShowTaxColumn && printOptions.ShowTax !== 'NO') { if (printOptions.Disc === 'NO') { return [16, '*', 40, 45, 25, 20, 20, 45, 45, 30, 50]; } else { return [16, '*', 40, 45, 25, 20, 20, 45, 45, 35, 35, 45]; } } else { if (printOptions.Disc === 'NO') { return [22, '*', 40, 45, 25, 20, 20, 50, 50, 50]; } else { return [22, '*', 40, 45, 25, 20, 20, 50, 50, 50, 50]; } } } static GetAddress(Entity: any) { return Entity.Adrs1 + ', ' + Entity.Adrs2 + ', ' + Entity.City + '-' + Entity.PIN + ', Cell : ' + Entity.Phone; } static BuildTableBodyForLaborAndParts(Services: any, Items: any, ShowTaxColumn: any, SType: any, printOptions: any, size: any, DecimalsNumber: number) { let body: any = this.GetHeaderNames(ShowTaxColumn, SType, printOptions); let j = 1; if (!TrUtils.IsNull(Services) && Services.length !== 0) { Services.forEach((item: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1, }); if (!TrUtils.IsEmpty(item.EDesc)) { let DescData: any = []; DescData.push({ text: item.Desc, }); if (!TrUtils.IsEmpty(item['EDesc'])) { DescData.push({ text: item.EDesc, color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: item.Desc, }); } if (ShowTaxColumn) { dataRow.push({ text: item.SAC, alignment: 'center', style: ['headerstyle'], }); } dataRow.push({ text: '', alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: item.Qty, alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(item.Pr, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); if (printOptions.Disc !== 'NO') { if (printOptions.Disc === 'PERC') { dataRow.push({ text: TrUtils.FixPriceValue(item.DiscPerc, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); } else { dataRow.push({ text: TrUtils.FixPriceValue(item.Disc, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); } } if (ShowTaxColumn && printOptions.ShowTax !== 'NO') { let Tax: any = item.TaxName?.split('%'); dataRow.push({ text: TrUtils.IsNull(Tax) ? '' : Tax[0], alignment: 'right', style: ['headerstyle'], }); } dataRow.push({ text: item.Ret ? '-' + TrUtils.FixPriceValue(item.LineTotal, DecimalsNumber) : TrUtils.FixPriceValue(item.LineTotal, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); if (index + 1 === j * 9) { j++; if (size === 'diff') { let dataRow1: any = [{ text: '', pageBreak: 'after' }, '', '', '', '', '']; if (ShowTaxColumn) { dataRow1.push(''); dataRow1.push(''); } body.push(dataRow1); } } }); } if (!TrUtils.IsNull(Items) && Items.length !== 0) { if (!TrUtils.IsNull(Services) && Services.length !== 0) { let dataRow: any = []; dataRow.push({ text: '', }); dataRow.push({ text: '', }); if (ShowTaxColumn) { dataRow.push({ text: '', alignment: 'center', style: ['headerstyle'], }); } dataRow.push({ text: '', alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); if (printOptions.Disc !== 'NO') { if (printOptions.Disc === 'PERC') { dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); } else { dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); } } if (ShowTaxColumn && printOptions.ShowTax !== 'NO') { dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); } dataRow.push({ text: '', alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); } Items.forEach((item: any, index: any) => { let dataRow: any = []; dataRow.push({ text: index + 1, }); // dataRow.push({ text: item.Desc, }); if (!TrUtils.IsEmpty(item.EDesc)) { let DescData: any = []; DescData.push({ text: item.Desc, }); if (!TrUtils.IsEmpty(item['EDesc'])) { DescData.push({ text: item.EDesc, color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: item.Desc, }); } if (ShowTaxColumn) { dataRow.push({ text: item.HSN, alignment: 'center', style: ['headerstyle'], }); } dataRow.push({ text: item.Batch?.BN, alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: MyDate.ConvertUTCDateToReadableExDate(item['Batch']?.ExDt), alignment: 'center', style: ['headerstyle'], }); dataRow.push({ text: item.QtyAndUoM, alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: item.OfQty, alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(item.MRP, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(item.UnPr, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); if (printOptions.Disc !== 'NO') { if (printOptions.Disc === 'PERC') { dataRow.push({ text: TrUtils.FixPriceValue(item.DiscPerc, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); } else { dataRow.push({ text: TrUtils.FixPriceValue(item.Disc, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); } } if (ShowTaxColumn && printOptions.ShowTax !== 'NO') { let Tax: any = item.TaxName?.split('%'); dataRow.push({ text: TrUtils.IsNull(Tax) ? '' : Number(Tax[0]), alignment: 'right', style: ['headerstyle'], }); } dataRow.push({ text: item.Ret ? '-' + TrUtils.FixPriceValue(item.LineTotal, DecimalsNumber) : TrUtils.FixPriceValue(item.LineTotal, DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); if (index + 1 === j * 9) { j++; if (size === 'diff') { let dataRow1: any = [{ text: '', pageBreak: 'after' }, '', '', '', '', '']; if (ShowTaxColumn) { dataRow1.push(''); dataRow1.push(''); } body.push(dataRow1); } } }); } return body; } static GetHeaderNames(ShowTaxColumn: any, SType: any, printOptions: any) { let HeadingNames: any; if (ShowTaxColumn) { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', fontSize: 7 }, { text: 'Item Name', style: 'tableheader1', Field: 'Desc', alignment: 'left', line: true }, { text: 'HSN/SAC', style: 'tableheader1', Field: 'HSN' }, { text: 'Batch No.', style: 'tableheader1', Field: 'Batches' }, { text: 'Ex.Dt', style: 'tableheader1', Field: 'ExDate' }, { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Free', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, { text: 'MRP', style: 'tableheader1', Field: 'MRP', alignment: 'right' }, { text: 'Price', style: 'tableheader1', Field: 'UnPr', alignment: 'right' }, { text: 'Line Total', style: 'tableheader1', Field: 'LineTotal', alignment: 'right' }]]; if (printOptions.Disc !== 'NO') { HeadingNames[0].splice(9, 0, { text: (printOptions.Disc === 'PERC') ? 'Disc(%)' : 'Disc(Rs)', style: 'tableheader1', Field: 'Disc' }, ) } if (printOptions.ShowTax !== 'NO') { HeadingNames[0].splice(10, 0, { text: (SType === 'Intra') ? 'GST(%)' : 'IGST(%)', style: 'tableheader1', Field: 'TaxAmount', alignment: 'right' } ) } } else { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left' }, { text: 'Item Name', style: 'tableheader1', Field: 'Desc', alignment: 'left', line: true }, { text: 'Batch No.', style: 'tableheader1', Field: 'Batches', alignment: 'left' }, { text: 'Ex.Dt', style: 'tableheader1', Field: 'ExDate', alignment: 'left' }, { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Free', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, { text: 'MRP', style: 'tableheader1', Field: 'MRP', alignment: 'right' }, { text: 'Price', style: 'tableheader1', Field: 'UnPr', alignment: 'right' }, // { text: 'Disc(%)', style: 'tableheader1', Field: 'Disc' }, { text: 'Line Total', style: 'tableheader1', Field: 'LineTotal', alignment: 'right' }]]; if (printOptions.Disc !== 'NO') { HeadingNames[0].splice(8, 0, { text: (printOptions.Disc === 'PERC') ? 'Disc(%)' : 'Disc(Rs)', style: 'tableheader1', Field: 'Disc' }, ) } } return HeadingNames; } static TotalDetails(ROPrintData: any, moreDiscDetails: boolean, DecimalsNumber: number) { let totalDisc: any; let totalTax: any; if (!ROPrintData.Consolidate) { totalTax = TrUtils.FixPriceValue(Add(Number(ROPrintData.CustLaborITax), Number(ROPrintData.CustPartITax)), DecimalsNumber); if (TrUtils.isTaxable(ROPrintData.Settings.Tax)) { totalDisc = TrUtils.FixPriceValue(Add(Number(ROPrintData.CustLaborDiscTotal), Number(ROPrintData.CustPartsDiscTotal)), DecimalsNumber); } else { totalDisc = TrUtils.FixPriceValue(Add(Number(ROPrintData.CustLaborDiscTotal), Number(ROPrintData.CustPartsDiscTotal)), DecimalsNumber); } } return [ { style: 'tableExample', marginTop: -3, table: { widths: ['*', '*'], body: [ [ { stack: [this.PartsTaxAmounts1(ROPrintData.TaxSummary, true, ROPrintData.ShowIGST, ROPrintData.ShowTaxColumn)] }, { columns: [{ text: '', width: moreDiscDetails ? 120 : 150 }, this.GrandTotal(ROPrintData, '0.00', ROPrintData.CustPartsTotalBeforeDisc, totalDisc, totalTax, ROPrintData.For, ROPrintData.FixedTotal, ROPrintData.CustTotalRoundedBy, ROPrintData.CustRoundedTotal, null, ROPrintData.Consolidate, ROPrintData.STotal, moreDiscDetails, ROPrintData.Entity.DecimalsNumber)], } ], ] }, layout: 'noBorders' }, ]; } static PartsTaxAmounts(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (ShowTaxColumn) { return { stack: [this.AllHSNPartCGSTTaxListTable(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn)] }; } else { return ''; } } static GrandTotal(InvoiceData: any, LaborAfterGST: any, PartsAfterGST: any, OverAllRecordDiscount: any, totalTax: any, For: any, OverAllRecordTotal: any, Rounded: any, GrandTotal: any, Adj: any, Consolidate: any, subTotal: any, moreDiscDetails: boolean, DecimalsNumber: number) { let AccountFields = [ ]; if (moreDiscDetails) { if (!TrUtils.IsZero(InvoiceData.PDisc)) { AccountFields.push({ name: 'Items Discount', value: TrUtils.FixPriceValue(InvoiceData.PDisc, DecimalsNumber) }); } if (!TrUtils.IsZero(InvoiceData.LDisc)) { AccountFields.push({ name: 'Services Discount', value: TrUtils.FixPriceValue(InvoiceData.LDisc, DecimalsNumber) }); } if (!TrUtils.IsZero(InvoiceData.Disc)) { AccountFields.push({ name: 'Overall Discount', value: TrUtils.FixPriceValue(InvoiceData.Disc, DecimalsNumber) }); } } else { AccountFields.push({ name: 'Discount', value: OverAllRecordDiscount }); } if (!Consolidate && !TrUtils.IsNull(subTotal)) { AccountFields.unshift({ name: 'SubTotal', value: TrUtils.FixPriceValue(TrUtils.SetValueToZeroIfNull(Number(subTotal)), DecimalsNumber) }); } else { if (!Consolidate) { AccountFields.unshift({ name: 'SubTotal', value: TrUtils.FixPriceValue(Add(TrUtils.SetValueToZeroIfNull(Number(LaborAfterGST)), TrUtils.SetValueToZeroIfNull(Number(PartsAfterGST))), DecimalsNumber) }); } } if (!TrUtils.IsEmpty(totalTax)) { AccountFields.push({ name: 'Total Tax', value: totalTax }); } if (!TrUtils.IsEmpty(Adj)) { if (Adj > 0) { Adj = '+' + TrUtils.FixPriceValue(Adj, DecimalsNumber); } AccountFields.push({ name: 'Adjust', value: Adj }); } if (For === PayTypeEnum.Insurance) { let total = { name: 'Total', value: OverAllRecordTotal }; let Rounding = { name: 'Rounding', value: Rounded }; if (Rounding.value > 0) { Rounding.value = '+' + Rounding.value; } let FinalTotal = { name: 'Final Total', value: GrandTotal, bold: true, fontSize: 12 }; AccountFields.push(total); AccountFields.push(Rounding); if (!TrUtils.IsFixedZero(Rounded)) { AccountFields.push(FinalTotal); } } else { let total = { name: 'Total', value: OverAllRecordTotal }; let Rounding = { name: 'Rounding', value: Rounded }; let FinalTotal = { name: 'Final Total', value: GrandTotal }; if (Rounding.value > 0) { Rounding.value = '+' + Rounding.value; } // AccountFields.push(total); AccountFields.push(Rounding); if (!TrUtils.IsFixedZero(Rounded)) { AccountFields.push(FinalTotal); } } return { style: ['columnheader', 'TotalsStyles'], lineHeight: 0.7, marginBottom: 5, width: 'auto', table: { widths: ['auto', 'auto', 60], body: this.GrandTotalTable(AccountFields) }, layout: 'noBorders' }; } static AllHSNPartCGSTTaxListTable(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (ShowIGST) { return { style: 'tableExample1', table: { widths: [50, 30, 45, 45], headerRows: 1, body: this.CreateHSNTaxTable(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn) }, layout: this.HeaderLineStyle(), }; } else { return { style: 'tableExample1', table: { widths: [50, 30, 30, 60, 60], headerRows: 1, body: this.CreateHSNTaxTable(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn) }, layout: this.HeaderLineStyle(), }; } } static PartsTaxAmounts1(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (ShowTaxColumn && !TrUtils.IsNull(PartsTaxInfo) && PartsTaxInfo.length > 0) { return { stack: [this.AllHSNPartCGSTTaxListTable1(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn)] }; } else { return ''; } } static AllHSNPartCGSTTaxListTable1(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (ShowIGST) { return { style: 'tableExample', table: { widths: [25, 60, 50], headerRows: 1, body: this.CreateHSNTaxTable1(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn) }, layout: this.HeaderLineStyle(), }; } else { return { style: 'tableExample', table: { widths: [25, 60, 40, 40], headerRows: 1, body: SharedPDFService.CreateHSNTaxTable1(PartsTaxInfo, ShowAccParts, ShowIGST, ShowTaxColumn) }, layout: this.HeaderLineStyle(), }; } } static CreateHSNTaxTable1(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (!TrUtils.IsNull(PartsTaxInfo) && PartsTaxInfo.length !== 0 && ShowAccParts && ShowTaxColumn) { var body: any = []; let columns: any = this.CreateHeadingAllTaxList(ShowIGST); body.push(columns); PartsTaxInfo.forEach((part: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (!TrUtils.IsFixedZero(part[column.Field]) && !TrUtils.IsNull(part[column.Field]) || column.Field === 'SGST' || column.Field === 'CGST' || column.Field === 'SGSTAmt' || column.Field === 'CGSTAmt' || column.Field === 'TotalTaxableAmount') { if (column.Field === 'TotalTaxableAmount' || column.Field === 'SGSTAmt' || column.Field === 'CGSTAmt' || column.Field === 'IGSTAmt') { dataRow.push({ text: TrUtils.FixPriceValue(part[column.Field]), alignment: 'right', opacity: 0.7, nowrap: true, fontSize: 6 }); } else if (column.Field === 'CombinedTaxPercentage') { dataRow.push({ text: part[column.Field].toString() + '%', alignment: 'left', opacity: 0.7, nowrap: true, fontSize: 6 }); } else { dataRow.push({ text: part[column.Field].toString(), alignment: 'left', opacity: 0.7, nowrap: true, fontSize: 6 }); } } else { part[column.Field] = ''; dataRow.push({ text: part[column.Field].toString(), alignment: 'left', opacity: 0.7, fontSize: 6 }); } }); body.push(dataRow); }); return body; } else { return [{}]; } } static CreateHeadingAllHSNTaxList(ShowIGST: any) { let HeaderNames = [{ text: 'HSN', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'HSN', alignment: 'right' }, { text: 'Taxable Value', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'TotalTaxableAmount', alignment: 'right' }, { text: 'Amount', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'TotalTaxAmount', alignment: 'right' }, ]; if (ShowIGST) { HeaderNames.splice(1, 0, { text: 'IGST', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'IGST', alignment: 'right' }) } else { HeaderNames.splice(1, 0, { text: 'CGST', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'CGST', alignment: 'right' }) HeaderNames.splice(2, 0, { text: 'SGST', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'SGST', alignment: 'right' }) } return HeaderNames; } static CreateHeadingAllTaxList(ShowIGST: any) { let HeaderNames = [ // { text: 'CGST', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'CGST' }, // { text: 'SGST', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'SGST' }, // { text: 'Count', style: 'tableheader', fontSize: 6, lineHeight: 0.3, Field: 'PartsCount' }, { text: 'Tax Rate', style: 'tableheader2', fontSize: 6, lineHeight: 0.8, Field: 'CombinedTaxPercentage', alignment: 'left' }, { text: 'Taxable Amount', style: 'tableheader2', fontSize: 6, lineHeight: 0.8, Field: 'TotalTaxableAmount', alignment: 'right' }, // { text: 'Tax Amount', style: 'tableheader2', fontSize: 6, lineHeight: 0.3, Field: 'TotalTaxAmount' }, ]; if (ShowIGST) { // HeaderNames.splice(1, 0, { text: 'IGST(%)', style: 'tableheader2', fontSize: 6, lineHeight: 0.3, Field: 'IGST' }); HeaderNames.splice(2, 0, { text: 'IGST(Rs.)', style: 'tableheader2', fontSize: 6, lineHeight: 0.8, Field: 'IGSTAmt', alignment: 'right' }); } else { // HeaderNames.splice(1, 0, { text: 'CGST(%)', style: 'tableheader2', fontSize: 6, lineHeight: 0.3, Field: 'CGST' }); HeaderNames.splice(2, 0, { text: 'CGST(Rs.)', style: 'tableheader2', fontSize: 6, lineHeight: 0.8, Field: 'CGSTAmt', alignment: 'right' }); // HeaderNames.splice(3, 0, { text: 'SGST(%)', style: 'tableheader2', fontSize: 6, lineHeight: 0.3, Field: 'CGST' }); HeaderNames.splice(3, 0, { text: 'SGST(Rs.)', style: 'tableheader2', fontSize: 6, lineHeight: 0.8, Field: 'SGSTAmt', alignment: 'right' }); } return HeaderNames; } static CreateHSNTaxTable(PartsTaxInfo: any, ShowAccParts: any, ShowIGST: any, ShowTaxColumn: any) { if (!TrUtils.IsNull(PartsTaxInfo) && PartsTaxInfo.length !== 0 && ShowAccParts && ShowTaxColumn) { var body: any = []; let columns: any = this.CreateHeadingAllHSNTaxList(ShowIGST); // body.push(columns); PartsTaxInfo.forEach((part: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (!TrUtils.IsFixedZero(part[column.Field]) && !TrUtils.IsNull(part[column.Field]) || column.Field === 'SGST' || column.Field === 'CGST' || column.Field === 'TotalTaxAmount') { if (column.Field === 'HSN') { dataRow.push({ text: part[column.Field].toString(), alignment: 'right', nowrap: true }); } else { dataRow.push({ text: part[column.Field].toString(), alignment: 'right', nowrap: true }); } } else { part[column.Field] = ''; dataRow.push({ text: part[column.Field].toString(), alignment: 'right' }); } }); body.push(dataRow); }); return body; } else { return [{}]; } } static GetNumberInWords(TotalAmount: any) { var rupee = SharedPDFService.convertNumberToWords(TotalAmount); // console.log('rupee', rupee); return { columns: [{ text: 'In Words :', fontSize: 8, width: 45 }, { text: rupee, bold: true, fontSize: 8, width: '*' }] } } static HeaderLineStyle() { return { hLineWidth: function (i: any, node: any) { return (i === 1) ? 0.1 : 0; }, vLineWidth: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 0 : 0; }, hLineColor: function (i: any, node: any) { let color; if (i === 0 || i === node.table.body.length) { color = 'black'; } else { if (i === 1) { color = 'lightgray'; } else { color = 'lightgray'; } } return color; }, }; } }