add employee leaves to TotalHourse
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
using System;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
|
||||
public class LeaveSearchModel
|
||||
{
|
||||
public string StartLeave { get; set; }
|
||||
public string EndLeave { get; set; }
|
||||
public string LeaveHourses { get; set; }
|
||||
public DateTime? StartLeaveGr { get; set; }
|
||||
public DateTime? EndLeaveGr { get; set; }
|
||||
public string LeaveHourses { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public string PaidLeaveType { get; set; }
|
||||
|
||||
@@ -22,4 +22,6 @@ public class LeaveViewModel
|
||||
public int Month { get; set; }
|
||||
public string MonthStr { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
|
||||
public int DayCounter { get; set; }
|
||||
}
|
||||
@@ -78,8 +78,15 @@ public class LeaveRepository : RepositoryBase<long, Leave>, ILeaveRepository
|
||||
(startSearch <= x.EndLeaveGr && endSearch >= x.EndLeaveGr) ||
|
||||
(startSearch >= x.StartLeaveGr && startSearch <= x.EndLeaveGr) ||
|
||||
(endSearch >= x.StartLeaveGr && endSearch <= x.EndLeaveGr));
|
||||
}
|
||||
|
||||
}else if (searchModel.StartLeaveGr != null && searchModel.EndLeaveGr != null)
|
||||
{
|
||||
query = query.Where(x => (searchModel.StartLeaveGr <= x.StartLeaveGr && searchModel.EndLeaveGr >= x.StartLeaveGr) ||
|
||||
(searchModel.StartLeaveGr <= x.EndLeaveGr && searchModel.EndLeaveGr >= x.EndLeaveGr) ||
|
||||
(searchModel.StartLeaveGr >= x.StartLeaveGr && searchModel.StartLeaveGr <= x.EndLeaveGr) ||
|
||||
(searchModel.EndLeaveGr >= x.StartLeaveGr && searchModel.EndLeaveGr <= x.EndLeaveGr));
|
||||
}
|
||||
if(searchModel.IsAccepted)
|
||||
query = query.Where(x => x.IsAccepted == true);
|
||||
return query.OrderByDescending(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.LeaveAgg;
|
||||
using Company.Domain.LeftWorkAgg;
|
||||
using Company.Domain.RollCallAgg;
|
||||
using Company.Domain.YearlySalaryAgg;
|
||||
using CompanyManagment.App.Contracts.Contract;
|
||||
using CompanyManagment.App.Contracts.Leave;
|
||||
using CompanyManagment.App.Contracts.LeftWork;
|
||||
using CompanyManagment.App.Contracts.RollCall;
|
||||
using CompanyManagment.App.Contracts.WorkingHoursTemp;
|
||||
@@ -20,13 +22,15 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
private readonly CompanyContext _context;
|
||||
private readonly IYearlySalaryRepository _yearlySalaryRepository;
|
||||
private readonly ILeftWorkRepository _leftWorkRepository;
|
||||
private readonly ILeaveRepository _leaveRepository;
|
||||
|
||||
public RollCallMandatoryRepository(CompanyContext context, IYearlySalaryRepository yearlySalaryRepository,
|
||||
ILeftWorkRepository leftWorkRepository) : base(context)
|
||||
ILeftWorkRepository leftWorkRepository, ILeaveRepository leaveRepository) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
_yearlySalaryRepository = yearlySalaryRepository;
|
||||
_leftWorkRepository = leftWorkRepository;
|
||||
_leaveRepository = leaveRepository;
|
||||
}
|
||||
|
||||
public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart,
|
||||
@@ -56,15 +60,73 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
|
||||
var groupedRollCall = rollCallResult.GroupBy(x=>x.CreationDate).Select(x => new GroupedRollCalls()
|
||||
{
|
||||
CreationDate = x.Key,
|
||||
SumOneDaySpan = new TimeSpan(x.Sum(x => x.ShiftSpan.Ticks)),
|
||||
SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)),
|
||||
}).ToList();
|
||||
//*****کسر ساعاعت استراحت پرسنل از ساعت کار
|
||||
var rollCallSubtractSpan = groupedRollCall.Select(x => new GroupedRollCalls()
|
||||
{
|
||||
CreationDate = x.CreationDate,
|
||||
AfterSubtractRestSpan = AfterSubtract(command,x.SumOneDaySpan,x.CreationDate),
|
||||
}).ToList();
|
||||
var sumSpans = new TimeSpan(rollCallSubtractSpan.Sum(x => x.AfterSubtractRestSpan.Ticks));
|
||||
|
||||
TimeSpan sumSpans = new TimeSpan(rollCallSubtractSpan.Sum(x => x.AfterSubtractRestSpan.Ticks));
|
||||
|
||||
|
||||
//****افزودن مرخصی پرسنل به مجموع ساعات کار***
|
||||
#region AddEmployeeLeavs
|
||||
|
||||
|
||||
LeaveSearchModel leaveSearch = new LeaveSearchModel()
|
||||
{
|
||||
EmployeeId = employeeId,
|
||||
WorkshopId = workshopId,
|
||||
LeaveType = "استحقاقی",
|
||||
PaidLeaveType = "روزانه",
|
||||
StartLeaveGr = contractStart,
|
||||
EndLeaveGr = contractEnd,
|
||||
IsAccepted = true,
|
||||
};
|
||||
var leaveSearchResult = _leaveRepository.search(leaveSearch);
|
||||
if (leaveSearchResult.Count > 0)
|
||||
{
|
||||
int leavingDayCout = 0;
|
||||
//مرخصی های مابین
|
||||
List<LeaveViewModel> beatweenCheckout = leaveSearchResult.Where(x => x.StartLeaveGr >= contractStart && x.EndLeaveGr <= contractEnd).Select(x => new LeaveViewModel()
|
||||
{
|
||||
DayCounter = Convert.ToInt32(x.LeaveHourses),
|
||||
|
||||
}).ToList();
|
||||
leavingDayCout += beatweenCheckout.Sum(x => x.DayCounter);
|
||||
// مرخصی که شروعش قبل از شروع تصفیه حساب است
|
||||
List<LeaveViewModel> beforeCheckout = leaveSearchResult.Where(x => x.StartLeaveGr < contractStart).Select(x => new LeaveViewModel()
|
||||
{
|
||||
DayCounter = (int)(contractStart - x.EndLeaveGr).TotalDays + 1,
|
||||
|
||||
}).ToList();
|
||||
leavingDayCout+= beforeCheckout.Sum(x => x.DayCounter);
|
||||
// مرخصی که پایانش بعد از پایان تصفیه حساب است
|
||||
List<LeaveViewModel> afterCheckout = leaveSearchResult.Where(x => x.EndLeaveGr > contractEnd).Select(x => new LeaveViewModel()
|
||||
{
|
||||
DayCounter = (int)(x.StartLeaveGr - contractEnd).TotalDays + 1,
|
||||
|
||||
}).ToList();
|
||||
leavingDayCout += afterCheckout.Sum(x => x.DayCounter);
|
||||
Console.WriteLine(leavingDayCout);
|
||||
TimeSpan workingPerDayAve = sumSpans / rollCallSubtractSpan.Count;//میانگین ساعت کار در روز
|
||||
TimeSpan sumLeave = new TimeSpan();
|
||||
if (workingPerDayAve <= new TimeSpan(7, 20, 0))
|
||||
{
|
||||
sumLeave = leavingDayCout * workingPerDayAve;
|
||||
}
|
||||
else
|
||||
{
|
||||
sumLeave = leavingDayCout * new TimeSpan(7, 20, 0);
|
||||
}
|
||||
|
||||
sumSpans = sumSpans.Add(sumLeave);
|
||||
}
|
||||
|
||||
Console.WriteLine(sumSpans);
|
||||
#endregion
|
||||
//***********************************//
|
||||
//ToTalHourse Employe eWorked
|
||||
var totalHourses = (sumSpans.TotalMinutes) / 60;
|
||||
|
||||
@@ -1675,7 +1675,8 @@ public class IndexModel : PageModel
|
||||
LeaveType = "استحقاقی",
|
||||
PaidLeaveType = "روزانه",
|
||||
StartLeave = command.ContarctStart,
|
||||
EndLeave = command.ContractEnd
|
||||
EndLeave = command.ContractEnd,
|
||||
IsAccepted = true,
|
||||
};
|
||||
var leavList = _leaveApplication.search(serachModel);
|
||||
#region entityes
|
||||
|
||||
Reference in New Issue
Block a user