Beispiel #1
0
        public IActionResult Statements(string[] Month, ZarplataModel model)
        {
            List <ZarplataModel> inf = new List <ZarplataModel>();

            if (Month.Length == 0)
            {
                ViewBag.inf = _zarplata.Read(null);
                return(View());
            }
            var agent = _agent.Read(null).Last();

            for (int i = 1; i <= agent.Id; i++)
            {
                var ag = _agent.Read(new AgentBindingModel {
                    Id = i
                }).FirstOrDefault();
                if (ag != null)
                {
                    bool check = false;
                    foreach (var zp in _zarplata.Read(null))
                    {
                        if (zp.data == AgentController.PeriodDate(Month[0]) && zp.UserId == ag.Id)
                        {
                            check = true;
                        }
                    }
                    var summ = _agent.Read(new AgentBindingModel {
                        Id = i
                    }).FirstOrDefault();
                    zp = summ.Oklad;
                    var com = _agent.Read(new AgentBindingModel {
                        Id = i
                    }).FirstOrDefault();
                    comis = com.Comission;
                    inf.Add(new ZarplataModel
                    {
                        Id    = i,
                        Name  = ag.Name,
                        Summa = ResultZp(Month, i, false)
                    });
                    if (!check)
                    {
                        _zarplata.CreateOrUpdate(new ZarplataBindingModel
                        {
                            UserId = i,
                            Name   = ag.Name,
                            Summa  = ResultZp(Month, i, false),
                            data   = AgentController.PeriodDate(Month[0])
                        });
                    }
                }
            }
            ViewBag.inf = inf;
            return(View());
        }
Beispiel #2
0
        private double ResultZp(string[] Month, int id, bool check)
        {
            if (Month.Length == 0)
            {
                TempData["ErrorLack"] = "Вы не выбрали месяц";
                return(0);
            }
            double dogovor = 0;

            if (check)
            {
                dogovor = _dogovor.Read(null).Where(rec => (rec.data > DateTime.Now.AddYears(-1) && rec.data < DateTime.Now) && (rec.AgentId == id)).Select(rec => rec.Summa).Sum();
                zp     *= 12;
            }
            else
            {
                DateTime date = AgentController.PeriodDate(Month[0]);
                dogovor = _dogovor.Read(null).Where(rec => (rec.data.Month == date.Month) && (rec.AgentId == id)).Select(rec => rec.Summa).Sum();
            }
            zp += dogovor * (comis / 100);
            return(zp);
        }
        public IActionResult ReadOfAgent(string[] Month, ReportModel m)
        {
            if (Month.Length == 0)
            {
                TempData["ErrorLack"] = "Вы не выбрали месяц";
                return(RedirectToAction("Report"));
            }
            var           FileName = m.puth + $"ReportMonth{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}.pdf";
            List <string> list     = new List <string> {
                "Номер", "Дата", "Агент", "Сумма"
            };
            DateTime date = AgentController.PeriodDate(Month[0]);

            SaveToPdf.ZpMonth(new Info
            {
                FileName  = FileName,
                Title     = $"Отчет зп за месяц {DateTime.Now.Month} года {DateTime.Now.Year}",
                Colon     = list,
                zarplatas = _zarplata.Read(null).Where(rec => rec.data.Month == date.Month).ToList()
            }, date);;
            Mail.SendMail(m.SendMail, FileName, $"Отчет за месяц {DateTime.Now.Month} года {DateTime.Now.Year}");
            return(RedirectToAction("Report"));
        }