Exemplo n.º 1
0
            public static PaymentGroup ToPaymentGroup(PaymentsGroupViewModel vm, bool showCategorized)
            {
                var visiblePayments = vm.GetVisiblePayments(showCategorized);
                var paymentGroup    = new PaymentGroup
                {
                    IsExpanded   = vm.IsExpanded,
                    Amount       = visiblePayments.Select(v => v.Amount).Sum(),
                    Ccy          = visiblePayments[0].Ccy,
                    Id           = vm.Id.ToUUID(),
                    Kind         = visiblePayments[0].Kind,
                    PaymentCount = visiblePayments.Count,
                    What         = visiblePayments[0].What,
                    When         = visiblePayments[0].When.ToTimestamp(),
                    CategoryId   = visiblePayments[0].CategoryId.ToUUID(),
                    ColumnId     = visiblePayments[0].ColumnId.ToUUID(),
                    DebtId       = visiblePayments[0].DebtId.ToUUID()
                };

                if (vm.IsExpanded)
                {
                    foreach (var v in visiblePayments)
                    {
                        paymentGroup.Payments.Add(new PaymentView {
                            Payment = ToPaymentView(v)
                        });
                    }
                }
                return(paymentGroup);
            }
Exemplo n.º 2
0
        PaymentsGroupViewModel getPaymentsGroupViewModel(PaymentsGroup paymentsGroup)
        {
            PaymentsGroupViewModel model = new PaymentsGroupViewModel();

            model.Header = getPG_HeaderViewModel(paymentsGroup);

            List <Project> Projects = paymentsGroup.UsersPayments.Select(n => n.Project).Distinct().ToList();

            model.ProjectsNames = Projects.Select(n => n.Name).ToArray();
            model.ProjectsIds   = Projects.Select(n => n.ProjectId).ToArray();

            for (int i = 0; i < model.Header.UserIds.Length; i++)
            {
                model.Header.Payments[i] = new double[model.ProjectsIds.Length];
            }

            for (int i = 0; i < model.Header.UserNames.Length; i++)
            {
                Dictionary <int, double> up = paymentsGroup.UsersPayments.Where(x => x.User.Id == model.Header.UserIds[i]).ToDictionary(z => z.Project.ProjectId, z => z.Sum);
                for (int j = 0; j < model.ProjectsIds.Length; j++)
                {
                    model.Header.Payments[i][j] = up.ContainsKey(model.ProjectsIds[j]) ? up[model.ProjectsIds[j]] : -1;
                }
            }
            return(model);
        }
Exemplo n.º 3
0
            public void AddPayment(PaymentModel paymentModel)
            {
                var key = PaymentKey(paymentModel);

                if (!_payments.ContainsKey(key))
                {
                    _payments[key] = new PaymentsGroupViewModel(paymentModel);
                }
                else
                {
                    _payments[key].Payments.Add(paymentModel);
                }
            }
Exemplo n.º 4
0
        public ActionResult EditByTable(PaymentsGroupViewModel model)
        {
            if (ModelState.IsValid)
            {
                PaymentsGroup paymentsGroup = db.PaymentsGroups.Find(model.Header.PaymentsGroupId);
                if (paymentsGroup != null)
                {
                    bool was_apply = false;
                    bool has_error = false;
                    for (int i = 0; i < model.Header.UserIds.Length; i++)
                    {
                        ApplicationUser user = db.Users.Find(model.Header.UserIds[i]);
                        if (user != null)
                        {
                            for (int j = 0; j < model.ProjectsIds.Length; j++)
                            {
                                if (model.Header.Payments[i][j] == -1)
                                {
                                    continue;
                                }
                                UserBalance user_b = user.UserBalances.FirstOrDefault(x => x.Project.ProjectId == model.ProjectsIds[j]);
                                UserPayment user_p = paymentsGroup.UsersPayments.FirstOrDefault(x => x.Project.ProjectId == model.ProjectsIds[j] && x.User.Id == model.Header.UserIds[i]);
                                if (user_b != null && user_p != null)
                                {
                                    if (user_b.Sum >= model.Header.Payments[i][j])
                                    {
                                        if (model.Header.State == PaymentsGroupState.PaidOut)
                                        {
                                            user_b.Sum -= model.Header.Payments[i][j];
                                        }
                                        user_p.Sum = model.Header.Payments[i][j];
                                        was_apply  = true;
                                    }
                                    else
                                    {
                                        has_error = true;
                                        ModelState.AddModelError("", "Сумма платежа первышает остаток, Пользователь " + model.Header.UserNames[i] + " Проект " + model.ProjectsNames[j]);
                                    }
                                }
                                else
                                {
                                    has_error = true;
                                    if (user_b == null)
                                    {
                                        ModelState.AddModelError("", "Не найден счет, Пользователь " + model.Header.UserNames[i] + " Проект " + model.ProjectsNames[j]);
                                    }
                                    if (user_p == null)
                                    {
                                        ModelState.AddModelError("", "Не найден платеж, Пользователь " + model.Header.UserNames[i] + " Проект " + model.ProjectsNames[j]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            has_error = true;
                            ModelState.AddModelError("", "Пользователь " + model.Header.UserNames[i] + " не найден");
                        }
                    }


                    if (was_apply && !has_error)
                    {
                        var             UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                        string          uid         = User.Identity.GetUserId();
                        ApplicationUser admin       = db.Users.FirstOrDefault(x => x.Id == uid);
                        if (model.Header.State == PaymentsGroupState.PaidOut)
                        {
                            paymentsGroup.UserClosed  = admin;
                            paymentsGroup.State       = PaymentsGroupState.PaidOut;
                            paymentsGroup.WhenPaidOut = DateTime.Now;
                        }

                        db.SaveChanges();

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        if (!was_apply)
                        {
                            ModelState.AddModelError("", "В счете не найдено корректных платежей");
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Счет не найден, id=" + model.Header.PaymentsGroupId);
                }
            }
            else
            {
                ModelState.AddModelError("", "Ошибка ввода ");
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult ExportForm(RateUploadModel input)
        {
            if (input.PaymentsGroupId != null)
            {
                if (input.UploadFile != null)
                {
                    PaymentsGroupViewModel payments = getPaymentsGroupViewModel(input.PaymentsGroupId);
                    if (payments != null)
                    {
                        MemoryStream ms = new MemoryStream();
                        using (var package = new ExcelPackage(input.UploadFile.InputStream))
                        {
                            var Sheet   = package.Workbook.Worksheets[1];
                            int lastRow = Sheet.Dimension.End.Row;
                            int lastCol = Sheet.Dimension.End.Column;

                            if (Sheet.AutoFilterAddress != null)
                            {
                                Sheet.Cells[Sheet.AutoFilterAddress.ToString()].AutoFilter = false;
                            }
                            try
                            {
                                Sheet.Cells["F:" + Sheet.Dimension.End.Address].Clear();
                            }
                            catch (Exception) { }

                            for (int j = 0; j < payments.ProjectsNames.Length; j++)
                            {
                                Sheet.Cells[4, 6 + j].Value = payments.ProjectsNames[j];
                                Sheet.Cells[4, 6 + j].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
                            }
                            Sheet.Cells[4, 6 + payments.ProjectsNames.Length].Value = "ВСЕГО";
                            var f = Sheet.Cells[4, 6 + payments.ProjectsNames.Length].Style.Font;
                            f.Bold = true;
                            Sheet.Cells[4, 6 + payments.ProjectsNames.Length].Style.Font = f;
                            Sheet.Cells[4, 6 + payments.ProjectsNames.Length].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);



                            int i = 5;
                            int count_sum_lines = 0;
                            do
                            {
                                if (Sheet.Cells[i, 1].Value != null)
                                {
                                    if (Sheet.Cells[i, 1].Value.ToString().Trim() != "ИТОГО")
                                    {
                                        int index = payments.PaymentsIndexByShortName(Sheet.Cells[i, 1].Value.ToString());
                                        if (index != -1)
                                        {
                                            for (int j = 0; j < payments.Header.Payments[index].Length; j++)
                                            {
                                                if (payments.Header.Payments[index][j] != -1)
                                                {
                                                    Sheet.Cells[i, 6 + j].Value = payments.Header.Payments[index][j];
                                                }
                                            }
                                        }
                                        Sheet.Cells[i, 6 + payments.ProjectsNames.Length].FormulaR1C1 = "SUM(RC[-" + (payments.ProjectsNames.Length + 1) + "]:RC[-1])";
                                        count_sum_lines++;
                                    }
                                    for (int j = 0; j <= payments.ProjectsNames.Length; j++)
                                    {
                                        Sheet.Cells[i, 6 + j].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
                                    }
                                }
                                i++;
                            } while (i <= lastRow);

                            Sheet.Cells[i - 1, 6 + payments.ProjectsNames.Length].FormulaR1C1 = "SUM(R[-1]C[0]:R[-" + count_sum_lines + "]C[0])";

                            var range = Sheet.Cells["A4:" + Sheet.Cells[i, 6 + payments.ProjectsNames.Length].Address];
                            range.AutoFilter = true;

                            package.SaveAs(ms);
                        }
                        ms.Position = 0;
                        return(new FileStreamResult(ms, "application/xlsx")
                        {
                            FileDownloadName = "Виртуальный счет КБ Харьков от " + payments.Header.WhenCreated.ToString("dd.MM.yyyy") + ".xlsx"
                        });
                    }
                    else
                    {
                        ModelState.AddModelError("", "Ошибка, не найден счет ");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка загрузки файла ");
                }
            }
            else
            {
                ModelState.AddModelError("", "Ошибка, не задан счет ");
            }

            return(View());
        }