Exemple #1
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,OTDate,OTStartTime,OTEndTime,Status,ApprovedDate,OTTime,Year,FromEmployeeInfoId,ToEmployeeInfoId")] OverTime overTime)
        {
            if (id != overTime.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //_context.Update(overTime);
                    //await _context.SaveChangesAsync();
                    await overTimeRepository.Update(overTime);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OverTimeExists(overTime.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FromEmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", overTime.FromEmployeeInfoId);
            ViewData["ToEmployeeInfoId"]   = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", overTime.ToEmployeeInfoId);
            return(View(overTime));
        }
Exemple #2
0
        private void SaveOverTime()
        {
            if (dtpDate.Value.Month != Store.ActiveMonth || dtpDate.Value.Year != Store.ActiveYear)
            {
                MessageBox.Show("Tanggal harus dalam periode" + "\n\n" + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtEmployeeId.Text == "")
            {
                MessageBox.Show("Karyawan harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtEmployeeId.Focus();
            }
            else if (txtStartHour.Text == "" || int.Parse(txtStartHour.Text.Replace(".", "")) == 0)
            {
                MessageBox.Show("Jumlah jam harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtStartHour.Focus();
            }
            else if (formMode == FormMode.Add && overTimeRepository.IsExisted(new Guid(txtEmployeeId.Text), dtpDate.Value))
            {
                MessageBox.Show("NIK : " + txtCode.Text + "\nNama : " + txtName.Text + "\nTanggal : " + dtpDate.Value.ToString("dd/MM/yyyy") + "\n\nsudah ada ", "Perhatian",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                int day   = (int)DateTime.Now.DayOfWeek;
                int date  = DateTime.Now.Day;
                int year  = Store.ActiveYear;
                int month = Store.ActiveMonth;

                if (Store.ActiveMonth == 1)
                {
                    year  = Store.ActiveYear - 1;
                    month = 12;
                }

                string department = "";
                string branch     = "";

                DateTime dtStart = new DateTime(year, month - 1, (int)Store.CutOffDate);
                DateTime dtEnd   = new DateTime(year, month, (int)Store.CutOffDate - 1);

                OverTime overTime = new OverTime();

                overTime.EmployeeId = new Guid(txtEmployeeId.Text);

                //AMBIL BRANCH & DEPT
                var dept = employeeDepartmentRepository.GetCurrentDepartment(new Guid(txtEmployeeId.Text), Store.ActiveMonth, Store.ActiveYear);
                if (dept != null)
                {
                    department = dept.DepartmentName;
                    branch     = dept.BranchName;
                }
                else
                {
                    var previousDept = employeeDepartmentRepository.GetPreviousDepartment(new Guid(txtEmployeeId.Text), Store.ActiveMonth, Store.ActiveYear);
                    if (previousDept != null)
                    {
                        department = previousDept.DepartmentName;
                        branch     = previousDept.BranchName;
                    }
                }

                overTime.Department = department;
                overTime.Branch     = branch;


                overTime.MonthPeriod = Store.ActiveMonth;
                overTime.YearPeriod  = Store.ActiveYear;

                if (optWorkDay.Checked == true)
                {
                    overTime.DayType = 0;
                }
                else if (optHoliday.Checked == true)
                {
                    overTime.DayType = 1;
                }

                overTime.OverTimeDate  = dtpDate.Value;
                overTime.StartHour     = txtStartHour.Text + ":" + txtStartMinute.Text;
                overTime.EndHour       = txtEndHour.Text + ":" + txtEndMinute.Text;
                overTime.TotalInMinute = Store.GetTotalOverTimeInMinute(int.Parse(txtStartHour.Text), int.Parse(txtStartMinute.Text),
                                                                        int.Parse(txtEndHour.Text), int.Parse(txtEndMinute.Text));

                overTime.TotalInHour = Store.GetTotalInHour(overTime.TotalInMinute);


                overTime.Amount = Math.Round(overTimeRepository.CalculateOverTime(overTime.EmployeeId, overTime.TotalInMinute, overTime.DayType), 0);

                if (overTime.Amount > 0)
                {
                    string amountInWords = Store.GetAmounInWords(Convert.ToInt32(overTime.Amount));
                    string firstLetter   = amountInWords.Substring(0, 2).Trim().ToUpper();
                    string theRest       = amountInWords.Substring(2, amountInWords.Length - 2);
                    overTime.AmountInWords = firstLetter + theRest + " rupiah";
                }
                else
                {
                    overTime.AmountInWords = "Nol rupiah";
                }
                overTime.Notes = txtNotes.Text;

                if (formMode == FormMode.Add)
                {
                    overTimeRepository.Save(overTime);
                    GetLastOverTime();
                }
                else if (formMode == FormMode.Edit)
                {
                    overTime.ID = new Guid(txtID.Text);
                    overTimeRepository.Update(overTime);
                }

                LoadOverTime();
                DisableForm();

                formMode  = FormMode.View;
                this.Text = "Lembur";
            }
        }