private void LoadJsonConfig() { if (!File.Exists(Config.ConfigFile)) { return; } JObject json = JObject.Parse(File.ReadAllText(Config.ConfigFile)); ConfigSalary configSalary = JsonConvert.DeserializeObject <ConfigSalary>(json.ToString()); nudOvertimeSalaryRate.Value = Convert.ToDecimal(configSalary.overTimeSalaryRate); nudSalaryPerHour.Value = Convert.ToDecimal(configSalary.salaryPerHour); nudTaxRate.Value = Convert.ToDecimal(configSalary.taxRate); nudAllowance.Value = Convert.ToDecimal(configSalary.allowance); nudBonusPerDay.Value = Convert.ToDecimal(configSalary.bonusPerDay); nudLateFee.Value = Convert.ToDecimal(configSalary.lateFeePerMinute); dtpFromDate.Value = configSalary.dateOffFrom; dtpToDate.Value = configSalary.dateOffTo; }
private void btnSave_Click(object sender, EventArgs e) { ConfigSalary configSalary = new ConfigSalary(); configSalary.overTimeSalaryRate = Convert.ToDouble(nudOvertimeSalaryRate.Value); configSalary.salaryPerHour = Convert.ToDouble(nudSalaryPerHour.Value); configSalary.taxRate = Convert.ToDouble(nudTaxRate.Value); configSalary.allowance = Convert.ToDouble(nudAllowance.Value); configSalary.bonusPerDay = Convert.ToDouble(nudBonusPerDay.Value); configSalary.lateFeePerMinute = Convert.ToDouble(nudLateFee.Value); configSalary.dateOffFrom = dtpFromDate.Value; configSalary.dateOffTo = dtpToDate.Value; using (StreamWriter file = File.CreateText(Config.ConfigFile)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, configSalary); MessageBox.Show("Save successfull!"); } this.Close(); }
private async void btnConfirm_Click(object sender, EventArgs e) { if (isPinMode == true && txtPin.Text != null && txtPin.Text != "") { Users userResult = await _userRepository.GetByPinAsync(txtPin.Text); if (userResult != null) { Attendances attendance = await GetAttendanceForRequestAsync(userResult); Shifts shifts = await _shiftsRepository.GetByIdAsync(userResult.shiftId); if (attendance != null) { // Time <= 0 when check-in meanwhile > 0 when checkout if (attendance.workingHours <= 0) { MessageBox.Show($"Check in success! Welcome {userResult.fullName}!"); } else { MessageBox.Show($"Check out success! Good bye {userResult.fullName}!"); JObject json = JObject.Parse(File.ReadAllText(Config.ConfigFile)); ConfigSalary configSalary = JsonConvert.DeserializeObject <ConfigSalary>(json.ToString()); _payslipsRepository.Add(CalcualteTodayPayslips(attendance, shifts, userResult.roles.fixedSalary, new DateTime(DateTime.Now.Ticks), configSalary, userResult.id)); } } } } else { MessageBox.Show("Please choose PIN Mode!!!"); } isPinMode = false; }
private Payslips CalcualteTodayPayslips(Attendances attendances, Shifts shifts, double salaryRate, DateTime today, ConfigSalary configSalary, long userId) { Payslips payslips = new Payslips(); payslips.payDate = today; payslips.allowance = configSalary.allowance; payslips.bonus = configSalary.bonusPerDay; payslips.otherSalary = 0; payslips.overtimeSalary = 0; payslips.annualLeaveSalary = 0; payslips.userId = userId; payslips.workingSalary = configSalary.salaryPerHour * CalculateWorkingTime(attendances) * salaryRate; payslips.tax = configSalary.taxRate / 100 * payslips.workingSalary; payslips.deductionSalary = payslips.tax + configSalary.lateFeePerMinute * ((attendances.checkinAt - Convert.ToDateTime(shifts.timeStart)).TotalMinutes + (attendances.checkoutAt - Convert.ToDateTime(shifts.timeEnd)).TotalMinutes); payslips.publicSalary = payslips.workingSalary - payslips.deductionSalary + configSalary.allowance; return(payslips); }