diff --git a/AccountManagement.Application.Contracts/Media/IMediaApplication.cs b/AccountManagement.Application.Contracts/Media/IMediaApplication.cs index b2473b34..cbeb3184 100644 --- a/AccountManagement.Application.Contracts/Media/IMediaApplication.cs +++ b/AccountManagement.Application.Contracts/Media/IMediaApplication.cs @@ -4,13 +4,13 @@ using System.Collections.Generic; namespace AccountManagement.Application.Contracts.Media { - public interface IMediaApplication - { - MediaViewModel Get(long id); - OperationResult UploadFile(IFormFile file, string fileLabel, string relativePath, int maximumFileLength, + public interface IMediaApplication + { + MediaViewModel Get(long id); + OperationResult UploadFile(IFormFile file, string fileLabel, string relativePath, int maximumFileLength, List allowedExtensions, string category); - OperationResult MoveFile(long mediaId, string newRelativePath); - OperationResult DeleteFile(long mediaId); - List GetRange(IEnumerable select); - } -} + OperationResult MoveFile(long mediaId, string newRelativePath); + OperationResult DeleteFile(long mediaId); + List GetRange(IEnumerable select); + } +} \ No newline at end of file diff --git a/AccountManagement.Application/MediaApplication.cs b/AccountManagement.Application/MediaApplication.cs index 80278876..354027da 100644 --- a/AccountManagement.Application/MediaApplication.cs +++ b/AccountManagement.Application/MediaApplication.cs @@ -9,17 +9,17 @@ using Microsoft.AspNetCore.Http; namespace AccountManagement.Application { - public class MediaApplication:IMediaApplication - { + public class MediaApplication : IMediaApplication + { - private const string _basePath = "Medias"; - private readonly IMediaRepository _mediaRepository; + private const string _basePath = "Medias"; + private readonly IMediaRepository _mediaRepository; - public MediaApplication(IMediaRepository mediaRepository) - { - _mediaRepository = mediaRepository; - } + public MediaApplication(IMediaRepository mediaRepository) + { + _mediaRepository = mediaRepository; + } /// @@ -34,88 +34,88 @@ namespace AccountManagement.Application /// public OperationResult UploadFile(IFormFile file, string fileLabel, string relativePath, int maximumFileLength, List allowedExtensions, string category) - { - return _mediaRepository.UploadFile(file,fileLabel, relativePath, maximumFileLength, allowedExtensions, category); - } + { + return _mediaRepository.UploadFile(file, fileLabel, relativePath, maximumFileLength, allowedExtensions, category); + } - /// - /// حذف فایل - /// - public OperationResult DeleteFile(long mediaId) - { - OperationResult op = new(); - var media = _mediaRepository.Get(mediaId); - if (media == null) - return op.Failed("رکورد مورد نظر یافت نشد"); - try - { - if (File.Exists(media.Path)) - File.Delete(media.Path); - else - return op.Failed("فایل یافت نشد"); - } - catch - { - return op.Failed("خطایی در حذف فایل رخ داده است"); - } + /// + /// حذف فایل + /// + public OperationResult DeleteFile(long mediaId) + { + OperationResult op = new(); + var media = _mediaRepository.Get(mediaId); + if (media == null) + return op.Failed("رکورد مورد نظر یافت نشد"); + try + { + if (File.Exists(media.Path)) + File.Delete(media.Path); + else + return op.Failed("فایل یافت نشد"); + } + catch + { + return op.Failed("خطایی در حذف فایل رخ داده است"); + } - _mediaRepository.Remove(media.id); - _mediaRepository.SaveChanges(); - return op.Succcedded(); - } + _mediaRepository.Remove(media.id); + _mediaRepository.SaveChanges(); + return op.Succcedded(); + } - /// - /// جابجا کردن فایل - /// - public OperationResult MoveFile(long mediaId, string newRelativePath) - { - OperationResult op = new(); - var media = _mediaRepository.Get(mediaId); - var oldPath = media.Path; - var path = Path.Combine(_basePath, newRelativePath); - Directory.CreateDirectory(path); + /// + /// جابجا کردن فایل + /// + public OperationResult MoveFile(long mediaId, string newRelativePath) + { + OperationResult op = new(); + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine(_basePath, newRelativePath); + Directory.CreateDirectory(path); - string filepath = Path.Combine(path, Path.GetFileName(oldPath)); - try - { - File.Move(oldPath, filepath); - } - catch - { - return op.Failed("در جابجایی فایل خطایی رخ داده است"); - } + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + try + { + File.Move(oldPath, filepath); + } + catch + { + return op.Failed("در جابجایی فایل خطایی رخ داده است"); + } - media.Edit(filepath, media.Type, media.Category); - _mediaRepository.SaveChanges(); - return op.Succcedded(); - } + media.Edit(filepath, media.Type, media.Category); + _mediaRepository.SaveChanges(); + return op.Succcedded(); + } - public MediaViewModel Get(long id) - { - var media = _mediaRepository.Get(id); - if (media == null) - return new(); - return new MediaViewModel() - { - Category = media.Category, - Path = media.Path, - Id = media.id, - Type = media.Type - }; - } + public MediaViewModel Get(long id) + { + var media = _mediaRepository.Get(id); + if (media == null) + return new(); + return new MediaViewModel() + { + Category = media.Category, + Path = media.Path, + Id = media.id, + Type = media.Type + }; + } - public List GetRange(IEnumerable ids) - { - var medias = _mediaRepository.GetRange(ids); - return medias.Select(x=>new MediaViewModel() - { - Category = x.Category, - Path = x.Path, - Id = x.id, - Type = x.Type, - }).ToList(); - } + public List GetRange(IEnumerable ids) + { + var medias = _mediaRepository.GetRange(ids); + return medias.Select(x => new MediaViewModel() + { + Category = x.Category, + Path = x.Path, + Id = x.id, + Type = x.Type, + }).ToList(); + } - } + } } diff --git a/AccountManagement.Domain/MediaAgg/IMediaRepository.cs b/AccountManagement.Domain/MediaAgg/IMediaRepository.cs index 1b71139d..f84117d6 100644 --- a/AccountManagement.Domain/MediaAgg/IMediaRepository.cs +++ b/AccountManagement.Domain/MediaAgg/IMediaRepository.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Http; namespace AccountManagement.Domain.MediaAgg; -public interface IMediaRepository:IRepository +public interface IMediaRepository : IRepository { public string BasePath { get; protected set; } void CreateMediaWithTaskMedia(long taskId, long mediaId); diff --git a/AccountMangement.Infrastructure.EFCore/Repository/MediaRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/MediaRepository.cs index 7c8588c4..756bfae3 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/MediaRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/MediaRepository.cs @@ -16,29 +16,29 @@ using Microsoft.EntityFrameworkCore; namespace AccountMangement.Infrastructure.EFCore.Repository; -public class MediaRepository:RepositoryBase,IMediaRepository +public class MediaRepository : RepositoryBase, IMediaRepository { private const string _basePath = "Storage/Medias"; public string BasePath { get; set; } - + private readonly AccountContext _accountContext; - public MediaRepository( AccountContext taskManagerContext, IWebHostEnvironment webHostEnvironment) : base(taskManagerContext) + public MediaRepository(AccountContext taskManagerContext, IWebHostEnvironment webHostEnvironment) : base(taskManagerContext) { _accountContext = taskManagerContext; - BasePath = webHostEnvironment.ContentRootPath+"/Storage"; + BasePath = webHostEnvironment.ContentRootPath + "/Storage"; } //ساخت جدول واسط بین مدیا و نسک //نکته: این متد ذخیره انجام نمیدهد public void CreateMediaWithTaskMedia(long taskId, long mediaId) { - var Taskmedias = new TaskMedia(taskId,mediaId); + var Taskmedias = new TaskMedia(taskId, mediaId); _accountContext.Add(Taskmedias); } public void Remove(long id) { - var media = Get(id); + var media = Get(id); Remove(media); } diff --git a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs index d40fca9c..f7a1b777 100644 --- a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs +++ b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs @@ -60,4 +60,13 @@ public interface IInsuranceListRepository:IRepository #region client List SearchForClient(InsuranceListSearchModel searchModel); #endregion -} \ No newline at end of file + + #region Mahan + Task GetInsuranceOperationDetails(long id); + + Task GetTabCounts(long accountId,int month,int year); + + #endregion +} + + diff --git a/Company.Domain/InsuranceListAgg/InsuranceList.cs b/Company.Domain/InsuranceListAgg/InsuranceList.cs index ade683ed..3da643cb 100644 --- a/Company.Domain/InsuranceListAgg/InsuranceList.cs +++ b/Company.Domain/InsuranceListAgg/InsuranceList.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using _0_Framework.Domain; using Company.Domain.InsuranceListAgg.ValueObjects; using Company.Domain.InsuranceWorkshopAgg; +using CompanyManagment.App.Contracts.InsuranceList.Enums; namespace Company.Domain.InsuranceListAgg; @@ -156,7 +157,7 @@ public class InsuranceList : EntityBase /// /// بازرسی /// - public InsuranceListInspection Inspection { get; set; } =new (InsuraceListInspectionType.None,DateTime.MinValue, 0); + public InsuranceListInspection Inspection { get; set; } =new (InsuranceListInspectionType.None,DateTime.MinValue, 0); /// /// بدهی /// diff --git a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListDebt.cs b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListDebt.cs index 8190e47d..1d3b488b 100644 --- a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListDebt.cs +++ b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListDebt.cs @@ -1,4 +1,5 @@ using System; +using CompanyManagment.App.Contracts.InsuranceList.Enums; namespace Company.Domain.InsuranceListAgg.ValueObjects; @@ -18,6 +19,7 @@ public class InsuranceListDebt DebtDate = debtDate; Amount = amount; MediaId = mediaId; + IsDone = true; } } @@ -25,4 +27,5 @@ public class InsuranceListDebt public DateTime DebtDate { get; set; } public double Amount { get; set; } public long MediaId { get; set; } + public bool IsDone { get; set; } } \ No newline at end of file diff --git a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListEmployerApproval.cs b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListEmployerApproval.cs index b514e022..64a53bf4 100644 --- a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListEmployerApproval.cs +++ b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListEmployerApproval.cs @@ -1,13 +1,26 @@ -namespace Company.Domain.InsuranceListAgg.ValueObjects; +using System.Security.Cryptography; +using CompanyManagment.App.Contracts.InsuranceList.Enums; + +namespace Company.Domain.InsuranceListAgg.ValueObjects; public class InsuranceListEmployerApproval { public InsuranceListEmployerApproval(InsuranceListEmployerApprovalStatus status, string description) { Status = status; - Description = status == InsuranceListEmployerApprovalStatus.None ? string.Empty : description; + if (status == InsuranceListEmployerApprovalStatus.None) + { + Description = string.Empty; + } + else + { + + Description = description; + IsDone = true; + } } public InsuranceListEmployerApprovalStatus Status { get; set; } public string Description { get; set; } + public bool IsDone { get; set; } } \ No newline at end of file diff --git a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListInspection.cs b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListInspection.cs index 89df8081..4a1d15dd 100644 --- a/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListInspection.cs +++ b/Company.Domain/InsuranceListAgg/ValueObjects/InsuranceListInspection.cs @@ -1,13 +1,14 @@ using System; +using CompanyManagment.App.Contracts.InsuranceList.Enums; namespace Company.Domain.InsuranceListAgg.ValueObjects; public class InsuranceListInspection { - public InsuranceListInspection(InsuraceListInspectionType type, DateTime lastInspectionDateTime, long mediaId) + public InsuranceListInspection(InsuranceListInspectionType type, DateTime lastInspectionDateTime, long mediaId) { Type = type; - if (type == InsuraceListInspectionType.None) + if (type == InsuranceListInspectionType.None) { LastInspectionDateTime = DateTime.MinValue; MediaId = 0; @@ -16,10 +17,13 @@ public class InsuranceListInspection { LastInspectionDateTime = lastInspectionDateTime; MediaId = mediaId; + IsDone = true; } } - public InsuraceListInspectionType Type { get; set; } + public InsuranceListInspectionType Type { get; set; } public DateTime LastInspectionDateTime { get; set; } public long MediaId { get; set; } + public bool IsDone { get; set; } + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/EditInsuranceList.cs b/CompanyManagment.App.Contracts/InsuranceList/EditInsuranceList.cs index 9a45fa67..93301e98 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/EditInsuranceList.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/EditInsuranceList.cs @@ -14,9 +14,6 @@ public class EditInsuranceList:CreateInsuranceList public bool FixedSalary { get; set; } public string Population { get; set; } public long? InsuranceJobId { get; set; } - - /// - /// پرسنل هایی که قرارداد ترک کار کرده اند ولی ترک کار بیمه ندارند - /// public List LeftWorkEmployees { get; set; } + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuraceListInspectionType.cs b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuraceListInspectionType.cs deleted file mode 100644 index 2e0f6d2c..00000000 --- a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuraceListInspectionType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Company.Domain.InsuranceListAgg.ValueObjects; - -public enum InsuraceListInspectionType -{ - None, - Old, - New -} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListDebtType.cs b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListDebtType.cs index 94cd6b34..8af13a94 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListDebtType.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListDebtType.cs @@ -1,4 +1,4 @@ -namespace Company.Domain.InsuranceListAgg.ValueObjects; +namespace CompanyManagment.App.Contracts.InsuranceList.Enums; public enum InsuranceListDebtType { diff --git a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListEmployerApprovalStatus.cs b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListEmployerApprovalStatus.cs index 9719cbab..cce4e634 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListEmployerApprovalStatus.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListEmployerApprovalStatus.cs @@ -1,4 +1,4 @@ -namespace Company.Domain.InsuranceListAgg.ValueObjects; +namespace CompanyManagment.App.Contracts.InsuranceList.Enums; public enum InsuranceListEmployerApprovalStatus { diff --git a/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListInspectionType.cs b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListInspectionType.cs new file mode 100644 index 00000000..184cb99d --- /dev/null +++ b/CompanyManagment.App.Contracts/InsuranceList/Enums/InsuranceListInspectionType.cs @@ -0,0 +1,8 @@ +namespace CompanyManagment.App.Contracts.InsuranceList.Enums; + +public enum InsuranceListInspectionType +{ + None, + Old, + New +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs index 0098ab7c..fc91ef9f 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; -using Company.Domain.InsuranceListAgg.ValueObjects; using CompanyManagment.App.Contracts.InsuranceList; using Microsoft.AspNetCore.Http; @@ -19,9 +18,9 @@ public interface IInsuranceListApplication MainEmployeeDetailsViewModel SearchEmployeeForCreateInsuranceList(EmployeeForCreateInsuranceListSearchModel searchModel); double MarriedAllowance(string maritalStatus, long jobId, bool includedStatus, - int countWorkingDays, double marriedAlowance, int endMonthCurrentDay); + int countWorkingDays, double marriedAlowance, int endMonthCurrentDay); - OperationResult CreateEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command); + OperationResult CreateEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command); OperationResult EditEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command); OperationResult Remove(long id); EditInsuranceList GetDetailsForEdit(long id); @@ -43,7 +42,9 @@ public interface IInsuranceListApplication /// /// Task ConfirmInsuranceOperation(InsuranceListConfirmOperation command); + Task GetInsuranceOperationDetails(long id); + + Task GetTabCounts(long accountId, int month, int year); #endregion -} - +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListConfirmOperation.cs b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListConfirmOperation.cs index abd1c013..a13d7d1b 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListConfirmOperation.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListConfirmOperation.cs @@ -1,4 +1,4 @@ -using Company.Domain.InsuranceListAgg.ValueObjects; +using CompanyManagment.App.Contracts.InsuranceList.Enums; using Microsoft.AspNetCore.Http; namespace CompanyManagment.App.Contracts.InsuranceList; @@ -6,8 +6,17 @@ namespace CompanyManagment.App.Contracts.InsuranceList; public class InsuranceListConfirmOperation { public long InsuranceListId { get; set; } + /// + /// بازرسی + /// public CreateInsuranceListInspection Inspection { get; set; } + /// + /// بدهی + /// public CreateInsuranceListDebt Debt { get; set; } + /// + /// تاییدیه کارفرما + /// public CreateInsuranceListApproval Approval { get; set; } public bool ConfirmSentList { get; set; } } @@ -23,11 +32,17 @@ public class CreateInsuranceListDebt public string DebtDate { get; set; } public string Amount { get; set; } public IFormFile DebtFile { get; set; } + public long DebtFileMediaId { get; set; } + public string FilePath { get; set; } } public class CreateInsuranceListInspection { - public InsuraceListInspectionType Type { get; set; } + public InsuranceListInspectionType Type { get; set; } public string LastInspectionDate { get; set; } public IFormFile InspectionFile { get; set; } + public long InspectionFileMediaId { get; set; } + public string FilePath { get; set; } + + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListSearchModel.cs b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListSearchModel.cs index 432e79be..45606294 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListSearchModel.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListSearchModel.cs @@ -25,4 +25,29 @@ public class InsuranceListSearchModel public int PageIndex { get; set; } public bool SearchAll { get; set; } + + public InsuranceListSearchStatus Status { get; set; } +} + +public enum InsuranceListSearchStatus +{ + /// + /// انجام نشده + /// + NotStarted = 0, + + /// + /// در حال انجام امور + /// + InProgress = 1, + + /// + /// آماده ارسال لیست + /// + ReadyToSendList = 2, + + /// + /// انجام بیمه + /// + Done = 3 } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListTabsCountViewModel.cs b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListTabsCountViewModel.cs new file mode 100644 index 00000000..5764a66b --- /dev/null +++ b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListTabsCountViewModel.cs @@ -0,0 +1,24 @@ +namespace CompanyManagment.App.Contracts.InsuranceList; + +public class InsuranceListTabsCountViewModel +{ + /// + /// انجام نشده + /// + public int NotStarted { get; set; } + + /// + /// در حال انجام امور + /// + public int InProgress { get; set; } + + /// + /// آماده ارسال لیست + /// + public int ReadyToSendList { get; set; } + + /// + /// انجام بیمه + /// + public int Done { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListViewModel.cs b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListViewModel.cs index 604d89b4..0d562f76 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/InsuranceListViewModel.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/InsuranceListViewModel.cs @@ -27,4 +27,11 @@ public class InsuranceListViewModel public long WorkShopId { get; set; } public string IsBlockCantracingParty { get; set; } public long EmployerId { get; set; } + + /// وضعیت بازرسی + public bool InspectionDone { get; set; } + /// وضعیت بدهی + public bool DebtDone { get; set; } + /// وضعیت تاییدیه کارفرما + public bool EmployerApproved { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index e3b9a51e..03f64433 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -29,6 +29,7 @@ using CompanyManagment.App.Contracts.EmployeeInsurancListData; using CompanyManagment.App.Contracts.InsuranceEmployeeInfo; using CompanyManagment.App.Contracts.InsuranceJobItem; using CompanyManagment.App.Contracts.InsuranceList; +using CompanyManagment.App.Contracts.InsuranceList.Enums; using CompanyManagment.App.Contracts.InsuranceYearlySalary; using CompanyManagment.App.Contracts.LeftWorkInsurance; using CompanyManagment.App.Contracts.PersonalContractingParty; @@ -44,2277 +45,2294 @@ namespace CompanyManagment.Application; public class InsuranceListApplication : IInsuranceListApplication { - //private readonly ITransactionManager _transactionManager; - private readonly IInsuranceListRepository _insuranceListRepositpry; - private readonly IEmployeeInsurancListDataRepository _employeeInsurancListDataRepository; - private readonly IInsuranceEmployeeInfoRepository _insuranceEmployeeInfoRepository; - private readonly IEmployeeRepository _employeeRepository; - private readonly IWorkshopRepository _workShopRepository; - private readonly ILeftWorkInsuranceApplication _leftWorkInsuranceApplication; - private readonly IInsuranceEmployeeInfoApplication _insuranceEmployeeInfoApplication; - private readonly IEmployeeInsurancListDataApplication _employeeInsurancListDataApplication; - private readonly IYearlySalaryApplication _yearlySalaryApplication; - private readonly IYearlySalaryItemApplication _yearlySalaryItemApplication; - private readonly IInsuranceWorkshopInfoRepository _insuranceWorkshopInfoRepository; - private readonly IInsuranceJobItemRepositpry _insuranceJobItemRepository; - private readonly IDateSalaryRepository _dateSalaryRepository; - private readonly IDateSalaryItemRepository _dateSalaryItemRepository; - private readonly IPersonalContractingPartyApp _contractingPartyApp; - private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository; - private readonly IInsuranceYearlySalaryApplication _insuranceYearlySalaryApplication; - private readonly ICheckoutRepository _checkoutRepository; - private readonly IMediaRepository _mediaRepository; - public InsuranceListApplication(IInsuranceListRepository insuranceListRepositpry, IEmployeeInsurancListDataRepository employeeInsurancListDataRepository, IInsuranceEmployeeInfoRepository insuranceEmployeeInfoRepository, IEmployeeRepository employeeRepository, IWorkshopRepository workShopRepository, ILeftWorkInsuranceApplication leftWorkInsuranceApplication, IInsuranceEmployeeInfoApplication insuranceEmployeeInfoApplication, IEmployeeInsurancListDataApplication employeeInsurancListDataApplication, IYearlySalaryApplication yearlySalaryApplication, IYearlySalaryItemApplication yearlySalaryItemApplication, IInsuranceWorkshopInfoRepository insuranceWorkshopInfoRepository, IInsuranceJobItemRepositpry insuranceJobItemRepository, IDateSalaryRepository dateSalaryRepository, IDateSalaryItemRepository dateSalaryItemRepository, IPersonalContractingPartyApp contractingPartyApp, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IInsuranceYearlySalaryApplication insuranceYearlySalaryApplication, ICheckoutRepository checkoutRepository, IMediaRepository mediaRepository) - { - // _transactionManager = transactionManager; - - _insuranceListRepositpry = insuranceListRepositpry; - _employeeInsurancListDataRepository = employeeInsurancListDataRepository; - _insuranceEmployeeInfoRepository = insuranceEmployeeInfoRepository; - _employeeRepository = employeeRepository; - _workShopRepository = workShopRepository; - _leftWorkInsuranceApplication = leftWorkInsuranceApplication; - _insuranceEmployeeInfoApplication = insuranceEmployeeInfoApplication; - _employeeInsurancListDataApplication = employeeInsurancListDataApplication; - _yearlySalaryApplication = yearlySalaryApplication; - _yearlySalaryItemApplication = yearlySalaryItemApplication; - _insuranceWorkshopInfoRepository = insuranceWorkshopInfoRepository; - _insuranceJobItemRepository = insuranceJobItemRepository; - _dateSalaryRepository = dateSalaryRepository; - _dateSalaryItemRepository = dateSalaryItemRepository; - _contractingPartyApp = contractingPartyApp; - _leftWorkInsuranceRepository = leftWorkInsuranceRepository; - _insuranceYearlySalaryApplication = insuranceYearlySalaryApplication; - _checkoutRepository = checkoutRepository; - _mediaRepository = mediaRepository; - } - - public OperationResult Create(CreateInsuranceList command) - { - - var operation = new OperationResult(); - if (command.WorkshopId == 0) - { - return operation.Failed(" انتخاب کارگاه اجباری می باشد "); - } - if (command.Month == "0") - { - return operation.Failed(" انتخاب ماه اجباری می باشد "); - } - if (command.Year == "0") - { - return operation.Failed("انتخاب سال اجباری می باشد "); - } - else if (_insuranceListRepositpry.Exists(x => - x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) - { - return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); - } - else - { - #region EmployeeDetailsForInsurance - if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) - { - foreach (var item in command.EmployeeDetailsForInsuranceList) - { - if (item.InsuranceEmployeeInformationId == 0) - { - var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); - - createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; - createInsuranceEmployeeInfo.FName = item.FName; - createInsuranceEmployeeInfo.LName = item.LName; - createInsuranceEmployeeInfo.FatherName = item.FatherName; - createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; - createInsuranceEmployeeInfo.NationalCode = item.NationalCode; - createInsuranceEmployeeInfo.IdNumber = item.IdNumber; - createInsuranceEmployeeInfo.Gender = item.Gender; - createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; - createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); - createInsuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); - _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); - } - else - { - - var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); - insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; - insuranceEmployeeInfo.EmployeeId = item.EmployeeId; - insuranceEmployeeInfo.FName = item.FName; - insuranceEmployeeInfo.LName = item.LName; - insuranceEmployeeInfo.FatherName = item.FatherName; - insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; - insuranceEmployeeInfo.NationalCode = item.NationalCode; - insuranceEmployeeInfo.IdNumber = item.IdNumber; - insuranceEmployeeInfo.Gender = item.Gender; - insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; - insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); - insuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); - _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); - - } - } - } - else - { - return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); - } - #endregion - - string startMonthCurrent = command.Year + "/" + command.Month + "/01"; - string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - command.StartDate = startMonthCurrent.ToGeorgianDateTime(); - command.EndDate = endMonthCurrent.ToGeorgianDateTime(); - - #region InsuranceList - - operation = _insuranceListRepositpry.CreateInsuranceList(command); - - #endregion - - return operation; - } - } - - public OperationResult Edit(EditInsuranceList command) - { - - var operation = new OperationResult(); - if (command.WorkshopId == 0) - { - return operation.Failed(" انتخاب کارگاه اجباری می باشد "); - } - if (command.Month == "0") - { - return operation.Failed(" انتخاب ماه اجباری می باشد "); - } - if (command.Year == "0") - { - return operation.Failed("انتخاب سال اجباری می باشد "); - } - else if (_insuranceListRepositpry.Exists(x => x.id != command.Id && x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) - { - return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); - } - else - { - - #region EmployeeDetailsForInsurance - if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) - { - foreach (var item in command.EmployeeDetailsForInsuranceList) - { - if (item.InsuranceEmployeeInformationId == 0) - { - var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); - - createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; - createInsuranceEmployeeInfo.FName = item.FName; - createInsuranceEmployeeInfo.LName = item.LName; - createInsuranceEmployeeInfo.FatherName = item.FatherName; - createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; - createInsuranceEmployeeInfo.NationalCode = item.NationalCode; - createInsuranceEmployeeInfo.IdNumber = item.IdNumber; - createInsuranceEmployeeInfo.Gender = item.Gender; - createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; - createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); - createInsuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); - _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); - } - else - { - - var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); - insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; - insuranceEmployeeInfo.EmployeeId = item.EmployeeId; - insuranceEmployeeInfo.FName = item.FName; - insuranceEmployeeInfo.LName = item.LName; - insuranceEmployeeInfo.FatherName = item.FatherName; - insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; - insuranceEmployeeInfo.NationalCode = item.NationalCode; - insuranceEmployeeInfo.IdNumber = item.IdNumber; - insuranceEmployeeInfo.Gender = item.Gender; - insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; - insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); - insuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); ; - _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); - - } - } - } - else - { - return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); - } - #endregion - - string startMonthCurrent = command.Year + "/" + command.Month + "/01"; - string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - command.StartDate = startMonthCurrent.ToGeorgianDateTime(); - command.EndDate = endMonthCurrent.ToGeorgianDateTime(); - - #region InsuranceList - - operation = _insuranceListRepositpry.EditInsuranceList(command); - - - #endregion - - if (command.InsuranceWorkshopInfo != null) - { - var insuranceWorkshopInfoObj = - _insuranceWorkshopInfoRepository.Get(command.InsuranceWorkshopInfo.InsuranceWorkshopInfoId); - insuranceWorkshopInfoObj.Edit(command.InsuranceWorkshopInfo.WorkshopName, - command.InsuranceWorkshopInfo.InsuranceCode, command.InsuranceWorkshopInfo.AgreementNumber, - command.InsuranceWorkshopInfo.EmployerName, command.InsuranceWorkshopInfo.Address, command.InsuranceWorkshopInfo.ListNumber); - _insuranceWorkshopInfoRepository.SaveChanges(); - - } - - return operation; - } - - } - - public EditInsuranceList GetDetails(long id) - { - var insuranceListDetails = _insuranceListRepositpry.GetDetails(id); - string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; - string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - var year = Convert.ToInt32(insuranceListDetails.Year); - var month = Convert.ToInt32(insuranceListDetails.Month); - var day = 1; - var persianCurrentStartDate = new PersianDateTime(year, month, day); - var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); - - - var model = new YearlySalarySearchModel(); - model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); - model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); - model.year = insuranceListDetails.Year; - var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); - var yearlysalaryItem = new YearlysalaryItemViewModel(); - var housingAllowance = new YearlysalaryItemViewModel(); - var consumableItems = new YearlysalaryItemViewModel(); - if (yearSalaryObj != null) - { - yearlysalaryItem = _yearlySalaryItemApplication - .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "مزد روزانه"); - housingAllowance = _yearlySalaryItemApplication - .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه مسکن"); - consumableItems = _yearlySalaryItemApplication - .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه اقلام"); - } - - foreach (var item in insuranceListDetails.EmployeeDetailsForInsuranceList) - { - - item.IncludeStatus = _leftWorkInsuranceApplication.GetLeftPersonelByWorkshopIdAndEmployeeId(insuranceListDetails.WorkshopId, item.EmployeeId).IncludeStatus; - if (!string.IsNullOrEmpty(item.LeftWorkDate)) - { - var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); - var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); - var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); - - var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); - if (persianLeftDateUser <= persianCurrentEndDate) - item.HasLeftWorkInMonth = true; - else - item.HasLeftWorkInMonth = false; - } - else - { - item.HasLeftWorkInMonth = false; - } - var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); - var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); - var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); - var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); - if (persianStartDateUser < persianCurrentStartDate) - item.HasStartWorkInMonth = false; - else - item.HasStartWorkInMonth = true; - item.StartMonthCurrent = startMonthCurrent; - item.DailyWageStr = item.DailyWage.ToMoney(); - - item.HousingAllowance = housingAllowance.ItemValue; - item.ConsumableItems = consumableItems.ItemValue; - item.EndMonthCurrentDay = dayMonthCurrent; - } - insuranceListDetails.EmployeeDetailsForInsuranceList = insuranceListDetails.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) - .ThenBy(x => x.LName).ToList(); - - insuranceListDetails.AllInsuredShare = insuranceListDetails.InsuredShare + - insuranceListDetails.EmployerShare + - insuranceListDetails.UnEmploymentInsurance; - - insuranceListDetails.LeftWorkEmployees = - _leftWorkInsuranceRepository.GetEmployeesWithContractExitOnly(insuranceListDetails.WorkshopId); - - return insuranceListDetails; - } - - public List Search(InsuranceListSearchModel searchModel) - { - return _insuranceListRepositpry.OptimizedSearch(searchModel); - //var result = _insuranceListRepositpry.Search(searchModel); - //result = result.Select(x => new InsuranceListViewModel() - //{ - // Id = x.Id, - // Year = x.Year, - // Month = x.Month.GetMonthByNumber(), - // MonthNumber = x.MonthNumber, - // WorkShopCode = x.WorkShopCode, - // WorkShopName = x.WorkShopName, - // WorkShopId = x.WorkShopId, - // TypeOfInsuranceSend = x.TypeOfInsuranceSend, - // FixedSalary = x.FixedSalary, - // StrFixedSalary = x.StrFixedSalary, - // EmployerName = x.EmployerName, - // Branch = x.Branch, - // City = x.City, - // ConfirmSentlist = x.ConfirmSentlist, - // EmployerId = x.EmployerId, - // IsBlockCantracingParty = _contractingPartyApp.IsBlockByEmployerId(x.EmployerId), - - //}).ToList(); - //return result; - } - - /// - /// محاسبه جدول پرسنل در مودال ایجاد لیست بیمه - /// - /// - /// - public MainEmployeeDetailsViewModel SearchEmployeeForCreateInsuranceList(EmployeeForCreateInsuranceListSearchModel searchModel) - { - var watch = new Stopwatch(); - - var result = new MainEmployeeDetailsViewModel(); - var workshopId = searchModel.WorkshopIds.FirstOrDefault(); - var workshop = _workShopRepository.GetDetails(workshopId); - //var isBolock = _contractingPartyApp.IsBlockByEmployerId(employerId); - var isBolock = _contractingPartyApp.IsBlockCheckByWorkshopId(workshopId); - double monthlybaseYear = 0; - // اگر در این سال و ماه برای این کارگاه لیست بیمه ایجاد نشده بود - if (!_insuranceListRepositpry.Exists(x => - x.Year == searchModel.Year && x.Month == searchModel.Month && - searchModel.WorkshopIds.Contains(x.WorkshopId))) - { - - var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; - DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); - DateTime endDateGr = startMonthFa.FindeEndOfMonth() - .ToGeorgianDateTime(); - int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); - - - //مقادیر سالانه این تاریخ - var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); - - - // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان - var employeesInfoAndLeftWorks = - _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, - endDateGr); - - var employeeInsurancDataPreviusList = - _insuranceListRepositpry.GetEmployeeInsuranceDataAmonthAgo(startDateGr, workshopId); - watch.Start(); - var computeResult = employeesInfoAndLeftWorks.Select(employee => - { - var dateOfBirth = employee.DateOfBirthGr.ToFarsi(); - var dateOfIssue = employee.DateOfIssueGr.ToFarsi(); - var leftDate = employee.LeftWorkDateGr?.AddDays(-1) ?? new DateTime(); - - bool isManager = employee.JobId is 10 or 16 or 17 or 18 or 3498; - - //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ - bool hasWorkshopOverTimeOrFamilyAllowance = - workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; - - //آیا پرسنل فیش حقوق دارد - //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد - // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود - bool employeeHasCheckout = true; - double familyAllowance = 0; - double overTimePay = 0; - if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employee.LeftWorkDateGr == null)) - { - var checkout = _checkoutRepository.HasCheckout(workshopId, employee.EmployeeId, - searchModel.Year, searchModel.Month); - if (checkout.hasChekout) - { - - familyAllowance = checkout.FamilyAlloance; - overTimePay = checkout.OverTimePay; - - } - else - { - employeeHasCheckout = isManager == false ? false : true; - } - } - - - - var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employee.StartWorkDateGr, leftDate, startDateGr, endDateGr, employee.EmployeeId); - var leftWorkFa = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr.ToFarsi() : ""; - var startWorkFa = employee.StartWorkDateGr.ToFarsi(); - //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر - - double dailyWage = 0; - if (searchModel.FixedSalary) - { - var res = GetDailyWageFixedSalary(searchModel.Year, workshopId, employee.EmployeeId, startDateGr, - endDateGr, employee.JobId, searchModel.Population, searchModel.InsuranceJobId); - dailyWage = res ?? 0; - - } - else - { - var res = ComputeDailyWage(yearlysaleries.DayliWage, employee.EmployeeId, workshopId, searchModel.Year); - dailyWage = res; - } - - - //بدست آوردن پایه سنوات - var baseYears = _insuranceListRepositpry.GetEmployeeInsuranceBaseYear(employee.EmployeeId, workshopId, - workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); - //آیا کارفرما یا مدیر عامل است؟ - - baseYears.baseYear = isManager ? 0 : baseYears.baseYear; - Console.WriteLine(employee.JobId + " - " + baseYears.baseYear); - //جمع مزد روزانه و پایه سنوات - var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; - - - //دستمزد ماهانه با محاسبه پایه سنوات - var monthlySalary = GetRoundValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); - - //حق تاهل - var marriedAllowance = employee.MaritalStatus == "متاهل" && !isManager ? yearlysaleries.MarriedAllowance : 0; - - //محاسبه مزایای ماهانه - var monthlyBenefits = GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowance, workingDays.countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, employee.JobId, employee.EmployeeId, employee.IncludeStatus); - - //if (employee.EmployeeId is 7999)// سید عباس خوشکلام سلیمان - // monthlyBenefits = 80869389; - //if (employee.EmployeeId is 43787)// شهرام براهیمی سیقلان - // monthlyBenefits = 54748472; - if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && !isManager) - { - - monthlyBenefits = GetRoundValue(monthlyBenefits += overTimePay); - } - - //سرای ملک - // نوشین خالی - // 39692467 - //if (employee.EmployeeId == 45280) - // monthlyBenefits += 39692467; - - var marriedAllowanceCompute = MarriedAllowance(employee.MaritalStatus, employee.JobId, employee.IncludeStatus, - workingDays.countWorkingDays, yearlysaleries.MarriedAllowance, endOfMonth); - //محاسبه جمع مزایای مشمول و دستمزد ماهانه - var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; - - //benefitsIncludedContinuous = employee.JobId != 16 ? benefitsIncludedContinuous : 0; - //محاسبه حق بیمه سهم بیمه شده - var insuranceShare = (benefitsIncludedContinuous * 7) / 100; - - //محاسبه حق بیمه سهم کارفرما - var employerShare = (benefitsIncludedContinuous * 20) / 100; - - // محاسبه بیمه بیکاری - var unEmploymentInsurance = (benefitsIncludedContinuous * 3) / 100; - - - var employeeListData = employeeInsurancDataPreviusList - .FirstOrDefault(e => e.EmployeeId == employee.EmployeeId); - //مزیای عیر مشمول لیست قبل - var benefitsIncludedNonContinuous = - employeeListData?.BenefitsIncludedNonContinuous ?? 0; - if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && !isManager) - { - - benefitsIncludedNonContinuous = GetRoundValue(benefitsIncludedNonContinuous + familyAllowance); - } + //private readonly ITransactionManager _transactionManager; + private readonly IInsuranceListRepository _insuranceListRepositpry; + private readonly IEmployeeInsurancListDataRepository _employeeInsurancListDataRepository; + private readonly IInsuranceEmployeeInfoRepository _insuranceEmployeeInfoRepository; + private readonly IEmployeeRepository _employeeRepository; + private readonly IWorkshopRepository _workShopRepository; + private readonly ILeftWorkInsuranceApplication _leftWorkInsuranceApplication; + private readonly IInsuranceEmployeeInfoApplication _insuranceEmployeeInfoApplication; + private readonly IEmployeeInsurancListDataApplication _employeeInsurancListDataApplication; + private readonly IYearlySalaryApplication _yearlySalaryApplication; + private readonly IYearlySalaryItemApplication _yearlySalaryItemApplication; + private readonly IInsuranceWorkshopInfoRepository _insuranceWorkshopInfoRepository; + private readonly IInsuranceJobItemRepositpry _insuranceJobItemRepository; + private readonly IDateSalaryRepository _dateSalaryRepository; + private readonly IDateSalaryItemRepository _dateSalaryItemRepository; + private readonly IPersonalContractingPartyApp _contractingPartyApp; + private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository; + private readonly IInsuranceYearlySalaryApplication _insuranceYearlySalaryApplication; + private readonly ICheckoutRepository _checkoutRepository; + private readonly IMediaRepository _mediaRepository; + public InsuranceListApplication(IInsuranceListRepository insuranceListRepositpry, IEmployeeInsurancListDataRepository employeeInsurancListDataRepository, IInsuranceEmployeeInfoRepository insuranceEmployeeInfoRepository, IEmployeeRepository employeeRepository, IWorkshopRepository workShopRepository, ILeftWorkInsuranceApplication leftWorkInsuranceApplication, IInsuranceEmployeeInfoApplication insuranceEmployeeInfoApplication, IEmployeeInsurancListDataApplication employeeInsurancListDataApplication, IYearlySalaryApplication yearlySalaryApplication, IYearlySalaryItemApplication yearlySalaryItemApplication, IInsuranceWorkshopInfoRepository insuranceWorkshopInfoRepository, IInsuranceJobItemRepositpry insuranceJobItemRepository, IDateSalaryRepository dateSalaryRepository, IDateSalaryItemRepository dateSalaryItemRepository, IPersonalContractingPartyApp contractingPartyApp, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IInsuranceYearlySalaryApplication insuranceYearlySalaryApplication, ICheckoutRepository checkoutRepository, IMediaRepository mediaRepository) + { + // _transactionManager = transactionManager; + + _insuranceListRepositpry = insuranceListRepositpry; + _employeeInsurancListDataRepository = employeeInsurancListDataRepository; + _insuranceEmployeeInfoRepository = insuranceEmployeeInfoRepository; + _employeeRepository = employeeRepository; + _workShopRepository = workShopRepository; + _leftWorkInsuranceApplication = leftWorkInsuranceApplication; + _insuranceEmployeeInfoApplication = insuranceEmployeeInfoApplication; + _employeeInsurancListDataApplication = employeeInsurancListDataApplication; + _yearlySalaryApplication = yearlySalaryApplication; + _yearlySalaryItemApplication = yearlySalaryItemApplication; + _insuranceWorkshopInfoRepository = insuranceWorkshopInfoRepository; + _insuranceJobItemRepository = insuranceJobItemRepository; + _dateSalaryRepository = dateSalaryRepository; + _dateSalaryItemRepository = dateSalaryItemRepository; + _contractingPartyApp = contractingPartyApp; + _leftWorkInsuranceRepository = leftWorkInsuranceRepository; + _insuranceYearlySalaryApplication = insuranceYearlySalaryApplication; + _checkoutRepository = checkoutRepository; + _mediaRepository = mediaRepository; + } + + public OperationResult Create(CreateInsuranceList command) + { + + var operation = new OperationResult(); + if (command.WorkshopId == 0) + { + return operation.Failed(" انتخاب کارگاه اجباری می باشد "); + } + if (command.Month == "0") + { + return operation.Failed(" انتخاب ماه اجباری می باشد "); + } + if (command.Year == "0") + { + return operation.Failed("انتخاب سال اجباری می باشد "); + } + else if (_insuranceListRepositpry.Exists(x => + x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) + { + return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); + } + else + { + #region EmployeeDetailsForInsurance + if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) + { + foreach (var item in command.EmployeeDetailsForInsuranceList) + { + if (item.InsuranceEmployeeInformationId == 0) + { + var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); + + createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; + createInsuranceEmployeeInfo.FName = item.FName; + createInsuranceEmployeeInfo.LName = item.LName; + createInsuranceEmployeeInfo.FatherName = item.FatherName; + createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; + createInsuranceEmployeeInfo.NationalCode = item.NationalCode; + createInsuranceEmployeeInfo.IdNumber = item.IdNumber; + createInsuranceEmployeeInfo.Gender = item.Gender; + createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; + createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); + createInsuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); + _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); + } + else + { + + var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); + insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; + insuranceEmployeeInfo.EmployeeId = item.EmployeeId; + insuranceEmployeeInfo.FName = item.FName; + insuranceEmployeeInfo.LName = item.LName; + insuranceEmployeeInfo.FatherName = item.FatherName; + insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; + insuranceEmployeeInfo.NationalCode = item.NationalCode; + insuranceEmployeeInfo.IdNumber = item.IdNumber; + insuranceEmployeeInfo.Gender = item.Gender; + insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; + insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); + insuranceEmployeeInfo.DateOfIssueGr = item.DateOfIssue.ToGeorgianDateTime(); + _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); + + } + } + } + else + { + return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); + } + #endregion + + string startMonthCurrent = command.Year + "/" + command.Month + "/01"; + string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + command.StartDate = startMonthCurrent.ToGeorgianDateTime(); + command.EndDate = endMonthCurrent.ToGeorgianDateTime(); + + #region InsuranceList + + operation = _insuranceListRepositpry.CreateInsuranceList(command); + + #endregion + + return operation; + } + } + + public OperationResult Edit(EditInsuranceList command) + { + + var operation = new OperationResult(); + if (command.WorkshopId == 0) + { + return operation.Failed(" انتخاب کارگاه اجباری می باشد "); + } + if (command.Month == "0") + { + return operation.Failed(" انتخاب ماه اجباری می باشد "); + } + if (command.Year == "0") + { + return operation.Failed("انتخاب سال اجباری می باشد "); + } + else if (_insuranceListRepositpry.Exists(x => x.id != command.Id && x.WorkshopId == command.WorkshopId && x.Month == command.Month && x.Year == command.Year)) + { + return operation.Failed(" لیست بیمه برای کارگاه، سال و ماه انتخاب شده قبلا ایجاد شده است "); + } + else + { + + #region EmployeeDetailsForInsurance + if (command.EmployeeDetailsForInsuranceList != null && command.EmployeeDetailsForInsuranceList.Count > 0) + { + foreach (var item in command.EmployeeDetailsForInsuranceList) + { + if (item.InsuranceEmployeeInformationId == 0) + { + var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); + + createInsuranceEmployeeInfo.EmployeeId = item.EmployeeId; + createInsuranceEmployeeInfo.FName = item.FName; + createInsuranceEmployeeInfo.LName = item.LName; + createInsuranceEmployeeInfo.FatherName = item.FatherName; + createInsuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; + createInsuranceEmployeeInfo.NationalCode = item.NationalCode; + createInsuranceEmployeeInfo.IdNumber = item.IdNumber; + createInsuranceEmployeeInfo.Gender = item.Gender; + createInsuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; + createInsuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); + createInsuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); + _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); + } + else + { + + var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); + insuranceEmployeeInfo.Id = item.InsuranceEmployeeInformationId; + insuranceEmployeeInfo.EmployeeId = item.EmployeeId; + insuranceEmployeeInfo.FName = item.FName; + insuranceEmployeeInfo.LName = item.LName; + insuranceEmployeeInfo.FatherName = item.FatherName; + insuranceEmployeeInfo.PlaceOfIssue = item.PlaceOfIssue; + insuranceEmployeeInfo.NationalCode = item.NationalCode; + insuranceEmployeeInfo.IdNumber = item.IdNumber; + insuranceEmployeeInfo.Gender = item.Gender; + insuranceEmployeeInfo.InsuranceCode = item.InsuranceCode; + insuranceEmployeeInfo.DateOfBirthGr = item.DateOfBirth.ToGeorgianDateTime(); + insuranceEmployeeInfo.DateOfIssueGr = !string.IsNullOrEmpty(item.DateOfIssue) ? item.DateOfIssue.ToGeorgianDateTime() : "1300/10/11".ToGeorgianDateTime(); ; + _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); + + } + } + } + else + { + return operation.Failed(" لیست پرسنل در کارگاه و تاریخ انتخاب شده خالی است "); + } + #endregion + + string startMonthCurrent = command.Year + "/" + command.Month + "/01"; + string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + command.StartDate = startMonthCurrent.ToGeorgianDateTime(); + command.EndDate = endMonthCurrent.ToGeorgianDateTime(); + + #region InsuranceList + + operation = _insuranceListRepositpry.EditInsuranceList(command); + + + #endregion + + if (command.InsuranceWorkshopInfo != null) + { + var insuranceWorkshopInfoObj = + _insuranceWorkshopInfoRepository.Get(command.InsuranceWorkshopInfo.InsuranceWorkshopInfoId); + insuranceWorkshopInfoObj.Edit(command.InsuranceWorkshopInfo.WorkshopName, + command.InsuranceWorkshopInfo.InsuranceCode, command.InsuranceWorkshopInfo.AgreementNumber, + command.InsuranceWorkshopInfo.EmployerName, command.InsuranceWorkshopInfo.Address, command.InsuranceWorkshopInfo.ListNumber); + _insuranceWorkshopInfoRepository.SaveChanges(); + + } + + return operation; + } + + } + + public EditInsuranceList GetDetails(long id) + { + var insuranceListDetails = _insuranceListRepositpry.GetDetails(id); + string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; + string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + var year = Convert.ToInt32(insuranceListDetails.Year); + var month = Convert.ToInt32(insuranceListDetails.Month); + var day = 1; + var persianCurrentStartDate = new PersianDateTime(year, month, day); + var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); + + + var model = new YearlySalarySearchModel(); + model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); + model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); + model.year = insuranceListDetails.Year; + var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); + var yearlysalaryItem = new YearlysalaryItemViewModel(); + var housingAllowance = new YearlysalaryItemViewModel(); + var consumableItems = new YearlysalaryItemViewModel(); + if (yearSalaryObj != null) + { + yearlysalaryItem = _yearlySalaryItemApplication + .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "مزد روزانه"); + housingAllowance = _yearlySalaryItemApplication + .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه مسکن"); + consumableItems = _yearlySalaryItemApplication + .GetItemsByYearlySalaryId(yearSalaryObj.Id).FirstOrDefault(x => x.ItemName == "کمک هزینه اقلام"); + } + + foreach (var item in insuranceListDetails.EmployeeDetailsForInsuranceList) + { + + item.IncludeStatus = _leftWorkInsuranceApplication.GetLeftPersonelByWorkshopIdAndEmployeeId(insuranceListDetails.WorkshopId, item.EmployeeId).IncludeStatus; + if (!string.IsNullOrEmpty(item.LeftWorkDate)) + { + var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); + var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); + var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); + + var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); + if (persianLeftDateUser <= persianCurrentEndDate) + item.HasLeftWorkInMonth = true; + else + item.HasLeftWorkInMonth = false; + } + else + { + item.HasLeftWorkInMonth = false; + } + var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); + var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); + var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); + var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); + if (persianStartDateUser < persianCurrentStartDate) + item.HasStartWorkInMonth = false; + else + item.HasStartWorkInMonth = true; + item.StartMonthCurrent = startMonthCurrent; + item.DailyWageStr = item.DailyWage.ToMoney(); + + item.HousingAllowance = housingAllowance.ItemValue; + item.ConsumableItems = consumableItems.ItemValue; + item.EndMonthCurrentDay = dayMonthCurrent; + } + insuranceListDetails.EmployeeDetailsForInsuranceList = insuranceListDetails.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) + .ThenBy(x => x.LName).ToList(); + + insuranceListDetails.AllInsuredShare = insuranceListDetails.InsuredShare + + insuranceListDetails.EmployerShare + + insuranceListDetails.UnEmploymentInsurance; + + insuranceListDetails.LeftWorkEmployees = + _leftWorkInsuranceRepository.GetEmployeesWithContractExitOnly(insuranceListDetails.WorkshopId); + + return insuranceListDetails; + } + + public List Search(InsuranceListSearchModel searchModel) + { + return _insuranceListRepositpry.OptimizedSearch(searchModel); + //var result = _insuranceListRepositpry.Search(searchModel); + //result = result.Select(x => new InsuranceListViewModel() + //{ + // Id = x.Id, + // Year = x.Year, + // Month = x.Month.GetMonthByNumber(), + // MonthNumber = x.MonthNumber, + // WorkShopCode = x.WorkShopCode, + // WorkShopName = x.WorkShopName, + // WorkShopId = x.WorkShopId, + // TypeOfInsuranceSend = x.TypeOfInsuranceSend, + // FixedSalary = x.FixedSalary, + // StrFixedSalary = x.StrFixedSalary, + // EmployerName = x.EmployerName, + // Branch = x.Branch, + // City = x.City, + // ConfirmSentlist = x.ConfirmSentlist, + // EmployerId = x.EmployerId, + // IsBlockCantracingParty = _contractingPartyApp.IsBlockByEmployerId(x.EmployerId), + + //}).ToList(); + //return result; + } + + /// + /// محاسبه جدول پرسنل در مودال ایجاد لیست بیمه + /// + /// + /// + public MainEmployeeDetailsViewModel SearchEmployeeForCreateInsuranceList(EmployeeForCreateInsuranceListSearchModel searchModel) + { + var watch = new Stopwatch(); + + var result = new MainEmployeeDetailsViewModel(); + var workshopId = searchModel.WorkshopIds.FirstOrDefault(); + var workshop = _workShopRepository.GetDetails(workshopId); + //var isBolock = _contractingPartyApp.IsBlockByEmployerId(employerId); + var isBolock = _contractingPartyApp.IsBlockCheckByWorkshopId(workshopId); + double monthlybaseYear = 0; + // اگر در این سال و ماه برای این کارگاه لیست بیمه ایجاد نشده بود + if (!_insuranceListRepositpry.Exists(x => + x.Year == searchModel.Year && x.Month == searchModel.Month && + searchModel.WorkshopIds.Contains(x.WorkshopId))) + { + + var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; + DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); + DateTime endDateGr = startMonthFa.FindeEndOfMonth() + .ToGeorgianDateTime(); + int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); + + + //مقادیر سالانه این تاریخ + var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); + + + // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان + var employeesInfoAndLeftWorks = + _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, + endDateGr); + + var employeeInsurancDataPreviusList = + _insuranceListRepositpry.GetEmployeeInsuranceDataAmonthAgo(startDateGr, workshopId); + watch.Start(); + var computeResult = employeesInfoAndLeftWorks.Select(employee => + { + var dateOfBirth = employee.DateOfBirthGr.ToFarsi(); + var dateOfIssue = employee.DateOfIssueGr.ToFarsi(); + var leftDate = employee.LeftWorkDateGr != null ? employee.LeftWorkDateGr.Value.AddDays(-1) : new DateTime(); + + bool isManager = employee.JobId is 10 or 16 or 17 or 18 or 3498; + + //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ + bool hasWorkshopOverTimeOrFamilyAllowance = + workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; + + //آیا پرسنل فیش حقوق دارد + //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد + // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود + bool employeeHasCheckout = true; + double familyAllowance = 0; + double overTimePay = 0; + if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employee.LeftWorkDateGr == null)) + { + var checkout = _checkoutRepository.HasCheckout(workshopId, employee.EmployeeId, + searchModel.Year, searchModel.Month); + if (checkout.hasChekout) + { + + familyAllowance = checkout.FamilyAlloance; + overTimePay = checkout.OverTimePay; + + } + else + { + employeeHasCheckout = isManager == false ? false : true; + } + } + + + + var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employee.StartWorkDateGr, leftDate, startDateGr, endDateGr, employee.EmployeeId); + var leftWorkFa = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr.ToFarsi() : ""; + var startWorkFa = employee.StartWorkDateGr.ToFarsi(); + //به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر + + double dailyWage = 0; + if (searchModel.FixedSalary) + { + var res = GetDailyWageFixedSalary(searchModel.Year, workshopId, employee.EmployeeId, startDateGr, + endDateGr, employee.JobId, searchModel.Population, searchModel.InsuranceJobId); + dailyWage = res ?? 0; + + } + else + { + var res = ComputeDailyWage(yearlysaleries.DayliWage, employee.EmployeeId, workshopId, searchModel.Year); + dailyWage = res; + } + + + //بدست آوردن پایه سنوات + var baseYears = _insuranceListRepositpry.GetEmployeeInsuranceBaseYear(employee.EmployeeId, workshopId, + workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); + //آیا کارفرما یا مدیر عامل است؟ + + baseYears.baseYear = isManager ? 0 : baseYears.baseYear; + Console.WriteLine(employee.JobId + " - " + baseYears.baseYear); + //جمع مزد روزانه و پایه سنوات + var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; + + + //دستمزد ماهانه با محاسبه پایه سنوات + var monthlySalary = GetRoundValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); + + //حق تاهل + var marriedAllowance = employee.MaritalStatus == "متاهل" && !isManager ? yearlysaleries.MarriedAllowance : 0; + + //محاسبه مزایای ماهانه + var monthlyBenefits = GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowance, workingDays.countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, employee.JobId, employee.EmployeeId, employee.IncludeStatus); + + //if (employee.EmployeeId is 7999)// سید عباس خوشکلام سلیمان + // monthlyBenefits = 80869389; + //if (employee.EmployeeId is 43787)// شهرام براهیمی سیقلان + // monthlyBenefits = 54748472; + if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && !isManager) + { + + monthlyBenefits = GetRoundValue(monthlyBenefits += overTimePay); + } + + var marriedAllowanceCompute = MarriedAllowance(employee.MaritalStatus, employee.JobId, employee.IncludeStatus, + workingDays.countWorkingDays, yearlysaleries.MarriedAllowance, endOfMonth); + //محاسبه جمع مزایای مشمول و دستمزد ماهانه + var benefitsIncludedContinuous = monthlyBenefits + monthlySalary; + + //benefitsIncludedContinuous = employee.JobId != 16 ? benefitsIncludedContinuous : 0; + //محاسبه حق بیمه سهم بیمه شده + var insuranceShare = (benefitsIncludedContinuous * 7) / 100; + + //محاسبه حق بیمه سهم کارفرما + var employerShare = (benefitsIncludedContinuous * 20) / 100; + + // محاسبه بیمه بیکاری + var unEmploymentInsurance = (benefitsIncludedContinuous * 3) / 100; + + + var employeeListData = employeeInsurancDataPreviusList + .FirstOrDefault(e => e.EmployeeId == employee.EmployeeId); + //مزیای عیر مشمول لیست قبل + var benefitsIncludedNonContinuous = + employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; + if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && !isManager) + { + + benefitsIncludedNonContinuous = GetRoundValue(benefitsIncludedNonContinuous + familyAllowance); + } + + + + var includedAndNotIncluded = benefitsIncludedContinuous + benefitsIncludedNonContinuous; + + return new EmployeeDetailsForInsuranceListViewModel + { + #region EmployeeInfo + EmployeeHasCheckout = employeeHasCheckout, + InsuranceEmployeeInformationId = employee.InsuranceEmployeeInformationId, + EmployeeId = employee.EmployeeId, + FName = employee.FName, + LName = employee.LName, + FatherName = employee.FatherName, + DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, + DateOfIssue = dateOfIssue, + DateOfBirthGr = employee.DateOfBirthGr, + DateOfIssueGr = employee.DateOfIssueGr, + PlaceOfIssue = employee.PlaceOfIssue, + IdNumber = employee.IdNumber, + Gender = employee.Gender, + NationalCode = employee.NationalCode, + Nationality = employee.Nationality, + InsuranceCode = employee.InsuranceCode, + // آیا وضعیت تاهل پرسنل ست شده است + IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employee.MaritalStatus), + MaritalStatus = employee.MaritalStatus, + StartMonthCurrent = startMonthFa, + WorkingDays = workingDays.countWorkingDays, + StartWorkDate = startWorkFa, + StartWorkDateGr = employee.StartWorkDateGr, + LeftWorkDate = leftWorkFa, + LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr : null, + JobId = employee.JobId, + JobName = employee.JobName, + JobCode = employee.JobCode, - var includedAndNotIncluded = benefitsIncludedContinuous + benefitsIncludedNonContinuous; + HasStartWorkInMonth = workingDays.hasStartWorkInMonth, + HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, + #endregion + #region Compute + //مشمول مزایا بودن + IncludeStatus = employee.IncludeStatus, - return new EmployeeDetailsForInsuranceListViewModel - { - #region EmployeeInfo - EmployeeHasCheckout = employeeHasCheckout, - InsuranceEmployeeInformationId = employee.InsuranceEmployeeInformationId, - EmployeeId = employee.EmployeeId, - FName = employee.FName, - LName = employee.LName, - FatherName = employee.FatherName, - DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, - DateOfIssue = dateOfIssue, - DateOfBirthGr = employee.DateOfBirthGr, - DateOfIssueGr = employee.DateOfIssueGr, - PlaceOfIssue = employee.PlaceOfIssue, - IdNumber = employee.IdNumber, - Gender = employee.Gender, - NationalCode = employee.NationalCode, - Nationality = employee.Nationality, - InsuranceCode = employee.InsuranceCode, - // آیا وضعیت تاهل پرسنل ست شده است - IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employee.MaritalStatus), - MaritalStatus = employee.MaritalStatus, + //دستمزد روزانه + DailyWage = GetRoundValue(dailyWage), + DailyWageStr = dailyWage.ToMoney(), - StartMonthCurrent = startMonthFa, - WorkingDays = workingDays.countWorkingDays, - StartWorkDate = startWorkFa, - StartWorkDateGr = employee.StartWorkDateGr, - LeftWorkDate = leftWorkFa, - LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employee.LeftWorkDateGr : null, - JobId = employee.JobId, - JobName = employee.JobName, - JobCode = employee.JobCode, + HasConfilictJobs = dailyWage == 0, - HasStartWorkInMonth = workingDays.hasStartWorkInMonth, - HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, - #endregion - - #region Compute - //مشمول مزایا بودن - IncludeStatus = employee.IncludeStatus, - - //دستمزد روزانه - DailyWage = GetRoundValue(dailyWage), - DailyWageStr = dailyWage.ToMoney(), - - HasConfilictJobs = dailyWage == 0, - - //پایه سنوات - BaseYears = baseYears.baseYear, - - //مجموع مزد روزانه و پایه سنوات - DailyWagePlusBaseYears = dailyWagePlusBaseYears, - - //حق تاهل - MarriedAllowance = marriedAllowanceCompute, - - //دستمزد ماهانه - MonthlySalary = monthlySalary, - - - //مزایای ماهانه - MonthlyBenefits = monthlyBenefits, - - //جمع مزایای مشمول و دستمزد ماهانه - BenefitsIncludedContinuous = benefitsIncludedContinuous, - - //مزایای غیر مشمول * - BenefitsIncludedNonContinuous = benefitsIncludedNonContinuous, - - // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول * - IncludedAndNotIncluded = includedAndNotIncluded, - - //حق بیمه سهم بیمه شده - InsuranceShare = GetRoundValue(insuranceShare), - - //حق بیمه سهم کارفرما - EmployerShare = GetRoundValue(employerShare), - - //بیمه بیکاری - UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), - - //کمک هزینه مسکن - HousingAllowance = yearlysaleries.HousingAllowance, - //کمک هزینه اقلام - ConsumableItems = yearlysaleries.ConsumableItems, - - EndMonthCurrentDay = endOfMonth, - YearlySalaryItem = yearlysaleries.DayliWage, - MonthlyBaseYearsStr = "0", - MonthlyBaseYears = 0, - OverTimePay = overTimePay, - FamilyAllowance = familyAllowance - #endregion - - - }; - }).ToList(); - Console.WriteLine("New Compute : " + watch.Elapsed); - watch.Stop(); - - watch.Start(); - - #region Old_heydari - //List list = new List(); - //var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); - ////int leftWorkInsuranceCount= leftWorkInsuranceViewModelList.Count(); - - //string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; - //string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - - //var model = new YearlySalarySearchModel(); - //var startDate = startMonthCurrent.ToGeorgianDateTime(); - //var endDate = endMonthCurrent.ToGeorgianDateTime(); - //model.StartDateGr = startDate; - //model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); - //model.year = searchModel.Year; - - - - - - //foreach (var item in leftWorkInsuranceViewModel) - //{ - // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); - - // var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); - // employeeDetailsForInsuranceObj.HasConfilictJobs = false; - - // // آیا وضعیت تاهل پرسنل ست شده است - // employeeDetailsForInsuranceObj.IsMaritalStatusSet = - // !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); - // //دزیافت اطلاعات هویتی پرسنل - // //در صورت نداشن دیتا از جدول پرسنل پر می شود - // #region PersonnelInfo - - // if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) - // { - // var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); - // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; - // employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; - // employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; - // employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; - // employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; - // employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; - // employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; - // employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; - // employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; - // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; - // employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; - // employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; - - // //از جدول پرسنل پر می شود - // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; //employeeInfoObject.NationalCode; - // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; - // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; - // } - // else - // { - // // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); - // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; - // //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; - // employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; - // employeeDetailsForInsuranceObj.FName = employeeObject.FName; - // employeeDetailsForInsuranceObj.LName = employeeObject.LName; - // employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; - // employeeDetailsForInsuranceObj.DateOfBirth = (employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth); - // employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; - // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; - // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; - // employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; - // employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; - // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; - // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; - // } - // #endregion - - // //روزهای کارکرد پرسنل - // #region ComputingWorkingDays - - // int startWork = 0; - // int endWork = 0; - - // var year = Convert.ToInt32(searchModel.Year); - // var month = Convert.ToInt32(searchModel.Month); - // var day = 1; - // var persianCurrentStartDate = new PersianDateTime(year, month, day); - // var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - // var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); - // //آخرین روز ماه جاری - // var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - - // var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); - // var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); - // var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); - // var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); - - // if (persianStartDateUser < persianCurrentStartDate) - // employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; - // else - // employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; - - // //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد - // if (persianStartDateUser <= persianCurrentStartDate) - // { - // startWork = 1; - // } - // else - // { - // startWork = dayStartDateUser; - // } - - // if (!string.IsNullOrEmpty(item.LeftWorkDate)) - // { - // var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); - // var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); - // var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); - // var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); - // var persianEndDateUser = persianLeftDateUser.AddDays(-1); - // var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); - - // //if (persianLeftDateUser <= persianCurrentEndDate) - // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; - // //else - // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - - // //ترک کارش در ماه و سال جاری بود نمایش داده شود - // if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) - // { - // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - // item.LeftWorkDate = string.Empty; - // item.LeftWorkDateGr = null; - // } - // else - // { - // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; - // } - - // //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد - // if (persianEndDateUser >= persianCurrentEndDate) - // { - // endWork = endMonthCurrentDay; - // } - // else - // { - // endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); - // } - // } - // else - // { - // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - // endWork = endMonthCurrentDay; - // } - - // int countWorkingDays = 0; - // for (int i = startWork; i <= endWork; i++) - // { - // countWorkingDays = countWorkingDays + 1; - // } - // //farokhiChanges - // //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد - // switch (item.EmployeeId) - // { - - // //case 3812://ثابت- کسری حاجی پور - // // countWorkingDays = 15; - // // break; - // case 40463://ثابت - // countWorkingDays = 10; - // break; - // case 40469://ثابت - // countWorkingDays = 7; - // break; - // case 9950://ثابت - // countWorkingDays = 15; - // break; - // case 9640://ثابت - // countWorkingDays = 15; - // break; - // case 40998://ثابت - // countWorkingDays = 15; - // break; - // case 6219://ثابت - // countWorkingDays = 15; - // break; - // //case 7897://ثابت - // // countWorkingDays = 15; - // break; - // } - // #endregion - - // employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; - - - // #region InsuranceJob - // double dailyWage = employeeDetailsForInsuranceObj.DailyWage; - // if (searchModel.FixedSalary) - // { - // dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, workshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); - // employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); - // } - // #endregion - - // if (yearlysaleries != null) - // { - // if (!searchModel.FixedSalary) - // { - // //dailyWage= yearlysalaryItem.ItemValue; - // dailyWage = ComputeDailyWage(yearlysaleries.DayliWage, item.EmployeeId, workshopId, searchModel.Year); - // //(double basic, int totalYears) basicResult = BasicYear(item.EmployeeId, workshopId, startDate); - // //var basic = basicResult.basic; - - // //if (basicResult.totalYears > 0) - // //{ - // // monthlybaseYear = GetMonthlyBaseYear(basicResult.basic, countWorkingDays); - // //} - // } - // employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); - // employeeDetailsForInsuranceObj.BaseYears = 0; - - // employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); - // employeeDetailsForInsuranceObj.DailyWagePlusBaseYears = 0; - // employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); - // employeeDetailsForInsuranceObj.HousingAllowance = yearlysaleries.HousingAllowance; - // employeeDetailsForInsuranceObj.ConsumableItems = yearlysaleries.ConsumableItems; - // employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; - // employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysaleries.DayliWage; - // employeeDetailsForInsuranceObj.MonthlyBaseYearsStr = monthlybaseYear.ToMoney(); - - - - // employeeDetailsForInsuranceObj.MarriedAllowance = 0; - - // if (item.IncludeStatus) - // { - // var marital = employeeObject.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; - // employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId); - // } - // else - // { - // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; - // } - - // if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت - // { - // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; - // } - // //farokhiChanges - // if (item.EmployeeId == 42783) - // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; - - // employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; - - - // //حق بیمه سهم بیمه شده - // var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; - // employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); - - // //حق بیمه سهم کارفرما - // var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; - // employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); - - - // //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت - // //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} - - - // var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; - // employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); - - // employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; - // employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; - - // } - - // employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; - // employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; - // employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; - // employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; - // employeeDetailsForInsuranceObj.JobId = item.JobId; - // employeeDetailsForInsuranceObj.JobName = item.JobName; - // employeeDetailsForInsuranceObj.JobCode = item.JobCode; - // if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) - // employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; - - // employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; - // //farokhiChanges - // if (item.EmployeeId == 42783) - // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; - - // list.Add(employeeDetailsForInsuranceObj); - //} - - //result.EmployeeDetailsForInsuranceList = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) - // .ThenBy(x => x.LName).ToList(); - - - #endregion - - result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) - .ThenBy(x => x.LName).ToList(); - Console.WriteLine("ToList compute : " + watch.Elapsed); - result.IsExist = false; - result.IsBlock = isBolock; - result.MaritalStatus = yearlysaleries.MarriedAllowance; - - } - else - { - result.IsExist = true; - result.IsBlock = isBolock; - } - - return result; - } - - public double MarriedAllowance(string maritalStatus, long jobId, bool includedStatus, - int countWorkingDays, double marriedAlowance, int endMonthCurrentDay) - { - bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; - if (isManager)//اگر مدیر عامل بود - return 0; - if (maritalStatus != "متاهل")//اگر مجرد بود - return 0; - - if (countWorkingDays == endMonthCurrentDay) - return (marriedAlowance); - - return endMonthCurrentDay switch - { - 29 => GetRoundValue((marriedAlowance / 29) * countWorkingDays), - 30 => GetRoundValue((marriedAlowance / 30) * countWorkingDays), - 31 => GetRoundValue((marriedAlowance / 31) * countWorkingDays), - _ => marriedAlowance - }; - } - - public OperationResult CreateEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) - { - var result = new OperationResult(); - - try - { - //_transactionManager.BeginTransaction(); - - var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); - createInsuranceEmployeeInfo.EmployeeId = command.EmployeeId; - createInsuranceEmployeeInfo.FName = command.FName; - createInsuranceEmployeeInfo.LName = command.LName; - createInsuranceEmployeeInfo.FatherName = command.FatherName; - createInsuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; - createInsuranceEmployeeInfo.NationalCode = command.NationalCode; - createInsuranceEmployeeInfo.IdNumber = command.IdNumber; - createInsuranceEmployeeInfo.Gender = command.Gender; - createInsuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; - createInsuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); - createInsuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); - result = _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); - - //var createEmployeeInsuranceListData = new CreateEmployeeInsurancListData(); - //createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; - //createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; - ////روزهای کارکرد پرسنل - //createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; - //// دستمزد روزانه - //createEmployeeInsuranceListData.DailyWage = command.DailyWage; - ////دستمزد ماهانه - //createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; - ////مزایای ماهانه - //createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; - ////دستمزد و مزایای ماهانه مشمول - //createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; - //// مزایای مشمول مستمر - //createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; - ////مزایای مشمول غیر مستمر - //createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; - ////سهم بیمه حق کارگر - //createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; - //// تاریخ شروع به کار - //createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); - ////تاریخ ترک کار - //if() - //createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); - //// آی دی شغل - //createEmployeeInsuranceListData.JobId = command.JobId; - //result = _employeeInsurancListDataApplication.Create(createEmployeeInsuranceListData); - - // _transactionManager.CommitTransaction(); - } - catch (Exception ex) - { - result.IsSuccedded = false; - result.Message = "ثبت اطلاعات با خطا مواجه شد"; - // _transactionManager.RollbackTransaction(); - } - - return result; - - } - - public OperationResult EditEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) - { - var result = new OperationResult(); - - try - { - //_transactionManager.BeginTransaction(); - var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); - insuranceEmployeeInfo.Id = command.InsuranceEmployeeInformationId; - insuranceEmployeeInfo.EmployeeId = command.EmployeeId; - insuranceEmployeeInfo.FName = command.FName; - insuranceEmployeeInfo.LName = command.LName; - insuranceEmployeeInfo.FatherName = command.FatherName; - insuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; - insuranceEmployeeInfo.NationalCode = command.NationalCode; - insuranceEmployeeInfo.IdNumber = command.IdNumber; - insuranceEmployeeInfo.Gender = command.Gender; - insuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; - insuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); - insuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); - result = _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); - - - // var createEmployeeInsuranceListData = new EditEmployeeInsurancListData(); - // createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; - //// createEmployeeInsuranceListData.Id = command.EmployeeInsurancListDataId; - // createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; - // //روزهای کارکرد پرسنل - // createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; - // // دستمزد روزانه - // createEmployeeInsuranceListData.DailyWage = command.DailyWage; - // //دستمزد ماهانه - // createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; - // //مزایای ماهانه - // createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; - // //دستمزد و مزایای ماهانه مشمول - // createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; - // // مزایای مشمول مستمر - // createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; - // //مزایای مشمول غیر مستمر - // createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; - // //سهم بیمه حق کارگر - // createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; - // // تاریخ شروع به کار - // createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); - // //تاریخ ترک کار - // createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); - // // آی دی شغل - // createEmployeeInsuranceListData.JobId = command.JobId; - // result = _employeeInsurancListDataApplication.Edit(createEmployeeInsuranceListData); - - // _transactionManager.CommitTransaction(); - } - catch (Exception ex) - { - result.IsSuccedded = false; - result.Message = "ثبت اطلاعات با خطا مواجه شد"; - // _transactionManager.RollbackTransaction(); - } - - return result; - - } - - public OperationResult Remove(long id) - { - return _insuranceListRepositpry.Remove(id); - } - - public EditInsuranceList GetDetailsForEdit(long id) - { - var insuranceListDetails = _insuranceListRepositpry.GetDetailsForEdit(id); - //string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; - //string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - //var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - //var year = Convert.ToInt32(insuranceListDetails.Year); - //var month = Convert.ToInt32(insuranceListDetails.Month); - //var day = 1; - //var persianCurrentStartDate = new PersianDateTime(year, month, day); - //var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); - - - //var model = new YearlySalarySearchModel(); - //model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); - //model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); - //model.year = insuranceListDetails.Year; - //var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); - //var yearlysalaryItem = new YearlysalaryItemViewModel(); - //var housingAllowance = new YearlysalaryItemViewModel(); - //var consumableItems = new YearlysalaryItemViewModel(); - //if (yearSalaryObj != null) - //{ - // yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - // .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); - // housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - // .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); - // consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - // .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); - //} - - return insuranceListDetails; - } - - public double GetRoundValue(double value) - { - string strValue = value.ToString(); - if (strValue.IndexOf('.') > -1) - { - - - string a = strValue.Substring(strValue.IndexOf('.') + 1, 1); - if (int.Parse(a) > 5) - { - return (Math.Round(value, MidpointRounding.ToPositiveInfinity)); - } - else - { - return (Math.Round(value, MidpointRounding.ToNegativeInfinity)); - } - } - - return value; - } - - //محاسبه پرسنل در جدول - DSKWOR EDIT - public MainEmployeeDetailsViewModel SearchEmployeeListForEditByInsuranceListId(EmployeeForEditInsuranceListSearchModel searchModel) - { - var mainEmployeeDetailsViewModel = new MainEmployeeDetailsViewModel(); - var mainEmployeeDetailsViewModel2 = new MainEmployeeDetailsViewModel(); - var mainEmployeeDetailsViewModelForNewPersonel = new MainEmployeeDetailsViewModel(); - - List ids = searchModel.WorkshopIds.Where(x => x != searchModel.WorkshopId).ToList(); - searchModel.Month = searchModel.Month.PadLeft(2, '0'); - if (!_insuranceListRepositpry.Exists(x => x.Year == searchModel.Year && x.Month == searchModel.Month && (ids != null && ids.Count > 0 && ids.Contains(x.WorkshopId)))) - { - - mainEmployeeDetailsViewModel = _insuranceListRepositpry.SearchEmployeeListForEditByInsuranceListId(searchModel); - - var employeeForCreateInsurance = new EmployeeForCreateInsuranceListSearchModel(); - employeeForCreateInsurance.Month = searchModel.Month; - employeeForCreateInsurance.Year = searchModel.Year; - employeeForCreateInsurance.WorkshopIds = ids; - #region OtherWorkshop - if (ids != null && ids.Count > 0)//اگر ورکشاپهای دیگر را انتخاب کرد - { - mainEmployeeDetailsViewModel2 = SearchEmployeeForCreateInsuranceList(employeeForCreateInsurance); - } - #endregion - - - #region NewPersonel - //اگر افراد جدیدی به لیست بیمه اضافه شوند. - var searchModelForCreate = new EmployeeForCreateInsuranceListSearchModel(); - searchModelForCreate.Month = searchModel.Month; - searchModelForCreate.Year = searchModel.Year; - searchModelForCreate.WorkshopIds = new List() { searchModel.WorkshopId }; - var leftWorkInsuranceViewModelList = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModelForCreate); - var newEmployeeId = leftWorkInsuranceViewModelList.Select(x => x.EmployeeId).ToList(); - var oldEmployeeId = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Select(x => x.EmployeeId).ToList(); - if (!newEmployeeId.SequenceEqual(oldEmployeeId)) - { - var employeeAddIds = new List(); - var employeeRemoveIds = new List(); - //var employeeAddIds = newEmployeeId.Except(oldEmployeeId).ToList(); - //var employeeRemoveIds = newEmployeeId.Where(x => !oldEmployeeId.Any(z => z == x)).ToList(); - foreach (var newitem in newEmployeeId) - { - if (!oldEmployeeId.Any(x => x == newitem)) - { - employeeAddIds.Add(newitem); - } - } - foreach (var olditem in oldEmployeeId) - { - if (!newEmployeeId.Any(x => x == olditem)) - { - employeeRemoveIds.Add(olditem); - } - } - - - if (employeeAddIds != null && employeeAddIds.Count > 0) - { - leftWorkInsuranceViewModelList = leftWorkInsuranceViewModelList.Where(x => employeeAddIds.Contains(x.EmployeeId)).ToList(); - mainEmployeeDetailsViewModelForNewPersonel = GetEmployeeForInsuranceList(leftWorkInsuranceViewModelList, searchModel); - if (mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList != null && - mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList.Count > 0) - { - mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList).ToList(); - } - } - if (employeeRemoveIds != null && employeeRemoveIds.Count > 0) - { - mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel - .EmployeeDetailsForInsuranceList.Where(x => !employeeRemoveIds.Contains(x.EmployeeId)) - .ToList(); - - - } - - } - #endregion - - - string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; - string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - var year = Convert.ToInt32(searchModel.Year); - var month = Convert.ToInt32(searchModel.Month); - var day = 1; - var persianCurrentStartDate = new PersianDateTime(year, month, day); - var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); - - var model = new YearlySalarySearchModel(); - model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); - model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); - model.year = searchModel.Year; - - var yearlysalaryItem = new YearlysalaryItemViewModel(); - var housingAllowance = new YearlysalaryItemViewModel(); - var consumableItems = new YearlysalaryItemViewModel(); - var maritalStatus = new YearlysalaryItemViewModel(); - foreach (var item in mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList) - { - var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); - item.HasConfilictJobs = false; - item.IncludeStatus = item.IncludeStatus; - int startWork = 0; - int endWork = 0; - item.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است - !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); - - #region HasConfilictLeftWork - - bool hasConfilict = false; - // // اگر شروع به کار و ترک کارش در جدول ترک کار تغییر کرده باشد - if (item.HasConfilictLeftWork)//item.LeftWorkDate != item.StrLeftWorkDateNew || (item.StartWorkDate != item.StrStartWorkDateNew && !string.IsNullOrEmpty(item.StrStartWorkDateNew) ) ||(item.JobId!=item.JobIdNew && item.JobIdNew!=0)) - { - if (item.LeftWorkDate != item.StrLeftWorkDateNew) - { - item.LeftWorkDate = item.StrLeftWorkDateNew; - item.LeftWorkDateGr = item.LeftWorkDateNew; - - } - - if (item.StartWorkDate != item.StrStartWorkDateNew && - !string.IsNullOrEmpty(item.StrStartWorkDateNew)) - { - item.StartWorkDate = item.StrStartWorkDateNew; - item.StartWorkDateGr = item.StartWorkDateNew; - } - - if (item.JobId != item.JobIdNew && item.JobIdNew != 0) - { - item.JobId = item.JobIdNew; - item.JobCode = item.JobCodeNew; - item.JobName = item.JobNameNew; - } - - item.IncludeStatus = item.IncludeStatusNew;//(item.IncludeStatus==item.IncludeStatusNew); - - - hasConfilict = true; - } - - #endregion - - var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); - if (yearSalaryObj != null) - { - yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); - housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); - consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); - maritalStatus = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); - item.HousingAllowance = housingAllowance.ItemValue; - item.ConsumableItems = consumableItems.ItemValue; - //item.MarriedAllowance = maritalStatus.ItemValue; - item.YearlySalaryItem = yearlysalaryItem.ItemValue; - - } - - //ترک کارش در ماه و سال جاری بود نمایش داده شود - if (!string.IsNullOrEmpty(item.LeftWorkDate) && !item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) - { - item.LeftWorkDate = string.Empty; - item.LeftWorkDateGr = null; - } - - if (!string.IsNullOrEmpty(item.LeftWorkDate)) //&& item.LeftWorkDate.Substring(5, 2)==searchModel.Month && item.LeftWorkDate.Substring(0, 4) == searchModel.Year) - { - // item.HasLeftWorkInMonth = true; - var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); - var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); - var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); - - var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); - var persianEndDateUser = persianLeftDateUser.AddDays(-1); - var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); - - if (persianLeftDateUser <= persianCurrentEndDate) - item.HasLeftWorkInMonth = true; - else - item.HasLeftWorkInMonth = false; - - //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد - if (persianEndDateUser >= persianCurrentEndDate) - { - endWork = dayMonthCurrent; - } - else - { - endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); - } - } - else - { - // item.HasLeftWorkInMonth = false; - endWork = dayMonthCurrent; - } - var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); - var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); - var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); - var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); - - if (persianStartDateUser <= persianCurrentStartDate) - { - startWork = 1; - } - else - { - startWork = dayStartDateUser; - } - - if (persianStartDateUser < persianCurrentStartDate) - item.HasStartWorkInMonth = false; - else - item.HasStartWorkInMonth = true; - - - if (hasConfilict) //اگر ترک کار شخص تغییر کرده بود، دوباره محاسبه شود - { - item.StartMonthCurrent = startMonthCurrent; - item.HousingAllowance = housingAllowance.ItemValue; - item.ConsumableItems = consumableItems.ItemValue; - item.DailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, searchModel.WorkshopId, searchModel.Year); - item.DailyWageStr = item.DailyWage.ToMoney(); - } - else - { - item.DailyWageStr = item.DailyWage.ToMoney(); - } - item.EndMonthCurrentDay = dayMonthCurrent; - if (hasConfilict || searchModel.FixedSalary || searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist") - { - #region InsuranceJob - - double dailyWage = item.DailyWage; - if (searchModel.FixedSalary) - { - dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, searchModel.WorkshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); - item.HasConfilictJobs = (dailyWage == 0 ? true : false); - } - #endregion - - if (hasConfilict) - { - int countWorkingDays = 0; - for (int i = startWork; i <= endWork; i++) - { - countWorkingDays = countWorkingDays + 1; - } - - item.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); - item.WorkingDays = countWorkingDays; - if (item.IncludeStatus) - { - var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; - item.MonthlyBenefits = GetMonthlyBenefits(dayMonthCurrent, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); - } - else - { - item.MonthlyBenefits = 0; - } - } - - if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت - { - item.MonthlyBenefits = 0; - } - - item.BenefitsIncludedContinuous = item.MonthlyBenefits + item.MonthlySalary; - - - var insuranceShare = (item.BenefitsIncludedContinuous * 7) / 100; - item.InsuranceShare = GetRoundValue(insuranceShare); - //} - - var employerShare = (item.BenefitsIncludedContinuous * 20) / 100; - item.EmployerShare = GetRoundValue(employerShare); - - var unEmploymentInsurance = (item.BenefitsIncludedContinuous * 3) / 100; - item.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); - - // item.BenefitsIncludedNonContinuous = item.BenefitsIncludedContinuous; - item.IncludedAndNotIncluded = item.BenefitsIncludedContinuous + item.BenefitsIncludedNonContinuous; - } - - } - if (mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList != null && mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList.Count > 0) - mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList).OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); - else - mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); - - mainEmployeeDetailsViewModel.IsExist = false; - mainEmployeeDetailsViewModel.MaritalStatus = maritalStatus.ItemValue; - } - else - { - mainEmployeeDetailsViewModel.IsExist = true; - } - return mainEmployeeDetailsViewModel; - } - - public MainEmployeeDetailsViewModel GetEmployeeListForEditByInsuranceListId( - EmployeeForEditInsuranceListSearchModel searchModel) - { - var result = new MainEmployeeDetailsViewModel(); - var workshopId = searchModel.WorkshopIds.FirstOrDefault(); - var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; - DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); - DateTime endDateGr = startMonthFa.FindeEndOfMonth() - .ToGeorgianDateTime(); - int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); - - //مقادیر سالانه این تاریخ - var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); - - // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان - //var employeesInfoAndLeftWorks = - // _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, - // endDateGr); - - var employeeInsurancDataPreviusList = - _insuranceListRepositpry.GetEmployeeInsuranceDataForEdit(searchModel.InsuranceId, startDateGr, endDateGr); - - var computeResult = employeeInsurancDataPreviusList.Select(employeeData => - { - var dateOfBirth = employeeData.DateOfBirthGr.ToFarsi(); - var dateOfIssue = employeeData.DateOfIssueGr.ToFarsi(); - var leftDate = employeeData.LeftWorkDateGr != null ? employeeData.LeftWorkDateGr.Value.AddDays(-1) : new DateTime(); - var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employeeData.StartWorkDateGr, leftDate, startDateGr, endDateGr, employeeData.EmployeeId); - var leftWorkFa = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr.ToFarsi() : ""; - var startWorkFa = employeeData.StartWorkDateGr.ToFarsi(); - var workshop = _workShopRepository.GetDetails(workshopId); - - //آیا کارفرما است - bool isManager = employeeData.JobId is 10 or 16 or 17 or 18 or 3498; - - //محاسبه حق بیمه سهم کارفرما - var employerShare = (employeeData.BenefitsIncludedContinuous * 20) / 100; - - // محاسبه بیمه بیکاری - var unEmploymentInsurance = (employeeData.BenefitsIncludedContinuous * 3) / 100; - - - //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ - //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد - // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود - bool hasWorkshopOverTimeOrFamilyAllowance = - workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; - - bool employeeHasCheckout = true; - bool hasOverTimePay = false; - bool hasFamilyAllowance = false; - - if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employeeData.LeftWorkDateGr == null)) - { - var checkout = _checkoutRepository.HasCheckout(workshopId, employeeData.EmployeeId, - searchModel.Year, searchModel.Month); - if (checkout.hasChekout) - { - if (checkout.OverTimePay > 0) - hasOverTimePay = true; - if (checkout.FamilyAlloance > 0) - hasFamilyAllowance = true; - - } - else - { - employeeHasCheckout = isManager == false ? false : true; - } - } - - bool familyAllowanceIsSet = true; - bool overTimePayIsSet = true; - if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && employeeData.FamilyAllowance == 0 && hasFamilyAllowance && !isManager) - { - - familyAllowanceIsSet = false; - } - - if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && employeeData.OverTimePay == 0 && hasOverTimePay && !isManager) - { - - overTimePayIsSet = false; - } - return new EmployeeDetailsForInsuranceListViewModel - { - #region EmployeeInfo - EmployeeHasCheckout = employeeHasCheckout, - EmployeeInsurancListDataId = employeeData.EmployeeInsurancListDataId, - - InsuranceEmployeeInformationId = employeeData.InsuranceEmployeeInformationId, - EmployeeId = employeeData.EmployeeId, - FName = employeeData.FName, - LName = employeeData.LName, - FatherName = employeeData.FatherName, - DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, - DateOfIssue = dateOfIssue, - DateOfBirthGr = employeeData.DateOfBirthGr, - DateOfIssueGr = employeeData.DateOfIssueGr, - PlaceOfIssue = employeeData.PlaceOfIssue, - IdNumber = employeeData.IdNumber, - Gender = employeeData.Gender, - NationalCode = employeeData.NationalCode, - Nationality = employeeData.Nationality, - InsuranceCode = employeeData.InsuranceCode, - // آیا وضعیت تاهل پرسنل ست شده است - IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employeeData.MaritalStatus), - MaritalStatus = employeeData.MaritalStatus, - - StartMonthCurrent = startMonthFa, - WorkingDays = workingDays.countWorkingDays, - StartWorkDate = startWorkFa, - StartWorkDateGr = employeeData.StartWorkDateGr, - LeftWorkDate = leftWorkFa, - LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr : null, - JobId = employeeData.JobId, - JobName = employeeData.JobName, - JobCode = employeeData.JobCode, - - HasStartWorkInMonth = workingDays.hasStartWorkInMonth, - HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, - #endregion - - #region Compute - //مشمول مزایا بودن - IncludeStatus = employeeData.IncludeStatus, - - //دستمزد روزانه - DailyWage = GetRoundValue(employeeData.DailyWage), - DailyWageStr = employeeData.DailyWage.ToMoney(), - - //HasConfilictJobs = dailyWage == 0, - - //پایه سنوات - BaseYears = employeeData.BaseYears, - - //مجموع مزد روزانه و پایه سنوات - DailyWagePlusBaseYears = employeeData.DailyWagePlusBaseYears, - - //حق تاهل - MarriedAllowance = employeeData.MarriedAllowance, - - //دستمزد ماهانه - MonthlySalary = employeeData.MonthlySalary, - - - //مزایای ماهانه - MonthlyBenefits = employeeData.MonthlyBenefits, - - //مزایای مشمول - BenefitsIncludedContinuous = employeeData.BenefitsIncludedContinuous, - - //مزایای غیر مشمول - BenefitsIncludedNonContinuous = employeeData.BenefitsIncludedNonContinuous, - - // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول - IncludedAndNotIncluded = employeeData.IncludedAndNotIncluded, - - //حق بیمه سهم بیمه شده - InsuranceShare = GetRoundValue(employeeData.InsuranceShare), - - //حق بیمه سهم کارفرما - EmployerShare = GetRoundValue(employerShare), - - //بیمه بیکاری - UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), - - //کمک هزینه مسکن - HousingAllowance = yearlysaleries.HousingAllowance, - //کمک هزینه اقلام - ConsumableItems = yearlysaleries.ConsumableItems, - - EndMonthCurrentDay = endOfMonth, - YearlySalaryItem = yearlysaleries.DayliWage, - MonthlyBaseYearsStr = "0", - MonthlyBaseYears = 0, - - OverTimeIsSet = overTimePayIsSet, - FamilyAllowanceIsSet = familyAllowanceIsSet - #endregion - - - }; - }); - - result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) - .ThenBy(x => x.LName).ToList(); - - result.IsExist = false; - result.MaritalStatus = yearlysaleries.MarriedAllowance; - - return result; - } - - public OperationResult ConfirmInsuranceList(long id) - { - OperationResult result = new OperationResult(); - - try - { - result = _insuranceListRepositpry.ConfirmInsuranceList(id); - result.Message = "تایید ارسال لیست بیمه با موفقیت انجام شد"; - } - catch (Exception) - { - result.Message = "تایید ارسال لیست بیمه با خطا انجام شد"; - } - - return result; - } - - private double? GetDailyWageFixedSalary(string year, long workshopId, long employeeId, DateTime? startDateGr, DateTime? endDateGr, long jobId, string population, long? insuranceJobId) - { - - double? result = 0; - string month = $"{startDateGr.ToFarsi()}".Substring(5, 2); - //اگر مشاغل مقطوع بود و شغلش کارفرما بود - // در جدول لیست بیمه قبلی چک شود - try - { - if (workshopId == 318 && year == "1403") - { - double percent = 0; - switch (jobId) - { - case 39: - percent = 1.75; - return 4180000; - break; - case 466: - percent = 1.6; - return 3822000; - break; - case 1192 or 398 or 8: - percent = 1.5; - return 3583000; - break; - } - - //var dateSaleryviewModel = new DateSalarySearchModel(); - //dateSaleryviewModel.StartDateGr = startDateGr; - //dateSaleryviewModel.EndDateGr = endDateGr; - //var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); - //// && _dateSalary.Id >0 - //if (_dateSalary != null) - //{ - // var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); - // dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; - // dateSaleryItemviewModel.Percent = percent; - // var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); - // if (dateSalaryItem != null) - // result = dateSalaryItem[0].Salary; - //} - } - if (jobId == 10) //کارفرما - { - InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); - var workshop = _workShopRepository.GetDetails(workshopId); - if (workshop.FixedSalary) - - { - var inJob = _insuranceJobItemRepository - .GetInsuranceJobItemByInsuranceJobId((long)workshop.InsuranceJobId, year, month); - if (workshop.Population == "MoreThan500") - { - var max = inJob.MaxBy(x => x.PercentageMoreThan); - var dateSaleryviewModel = new DateSalarySearchModel(); - dateSaleryviewModel.StartDateGr = startDateGr; - dateSaleryviewModel.EndDateGr = endDateGr; - var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); - if (_dateSalary != null) - { - var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); - dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; - dateSaleryItemviewModel.Percent = max.PercentageMoreThan; - var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); - if (dateSalaryItem != null) - result = dateSalaryItem[0].Salary; - } - } - else - { - var max = inJob.MaxBy(x => x.PercentageLessThan); - var dateSaleryviewModel = new DateSalarySearchModel(); - dateSaleryviewModel.StartDateGr = startDateGr; - dateSaleryviewModel.EndDateGr = endDateGr; - var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); - if (_dateSalary != null) - { - var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); - dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; - dateSaleryItemviewModel.Percent = max.PercentageLessThan; - var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); - if (dateSalaryItem != null) - result = dateSalaryItem[0].Salary; - } - } - - - - } - //var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); - //var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); - //if (employeeInsurancListData != null ) - //{ - // result = employeeInsurancListData.DailyWage; - //} - } - else - { - - var searchModel = new InsuranceJobItemSearchModel(); - searchModel.InsuranceJobId = (long)insuranceJobId; - var JobItem = _insuranceJobItemRepository.GetInsuranceJobItemByInsuranceJobIdForFixedSalary((long)insuranceJobId, jobId, year, month); - - if (JobItem != null && JobItem.Id != 0) - { - double percent = 0; - if (population == "MoreThan500") - percent = JobItem.PercentageMoreThan; - else if (population == "LessThan500") - percent = JobItem.PercentageLessThan; - - var dateSaleryviewModel = new DateSalarySearchModel(); - dateSaleryviewModel.StartDateGr = startDateGr; - dateSaleryviewModel.EndDateGr = endDateGr; - var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); - // && _dateSalary.Id >0 - if (_dateSalary != null) - { - var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); - dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; - dateSaleryItemviewModel.Percent = percent; - var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); - if (dateSalaryItem != null) - result = dateSalaryItem[0].Salary; - } - } - - - } - } - catch (Exception) - { - - result = 0; - } - return result; - } - - /// - /// محاسبه مزایای ماهانه مشمول - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - private double GetMonthlyBenefits(int endMonthCurrentDay, double consumableItemsItemValue, double housingAllowanceItemValue, double maritalStatus, int countWorkingDays, string typeOfInsuranceSendWorkshop, long jobId, long employeeId, bool includeStatus) - { - //ToDo - //افزودن شرط مشمول مزایای - - //اگر پرسنل کارفرما بود و نوع لیست کارگاه کمک دولت بود مزایا محاسبه نشود - //اگر تیک مشمول مزایا در ترک کار خاموش بود مزایا نگیرد - - bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; - if (isManager && !includeStatus) - return 0; - //پرسنل استثناء - if (employeeId == 42783) - return 53082855; - - - //if(employeeId == 8859) - // return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); - - //مزایای ماهانه با توجه به پایان ماه که 30 یا 31 روزه است، متفاوت می باشد - //برای ماه 29 روزه هم تقسیم بر 30 می شود. - if (countWorkingDays == endMonthCurrentDay) - return (consumableItemsItemValue + housingAllowanceItemValue + maritalStatus); - else if (endMonthCurrentDay == 29)//farokhiChanges در خط پایین عدد 30 رو به 29 تغییر دادم - return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 29) * countWorkingDays); - else if (endMonthCurrentDay == 30)//farokhiChanges این شرط و خط زیر رو اضافه کردم - return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 30) * countWorkingDays); - else if (endMonthCurrentDay == 31)//farokhiChanges این شرط و خط زیر رو اضافه کردم - return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); - else - return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / endMonthCurrentDay) * countWorkingDays); - } - - - - private double ComputeDailyWage(double yearlysalaryItemValue, long employeeId, long workshopId, string year) - { - double dailyWage = yearlysalaryItemValue; - InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); - var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); - if (insuransList != null) - { - var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); - if (employeeInsurancListData != null && employeeInsurancListData.DailyWage > dailyWage) - { - dailyWage = employeeInsurancListData.DailyWage; - } - } - - dailyWage = employeeId == 6536 ? 9399512 : dailyWage; - return dailyWage; - } - public MainEmployeeDetailsViewModel GetEmployeeForInsuranceList(List leftWorkInsuranceViewModelList, EmployeeForEditInsuranceListSearchModel searchModel) - { - var result = new MainEmployeeDetailsViewModel(); - - List list = new List(); - int leftWorkInsuranceCount = leftWorkInsuranceViewModelList.Count(); - string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; - string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); - - var model = new YearlySalarySearchModel(); - model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); - model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); - model.year = searchModel.Year; - - - - var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); - - var yearlysalaryItem = new YearlysalaryItemViewModel(); - var housingAllowance = new YearlysalaryItemViewModel(); - var consumableItems = new YearlysalaryItemViewModel(); - var maritalStatus = new YearlysalaryItemViewModel(); - if (yearSalaryObj != null) - { - yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); - housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); - consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); - maritalStatus = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) - .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); - } - - foreach (var item in leftWorkInsuranceViewModelList) - { - var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); - - var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); - employeeDetailsForInsuranceObj.HasConfilictJobs = false; - employeeDetailsForInsuranceObj.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است - !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); - if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) - { - var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); - employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; - employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; - employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; - employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; - employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; - employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; - employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; - employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; - employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; - employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; - employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; - employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; - - //از جدول پرسنل پر می شود - employeeDetailsForInsuranceObj.NationalCode = - employeeObject.NationalCode; //employeeInfoObject.NationalCode; - employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; - employeeDetailsForInsuranceObj.InsuranceCode = - employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; - } - else - { - // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); - employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; - //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; - employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; - employeeDetailsForInsuranceObj.FName = employeeObject.FName; - employeeDetailsForInsuranceObj.LName = employeeObject.LName; - employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; - employeeDetailsForInsuranceObj.DateOfBirth = employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth; - employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; - employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; - employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; - employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; - employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; - employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; - employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; - } - - #region ComputingWorkingDays - - int startWork = 0; - int endWork = 0; - - var year = Convert.ToInt32(searchModel.Year); - var month = Convert.ToInt32(searchModel.Month); - var day = 1; - var persianCurrentStartDate = new PersianDateTime(year, month, day); - var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); - //آخرین روز ماه جاری - var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); - - var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); - var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); - var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); - var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); - - if (persianStartDateUser < persianCurrentStartDate) - employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; - else - employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; - - //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد - if (persianStartDateUser <= persianCurrentStartDate) - { - startWork = 1; - } - else - { - startWork = dayStartDateUser; - } - - if (!string.IsNullOrEmpty(item.LeftWorkDate)) - { - var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); - var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); - var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); - var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); - var persianEndDateUser = persianLeftDateUser.AddDays(-1); - var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); - - //if (persianLeftDateUser <= persianCurrentEndDate) - // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; - //else - // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - - //ترک کارش در ماه و سال جاری بود نمایش داده شود - if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) - { - employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - item.LeftWorkDate = string.Empty; - item.LeftWorkDateGr = null; - } - else - { - employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; - } - - //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد - if (persianEndDateUser >= persianCurrentEndDate) - { - endWork = endMonthCurrentDay; - } - else - { - endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); - } - } - else - { - employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; - endWork = endMonthCurrentDay; - } - - int countWorkingDays = 0; - for (int i = startWork; i <= endWork; i++) - { - countWorkingDays = countWorkingDays + 1; - } - - //farokhiChanges - //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد - switch (item.EmployeeId) - { - - //case 3812://ثابت - // countWorkingDays = 15; - // break; - case 40463://ثابت - countWorkingDays = 10; - break; - case 40469://ثابت - countWorkingDays = 7; - break; - //case 9950://ثابت - // countWorkingDays = 15; - break; - case 9640://ثابت - countWorkingDays = 15; - break; - case 40998://ثابت - countWorkingDays = 15; - break; - case 6219://ثابت - countWorkingDays = 15; - break; - //case 7897://ثابت - // countWorkingDays = 15; - // break; - } + //پایه سنوات + BaseYears = baseYears.baseYear, + + //مجموع مزد روزانه و پایه سنوات + DailyWagePlusBaseYears = dailyWagePlusBaseYears, + + //حق تاهل + MarriedAllowance = marriedAllowanceCompute, + + //دستمزد ماهانه + MonthlySalary = monthlySalary, + + + //مزایای ماهانه + MonthlyBenefits = monthlyBenefits, + + //جمع مزایای مشمول و دستمزد ماهانه + BenefitsIncludedContinuous = benefitsIncludedContinuous, + + //مزایای غیر مشمول * + BenefitsIncludedNonContinuous = benefitsIncludedNonContinuous, + + // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول * + IncludedAndNotIncluded = includedAndNotIncluded, + + //حق بیمه سهم بیمه شده + InsuranceShare = GetRoundValue(insuranceShare), + + //حق بیمه سهم کارفرما + EmployerShare = GetRoundValue(employerShare), + + //بیمه بیکاری + UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), + + //کمک هزینه مسکن + HousingAllowance = yearlysaleries.HousingAllowance, + //کمک هزینه اقلام + ConsumableItems = yearlysaleries.ConsumableItems, + + EndMonthCurrentDay = endOfMonth, + YearlySalaryItem = yearlysaleries.DayliWage, + MonthlyBaseYearsStr = "0", + MonthlyBaseYears = 0, + OverTimePay = overTimePay, + FamilyAllowance = familyAllowance + #endregion + + + }; + }).ToList(); + Console.WriteLine("New Compute : " + watch.Elapsed); + watch.Stop(); + + watch.Start(); + + #region Old_heydari + //List list = new List(); + //var leftWorkInsuranceViewModel = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModel); + ////int leftWorkInsuranceCount= leftWorkInsuranceViewModelList.Count(); + + //string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + //string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + + //var model = new YearlySalarySearchModel(); + //var startDate = startMonthCurrent.ToGeorgianDateTime(); + //var endDate = endMonthCurrent.ToGeorgianDateTime(); + //model.StartDateGr = startDate; + //model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); + //model.year = searchModel.Year; + + + + + + //foreach (var item in leftWorkInsuranceViewModel) + //{ + // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); + + // var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); + // employeeDetailsForInsuranceObj.HasConfilictJobs = false; + + // // آیا وضعیت تاهل پرسنل ست شده است + // employeeDetailsForInsuranceObj.IsMaritalStatusSet = + // !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); + // //دزیافت اطلاعات هویتی پرسنل + // //در صورت نداشن دیتا از جدول پرسنل پر می شود + // #region PersonnelInfo + + // if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) + // { + // var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); + // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; + // employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; + // employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; + // employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; + // employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; + // employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; + // employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; + // employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; + // employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; + // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; + // employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; + // employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; + + // //از جدول پرسنل پر می شود + // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; //employeeInfoObject.NationalCode; + // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; + // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; + // } + // else + // { + // // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); + // employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; + // //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; + // employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; + // employeeDetailsForInsuranceObj.FName = employeeObject.FName; + // employeeDetailsForInsuranceObj.LName = employeeObject.LName; + // employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; + // employeeDetailsForInsuranceObj.DateOfBirth = (employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth); + // employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; + // employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; + // employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; + // employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; + // employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; + // employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; + // employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; + // } + // #endregion + + // //روزهای کارکرد پرسنل + // #region ComputingWorkingDays + + // int startWork = 0; + // int endWork = 0; + + // var year = Convert.ToInt32(searchModel.Year); + // var month = Convert.ToInt32(searchModel.Month); + // var day = 1; + // var persianCurrentStartDate = new PersianDateTime(year, month, day); + // var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + // var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); + // //آخرین روز ماه جاری + // var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + + // var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); + // var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); + // var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); + // var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); + + // if (persianStartDateUser < persianCurrentStartDate) + // employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; + // else + // employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; + + // //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد + // if (persianStartDateUser <= persianCurrentStartDate) + // { + // startWork = 1; + // } + // else + // { + // startWork = dayStartDateUser; + // } + + // if (!string.IsNullOrEmpty(item.LeftWorkDate)) + // { + // var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); + // var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); + // var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); + // var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); + // var persianEndDateUser = persianLeftDateUser.AddDays(-1); + // var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); + + // //if (persianLeftDateUser <= persianCurrentEndDate) + // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; + // //else + // // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + + // //ترک کارش در ماه و سال جاری بود نمایش داده شود + // if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) + // { + // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + // item.LeftWorkDate = string.Empty; + // item.LeftWorkDateGr = null; + // } + // else + // { + // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; + // } + + // //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد + // if (persianEndDateUser >= persianCurrentEndDate) + // { + // endWork = endMonthCurrentDay; + // } + // else + // { + // endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); + // } + // } + // else + // { + // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + // endWork = endMonthCurrentDay; + // } + + // int countWorkingDays = 0; + // for (int i = startWork; i <= endWork; i++) + // { + // countWorkingDays = countWorkingDays + 1; + // } + // //farokhiChanges + // //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد + // switch (item.EmployeeId) + // { + + // //case 3812://ثابت- کسری حاجی پور + // // countWorkingDays = 15; + // // break; + // case 40463://ثابت + // countWorkingDays = 10; + // break; + // case 40469://ثابت + // countWorkingDays = 7; + // break; + // case 9950://ثابت + // countWorkingDays = 15; + // break; + // case 9640://ثابت + // countWorkingDays = 15; + // break; + // case 40998://ثابت + // countWorkingDays = 15; + // break; + // case 6219://ثابت + // countWorkingDays = 15; + // break; + // //case 7897://ثابت + // // countWorkingDays = 15; + // break; + // } + // #endregion + + // employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; + + + // #region InsuranceJob + // double dailyWage = employeeDetailsForInsuranceObj.DailyWage; + // if (searchModel.FixedSalary) + // { + // dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, workshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); + // employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); + // } + // #endregion + + // if (yearlysaleries != null) + // { + // if (!searchModel.FixedSalary) + // { + // //dailyWage= yearlysalaryItem.ItemValue; + // dailyWage = ComputeDailyWage(yearlysaleries.DayliWage, item.EmployeeId, workshopId, searchModel.Year); + // //(double basic, int totalYears) basicResult = BasicYear(item.EmployeeId, workshopId, startDate); + // //var basic = basicResult.basic; + + // //if (basicResult.totalYears > 0) + // //{ + // // monthlybaseYear = GetMonthlyBaseYear(basicResult.basic, countWorkingDays); + // //} + // } + // employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); + // employeeDetailsForInsuranceObj.BaseYears = 0; + + // employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); + // employeeDetailsForInsuranceObj.DailyWagePlusBaseYears = 0; + // employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); + // employeeDetailsForInsuranceObj.HousingAllowance = yearlysaleries.HousingAllowance; + // employeeDetailsForInsuranceObj.ConsumableItems = yearlysaleries.ConsumableItems; + // employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; + // employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysaleries.DayliWage; + // employeeDetailsForInsuranceObj.MonthlyBaseYearsStr = monthlybaseYear.ToMoney(); + + + + // employeeDetailsForInsuranceObj.MarriedAllowance = 0; + + // if (item.IncludeStatus) + // { + // var marital = employeeObject.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; + // employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId); + // } + // else + // { + // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; + // } + + // if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت + // { + // employeeDetailsForInsuranceObj.MonthlyBenefits = 0; + // } + // //farokhiChanges + // if (item.EmployeeId == 42783) + // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; + + // employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; + + + // //حق بیمه سهم بیمه شده + // var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; + // employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); + + // //حق بیمه سهم کارفرما + // var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; + // employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); + + + // //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت + // //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} + + + // var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; + // employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); + + // employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; + // employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; + + // } + + // employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; + // employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; + // employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; + // employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; + // employeeDetailsForInsuranceObj.JobId = item.JobId; + // employeeDetailsForInsuranceObj.JobName = item.JobName; + // employeeDetailsForInsuranceObj.JobCode = item.JobCode; + // if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) + // employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; + + // employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; + // //farokhiChanges + // if (item.EmployeeId == 42783) + // employeeDetailsForInsuranceObj.MonthlyBenefits = 53082855; + + // list.Add(employeeDetailsForInsuranceObj); + //} + + //result.EmployeeDetailsForInsuranceList = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) + // .ThenBy(x => x.LName).ToList(); + + + #endregion + + result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) + .ThenBy(x => x.LName).ToList(); + Console.WriteLine("ToList compute : " + watch.Elapsed); + result.IsExist = false; + result.IsBlock = isBolock; + result.MaritalStatus = yearlysaleries.MarriedAllowance; + + } + else + { + result.IsExist = true; + result.IsBlock = isBolock; + } + + return result; + } + + public double MarriedAllowance(string maritalStatus, long jobId, bool includedStatus, + int countWorkingDays, double marriedAlowance, int endMonthCurrentDay) + { + bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; + if (isManager)//اگر مدیر عامل بود + return 0; + if (maritalStatus != "متاهل")//اگر مجرد بود + return 0; + + if (countWorkingDays == endMonthCurrentDay) + return (marriedAlowance); + + return endMonthCurrentDay switch + { + 29 => GetRoundValue((marriedAlowance / 29) * countWorkingDays), + 30 => GetRoundValue((marriedAlowance / 30) * countWorkingDays), + 31 => GetRoundValue((marriedAlowance / 31) * countWorkingDays), + _ => marriedAlowance + }; + } + + + public OperationResult CreateEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) + { + var result = new OperationResult(); + + try + { + //_transactionManager.BeginTransaction(); + + var createInsuranceEmployeeInfo = new CreateInsuranceEmployeeInfo(); + createInsuranceEmployeeInfo.EmployeeId = command.EmployeeId; + createInsuranceEmployeeInfo.FName = command.FName; + createInsuranceEmployeeInfo.LName = command.LName; + createInsuranceEmployeeInfo.FatherName = command.FatherName; + createInsuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; + createInsuranceEmployeeInfo.NationalCode = command.NationalCode; + createInsuranceEmployeeInfo.IdNumber = command.IdNumber; + createInsuranceEmployeeInfo.Gender = command.Gender; + createInsuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; + createInsuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); + createInsuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); + result = _insuranceEmployeeInfoApplication.Create(createInsuranceEmployeeInfo); + + //var createEmployeeInsuranceListData = new CreateEmployeeInsurancListData(); + //createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; + //createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; + ////روزهای کارکرد پرسنل + //createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; + //// دستمزد روزانه + //createEmployeeInsuranceListData.DailyWage = command.DailyWage; + ////دستمزد ماهانه + //createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; + ////مزایای ماهانه + //createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; + ////دستمزد و مزایای ماهانه مشمول + //createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; + //// مزایای مشمول مستمر + //createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; + ////مزایای مشمول غیر مستمر + //createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; + ////سهم بیمه حق کارگر + //createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; + //// تاریخ شروع به کار + //createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); + ////تاریخ ترک کار + //if() + //createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); + //// آی دی شغل + //createEmployeeInsuranceListData.JobId = command.JobId; + //result = _employeeInsurancListDataApplication.Create(createEmployeeInsuranceListData); + + // _transactionManager.CommitTransaction(); + } + catch (Exception ex) + { + result.IsSuccedded = false; + result.Message = "ثبت اطلاعات با خطا مواجه شد"; + // _transactionManager.RollbackTransaction(); + } + + return result; + + } + + public OperationResult EditEmployeeDetailsInfo(EmployeeDetailsForInsuranceListViewModel command) + { + var result = new OperationResult(); + + try + { + //_transactionManager.BeginTransaction(); + var insuranceEmployeeInfo = new EditInsuranceEmployeeInfo(); + insuranceEmployeeInfo.Id = command.InsuranceEmployeeInformationId; + insuranceEmployeeInfo.EmployeeId = command.EmployeeId; + insuranceEmployeeInfo.FName = command.FName; + insuranceEmployeeInfo.LName = command.LName; + insuranceEmployeeInfo.FatherName = command.FatherName; + insuranceEmployeeInfo.PlaceOfIssue = command.PlaceOfIssue; + insuranceEmployeeInfo.NationalCode = command.NationalCode; + insuranceEmployeeInfo.IdNumber = command.IdNumber; + insuranceEmployeeInfo.Gender = command.Gender; + insuranceEmployeeInfo.InsuranceCode = command.InsuranceCode; + insuranceEmployeeInfo.DateOfBirthGr = command.DateOfBirth.ToGeorgianDateTime(); + insuranceEmployeeInfo.DateOfIssueGr = command.DateOfIssue.ToGeorgianDateTime(); + result = _insuranceEmployeeInfoApplication.Edit(insuranceEmployeeInfo); + + + // var createEmployeeInsuranceListData = new EditEmployeeInsurancListData(); + // createEmployeeInsuranceListData.InsuranceListId = command.InsuranceListId; + //// createEmployeeInsuranceListData.Id = command.EmployeeInsurancListDataId; + // createEmployeeInsuranceListData.EmployeeId = command.EmployeeId; + // //روزهای کارکرد پرسنل + // createEmployeeInsuranceListData.WorkingDays = command.WorkingDays; + // // دستمزد روزانه + // createEmployeeInsuranceListData.DailyWage = command.DailyWage; + // //دستمزد ماهانه + // createEmployeeInsuranceListData.MonthlySalary = command.MonthlySalary; + // //مزایای ماهانه + // createEmployeeInsuranceListData.MonthlyBenefits = command.MonthlyBenefits; + // //دستمزد و مزایای ماهانه مشمول + // createEmployeeInsuranceListData.MonthlyBenefitsIncluded = command.MonthlyBenefitsIncluded; + // // مزایای مشمول مستمر + // createEmployeeInsuranceListData.BenefitsIncludedContinuous = command.BenefitsIncludedContinuous; + // //مزایای مشمول غیر مستمر + // createEmployeeInsuranceListData.BenefitsIncludedNonContinuous = command.BenefitsIncludedNonContinuous; + // //سهم بیمه حق کارگر + // createEmployeeInsuranceListData.InsuranceShare = command.InsuranceShare; + // // تاریخ شروع به کار + // createEmployeeInsuranceListData.StartWorkDate = command.StartWorkDate.ToGeorgian(); + // //تاریخ ترک کار + // createEmployeeInsuranceListData.LeftWorkDate = command.LeftWorkDate.ToGeorgian(); + // // آی دی شغل + // createEmployeeInsuranceListData.JobId = command.JobId; + // result = _employeeInsurancListDataApplication.Edit(createEmployeeInsuranceListData); + + // _transactionManager.CommitTransaction(); + } + catch (Exception ex) + { + result.IsSuccedded = false; + result.Message = "ثبت اطلاعات با خطا مواجه شد"; + // _transactionManager.RollbackTransaction(); + } + + return result; + + } + + public OperationResult Remove(long id) + { + return _insuranceListRepositpry.Remove(id); + } + + public EditInsuranceList GetDetailsForEdit(long id) + { + var insuranceListDetails = _insuranceListRepositpry.GetDetailsForEdit(id); + //string startMonthCurrent = insuranceListDetails.Year + "/" + insuranceListDetails.Month + "/01"; + //string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + //var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + //var year = Convert.ToInt32(insuranceListDetails.Year); + //var month = Convert.ToInt32(insuranceListDetails.Month); + //var day = 1; + //var persianCurrentStartDate = new PersianDateTime(year, month, day); + //var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); + + + //var model = new YearlySalarySearchModel(); + //model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); + //model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); + //model.year = insuranceListDetails.Year; + //var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); + //var yearlysalaryItem = new YearlysalaryItemViewModel(); + //var housingAllowance = new YearlysalaryItemViewModel(); + //var consumableItems = new YearlysalaryItemViewModel(); + //if (yearSalaryObj != null) + //{ + // yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + // .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); + // housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + // .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); + // consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + // .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); + //} + + return insuranceListDetails; + } + + public double GetRoundValue(double value) + { + string strValue = value.ToString(); + if (strValue.IndexOf('.') > -1) + { + + + string a = strValue.Substring(strValue.IndexOf('.') + 1, 1); + if (int.Parse(a) > 5) + { + return (Math.Round(value, MidpointRounding.ToPositiveInfinity)); + } + else + { + return (Math.Round(value, MidpointRounding.ToNegativeInfinity)); + } + } + + return value; + } + + //محاسبه پرسنل در جدول - DSKWOR EDIT + public MainEmployeeDetailsViewModel SearchEmployeeListForEditByInsuranceListId(EmployeeForEditInsuranceListSearchModel searchModel) + { + var mainEmployeeDetailsViewModel = new MainEmployeeDetailsViewModel(); + var mainEmployeeDetailsViewModel2 = new MainEmployeeDetailsViewModel(); + var mainEmployeeDetailsViewModelForNewPersonel = new MainEmployeeDetailsViewModel(); + + List ids = searchModel.WorkshopIds.Where(x => x != searchModel.WorkshopId).ToList(); + searchModel.Month = searchModel.Month.PadLeft(2, '0'); + if (!_insuranceListRepositpry.Exists(x => x.Year == searchModel.Year && x.Month == searchModel.Month && (ids != null && ids.Count > 0 && ids.Contains(x.WorkshopId)))) + { + + mainEmployeeDetailsViewModel = _insuranceListRepositpry.SearchEmployeeListForEditByInsuranceListId(searchModel); + + var employeeForCreateInsurance = new EmployeeForCreateInsuranceListSearchModel(); + employeeForCreateInsurance.Month = searchModel.Month; + employeeForCreateInsurance.Year = searchModel.Year; + employeeForCreateInsurance.WorkshopIds = ids; + #region OtherWorkshop + if (ids != null && ids.Count > 0)//اگر ورکشاپهای دیگر را انتخاب کرد + { + mainEmployeeDetailsViewModel2 = SearchEmployeeForCreateInsuranceList(employeeForCreateInsurance); + } + #endregion + + + #region NewPersonel + //اگر افراد جدیدی به لیست بیمه اضافه شوند. + var searchModelForCreate = new EmployeeForCreateInsuranceListSearchModel(); + searchModelForCreate.Month = searchModel.Month; + searchModelForCreate.Year = searchModel.Year; + searchModelForCreate.WorkshopIds = new List() { searchModel.WorkshopId }; + var leftWorkInsuranceViewModelList = _leftWorkInsuranceApplication.SearchForCreateInsuranceList(searchModelForCreate); + var newEmployeeId = leftWorkInsuranceViewModelList.Select(x => x.EmployeeId).ToList(); + var oldEmployeeId = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Select(x => x.EmployeeId).ToList(); + if (!newEmployeeId.SequenceEqual(oldEmployeeId)) + { + var employeeAddIds = new List(); + var employeeRemoveIds = new List(); + //var employeeAddIds = newEmployeeId.Except(oldEmployeeId).ToList(); + //var employeeRemoveIds = newEmployeeId.Where(x => !oldEmployeeId.Any(z => z == x)).ToList(); + foreach (var newitem in newEmployeeId) + { + if (!oldEmployeeId.Any(x => x == newitem)) + { + employeeAddIds.Add(newitem); + } + } + foreach (var olditem in oldEmployeeId) + { + if (!newEmployeeId.Any(x => x == olditem)) + { + employeeRemoveIds.Add(olditem); + } + } + + + if (employeeAddIds != null && employeeAddIds.Count > 0) + { + leftWorkInsuranceViewModelList = leftWorkInsuranceViewModelList.Where(x => employeeAddIds.Contains(x.EmployeeId)).ToList(); + mainEmployeeDetailsViewModelForNewPersonel = GetEmployeeForInsuranceList(leftWorkInsuranceViewModelList, searchModel); + if (mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList != null && + mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList.Count > 0) + { + mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModelForNewPersonel.EmployeeDetailsForInsuranceList).ToList(); + } + } + if (employeeRemoveIds != null && employeeRemoveIds.Count > 0) + { + mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel + .EmployeeDetailsForInsuranceList.Where(x => !employeeRemoveIds.Contains(x.EmployeeId)) + .ToList(); + + + } + + } + #endregion + + + string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + var year = Convert.ToInt32(searchModel.Year); + var month = Convert.ToInt32(searchModel.Month); + var day = 1; + var persianCurrentStartDate = new PersianDateTime(year, month, day); + var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); + + var model = new YearlySalarySearchModel(); + model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); + model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); + model.year = searchModel.Year; + + var yearlysalaryItem = new YearlysalaryItemViewModel(); + var housingAllowance = new YearlysalaryItemViewModel(); + var consumableItems = new YearlysalaryItemViewModel(); + var maritalStatus = new YearlysalaryItemViewModel(); + foreach (var item in mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList) + { + var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); + item.HasConfilictJobs = false; + item.IncludeStatus = item.IncludeStatus; + int startWork = 0; + int endWork = 0; + item.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است + !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); + + #region HasConfilictLeftWork + + bool hasConfilict = false; + // // اگر شروع به کار و ترک کارش در جدول ترک کار تغییر کرده باشد + if (item.HasConfilictLeftWork)//item.LeftWorkDate != item.StrLeftWorkDateNew || (item.StartWorkDate != item.StrStartWorkDateNew && !string.IsNullOrEmpty(item.StrStartWorkDateNew) ) ||(item.JobId!=item.JobIdNew && item.JobIdNew!=0)) + { + if (item.LeftWorkDate != item.StrLeftWorkDateNew) + { + item.LeftWorkDate = item.StrLeftWorkDateNew; + item.LeftWorkDateGr = item.LeftWorkDateNew; + + } + + if (item.StartWorkDate != item.StrStartWorkDateNew && + !string.IsNullOrEmpty(item.StrStartWorkDateNew)) + { + item.StartWorkDate = item.StrStartWorkDateNew; + item.StartWorkDateGr = item.StartWorkDateNew; + } + + if (item.JobId != item.JobIdNew && item.JobIdNew != 0) + { + item.JobId = item.JobIdNew; + item.JobCode = item.JobCodeNew; + item.JobName = item.JobNameNew; + } + + item.IncludeStatus = item.IncludeStatusNew;//(item.IncludeStatus==item.IncludeStatusNew); + + + hasConfilict = true; + } + + #endregion + + var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); + if (yearSalaryObj != null) + { + yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); + housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); + consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); + maritalStatus = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); + item.HousingAllowance = housingAllowance.ItemValue; + item.ConsumableItems = consumableItems.ItemValue; + //item.MarriedAllowance = maritalStatus.ItemValue; + item.YearlySalaryItem = yearlysalaryItem.ItemValue; + + } + + //ترک کارش در ماه و سال جاری بود نمایش داده شود + if (!string.IsNullOrEmpty(item.LeftWorkDate) && !item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) + { + item.LeftWorkDate = string.Empty; + item.LeftWorkDateGr = null; + } + + if (!string.IsNullOrEmpty(item.LeftWorkDate)) //&& item.LeftWorkDate.Substring(5, 2)==searchModel.Month && item.LeftWorkDate.Substring(0, 4) == searchModel.Year) + { + // item.HasLeftWorkInMonth = true; + var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); + var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); + var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); + + var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); + var persianEndDateUser = persianLeftDateUser.AddDays(-1); + var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); + + if (persianLeftDateUser <= persianCurrentEndDate) + item.HasLeftWorkInMonth = true; + else + item.HasLeftWorkInMonth = false; + + //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد + if (persianEndDateUser >= persianCurrentEndDate) + { + endWork = dayMonthCurrent; + } + else + { + endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); + } + } + else + { + // item.HasLeftWorkInMonth = false; + endWork = dayMonthCurrent; + } + var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); + var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); + var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); + var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); + + if (persianStartDateUser <= persianCurrentStartDate) + { + startWork = 1; + } + else + { + startWork = dayStartDateUser; + } + + if (persianStartDateUser < persianCurrentStartDate) + item.HasStartWorkInMonth = false; + else + item.HasStartWorkInMonth = true; + + + if (hasConfilict) //اگر ترک کار شخص تغییر کرده بود، دوباره محاسبه شود + { + item.StartMonthCurrent = startMonthCurrent; + item.HousingAllowance = housingAllowance.ItemValue; + item.ConsumableItems = consumableItems.ItemValue; + item.DailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, searchModel.WorkshopId, searchModel.Year); + item.DailyWageStr = item.DailyWage.ToMoney(); + } + else + { + item.DailyWageStr = item.DailyWage.ToMoney(); + } + item.EndMonthCurrentDay = dayMonthCurrent; + if (hasConfilict || searchModel.FixedSalary || searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist") + { + #region InsuranceJob + + double dailyWage = item.DailyWage; + if (searchModel.FixedSalary) + { + dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, searchModel.WorkshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); + item.HasConfilictJobs = (dailyWage == 0 ? true : false); + } + #endregion + + if (hasConfilict) + { + int countWorkingDays = 0; + for (int i = startWork; i <= endWork; i++) + { + countWorkingDays = countWorkingDays + 1; + } + + item.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); + item.WorkingDays = countWorkingDays; + if (item.IncludeStatus) + { + var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; + item.MonthlyBenefits = GetMonthlyBenefits(dayMonthCurrent, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); + } + else + { + item.MonthlyBenefits = 0; + } + } + + if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت + { + item.MonthlyBenefits = 0; + } + + item.BenefitsIncludedContinuous = item.MonthlyBenefits + item.MonthlySalary; + + + var insuranceShare = (item.BenefitsIncludedContinuous * 7) / 100; + item.InsuranceShare = GetRoundValue(insuranceShare); + //} + + var employerShare = (item.BenefitsIncludedContinuous * 20) / 100; + item.EmployerShare = GetRoundValue(employerShare); + + var unEmploymentInsurance = (item.BenefitsIncludedContinuous * 3) / 100; + item.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); + + // item.BenefitsIncludedNonContinuous = item.BenefitsIncludedContinuous; + item.IncludedAndNotIncluded = item.BenefitsIncludedContinuous + item.BenefitsIncludedNonContinuous; + } + + } + if (mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList != null && mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList.Count > 0) + mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.Union(mainEmployeeDetailsViewModel2.EmployeeDetailsForInsuranceList).OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); + else + mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList = mainEmployeeDetailsViewModel.EmployeeDetailsForInsuranceList.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth).ThenBy(x => x.LName).ToList(); + + mainEmployeeDetailsViewModel.IsExist = false; + mainEmployeeDetailsViewModel.MaritalStatus = maritalStatus.ItemValue; + } + else + { + mainEmployeeDetailsViewModel.IsExist = true; + } + return mainEmployeeDetailsViewModel; + } + + public MainEmployeeDetailsViewModel GetEmployeeListForEditByInsuranceListId( + EmployeeForEditInsuranceListSearchModel searchModel) + { + var result = new MainEmployeeDetailsViewModel(); + var workshopId = searchModel.WorkshopIds.FirstOrDefault(); + var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; + DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); + DateTime endDateGr = startMonthFa.FindeEndOfMonth() + .ToGeorgianDateTime(); + int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); + + //مقادیر سالانه این تاریخ + var yearlysaleries = _yearlySalaryApplication.GetInsuranceItems(startDateGr, endDateGr, searchModel.Year); + + // دریافت اطلاعات هویتی و شروع و ترک کار کارکنان + //var employeesInfoAndLeftWorks = + // _leftWorkInsuranceApplication.GetEmployeeInsuranceLeftWorksAndInformation(workshopId, startDateGr, + // endDateGr); + + var employeeInsurancDataPreviusList = + _insuranceListRepositpry.GetEmployeeInsuranceDataForEdit(searchModel.InsuranceId, startDateGr, endDateGr); + + var computeResult = employeeInsurancDataPreviusList.Select(employeeData => + { + var dateOfBirth = employeeData.DateOfBirthGr.ToFarsi(); + var dateOfIssue = employeeData.DateOfIssueGr.ToFarsi(); + var leftDate = employeeData.LeftWorkDateGr != null ? employeeData.LeftWorkDateGr.Value.AddDays(-1) : new DateTime(); + var workingDays = Tools.GetEmployeeInsuranceWorkingDays(employeeData.StartWorkDateGr, leftDate, startDateGr, endDateGr, employeeData.EmployeeId); + var leftWorkFa = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr.ToFarsi() : ""; + var startWorkFa = employeeData.StartWorkDateGr.ToFarsi(); + var workshop = _workShopRepository.GetDetails(workshopId); + + //آیا کارفرما است + bool isManager = employeeData.JobId is 10 or 16 or 17 or 18 or 3498; + + //محاسبه حق بیمه سهم کارفرما + var employerShare = (employeeData.BenefitsIncludedContinuous * 20) / 100; + + // محاسبه بیمه بیکاری + var unEmploymentInsurance = (employeeData.BenefitsIncludedContinuous * 3) / 100; + + + //آیا در کارگاه تیک محاسبه اضافه کار یا حق اولاد زده شده است؟ + //این مورد زمانی چک می شود که تیک محاسبه در کارگاه زده شده باشد + // در غیر اینصورت بصورت پیشفرض دارای فیش حقوق در نظر گرفته می شود + bool hasWorkshopOverTimeOrFamilyAllowance = + workshop.InsuranceCheckoutFamilyAllowance || workshop.InsuranceCheckoutOvertime; + + bool employeeHasCheckout = true; + bool hasOverTimePay = false; + bool hasFamilyAllowance = false; + + if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employeeData.LeftWorkDateGr == null)) + { + var checkout = _checkoutRepository.HasCheckout(workshopId, employeeData.EmployeeId, + searchModel.Year, searchModel.Month); + if (checkout.hasChekout) + { + if (checkout.OverTimePay > 0) + hasOverTimePay = true; + if (checkout.FamilyAlloance > 0) + hasFamilyAllowance = true; + + } + else + { + employeeHasCheckout = isManager == false ? false : true; + } + } + + bool familyAllowanceIsSet = true; + bool overTimePayIsSet = true; + if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && employeeData.FamilyAllowance == 0 && hasFamilyAllowance && !isManager) + { + + familyAllowanceIsSet = false; + } + + if (workshop.InsuranceCheckoutOvertime && employeeHasCheckout && employeeData.OverTimePay == 0 && hasOverTimePay && !isManager) + { + + overTimePayIsSet = false; + } + return new EmployeeDetailsForInsuranceListViewModel + { + #region EmployeeInfo + EmployeeHasCheckout = employeeHasCheckout, + EmployeeInsurancListDataId = employeeData.EmployeeInsurancListDataId, + + InsuranceEmployeeInformationId = employeeData.InsuranceEmployeeInformationId, + EmployeeId = employeeData.EmployeeId, + FName = employeeData.FName, + LName = employeeData.LName, + FatherName = employeeData.FatherName, + DateOfBirth = dateOfBirth == "1300/10/11" ? "" : dateOfBirth, + DateOfIssue = dateOfIssue, + DateOfBirthGr = employeeData.DateOfBirthGr, + DateOfIssueGr = employeeData.DateOfIssueGr, + PlaceOfIssue = employeeData.PlaceOfIssue, + IdNumber = employeeData.IdNumber, + Gender = employeeData.Gender, + NationalCode = employeeData.NationalCode, + Nationality = employeeData.Nationality, + InsuranceCode = employeeData.InsuranceCode, + // آیا وضعیت تاهل پرسنل ست شده است + IsMaritalStatusSet = !string.IsNullOrWhiteSpace(employeeData.MaritalStatus), + MaritalStatus = employeeData.MaritalStatus, + + StartMonthCurrent = startMonthFa, + WorkingDays = workingDays.countWorkingDays, + StartWorkDate = startWorkFa, + StartWorkDateGr = employeeData.StartWorkDateGr, + LeftWorkDate = leftWorkFa, + LeftWorkDateGr = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr : null, + JobId = employeeData.JobId, + JobName = employeeData.JobName, + JobCode = employeeData.JobCode, + + HasStartWorkInMonth = workingDays.hasStartWorkInMonth, + HasLeftWorkInMonth = workingDays.hasLeftWorkInMonth, + #endregion + + #region Compute + //مشمول مزایا بودن + IncludeStatus = employeeData.IncludeStatus, + + //دستمزد روزانه + DailyWage = GetRoundValue(employeeData.DailyWage), + DailyWageStr = employeeData.DailyWage.ToMoney(), + + //HasConfilictJobs = dailyWage == 0, + + //پایه سنوات + BaseYears = employeeData.BaseYears, + + //مجموع مزد روزانه و پایه سنوات + DailyWagePlusBaseYears = employeeData.DailyWagePlusBaseYears, + + //حق تاهل + MarriedAllowance = employeeData.MarriedAllowance, + + //دستمزد ماهانه + MonthlySalary = employeeData.MonthlySalary, + + + //مزایای ماهانه + MonthlyBenefits = employeeData.MonthlyBenefits, + + //مزایای مشمول + BenefitsIncludedContinuous = employeeData.BenefitsIncludedContinuous, + + //مزایای غیر مشمول + BenefitsIncludedNonContinuous = employeeData.BenefitsIncludedNonContinuous, + + // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول + IncludedAndNotIncluded = employeeData.IncludedAndNotIncluded, + + //حق بیمه سهم بیمه شده + InsuranceShare = GetRoundValue(employeeData.InsuranceShare), + + //حق بیمه سهم کارفرما + EmployerShare = GetRoundValue(employerShare), + + //بیمه بیکاری + UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance), + + //کمک هزینه مسکن + HousingAllowance = yearlysaleries.HousingAllowance, + //کمک هزینه اقلام + ConsumableItems = yearlysaleries.ConsumableItems, + + EndMonthCurrentDay = endOfMonth, + YearlySalaryItem = yearlysaleries.DayliWage, + MonthlyBaseYearsStr = "0", + MonthlyBaseYears = 0, + + OverTimeIsSet = overTimePayIsSet, + FamilyAllowanceIsSet = familyAllowanceIsSet + #endregion + + + }; + }); + + result.EmployeeDetailsForInsuranceList = computeResult.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) + .ThenBy(x => x.LName).ToList(); + + result.IsExist = false; + result.MaritalStatus = yearlysaleries.MarriedAllowance; + + return result; + } + + public OperationResult ConfirmInsuranceList(long id) + { + OperationResult result = new OperationResult(); + + try + { + result = _insuranceListRepositpry.ConfirmInsuranceList(id); + result.Message = "تایید ارسال لیست بیمه با موفقیت انجام شد"; + } + catch (Exception) + { + result.Message = "تایید ارسال لیست بیمه با خطا انجام شد"; + } + + return result; + } + + private double? GetDailyWageFixedSalary(string year, long workshopId, long employeeId, DateTime? startDateGr, DateTime? endDateGr, long jobId, string population, long? insuranceJobId) + { + + double? result = 0; + string month = $"{startDateGr.ToFarsi()}".Substring(5, 2); + //اگر مشاغل مقطوع بود و شغلش کارفرما بود + // در جدول لیست بیمه قبلی چک شود + try + { + if (workshopId == 318 && year == "1403") + { + double percent = 0; + switch (jobId) + { + case 39: + percent = 1.75; + return 4180000; + break; + case 466: + percent = 1.6; + return 3822000; + break; + case 1192 or 398 or 8: + percent = 1.5; + return 3583000; + break; + } + + //var dateSaleryviewModel = new DateSalarySearchModel(); + //dateSaleryviewModel.StartDateGr = startDateGr; + //dateSaleryviewModel.EndDateGr = endDateGr; + //var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); + //// && _dateSalary.Id >0 + //if (_dateSalary != null) + //{ + // var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); + // dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; + // dateSaleryItemviewModel.Percent = percent; + // var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); + // if (dateSalaryItem != null) + // result = dateSalaryItem[0].Salary; + //} + } + if (jobId == 10) //کارفرما + { + InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); + var workshop = _workShopRepository.GetDetails(workshopId); + if (workshop.FixedSalary) + + { + var inJob = _insuranceJobItemRepository + .GetInsuranceJobItemByInsuranceJobId((long)workshop.InsuranceJobId); + if (workshop.Population == "MoreThan500") + { + var max = inJob.MaxBy(x => x.PercentageMoreThan); + var dateSaleryviewModel = new DateSalarySearchModel(); + dateSaleryviewModel.StartDateGr = startDateGr; + dateSaleryviewModel.EndDateGr = endDateGr; + var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); + if (_dateSalary != null) + { + var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); + dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; + dateSaleryItemviewModel.Percent = max.PercentageMoreThan; + var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); + if (dateSalaryItem != null) + result = dateSalaryItem[0].Salary; + } + } + else + { + var max = inJob.MaxBy(x => x.PercentageLessThan); + var dateSaleryviewModel = new DateSalarySearchModel(); + dateSaleryviewModel.StartDateGr = startDateGr; + dateSaleryviewModel.EndDateGr = endDateGr; + var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); + if (_dateSalary != null) + { + var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); + dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; + dateSaleryItemviewModel.Percent = max.PercentageLessThan; + var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); + if (dateSalaryItem != null) + result = dateSalaryItem[0].Salary; + } + } + + + + } + //var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); + //var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); + //if (employeeInsurancListData != null ) + //{ + // result = employeeInsurancListData.DailyWage; + //} + } + else + { + + var searchModel = new InsuranceJobItemSearchModel(); + searchModel.InsuranceJobId = (long)insuranceJobId; + var JobItem = _insuranceJobItemRepository.GetInsuranceJobItemByInsuranceJobIdForFixedSalary((long)insuranceJobId, jobId); + + if (JobItem != null && JobItem.Id != 0) + { + double percent = 0; + if (population == "MoreThan500") + percent = JobItem.PercentageMoreThan; + else if (population == "LessThan500") + percent = JobItem.PercentageLessThan; + + var dateSaleryviewModel = new DateSalarySearchModel(); + dateSaleryviewModel.StartDateGr = startDateGr; + dateSaleryviewModel.EndDateGr = endDateGr; + var _dateSalary = _dateSalaryRepository.GetDateSalaryViewModel(dateSaleryviewModel); + // && _dateSalary.Id >0 + if (_dateSalary != null) + { + var dateSaleryItemviewModel = new DateSalaryItemSearchModel(); + dateSaleryItemviewModel.DateSalaryId = _dateSalary.Id; + dateSaleryItemviewModel.Percent = percent; + var dateSalaryItem = _dateSalaryItemRepository.Search(dateSaleryItemviewModel); + if (dateSalaryItem != null) + result = dateSalaryItem[0].Salary; + } + } + + + } + } + catch (Exception) + { + + result = 0; + } + return result; + } + + /// + /// محاسبه مزایای ماهانه مشمول + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + private double GetMonthlyBenefits(int endMonthCurrentDay, double consumableItemsItemValue, double housingAllowanceItemValue, double maritalStatus, int countWorkingDays, string typeOfInsuranceSendWorkshop, long jobId, long employeeId, bool includeStatus) + { + //ToDo + //افزودن شرط مشمول مزایای + + //اگر پرسنل کارفرما بود و نوع لیست کارگاه کمک دولت بود مزایا محاسبه نشود + //اگر تیک مشمول مزایا در ترک کار خاموش بود مزایا نگیرد + + bool isManager = jobId is 10 or 16 or 17 or 18 or 3498; + if (isManager && !includeStatus) + return 0; + //پرسنل استثناء + if (employeeId == 42783) + return 53082855; + + + //if(employeeId == 8859) + // return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); + + //مزایای ماهانه با توجه به پایان ماه که 30 یا 31 روزه است، متفاوت می باشد + //برای ماه 29 روزه هم تقسیم بر 30 می شود. + if (countWorkingDays == endMonthCurrentDay) + return (consumableItemsItemValue + housingAllowanceItemValue + maritalStatus); + else if (endMonthCurrentDay == 29)//farokhiChanges در خط پایین عدد 30 رو به 29 تغییر دادم + return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 29) * countWorkingDays); + else if (endMonthCurrentDay == 30)//farokhiChanges این شرط و خط زیر رو اضافه کردم + return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 30) * countWorkingDays); + else if (endMonthCurrentDay == 31)//farokhiChanges این شرط و خط زیر رو اضافه کردم + return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / 31) * countWorkingDays); + else + return GetRoundValue(((consumableItemsItemValue + housingAllowanceItemValue + maritalStatus) / endMonthCurrentDay) * countWorkingDays); + } + + + + private double ComputeDailyWage(double yearlysalaryItemValue, long employeeId, long workshopId, string year) + { + double dailyWage = yearlysalaryItemValue; + InsuranceListSearchModel searchModel = new InsuranceListSearchModel(); + var insuransList = _insuranceListRepositpry.GetInsuranceListByWorkshopIdAndYear(workshopId, year); + if (insuransList != null) + { + var employeeInsurancListData = _employeeInsurancListDataRepository.GetEmployeeInsurancListDataByEmployeeIdAndInsuranceListId(employeeId, insuransList.Id); + if (employeeInsurancListData != null && employeeInsurancListData.DailyWage > dailyWage) + { + dailyWage = employeeInsurancListData.DailyWage; + } + } + + dailyWage = employeeId == 6536 ? 9399512 : dailyWage; + return dailyWage; + } + public MainEmployeeDetailsViewModel GetEmployeeForInsuranceList(List leftWorkInsuranceViewModelList, EmployeeForEditInsuranceListSearchModel searchModel) + { + var result = new MainEmployeeDetailsViewModel(); + + List list = new List(); + int leftWorkInsuranceCount = leftWorkInsuranceViewModelList.Count(); + string startMonthCurrent = searchModel.Year + "/" + searchModel.Month + "/01"; + string endMonthCurrent = startMonthCurrent.FindeEndOfMonth(); + + var model = new YearlySalarySearchModel(); + model.StartDateGr = startMonthCurrent.ToGeorgianDateTime(); + model.EndDateGr = endMonthCurrent.ToGeorgianDateTime(); + model.year = searchModel.Year; + + + + var yearSalaryObj = _yearlySalaryApplication.GetDetailsBySearchModel(model); + + var yearlysalaryItem = new YearlysalaryItemViewModel(); + var housingAllowance = new YearlysalaryItemViewModel(); + var consumableItems = new YearlysalaryItemViewModel(); + var maritalStatus = new YearlysalaryItemViewModel(); + if (yearSalaryObj != null) + { + yearlysalaryItem = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "مزد روزانه").FirstOrDefault(); + housingAllowance = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "کمک هزینه مسکن").FirstOrDefault(); + consumableItems = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "کمک هزینه اقلام").FirstOrDefault(); + maritalStatus = _yearlySalaryItemApplication.GetItemsByYearlySalaryId(yearSalaryObj.Id) + .Where(x => x.ItemName == "حق تاهل").FirstOrDefault(); + } + + foreach (var item in leftWorkInsuranceViewModelList) + { + var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); + + var employeeDetailsForInsuranceObj = new EmployeeDetailsForInsuranceListViewModel(); + employeeDetailsForInsuranceObj.HasConfilictJobs = false; + employeeDetailsForInsuranceObj.IsMaritalStatusSet = // آیا وضعیت تاهل پرسنل ست شده است + !string.IsNullOrWhiteSpace(employeeObject.MaritalStatus); + if (_insuranceEmployeeInfoRepository.Exists(x => x.EmployeeId == item.EmployeeId)) + { + var employeeInfoObject = _insuranceEmployeeInfoApplication.GetDetailsByEmployeeId(item.EmployeeId); + employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = employeeInfoObject.Id; + employeeDetailsForInsuranceObj.EmployeeId = employeeInfoObject.EmployeeId; + employeeDetailsForInsuranceObj.FName = employeeInfoObject.FName; + employeeDetailsForInsuranceObj.LName = employeeInfoObject.LName; + employeeDetailsForInsuranceObj.FatherName = employeeInfoObject.FatherName; + employeeDetailsForInsuranceObj.DateOfBirth = employeeInfoObject.DateOfBirth; + employeeDetailsForInsuranceObj.DateOfIssue = employeeInfoObject.DateOfIssue; + employeeDetailsForInsuranceObj.DateOfBirthGr = employeeInfoObject.DateOfBirthGr; + employeeDetailsForInsuranceObj.DateOfIssueGr = employeeInfoObject.DateOfIssueGr; + employeeDetailsForInsuranceObj.PlaceOfIssue = employeeInfoObject.PlaceOfIssue; + employeeDetailsForInsuranceObj.IdNumber = employeeInfoObject.IdNumber; + employeeDetailsForInsuranceObj.Gender = employeeInfoObject.Gender; + + //از جدول پرسنل پر می شود + employeeDetailsForInsuranceObj.NationalCode = + employeeObject.NationalCode; //employeeInfoObject.NationalCode; + employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; + employeeDetailsForInsuranceObj.InsuranceCode = + employeeObject.InsuranceCode; //employeeInfoObject.InsuranceCode; + } + else + { + // var employeeObject = _employeeRepository.GetDetailsByADDate(item.EmployeeId); + employeeDetailsForInsuranceObj.InsuranceEmployeeInformationId = 0; + //employeeDetailsForInsuranceObj.EmployeeInsurancListDataId = 0; + employeeDetailsForInsuranceObj.EmployeeId = employeeObject.Id; + employeeDetailsForInsuranceObj.FName = employeeObject.FName; + employeeDetailsForInsuranceObj.LName = employeeObject.LName; + employeeDetailsForInsuranceObj.FatherName = employeeObject.FatherName; + employeeDetailsForInsuranceObj.DateOfBirth = employeeObject.DateOfBirth == "1300/10/11" ? "" : employeeObject.DateOfBirth; + employeeDetailsForInsuranceObj.DateOfIssue = employeeObject.DateOfIssue; + employeeDetailsForInsuranceObj.PlaceOfIssue = employeeObject.PlaceOfIssue; + employeeDetailsForInsuranceObj.NationalCode = employeeObject.NationalCode; + employeeDetailsForInsuranceObj.IdNumber = employeeObject.IdNumber; + employeeDetailsForInsuranceObj.Gender = employeeObject.Gender; + employeeDetailsForInsuranceObj.InsuranceCode = employeeObject.InsuranceCode; + employeeDetailsForInsuranceObj.Nationality = employeeObject.Nationality; + } + + #region ComputingWorkingDays + + int startWork = 0; + int endWork = 0; + + var year = Convert.ToInt32(searchModel.Year); + var month = Convert.ToInt32(searchModel.Month); + var day = 1; + var persianCurrentStartDate = new PersianDateTime(year, month, day); + var dayMonthCurrent = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + var persianCurrentEndDate = new PersianDateTime(year, month, dayMonthCurrent); + //آخرین روز ماه جاری + var endMonthCurrentDay = Convert.ToInt32(endMonthCurrent.Substring(8, 2)); + + var yearStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(0, 4)); + var monthStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(5, 2)); + var dayStartDateUser = Convert.ToInt32(item.StartWorkDate.Substring(8, 2)); + var persianStartDateUser = new PersianDateTime(yearStartDateUser, monthStartDateUser, dayStartDateUser); + + if (persianStartDateUser < persianCurrentStartDate) + employeeDetailsForInsuranceObj.HasStartWorkInMonth = false; + else + employeeDetailsForInsuranceObj.HasStartWorkInMonth = true; + + //اگر شروع به کار کاربر از ابتدای ماه جاری کمتر باشد + if (persianStartDateUser <= persianCurrentStartDate) + { + startWork = 1; + } + else + { + startWork = dayStartDateUser; + } + + if (!string.IsNullOrEmpty(item.LeftWorkDate)) + { + var yearEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(0, 4)); + var monthEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(5, 2)); + var dayEndDateUser = Convert.ToInt32(item.LeftWorkDate.Substring(8, 2)); + var persianLeftDateUser = new PersianDateTime(yearEndDateUser, monthEndDateUser, dayEndDateUser); + var persianEndDateUser = persianLeftDateUser.AddDays(-1); + var persianEndDateUserStr = persianLeftDateUser.AddDays(-1).ToString("yyyy/MM/dd"); + + //if (persianLeftDateUser <= persianCurrentEndDate) + // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; + //else + // employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + + //ترک کارش در ماه و سال جاری بود نمایش داده شود + if (!item.LeftWorkDate.Contains(searchModel.Year + "/" + searchModel.Month)) + { + employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + item.LeftWorkDate = string.Empty; + item.LeftWorkDateGr = null; + } + else + { + employeeDetailsForInsuranceObj.HasLeftWorkInMonth = true; + } + + //اگر پایان به کار کاربر از پایان ماه جاری بیشتر باشد + if (persianEndDateUser >= persianCurrentEndDate) + { + endWork = endMonthCurrentDay; + } + else + { + endWork = Convert.ToInt32(persianEndDateUserStr.Substring(8, 2)); + } + } + else + { + employeeDetailsForInsuranceObj.HasLeftWorkInMonth = false; + endWork = endMonthCurrentDay; + } + + int countWorkingDays = 0; + for (int i = startWork; i <= endWork; i++) + { + countWorkingDays = countWorkingDays + 1; + } + + //farokhiChanges + //روزهای کارکرد پرسنل با آی دی های زیر دستی تعریف شد + switch (item.EmployeeId) + { + + //case 3812://ثابت + // countWorkingDays = 15; + // break; + case 40463://ثابت + countWorkingDays = 10; + break; + case 40469://ثابت + countWorkingDays = 7; + break; + //case 9950://ثابت + // countWorkingDays = 15; + break; + case 9640://ثابت + countWorkingDays = 15; + break; + case 40998://ثابت + countWorkingDays = 15; + break; + case 6219://ثابت + countWorkingDays = 15; + break; + //case 7897://ثابت + // countWorkingDays = 15; + // break; + } ; - #endregion + #endregion - employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; + employeeDetailsForInsuranceObj.IncludeStatus = item.IncludeStatus; - #region InsuranceJob - double dailyWage = employeeDetailsForInsuranceObj.DailyWage; - if (searchModel.FixedSalary) - { - dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, item.WorkshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); - employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); - } - #endregion + #region InsuranceJob + double dailyWage = employeeDetailsForInsuranceObj.DailyWage; + if (searchModel.FixedSalary) + { + dailyWage = Convert.ToDouble(GetDailyWageFixedSalary(searchModel.Year, item.WorkshopId, item.EmployeeId, model.StartDateGr, model.EndDateGr, item.JobId, searchModel.Population, searchModel.InsuranceJobId)); + employeeDetailsForInsuranceObj.HasConfilictJobs = (dailyWage == 0 ? true : false); + } + #endregion - if (yearlysalaryItem != null) - { - if (!searchModel.FixedSalary) - { - //dailyWage= yearlysalaryItem.ItemValue; - dailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, item.WorkshopId, searchModel.Year); - } - employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); - employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); - employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); - employeeDetailsForInsuranceObj.HousingAllowance = housingAllowance.ItemValue; - employeeDetailsForInsuranceObj.ConsumableItems = consumableItems.ItemValue; - employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; - employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysalaryItem.ItemValue; - if (item.IncludeStatus) - { - var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; - employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); - } - else - { - employeeDetailsForInsuranceObj.MonthlyBenefits = 0; - } + if (yearlysalaryItem != null) + { + if (!searchModel.FixedSalary) + { + //dailyWage= yearlysalaryItem.ItemValue; + dailyWage = ComputeDailyWage(yearlysalaryItem.ItemValue, item.EmployeeId, item.WorkshopId, searchModel.Year); + } + employeeDetailsForInsuranceObj.DailyWage = GetRoundValue(dailyWage); + employeeDetailsForInsuranceObj.DailyWageStr = employeeDetailsForInsuranceObj.DailyWage.ToMoney(); + employeeDetailsForInsuranceObj.MonthlySalary = GetRoundValue(dailyWage * countWorkingDays); + employeeDetailsForInsuranceObj.HousingAllowance = housingAllowance.ItemValue; + employeeDetailsForInsuranceObj.ConsumableItems = consumableItems.ItemValue; + employeeDetailsForInsuranceObj.EndMonthCurrentDay = endMonthCurrentDay; + employeeDetailsForInsuranceObj.YearlySalaryItem = yearlysalaryItem.ItemValue; + if (item.IncludeStatus) + { + var marital = employeeObject.MaritalStatus == "متاهل" ? maritalStatus.ItemValue : 0; + employeeDetailsForInsuranceObj.MonthlyBenefits = GetMonthlyBenefits(endMonthCurrentDay, consumableItems.ItemValue, housingAllowance.ItemValue, marital, countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, item.JobId, item.EmployeeId, item.IncludeStatus); + } + else + { + employeeDetailsForInsuranceObj.MonthlyBenefits = 0; + } - if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت - { - employeeDetailsForInsuranceObj.MonthlyBenefits = 0; - } + if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId == 10) //کمک دولت + { + employeeDetailsForInsuranceObj.MonthlyBenefits = 0; + } - employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous = employeeDetailsForInsuranceObj.MonthlyBenefits + employeeDetailsForInsuranceObj.MonthlySalary; - //if ((!item.IncludeStatus &&(item.JobId == 10 || item.JobId == 17 || item.JobId == 18 || item.JobId == 16)) ||(item.IncludeStatus && item.JobId == 10)) // 10 --> karfarma - //{ - // var insuranceShare2 =(employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 27) / 100; - // employeeDetailsForInsuranceObj.InsuranceShare =GetRoundValue(insuranceShare2); - //} - //else - //{ - var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; - employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); - //} + //if ((!item.IncludeStatus &&(item.JobId == 10 || item.JobId == 17 || item.JobId == 18 || item.JobId == 16)) ||(item.IncludeStatus && item.JobId == 10)) // 10 --> karfarma + //{ + // var insuranceShare2 =(employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 27) / 100; + // employeeDetailsForInsuranceObj.InsuranceShare =GetRoundValue(insuranceShare2); + //} + //else + //{ + var insuranceShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 7) / 100; + employeeDetailsForInsuranceObj.InsuranceShare = GetRoundValue(insuranceShare); //Math.Round(insuranceShare, MidpointRounding.ToPositiveInfinity); + //} - var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; - employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); + var employerShare = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 20) / 100; + employeeDetailsForInsuranceObj.EmployerShare = GetRoundValue(employerShare); //Math.Round(employerShare, MidpointRounding.ToPositiveInfinity); - //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت - //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} + //if (searchModel.TypeOfInsuranceSendWorkshop == "Govermentlist" && item.JobId==10)//کمک دولت + //{employeeDetailsForInsuranceObj.InsuranceShare = 0;} - var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; - employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); + var unEmploymentInsurance = (employeeDetailsForInsuranceObj.BenefitsIncludedContinuous * 3) / 100; + employeeDetailsForInsuranceObj.UnEmploymentInsurance = GetRoundValue(unEmploymentInsurance); - employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; - employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; + employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous; + employeeDetailsForInsuranceObj.IncludedAndNotIncluded = employeeDetailsForInsuranceObj.BenefitsIncludedNonContinuous + employeeDetailsForInsuranceObj.BenefitsIncludedContinuous; - } + } - employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; - employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; - employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; - employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; - employeeDetailsForInsuranceObj.JobId = item.JobId; - employeeDetailsForInsuranceObj.JobName = item.JobName; - employeeDetailsForInsuranceObj.JobCode = item.JobCode; - if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) - employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; + employeeDetailsForInsuranceObj.StartMonthCurrent = startMonthCurrent; + employeeDetailsForInsuranceObj.WorkingDays = countWorkingDays; + employeeDetailsForInsuranceObj.StartWorkDate = item.StartWorkDate; + employeeDetailsForInsuranceObj.LeftWorkDate = item.LeftWorkDate; + employeeDetailsForInsuranceObj.JobId = item.JobId; + employeeDetailsForInsuranceObj.JobName = item.JobName; + employeeDetailsForInsuranceObj.JobCode = item.JobCode; + if (!string.IsNullOrWhiteSpace(item.LeftWorkDate)) + employeeDetailsForInsuranceObj.LeftWorkDateGr = item.LeftWorkDateGr; - employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; + employeeDetailsForInsuranceObj.StartWorkDateGr = item.StartWorkDateGr; - list.Add(employeeDetailsForInsuranceObj); - } + list.Add(employeeDetailsForInsuranceObj); + } - list = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) - .ThenBy(x => x.LName).ToList(); - result.EmployeeDetailsForInsuranceList = list; - result.IsExist = false; - result.MaritalStatus = maritalStatus.ItemValue; - //} - //else - //{ - // result.IsExist = true; - //} - return result; - } + list = list.OrderByDescending(x => x.HasLeftWorkInMonth).ThenByDescending(x => x.HasStartWorkInMonth) + .ThenBy(x => x.LName).ToList(); + result.EmployeeDetailsForInsuranceList = list; + result.IsExist = false; + result.MaritalStatus = maritalStatus.ItemValue; + //} + //else + //{ + // result.IsExist = true; + //} + return result; + } - #region Client + #region Client - public List SearchForClient(InsuranceListSearchModel searchModel) - { - var result = _insuranceListRepositpry.SearchForClient(searchModel); - return result; - } + public List SearchForClient(InsuranceListSearchModel searchModel) + { + var result = _insuranceListRepositpry.SearchForClient(searchModel); + return result; + } - #endregion - //farokhiChanges - public (double basic, int totalYear) BasicYear(long employeeId, long worshopId, DateTime startDate) - { - var totalYears = _leftWorkInsuranceRepository.TotalWorkingYears(employeeId, worshopId, startDate); - var baseSalary = _insuranceYearlySalaryApplication.GetBaseYearByDate(startDate, totalYears); - return (baseSalary, totalYears); - } + #endregion + //farokhiChanges + public (double basic, int totalYear) BasicYear(long employeeId, long worshopId, DateTime startDate) + { + var totalYears = _leftWorkInsuranceRepository.TotalWorkingYears(employeeId, worshopId, startDate); + var baseSalary = _insuranceYearlySalaryApplication.GetBaseYearByDate(startDate, totalYears); + return (baseSalary, totalYears); + } - public double GetMonthlyBaseYear(double dayliBase, int countWorkingDays) - { - double res = GetRoundValue(dayliBase * countWorkingDays); - return res; - } + public double GetMonthlyBaseYear(double dayliBase, int countWorkingDays) + { + double res = GetRoundValue(dayliBase * countWorkingDays); + return res; + } - #region Mahan + #region Mahan + + public async Task ConfirmInsuranceOperation(InsuranceListConfirmOperation command) + { + // Improved version of the ConfirmInsuranceOperation method's main logic + async Task CreateMediaAsync(InsuranceList insuranceList, string insuranceType, IFormFile file) + { + var path = Path.Combine(_mediaRepository.BasePath, "InsuranceList", $"{insuranceList.Year}_{insuranceList.Month}", insuranceList.id.ToString()); + Directory.CreateDirectory(path); + + string uniqueFileName = $"{insuranceType}_{Path.GetFileNameWithoutExtension(file.FileName)}_{DateTime.Now.Ticks}{Path.GetExtension(file.FileName)}"; + string filePath = Path.Combine(path, uniqueFileName); + + await using (var stream = new FileStream(filePath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + var type = Path.GetExtension(filePath); + var media = new Media(filePath, type, "فایل", "InsuranceList"); + await _mediaRepository.CreateAsync(media); + await _mediaRepository.SaveChangesAsync(); + return media.id; + } + + var op = new OperationResult(); + var insuranceList = _insuranceListRepositpry.Get(command.InsuranceListId); + if (insuranceList == null) + return op.Failed("لیست بیمه پیدا نشد"); + + bool completeDebt = false, completeInspection = false, completeApproval = false; + + // Debt Section + if (command.Debt.Type != InsuranceListDebtType.None) + { + var debt = command.Debt; + if (string.IsNullOrWhiteSpace(debt.DebtDate)) + return op.Failed("لطفا تاریخ بدهی را وارد کنید"); + if (!debt.DebtDate.TryToGeorgianDateTime(out var debtDateGr)) + return op.Failed("تاریخ بدهی نامعتبر است"); + + if (debt.DebtFile is not { Length: > 0 } && debt.DebtFileMediaId <= 0) + return op.Failed("لطفا فایل بدهی را وارد کنید"); + + if (debt.DebtFile is { Length: > 20_000_000 }) + return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); + + var debtAmount = debt.Amount.MoneyToDouble(); + if (debtAmount <= 0) + return op.Failed("مبلغ بدهی نامعتبر است"); - public async Task ConfirmInsuranceOperation(InsuranceListConfirmOperation command) - { - // Improved version of the ConfirmInsuranceOperation method's main logic - async Task CreateMediaAsync(InsuranceList insuranceList, string insuranceType, IFormFile file) - { - var path = Path.Combine(_mediaRepository.BasePath, "InsuranceList", $"{insuranceList.Year}_{insuranceList.Month}", insuranceList.id.ToString()); - Directory.CreateDirectory(path); + var mediaId = command.Debt.DebtFileMediaId; + if (debt.DebtFile is { Length: > 0 }) + { + mediaId = await CreateMediaAsync(insuranceList, "debt", debt.DebtFile); + } - string uniqueFileName = $"{insuranceType}_{Path.GetFileNameWithoutExtension(file.FileName)}_{DateTime.Now.Ticks}{Path.GetExtension(file.FileName)}"; - string filePath = Path.Combine(path, uniqueFileName); + var debtEntity = new InsuranceListDebt(debt.Type, debtDateGr, debtAmount, mediaId); + insuranceList.SetDebt(debtEntity); + completeDebt = true; + } - await using (var stream = new FileStream(filePath, FileMode.Create)) - { - await file.CopyToAsync(stream); - } - var type = Path.GetExtension(filePath); - var media = new Media(filePath, type, "فایل", "InsuranceList"); - await _mediaRepository.CreateAsync(media); - await _mediaRepository.SaveChangesAsync(); - return media.id; - } + // Inspection Section + if (command.Inspection.Type != InsuranceListInspectionType.None) + { + var inspection = command.Inspection; + if (string.IsNullOrWhiteSpace(inspection.LastInspectionDate)) + return op.Failed("لطفا تاریخ بازرسی را وارد کنید"); - var op = new OperationResult(); - var insuranceList = _insuranceListRepositpry.Get(command.InsuranceListId); - if (insuranceList == null) - return op.Failed("لیست بیمه پیدا نشد"); + if (!inspection.LastInspectionDate.TryToGeorgianDateTime(out var inspectionDateGr)) + return op.Failed("تاریخ بازرسی نامعتبر است"); - bool completeDebt = false, completeInspection = false, completeApproval = false; + if (inspection.InspectionFile is not { Length: > 0 } && inspection.InspectionFileMediaId <= 0) + return op.Failed("لطفا فایل بازرسی را وارد کنید"); - // Debt Section - if (command.Debt.Type != InsuranceListDebtType.None) - { - var debt = command.Debt; - if (string.IsNullOrWhiteSpace(debt.DebtDate)) - return op.Failed("لطفا تاریخ بدهی را وارد کنید"); - if (!debt.DebtDate.TryToGeorgianDateTime(out var debtDateGr)) - return op.Failed("تاریخ بدهی نامعتبر است"); + if (inspection.InspectionFile is { Length: > 20_000_000 }) + return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); - if (debt.DebtFile is not { Length: > 0 }) - return op.Failed("لطفا فایل بدهی را وارد کنید"); - if (debt.DebtFile.Length > 20_000_000) - return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); + var mediaId = command.Debt.DebtFileMediaId; + if (inspection.InspectionFile is { Length: > 0 }) + { + mediaId = await CreateMediaAsync(insuranceList, "inspection", inspection.InspectionFile); + } + var inspectionEntity = new InsuranceListInspection(inspection.Type, inspectionDateGr, mediaId); + insuranceList.SetInspection(inspectionEntity); + completeInspection = true; + } - var debtAmount = debt.Amount.MoneyToDouble(); - if (debtAmount <= 0) - return op.Failed("مبلغ بدهی نامعتبر است"); + // Approval Section + if (command.Approval.ApprovalStatus != InsuranceListEmployerApprovalStatus.None) + { + var approval = command.Approval; + if (approval.ApprovalStatus == InsuranceListEmployerApprovalStatus.VerbalApproval) + { + if (string.IsNullOrWhiteSpace(approval.Description)) + return op.Failed("لطفا توضیحات را وارد کنید"); - var mediaId = await CreateMediaAsync(insuranceList, "debt", debt.DebtFile); - var debtEntity = new InsuranceListDebt(debt.Type, debtDateGr, debtAmount, mediaId); - insuranceList.SetDebt(debtEntity); - completeDebt = true; - } + if (approval.Description.Length < 15) + return op.Failed("توضیحات باید حداقل 15 کاراکتر باشد"); + } + var approvalEntity = new InsuranceListEmployerApproval(approval.ApprovalStatus, approval.Description); + insuranceList.SetEmployerApproval(approvalEntity); + completeApproval = true; + } - // Inspection Section - if (command.Inspection.Type != InsuraceListInspectionType.None) - { - var inspection = command.Inspection; - if (string.IsNullOrWhiteSpace(inspection.LastInspectionDate)) - return op.Failed("لطفا تاریخ بازرسی را وارد کنید"); + // Final Confirmation + if (command.ConfirmSentList) + { + if (!(completeApproval && completeDebt && completeInspection)) + return op.Failed("تا زمانی که تمامی بخش ها پر نشده باشد نمیتوانید لیست را ارسال کنید"); - if (!inspection.LastInspectionDate.TryToGeorgianDateTime(out var inspectionDateGr)) - return op.Failed("تاریخ بازرسی نامعتبر است"); + insuranceList.SetConfirmSentlist(true); + } - if (inspection.InspectionFile is not { Length: > 0 }) - return op.Failed("لطفا فایل بازرسی را وارد کنید"); + await _insuranceListRepositpry.SaveChangesAsync(); + return op.Succcedded(); - if (inspection.InspectionFile.Length > 20_000_000) - return op.Failed("حجم فایل نمیتواند از 20 مگابایت بیشتر باشد"); + } - var mediaId = await CreateMediaAsync(insuranceList, "inspection", inspection.InspectionFile); - var inspectionEntity = new InsuranceListInspection(inspection.Type, inspectionDateGr, mediaId); - insuranceList.SetInspection(inspectionEntity); - completeInspection = true; - } - // Approval Section - if (command.Approval.ApprovalStatus != InsuranceListEmployerApprovalStatus.None) - { - var approval = command.Approval; - if (approval.ApprovalStatus == InsuranceListEmployerApprovalStatus.VerbalApproval) - { - if (string.IsNullOrWhiteSpace(approval.Description)) - return op.Failed("لطفا توضیحات را وارد کنید"); + public Task GetInsuranceOperationDetails(long id) + { + return _insuranceListRepositpry.GetInsuranceOperationDetails(id); + } - if (approval.Description.Length < 15) - return op.Failed("توضیحات باید حداقل 15 کاراکتر باشد"); - } - var approvalEntity = new InsuranceListEmployerApproval(approval.ApprovalStatus, approval.Description); - insuranceList.SetEmployerApproval(approvalEntity); - completeApproval = true; - } + public Task GetTabCounts(long accountId, int month, int year) + { + return _insuranceListRepositpry.GetTabCounts(accountId, month, year); + } - // Final Confirmation - if (command.ConfirmSentList) - { - if (!(completeApproval && completeDebt && completeInspection)) - return op.Failed("تا زمانی که تمامی بخش ها پر نشده باشد نمیتوانید لیست را ارسال کنید"); - - insuranceList.SetConfirmSentlist(true); - } - - await _insuranceListRepositpry.SaveChangesAsync(); - return op.Succcedded(); - - } - #endregion + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Mapping/InsuranceListMapping.cs b/CompanyManagment.EFCore/Mapping/InsuranceListMapping.cs index 91fa7198..b89965e2 100644 --- a/CompanyManagment.EFCore/Mapping/InsuranceListMapping.cs +++ b/CompanyManagment.EFCore/Mapping/InsuranceListMapping.cs @@ -33,10 +33,12 @@ public class InsuranceListMapping : IEntityTypeConfiguration builder.ComplexProperty(x => x.EmployerApproval, approval => { - approval.IsRequired(); + approval.IsRequired(); approval.Property(x => x.Status).HasConversion().HasMaxLength(50); approval.Property(x => x.Description).HasMaxLength(500); }); + //builder.HasMany(x => x.EmployerSignatures) + // .WithOne(x => x.InsuranceList).HasForeignKey(x => x.InsuranceListId); } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index 1a2e51f0..d8e70d3d 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -1,10 +1,14 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.InfraStructure; +using AccountMangement.Infrastructure.EFCore; using Company.Domain.EmployeeAgg; using Company.Domain.EmployeeChildrenAgg; using Company.Domain.EmployeeInsurancListDataAgg; @@ -16,6 +20,7 @@ using CompanyManagment.App.Contracts.EmployeeInsurancListData; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.InsuranceWorkshopInfo; using CompanyManagment.App.Contracts.PersonalContractingParty; +using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Client; using PersianTools.Core; @@ -32,7 +37,10 @@ public class InsuranceListRepository : RepositoryBase, IIns private readonly IAuthHelper _authHelper; private readonly IPersonalContractingPartyApp _contractingPartyApp; private readonly IInsuranceYearlySalaryRepository _insuranceYearlySalaryRepository; - public InsuranceListRepository(CompanyContext context, IEmployeeInsurancListDataRepository employeeInsurancListDataRepository, IInsuranceListWorkshopRepository insuranceListWorkshopRepository , IInsuranceWorkshopInfoRepository insuranceWorkshopInfoRepository, IAuthHelper authHelper, IPersonalContractingPartyApp contractingPartyApp, IInsuranceYearlySalaryRepository insuranceYearlySalaryRepository) : base(context) + private readonly IWebHostEnvironment _webHostEnvironment; + private readonly AccountContext _accountContext; + + public InsuranceListRepository(CompanyContext context, IEmployeeInsurancListDataRepository employeeInsurancListDataRepository, IInsuranceListWorkshopRepository insuranceListWorkshopRepository, IInsuranceWorkshopInfoRepository insuranceWorkshopInfoRepository, IAuthHelper authHelper, IPersonalContractingPartyApp contractingPartyApp, IInsuranceYearlySalaryRepository insuranceYearlySalaryRepository, IWebHostEnvironment webHostEnvironment, AccountContext accountContext) : base(context) { _context = context; _employeeInsurancListDataRepository = employeeInsurancListDataRepository; @@ -41,20 +49,22 @@ public class InsuranceListRepository : RepositoryBase, IIns _authHelper = authHelper; _contractingPartyApp = contractingPartyApp; _insuranceYearlySalaryRepository = insuranceYearlySalaryRepository; + _webHostEnvironment = webHostEnvironment; + _accountContext = accountContext; } public OperationResult CreateInsuranceListworkshop(long id, List workshopIds) { var operation = new OperationResult(); //try //{ - var list= new List(); + var list = new List(); foreach (var item in workshopIds) { list.Add(new InsuranceListWorkshop() { - WorkshopId =item, - InsurancListId= id + WorkshopId = item, + InsurancListId = id }); } @@ -76,11 +86,11 @@ public class InsuranceListRepository : RepositoryBase, IIns public OperationResult CreateInsuranceListworkshopInfo(CreateInsuranceWorkshopInfo command) { var operation = new OperationResult(); - - var obj = _context.InsuranceWorkshopInformationSet.Where(x=>x.WorkshopId== command.WorkshopId).FirstOrDefault(); + + var obj = _context.InsuranceWorkshopInformationSet.Where(x => x.WorkshopId == command.WorkshopId).FirstOrDefault(); if (obj != null) { - obj.Edit(command.WorkshopName, command.InsuranceCode, command.AgreementNumber, command.EmployerName, command.Address,command.ListNumber); + obj.Edit(command.WorkshopName, command.InsuranceCode, command.AgreementNumber, command.EmployerName, command.Address, command.ListNumber); _context.SaveChanges(); } else @@ -91,7 +101,7 @@ public class InsuranceListRepository : RepositoryBase, IIns _context.SaveChanges(); } - + return operation; } @@ -103,9 +113,9 @@ public class InsuranceListRepository : RepositoryBase, IIns try { var insuranceListObj = Get(command.Id); - insuranceListObj.Edit(command.SumOfEmployees,command.SumOfWorkingDays,command.SumOfSalaries,command.SumOfBenefitsIncluded,command.Included,command.IncludedAndNotIncluded,command.InsuredShare, - command.EmployerShare,command.UnEmploymentInsurance,command.DifficultJobsInsuranc,command.StartDate,command.SumOfDailyWage,command.SumOfBaseYears,command.SumOfMarriedAllowance, command.ConfirmSentlist); - + insuranceListObj.Edit(command.SumOfEmployees, command.SumOfWorkingDays, command.SumOfSalaries, command.SumOfBenefitsIncluded, command.Included, command.IncludedAndNotIncluded, command.InsuredShare, + command.EmployerShare, command.UnEmploymentInsurance, command.DifficultJobsInsuranc, command.StartDate, command.SumOfDailyWage, command.SumOfBaseYears, command.SumOfMarriedAllowance, command.ConfirmSentlist); + var id = insuranceListObj.id; if (command.EmployeeInsurancListDataList != null && command.EmployeeInsurancListDataList.Count > 0) { @@ -121,14 +131,14 @@ public class InsuranceListRepository : RepositoryBase, IIns item.BenefitsIncludedContinuous, item.BenefitsIncludedNonContinuous, item.InsuranceShare, item.StartWorkDate, - item.LeftWorkDate, item.JobId,item.IncludeStatus,item.BaseYears,item.MarriedAllowance,item.OverTimePay,item.FamilyAllowance); + item.LeftWorkDate, item.JobId, item.IncludeStatus, item.BaseYears, item.MarriedAllowance, item.OverTimePay, item.FamilyAllowance); _employeeInsurancListDataRepository.Create(employeeInsurancListData); } else { var employeeInsurancListDataObj = _employeeInsurancListDataRepository.Get(item.EmployeeInsurancListDataId); - employeeInsurancListDataObj.Edit(item.WorkingDays,item.DailyWage,item.MonthlySalary,item.MonthlyBenefits,item .MonthlyBenefitsIncluded,item.BenefitsIncludedContinuous, - item.BenefitsIncludedNonContinuous,item.InsuranceShare,item.StartWorkDate,item.LeftWorkDate,item.JobId,item.IncludeStatus,item.BaseYears,item.MarriedAllowance,item.OverTimePay,item.FamilyAllowance); + employeeInsurancListDataObj.Edit(item.WorkingDays, item.DailyWage, item.MonthlySalary, item.MonthlyBenefits, item.MonthlyBenefitsIncluded, item.BenefitsIncludedContinuous, + item.BenefitsIncludedNonContinuous, item.InsuranceShare, item.StartWorkDate, item.LeftWorkDate, item.JobId, item.IncludeStatus, item.BaseYears, item.MarriedAllowance, item.OverTimePay, item.FamilyAllowance); } } _employeeInsurancListDataRepository.SaveChanges(); @@ -210,7 +220,7 @@ public class InsuranceListRepository : RepositoryBase, IIns // نام کارفرما EmployerName = x.EmployerName, //آدرس کارگاه - Address = x.Address, + Address = x.Address, ListNumber = x.ListNumber, }).FirstOrDefault(); #endregion @@ -234,7 +244,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //مزایای ماهانه employeeInsurancListData.MonthlyBenefits = item.MonthlyBenefits; //دستمزد و مزایای ماهانه مشمول - employeeInsurancListData.MonthlyBenefitsIncluded =item.MonthlyBenefitsIncluded; + employeeInsurancListData.MonthlyBenefitsIncluded = item.MonthlyBenefitsIncluded; // مزایای مشمول و غیر مشمول employeeInsurancListData.BenefitsIncludedContinuous = item.BenefitsIncludedContinuous; //مزایای مشمول غیر مستمر @@ -252,8 +262,8 @@ public class InsuranceListRepository : RepositoryBase, IIns employeeInsurancListData.JobName = job != null ? job.JobName : string.Empty; ; employeeInsurancListData.JobCode = job != null ? job.JobCode : string.Empty; ; employeeInsurancListData.StrStartWorkDate = item.StartWorkDate.ToFarsi(); - - if(item.LeftWorkDate!=null) + + if (item.LeftWorkDate != null) employeeInsurancListData.StrLeftWorkDate = item.LeftWorkDate.ToFarsi(); @@ -266,7 +276,7 @@ public class InsuranceListRepository : RepositoryBase, IIns #endregion #region WorkshopIds - var workshopIds = _context.InsuranceListWorkshopSet.Where(x=>x.InsurancListId==id).Select(x => x.WorkshopId).ToList(); + var workshopIds = _context.InsuranceListWorkshopSet.Where(x => x.InsurancListId == id).Select(x => x.WorkshopId).ToList(); #endregion #region InsuranceEmployeeInformation @@ -286,7 +296,7 @@ public class InsuranceListRepository : RepositoryBase, IIns employeeDetails.DateOfBirthGr = item.DateOfBirth; employeeDetails.DateOfIssueGr = item.DateOfIssue; employeeDetails.DateOfBirth = item.DateOfBirth.ToFarsi(); - employeeDetails.DateOfIssue = ((item.DateOfIssue.ToFarsi())=="1300/10/11")?"": item.DateOfIssue.ToFarsi(); + employeeDetails.DateOfIssue = ((item.DateOfIssue.ToFarsi()) == "1300/10/11") ? "" : item.DateOfIssue.ToFarsi(); employeeDetails.PlaceOfIssue = item.PlaceOfIssue; employeeDetails.NationalCode = item.NationalCode; //employeeDetails.Nationality = item.Nationality; @@ -329,7 +339,7 @@ public class InsuranceListRepository : RepositoryBase, IIns public List OptimizedSearch(InsuranceListSearchModel searchModel) { - + var acountId = _authHelper.CurrentAccountId(); var workshopIds = _context.WorkshopAccounts.Where(x => x.AccountId == acountId).Select(x => x.WorkshopId); @@ -380,7 +390,7 @@ public class InsuranceListRepository : RepositoryBase, IIns result => result.workshop.id, employer => employer.WorkshopId, (result, employer) => new { result.insurance, result.workshop, employer }) - .Select(result => new InsuranceListViewModel + .Select(result => new InsuranceListViewModel { Id = result.insurance.id, Year = result.insurance.Year, @@ -402,9 +412,27 @@ public class InsuranceListRepository : RepositoryBase, IIns .Where(p => p.Employers.Any(e => e.id == result.employer.First().EmployerId)) .Select(p => p.IsBlock) .FirstOrDefault(), - EmployerId = result.employer.First().EmployerId + EmployerId = result.employer.First().EmployerId, + DebtDone = result.insurance.Debt.IsDone, + EmployerApproved = result.insurance.EmployerApproval.IsDone, + InspectionDone = result.insurance.Inspection.IsDone }); + query = searchModel.Status switch + { + InsuranceListSearchStatus.NotStarted => query.Where(x => + !x.DebtDone && !x.EmployerApproved && !x.InspectionDone && !x.ConfirmSentlist), + + InsuranceListSearchStatus.InProgress => query.Where(x => + (x.DebtDone || x.EmployerApproved || x.InspectionDone)&& !(x.DebtDone && x.EmployerApproved && x.InspectionDone) && !x.ConfirmSentlist), + + InsuranceListSearchStatus.ReadyToSendList => query.Where(x => + x.DebtDone && x.EmployerApproved && x.InspectionDone && !x.ConfirmSentlist), + + InsuranceListSearchStatus.Done => query.Where(x => x.ConfirmSentlist), + + _ => query + }; if (!string.IsNullOrEmpty(searchModel.Year) && searchModel.Year != "0" && !string.IsNullOrEmpty(searchModel.Month) && searchModel.Month != "0") query = query.Where(x => x.Year == searchModel.Year && x.Month == searchModel.Month).OrderByDescending(x => x.Id); @@ -456,7 +484,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //var testquery = query.Where(x => x.Year == searchModel.Year).AsEnumerable(); - return query.ToList(); + return query.Skip(searchModel.PageIndex).Take(30).ToList(); } public List Search(InsuranceListSearchModel searchModel) { @@ -465,9 +493,9 @@ public class InsuranceListRepository : RepositoryBase, IIns var acountID = _authHelper.CurrentAccountId(); var workshopIds = _context.WorkshopAccounts.Where(x => x.AccountId == acountID).Select(x => x.WorkshopId).ToList(); List list = new List(); - var query = _context.InsuranceListSet.Where(x=> workshopIds.Contains(x.WorkshopId)).ToList(); + var query = _context.InsuranceListSet.Where(x => workshopIds.Contains(x.WorkshopId)).ToList(); var insuranceWorkshopInformationList = _context.InsuranceWorkshopInformationSet.Where(u => workshopIds.Contains(u.WorkshopId)); - var workshopList = _context.Workshops.Where(u => workshopIds.Contains(u.id)); + var workshopList = _context.Workshops.Where(u => workshopIds.Contains(u.id)); foreach (var item in query) { @@ -475,7 +503,7 @@ public class InsuranceListRepository : RepositoryBase, IIns var workshop = workshopList.FirstOrDefault(u => u.id == item.WorkshopId); var employerId = _context.WorkshopEmployers.Where(x => x.WorkshopId == item.WorkshopId) .Select(x => x.EmployerId).FirstOrDefault(); - + string typeOfInsuranceSend = ""; if (workshop.TypeOfInsuranceSend == "NormalList") { @@ -489,20 +517,20 @@ public class InsuranceListRepository : RepositoryBase, IIns { typeOfInsuranceSend = "خانوادگی"; } - - var insuranceListViewModel =new InsuranceListViewModel() + + var insuranceListViewModel = new InsuranceListViewModel() { Id = item.id, Year = item.Year, Month = item.Month, MonthNumber = item.Month, - WorkShopCode = insuranceWorkshopInformation==null? workshop.InsuranceCode: insuranceWorkshopInformation.InsuranceCode, + WorkShopCode = insuranceWorkshopInformation == null ? workshop.InsuranceCode : insuranceWorkshopInformation.InsuranceCode, WorkShopName = insuranceWorkshopInformation == null ? workshop.WorkshopName : insuranceWorkshopInformation.WorkshopName, - WorkShopId = workshop.id , + WorkShopId = workshop.id, TypeOfInsuranceSend = typeOfInsuranceSend, FixedSalary = workshop.FixedSalary, - StrFixedSalary = workshop.FixedSalary?"دارد":"ندارد", - EmployerName = insuranceWorkshopInformation == null? workshop.WorkshopFullName: insuranceWorkshopInformation.EmployerName, + StrFixedSalary = workshop.FixedSalary ? "دارد" : "ندارد", + EmployerName = insuranceWorkshopInformation == null ? workshop.WorkshopFullName : insuranceWorkshopInformation.EmployerName, Branch = "", City = "", ConfirmSentlist = item.ConfirmSentlist, @@ -530,7 +558,7 @@ public class InsuranceListRepository : RepositoryBase, IIns list = list.Where(x => x.WorkShopCode == searchModel.WorkShopCode).OrderByDescending(x => x.Year).OrderByDescending(x => x.Month).ThenByDescending(x => x.EmployerName).ToList(); if (!string.IsNullOrEmpty(searchModel.WorkShopName)) - list = list.Where(x => x.WorkShopName.Contains(searchModel.WorkShopName) ).OrderByDescending(x => x.EmployerName).ThenByDescending(x => x.Year).OrderByDescending(x => x.Month).ToList(); + list = list.Where(x => x.WorkShopName.Contains(searchModel.WorkShopName)).OrderByDescending(x => x.EmployerName).ThenByDescending(x => x.Year).OrderByDescending(x => x.Month).ToList(); if (searchModel.WorkshopId > 0) @@ -553,7 +581,7 @@ public class InsuranceListRepository : RepositoryBase, IIns list = list.Where(x => x.EmployerName.Contains(searchModel.EmployerName)).OrderByDescending(x => x.EmployerName).ThenByDescending(x => x.Year).OrderByDescending(x => x.Month).ToList(); - if (searchModel.FixedSalary!=null) + if (searchModel.FixedSalary != null) list = list.Where(x => x.FixedSalary == searchModel.FixedSalary).ToList(); if (!string.IsNullOrEmpty(searchModel.TypeOfInsuranceSend) && searchModel.TypeOfInsuranceSend != "0") @@ -574,7 +602,7 @@ public class InsuranceListRepository : RepositoryBase, IIns OperationResult result = new OperationResult(); using (var transaction = _context.Database.BeginTransaction()) { - + try { //var employeeInsurancList= _context.EmployeeInsurancListDataSet.Where(x => x.InsuranceListId == id).ToList(); @@ -584,10 +612,10 @@ public class InsuranceListRepository : RepositoryBase, IIns //var insuranceListWorkshopList = _context.InsuranceListWorkshopSet.Where(x => x.InsurancListId == id).ToList(); //if (insuranceListWorkshopList != null && insuranceListWorkshopList.Count > 0) _insuranceListWorkshopRepository.RemoveRange(id); - + var insuranceListObj = _context.InsuranceListSet.Where(x => x.id == id).FirstOrDefault(); - if(insuranceListObj!=null) + if (insuranceListObj != null) Remove(insuranceListObj); SaveChanges(); @@ -606,11 +634,11 @@ public class InsuranceListRepository : RepositoryBase, IIns return result; } - /// - /// ایجاد لیست بیمه - /// - /// - /// + /// + /// ایجاد لیست بیمه + /// + /// + /// public OperationResult CreateInsuranceList(CreateInsuranceList command) { OperationResult result = new OperationResult(); @@ -625,7 +653,7 @@ public class InsuranceListRepository : RepositoryBase, IIns command.InsuredShare, command.EmployerShare, command.UnEmploymentInsurance, command.DifficultJobsInsuranc, command.StartDate, - command.EndDate, command.SumOfDailyWage,command.SumOfBaseYears,command.SumOfMarriedAllowance); + command.EndDate, command.SumOfDailyWage, command.SumOfBaseYears, command.SumOfMarriedAllowance); Create(insuranceListObj); SaveChanges(); var id = insuranceListObj.id; @@ -641,10 +669,11 @@ public class InsuranceListRepository : RepositoryBase, IIns item.BenefitsIncludedContinuous, item.BenefitsIncludedNonContinuous, item.InsuranceShare, item.StartWorkDate, - item.LeftWorkDate, item.JobId,item.IncludeStatus,item.BaseYears,item.MarriedAllowance,item.OverTimePay,item.FamilyAllowance); + item.LeftWorkDate, item.JobId, item.IncludeStatus, item.BaseYears, item.MarriedAllowance, item.OverTimePay, item.FamilyAllowance); _employeeInsurancListDataRepository.Create(employeeInsurancListData); - - }_employeeInsurancListDataRepository.SaveChanges(); + + } + _employeeInsurancListDataRepository.SaveChanges(); } if (command.WorkshopIds != null && command.WorkshopIds.Count > 0) @@ -831,10 +860,10 @@ public class InsuranceListRepository : RepositoryBase, IIns editInsuranceList.WorkshopIds = workshopIds; return editInsuranceList; - + } - public MainEmployeeDetailsViewModel SearchEmployeeListForEditByInsuranceListId(EmployeeForEditInsuranceListSearchModel searchModel ) + public MainEmployeeDetailsViewModel SearchEmployeeListForEditByInsuranceListId(EmployeeForEditInsuranceListSearchModel searchModel) { var employeeDetailsViewModel = new MainEmployeeDetailsViewModel(); @@ -845,7 +874,7 @@ public class InsuranceListRepository : RepositoryBase, IIns { var leftWorkInsurance = _context.LeftWorkInsuranceList .Where(i => i.EmployeeId == item.EmployeeId && i.WorkshopId == searchModel.WorkshopId) - .AsNoTracking().OrderByDescending(x=>x.id).FirstOrDefault(); + .AsNoTracking().OrderByDescending(x => x.id).FirstOrDefault(); var job = _context.Jobs.Where(i => i.id == item.JobId).AsNoTracking().FirstOrDefault(); var employeeInsurancListData = new EmployeeInsurancListDataViewModel(); employeeInsurancListData.EmployeeInsurancListDataId = item.id; @@ -866,7 +895,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //// مزایای ماهیانه مشمول employeeInsurancListData.BenefitsIncludedNonContinuous = item.BenefitsIncludedNonContinuous; //// حقوق و مزایای ماهیانه مشمول و غیر مشمول ** - employeeInsurancListData.IncludedAndNotIncluded = item.BenefitsIncludedContinuous; + employeeInsurancListData.IncludedAndNotIncluded = item.BenefitsIncludedContinuous; employeeInsurancListData.BaseYears = item.BaseYears; employeeInsurancListData.MarriedAllowance = item.MarriedAllowance; @@ -875,7 +904,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //سهم بیمه حق کارگر employeeInsurancListData.InsuranceShare = item.InsuranceShare; // تاریخ شروع به کار - employeeInsurancListData.StartWorkDate =item.StartWorkDate; + employeeInsurancListData.StartWorkDate = item.StartWorkDate; //تاریخ ترک کار employeeInsurancListData.LeftWorkDate = item.LeftWorkDate; // آی دی شغل @@ -883,7 +912,7 @@ public class InsuranceListRepository : RepositoryBase, IIns employeeInsurancListData.JobName = job != null ? job.JobName : string.Empty; employeeInsurancListData.JobCode = job != null ? job.JobCode : string.Empty; employeeInsurancListData.StrStartWorkDate = item.StartWorkDate.ToFarsi(); - + if (item.LeftWorkDate != null) employeeInsurancListData.StrLeftWorkDate = item.LeftWorkDate.ToFarsi(); @@ -893,7 +922,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //ممکن است کسی شامل مزایا باشد و در آن ماه برایش یا مزد روزانه رد نشده باشد // باید با یک فیلد چک شود // - if (leftWorkInsurance != null && ((leftWorkInsurance.IncludeStatus!=leftWorkInsurance.IncludeStatus ) || ((leftWorkInsurance.LeftWorkDate!=item.LeftWorkDate)||(leftWorkInsurance.StartWorkDate != item.StartWorkDate ) ||(leftWorkInsurance.JobId != item.JobId)))) + if (leftWorkInsurance != null && ((leftWorkInsurance.IncludeStatus != leftWorkInsurance.IncludeStatus) || ((leftWorkInsurance.LeftWorkDate != item.LeftWorkDate) || (leftWorkInsurance.StartWorkDate != item.StartWorkDate) || (leftWorkInsurance.JobId != item.JobId)))) { employeeInsurancListData.HasConfilictLeftWork = true; if (leftWorkInsurance.LeftWorkDate != null) @@ -924,7 +953,7 @@ public class InsuranceListRepository : RepositoryBase, IIns var employeeDetailsForInsuranceList = new List(); foreach (var item in insuranceEmployeeInformationList) { - var employeeObject = _context.Employees.Where(x=>x.id==item.EmployeeId)?.FirstOrDefault(); + var employeeObject = _context.Employees.Where(x => x.id == item.EmployeeId)?.FirstOrDefault(); var employeeInsurancListData = employeeInsurancListDataViewModelList.Where(x => x.EmployeeId == item.EmployeeId)?.FirstOrDefault(); var employeeDetails = new EmployeeDetailsForInsuranceListViewModel(); employeeDetails.EmployeeId = item.EmployeeId; @@ -993,13 +1022,13 @@ public class InsuranceListRepository : RepositoryBase, IIns public OperationResult ConfirmInsuranceList(long id) { OperationResult result = new OperationResult(); - + try { var insuranceListObj = Get(id); insuranceListObj.Edit(insuranceListObj.SumOfEmployees, insuranceListObj.SumOfWorkingDays, insuranceListObj.SumOfSalaries, insuranceListObj.SumOfBenefitsIncluded, insuranceListObj.Included, insuranceListObj.IncludedAndNotIncluded, insuranceListObj.InsuredShare, - insuranceListObj.EmployerShare, insuranceListObj.UnEmploymentInsurance, insuranceListObj.DifficultJobsInsuranc, insuranceListObj.StartDate, insuranceListObj.SumOfDailyWage,insuranceListObj.SumOfBaseYears,insuranceListObj.SumOfMarriedAllowance,true); + insuranceListObj.EmployerShare, insuranceListObj.UnEmploymentInsurance, insuranceListObj.DifficultJobsInsuranc, insuranceListObj.StartDate, insuranceListObj.SumOfDailyWage, insuranceListObj.SumOfBaseYears, insuranceListObj.SumOfMarriedAllowance, true); SaveChanges(); @@ -1009,9 +1038,9 @@ public class InsuranceListRepository : RepositoryBase, IIns { result.Message = "تایید ارسال لیست بیمه با موفقیت انجام شد"; - + } - + return result; } @@ -1020,7 +1049,7 @@ public class InsuranceListRepository : RepositoryBase, IIns { var insuranceListViewModel = new InsuranceListViewModel(); - var insuranceList = _context.InsuranceListSet.Where(x => x.WorkshopId == workshopId && x.Year == year).OrderByDescending(x=>x.id)?.FirstOrDefault(); + var insuranceList = _context.InsuranceListSet.Where(x => x.WorkshopId == workshopId && x.Year == year).OrderByDescending(x => x.id)?.FirstOrDefault(); if (insuranceList != null) { @@ -1031,7 +1060,7 @@ public class InsuranceListRepository : RepositoryBase, IIns insuranceListViewModel.WorkShopId = insuranceList.WorkshopId; insuranceListViewModel.ConfirmSentlist = insuranceList.ConfirmSentlist; } - return insuranceListViewModel; + return insuranceListViewModel; } #region client @@ -1113,11 +1142,46 @@ public class InsuranceListRepository : RepositoryBase, IIns default: return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).ToList(); } } + + public async Task GetInsuranceOperationDetails(long id) + { + var res = await _context.InsuranceListSet.Select(x => new InsuranceListConfirmOperation() + { + InsuranceListId = x.id, + Approval = new CreateInsuranceListApproval() + { + ApprovalStatus = x.EmployerApproval.Status, + Description = x.EmployerApproval.Description, + }, + Debt = new CreateInsuranceListDebt() + { + Amount = x.Debt.Amount.ToMoney(), + DebtDate = x.Debt.DebtDate.ToFarsi(), + DebtFileMediaId = x.Debt.MediaId, + Type = x.Debt.Type + }, + Inspection = new CreateInsuranceListInspection() + { + Type = x.Inspection.Type, + InspectionFileMediaId = x.Inspection.MediaId, + LastInspectionDate = x.Inspection.LastInspectionDateTime.ToFarsi() + }, + ConfirmSentList = x.ConfirmSentlist, + }).FirstOrDefaultAsync(x => x.InsuranceListId == id); + + res.Inspection.FilePath = GetInsuranceListFilePath(res.Inspection.InspectionFileMediaId); + res.Debt.FilePath = GetInsuranceListFilePath(res.Debt.DebtFileMediaId); + return res; + } + + + + public List SearchForClientOld(InsuranceListSearchModel searchModel) { List list = new List(); - var query = _context.InsuranceListSet.Where(x=>x.WorkshopId== searchModel.WorkshopId).ToList(); + var query = _context.InsuranceListSet.Where(x => x.WorkshopId == searchModel.WorkshopId).ToList(); foreach (var item in query) { var insuranceWorkshopInformation = _context.InsuranceWorkshopInformationSet.FirstOrDefault(u => u.WorkshopId == item.WorkshopId); @@ -1194,16 +1258,16 @@ public class InsuranceListRepository : RepositoryBase, IIns #endregion - public (int insuranceHistoryYearsCount, double baseYear) GetEmployeeInsuranceBaseYear(long employeeId, long workshopId, int countWorkingDay,DateTime listStartDate, DateTime listEndDate, DateTime startWorkDate, DateTime leftDate, bool hasLeft) + public (int insuranceHistoryYearsCount, double baseYear) GetEmployeeInsuranceBaseYear(long employeeId, long workshopId, int countWorkingDay, DateTime listStartDate, DateTime listEndDate, DateTime startWorkDate, DateTime leftDate, bool hasLeft) { - - + + var lefts = _context.LeftWorkInsuranceList - .Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x=> new + .Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).Select(x => new { - startWork = x.StartWorkDate, - leftWork = x.LeftWorkDate == null ? listStartDate : x.LeftWorkDate.Value, - }).OrderBy(x=>x.startWork).ToList(); + startWork = x.StartWorkDate, + leftWork = x.LeftWorkDate == null ? listStartDate : x.LeftWorkDate.Value, + }).OrderBy(x => x.startWork).ToList(); int countDay = 0; foreach (var left in lefts) { @@ -1212,12 +1276,12 @@ public class InsuranceListRepository : RepositoryBase, IIns //شمارش فقط تا روز قبل از شروع لیست انجام شود if (left.leftWork >= listStartDate) { - var endBeforStartList = new DateTime(listStartDate.Year, listStartDate.Month, listStartDate.Day); - end = endBeforStartList.AddDays(-1).ToPersianDateTime(); - } - - - var count = (int)(end - start).TotalDays +1; + var endBeforStartList = new DateTime(listStartDate.Year, listStartDate.Month, listStartDate.Day); + end = endBeforStartList.AddDays(-1).ToPersianDateTime(); + } + + + var count = (int)(end - start).TotalDays + 1; countDay += count; } @@ -1226,12 +1290,12 @@ public class InsuranceListRepository : RepositoryBase, IIns //تعداد سال های سابقه بیمه int yearsCount = countDay / 365; - + //بدست آوردن مزد سنوات بر اساس سابقه به سال var baseYear = _insuranceYearlySalaryRepository.GetBaseYearByDate(listStartDate, yearsCount); - if(baseYear == 0) + if (baseYear == 0) return (0, 0); - + //اگر ترک کار کرده بود //یا @@ -1250,7 +1314,7 @@ public class InsuranceListRepository : RepositoryBase, IIns //} - + return (yearsCount, baseYear); } @@ -1278,109 +1342,109 @@ public class InsuranceListRepository : RepositoryBase, IIns public List GetEmployeeInsuranceDataForEdit(long insuranceListId, DateTime startDate, DateTime endDate) { - - var res = _context.EmployeeInsurancListDataSet - .Where(x => x.InsuranceListId == insuranceListId) - .Join(_context.LeftWorkInsuranceList - .Where(x => - ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && - ((DateTime)x.LeftWorkDate >= startDate && - (DateTime)x.LeftWorkDate <= endDate)) || - ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && - (DateTime)x.LeftWorkDate >= endDate) || - (x.LeftWorkDate == null || x.LeftWorkDate == DateTime.MinValue)) - .Where(x => x.StartWorkDate <= endDate) - .Include(x => x.Employee), - employeeData => employeeData.EmployeeId, - leftwork => leftwork.EmployeeId, - (employeeData, leftwork) => new { employeeData, leftwork }) - .Join(_context.Jobs, - result => result.leftwork.JobId, - job => job.id, - (result, job) => new { result, job }) - .GroupJoin(_context.InsuranceEmployeeInformationSet.AsSplitQuery(), - allResult => allResult.result.employeeData.EmployeeId, - employeeInfo => employeeInfo.EmployeeId, - (allResult, employeeInfo) => new - { - allResult.result, - allResult.job, - employeeInfo - }) - .SelectMany(x => x.employeeInfo.DefaultIfEmpty(), (x, employeeInfo) => new { x, employeeInfo }) - .Select(result => new EmployeeDetailsForInsuranceListViewModel - { - StartWorkDateNew = result.x.result.leftwork.StartWorkDate, - LeftWorkDateNew = result.x.result.leftwork.LeftWorkDate, - JobIdNew = result.x.result.leftwork.JobId, - - StartWorkDateGr = result.x.result.leftwork.StartWorkDate, - LeftWorkDateGr = result.x.result.leftwork.LeftWorkDate, - IncludeStatus = result.x.result.employeeData.IncludeStatus, - JobId = result.x.result.employeeData.JobId, - JobName = result.x.job != null ? result.x.job.JobName : string.Empty, - JobCode = result.x.job != null ? result.x.job.JobCode : string.Empty, - InsuranceEmployeeInformationId = result.employeeInfo != null ? result.employeeInfo.id : 0, - EmployeeId = result.x.result.employeeData.EmployeeId, - - //اطلاعات هویتی - FName = result.employeeInfo != null ? result.employeeInfo.FName : result.x.result.leftwork.Employee.FName, - LName = result.employeeInfo != null ? result.employeeInfo.LName : result.x.result.leftwork.Employee.LName, - FatherName = result.employeeInfo != null ? result.employeeInfo.FatherName : result.x.result.leftwork.Employee.FatherName, - DateOfBirthGr = result.employeeInfo != null ? result.employeeInfo.DateOfBirth : result.x.result.leftwork.Employee.DateOfBirth, - DateOfIssueGr = result.employeeInfo != null ? result.employeeInfo.DateOfIssue : result.x.result.leftwork.Employee.DateOfIssue, - PlaceOfIssue = result.employeeInfo != null ? result.employeeInfo.PlaceOfIssue : result.x.result.leftwork.Employee.PlaceOfIssue, - IdNumber = result.employeeInfo != null ? result.employeeInfo.IdNumber : result.x.result.leftwork.Employee.IdNumber, - Gender = result.employeeInfo != null ? result.employeeInfo.Gender : result.x.result.leftwork.Employee.Gender, - NationalCode = result.x.result.leftwork.Employee.NationalCode, - Nationality = result.x.result.leftwork.Employee.Nationality, - InsuranceCode = result.x.result.leftwork.Employee.InsuranceCode, - MaritalStatus = result.x.result.leftwork.Employee.MaritalStatus, - IsMaritalStatusSet = !string.IsNullOrWhiteSpace(result.x.result.leftwork.Employee.MaritalStatus), - - //اطاعات محاسباتی - EmployeeInsurancListDataId = result.x.result.employeeData.id, - DailyWage = result.x.result.employeeData.DailyWage, - // LeftWorkDateGr = x.LeftWorkDate, - // StartWorkDateGr = x.StartWorkDate, - MonthlyBenefitsIncluded = result.x.result.employeeData.MonthlyBenefitsIncluded, - // JobId = x.JobId, - WorkingDays = result.x.result.employeeData.WorkingDays, - //پایه سنوات - BaseYears = result.x.result.employeeData.BaseYears, - - //مجموع مزد روزانه و پایه سنوات - DailyWagePlusBaseYears = result.x.result.employeeData.DailyWagePlusBaseYears, - - //حق تاهل - MarriedAllowance = result.x.result.employeeData.MarriedAllowance, - - //دستمزد ماهانه - MonthlySalary = result.x.result.employeeData.MonthlySalary, + var res = _context.EmployeeInsurancListDataSet + .Where(x => x.InsuranceListId == insuranceListId) + .Join(_context.LeftWorkInsuranceList + .Where(x => + ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && + ((DateTime)x.LeftWorkDate >= startDate && + (DateTime)x.LeftWorkDate <= endDate)) || + ((x.LeftWorkDate != null && x.LeftWorkDate != DateTime.MinValue) && + (DateTime)x.LeftWorkDate >= endDate) || + (x.LeftWorkDate == null || x.LeftWorkDate == DateTime.MinValue)) + .Where(x => x.StartWorkDate <= endDate) + .Include(x => x.Employee), + employeeData => employeeData.EmployeeId, + leftwork => leftwork.EmployeeId, + (employeeData, leftwork) => new { employeeData, leftwork }) + .Join(_context.Jobs, + result => result.leftwork.JobId, + job => job.id, + (result, job) => new { result, job }) + .GroupJoin(_context.InsuranceEmployeeInformationSet.AsSplitQuery(), + allResult => allResult.result.employeeData.EmployeeId, + employeeInfo => employeeInfo.EmployeeId, + (allResult, employeeInfo) => new + { + allResult.result, + allResult.job, + employeeInfo + }) + .SelectMany(x => x.employeeInfo.DefaultIfEmpty(), (x, employeeInfo) => new { x, employeeInfo }) + .Select(result => new EmployeeDetailsForInsuranceListViewModel + { + StartWorkDateNew = result.x.result.leftwork.StartWorkDate, + LeftWorkDateNew = result.x.result.leftwork.LeftWorkDate, + JobIdNew = result.x.result.leftwork.JobId, - //مزایای ماهانه - MonthlyBenefits = result.x.result.employeeData.MonthlyBenefits, + StartWorkDateGr = result.x.result.leftwork.StartWorkDate, + LeftWorkDateGr = result.x.result.leftwork.LeftWorkDate, + IncludeStatus = result.x.result.employeeData.IncludeStatus, + JobId = result.x.result.employeeData.JobId, + JobName = result.x.job != null ? result.x.job.JobName : string.Empty, + JobCode = result.x.job != null ? result.x.job.JobCode : string.Empty, + InsuranceEmployeeInformationId = result.employeeInfo != null ? result.employeeInfo.id : 0, + EmployeeId = result.x.result.employeeData.EmployeeId, - //مزایای مشمول - BenefitsIncludedContinuous = result.x.result.employeeData.MonthlyBenefitsIncluded, + //اطلاعات هویتی + FName = result.employeeInfo != null ? result.employeeInfo.FName : result.x.result.leftwork.Employee.FName, + LName = result.employeeInfo != null ? result.employeeInfo.LName : result.x.result.leftwork.Employee.LName, + FatherName = result.employeeInfo != null ? result.employeeInfo.FatherName : result.x.result.leftwork.Employee.FatherName, + DateOfBirthGr = result.employeeInfo != null ? result.employeeInfo.DateOfBirth : result.x.result.leftwork.Employee.DateOfBirth, + DateOfIssueGr = result.employeeInfo != null ? result.employeeInfo.DateOfIssue : result.x.result.leftwork.Employee.DateOfIssue, + PlaceOfIssue = result.employeeInfo != null ? result.employeeInfo.PlaceOfIssue : result.x.result.leftwork.Employee.PlaceOfIssue, + IdNumber = result.employeeInfo != null ? result.employeeInfo.IdNumber : result.x.result.leftwork.Employee.IdNumber, + Gender = result.employeeInfo != null ? result.employeeInfo.Gender : result.x.result.leftwork.Employee.Gender, + NationalCode = result.x.result.leftwork.Employee.NationalCode, + Nationality = result.x.result.leftwork.Employee.Nationality, + InsuranceCode = result.x.result.leftwork.Employee.InsuranceCode, + MaritalStatus = result.x.result.leftwork.Employee.MaritalStatus, + IsMaritalStatusSet = !string.IsNullOrWhiteSpace(result.x.result.leftwork.Employee.MaritalStatus), - //مزایای غیر مشمول - BenefitsIncludedNonContinuous = result.x.result.employeeData.BenefitsIncludedNonContinuous, + //اطاعات محاسباتی + EmployeeInsurancListDataId = result.x.result.employeeData.id, + DailyWage = result.x.result.employeeData.DailyWage, + // LeftWorkDateGr = x.LeftWorkDate, + // StartWorkDateGr = x.StartWorkDate, + MonthlyBenefitsIncluded = result.x.result.employeeData.MonthlyBenefitsIncluded, + // JobId = x.JobId, + WorkingDays = result.x.result.employeeData.WorkingDays, + //پایه سنوات + BaseYears = result.x.result.employeeData.BaseYears, - // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول - IncludedAndNotIncluded = result.x.result.employeeData.BenefitsIncludedContinuous, + //مجموع مزد روزانه و پایه سنوات + DailyWagePlusBaseYears = result.x.result.employeeData.DailyWagePlusBaseYears, - //حق بیمه سهم بیمه شده - InsuranceShare = result.x.result.employeeData.InsuranceShare, + //حق تاهل + MarriedAllowance = result.x.result.employeeData.MarriedAllowance, - //اضافه کار فیش حقوقی - OverTimePay = result.x.result.employeeData.OverTimePay, + //دستمزد ماهانه + MonthlySalary = result.x.result.employeeData.MonthlySalary, - //حق اولا فیش حقوقی - FamilyAllowance = result.x.result.employeeData.FamilyAllowance, - }); + + //مزایای ماهانه + MonthlyBenefits = result.x.result.employeeData.MonthlyBenefits, + + //مزایای مشمول + BenefitsIncludedContinuous = result.x.result.employeeData.MonthlyBenefitsIncluded, + + //مزایای غیر مشمول + BenefitsIncludedNonContinuous = result.x.result.employeeData.BenefitsIncludedNonContinuous, + + // جمع کل دستمزد و مزایای ماهانه مشمول و غیر مشمول + IncludedAndNotIncluded = result.x.result.employeeData.BenefitsIncludedContinuous, + + //حق بیمه سهم بیمه شده + InsuranceShare = result.x.result.employeeData.InsuranceShare, + + //اضافه کار فیش حقوقی + OverTimePay = result.x.result.employeeData.OverTimePay, + + //حق اولا فیش حقوقی + FamilyAllowance = result.x.result.employeeData.FamilyAllowance, + }); //.Select(x => new EmployeeDetailsForInsuranceListViewModel @@ -1427,4 +1491,45 @@ public class InsuranceListRepository : RepositoryBase, IIns return res.ToList(); } + + public async Task GetTabCounts(long accountId, int month, int year) + { + var workshopIds = _context.WorkshopAccounts + .Where(a => a.AccountId == accountId) + .Select(a => a.WorkshopId); + var res = await _context.InsuranceListSet + .Where(x => + x.Year == year.ToString("0000") && + x.Month == month.ToString("00") && + workshopIds.Contains(x.WorkshopId) + ) + .GroupBy(x => 1) + .Select(g => new InsuranceListTabsCountViewModel + { + NotStarted = g.Count(x => + !x.Debt.IsDone && !x.EmployerApproval.IsDone && !x.Inspection.IsDone && !x.ConfirmSentlist), + InProgress = g.Count(x => + (x.Debt.IsDone || x.EmployerApproval.IsDone || x.Inspection.IsDone)&& !(x.Debt.IsDone && x.EmployerApproval.IsDone && x.Inspection.IsDone) && !x.ConfirmSentlist), + ReadyToSendList = g.Count(x => + x.Debt.IsDone && x.EmployerApproval.IsDone && x.Inspection.IsDone && !x.ConfirmSentlist), + Done = g.Count(x => x.ConfirmSentlist) + }) + .FirstOrDefaultAsync() ?? new InsuranceListTabsCountViewModel(); + + return res; + + } + + /// + /// + /// + /// + /// + /// + /// debt / inspection + /// + private string GetInsuranceListFilePath(long mediaId) + { + return _accountContext.Medias.FirstOrDefault(x => x.id == mediaId)?.Path ?? ""; + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml index 7ebf9c63..32074ae6 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml @@ -2,23 +2,34 @@ @Html.AntiForgeryToken() @{ - + } + }
@@ -36,7 +47,7 @@
- + @@ -44,7 +55,7 @@
-
+
@@ -77,7 +88,7 @@
-
+
@* *@ @@ -127,7 +138,7 @@
-