public ActionResult Details(int?id, int?version) { if (id == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } if (version != null && version.HasValue) { int ID = id.Value; var recordVersion = _costSubItemService.Get(c => c.Where(x => x.ItemID == ID && ((x.VersionNumber == version.Value) || (version.Value == 0 && x.VersionNumber == null))) .ToList(), GetEntityMode.VersionAndOther).FirstOrDefault(); if (recordVersion == null) { return(StatusCode(StatusCodes.Status404NotFound)); } recordVersion.Versions = new List <CostSubItem>().AsEnumerable(); return(View(recordVersion)); } var record = _costSubItemService.GetById(id.Value); if (record == null) { return(StatusCode(StatusCodes.Status404NotFound)); } record.Versions = _costSubItemService.Get(x => x .Where(p => /*p.IsVersion == true &&*/ p.ItemID == record.ID || p.ID == record.ID) .OrderByDescending(p => p.VersionNumber).ToList(), GetEntityMode.VersionAndOther); int versionsCount = record.Versions.Count(); for (int i = 0; i < versionsCount; i++) { if (i == versionsCount - 1) { continue; } var changes = ChangedRecordsFiller.GetChangedData(record.Versions.ElementAt(i), record.Versions.ElementAt(i + 1)); record.Versions.ElementAt(i).ChangedRecords = changes; } return(View(record)); }
private List <BitrixApplicationForPayment> ExtractApplicationsForPaymentFromBitrixRequestForTrip(BitrixRequestForTrip bitrixRFTListItem, List <BitrixCSI> bitrixCSIList, List <BitrixFRC> bitrixFRCList, List <BitrixProject> bitrixProjectList) { var result = new List <BitrixApplicationForPayment>(); if (bitrixRFTListItem.Project != null) { foreach (var rftProject in bitrixRFTListItem.Project) { int projectID = 0; var bitrixProject = bitrixProjectList.Where(x => x.ID == rftProject.Value).FirstOrDefault(); if (bitrixProject != null) { int.TryParse(bitrixProject?.SKIPR_ID?.FirstOrDefault().Value, out projectID); } if (bitrixProject != null) { var load = 100; if (bitrixRFTListItem.BlockProjects != null) { foreach (var project_data in bitrixRFTListItem.BlockProjects) { var project_params = JsonConvert.DeserializeObject <Dictionary <string, string> >(project_data.Value); if (project_params != null && String.IsNullOrEmpty(project_params["CODE"]) == false && bitrixProject.ID == project_params["CODE"]) { Int32.TryParse(project_params["LOAD"], out load); break; } } } Project project = null; if (projectID != 0) { project = _projectService.GetById(projectID); } else { var projectTitle = bitrixProject.ProjectTitle?.FirstOrDefault().Value; project = _projectService.Get(p => p.Where(x => x.ShortName == projectTitle).ToList()).FirstOrDefault(); } if (project == null) { continue; } if (!project.DepartmentID.HasValue) { continue; } Department department = _departmentService.GetById(project.DepartmentID.Value); if (!project.ProjectTypeID.HasValue) { continue; } int?costSubItemID = project.ProjectType.BusinessTripCostSubItemID; if (costSubItemID == null) { continue; } CostSubItem costSubItem = _costSubItemService.GetById(costSubItemID.Value); double total_planned_amount = 0; if (bitrixRFTListItem.CostAmountTripInfo != null) { if (bitrixRFTListItem.CostAmountTripInfo.FirstOrDefault().Value.Contains("|")) { total_planned_amount = Convert.ToDouble(bitrixRFTListItem.CostAmountTripInfo.FirstOrDefault().Value.Split('|')[0].Replace(".", ",")); } else { total_planned_amount = Convert.ToDouble(bitrixRFTListItem.CostAmountTripInfo.FirstOrDefault().Value.Replace("руб.", "").Replace(".", ",")); } } double total_actual_amount = 0; if (bitrixRFTListItem.TOTAL_ACTUAL_COSTS_AMOUNT != null) { if (bitrixRFTListItem.TOTAL_ACTUAL_COSTS_AMOUNT.FirstOrDefault().Value.Contains("|")) { total_actual_amount = Convert.ToDouble(bitrixRFTListItem.TOTAL_ACTUAL_COSTS_AMOUNT.FirstOrDefault().Value.Split('|')[0].Replace(".", ",")); } else { total_actual_amount = Convert.ToDouble(bitrixRFTListItem.TOTAL_ACTUAL_COSTS_AMOUNT.FirstOrDefault().Value.Replace("руб.", "").Replace(".", ",")); } } string expensesRecordName = bitrixRFTListItem.NAME; try { expensesRecordName = (String.IsNullOrEmpty(bitrixRFTListItem.CommittedNotDirectory?.FirstOrDefault().Value) == false) ? bitrixRFTListItem.CommittedNotDirectory?.FirstOrDefault().Value : ""; expensesRecordName += ": " + ((bitrixRFTListItem.StartDateTrip != null) ? Convert.ToDateTime(bitrixRFTListItem.StartDateTrip?.FirstOrDefault().Value).ToShortDateString() : "") + " - " + ((bitrixRFTListItem.EndDateTrip != null) ? Convert.ToDateTime(bitrixRFTListItem.EndDateTrip?.FirstOrDefault().Value).ToShortDateString() : ""); } catch (Exception) { } BitrixCSI bitrixCSI = bitrixCSIList.Where(x => x.NAME.StartsWith(costSubItem.ShortName)).FirstOrDefault(); BitrixFRC bitrixFRC = bitrixFRCList.Where(x => x.NAME.StartsWith(department.ShortName)).FirstOrDefault(); var bitrixApplicationForPayment = new BitrixApplicationForPayment { ID = bitrixRFTListItem.ID, IBLOCK_ID = bitrixRFTListItem.IBLOCK_ID, NAME = expensesRecordName, IBLOCK_SECTION_ID = bitrixRFTListItem.IBLOCK_SECTION_ID, CREATED_BY = bitrixRFTListItem.CREATED_BY, BP_PUBLISHED = bitrixRFTListItem.BP_PUBLISHED, CODE = bitrixRFTListItem.CODE, DATE_CREATE = bitrixRFTListItem.DATE_CREATE, URegNum = bitrixRFTListItem.URegNum, FinResponsibilityCenter = (bitrixFRC != null) ? new Dictionary <string, string>() { { "FinResponsibilityCenter", bitrixFRC.ID } } : null, CostSubitem = (bitrixCSI != null) ? new Dictionary <string, string>() { { "CostSubitem", bitrixCSI.ID } } : null, DeliveryDate = null, Amount = new Dictionary <string, string>() { { "Amount", (total_planned_amount * load / 100).ToString() } }, AmountRuble = null, RateVAT = null, AmountWithoutVAT = new Dictionary <string, string>() { { "AmountWithoutVAT", (total_planned_amount * load / 100).ToString() } }, AmountVAT = null, PaymentForm = null, Contragent = null, ContragentText = null, ProjectShortName = new Dictionary <string, string>() { { "ProjectShortName", project.ShortName } }, Project = null, ActualPaymentDate = (total_actual_amount != 0) ? new Dictionary <string, string>() { { "ActualPaymentDate", bitrixRFTListItem.Updated.Value.ToString() } } : null, ActualPaymentAmount = new Dictionary <string, string>() { { "ActualPaymentAmount", (total_actual_amount * load / 100).ToString() } }, ActualPaymentAmountWithoutVAT = new Dictionary <string, string>() { { "ActualPaymentAmountWithoutVAT", (total_actual_amount * load / 100).ToString() } }, ActualPaymentVAT = null, OverallPaymentAmount = new Dictionary <string, string>() { { "OverallPaymentAmount", (total_actual_amount * load / 100).ToString() } }, OverallPaymentAmountWithoutVAT = new Dictionary <string, string>() { { "OverallPaymentAmountWithoutVAT", (total_actual_amount * load / 100).ToString() } }, OverallPaymentAmountVAT = null, FinancialYear = null, DOCUMENT_STATE = bitrixRFTListItem.DOCUMENT_STATE, APPROVE_DATE = bitrixRFTListItem.APPROVE_DATE, //(total_actual_amount != 0) ? new Dictionary<string, string>() { { "APPROVE_DATE", bitrixRFTListItem.Updated.Value.ToString() } } : null, PAYMENT_COMPLETED_DATE = bitrixRFTListItem.PAYMENT_COMPLETED_DATE, // //(total_actual_amount != 0) ? new Dictionary<string, string>() { { "PAYMENT_COMPLETED_DATE", bitrixRFTListItem.Updated.Value.ToString() } } : null, DISPLAY_STATUS = bitrixRFTListItem.DISPLAY_STATUS }; result.Add(bitrixApplicationForPayment); } } } return(result); }