예제 #1
0
        public PayrollSalaryTableDTO GetPayollGenerationForm(int fyid)
        {
            List <SelectListItem> OfficeSelectList = new List <SelectListItem>();
            int           EmployeeCode             = Convert.ToInt32(HttpContext.Current.Session["EmpCode"]);
            SqlConnection conn = DbConnectHelper.GetConnection();

            conn.Open();
            SqlCommand cmd = new SqlCommand("sp_MyRoleOfficesList", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EmpCode", EmployeeCode);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            da.Dispose();
            cmd.Dispose();
            conn.Close();
            conn.Dispose();
            foreach (DataRow row in dt.Rows)
            {
                OfficeSelectList.Add(new SelectListItem
                {
                    Text  = row["ChildOfficeName"].ToString(),
                    Value = row["ChildOfficeId"].ToString()
                });
            }
            IEnumerable <PayrollMonthDescription> MonthDescriptrionList = _unitOfWork.PayrollMonthDescriptipnRepository.All().Where(x => x.FyId == fyid).ToList();
            List <SelectListItem> MonthDescription = new List <SelectListItem>();

            foreach (var str in MonthDescriptrionList)
            {
                MonthDescription.Add(new SelectListItem
                {
                    Text  = str.MonthNameNepali,
                    Value = str.Id.ToString()
                });
            }
            PayrollSalaryTableDTO Record           = new PayrollSalaryTableDTO();
            IEnumerable <Fiscal>  FiscalRecord     = _unitOfWork.FiscalRepository.All().ToList();
            List <SelectListItem> FiscalSelectList = new List <SelectListItem>();

            foreach (var Fiscalstr in FiscalRecord)
            {
                FiscalSelectList.Add(new SelectListItem
                {
                    Text  = Fiscalstr.FyName,
                    Value = Fiscalstr.FyId.ToString()
                });
            }
            Record.CreatorId       = EmployeeCode;
            Record.FiscalYearList  = FiscalSelectList;
            Record.OfficeList      = OfficeSelectList;
            Record.MonthSelectList = MonthDescription;
            return(Record);
        }
예제 #2
0
        public ActionResult GeneratePayroll()
        {
            int fyid     = _fiscalService.GetCurrentFyId();
            var fdetails = _fiscalService.GetFiscalById(fyid);

            ViewBag.CurrentFiscalYear = fdetails.FyName;

            PayrollSalaryTableDTO Record = _PayrollGenerationService.GetPayollGenerationForm(fyid);

            return(View(Record));
        }
예제 #3
0
        public ActionResult GeneratePayroll(PayrollSalaryTableDTO Record)
        {
            int fyid     = _fiscalService.GetCurrentFyId();
            var fdetails = _fiscalService.GetFiscalById(fyid);

            ViewBag.CurrentFiscalYear = fdetails.FyName;

            Record.FyId = fyid;

            PayrollSalaryTableDTO ModelRecord = _PayrollGenerationService.GetPayollGenerationForm(fyid);
            string Message        = null;
            bool   Success        = false;
            bool   UpdateExisting = false;

            try
            {
                if (ModelState.IsValid)
                {
                    PayrollSalaryTableDTO ReturnRecord = _PayrollGenerationService.GeneratePayroll(Record, out Message, out Success, out UpdateExisting);
                    if (Success == true)
                    {
                        TempData["Success"] = "Payroll Generated Successfully";
                    }
                    else
                    {
                        if (UpdateExisting)
                        {
                            ViewBag.UpdateExisting = "true";
                        }
                        TempData["Error"] = Message;
                        PayrollSalaryTableDTO FormRecord = _PayrollGenerationService.GetPayollGenerationForm(fyid);
                        return(View(FormRecord));
                    }
                    ModelRecord.SalaryConfirmed = ReturnRecord.SalaryConfirmed;
                    TempData["Success"]         = "Payroll Generated Successfully";
                    return(RedirectToAction("Index", new { Id = ReturnRecord.Id }));
                }
                else
                {
                    ViewBag.Error = "Form Validation Failed";
                    return(View(ModelRecord));
                }
            }
            catch (Exception Ex)
            {
                ViewBag.Error = Ex.Message;
                return(View(ModelRecord));
            }
        }
예제 #4
0
 public static PayrollSalaryTable ConvertRespondentInfoFromDTO(PayrollSalaryTableDTO PayrollSalaryTableDTO)
 {
     Mapper.CreateMap <PayrollSalaryTableDTO, PayrollSalaryTable>().ConvertUsing(
         m =>
     {
         return(new PayrollSalaryTable
         {
             Id = m.Id,
             OfficeId = m.OfficeId,
             PayrollMonthId = m.PayrollMonthId,
             BgId = m.BgId,
             CreatorId = m.CreatorId,
             Details = m.Details,
             SalaryConfirmed = m.SalaryConfirmed,
             PayrollMonthDescription = new PayrollMonthDescription {
                 Id = m.PayrollMonthDescription.Id,
                 FyId = m.PayrollMonthDescription.FyId,
                 MonthNameEnglish = m.PayrollMonthDescription.MonthNameEnglish,
                 MonthNameNepali = m.PayrollMonthDescription.MonthNameNepali,
                 StartDate = m.PayrollMonthDescription.StartDate,
                 EndDate = m.PayrollMonthDescription.EndDate,
                 WorkingDays = m.PayrollMonthDescription.WorkingDays
             },
             Office = new Office
             {
                 OfficeId = m.Office.OfficeId,
                 OfficeName = m.Office.OfficeName,
                 OfficeAddress = m.Office.OfficeAddress,
                 OfficeCode = m.Office.OfficeCode,
                 OfficeGeoLocation = m.Office.OfficeGeoLocation,
                 OfficeParentId = m.Office.OfficeParentId,
                 OfficePhone = m.Office.OfficePhone,
                 OfficeStatus = m.Office.OfficeStatus
             },
             Fiscal = new Fiscal
             {
                 FyId = m.Fiscal.FyId,
                 FyName = m.Fiscal.FyName
             }
         });
     });
     return(Mapper.Map <PayrollSalaryTableDTO, PayrollSalaryTable>(PayrollSalaryTableDTO));
 }
예제 #5
0
        public PayrollSalaryTableDTO GeneratePayroll(PayrollSalaryTableDTO Record, out string Message, out bool Success, out bool UpdateExisting)
        {
            List <PayrollSalaryTable> CheckConfirmedSalary = _unitOfWork.PayrollSalaryTableRepository.All().Where(x => x.OfficeId == Record.OfficeId && x.SalaryConfirmed == false).ToList();


            if (CheckConfirmedSalary.Count != 0)
            {
                foreach (PayrollSalaryTable Rec in CheckConfirmedSalary)
                {
                    if (!(Rec.OfficeId == Record.OfficeId && Rec.PayrollMonthId == Record.PayrollMonthId && Rec.FyId == Record.FyId))
                    {
                        Message = "There is a previous unconfirmed salary for this office";
                        Success = false;
                        Record.SalaryConfirmed = true;
                        UpdateExisting         = false;
                        return(Record);
                    }
                }
            }
            PayrollSalaryTableDTO ReturnRecord = new PayrollSalaryTableDTO();
            PayrollSalaryTable    Domain       = _unitOfWork.PayrollSalaryTableRepository.All().Where(x => x.FyId == Record.FyId && x.OfficeId == Record.OfficeId && x.PayrollMonthId == Record.PayrollMonthId).FirstOrDefault();

            if (Domain == null)
            {
                SqlConnection conn = DbConnectHelper.GetConnection();
                conn.Open();
                SqlCommand cmd = new SqlCommand("sp_GeneratePayrollNewVersion", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@FyId", Record.FyId);
                cmd.Parameters.AddWithValue("@MonthDescriptId", Record.PayrollMonthId);
                cmd.Parameters.AddWithValue("@CreatorId", Record.CreatorId);
                cmd.Parameters.AddWithValue("@BranchId", Record.OfficeId);
                cmd.Parameters.AddWithValue("@Details", Record.Details);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                da.Dispose();
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
                Message = "Payroll generated successfully";
                Success = true;
                PayrollSalaryTable ReturnId = _unitOfWork.PayrollSalaryTableRepository.Get(x => x.FyId == Record.FyId && x.OfficeId == Record.OfficeId && x.PayrollMonthId == Record.PayrollMonthId).FirstOrDefault();
                UpdateExisting = false;
                return(PayrollSalaryTableRequestFormatter.ConvertRespondentInfoToDTO(ReturnId));
            }
            else
            {
                if (!Domain.SalaryConfirmed)
                {
                    if (Record.UpdateExisting == true)
                    {
                        SqlConnection conn = DbConnectHelper.GetConnection();
                        conn.Open();
                        SqlCommand cmd = new SqlCommand("sp_GeneratePayrollNewVersion", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@FyId", Record.FyId);
                        cmd.Parameters.AddWithValue("@MonthDescriptId", Record.PayrollMonthId);
                        cmd.Parameters.AddWithValue("@CreatorId", Record.CreatorId);
                        cmd.Parameters.AddWithValue("@BranchId", Record.OfficeId);
                        cmd.Parameters.AddWithValue("@Details", Record.Details);
                        cmd.Parameters.AddWithValue("@DeleteFlag", Record.UpdateExisting);
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataTable      dt = new DataTable();
                        da.Fill(dt);
                        da.Dispose();
                        cmd.Dispose();
                        conn.Close();
                        conn.Dispose();
                        Message        = "Payroll updated successfully";
                        Success        = true;
                        UpdateExisting = false;
                        return(Record);
                    }
                    else
                    {
                        UpdateExisting = true;
                        Message        = "Payroll of this month for this Office already exists.";
                    }
                }
                else
                {
                    UpdateExisting = false;
                    Message        = "Payroll for this month is already confirmed";
                }
            }

            ReturnRecord = PayrollSalaryTableRequestFormatter.ConvertRespondentInfoToDTO(Domain);
            Success      = false;
            return(ReturnRecord);
        }