Пример #1
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";
            }
        }