import { differenceInYears } from 'date-fns'; import { TrUtils } from '../../utils/tr-utils'; import { SharedPDFService } from '../../shared/shared-pdf.service'; import { MyDate } from '../../utils/my-date'; import { Add } from '../../shared/math-operations'; export class ConsultationFeeReceiptPrintService { static GetPrint(consultationData: any) { if (TrUtils.IsNull(consultationData.Name)) { consultationData.Name = ''; } let dd: any = { info: { title: 'Consultation', }, footer: this.FooterContent(consultationData), header: function (currentPage: any, pageCount: any, pageSize: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 25, fontSize: 8, marginTop: 2 }; }, pageMargins: [35, 15, 15, 435.945], pageSize: 'A4', content: [ this.GetMainHeaderDetails(consultationData, consultationData.Entity, consultationData.HeaderName, consultationData.Image, consultationData.HColor, consultationData.AColor, null), this.GetItemsTable(consultationData.Items, consultationData.ShowTaxColumn), { columns: [{ text: '', width: '*' }, { text: this.finalReturnTotal(consultationData), width: '*', bold: true, fontSize: 10, alignment: 'center' }, this.GetTotalDeetails(consultationData)] }, ], styles: { headerstyle: { fontFamily: 'Calibri', fontSize: 9 }, Sign: { fontSize: 8, margin: [0, 30, 0, 5] }, forCompany: { // margin: [0, 10, 30, 0], marginRight: 5, marginTop: 10, fontSize: 9, alignment: 'left' }, 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 }, ws_adrs_left: { fontSize: 8, alignment: 'left', } } }; return dd; } static FooterContent(consultationData: any) { if (consultationData.Entity.Header === 2) { return { table: { widths: ['auto'], body: [ [{ text:consultationData.Entity.FootText, alignment:'center', fontSize:9 }] ] }, margin: [25, -50, 25, 10] } }else{ return { stack: [{ text: consultationData.Doc?.Name, bold: true, alignment: 'right', marginBottom: 5 }, SharedPDFService.HeaderAfterLine1(), { columns: [SharedPDFService.GetEntityAddress(consultationData.Entity)] }], margin: [25, -50, 25, 10] } } } static GetMainHeaderDetails(CnstData: any, Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any) { return [ this.GetHeaderBasedOnCondition(CnstData, Entity, HeaderName, Image, HColor, AColor, text), SharedPDFService.HeaderAfterLine1(), { columns: [{ stack: [{ text: CnstData.Pat.Name, fontSize: 10, marginTop: 5 }, { text: CnstData.Pat.Code + ' | ' + this.DifferenceInYears(CnstData.Pat.DOB, Entity.User.TZ) + ' | ' + CnstData.Pat.Sex + this.GetPhoneNumber(CnstData?.Pat?.Ph), fontSize: 10, marginBottom: 5 }] }, { stack: [{ text: 'Bill No : ' + CnstData.Code, style: ['headerstyle'] }, { text: 'Date : ' + MyDate.ConvertUTCDateToReadable(CnstData.CrDate), style: ['headerstyle'] }], marginTop: 5, width: 120 } ] } ]; } static GetHeaderBasedOnCondition(CnstData: any, Entity: any, HeaderName: any, Image: any, HColor: any, AColor: any, text: any) { if (Entity.Header === 2) { return { columns: [ SharedPDFService.GetConsultationMainHeader(Entity, null, AColor, HColor, text), {stack:[{ text: CnstData?.Doc?.Name, fontSize: 12, bold:true, alignment: 'right' }, { text: CnstData?.Doc?.Intro1, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro2, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro3, fontSize: 9, alignment: 'right' }, { text: 'Registration ID- '+CnstData?.Doc?.CounReg, fontSize: 9, alignment: 'right',marginBottom:5 }], width: '40%'}] }; } else { return { columns: [SharedPDFService.GetImage(Image,Entity.Header.ShowLogo), {stack:[{ text: CnstData?.Doc?.Name, fontSize: 12, bold:true, alignment: 'right' }, { text: CnstData?.Doc?.Intro1, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro2, fontSize: 9, alignment: 'right' }, { text: CnstData?.Doc?.Intro3, fontSize: 9, alignment: 'right' }, { text: 'Registration ID- '+CnstData?.Doc?.CounReg, fontSize: 9, alignment: 'right',marginBottom:5 }], width: '40%'}] }; } } static GetPhoneNumber(phone: any) { if (!TrUtils.IsNull(phone)) { return ' | ' + phone; } else { return ''; } } static getDoctorName(DocName: any) { if (!TrUtils.IsNull(DocName)) { return DocName; } else { return ''; } } static GetPhone(Phone: any) { if (TrUtils.IsNull(Phone)) { return ''; } else { return Phone; } } static DifferenceInYears(DOB: any, TZ: any) { if (TrUtils.IsNull(DOB)) { return 'DOB Not Specified'; } const result = differenceInYears(MyDate.GetDateTimeNowInUTC(TZ), new Date(DOB)); return result + ' Years'; } 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(consultationData: any) { let TaxInfo: any = []; if (!TrUtils.IsEmpty(consultationData.Entity.GSTIN)) { TaxInfo.push({ text: 'GSTIN : ' + consultationData.Entity.GSTIN, marginTop: 2, marginLeft: 5, alignment: 'left', fontSize: 9, width: 'auto' }, ); } if (!TrUtils.IsEmpty(consultationData.Entity.DLNo)) { TaxInfo.push({ text: 'D.L.NO : ' + consultationData.Entity.DLNo, marginTop: 2, marginLeft: 5, alignment: 'left', fontSize: 9, width: '*' }, ); } TaxInfo.push(this.GetBillofSupplyName(consultationData.Settings)); return TaxInfo; } static finalReturnTotal(consultationData: any) { // if (!TrUtils.IsFixedZero(consultationData.CustRetRoundedTotal)) { // return 'Returns Total : ' + consultationData.CustRetRoundedTotal // } else { return ''; // } } static GetTotalDeetails(consultationData: any) { let TotalData: any = []; TotalData.push({ name: 'Total', value: 500 }); return { style: ['columnheader', 'TotalsStyles'], lineHeight: 0.7, marginBottom: 5, width: 'auto', table: { body: this.GrandTotalTable(TotalData) }, layout: 'noBorders' }; } 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, bold: true, style: ['headerstyle'], fontSize: 10 }); dataRow.push({ text: ':', style: ['headerstyle'], bold: true, fontSize: 10 }); if (!TrUtils.IsNull(row.value)) { dataRow.push({ text: (row.value).toString(), noWrap: true, alignment: 'right', bold: true, style: ['headerstyle'], fontSize: 10, marginRight: 5 }); } else { dataRow.push({ text: '', noWrap: true, alignment: 'right', style: ['headerstyle'] }); } body.push(dataRow); } }); return body; } static GetBillofSupplyName(Settings: any) { return { text: Settings?.Tax === 'BS' ? 'Bill of Supply' : null, alignment: 'right', marginRight: 5, marginTop: 2, marginBottom: 3, fontSize: 9, width: 'auto' }; } static GetDiscountOverall(consultationData: any, DecimalsNumber: number) { let OveralDisc: number = Add(TrUtils.SetValueToZeroIfNull(Number(consultationData.Disc)) , TrUtils.SetValueToZeroIfNull(Number(consultationData.CustPartsDiscTotal))); return TrUtils.FixPriceValue(OveralDisc, DecimalsNumber); } 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, For: any, Type: any) { return { columns: [{ stack: [ this.CompanyName(CName), // { columns: [this.Authorizedsignature(), this.SurveyorSignature(For, Type), this.CustomerSignature()] } ] }], }; } static CompanyName(CName: any) { return { style: 'forCompany', text: ['For ', { text: CName, }], }; } static Authorizedsignature() { return { style: 'Sign', text: ['Authorized Signatory'], }; } static CustomerSignature() { return { style: 'Sign', text: ['Customer Signature'], marginLeft: 90 }; } static GetItemsTable(Items: any, ShowTaxColumn: boolean) { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.GetWidths(ShowTaxColumn), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(Items, ShowTaxColumn) }, layout: { hLineWidth: function (i:any, node:any) { return (i === 0 || i === 1 || (i === 20) || i === node.table.body.length) ? 1 : 0; }, vLineWidth: function (i:any, node:any) { return (i === 0 || i === node.table.widths.length) ? 1 : 0.5; }, // hLineStyle: function (i, node) { // return (i === 0 || i === 1) ? { dash: { length: 5, space: 5 } } : null; // }, hLineColor: function (i: any, node: any) { return 'gray'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, } }; } static GetWidths(ShowTaxColumn: any) { // if (ShowTaxColumn) { return [25, '*', 50, 60, 60, 70, 60]; // } else { // return ['*', 100, 50, 20, 50, 50]; // } } static GetAddress(Entity: any) { let Addres: string = Entity.Adrs1; if (!TrUtils.IsEmpty(Entity.Adrs2)) { Addres = Addres + ',' + Entity.Adrs2; } Addres = Addres + ',' + Entity.City + SharedPDFService.getPinCode(Entity.PIN); return { style: 'tableExample', table: { widths: ['auto', '*'], body: [ [{ text: 'Address -', bold: true }, { text: Addres }], [{ text: 'For Appointments' }, { text: 'Call: ' + Entity.Phone + ', ' + SharedPDFService.GetEmail(Entity.Email) }], ] }, layout: 'noBorders', } } static GetPINCode(PIN: any) { if (TrUtils.IsNull(PIN)) { return ''; } else { return '-' + PIN; } } static BuildTableBodyForLaborAndParts(Items: any, ShowTaxColumn: any) { let body: any = this.GetHeaderNames(ShowTaxColumn); let dataRow: any = []; dataRow.push({ text: '1', }); dataRow.push({ text: 'Doctor', }); dataRow.push({ text: '43423423', }); dataRow.push({ text: '1', alignment: 'right' }); dataRow.push({ text: '500', alignment: 'right' }); dataRow.push({ text: '', alignment: 'right' }); dataRow.push({ text: '500', alignment: 'right' }); body.push(dataRow); return body; } static GetHeaderNames(ShowTaxColumn: any) { let HeadingNames: any; // if (ShowTaxColumn) { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Services', style: 'tableheader1', Field: 'Doctor' }, { text: 'SAC', style: 'tableheader1', Field: 'SAC' }, { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Price', style: 'tableheader1', Field: 'UnPr', alignment: 'right' }, { text: 'Discount', style: 'tableheader1', Field: 'Disc' }, { text: 'Amount', style: 'tableheader1', Field: 'Amount', alignment: 'right' }]]; // } else { // HeadingNames = [[{ text: 'Description', style: 'tableheader1', Field: 'Desc', alignment: 'left', line: true }, // { text: 'Batches', style: 'tableheader1', Field: 'Batches', alignment: 'left' }, // { text: 'Ex.Dt', style: 'tableheader1', Field: 'ExDate', alignment: 'left' }, // { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, // { text: 'Price', style: 'tableheader1', Field: 'UnPr', alignment: 'right' }, // { text: 'Line Total', style: 'tableheader1', Field: 'LineTotal', alignment: 'right' }]]; // } return HeadingNames; } }