瀏覽代碼

AllocationBalance

zinab_elgendy 2 月之前
父節點
當前提交
bfe193613e

+ 1 - 1
MTWorkHR.API/Program.cs

@@ -39,7 +39,7 @@ var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
 {
-    options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
+    options.UseSqlServer(config.ConnectionStrings.MTWorkHRConnectionString);
     //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 

+ 1 - 0
MTWorkHR.Application/Dtos/Attendance/OrderAllocationDto.cs

@@ -14,6 +14,7 @@ namespace MTWorkHR.Application.Models
     public class OrderAllocationDto : EntityDto
     {
         public int? NumberOfDays { get; set; }
+        public long ContractId { get; set; }
         public int OrderTypeId { get; set; }
         public string? EmployeeId { get; set; }
         public int? LeaveTypeId { get; set; }

+ 2 - 1
MTWorkHR.Application/Dtos/Contract/ContractDto.cs

@@ -55,7 +55,7 @@ namespace MTWorkHR.Application.Models
 
         //------Working time---------------
         [JsonProperty(Required = Required.AllowNull)]
-        public List<ContractWorkingDayDto>? WorkingDays { get; set; } //:   اختيار متعدد الأيام سبت أحد اثنين..... (بحيث الأيام الأخرى تكون إجازة) 1,2,3,4,5
+        public List<string>? WorkingDays { get; set; } //:   اختيار متعدد الأيام سبت أحد اثنين..... (بحيث الأيام الأخرى تكون إجازة) 1,2,3,4,5
         public WorkingHours WorkingHours { get; set; } //	يومي/ اسبوعي  
         public int? WorkingHoursNum { get; set; } // عدد الساعات
         public DateTime? StartDailyWorkingHours { get; set; } // تحديد ساعات الدوام قائمة الساعات << التوقيت بحسب دولة صاحب العمل
@@ -75,6 +75,7 @@ namespace MTWorkHR.Application.Models
         public DateTime? LastPatchDateTo { get; set; } // 
         public decimal? LastPatchAmount { get; set; }
         public string? Teams{ get; set; }
+        public string? Vacations{ get; set; }
 
 
 

+ 2 - 2
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -138,13 +138,13 @@ namespace MTWorkHR.Application.Mapper
             CreateMap<ChatMessageDto, ChatMessage>().ReverseMap();
             
             //-----------Contract----
-            CreateMap<Contract, ContractDto>();
+            CreateMap<Contract, ContractDto>() .ForMember(d => d.WorkingDays, o => o.Ignore());
             CreateMap<ContractDto, Contract>()
                 .ForMember(d => d.CreateDate, o => o.Ignore())
                 .ForMember(d => d.CreateUser, o => o.Ignore());
             CreateMap<ContractAllowance, ContractAllowanceDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
             CreateMap<ContractTask, ContractTaskDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
-            CreateMap<ContractWorkingDay, ContractWorkingDayDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
+            //CreateMap<ContractWorkingDay, ContractWorkingDayDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
             CreateMap<ContractTaskAttachment, ContractTaskAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
             CreateMap<ProjectStage, ProjectStageDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;
             CreateMap<ProjectStageAttachment, ProjectStageAttachmentDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore()).ForMember(d => d.CreateUser, o => o.Ignore()); ;

+ 48 - 33
MTWorkHR.Application/Services/Contract/ContractService.cs

@@ -18,19 +18,22 @@ namespace MTWorkHR.Application.Services
         private readonly IUnitOfWork _unitOfWork;
         private readonly IUserService _userService;
         private readonly GlobalInfo _globalInfo;
-        private readonly OrderAllocationService _orderAllocationService;
+        private readonly IOrderAllocationService _orderAllocationService;
 
-        public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
+        public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo, IOrderAllocationService orderAllocationService) : base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _userService = userService;
             _globalInfo = globalInfo;
+            _orderAllocationService = orderAllocationService;
         }
 
         public override async Task<ContractDto> GetById(long id)
         {
             var entity = await _unitOfWork.Contract.GetByIdWithAllChildren(id);
             var response = MapperObject.Mapper.Map<ContractDto>(entity);
+            response.WorkingDays = entity.WorkingDays != null ? entity.WorkingDays.Split(",").ToList() : null;
+
             return response;
         }
        
@@ -42,7 +45,7 @@ namespace MTWorkHR.Application.Services
             {
                 throw new AppException(ExceptionEnum.MapperIssue);
             }
-
+            entity.WorkingDays = input.WorkingDays!=null? string.Join(",", input.WorkingDays): null;
             var team = await _unitOfWork.Contract.AddAsync(entity);
             await _unitOfWork.CompleteAsync();
 
@@ -71,22 +74,6 @@ namespace MTWorkHR.Application.Services
             var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
             var query = res.Item1;
 
-
-           
-            //var query = queryx
-            //     .Join(
-            //         teamUsersList.Item1,
-            //         c => c.UserId,
-            //         teamUser => teamUser.AssignedUserId,
-            //         (contract, teamUser) => new
-            //         {
-            //             Contract = contract,
-            //             Teams = teamUser.Team.NameEn
-            //         }
-            //     )
-            //     .AsQueryable();
-
-
             if (_globalInfo.UserType != UserTypeEnum.Business)
             {
                // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
@@ -115,7 +102,10 @@ namespace MTWorkHR.Application.Services
 
             var list = MapperObject.Mapper
                 .Map<IList<ContractDto>>(await page.ToListAsync());
-            
+
+
+            var teamUsersList = await _unitOfWork.TeamUser.GetAllWithChildrenAsync();
+            var vacationAllocations = await _unitOfWork.OrderAllocation.GetAllAsync();
             foreach (var item in list)
             {
                 if (item.UserId != null)
@@ -125,17 +115,20 @@ namespace MTWorkHR.Application.Services
                     {
                         item.EmployeeName = user.FirstName + " " + user.LastName;
                         item.EmployeeEmail = user.Email;
+                        //___________Get Teams
+                        var TeamsList = teamUsersList.Item1.Where(t => t.AssignedUserId == item.UserId).Select(t => GlobalInfo.lang == "en" ? t.Team.NameEn : t.Team.NameAr);
+                        item.Teams = TeamsList == null ? "" : string.Join(",", TeamsList);
+                        //_____________Get vacation balance
+                        var remainVacations = vacationAllocations.Item1.FirstOrDefault(t => t.EmployeeId == item.UserId && t.ContractId == item.Id);
+                        item.Vacations = remainVacations == null ? "" : remainVacations.NumberOfDays + " / " + item.VacationDays;
                     }
                 }
             }
-            var teamUsersList = await _unitOfWork.TeamUser.GetAllWithChildrenAsync();
-            foreach (var item in list)
-            {
-                if (item.UserId != null)
-                {
-                   item.Teams = teamUsersList.Item1.Where(t => t.AssignedUserId == item.UserId).Select(t=> t.Team.NameEn).Aggregate((a,b)=> a+","+b);
-                }
-            }
+         
+         
+
+           
+           
             var response = new PagingResultDto<ContractDto>
             {
                 Result = list,
@@ -155,16 +148,38 @@ namespace MTWorkHR.Application.Services
             if (statusId == (int)ContractStatusEnum.Approved)
             {
                 var updatedSuccess = await _userService.Update(entity.UserId, entity.CompanyId);
-                addVacationAllocation(entity.VacationDays.HasValue ? entity.VacationDays.Value : 0, entity.UserId);
-                if (!updatedSuccess) { result = false; }
+                addVacationAllocation(entity.VacationDays.HasValue ? entity.VacationDays.Value : 0, entity.UserId, contractId);
+                if (!updatedSuccess) { 
+                    result = false; 
+                }
             }
-            await _unitOfWork.CompleteAsync();
             return result;
         }
 
-        private void addVacationAllocation(int noVacationDays, string employeeId)
+        private async void addVacationAllocation(int noVacationDays, string employeeId, long contractId)
         {
-            _orderAllocationService.Create(new OrderAllocationDto { EmployeeId = employeeId,OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year});
+            await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
+            var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
+            var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
+            foreach(var orderType in orderTypes.Item1)
+            {
+                foreach (var leaveType in leaveTypes.Item1)
+                {
+                    if(orderType.Id !=1 && leaveType.Id != 1 && (leaveType.DefaultDays> 0 || orderType.DefaultDays > 0))
+                    {
+                        await _orderAllocationService.Create(new OrderAllocationDto 
+                        { 
+                            ContractId = contractId, 
+                            EmployeeId = employeeId, 
+                            OrderTypeId =(int) orderType.Id, 
+                            LeaveTypeId = (int)leaveType.Id, 
+                            NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays, 
+                            Period = DateTime.Now.Year }
+                        );
+                    }
+                }
+            }
+            
         }
 
 

+ 1 - 0
MTWorkHR.Application/Services/User/UserService.cs

@@ -358,6 +358,7 @@ namespace MTWorkHR.Application.Services
                 throw new AppException(ExceptionEnum.RecordNameAlreadyExist);
             //loop for given list of attachment, and move each file from Temp path to Actual path
             //  _fileService.UploadFiles(files);
+            input.CountryId = input.CountryId == null || input.CountryId == 0 ? input.UserAddress?.CountryId : input.CountryId;
             if (input.UserAttachments == null )
                 input.UserAttachments = new List<AttachmentDto>();
             if (input.ProfileImage != null)

+ 2 - 0
MTWorkHR.Core/Entities/Attendance/OrderAllocation.cs

@@ -12,6 +12,8 @@ namespace MTWorkHR.Core.Entities
     public class OrderAllocation : AuditEntity, IHaveCompany
     {
         public int NumberOfDays { get; set; }
+        public long ContractId { get; set; }
+
         [ForeignKey("OrderTypeId")]
         public OrderType OrderType { get; set; }
         public long OrderTypeId { get; set; }

+ 1 - 1
MTWorkHR.Core/Entities/Contract/Contract.cs

@@ -45,7 +45,7 @@ namespace MTWorkHR.Core.Entities
 
 
         //------Working time---------------
-        public List<ContractWorkingDay>? WorkingDays { get; set; } //:   اختيار متعدد الأيام سبت أحد اثنين..... (بحيث الأيام الأخرى تكون إجازة) 1,2,3,4,5
+        public string? WorkingDays { get; set; } //:   اختيار متعدد الأيام سبت أحد اثنين..... (بحيث الأيام الأخرى تكون إجازة) 1,2,3,4,5
         public int? WorkingHours { get; set; } //	يومي/ اسبوعي  
         public int? WorkingHoursNum { get; set; } // عدد الساعات
         public DateTime? StartDailyWorkingHours { get; set; } // تحديد ساعات الدوام قائمة الساعات << التوقيت بحسب دولة صاحب العمل

+ 4 - 1
MTWorkHR.Core/Global/Enum/WorkingHours.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Runtime.Serialization;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -8,7 +9,9 @@ namespace MTWorkHR.Core.Global
 {
     public enum WorkingHours
     {
-        Daily,
+        [EnumMember(Value = "1")]
+        Daily ,
+        [EnumMember(Value = "2")]
         Weekly,
     }
 }

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -32,7 +32,7 @@ namespace MTWorkHR.Infrastructure
             
             services.AddDbContext<HRDataContext>(options =>
                 options.UseSqlServer(
-                    config.ConnectionStrings.LocalConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
+                    config.ConnectionStrings.MTWorkHRConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
                     ));
            
             services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();

文件差異過大導致無法顯示
+ 6788 - 0
MTWorkHR.Infrastructure/Migrations/20250127103524_altrContractWorkingDays.Designer.cs


+ 61 - 0
MTWorkHR.Infrastructure/Migrations/20250127103524_altrContractWorkingDays.cs

@@ -0,0 +1,61 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrContractWorkingDays : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropTable(
+                name: "ContractWorkingDay");
+
+            migrationBuilder.AddColumn<string>(
+                name: "WorkingDays",
+                table: "Contracts",
+                type: "nvarchar(max)",
+                nullable: true);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "WorkingDays",
+                table: "Contracts");
+
+            migrationBuilder.CreateTable(
+                name: "ContractWorkingDay",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    ContractId = table.Column<long>(type: "bigint", nullable: false),
+                    WorkingDay = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_ContractWorkingDay", x => x.Id);
+                    table.ForeignKey(
+                        name: "FK_ContractWorkingDay_Contracts_ContractId",
+                        column: x => x.ContractId,
+                        principalTable: "Contracts",
+                        principalColumn: "Id",
+                        onDelete: ReferentialAction.Cascade);
+                });
+
+            migrationBuilder.CreateIndex(
+                name: "IX_ContractWorkingDay_ContractId",
+                table: "ContractWorkingDay",
+                column: "ContractId");
+        }
+    }
+}

文件差異過大導致無法顯示
+ 6791 - 0
MTWorkHR.Infrastructure/Migrations/20250128084505_altrAllocationContractId.Designer.cs


+ 29 - 0
MTWorkHR.Infrastructure/Migrations/20250128084505_altrAllocationContractId.cs

@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrAllocationContractId : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AddColumn<long>(
+                name: "ContractId",
+                table: "OrderAllocations",
+                type: "bigint",
+                nullable: false,
+                defaultValue: 0L);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "ContractId",
+                table: "OrderAllocations");
+        }
+    }
+}

+ 6 - 55
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -687,6 +687,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<int?>("WorkStateId")
                         .HasColumnType("int");
 
+                    b.Property<string>("WorkingDays")
+                        .HasColumnType("nvarchar(max)");
+
                     b.Property<int?>("WorkingHours")
                         .HasColumnType("int");
 
@@ -857,48 +860,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.ToTable("ContractTaskAttachment");
                 });
 
-            modelBuilder.Entity("MTWorkHR.Core.Entities.ContractWorkingDay", b =>
-                {
-                    b.Property<long>("Id")
-                        .ValueGeneratedOnAdd()
-                        .HasColumnType("bigint")
-                        .HasColumnOrder(0);
-
-                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
-
-                    b.Property<long>("ContractId")
-                        .HasColumnType("bigint");
-
-                    b.Property<DateTime>("CreateDate")
-                        .HasColumnType("datetime2")
-                        .HasColumnOrder(3);
-
-                    b.Property<string>("CreateUser")
-                        .HasMaxLength(450)
-                        .HasColumnType("nvarchar(450)")
-                        .HasColumnOrder(1);
-
-                    b.Property<DateTime?>("UpdateDate")
-                        .HasColumnType("datetime2")
-                        .HasColumnOrder(4);
-
-                    b.Property<string>("UpdateUser")
-                        .HasMaxLength(450)
-                        .HasColumnType("nvarchar(450)")
-                        .HasColumnOrder(2);
-
-                    b.Property<string>("WorkingDay")
-                        .IsRequired()
-                        .HasMaxLength(50)
-                        .HasColumnType("nvarchar(50)");
-
-                    b.HasKey("Id");
-
-                    b.HasIndex("ContractId");
-
-                    b.ToTable("ContractWorkingDay");
-                });
-
             modelBuilder.Entity("MTWorkHR.Core.Entities.CountryLookup", b =>
                 {
                     b.Property<long>("Id")
@@ -3274,6 +3235,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<long>("CompanyId")
                         .HasColumnType("bigint");
 
+                    b.Property<long>("ContractId")
+                        .HasColumnType("bigint");
+
                     b.Property<DateTime>("CreateDate")
                         .HasColumnType("datetime2")
                         .HasColumnOrder(3);
@@ -6446,17 +6410,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Navigation("ContractTask");
                 });
 
-            modelBuilder.Entity("MTWorkHR.Core.Entities.ContractWorkingDay", b =>
-                {
-                    b.HasOne("MTWorkHR.Core.Entities.Contract", "Contract")
-                        .WithMany("WorkingDays")
-                        .HasForeignKey("ContractId")
-                        .OnDelete(DeleteBehavior.Cascade)
-                        .IsRequired();
-
-                    b.Navigation("Contract");
-                });
-
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingUser", b =>
                 {
                     b.HasOne("MTWorkHR.Core.Entities.Meeting", "Meeting")
@@ -6781,8 +6734,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Navigation("FixedAllowances");
 
                     b.Navigation("ProjectStages");
-
-                    b.Navigation("WorkingDays");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTask", b =>