public static NavPurchaseOrderPostedInvoiceResponse GetNavPostedPurchaseInvoiceResponse(string username, string password, string serviceUrl, string documentNumber) { NavPurchaseOrderPostedInvoiceResponse navPurchaseOrderResponse = null; string serviceCall = string.Format("{0}/PostedPurchaseInvoice?$filter=No eq '{1}'", serviceUrl, documentNumber); try { navPurchaseOrderResponse = new NavPurchaseOrderPostedInvoiceResponse(); NetworkCredential myCredentials = new NetworkCredential(username, password); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceCall); request.Credentials = myCredentials; request.KeepAlive = false; request.ContentType = "application/json"; WebResponse response = request.GetResponse(); using (Stream navPurchaseOrderStream = response.GetResponseStream()) { using (TextReader navPurchaseOrderReader = new StreamReader(navPurchaseOrderStream)) { string responceString = navPurchaseOrderReader.ReadToEnd(); using (var stringReader = new StringReader(responceString)) { navPurchaseOrderResponse = JsonConvert.DeserializeObject <NavPurchaseOrderPostedInvoiceResponse>(responceString); } } } } catch (Exception exp) { _logger.Log(exp, string.Format("Error is occuring while Getting the PostedPurchaseInvoice: Request Url is: {0}", serviceCall), "Get the PostedPurchaseInvoice List From NAV.", LogType.Error); } return(navPurchaseOrderResponse); }
public DocumentData GetCostCodeReportByJobId(string jobId) { List <long> selectedJobId = jobId.Split(',').Select(Int64.Parse).ToList(); List <Task> tasks = new List <Task>(); NavPurchaseOrderPostedInvoiceResponse navPurchaseOrderPostedInvoiceResponse = CommonCommands.GetCachedNavPurchaseOrderValues(); NavPurchaseOrderItemResponse navPurchaseOrderItemResponse = CommonCommands.GetCachedNavPurchaseOrderItemValues(); DocumentData documentData = null; List <DocumentData> documentDataList = new List <DocumentData>(); foreach (var currentJobId in selectedJobId) { tasks.Add(Task.Factory.StartNew(() => { var currentNavSalesOrder = navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJobId); if (currentNavSalesOrder != null && !string.IsNullOrEmpty(currentNavSalesOrder.No)) { var currentPurchaseLineItem = navPurchaseOrderItemResponse.NavPurchaseOrderItem.Where(x => x.Document_No.Equals(currentNavSalesOrder.No, StringComparison.OrdinalIgnoreCase)); if (currentPurchaseLineItem.Any() && currentPurchaseLineItem.Count() > 0) { documentDataList.Add(GetCostCodeReportDataByJobId(currentJobId, currentPurchaseLineItem.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", "ConsolidatedCostCode"); documentData.ContentType = "application/zip"; } } else if (documentDataList?.Count == 1) { return(documentDataList[0]); } return(documentData); }
public DocumentStatus IsCostCodeDataPresentForJobInNAV(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 }; NavPurchaseOrderPostedInvoiceResponse navPurchaseOrderPostedInvoiceResponse = CommonCommands.GetCachedNavPurchaseOrderValues(); NavPurchaseOrderItemResponse navPurchaseOrderItemResponse = CommonCommands.GetCachedNavPurchaseOrderItemValues(); if (navPurchaseOrderPostedInvoiceResponse == null || (navPurchaseOrderPostedInvoiceResponse != null && navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder == null) || (navPurchaseOrderPostedInvoiceResponse != null && navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder != null && navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder.Count == 0)) { return(documentStatus); } else if (navPurchaseOrderItemResponse == null || (navPurchaseOrderItemResponse != null && navPurchaseOrderItemResponse.NavPurchaseOrderItem == null) || (navPurchaseOrderItemResponse != null && navPurchaseOrderItemResponse.NavPurchaseOrderItem != null && navPurchaseOrderItemResponse.NavPurchaseOrderItem.Count == 0)) { return(documentStatus); } foreach (var currentJob in selectedJobId) { tasks.Add(Task.Factory.StartNew(() => { var currentNavSalesOrder = navPurchaseOrderPostedInvoiceResponse.NavPurchaseOrder.FirstOrDefault(x => x.M4PL_Job_ID.ToLong() == currentJob); if (currentNavSalesOrder != null && !string.IsNullOrEmpty(currentNavSalesOrder.No)) { var currentSalesLineItem = navPurchaseOrderItemResponse.NavPurchaseOrderItem.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); }
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); }