Ejemplo n.º 1
0
        public string GetXplugDepartment(string refId)
        {
            var r = int.Parse(refId);
            const XplugDepartments xPlug = XplugDepartments.XPlug;
            var x            = (int)Enum.Parse(typeof(XplugDepartments), Enum.GetName(typeof(XplugDepartments), xPlug));
            var jsSerializer = new JavaScriptSerializer {
                MaxJsonLength = Int32.MaxValue
            };

            return(x == r?jsSerializer.Serialize(x) : jsSerializer.Serialize(-3));
        }
Ejemplo n.º 2
0
        public string GetLrDepartment(string refId)
        {
            var r = int.Parse(refId);
            const XplugDepartments lrGlobal = XplugDepartments.LrGlobal;
            var y = (int)Enum.Parse(typeof(XplugDepartments), Enum.GetName(typeof(XplugDepartments), lrGlobal));

            var jsSerializer = new JavaScriptSerializer {
                MaxJsonLength = Int32.MaxValue
            };

            return(y == r?jsSerializer.Serialize(y) : jsSerializer.Serialize(-3));
        }
        public bool GenerateReport(List <DictObject> dictObjList)
        {
            try
            {
                const XplugDepartments lrGlobal = XplugDepartments.LrGlobal;
                var z = Enum.GetName(typeof(XplugDepartments), lrGlobal);
                var y = 0;
                if (z != null)
                {
                    y = (int)Enum.Parse(typeof(XplugDepartments), z);
                }

                const XplugDepartments xPlug = XplugDepartments.XPlug;
                var s = Enum.GetName(typeof(XplugDepartments), xPlug);
                var x = 0;
                if (s != null)
                {
                    x = (int)Enum.Parse(typeof(XplugDepartments), s);
                }

                var repFilePath = "";

                if (dictObjList.ElementAt(0).DepartmentId == x)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/XplugMultiVoucher.rpt");
                }

                if (dictObjList.ElementAt(0).DepartmentId == y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/LRMultiVoucher.rpt");
                }

                if (dictObjList.ElementAt(0).DepartmentId != x && dictObjList.ElementAt(0).DepartmentId != y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/XplugMultiVoucher.rpt");
                }

                var voucherItemList = new List <VoucherItem>();

                foreach (var dictObj in dictObjList)
                {
                    foreach (var dictItem in dictObj.TransactionItems)
                    {
                        var newVoucherItem = new VoucherItem
                        {
                            AmountInWords       = dictObj.WordValue,
                            AmountPaid          = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObj.AmmountPaid.ToString(CultureInfo.InvariantCulture))),
                            Approver            = dictObj.Approver,
                            DatePaid            = dictObj.DatePaid,
                            ChequeNo            = dictObj.ChequeNo,
                            PcvNo               = dictObj.PcvNo,
                            TransactionId       = dictObj.TransactionpaymentHistoryId,
                            RequestedBy         = dictObj.RequestedBy,
                            ReceivedBy          = dictObj.ReceivedBy,
                            TotalApprovedAmount = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObj.TotalApprovedAmmount.ToString(CultureInfo.InvariantCulture))),
                            ApprovedQuantity    = dictItem.ApprovedQuantity.ToString(CultureInfo.InvariantCulture),
                            ApprovedUnitPrice   = NumberMap.GroupToDigits(dictItem.ApprovedUnitPrice.ToString(CultureInfo.InvariantCulture)),
                            ApprovedTotalPrice  = NumberMap.GroupToDigits(dictItem.ApprovedTotalPrice.ToString(CultureInfo.InvariantCulture)),
                            ItemName            = dictItem.ExpenseItem.Title,
                            ItemCode            = dictItem.ExpenseItem.Code,
                            DetailDesription    = dictItem.Description
                        };

                        if (newVoucherItem.TransactionId > 0 && !string.IsNullOrEmpty(newVoucherItem.ItemName) && !string.IsNullOrEmpty(newVoucherItem.ItemCode))
                        {
                            voucherItemList.Add(newVoucherItem);
                        }
                    }
                }

                var pdfPath = Session.SessionID + DateTime.Now.Millisecond.ToString(CultureInfo.InvariantCulture) + Environment.TickCount.ToString(CultureInfo.InvariantCulture) + ".pdf";
                var path    = Server.MapPath("~/GeneratedDocuments/");
                pdfPath = path + pdfPath;

                var repDoc = new ReportDocument();
                repDoc.Load(repFilePath);

                repDoc.SetDataSource(voucherItemList);

                var crDiskFileDestinationOptions = new DiskFileDestinationOptions();
                var crFormatTypeOptions          = new PdfRtfWordFormatOptions();
                crDiskFileDestinationOptions.DiskFileName = pdfPath;
                var crExportOptions = repDoc.ExportOptions;
                {
                    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    crExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                    crExportOptions.DestinationOptions    = crDiskFileDestinationOptions;
                    crExportOptions.FormatOptions         = crFormatTypeOptions;
                }
                repDoc.Export();
                Session["myPDF.InvoicePath"] = pdfPath;

                Context.Response.Buffer = false;
                var buffer = new byte[1024];
                var inStr  = File.OpenRead(pdfPath);
                while ((inStr.Read(buffer, 0, buffer.Length)) > 0)
                {
                    if (Context.Response.IsClientConnected)
                    {
                        Response.Clear();
                        Response.ContentType = "application/pdf";
                        Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                        Context.Response.Flush();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }
        public bool GenerateReport(DictObject dictObject)
        {
            try
            {
                string wordValue;
                if (Session["_wordString"] == null)
                {
                    wordValue = "N/A";
                }

                wordValue = (string)Session["_wordString"];

                if (string.IsNullOrEmpty(wordValue))
                {
                    wordValue = "N/A";
                }

                var dataTable = new DataTable("TransactionPayment");
                dataTable.Columns.Add(new DataColumn("TransactionTitle", typeof(string)));
                dataTable.Columns.Add(new DataColumn("PaidBy", typeof(string)));
                dataTable.Columns.Add(new DataColumn("RequestedBy", typeof(string)));
                dataTable.Columns.Add(new DataColumn("ChequeNo", typeof(string)));
                dataTable.Columns.Add(new DataColumn("ReceivedBy", typeof(string)));
                dataTable.Columns.Add(new DataColumn("AmountPaid", typeof(string)));
                dataTable.Columns.Add(new DataColumn("TotalApprovedAmount", typeof(string)));
                dataTable.Columns.Add(new DataColumn("Approver", typeof(string)));
                dataTable.Columns.Add(new DataColumn("DatePaid", typeof(string)));
                dataTable.Columns.Add(new DataColumn("PaymentMode", typeof(string)));
                dataTable.Columns.Add(new DataColumn("PcvNo", typeof(string)));
                dataTable.Columns.Add(new DataColumn("AmountInWords", typeof(string)));

                DataRow dr = dataTable.NewRow();
                dr["TransactionTitle"]    = dictObject.TransactionTitle;
                dr["PaidBy"]              = dictObject.PaidBy;
                dr["RequestedBy"]         = dictObject.RequestedBy;
                dr["ChequeNo"]            = dictObject.ChequeNo;
                dr["ReceivedBy"]          = dictObject.ReceivedBy;
                dr["AmountPaid"]          = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObject.AmmountPaid.ToString(CultureInfo.InvariantCulture)));
                dr["TotalApprovedAmount"] = string.Format("{0}{1}", "N", NumberMap.GroupToDigits(dictObject.TotalApprovedAmmount.ToString(CultureInfo.InvariantCulture)));
                dr["Approver"]            = dictObject.Approver;
                dr["DatePaid"]            = dictObject.DatePaid;
                dr["PcvNo"]         = dictObject.PcvNo;
                dr["AmountInWords"] = wordValue;
                dataTable.Rows.Add(dr);

                //NumbersToWord(double s, string naira, string kobo)

                var dataTable2 = new DataTable("TransactionItem");
                dataTable2.Columns.Add(new DataColumn("ItemCode", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("ItemName", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("DetailDesription", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("ApprovedQuantity", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("ApprovedUnitPrice", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("ApprovedTotalPrice", typeof(string)));

                foreach (var transactionItem in dictObject.TransactionItems)
                {
                    var dr2 = dataTable2.NewRow();
                    dr2["ItemCode"]           = transactionItem.ExpenseItem.Code;
                    dr2["ItemName"]           = transactionItem.ExpenseItem.Title;
                    dr2["DetailDesription"]   = transactionItem.Description;
                    dr2["ApprovedQuantity"]   = transactionItem.ApprovedQuantity;
                    dr2["ApprovedUnitPrice"]  = NumberMap.GroupToDigits(transactionItem.ApprovedUnitPrice.ToString(CultureInfo.InvariantCulture));
                    dr2["ApprovedTotalPrice"] = NumberMap.GroupToDigits(transactionItem.ApprovedTotalPrice.ToString(CultureInfo.InvariantCulture));
                    dataTable2.Rows.Add(dr2);
                }

                const XplugDepartments lrGlobal = XplugDepartments.LrGlobal;
                var y = (int)Enum.Parse(typeof(XplugDepartments), Enum.GetName(typeof(XplugDepartments), lrGlobal));

                const XplugDepartments xPlug = XplugDepartments.XPlug;
                var x = (int)Enum.Parse(typeof(XplugDepartments), Enum.GetName(typeof(XplugDepartments), xPlug));

                var repFilePath = "";
                if (dictObject.DepartmentId == x)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/xPlugVoucher.rpt");
                }

                if (dictObject.DepartmentId == y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/LRVoucher.rpt");
                }

                if (dictObject.DepartmentId != x && dictObject.DepartmentId != y)
                {
                    repFilePath = Server.MapPath("~/ExpenseMgt/Reports/ReportFiles/xPlugVoucher.rpt");
                }

                var pdfPath = Session.SessionID + DateTime.Now.Millisecond.ToString(CultureInfo.InvariantCulture) + Environment.TickCount.ToString(CultureInfo.InvariantCulture) + ".pdf";
                var path    = Server.MapPath("~/GeneratedDocuments/");
                pdfPath = path + pdfPath;

                var repDoc = new ReportDocument();
                repDoc.Load(repFilePath);

                repDoc.Database.Tables[0].SetDataSource(dataTable2);
                repDoc.Database.Tables[1].SetDataSource(dataTable);

                var crDiskFileDestinationOptions = new DiskFileDestinationOptions();
                var crFormatTypeOptions          = new PdfRtfWordFormatOptions();
                crDiskFileDestinationOptions.DiskFileName = pdfPath;
                var crExportOptions = repDoc.ExportOptions;
                {
                    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    crExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                    crExportOptions.DestinationOptions    = crDiskFileDestinationOptions;
                    crExportOptions.FormatOptions         = crFormatTypeOptions;
                }
                repDoc.Export();
                Session["myPDF.InvoicePath"] = pdfPath;

                Context.Response.Buffer = false;
                var        buffer = new byte[1024];
                FileStream inStr  = File.OpenRead(pdfPath);
                while ((inStr.Read(buffer, 0, buffer.Length)) > 0)
                {
                    if (Context.Response.IsClientConnected)
                    {
                        Response.Clear();
                        //Response.AddHeader("Accept-Header", buffer.Length.ToString());
                        Response.ContentType = "application/pdf";
                        Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                        Context.Response.Flush();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }