Ejemplo n.º 1
0
        public DocumentData GetPriceCodeReportByJobId(string jobId)
        {
            List <long> selectedJobId = jobId.Split(',').Select(Int64.Parse).ToList();
            List <Task> tasks         = new List <Task>();
            NavSalesOrderPostedInvoiceResponse navSalesOrderPostedInvoiceResponse = CommonCommands.GetCachedNavSalesOrderValues();
            NavSalesOrderItemResponse          navSalesOrderItemResponse          = CommonCommands.GetCachedNavSalesOrderItemValues();
            DocumentData        documentData     = null;
            List <DocumentData> documentDataList = new List <DocumentData>();

            foreach (var currentJobId in selectedJobId)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var currentNavSalesOrder = navSalesOrderPostedInvoiceResponse.NavSalesOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJobId);
                    if (currentNavSalesOrder != null && !string.IsNullOrEmpty(currentNavSalesOrder.No))
                    {
                        var currentSalesLineItem = navSalesOrderItemResponse.NavSalesOrderItem.Where(x => x.Document_No.Equals(currentNavSalesOrder.No, StringComparison.OrdinalIgnoreCase));
                        if (currentSalesLineItem.Any() && currentSalesLineItem.Count() > 0)
                        {
                            documentDataList.Add(GetPriceCodeReportDataByJobId(currentJobId, currentSalesLineItem.ToList()));
                        }
                    }
                }));
            }

            if (tasks.Count > 0)
            {
                Task.WaitAll(tasks.ToArray());
            }
            documentDataList = documentDataList.Where(x => x != null).Any() ? documentDataList.Where(x => x != null).ToList() : new List <DocumentData>();
            if (documentDataList?.Count > 1)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var trackingDocument in documentDataList)
                        {
                            var entry = archive.CreateEntry(trackingDocument.DocumentName, CompressionLevel.Fastest);
                            using (var zipStream = entry.Open())
                            {
                                zipStream.Write(trackingDocument.DocumentContent, 0, trackingDocument.DocumentContent.Length);
                            }
                        }
                    }
                    documentData = new DocumentData();
                    documentData.DocumentContent = memoryStream.ToArray();
                    documentData.DocumentName    = string.Format("{0}.zip", "ConsolidatedPriceCode");
                    documentData.ContentType     = "application/zip";
                }
            }
            else if (documentDataList?.Count == 1)
            {
                return(documentDataList[0]);
            }

            return(documentData);
        }
Ejemplo n.º 2
0
        public DocumentStatus IsPriceCodeDataPresentForJobInNAV(string jobId)
        {
            if (string.IsNullOrEmpty(jobId))
            {
                return(new DocumentStatus()
                {
                    IsAttachmentPresent = false, IsPODPresent = false
                });
            }

            List <long>    selectedJobId  = jobId.Split(',').Select(Int64.Parse).ToList();
            List <Task>    tasks          = new List <Task>();
            DocumentStatus documentStatus = new DocumentStatus()
            {
                IsAttachmentPresent = false, IsPODPresent = false
            };
            NavSalesOrderPostedInvoiceResponse navSalesOrderPostedInvoiceResponse = CommonCommands.GetCachedNavSalesOrderValues();
            NavSalesOrderItemResponse          navSalesOrderItemResponse          = CommonCommands.GetCachedNavSalesOrderItemValues();

            if (navSalesOrderPostedInvoiceResponse == null || (navSalesOrderPostedInvoiceResponse != null && navSalesOrderPostedInvoiceResponse.NavSalesOrder == null) || (navSalesOrderPostedInvoiceResponse != null && navSalesOrderPostedInvoiceResponse.NavSalesOrder != null && navSalesOrderPostedInvoiceResponse.NavSalesOrder.Count == 0))
            {
                return(documentStatus);
            }
            else if (navSalesOrderItemResponse == null || (navSalesOrderItemResponse != null && navSalesOrderItemResponse.NavSalesOrderItem == null) || (navSalesOrderItemResponse != null && navSalesOrderItemResponse.NavSalesOrderItem != null && navSalesOrderItemResponse.NavSalesOrderItem.Count == 0))
            {
                return(documentStatus);
            }

            foreach (var currentJob in selectedJobId)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var currentNavSalesOrder = navSalesOrderPostedInvoiceResponse.NavSalesOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJob);
                    if (currentNavSalesOrder != null && !string.IsNullOrEmpty(currentNavSalesOrder.No))
                    {
                        var currentSalesLineItem = navSalesOrderItemResponse.NavSalesOrderItem.Where(x => x.Document_No.Equals(currentNavSalesOrder.No, StringComparison.OrdinalIgnoreCase));
                        if (currentSalesLineItem.Any() && currentSalesLineItem.Count() > 0)
                        {
                            documentStatus.IsAttachmentPresent = true;
                        }
                    }
                }));
            }

            if (tasks.Count > 0)
            {
                Task.WaitAll(tasks.ToArray());
            }

            return(documentStatus);
        }
Ejemplo n.º 3
0
        public IList <JobAdvanceReport> GetPagedData(PagedDataInfo pagedDataInfo)
        {
            IList <JobAdvanceReport> result = null;
            bool isCostChargeReport         = false;
            bool isPriceChargeReport        = false;

            result              = _commands.GetPagedData(ActiveUser, pagedDataInfo);
            isCostChargeReport  = result != null && result.Count > 0 && (result.ToList().Where(x => x.IsCostChargeReport).Any());
            isPriceChargeReport = result != null && result.Count > 0 && (result.ToList().Where(x => x.IsPriceChargeReport).Any());
            if (isCostChargeReport || isPriceChargeReport)
            {
                IList <JobAdvanceReport> updatedResult           = new List <JobAdvanceReport>();
                JobAdvanceReport         currentJobAdvanceReport = null;
                int jobItemCount = 1;
                if (isPriceChargeReport)
                {
                    NavSalesOrderPostedInvoiceResponse navSalesOrderPostedInvoiceResponse = CommonCommands.GetCachedNavSalesOrderValues();
                    NavSalesOrderItemResponse          navSalesOrderItemResponse          = CommonCommands.GetCachedNavSalesOrderItemValues();
                    foreach (var currentJob in result)
                    {
                        var currentNavSalesOrder = navSalesOrderPostedInvoiceResponse.NavSalesOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJob.JobId);
                        if (currentNavSalesOrder != null && !string.IsNullOrEmpty(currentNavSalesOrder.No))
                        {
                            var currentSalesLineItem = navSalesOrderItemResponse.NavSalesOrderItem.Where(x => x.Document_No.Equals(currentNavSalesOrder.No, StringComparison.OrdinalIgnoreCase));
                            if (currentSalesLineItem.Any() && currentSalesLineItem.Count() > 0)
                            {
                                foreach (var salesLineItem in currentSalesLineItem)
                                {
                                    currentJobAdvanceReport = currentJob.DeepCopy();
                                    currentJobAdvanceReport.RateChargeCode = string.IsNullOrEmpty(salesLineItem.Cross_Reference_No) ? salesLineItem.No : salesLineItem.Cross_Reference_No;
                                    currentJobAdvanceReport.RateTitle      = salesLineItem.Description;
                                    currentJobAdvanceReport.RateAmount     = salesLineItem.Unit_Price;
                                    currentJobAdvanceReport.Id             = currentJob.Id;
                                    updatedResult.Add(currentJobAdvanceReport);
                                    jobItemCount = jobItemCount + 1;
                                }
                            }
                        }
                    }
                }
                else
                {
                    NavPurchaseOrderPostedInvoiceResponse navPurchaseOrderPostedInvoiceResponse = CommonCommands.GetCachedNavPurchaseOrderValues();
                    NavPurchaseOrderItemResponse          navPurchaseOrderItemResponse          = CommonCommands.GetCachedNavPurchaseOrderItemValues();
                    foreach (var currentJob in result)
                    {
                        var currentNavPurchaseOrder = navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJob.JobId);
                        if (currentNavPurchaseOrder != null && !string.IsNullOrEmpty(currentNavPurchaseOrder.No))
                        {
                            var currentPurchaseLineItem = navPurchaseOrderItemResponse.NavPurchaseOrderItem.Where(x => x.Document_No.Equals(currentNavPurchaseOrder.No, StringComparison.OrdinalIgnoreCase));
                            if (currentPurchaseLineItem.Any() && currentPurchaseLineItem.Count() > 0)
                            {
                                foreach (var purchaseLineItem in currentPurchaseLineItem)
                                {
                                    currentJobAdvanceReport = currentJob.DeepCopy();
                                    currentJobAdvanceReport.RateChargeCode = string.IsNullOrEmpty(purchaseLineItem.Cross_Reference_No) ? purchaseLineItem.No : purchaseLineItem.Cross_Reference_No;
                                    currentJobAdvanceReport.RateTitle      = purchaseLineItem.Description;
                                    currentJobAdvanceReport.RateAmount     = purchaseLineItem.Unit_Cost_LCY;
                                    currentJobAdvanceReport.Id             = currentJob.Id;
                                    updatedResult.Add(currentJobAdvanceReport);
                                    jobItemCount = jobItemCount + 1;
                                }
                            }
                        }
                    }
                }

                pagedDataInfo.TotalCount = updatedResult != null && updatedResult.Count > 0 ? updatedResult.Count : 0;
                return(updatedResult);
            }

            return(result);
        }