Beispiel #1
0
        public HttpResponseMessage GenerateInventoryValuationReport(InventoryValuationRequestModel request)
        {
            HttpResponseMessage retVal;

            try
            {
                request.context = this.SelectedUserContext;
                var stream = _inventoryValuationReportLogic.GenerateReport(request);

                HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");

                if (request.ReportFormat.Equals("excel", StringComparison.CurrentCultureIgnoreCase))
                {
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                }
                else
                {
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                }

                retVal = result;
            }
            catch (Exception ex)
            {
                _log.WriteErrorLog("GenerateInventoryValuationReport", ex);
                retVal = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
            return(retVal);
        }
        private StringBuilder WriteTextSum(InventoryValuationRequestModel request)
        {
            StringBuilder ret = new StringBuilder();

            ret.Append(WriteTextValue("Total", request, true));
            ret.Append(WriteTextValue(request.ReportData.Sum(x => x.ExtPrice).ToString("F2"), request, false));
            return(ret);
        }
        private MemoryStream GenerateTextReport(InventoryValuationRequestModel request)
        {
            StringBuilder sb = GenerateInventoryValuationTextReport(request);

            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            sw.Write(sb.ToString());
            sw.Flush();

            ms.Seek(0, SeekOrigin.Begin);
            return(ms);
        }
        private string UseAppropriateDelimiter(InventoryValuationRequestModel request)
        {
            string ret;

            switch (request.ReportFormat.ToLower())
            {
            case "csv":
                ret = ",";
                break;

            default:
                ret = "\t";
                break;
            }
            return(ret);
        }
        private StringBuilder GenerateInventoryValuationTextReport(InventoryValuationRequestModel request)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Inventory Valuation Report");
            Customer customer = _customerRepo.GetCustomerByCustomerNumber(_context.CustomerId, _context.BranchId);

            sb.AppendLine(string.Format("{0}{1}{2}{3}{4}",
                                        customer.CustomerName, UseAppropriateDelimiter(request),
                                        customer.CustomerNumber, UseAppropriateDelimiter(request),
                                        customer.CustomerBranch));
            sb.AppendLine(WriteTextHeaders(request).ToString());
            sb.Append(WriteTextData(request).ToString());
            sb.AppendLine(WriteTextSum(request).ToString());
            return(sb);
        }
        private StringBuilder WriteTextHeaders(InventoryValuationRequestModel request)
        {
            StringBuilder ret = new StringBuilder();

            ret.Append(WriteTextValue("Item", request, true));
            ret.Append(WriteTextValue("Name", request, true));
            ret.Append(WriteTextValue("Brand", request, true));
            ret.Append(WriteTextValue("Category", request, true));
            ret.Append(WriteTextValue("Pack", request, true));
            ret.Append(WriteTextValue("Size", request, true));
            ret.Append(WriteTextValue("Label", request, true));
            ret.Append(WriteTextValue("Each", request, true));
            ret.Append(WriteTextValue("Price", request, true));
            ret.Append(WriteTextValue("Quantity", request, true));
            ret.Append(WriteTextValue("ExtPrice", request, false));

            return(ret);
        }
        private StringBuilder WriteTextData(InventoryValuationRequestModel request)
        {
            StringBuilder ret = new StringBuilder();

            foreach (var datarow in request.ReportData)
            {
                ret.Append(WriteTextValue(datarow.ItemId, request, true));
                ret.Append(WriteTextValue(datarow.Name, request, true));
                ret.Append(WriteTextValue(datarow.Brand, request, true));
                ret.Append(WriteTextValue(datarow.Category, request, true));
                ret.Append(WriteTextValue(datarow.Pack, request, true));
                ret.Append(WriteTextValue(datarow.Size, request, true));
                ret.Append(WriteTextValue(datarow.Label, request, true));
                ret.Append(WriteTextValue((datarow.Each ? "Y" : "N"), request, true));
                ret.Append(WriteTextValue(datarow.Price.ToString("F2"), request, true));
                ret.Append(WriteTextValue(datarow.Quantity.ToString("F0"), request, true));
                ret.AppendLine(WriteTextValue(datarow.ExtPrice.ToString("F2"), request, false));
            }
            return(ret);
        }
 public MemoryStream GenerateReport(InventoryValuationRequestModel request)
 {
     _context = request.context;
     foreach (InventoryValuationModel item in request.ReportData)
     {
         if (item.PackSize != null && item.PackSize.IndexOf('/') > -1)
         {
             item.Pack = item.PackSize.Substring(0, item.PackSize.IndexOf('/')).Trim();
             item.Size = item.PackSize.Substring(item.PackSize.IndexOf('/') + 1).Trim();
         }
     }
     if (request.ReportFormat.Equals("excel", StringComparison.InvariantCultureIgnoreCase))
     {
         return(GenerateExcelReport(request.ReportData));
     }
     else if (request.ReportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase))
     {
         return(GeneratePDFReport(request));
     }
     else
     {
         return(GenerateTextReport(request));
     }
 }
        private MemoryStream GeneratePDFReport(InventoryValuationRequestModel request)
        {
            Customer     customer = _customerRepo.GetCustomerByCustomerNumber(_context.CustomerId, _context.BranchId);
            ReportViewer rv       = new ReportViewer();

            rv.ProcessingMode = ProcessingMode.Local;

            Assembly assembly   = Assembly.Load("Keithlink.Svc.Impl");
            Stream   rdlcStream = null;

            if (request.GroupBy != null)
            {
                switch (request.GroupBy)
                {
                case "category":
                    rdlcStream = assembly.GetManifestResourceStream
                                     ("KeithLink.Svc.Impl.Reports.InventoryValuationByContractCategory.rdlc");
                    break;

                case "categorythenlabel":
                    rdlcStream = assembly.GetManifestResourceStream
                                     ("KeithLink.Svc.Impl.Reports.InventoryValuationByContractCategoryThenLabel.rdlc");
                    // if the user is requesting this specialized contract category then label,
                    // we add that to the data
                    request.ReportData = request.ReportData.Select(iv => ContractCategoryThenLabelIVM(iv)).ToList();
                    break;

                case "categoryname":
                    rdlcStream = assembly.GetManifestResourceStream
                                     ("KeithLink.Svc.Impl.Reports.InventoryValuationByCategory.rdlc");
                    break;

                case "label":
                    rdlcStream = assembly.GetManifestResourceStream
                                     ("KeithLink.Svc.Impl.Reports.InventoryValuationByLabel.rdlc");
                    break;

                case "supplier":
                    rdlcStream = assembly.GetManifestResourceStream
                                     ("KeithLink.Svc.Impl.Reports.InventoryValuationBySupplier.rdlc");
                    break;

                default:
                    break;
                }
            }
            else
            {
                rdlcStream = assembly.GetManifestResourceStream("KeithLink.Svc.Impl.Reports.InventoryValuation.rdlc");
            }
            rv.LocalReport.LoadReportDefinition(rdlcStream);

            rv.LocalReport.SetParameters(new ReportParameter("Branch", customer.CustomerBranch));
            rv.LocalReport.SetParameters(new ReportParameter("CustomerName", customer.CustomerName));
            rv.LocalReport.SetParameters(new ReportParameter("CustomerNumber", customer.CustomerNumber));

            rv.LocalReport.DataSources.Add(
                new ReportDataSource("DataSet1", request.ReportData));

            string deviceInfo = KeithLink.Svc.Core.Constants.SET_REPORT_SIZE_LANDSCAPE;
            var    bytes      = rv.LocalReport.Render("PDF", deviceInfo);

            return(new MemoryStream(bytes));
        }
 private string WriteTextValue(string Value, InventoryValuationRequestModel request, bool endWithDelimiter)
 {
     return((endWithDelimiter) ? Value + UseAppropriateDelimiter(request) : Value);
 }