Merge branch 'master' into Mahan

This commit is contained in:
MahanCh
2025-03-15 14:58:13 +03:30
7 changed files with 76 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.Domain;
using CompanyManagment.App.Contracts.LeftWork;
@@ -39,5 +40,7 @@ public interface ILeftWorkRepository : IRepository<long, LeftWork>
bool IsEmployeeWorkingInDates(long employeeId, long workshopId, List<(DateTime, DateTime)> dates);
List<LeftWorkViewModel> GetByWorkshopIdInDates(long workshopId, DateTime startDateGr, DateTime endDateGr);
LeftWorkViewModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end);
#endregion
#endregion
Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId);
}

View File

@@ -15,8 +15,7 @@ public class RollCallEmployeeViewModel : EditRollCallEmployee
public string PersonName { get; set; }
public bool ContractPerson { get; set; }
public bool InsurancePerson { get; set; }
public long WorkshopId { get; set; }
public long EmployeeId { get; set; }
public bool ContractLeft { get; set; }
public bool InsurancetLeft { get; set; }
public bool Black { get; set; }

View File

@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Company.Domain.RollCallServiceAgg;
using System.Globalization;
namespace CompanyManagment.Application
@@ -35,7 +36,7 @@ namespace CompanyManagment.Application
return op.Failed("کارمند مجاز نیست");
if (!_leftWorkRepository.Exists(x => x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date))
(x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date) || x.StartWorkDate >= DateTime.Today))
return op.Failed("کارمند در کارگاه شروع به کار نکرده است");
if (_employeeRollCallStatusRepository.Exists(y =>
@@ -50,7 +51,21 @@ namespace CompanyManagment.Application
}
else
{
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, DateTime.Now.Date);
var pc = new PersianCalendar();
var startStatus = DateTime.Today;
LeftWork leftWork =
_leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult();
if (leftWork.StartWorkDate > DateTime.Today)
startStatus = leftWork.StartWorkDate;
//else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate))
//{
// startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate),
// 1, pc);
//}
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus);
_employeeRollCallStatusRepository.Create(newRecord);
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.InfraStructure;
using Company.Domain.LeftWorkAgg;
@@ -162,15 +163,17 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
if (item != null)
{
_context.LeftWorkList.Remove(item);
_context.SaveChanges();
if (!_context.LeftWorkList.Any(x => x.WorkshopId == item.WorkshopId && x.EmployeeId == item.EmployeeId && item.id != x.id) && HasActiveRollCallStatus(item.WorkshopId, item.EmployeeId))
{
RemoveEmployeeRollCallStatus(item.WorkshopId,item.EmployeeId);
RemoveEmployeeRollCallStatus(item.WorkshopId, item.EmployeeId);
}
_context.LeftWorkList.Remove(item);
}
_context.SaveChanges();
return op.Succcedded();
}
@@ -238,8 +241,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
}
if (HasActiveRollCallStatus(workshopId, employeeId))
RemoveEmployeeRollCallStatus(workshopId, employeeId);
var list = _context.LeftWorkList.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).ToList();
@@ -255,7 +257,12 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
}
_context.SaveChanges();
transaction.Commit();
if (HasActiveRollCallStatus(workshopId, employeeId))
RemoveEmployeeRollCallStatus(workshopId, employeeId);
if (hasLeftWorkInsurance)
return
op.Succcedded(1, "حذف با موفقیت انجام شد."); //+ "<br/>" + "<span class='text-danger'>" + "کد پرسنلی این شخص به دلیل استفاده در ترک کار بیمه قابل حذف نمی باشد. " + "</span>");
@@ -630,19 +637,49 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
private bool HasActiveRollCallStatus(long workshopId, long employeeId)
{
var now = DateTime.Today;
var isDateUndefined = new DateTime(2121, 03, 21);
return
_context.RollCallEmployees.Include(x => x.EmployeesStatus).Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId &&
x.EmployeesStatus.Any(y => y.EndDate.Date > now && y.StartDate <= now));
x.EmployeesStatus.Any(y => (y.EndDate.Date > now && y.StartDate <= now) || (y.EndDate.Date == isDateUndefined)));
}
private void RemoveEmployeeRollCallStatus(long workshopId, long employeeId)
{
var entity = _context.RollCallEmployees.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
var entity = _context.RollCallEmployees.Include(x=>x.EmployeesStatus).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
if (entity == null)
return;
_context.RollCallEmployees.Remove(entity);
_context.SaveChanges();
var hasLeftWork = _context.LeftWorkList.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
//اگر هیچ شرع بکار ترک کاری نداشت
if (!hasLeftWork)
{
var now = DateTime.Today;
entity.DeActive();
var rollCallEmployeeStatus =
entity.EmployeesStatus.FirstOrDefault(x => x.EndDate.Date.IsDateUndefined() || x.EndDate.Date > now && x.StartDate <= now);
if (rollCallEmployeeStatus != null)
{
var end = rollCallEmployeeStatus.StartDate.Date > DateTime.Now.Date
? rollCallEmployeeStatus.StartDate.Date
: DateTime.Now.Date;
rollCallEmployeeStatus.Deactivate(end);
}
_context.SaveChanges();
}
//_context.RollCallEmployees.Remove(entity);
}
#endregion
public async Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId)
{
var leftWork = await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId)
.OrderByDescending(x => x.StartWorkDate).FirstOrDefaultAsync();
return leftWork;
}
}

View File

@@ -114,7 +114,7 @@ public class ReportRepository : IReportRepository
// };
//}
public async Task<AllReport> GetAllActiveWorkshopsNew(string year, string month)
public Task<AllReport> GetAllActiveWorkshopsNew(string year, string month)
{
var watch = System.Diagnostics.Stopwatch.StartNew();
//یافتن آغاز و پایان ماه جاری
@@ -442,7 +442,7 @@ public class ReportRepository : IReportRepository
};
Console.WriteLine("new metod >>>>>: " + watch.Elapsed);
return finalResult;
return Task.FromResult(finalResult);
}
public AllReport GetAllActiveWorkshops(string year, string month)

View File

@@ -48,12 +48,11 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
public EditRollCallEmployee GetDetails(long id)
{
return _context.RollCallEmployees.Select(x => new RollCallEmployeeViewModel()
return _context.RollCallEmployees.Select(x => new EditRollCallEmployee()
{
Id = x.id,
WorkshopId = x.WorkshopId,
EmployeeFName = x.FName,
EmployeeLName = x.LName,
EmployeeId = x.EmployeeId,
EmployeeFullName = x.EmployeeFullName,
IsActiveString = x.IsActiveString,
HasUploadedImage = x.HasUploadedImage
@@ -96,15 +95,15 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
var rawQuery = employeeQuery.Include(x => x.LeftWorks).Include(x => x.LeftWorkInsurances)
.Where(x => x.LeftWorks.Any(y =>
y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow &&
y.LeftWorkDate > dateNow) ||
(y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow &&
y.LeftWorkDate > dateNow) || y.StartWorkDate > dateNow) ||
x.LeftWorkInsurances.Any(y =>
y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow &&
(y.LeftWorkDate > dateNow || y.LeftWorkDate == null))).OrderByDescending(x => x.id)
.Select(x => new
{
Id = x.id,
FullName =x.FName +" "+x.LName,
FullName = x.FName + " " + x.LName,
x.NationalCode,
}).AsSplitQuery();

View File

@@ -198,7 +198,7 @@
</div>
<div class="card p-0">
<div class="card-section-btn">
<a class="btn loadingButton @(authHelper.GetPermissions().Any(x => x == 2) ? "" : "disable")" asp-area="AdminNew" asp-page="/Company/FileBackup/Index">
<a class="btn loadingButton @(authHelper.GetPermissions().Any(x => x == 2) || authHelper.CurrentAccountId() == 322 ? "" : "disable")" asp-area="AdminNew" asp-page="/Company/FileBackup/Index">
<svg width="50" height="50" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M42.75 7.875H11.25C10.0125 7.875 9 8.8875 9 10.125V16.875C9 18.1125 10.0125 19.125 11.25 19.125H42.75C43.9875 19.125 45 18.1125 45 16.875V10.125C45 8.8875 43.9875 7.875 42.75 7.875ZM42.75 21.375H11.25C10.0125 21.375 9 22.3875 9 23.625V30.375C9 31.6125 10.0125 32.625 11.25 32.625H42.75C43.9875 32.625 45 31.6125 45 30.375V23.625C45 22.3875 43.9875 21.375 42.75 21.375ZM42.75 34.875H11.25C10.0125 34.875 9 35.8875 9 37.125V43.875C9 45.1125 10.0125 46.125 11.25 46.125H42.75C43.9875 46.125 45 45.1125 45 43.875V37.125C45 35.8875 43.9875 34.875 42.75 34.875Z" fill="#C4E8E8"/>
<path d="M34.875 33.7492L42.75 40.0492V27.4492L34.875 33.7492Z" fill="#23A8A8"/>