Example #1
0
        public void CalculateTHR(DateTime effectiveDate, string holidays)
        {
            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                int mainSalaryDivider = 0;

                //employee
                DateTime startDate;

                string religion;

                int    monthPeriod = 0;
                int    yearPeriod  = 0;
                string branch      = "";
                string department  = "";
                string grade       = "";
                int    gradeLevel  = 0;
                string occupation  = "";
                string status      = "";
                string paymentType = "";

                bool   isTransfer    = false;
                string bankName      = "";
                string accountNumber = "";

                string  holidayType  = "";
                decimal mainSalary   = 0;
                decimal amount       = 0;
                decimal otherAmount  = 0;
                decimal totalAmount  = 0;
                string  amountInWord = "";
                bool    isPaid       = false;

                //EMPLOYEE
                List <Employee> employees = new List <Employee>();
                if (holidays == "LEBARAN")
                {
                    employees = employeeRepository.GetMoslemEmployee();
                }
                else
                {
                    employees = employeeRepository.GetNonMoslemEmployee();
                }

                foreach (var e in employees)
                {
                    mainSalary  = 0;
                    amount      = 0;
                    otherAmount = 0;
                    totalAmount = 0;

                    startDate     = e.StartDate;
                    isTransfer    = e.IsTransfer;
                    bankName      = e.BankName;
                    accountNumber = e.AccountNumber;

                    monthPeriod = effectiveDate.Month;
                    yearPeriod  = effectiveDate.Year;



                    //LAMA KERJA
                    CalculateYearAndMonth(startDate, effectiveDate);

                    if (monthOfWork >= 3 || yearOfWork >= 1)
                    {
                        //HARI RAYA
                        religion = e.Religion;

                        if (religion == "Islam")
                        {
                            holidayType = "LEBARAN";
                        }
                        else
                        {
                            holidayType = "NATAL";
                        }



                        //AMBIL BRANCH & DEPT
                        var dept = employeeDepartmentRepository.GetCurrentDepartment(e.ID, monthPeriod, yearPeriod);
                        if (dept != null)
                        {
                            department = dept.DepartmentName;
                            branch     = dept.BranchName;
                        }
                        else
                        {
                            var previousDept = employeeDepartmentRepository.GetPreviousDepartment(e.ID, monthPeriod, yearPeriod);
                            if (previousDept != null)
                            {
                                department = previousDept.DepartmentName;
                                branch     = previousDept.BranchName;
                            }
                        }

                        //AMBIL GRADE
                        var grades = employeeGradeRepository.GetCurrentGrade(e.ID, monthPeriod, yearPeriod);
                        if (grades != null)
                        {
                            grade      = grades.GradeName;
                            gradeLevel = grades.GradeLevel;
                        }
                        else
                        {
                            var previousGrade = employeeGradeRepository.GetPreviousGrade(e.ID, monthPeriod, yearPeriod);
                            if (previousGrade != null)
                            {
                                department = previousGrade.GradeName;
                                gradeLevel = previousGrade.GradeLevel;
                            }
                        }


                        //AMBIL OCCUPATION
                        var occupations = employeeOccupationRepository.GetCurrentOccupation(e.ID, monthPeriod, yearPeriod);
                        if (occupations != null)
                        {
                            occupation = occupations.OccupationName;
                        }
                        else
                        {
                            var previousOccupation = employeeOccupationRepository.GetPreviousOccupation(e.ID, monthPeriod, yearPeriod);
                            if (previousOccupation != null)
                            {
                                occupation = previousOccupation.OccupationName;
                            }
                        }

                        //AMBIL STATUS
                        var statusEmployee = employeeStatusRepository.GetCurrentStatus(e.ID, monthPeriod, yearPeriod);
                        if (statusEmployee != null)
                        {
                            status      = statusEmployee.Status;
                            paymentType = statusEmployee.PaymentType;
                        }
                        else
                        {
                            var previousStatus = employeeStatusRepository.GetPreviousStatus(e.ID, monthPeriod, yearPeriod);
                            if (previousStatus != null)
                            {
                                status      = previousStatus.Status;
                                paymentType = previousStatus.PaymentType;
                            }
                        }



                        //AMBIL NILAI-NILAI GAJI
                        var salary = employeeSalaryRepository.GetCurrentSalary(e.ID, monthPeriod, yearPeriod);
                        if (salary != null)
                        {
                            mainSalary = salary.MainSalary;
                        }
                        else
                        {
                            var previousSalary = employeeSalaryRepository.GetPreviousSalary(e.ID, monthPeriod, yearPeriod);
                            if (previousSalary != null)
                            {
                                mainSalary = previousSalary.MainSalary;
                            }
                        }


                        //HITUNG THR
                        if (yearOfWork >= 1)
                        {
                            amount = mainSalary;
                        }
                        else if (monthOfWork >= 3 && monthOfWork <= 12)
                        {
                            amount = ((Convert.ToDecimal(monthOfWork)) / 12) * mainSalary;
                        }
                        else if (monthOfWork < 3)
                        {
                            amount = 0;
                        }

                        totalAmount = Math.Round(amount) + otherAmount;

                        if (totalAmount > 0)
                        {
                            string amountInWords = Store.GetAmounInWords(Convert.ToInt32(totalAmount));
                            string firstLetter   = amountInWords.Substring(0, 2).Trim().ToUpper();
                            string theRest       = amountInWords.Substring(2, amountInWords.Length - 2);
                            amountInWord = firstLetter + theRest + " rupiah";
                        }
                        else
                        {
                            amountInWord = "Nol rupiah";
                        }


                        THR oldTHR = GetByEmployeeId(e.ID, Store.ActiveYear);
                        THR thr    = new THR();

                        thr.YearPeriod    = yearPeriod;
                        thr.EffectiveDate = effectiveDate;
                        thr.EmployeeId    = e.ID;
                        thr.StartDate     = startDate;
                        thr.Branch        = branch;
                        thr.Department    = department;
                        thr.Grade         = grade;
                        thr.GradeLevel    = gradeLevel;
                        thr.Occupation    = occupation;
                        thr.Status        = status;
                        thr.PaymentType   = paymentType;
                        thr.IsTransfer    = isTransfer;
                        thr.BankName      = bankName;
                        thr.AccountNumber = accountNumber;
                        thr.HolidayType   = holidayType;
                        thr.YearOfWork    = yearOfWork;
                        thr.MonthOfWork   = Convert.ToInt32(monthOfWork);
                        thr.DayOfWork     = daysOfWork;
                        thr.MainSalary    = mainSalary;
                        thr.Amount        = amount;
                        thr.OtherAmount   = otherAmount;
                        thr.TotalAmount   = totalAmount;
                        thr.AmountInWords = amountInWord;
                        thr.IsPaid        = false;

                        if (oldTHR == null)
                        {
                            Save(thr);
                        }
                        else
                        {
                            thr.ID            = oldTHR.ID;
                            thr.Branch        = branch;
                            thr.Department    = department;
                            thr.Grade         = grade;
                            thr.GradeLevel    = gradeLevel;
                            thr.Occupation    = occupation;
                            thr.Status        = status;
                            thr.PaymentType   = paymentType;
                            thr.IsTransfer    = isTransfer;
                            thr.BankName      = bankName;
                            thr.AccountNumber = accountNumber;
                            thr.MainSalary    = mainSalary;
                            thr.Amount        = amount;
                            thr.OtherAmount   = oldTHR.OtherAmount;
                            thr.TotalAmount   = amount + thr.OtherAmount;
                            if (thr.TotalAmount > 0)
                            {
                                string amountInWords = Store.GetAmounInWords(Convert.ToInt32(thr.TotalAmount));
                                string firstLetter   = amountInWords.Substring(0, 2).Trim().ToUpper();
                                string theRest       = amountInWords.Substring(2, amountInWords.Length - 2);
                                thr.AmountInWords = firstLetter + theRest + " rupiah";
                            }
                            else
                            {
                                thr.AmountInWords = "Nol rupiah";
                            }

                            Update(thr);
                        }
                    }
                }
            }
        }
Example #2
0
        private void SaveIncentive()
        {
            if (txtEmployeeId.Text == "")
            {
                MessageBox.Show("Karyawan harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtEmployeeId.Focus();
            }
            else if (txtAmount.Text == "" || decimal.Parse(txtAmount.Text.Replace(".", "")) == 0)
            {
                MessageBox.Show("Nilai harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtAmount.Focus();
            }
            else if (formMode == FormMode.Add && incentiveRepository.IsExisted(new Guid(txtEmployeeId.Text), Store.ActiveMonth, Store.ActiveYear))
            {
                MessageBox.Show("NIK : " + txtCode.Text + "\nNama : " + txtName.Text + "\n\nsudah ada ", "Perhatian",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                string department    = "";
                string branch        = "";
                bool   isTransfer    = false;
                string bankName      = "";
                string accountNumber = "";

                Incentive incentive = new Incentive();

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

                //AMBIL BANK NAME
                var employee = employeeRepository.GetById(new Guid(txtEmployeeId.Text));
                if (employee != null)
                {
                    isTransfer    = employee.IsTransfer;
                    bankName      = employee.BankName;
                    accountNumber = employee.AccountNumber;
                }

                //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;
                    }
                }

                incentive.Department       = department;
                incentive.Branch           = branch;
                incentive.IsTransfer       = isTransfer;
                incentive.BankName         = bankName;
                incentive.AccountNumber    = accountNumber;
                incentive.IsIncludePayroll = false;
                incentive.IsPaid           = false;
                incentive.MonthPeriod      = Store.ActiveMonth;
                incentive.YearPeriod       = Store.ActiveYear;
                incentive.Amount           = decimal.Parse(txtAmount.Text == "" ? "0" : txtAmount.Text.Replace(".", string.Empty));

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

                if (formMode == FormMode.Add)
                {
                    incentiveRepository.Save(incentive);
                    GetLastIncentive();
                }
                else if (formMode == FormMode.Edit)
                {
                    incentive.ID = new Guid(txtID.Text);
                    incentiveRepository.Update(incentive);
                }

                LoadIncentive();
                DisableForm();

                formMode  = FormMode.View;
                this.Text = "Insentif";
            }
        }
Example #3
0
        public void GenerateAbsence(int month, int year)
        {
            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    Guid     employeeId   = Guid.Empty;
                    string   employeeCode = "";
                    string   employeeName = "";
                    DateTime employeeStartDate;
                    string   branch     = "";
                    string   department = "";

                    int workingDays  = 0;
                    int absenceTotal = 0;
                    int workDay      = 0;
                    int workDayValue = 0;
                    int oldTotal     = 0;
                    int newOffDay    = 0;

                    int monthCutOfDate = month;
                    int yearCutOfDate  = year;

                    //ambil hari kerja
                    WorkCalendar workCalendar = workCalendarRepository.GetByMonthYear(month, year);
                    if (workCalendar != null)
                    {
                        workDay      = workCalendar.WorkDay;
                        absenceTotal = workDay;
                    }

                    //ambil tgl cut off
                    if (month == 1)
                    {
                        yearCutOfDate  = year - 1;
                        monthCutOfDate = 12;
                    }
                    DateTime dtStart = new DateTime(yearCutOfDate, monthCutOfDate - 1, (int)Store.CutOffDate - 1);
                    DateTime dtEnd   = new DateTime(yearCutOfDate, monthCutOfDate, (int)Store.CutOffDate);

                    //EMPLOYEE
                    List <Employee> employees = employeeRepository.GetActiveEmployee();

                    foreach (var e in employees)
                    {
                        workingDays = 0;
                        newOffDay   = 0;


                        employeeId        = e.ID;
                        employeeCode      = e.EmployeeCode;
                        employeeName      = e.EmployeeName;
                        employeeStartDate = e.StartDate;


                        TimeSpan days = dtEnd.Subtract(employeeStartDate);
                        if (days.TotalDays > 0)
                        {
                            workingDays = Convert.ToInt32(days.TotalDays);
                        }
                        else
                        {
                            workingDays = 0;
                        }

                        if (workingDays < workDay)
                        {
                            workDayValue = workingDays;
                        }
                        else
                        {
                            workDayValue = workDay;
                        }

                        if (absenceTotal > workDayValue)
                        {
                            newOffDay = absenceTotal - workDayValue;
                        }


                        Absence absence = new Absence();

                        //AMBIL BRANCH & DEPT
                        var dept = employeeDepartmentRepository.GetCurrentDepartment(employeeId, month, year);
                        if (dept != null)
                        {
                            department = dept.DepartmentName;
                            branch     = dept.BranchName;
                        }
                        else
                        {
                            var previousDept = employeeDepartmentRepository.GetPreviousDepartment(employeeId, month, year);
                            if (previousDept != null)
                            {
                                department = previousDept.DepartmentName;
                                branch     = previousDept.BranchName;
                            }
                        }

                        Absence oldAbsences = GetByEmployeeId(employeeId, month, year);

                        if (oldAbsences == null)
                        {
                            absence.MonthPeriod      = month;
                            absence.YearPeriod       = year;
                            absence.AbsenceStartDate = dtStart;
                            absence.AbsenceEndDate   = dtEnd;
                            absence.EmployeeId       = employeeId;
                            absence.Branch           = branch;
                            absence.Department       = department;
                            absence.WorkDay          = workDayValue;
                            absence.OnLeaveDay       = 0;
                            absence.OffDay           = newOffDay;
                            absence.Total            = absenceTotal;
                            absence.CreatedDate      = DateTime.Now;
                            absence.CreatedBy        = Store.ActiveUser;
                            absence.ModifiedDate     = DateTime.Now;
                            absence.ModifiedBy       = Store.ActiveUser;

                            Save(absence);
                        }
                        else
                        {
                            absence.ID               = oldAbsences.ID;
                            absence.MonthPeriod      = oldAbsences.MonthPeriod;
                            absence.YearPeriod       = oldAbsences.YearPeriod;
                            absence.AbsenceStartDate = oldAbsences.AbsenceStartDate;
                            absence.AbsenceEndDate   = oldAbsences.AbsenceEndDate;
                            absence.EmployeeId       = employeeId;
                            absence.Branch           = branch;
                            absence.Department       = department;
                            oldTotal = oldAbsences.WorkDay + oldAbsences.OnLeaveDay + oldAbsences.OffDay;
                            if (absenceTotal > 0)
                            {
                                newOffDay = (absenceTotal - oldTotal) + oldAbsences.OffDay;
                            }
                            absence.WorkDay    = oldAbsences.WorkDay;
                            absence.OnLeaveDay = oldAbsences.OnLeaveDay;
                            absence.OffDay     = newOffDay;
                            absence.Total      = absenceTotal;

                            absence.ModifiedDate = DateTime.Now;
                            absence.ModifiedBy   = Store.ActiveUser;

                            Update(absence);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
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";
            }
        }
Example #5
0
        private void SaveAbsence()
        {
            if (Store.IsPeriodClosed)
            {
                MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (int.Parse(txtTotalTemp.Text) > int.Parse(txtTotal.Text) || int.Parse(txtTotalTemp.Text) < int.Parse(txtTotal.Text))
            {
                MessageBox.Show("Total absensi harus sama dengan hari kerja", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtWorkDay.Focus();
            }
            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;
                }


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

                Absence absence = new Absence();

                absence.MonthPeriod      = Store.GetMonthCode(txtMonthPeriod.Text);
                absence.YearPeriod       = int.Parse(txtYearPeriod.Text);
                absence.AbsenceStartDate = dtStart;
                absence.AbsenceEndDate   = dtEnd;
                absence.EmployeeId       = new Guid(txtEmployeeId.Text);

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

                absence.WorkDay    = int.Parse(txtWorkDay.Text == "" ? "0" : txtWorkDay.Text);
                absence.OnLeaveDay = int.Parse(txtOnLeaveDay.Text == "" ? "0" : txtOnLeaveDay.Text);
                absence.OffDay     = int.Parse(txtOffDay.Text == "" ? "0" : txtOffDay.Text);
                absence.Total      = int.Parse(txtTotal.Text == "" ? "0" : txtTotal.Text);

                if (formMode == FormMode.Add)
                {
                    absenceRepository.Save(absence);
                    GetLastAbsence();
                }
                else if (formMode == FormMode.Edit)
                {
                    absence.ID = new Guid(txtID.Text);
                    absenceRepository.Update(absence);
                }

                LoadAbsence();
                DisableForm();

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