Ejemplo n.º 1
0
        public Att_TimeOffInLieu AddTimeOffInLieu(Att_Overtime overtime)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoHre_Profile = new CustomBaseRepository<Hre_Profile>(unitOfWork);
                //Insert vào Att_TimeOffInLieu
                Att_TimeOffInLieu timeOffInLieu = null;
                if (overtime.ID != Guid.Empty)
                {
                    Hre_Profile profile = repoHre_Profile.FindBy(m => m.ID == overtime.ProfileID).FirstOrDefault();
                    timeOffInLieu = new Att_TimeOffInLieu();
                    Cat_OvertimeType overtimeType = overtime.Cat_OvertimeType;
                    double Hour = 0;
                    if (overtime.Status == OverTimeStatus.E_CONFIRM.ToString())
                    {
                        Hour = overtime.ConfirmHours == null ? 0 : overtime.ConfirmHours;
                    }
                    else if (overtime.Status == OverTimeStatus.E_APPROVED.ToString())
                    {
                        Hour = overtime.ApproveHours == null ? 0 : overtime.ApproveHours.Value;
                    }
                    double HourTimeOffInLieu = Hour;
                    double UnusualLeaves = 0;
                    if (overtimeType != null)
                    {
                        UnusualLeaves = HourTimeOffInLieu * (overtimeType.TimeOffInLieuRate == null ? 0 : overtimeType.TimeOffInLieuRate.Value);
                    }
                    double accumulateLeaves = Att_LeavedayServices.getAccumulateLeaves(profile.ID);

                    timeOffInLieu.AccumulateLeaves = accumulateLeaves;
                    timeOffInLieu.UnusualLeaves = UnusualLeaves;
                    timeOffInLieu.TakenLeaves = 0;
                    timeOffInLieu.RemainLeaves = UnusualLeaves + accumulateLeaves;
                    timeOffInLieu.Date = overtime.WorkDate.Date;
                    if (overtime.DateApprove != null)
                        timeOffInLieu.DateApprove = overtime.DateApprove.Value;
                    timeOffInLieu.ConvertedCashHours = UnusualLeaves;
                    timeOffInLieu.Att_Overtime = overtime;
                    timeOffInLieu.Hre_Profile = profile;
                }
                return timeOffInLieu;
            }

        }
Ejemplo n.º 2
0
 public string GetStatusApproveOvertime(Att_Overtime overtime, Guid loginUserID)
 {
     string Status = string.Empty;
     if (overtime.UserApproveID2 != null && overtime.UserApproveID2 == loginUserID)
     {
         Status = OverTimeStatus.E_APPROVED.ToString();
     }
     else if (overtime.UserApproveID3 != null && overtime.UserApproveID3 == loginUserID)
     {
         Status = OverTimeStatus.E_APPROVED1.ToString();
     }
     else if (overtime.UserApproveID != null && overtime.UserApproveID == loginUserID)
     {
         Status = OverTimeStatus.E_FIRST_APPROVED.ToString();
     }
     if (Status == OverTimeStatus.E_APPROVED1.ToString() && (overtime.UserApproveID2 == null || overtime.UserApproveID3 == null))
     {
         Status = OverTimeStatus.E_APPROVED.ToString();
     }
     if (Status == string.Empty)
     {
         Status = OverTimeStatus.E_APPROVED.ToString();
     }
     return Status;
 }
Ejemplo n.º 3
0
        public void ChangeMethodOverTime_Manual(Att_OvertimeEntity model)
        {

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Overtime = new CustomBaseRepository<Att_Overtime>(unitOfWork);
                var repoAtt_TimeofInLieu = new CustomBaseRepository<Att_TimeOffInLieu>(unitOfWork);



                double TimeOffRealValidate = 0;
                double TimeOffValidate = 0;
                double CashOutValidate = 0;
                if (model.TimeOffReal != null)
                {
                    TimeOffRealValidate = (double)model.TimeOffReal;
                    //double.TryParse(model.TimeOffReal.ToString(), out TimeOffRealValidate);
                }
                if (model.HourToTimeOff != null)
                {
                    TimeOffValidate = (double)model.HourToTimeOff;
                    //double.TryParse(txt_TimeOff.Text, out TimeOffValidate);
                }
                if (model.TimeRegister != null)
                {
                    CashOutValidate = (double)model.TimeRegister;
                    //double.TryParse(txt_CashOut.Text, out CashOutValidate);
                }
                if (TimeOffRealValidate < 0 || TimeOffValidate < 0 || CashOutValidate < 0)
                {
                    return;
                }

                double Cashout = CashOutValidate;
                double Timeoff = TimeOffValidate;

                //if (Ot.Status == OverTimeStatus.E_APPROVED.ToString())
                //{
                //    Common.MessageBoxs(Messages.Msg, Messages.DataCantBeModify.TranslateString(), Ext.Net.MessageBox.Icon.WARNING, string.Empty);
                //    return;
                //}

                Att_Overtime OT_New = new Att_Overtime();

                if (Cashout > 0 && Timeoff <= 0)
                {
                    //Chuyển hết cho trả tiền
                    model.MethodPayment = MethodOption.E_CASHOUT.ToString();

                }
                else if (Cashout <= 0 && Timeoff > 0)
                {
                    //Chuyển hết cho nghỉ bù
                    model.MethodPayment = MethodOption.E_TIMEOFF.ToString();


                }
                else if (Cashout > 0 && Timeoff > 0)
                {
                    //Vửa chuyển tiền vừa nghỉ bù
                    model.MethodPayment = MethodOption.E_CASHOUT.ToString();
                    model.RegisterHours = Cashout;

                    if (model.Status == OverTimeStatus.E_APPROVED.ToString())
                    {
                        model.ApproveHours = Cashout;
                    }
                    if (model.Status == OverTimeStatus.E_CONFIRM.ToString())
                    {
                        model.ApproveHours = Cashout;
                        model.ConfirmHours = Cashout;
                    }
                    OT_New = model.CopyData<Att_Overtime>();
                    OT_New.ID = Guid.NewGuid();
                    OT_New.WorkDate = model.WorkDate.AddHours(model.RegisterHours);
                    OT_New.MethodPayment = MethodOption.E_TIMEOFF.ToString();
                    OT_New.RegisterHours = Timeoff;
                    if (OT_New.Status == OverTimeStatus.E_APPROVED.ToString())
                    {
                        OT_New.ApproveHours = Timeoff;
                    }
                    if (OT_New.Status == OverTimeStatus.E_CONFIRM.ToString())
                    {
                        OT_New.ApproveHours = Timeoff;
                        OT_New.ConfirmHours = Timeoff;
                    }
                    if (model.IsNonOvertime == true)
                    {
                        //model.IsNonOvertime = true;
                        OT_New.IsNonOvertime = true;
                    }
                    //repoAtt_Overtime.FindBy<Att_Overtime>();
                    repoAtt_Overtime.Add(OT_New);
                    var att_overtimeEntity = model.CopyData<Att_Overtime>();
                    repoAtt_Overtime.Edit(att_overtimeEntity);

                    //EntityService.AddEntity<Att_Overtime>(GuidContext, (new List<Att_Overtime>() { OT_New }).ToArray());
                }

                if (model.LeaveDay1 != null || model.LeaveDay2 != null)
                {
                    DateTime? date1 = null;
                    DateTime? date2 = null;
                    if (model.LeaveDay1 != null)
                    {
                        date1 = model.LeaveDay1;
                    }
                    if (model.LeaveDay2 != null)
                    {
                        date2 = model.LeaveDay2;
                    }
                    //string Error = AddTimeOffInLieu(new List<Att_Overtime>() { Ot, OT_New }, date1, date2);
                    //if (Error != string.Empty)
                    //{
                    //    return;
                    //}
                }

                if (model.Status == OverTimeStatus.E_APPROVED.ToString() || model.Status == OverTimeStatus.E_CONFIRM.ToString())
                {
                    List<Att_TimeOffInLieu> lstTimeOffInsert = new List<Att_TimeOffInLieu>();
                    //TimeOffInLieeu
                    //1 Xóa Đi những cái OT liên Quan trong TimeOff
                    //2 Insert lại nhưng cái liên quan đên TimeOff
                    List<Att_TimeOffInLieu> lstTimeOff = repoAtt_TimeofInLieu.FindBy(m => m.OvertimeID == model.ID).ToList<Att_TimeOffInLieu>();
                    foreach (var item in lstTimeOff)
                    {
                        item.IsDelete = null;
                    }

                    if (model.MethodPayment == MethodOption.E_TIMEOFF.ToString())
                    {
                        Att_TimeOffInLieu TimeOffInsert = AddTimeOffInLieu(model.CopyData<Att_Overtime>());
                        TimeOffInsert.ID = Guid.NewGuid();
                        TimeOffInsert.ProfileID = model.ProfileID;
                        lstTimeOffInsert.Add(TimeOffInsert);
                    }
                    if (OT_New.MethodPayment == MethodOption.E_TIMEOFF.ToString())
                    {
                        Att_TimeOffInLieu TimeOffInsert = AddTimeOffInLieu(OT_New);
                        TimeOffInsert.ID = Guid.NewGuid();
                        TimeOffInsert.ProfileID = model.ProfileID;
                        lstTimeOffInsert.Add(TimeOffInsert);
                    }
                    if (lstTimeOffInsert.Count > 0)
                    {
                        for (int i = 0; i < lstTimeOffInsert.Count; i++)
                        {
                            lstTimeOffInsert[i].Hre_Profile = null;
                            repoAtt_TimeofInLieu.Add(lstTimeOffInsert[i]);
                        }
                        // repoAtt_TimeofInLieu.Add(lstTimeOffInsert);
                        //EntityService.AddEntity<Att_TimeOffInLieu>(GuidContext, lstTimeOffInsert.ToArray());
                    }
                }
                unitOfWork.SaveChanges();
                // EntityService.SubmitChanges(GuidContext, LoginUserID.Value);
                //IsSave = false;

                //IsSave = false;
            }
            //return Json(new { });

        }