import { Add } from "../../../../shared/math-operations"; import { SharedPDFService } from "../../../../shared/shared-pdf.service"; import { TrUtils } from "../../../../utils/tr-utils"; declare var pdfMake: any; export class ManfWiseSalesService { static GetManfWiseSalePrint(InvoicesData: any, EntityData: any, isPhar: boolean, isHC: boolean, isSale:boolean, HeaderName:any, searchValue:any) { var dd = { info: { title: 'ManfWiseSale', }, 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: [ { text: '' + EntityData.DName + '', style: ['header'] }, { text: HeaderName, alignment: 'center', fontSize: 15, bold: true }, SharedPDFService.GetSearchValueDetails(searchValue), this.GetInvoiceDataTable(InvoicesData, isPhar, isHC, isSale, EntityData.Settings.DecimalsNumber), ], styles: SharedPDFService.GetStyles() }; return dd; } static GetInvoiceDataTable(InvoicesData: any, isPhar: boolean, isHC: boolean, isSale:boolean, DecimalsNumber: number) { let Data: any = [] // InvoicesData.forEach((invoice: any) => { Data.push(this.GetItemsTable(InvoicesData, isPhar, isHC, isSale, DecimalsNumber)); // }); return Data; } static getTableWidths(isSale: any) { if (isSale) { return [22, '*', 25, 25, 35,50, 40, 50, 80]; } else { return [22, '*', 25, 35,50, 50, 50, 80]; } } static GetItemsTable(InvoiceData: any, isPhar: boolean, isHC: boolean, isSale:boolean, DecimalsNumber: number) { // InvoicesData.forEach((InvoiceData: any) => { return { style: 'tableExample', marginTop: 3, marginBottom: 5, table: { widths: this.getTableWidths(isSale), headerRows: 1, body: this.BuildTableBodyForLaborAndParts(InvoiceData, isPhar, isHC, isSale, DecimalsNumber) // body:[['fsdfsdf','asfafdas','asdasdas','asdasdasd','asddass']] }, layout: { hLineWidth: function (i:any, node:any) { return (i === 0 || i === 1 || i === node.table.body.length) ? 1 : 0.5; }, 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 (i === 0 || i === 1 || i === node.table.body.length) ? 'gray' : 'lightgrey'; }, vLineColor: function (i: any, node: any) { return 'gray'; }, } }; // }); } static BuildTableBodyForLaborAndParts(InvoiceData: any, isPhar: boolean, isHC: boolean, isSale:boolean, DecimalsNumber: number) { let body: any = this.GetHeaderNames(isPhar, isHC, isSale); // let Row: any = [{ text: InvoiceData.Name, alignment: 'left', colSpan: isHC ? 5 : 8, bold: true, fontSize: 12 }, {}, {}, {}, {}]; // if (!isHC) { // Row.push({}); // Row.push({}); // Row.push({}); // } // body.unshift(Row); // InvoicesData.forEach((InvoiceData: any) => { InvoiceData.forEach((invoice: any, index: any) => { let dataRow: any = []; // if (isHC) { // dataRow.push({ text: index + 1 }); // dataRow.push({ text: invoice.Code }); // if (!isHC) { // dataRow.push({ text: invoice.Prod?.RegNo }); // dataRow.push({ text: TrUtils.IsNull(invoice.Prod) ? '' : invoice.Prod?.Model + ' ' + invoice.Prod?.Var }); // } // // dataRow.push({ text: invoice.BFrom.Name, alignment: 'left', style: ['headerstyle'], }); // dataRow.push({ text: MyDate.ConvertUTCDateToReadable(invoice.CrDate), alignment: 'center', style: ['headerstyle'], }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Total), alignment: 'right', style: ['headerstyle'], }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Due), alignment: 'right', style: ['headerstyle'], }); // body.push(dataRow); // if (InvoiceData.Invoices.length === (index + 1)) { // let Row: any = [{ text: 'Total Due ', alignment: 'right', colSpan: isHC ? 4 : 6, bold: true, fontSize: 9 }, {}, {}, {}, { text: TrUtils.FixPriceValue(InvoiceData.Balance), fontSize: 9, alignment: 'right', bold: true }]; // if (!isHC) { // Row.splice(2, 0, {}, {}); // // Row.push({}); // } // body.push(Row); // } // } else { dataRow.push({ text: index + 1 }); dataRow.push({ text:isSale?invoice.ShortName:invoice.VendName, style: ['headerstyle'], }); if(isSale){ dataRow.push({ text: invoice.Count, alignment: 'right' }); } dataRow.push({ text: invoice.Qty, alignment: 'right' }); // if(!isHC){ dataRow.push({ text: invoice.OfQty, alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.UnAmt, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Disc, DecimalsNumber), alignment: 'right' }); dataRow.push({ text: TrUtils.FixPriceValue(invoice.Tax, DecimalsNumber), alignment: 'right' }); // dataRow.push({ text: TrUtils.IsNull(invoice.Prod) ? '' : invoice.Prod?.Model + ' ' + invoice.Prod?.Var }); // } // dataRow.push({ text: invoice.BFrom.Name, alignment: 'left', style: ['headerstyle'], }); dataRow.push({ text: TrUtils.FixPriceValue(Add(invoice.UnAmt, invoice.Tax), DecimalsNumber), alignment: 'right', style: ['headerstyle'], }); // dataRow.push({ text: TrUtils.FixPriceValue(invoice.Due), alignment: 'right', style: ['headerstyle'], }); body.push(dataRow); // if (InvoiceData.Invoices.length === (index + 1)) { // let Row: any = [{ text: 'Total Due ', alignment: 'right', colSpan: isHC?4:6, bold: true, fontSize: 9 }, {}, {}, {}, { text: TrUtils.FixPriceValue(InvoiceData.Balance), fontSize: 9, alignment: 'right', bold: true }]; // if(!isHC){ // Row.splice(2, 0,{},{}); // // Row.push({}); // } // body.push(Row); // } // } }); // }); return body; } static GetHeaderNames(isPhar: boolean, isHC: boolean, isSale:boolean) { let HeadingNames: any; // if (isHC) { // HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, // { text: isPhar ? 'Counter Sale Number' : 'Invoice Number', style: 'tableheader1', Field: 'BNo', alignment: 'left' }, // { text: 'Create Date', style: 'tableheader1', Field: 'CrDate' }, // { text: 'Total', style: 'tableheader1', Field: 'Total', alignment: 'right' }, // { text: 'Due', style: 'tableheader1', Field: 'Due', alignment: 'right' }]]; // if (!isHC) { // HeadingNames[0].splice(2, 0, { text: 'Reg No', style: 'tableheader1', Field: 'Reg No', alignment: 'left' } // , { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // // HeadingNames.splice(3, 0, { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // } // } else { HeadingNames = [[{ text: 'S.No', style: 'tableheader1', Field: 'SNo', alignment: 'left', line: true }, { text: 'Name', style: 'tableheader1', Field: 'Name' }, { text: 'Qty', style: 'tableheader1', Field: 'Qty', alignment: 'right' }, { text: 'Offer Qty', style: 'tableheader1', Field: 'OfQty', alignment: 'right' }, { text: 'Amount', style: 'tableheader1', Field: 'UnAmt', alignment: 'right' }, { text: 'Disc', style: 'tableheader1', Field: 'Disc', alignment: 'right' }, { text: 'Tax', style: 'tableheader1', Field: 'Tax', alignment: 'right' }, { text: 'Amount With Tax', style: 'tableheader1', Field: 'Total', alignment: 'right' }]]; if(isSale){ HeadingNames[0].splice(2, 0, { text: 'Count', style: 'tableheader1', Field: 'Count', alignment: 'right' }); } // { text: 'Due', style: 'tableheader1', Field: 'Due', alignment: 'right' }]]; // if (!isHC) { // HeadingNames[0].splice(2, 0, { text: 'Reg No', style: 'tableheader1', Field: 'Reg No', alignment: 'left' } // , { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // // HeadingNames.splice(3, 0, { text: 'Vehicle', style: 'tableheader1', Field: 'Vehicle', alignment: 'left' }); // } // } return HeadingNames; } }