Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CostSubItem costSubItem            = _costSubItemService.GetById(id);
            var         user                   = _userService.GetUserDataForVersion();
            var         recycleBinInDBRelation = _serviceService.HasRecycleBinInDBRelation(costSubItem);

            if (recycleBinInDBRelation.hasRelated == false)
            {
                var recycleToRecycleBin = _costSubItemService.RecycleToRecycleBin(costSubItem.ID, user.Item1, user.Item2);
                if (!recycleToRecycleBin.toRecycleBin)
                {
                    ViewBag.RecycleBinError =
                        "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                        "Сначала необходимо удалить элементы, которые ссылаются на данный элемент. " +
                        recycleToRecycleBin.relatedClassId;
                    return(View(costSubItem));
                }
            }
            else
            {
                ViewBag.RecycleBinError =
                    "Невозможно удалить, так как на удаляемый элемент ссылаются другие элементы в системе." +
                    $"Сначала необходимо удалить элементы, которые ссылаются на данный элемент. {recycleBinInDBRelation.relatedInDBClassId}";
                return(View(costSubItem));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Edit(CostSubItem costSubItem)
        {
            if (ModelState.IsValid)
            {
                _costSubItemService.Update(costSubItem);
                return(RedirectToAction("Index"));
            }

            SetViewBag(costSubItem);
            return(View(costSubItem));
        }
Exemplo n.º 3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }

            CostSubItem costSubItem = _costSubItemService.GetById(id.Value);

            if (costSubItem == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            return(View(costSubItem));
        }
Exemplo n.º 4
0
        public ActionResult Edit(int?id)
        {
            if (id.HasValue == false)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }

            CostSubItem costSubItem = _costSubItemService.GetById(id.Value);

            if (costSubItem == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            if (costSubItem.IsVersion)
            {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }

            SetViewBag(costSubItem);
            return(View(costSubItem));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 private void SetViewBag(CostSubItem item)
 {
     ViewBag.CostItemID = new SelectList(_costItemService.Get(x => x.ToList()), "ID", "FullName", item?.CostItemID);
 }