import { SharedPDFService } from "../../shared/shared-pdf.service"; import { PrintSharedService } from "../../shared/shared-print.service"; import { TrUtils } from "../../utils/tr-utils"; export class MaterialOutprintService { static SmallFont: number = 6; static MediumFont: number = 8; static LargeFont: number = 9; dd: any; static MaterialOutPDF(MOutPrintData: any) { let dd = { info: { title: this.GetFileName(MOutPrintData), }, background: function (currentPage: any, pageSize: any) { return SharedPDFService.GetWatermarkImage(MOutPrintData.Image, pageSize, MOutPrintData.Entity.Wmark); }, header: function (currentPage: any, pageCount: any) { return { text: currentPage.toString() + ' of ' + pageCount, alignment: 'right', marginRight: 7, fontSize: 8, marginTop: 2 }; }, pageMargins: [10, 15, 10, 15], content: [ // SharedPDFService.MainHeading(MOutPrintData.Entity.CName, MOutPrintData.Entity.Header, MOutPrintData.Image, MOutPrintData.HColor, null), SharedPDFService.GetMainHeader(MOutPrintData.Entity, MOutPrintData.Image, MOutPrintData.AColor, MOutPrintData.HColor, null), SharedPDFService.GetPrintType(MOutPrintData.HeaderName), SharedPDFService.HeaderAfterLine(), this.GetVendorDetails(MOutPrintData), this.VendorDetailsAfterLine(), this.GetDisplayTable(), this.getPartsData(MOutPrintData), // SharedPDFService.GetUnderLine(), // SharedPDFService.GetTemsAndConditions(MOutPrintData.Entity.Terms), SharedPDFService.GetUnderLine(), this.GetSignatures(MOutPrintData.Entity.CName), ], styles: this.GetStyles() }; return dd; } static GetFileName(MOutPrintData: any) { let fileName: string = MOutPrintData.HeaderName; return fileName; } static GetDisplayTable() { return { text: '', fontSize: 10, bold: true, margin: [0, 0, 0, 5] }; } static GetStyles() { return { temp2header: { fontSize: 23, bold: true, alignment: 'left', // margin: [0, 10, 0, 0], }, header: { fontSize: 26, bold: true, alignment: 'center', // margin: [0, 10, 0, 0], }, Cust_Adrs: { fontSize: this.MediumFont, lineHeight: 1.2, }, WSHeader_Left: { fontSize: 23, bold: true, alignment: 'left', // margin: [0, 10, 0, 0], }, WSHeader_Center: { fontSize: 26, bold: true, alignment: 'center', // margin: [0, 10, 0, 0], }, ws_adrs_center: { fontSize: this.MediumFont, alignment: 'center', }, ws_adrs_left: { fontSize: this.MediumFont, alignment: 'left', }, table_data: { margin: [0, 0.5, 0, 5], fontSize: this.MediumFont }, table_header: { bold: true, fontSize: this.LargeFont, margin: [0, 1, 0, 5], alignment: 'center' }, vendor_font: { fontSize: this.MediumFont, margin: [0, 5, 0, 5], }, PO_Status: { fontSize: this.MediumFont, lineHeight: 1.4, margin: [10, 0, 0, 0], }, po_status_font: { fontSize: this.LargeFont, // bold: true }, totals_Styles: { marginTop: 15, lineHeight: 1.4, fontSize: this.MediumFont, margin: [15, 0, 0, 0], }, total_margin: { margin: [0, 5, 0, 0], }, hed: { fontSize: this.LargeFont, bold: true }, Receiptheader1: { fontSize: 12, bold: true, alignment: 'center', margin: [0, 0, 0, 3] }, } } static MainHeading(CName: any, Header: any, Image: any, HColor: any, AColor: any) { let headerstyle: string; let MainHeaderStyle: any = this.GetMainHeaderStyleForLeftAlignHeader(CName); if (Header === 1) { headerstyle = 'WSHeader_Center'; } else { headerstyle = 'WSHeader_Left'; } return [{ text: '' + CName + '', style: [headerstyle, MainHeaderStyle] }]; } static GetMainHeaderStyleForLeftAlignHeader(WorkShopName: string) { var wsname_fontSize: any; if (TrUtils.IsNull(WorkShopName)) { WorkShopName = ''; } switch (true) { case (WorkShopName.length < 30): wsname_fontSize = 23; break; case (WorkShopName.length < 35): wsname_fontSize = 20; break; case (WorkShopName.length < 50): wsname_fontSize = 17; break; default: wsname_fontSize = 14; } var WSHeaderFontSize: any = { fontSize: wsname_fontSize, bold: true, }; return WSHeaderFontSize; } static GetHeader(Entity: any) { let headerstyle: string; if (Entity.Header === 1) { headerstyle = 'ws_adrs_center'; } else { headerstyle = 'ws_adrs_left'; } let SubHeader: any = [ { text: '' + Entity.Adrs1 + '', style: [headerstyle] }, { text: '' + Entity.City + this.GetPinCode(Entity.PIN) + ', ' + 'Ph: ' + Entity.Phone, style: headerstyle }, { text: '' + this.GetEmailName(Entity.Email) + '', style: headerstyle } ]; if (!TrUtils.IsEmpty(Entity.Adrs2)) { SubHeader.splice(1, 0, { text: '' + Entity.Adrs2 + '', style: [headerstyle] }); } if (!TrUtils.IsEmpty(Entity.TLine)) { SubHeader.unshift({ text: this.GetTagLine(Entity.TLine), fontSize: 10, bold: true, margin: [0, 0, 0, 2] }); } return SubHeader; } static GetEntityDetails(Entity: any) { return { lineHeight: 0.7, columns: [this.GetEntityTaxDetails(Entity) ] }; } static GetTagLine(TLine: any) { if (TrUtils.IsEmpty(TLine)) { TLine = ''; } return TLine; } static GetEmailName(email: any) { let Email: any = ''; if (!TrUtils.IsNull(email)) { Email = 'Email: ' + email; } return Email; } static GetPinCode(pin: any) { let code: any = ''; if (!TrUtils.IsNull(pin)) { code = ' - ' + pin; } return code; } static GetEntityTaxDetails(Entity: any) { let EntityData: any = []; if (!TrUtils.IsEmpty(Entity.GSTIN)) { EntityData.push({ name: 'GSTIN', value: Entity.GSTIN }) } if (!TrUtils.IsEmpty(Entity.PAN)) { EntityData.push({ name: 'PAN No', value: Entity.PAN }) } if (EntityData.length !== 0) { return this.GetEntityeDataTable(EntityData); } else { return SharedPDFService.emptyObject(); } } static GetEntityeDataTable(EntityFields: any) { return { lineHeight: 0.7, marginLeft: 25, fontSize: this.SmallFont, table: { body: [ [{ table: { fontSize: this.SmallFont, widths: [37, 'auto', '*'], body: this.DataCreateForTable(EntityFields) }, layout: 'noBorders', }] ] }, layout: 'noBorders', }; } static DataCreateForTable(EntityFields: any) { var body: any = []; EntityFields.forEach((row: any) => { if (!TrUtils.IsFixedZero(row.value) && !TrUtils.IsEmpty(row.value)) { var dataRow: any = []; dataRow.push({ text: (row.name).toString(), noWrap: true }); dataRow.push(':'); dataRow.push({ text: (row.value).toString(), noWrap: true }); body.push(dataRow); } }); return body; } static GetVendorDetails(PurchaseOrder: any) { return { style: 'vendor_font', columns: [ { stack: [this.GetVendorData(PurchaseOrder.ShipTo, PurchaseOrder.Type)], width: 120 }, { text: '', width: 250 }, this.GetVehicle(PurchaseOrder) ], // columnGap: 150 }; } static GetVehicle(PurchaseOrder: any) { if(TrUtils.IsNull(PurchaseOrder.BL.VNo)){ PurchaseOrder.BL.VNo=''; } return { style: 'PO_Status', lineHeight: 0.7, columns: [ { table: { fontSize: 6, widths: [37, 'auto', '*'], body: [[{ text: 'ID', alignment: 'right', style: 'po_status_font' }, { text: ':', style: 'po_status_font' }, PurchaseOrder._id], [{ text: 'Date', alignment: 'right', style: 'po_status_font' }, { text: ':', style: 'po_status_font' }, PurchaseOrder.CrDate], [{ text: 'Reason', alignment: 'right', style: 'po_status_font' }, { text: ':', style: 'po_status_font' }, PurchaseOrder.ResName], [{ text: 'Vehicle', alignment: 'right', style: 'po_status_font' }, { text: ':', style: 'po_status_font' }, PurchaseOrder?.BL?.VNo], // [{ text: 'Status', alignment: 'right', style: 'po_status_font' }, { text: ':', style: 'po_status_font' }, PurchaseOrder.Status] ] }, layout: 'noBorders', }, ] }; } static GetVendorData(Vendor: any, Type: any) { if (TrUtils.IsNull(Vendor)) { return SharedPDFService.emptyObject(); } return { style: 'Cust_Adrs', stack: [{ text: 'User Name :', style: 'hed' }, { text: Vendor.Name, marginTop: 2 }, // { text: this.GetAddress(Vendor), marginTop: 3 }, this.GetVendorPhoneNumber(Vendor.Ph, Type) ] }; } static GetAddress(Vendor: any) { var Address = this.GetFormatAddress(Vendor); if (Address.length !== 5) { return Address; } else { let a: any = ''; return a; } } static GetFormatContact(CustomerObj: any) { var contactnew = ''; CustomerObj.Contact.forEach((Contact: any) => { contactnew = contactnew + '(' + Contact.Type + '):' + Contact.No + '\n'; }); return contactnew; } static GetFormatAddress(CustomerObj: any) { var Addressnew = ''; if (!TrUtils.IsNull(CustomerObj) && !TrUtils.IsNull(CustomerObj.Adrs)) { CustomerObj.Adrs.forEach((Adrs: any) => { Addressnew = Addressnew + Adrs + '\n'; }); } return Addressnew; } static GetVendorGSTIN(Vendor: any) { let GSTIN: any = {}; if (!TrUtils.IsEmpty(Vendor.GSTIN)) { let columns: any = []; columns.push({ text: 'GSTIN :', width: 33, style: 'hed' }); columns.push({ text: Vendor.GSTIN, marginTop: 1.5 }); GSTIN.columns = columns; return GSTIN; } else { return GSTIN; } } static GetVendorPhoneNumber(Phone: any, Type: any) { let PhoneNumber: any = {}; if (Type !== 'Technician Copy') { // var contact = this.GetFormatContact(Vendor); // if (contact.length !== 0) { let columns: any = []; columns.push({ text: 'Phone', width: 27, style: 'hed' }); columns.push({text:Phone+ '\n'}); PhoneNumber.columns = columns; return PhoneNumber; // } else { // return PhoneNumber; // } } else { return PhoneNumber; } } static VendorDetailsAfterLine() { return { canvas: [ { type: 'line', lineColor: 'black', x1: 0, y1: 0, x2: 575, y2: 0, lineWidth: 1 } ] }; } static getPartsData(MOutPrintData: any) { return this.GetWithOutDiscAndTaxFieldHeader( TrUtils.Stringify(MOutPrintData.Items), MOutPrintData.Entity.MPN, MOutPrintData.ShowTaxColumn, MOutPrintData.Entity.Body, MOutPrintData.ShowIGST, MOutPrintData.ShowDiscountColumn); } static GetWithOutDiscAndTaxFieldHeader(Items: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ShowDiscountColumn: any) { if (Items.length !== 0) { return this.WithOutTaxDataTable(PrintPartNo, ShowIGST, Items, Body, ShowTaxColumn, ShowDiscountColumn) } else { let a: any = ''; return a; } } static WithOutTaxDataTable(PrintPartNo: any, ShowIGST: any, Items: any, Body: any, ShowTaxColumn: any, ShowDiscountColumn: any) { return this.WithOutTaxDataTableWithPartNumber(Items, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ShowDiscountColumn); } static WithOutTaxDataTableWithPartNumber(Items: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ShowDiscountColumn: any) { return { style: 'table_data', table: { widths: [25, '*', 150, 60], body: this.BuildTableBodyForLaborAndParts(Items, PrintPartNo, ShowTaxColumn, Body, ShowIGST, ShowDiscountColumn) }, layout: PrintSharedService.LayOutStyle() }; } static GetHeaderNames(){ let headersNames: any = [{ text: 'S.No.', style: 'tableheader', Field: 'SNo' }, { text: 'Description', style: 'tableheader', Field: 'Desc' }, { text: 'MPN', style: 'tableheader', Field: 'MPN' }, { text: 'Qty', style: 'tableheader', Field: 'QtyAndUoM' }]; return headersNames; } static BuildTableBodyForLaborAndParts(Items: any, PrintPartNo: any, ShowTaxColumn: any, Body: any, ShowIGST: any, ShowDiscountColumn: any) { var body: any = []; let columns: any = this.GetHeaderNames(); // if (ShowTaxColumn) { // for (let i = 0; i < columns.length; i++) { body.push(columns); // } // columns = columns[0]; // } else { // body.push(columns); // } let PartsTable = this.GetPartsDataTable(Items, columns, body); return PartsTable; } static GetPartsDataTable(Items: any, columns: any, body: any) { let SNo: number = 1; // console.log('Items', Items); // console.log('columns', columns); Items.forEach((part: any) => { var dataRow: any = []; columns.forEach((column: any) => { if (!TrUtils.IsFixedZero(part[column.Field]) && !TrUtils.IsNull(part[column.Field])) { if (column.Field === 'QtyAndUoM') { dataRow.push({ text: part[column.Field]?.toString(), alignment: 'right', nowrap: true }); } else { // dataRow.push(part[column.Field].toString()); if (column.Field === 'Desc') { let DescData: any = []; DescData.push(part[column.Field]?.toString()); if (!TrUtils.IsEmpty(part['EDesc'])) { DescData.push({ text: part['EDesc'].toString(), color: 'grey' }); } dataRow.push({ stack: DescData }); } else { dataRow.push({ text: part[column.Field].toString() }); } } } else { if (column.Field === 'SNo') { part[column.Field] = SNo; SNo = SNo + 1; } else { part[column.Field] = ''; } dataRow.push({ text: part[column.Field].toString(), alignment: 'center' }); } }); body.push(dataRow); }); return body; } static GetSignatures(CName: any) { return { fontSize: this.MediumFont, columns: [{ stack: [ this.CompanyName(CName), { columns: [this.Authorizedsignature()] } ] }], }; } static CompanyName(CName: any) { return { style: 'forCompany', text: ['For ', { text: CName, bold: 'true' }], }; } static Authorizedsignature() { return { style: 'Sign', text: ['Authorized Signatory'], }; } static HeaderLineStyle() { return { hLineWidth: function (i: any, node: any) { return (i === 1) ? 0.5 : 0; }, vLineWidth: function (i: any, node: any) { return (i === 0 || i === node.table.widths.length) ? 0 : 0; }, }; } }