using AccountMangement.Infrastructure.EFCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; using CompanyManagment.App.Contracts.Report; using Microsoft.EntityFrameworkCore; using PersianTools.Core; namespace CompanyManagment.EFCore.Repository; public class ReportRepositoryNew { private readonly CompanyContext _context; private readonly AccountContext _accountContext; public ReportRepositoryNew(CompanyContext context, AccountContext accountContext) { _context = context; _accountContext = accountContext; } public AllReport GetAllActiveWorkshopsNew(string year, string month) { //یافتن آغاز و پایان ماه جاری //یافتن آغاز و پایان ماه بعد #region FindMonthStartAndEnd string nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01"; if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month)) nowFa = $"{year}/{month}/01"; var currentEndOfMonth = nowFa.FindeEndOfMonth(); //شروع ماه جاری var currentMonthStart = nowFa.ToGeorgianDateTime(); // پایان کاه جاری var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime(); int currentYear = Convert.ToInt32(nowFa.Substring(0, 4)); var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2)); var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1); //شروع ماه بعد var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime(); //پایان ماه بعد var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime(); #endregion var lefts = _context.LeftWorkList .Include(x=>x.Workshop) .Where(x=>x.Workshop.IsActiveString == "true") .Count(x => x.StartWorkDate < currentMonthEnd && x.LeftWorkDate > currentMonthStart); return new(); } }