示例#1
0
        public async Task <IActionResult> Create([Bind("Id,OTDate,OTStartTime,OTEndTime,Status,ApprovedDate,OTTime,Year,FromEmployeeInfoId,ToEmployeeInfoId")] OverTimeViewModel overTime)
        {
            if (ModelState.IsValid)
            {
                OverTime ot = new OverTime()
                {
                    OTDate             = overTime.OTDate,
                    OTStartTime        = overTime.OTStartTime,
                    OTEndTime          = overTime.OTEndTime,
                    Status             = overTime.Status,
                    ApprovedDate       = overTime.ApprovedDate,
                    OTTime             = overTime.OTTime,
                    Year               = overTime.Year,
                    FromEmployeeInfoId = overTime.FromEmployeeInfoId,
                    ToEmployeeInfoId   = overTime.ToEmployeeInfoId
                };
                //_context.Add(overTime);
                //await _context.SaveChangesAsync();
                await overTimeRepository.Save(ot);

                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));
        }
示例#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";
            }
        }
示例#3
0
        private void ImportOvertime(string fileName)
        {
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;
            Excel.Range       range;

            xlApp = new Excel.ApplicationClass();

            xlWorkBook  = xlApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            range = xlWorkSheet.UsedRange;

            double month = (double)(range.Cells[1, 2] as Excel.Range).Value2;
            double year  = (double)(range.Cells[2, 2] as Excel.Range).Value2;

            int dayType = 0;

            for (var row = 4; row <= range.Rows.Count; row++)
            {
                string nik       = (string)(range.Cells[row, 1] as Excel.Range).Value2;
                string type      = (string)(range.Cells[row, 2] as Excel.Range).Value2;
                string date      = (string)(range.Cells[row, 3] as Excel.Range).Value2;
                string startHour = (string)(range.Cells[row, 4] as Excel.Range).Value2;
                string endHour   = (string)(range.Cells[row, 5] as Excel.Range).Value2;
                string notes     = (string)(range.Cells[row, 6] as Excel.Range).Value2;

                if (nik == null)
                {
                    break;
                }

                if (type == "K")
                {
                    dayType = 0;
                }
                else if (type == "L")
                {
                    dayType = 1;
                }

                var employee = employeeRepository.GetByCode(nik);

                if (employee != null)
                {
                    Guid   employeeId = employee.ID;
                    string branch     = employee.CurrentInfo.BranchName;
                    string department = employee.CurrentInfo.DepartmentName;

                    var overTime = new OverTime();

                    overTime.MonthPeriod      = Convert.ToInt32(month);
                    overTime.YearPeriod       = Convert.ToInt32(year);
                    overTime.EmployeeId       = employeeId;
                    overTime.Branch           = branch;
                    overTime.Department       = department;
                    overTime.IsIncludePayroll = false;
                    overTime.IsPaid           = false;
                    overTime.DayType          = dayType;
                    overTime.OverTimeDate     = DateTime.ParseExact(date,
                                                                    "dd/MM/yyyy", CultureInfo.InvariantCulture);

                    overTime.StartHour     = startHour;
                    overTime.EndHour       = endHour;
                    overTime.TotalInMinute = Store.GetTotalOverTimeInMinute(startHour, endHour);
                    overTime.TotalInHour   = Store.GetTotalInHour(overTime.TotalInMinute);
                    overTime.Amount        = Math.Round(overTimeRepository.CalculateOverTime(overTime.EmployeeId, overTime.TotalInMinute, overTime.DayType), 0);
                    overTime.AmountInWords = Store.GetAmounInWords(Convert.ToInt32(overTime.Amount));
                    overTime.Notes         = notes;

                    overTimeRepository.Save(overTime);
                }
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();

            ReleaseObject(xlWorkSheet);
            ReleaseObject(xlWorkBook);
            ReleaseObject(xlApp);
        }