import { differenceInYears } from 'date-fns'; import { TrUtils } from '../../utils/tr-utils'; import { SharedPDFService } from '../../shared/shared-pdf.service'; import { MyDate } from '../../utils/my-date'; export class ConsultationFullPrintService { static GetPrint(consultationData: any) { if (TrUtils.IsNull(consultationData.Name)) { consultationData.Name = ''; } let dd: any = { info: { title: 'Consultation', }, footer: SharedPDFService.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, 80], pageSize: 'A4', content: [ this.GetMainHeaderDetails(consultationData, consultationData.Entity, consultationData.HeaderName, consultationData.Image, consultationData.HColor, consultationData.AColor, null), ], styles: { temp2header: { fontSize: 15, bold: true, alignment: 'left', // margin: [0, 10, 0, 0], }, 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 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, bold:true }, { 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: this.GetCnsltDate(CnstData, Entity.User), style: ['headerstyle'] }], marginTop: 5, width: 120 } ] } ]; } static GetCnsltDate(CnstData: any, User: any) { if (!TrUtils.IsNull(CnstData.ClDate)) { return MyDate.GetWeekDateAndTime(CnstData.ClDate, User.TZ); } else { return MyDate.GetWeekDateAndTime(CnstData.CrDate, User.TZ); } } 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?.Sltn+' '+CnstData?.Doc?.Name, fontSize: 15, 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%', marginTop:15} ] }; } else { return { columns: [SharedPDFService.GetImage(Image,Entity.Header.ShowLogo), {stack:[{ text: CnstData?.Doc?.Sltn+' '+CnstData?.Doc?.Name, fontSize: 15, 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 }], marginTop:25} ] }; } } 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; }, // 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 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 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 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 }; } }