import { SharedPDFService } from "../../shared/shared-pdf.service"; import { MyDate } from "../../utils/my-date"; import { TrUtils } from "../../utils/tr-utils"; declare var pdfMake: any; export class ReceiptPDFService { static PrintFile: any; static ReceiptPrint(ReceiptData: any, isHC: boolean) { var dd = { info: { title: 'Receipt', }, background: function (currentPage: any, pageSize: any) { return SharedPDFService.GetWatermarkImage(ReceiptData.Image, pageSize, ReceiptData.Entity.Wmark); }, header: function (currentPage: any, pageCount: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 7, fontSize: 8, marginTop: 2 }; }, pageMargins: [25, 15, 25, 15], content: [ // SharedPDFService.MainHeading(ReceiptData.Entity.CName, ReceiptData.Entity.Header, ReceiptData.Image, ReceiptData.HColor, null), SharedPDFService.GetMainHeader(ReceiptData.Entity, ReceiptData.Image, ReceiptData.AColor, ReceiptData.HColor, null), SharedPDFService.GetPrintType(ReceiptData.HeaderName), SharedPDFService.HeaderAfterLine2(), this.GetPayment(ReceiptData.PaymentId, isHC), this.GetName(ReceiptData.FullName), this.GetRupee(ReceiptData.TotalAmount), this.GetTowards(ReceiptData.Ids, ReceiptData.RepairOrder, ReceiptData.Sts, ReceiptData.RemAmt, ReceiptData.RefundAmount), this.GetAmount(ReceiptData.PaymentType, ReceiptData.TypeNumber, ReceiptData.PaidDate), // this.GetDrawDate(ReceiptData.PaymentType,ReceiptData.PaidDate), this.GetCompanyName(ReceiptData.Entity.CName), this.GetAmountAndSignature(ReceiptData.TotalAmount) ], styles: SharedPDFService.GetStyles() }; return dd; } static PrintFiles() { let dd = TrUtils.Stringify(this.PrintFile); pdfMake.createPdf(dd).open(); } static GetAmountAndSignature(Amount: any) { return { marginLeft: 20, columns: [ { stack: [ { text: [{ text: 'Rs. ', fontSize: 13 }, { text: Amount + '/-', bold: true, fontSize: 15 }], style: 'Rupees' }, { canvas: [ { type: 'line', x1: 25, y1: 2, x2: 80, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }, {}, { style: 'Signature', text: ['Authorized Signatory'], marginRight: 30, alignment: 'right', } ] }; } static GetCompanyName(CompanyName: any) { return { style: 'forCompany', alignment: 'right', marginTop: 15, text: ['For ', { text: CompanyName, bold: 'true' }], }; } static GetPayment(PaymentId: any, isHC: boolean) { var date = this.todaydate(); return { style: 'Row1', columns: [ { style: 'column', stack: [{ text: [{ text: 'No: ' }, { text: PaymentId, bold: true }] }, { canvas: [ { type: 'line', x1: 17, y1: 2, x2: 62, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }, { }, {}, this.GetDate(date, isHC) ] }; } static GetDate(date: any, isHC: boolean) { if (isHC) { return {}; } else { return { stack: [ { text: [{ text: 'Date: ' }, { text: date, bold: true }] }, { canvas: [ { type: 'line', x1: 25, y1: 2, x2: 80, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] } } } static GetName(Name: any) { return { stack: [ { text: [{ text: 'Received with thanks from ' }, { text: Name, bold: true },], style: 'rowdata' }, { canvas: [ { type: 'line', x1: 110, y1: 2, x2: 545, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }; } static GetRupee(TotalAmount: any) { var rupee = SharedPDFService.convertNumberToWords(TotalAmount); return { stack: [ [ { text: [ { text: 'the sum of Rs. ' }, { text: rupee, bold: true, fontSize: 8 } ], style: 'rowdata' }], { canvas: [ { type: 'line', x1: 63, y1: 2, x2: 545, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }; } static GetTowards(Ids: any, IsRepairOrder: boolean, Sts: any, RemAmt: any, RefundAmt: any) { let data: any = ''; let toward: any = ''; for (let i = 0; i < Ids.length; i++) { if (i + 1 < Ids.length) { data = data + Ids[i] + ', '; } else { data = data + Ids[i]; } } if (!TrUtils.IsEmpty(data) || RefundAmt > 0) { if (IsRepairOrder) { toward = 'RO - ' + data; } else { if (TrUtils.IsEmpty(data)) { if (RefundAmt > 0) { toward += '(refunded Rs.' + RefundAmt + ' )'; } } else { toward = 'INVOICE - ' + data; if (RefundAmt > 0) { toward += ', (refunded Rs.' + RefundAmt + ' )'; } } if (RemAmt > 0) { toward += ', (remaining Rs.' + RemAmt + ' as advance)'; } } } else { toward = ' Advance'; } return { columns: [ { stack: [ { text: [{ text: 'towards ', style: 'rowdata' }, { text: toward, bold: true, style: 'rowdata' }] }, { canvas: [ { type: 'line', x1: 38, y1: 2, x2: 545, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }, // { // stack: [ // { text: 'by way of', style: 'rowdata' }, // { // canvas: [ // { // type: 'line', // x1: 0, // y1: 2, // x2: 0, // y2: 2, // lineWidth: 0.1, // dash: {length: 2, space: 2} // } // ] // } // ] // } ], marginTop: 10 }; } static GetAmount(PaymentType: any, TypeNumber: any, PaidDate: any) { // var date = this.todaydate(); return { columns: [ { stack: [ { text: [{ text: 'by way of ', style: 'rowdata' }, { text: PaymentType + ' ' + TypeNumber + ' ', bold: true, style: 'rowdata' }] }, this.GetLineByPayType(PaymentType) ] }, { stack: [ { text: [{ text: ' dated ', style: 'rowdata', marginLeft: 10 }, { text: PaidDate, bold: true, style: 'rowdata' }], marginLeft: 5 }, { canvas: [ { type: 'line', x1: 32, y1: 2, x2: 90, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] } ], marginTop: 10 }; } static GetLineByPayType(PaymentType: any) { if (PaymentType === 'Debit Card' || PaymentType === 'Credit Card') { return { canvas: [ { type: 'line', x1: 43, y1: 2, x2: 275, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] }; } else if (PaymentType === 'Mobile Payment') { return { canvas: [ { type: 'line', x1: 43, y1: 2, x2: 275, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] }; } else { if (PaymentType !== 'Cash') { return { canvas: [ { type: 'line', x1: 43, y1: 2, x2: 275, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] }; } else { return { canvas: [ { type: 'line', x1: 43, y1: 2, x2: 275, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] }; } } } static GetDrawDate(PaymentType: any, date: any) { // var date = this.todaydate(); if (PaymentType === 'Cheque') { return { stack: [ { text: [{ text: 'drawn on ' }, { text: date, bold: true }], style: 'rowdata' }, { canvas: [ { type: 'line', x1: 38, y1: 2, x2: 545, y2: 2, lineWidth: 0.1, dash: { length: 2, space: 2 } } ] } ] }; } else { return {}; } } static todaydate() { let date = new Date(); let todayDate = date.toISOString(); return MyDate.ConvertUTCDateToReadable(todayDate); } }