159 lines
6.4 KiB
C#
159 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Model;
|
|
|
|
namespace Payroll.UI
|
|
{
|
|
public partial class fEmpLeaveAdjustment : BaseFormTest
|
|
{
|
|
public fEmpLeaveAdjustment()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private ObjectsTemplate<EmployeeUnAuthorizeLeave> _EmpLeaves = null;
|
|
|
|
private void fEmpLeaveAdjustment_Load(object sender, EventArgs e)
|
|
{
|
|
ctlEmployee.Focus();
|
|
}
|
|
|
|
private bool IsValid()
|
|
{
|
|
if (ctlEmployee.SelectedEmployee == null)
|
|
{
|
|
MessageBox.Show("Select an Employee.", "Calculate", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
ctlEmployee.Focus();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void RefreshList()
|
|
{
|
|
dgvEmpLeaves.Rows.Clear();
|
|
int count = 0;
|
|
_EmpLeaves = EmployeeUnAuthorizeLeave.GetByEmployee(ctlEmployee.SelectedEmployee.EmployeeID, GlobalFunctions.LastDateOfMonth(dtpSalaryOf.Value), EnumLeaveEntryType.Normal);
|
|
if (_EmpLeaves == null) return;
|
|
int previouslyAutorize = 0;
|
|
int CurrAuthorize = 0;
|
|
foreach (EmployeeUnAuthorizeLeave leave in _EmpLeaves)
|
|
{
|
|
leave.Type = EnumLeaveEntryType.PaidLeave;
|
|
dgvEmpLeaves.Rows.Add();
|
|
CurrAuthorize = leave.AuthorizedDays(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate);
|
|
previouslyAutorize = leave.AdjustedDays - CurrAuthorize;
|
|
if (previouslyAutorize < 0) previouslyAutorize = 0;
|
|
dgvEmpLeaves.Rows[count].Cells[0].Value = leave.MonthDate.Date.ToString("MMM yyyy");
|
|
dgvEmpLeaves.Rows[count].Cells[1].Value = leave.FromDate.Date.ToString("dd MMM yyyy") + "-" + leave.ToDate.Date.ToString("dd MMM yyyy");
|
|
dgvEmpLeaves.Rows[count].Cells[2].Value = leave.LeaveDays.ToString();
|
|
dgvEmpLeaves.Rows[count].Cells[3].Value = previouslyAutorize.ToString();
|
|
dgvEmpLeaves.Rows[count].Cells[4].Value = CurrAuthorize.ToString(); ;
|
|
dgvEmpLeaves.Rows[count].Tag = leave;
|
|
count++;
|
|
}
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (!IsValid()) return;
|
|
if (MessageBox.Show("Do you want to save the informations?", "Confirm Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
|
|
DateTime currentMonth = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
|
|
EmployeeUnAuthorizeLeave.SaveAuthrizedLeave(ctlEmployee.SelectedEmployee.EmployeeID, currentMonth, RefreshObject());
|
|
|
|
MessageBox.Show("Data saved successfully.", "Save information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
RefreshValue();
|
|
}
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
if (exp.InnerException == null)
|
|
MessageBox.Show(exp.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
else
|
|
MessageBox.Show(exp.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void RefreshValue()
|
|
{
|
|
dgvEmpLeaves.Rows.Clear();
|
|
ctlEmployee.Clear();
|
|
_EmpLeaves = null;
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void ctlEmployee_ItemChanged()
|
|
{
|
|
if (ctlEmployee.SelectedEmployee != null)
|
|
{
|
|
RefreshList();
|
|
}
|
|
}
|
|
|
|
private ObjectsTemplate<EmployeeUnAuthorizeLeave> RefreshObject()
|
|
{
|
|
ObjectsTemplate<EmployeeUnAuthorizeLeave> oEmpLeaves = new ObjectsTemplate<EmployeeUnAuthorizeLeave>();//EmployeeUnAuthorizeLeave.GetDeductedLeaves(ctlEmployee.SelectedEmployee.EmployeeID, _LeaveParams[cboLeaves.SelectedIndex].UnAhuthorizeLeaveID, EnumLeaveEntryType.Normal);
|
|
for (int i = 0; i < dgvEmpLeaves.RowCount - 1; i++)
|
|
{
|
|
EmployeeUnAuthorizeLeave olditem =((EmployeeUnAuthorizeLeave) dgvEmpLeaves.Rows[i].Tag);
|
|
EmployeeUnAuthorizeLeave newItem = olditem.GetClone();
|
|
newItem.ReferenceID = olditem.ID;
|
|
newItem.Type = EnumLeaveEntryType.PaidLeave;
|
|
newItem.LeaveDays = Convert.ToInt32(dgvEmpLeaves.Rows[i].Cells[4].Value);
|
|
|
|
if (newItem.LeaveDays > 0) oEmpLeaves.Add(newItem);
|
|
}
|
|
return oEmpLeaves;
|
|
}
|
|
private void cboLeaves_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (ctlEmployee.SelectedEmployee != null )
|
|
{
|
|
ObjectsTemplate<EmployeeUnAuthorizeLeave> oEmpLeaves = null;//EmployeeUnAuthorizeLeave.GetDeductedLeaves(ctlEmployee.SelectedEmployee.EmployeeID, _LeaveParams[cboLeaves.SelectedIndex].UnAhuthorizeLeaveID, EnumLeaveEntryType.Normal);
|
|
_EmpLeaves = new ObjectsTemplate<EmployeeUnAuthorizeLeave>();
|
|
|
|
foreach (EmployeeUnAuthorizeLeave oItem in oEmpLeaves)
|
|
{
|
|
EmployeeUnAuthorizeLeave oEmpLeave = new EmployeeUnAuthorizeLeave();
|
|
|
|
oEmpLeave.EmployeeID = oItem.EmployeeID;
|
|
oEmpLeave.FromDate = oItem.FromDate;
|
|
oEmpLeave.LeaveDays = oItem.LeaveDays;
|
|
oEmpLeave.LeaveMonth = oItem.LeaveMonth;
|
|
oEmpLeave.MonthDate = oItem.MonthDate;
|
|
oEmpLeave.ParamID = oItem.ParamID;
|
|
oEmpLeave.ReferenceID = oItem.ID;
|
|
oEmpLeave.ToDate = oItem.ToDate;
|
|
oEmpLeave.Type = EnumLeaveEntryType.PaidLeave;
|
|
oEmpLeave.UnAuthorizeleaveID = oItem.UnAuthorizeleaveID;
|
|
|
|
_EmpLeaves.Add(oEmpLeave);
|
|
}
|
|
RefreshList();
|
|
}
|
|
}
|
|
|
|
private void dtpSalaryOf_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
if(ctlEmployee.SelectedEmployee !=null)
|
|
RefreshList();
|
|
}
|
|
|
|
|
|
}
|
|
}
|