示例#1
0
        public async Task <IActionResult> Index(List <SalarySheetRecord> recordList, int n = 0)
        {
            if (ModelState.IsValid)
            {
                List <SalarySheet> salarySheet = new List <SalarySheet>();
                foreach (SalarySheetRecord record in recordList)
                {
                    Loan loan = await loanRepository.GetActiveLoanByUserId(record.UserID);

                    SalarySheet salaryRecord = new SalarySheet()
                    {
                        UserID = record.UserID,
                        Salary = record.Salary,
                        AttendancePenalties     = record.AttendancePenalties,
                        UnpaidVacationDeduction = record.UnpaidVacationDeduction,
                        InsuranceDeduction      = record.InsuranceDeduction,
                        LoanDeduction           = Math.Min(record.LoanDeduction, loan != null ? loan.RemainingAmount : 0),
                        OtherDeductions         = record.OtherDeductions,
                        HousingAllowance        = record.HousingAllowance,
                        TransportationAllowance = record.TransportationAllowance,
                        OtherAdditions          = record.OtherAdditions,
                        Comment = record.Comment,
                        Date    = record.EndDate
                    };
                    salaryRecord.SetFinalSalary();
                    salarySheet.Add(salaryRecord);

                    // Update remaining loan amount
                    if (loan != null)
                    {
                        loan.RemainingAmount -= salaryRecord.LoanDeduction;
                        await loanRepository.Update(loan);
                    }
                }

                await salarySheetRepository.UpdateList(salarySheet);

                TempData["StatusMessage"] = "Salary Sheet has been generated & saved successfully!";
            }
            else
            {
                TempData["StatusMessage"] = "Error: Some fields are invalid!";
            }
            return(await Index(n));
        }
 public SalarySheetRecord(SalarySheet salarySheetRecord, bool editable)
 {
     UserID                  = salarySheetRecord.UserID;
     UserName                = salarySheetRecord.User.FullName;
     Salary                  = salarySheetRecord.Salary;
     AttendancePenalties     = salarySheetRecord.AttendancePenalties;
     UnpaidVacationDeduction = salarySheetRecord.UnpaidVacationDeduction;
     InsuranceDeduction      = salarySheetRecord.InsuranceDeduction;
     LoanDeduction           = salarySheetRecord.LoanDeduction;
     HousingAllowance        = salarySheetRecord.HousingAllowance;
     TransportationAllowance = salarySheetRecord.TransportationAllowance;
     FinalSalary             = salarySheetRecord.FinalSalary;
     OtherDeductions         = salarySheetRecord.OtherDeductions;
     OtherAdditions          = salarySheetRecord.OtherAdditions;
     Comment                 = salarySheetRecord.Comment;
     EndDate                 = salarySheetRecord.Date;
     Editable                = editable;
 }
        private void btnBuild_Click(object sender, EventArgs e)
        {
            //是否为空
            if (cmbYear.SelectedIndex == -1 || cmbMonth.SelectedIndex == -1 || cmbDepartment.SelectedIndex == -1)
            {
                CommonHelper.FailedReply("不能为空!");
                return;
            }

            int  year    = int.Parse(cmbYear.Text);
            int  month   = int.Parse(cmbMonth.Text);
            Guid depId   = (Guid)cmbDepartment.SelectedValue;
            Guid sheetId = ss.GetSalarySheetId(year, month, depId);


            if (sheetId == Guid.Empty)
            {
                //生成新的工资单
                SalarySheet sheet = new SalarySheet();
                sheet.Id           = Guid.NewGuid();
                sheet.Year         = year;
                sheet.Month        = month;
                sheet.DepartmentId = depId;
                ss.BuildNewSalarySheet(sheet);
                ss.BuildSalaryItems(sheet.Id, depId);
                DataGridView.DataSource = ss.GetSalarySheetItems(sheet.Id);
            }
            else
            {
                //是否重新生成
                DialogResult dr = MessageBox.Show("已经生成该工资表,是否重新生成?", "警告", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    ss.DeleteSalaryItems(sheetId);
                    ss.BuildSalaryItems(sheetId, depId);
                    DataGridView.DataSource = ss.GetSalarySheetItems(sheetId);
                }
                else
                {
                    DataGridView.DataSource = ss.GetSalarySheetItems(sheetId);
                }
            }
        }
        public Guid BuildNewSalarySheet(SalarySheet sheet)
        {
            string sql = "insert into SalarySheet values(@Id, @Year, @Month, @DepartmentId)";

            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Id", sheet.Id),
                new SqlParameter("@Year", sheet.Year),
                new SqlParameter("@Month", sheet.Month),
                new SqlParameter("@DepartmentId", sheet.DepartmentId)
            };
            if (SqlHelper.ExcuteNonQuery(sql, parameters) > 0)
            {
                return(sheet.Id);
            }
            else
            {
                return(Guid.Empty);
            }
        }