CEL_Payroll/Payroll.UI/Payroll.UI/JVSetup/fJVSetupDetail.cs
2025-08-06 14:31:52 +06:00

537 lines
20 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 Ease.CoreV35.Utility;
using Payroll.BO;
using Ease.CoreV35.Model;
using Payroll.Report;
using Ease.CoreV35;
namespace Payroll.UI
{
public partial class fJVSetupDetail : BaseFormTest
{
public event JVSetup.ItemChanged ItemChanged;
ObjectsTemplate<JVType> _jvTypes = null;
List<JVSetupDetail> allItems = new List<JVSetupDetail>();
JVSetup _jvSetup = null;
bool _fromSap = false;
public fJVSetupDetail()
{
InitializeComponent();
allItems = JVSetupDetail.ConstantItems();
RefreshJVTypes();
//_fromSap = ConfigurationManager.GetBoolValue("jv", "sap", EnumConfigurationType.Logic);
//if (_fromSap ==true)
//{
// chkIsConfirmed.Visible = false;
// chkEmpDetailPage.Visible = true;
// chkCCWiseCumulative.Visible = false;
// grpCCPC.Enabled = true;
// grpCCPC.Visible = true;
//}
//else
//{
// chkIsConfirmed.Visible = true;
// chkEmpDetailPage.Visible = true;
// chkCCWiseCumulative.Visible = true;
// grpCCPC.Enabled = false;
// grpCCPC.Visible = false;
// AdjustControlLocation();
//}
dtpMonth.Value = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
chkIsConfirmed.Visible = false;
chkEmpDetailPage.Visible = false;
rdoCCWiseCumulative.Visible = true;
grpCCPC.Enabled = false;
grpCCPC.Visible = false;
AdjustControlLocation();
RefreshList();
}
#region Methods
public void ShowDlg(JVSetup oJVSetup)
{
_jvSetup = oJVSetup;
RefreshJVTypes();
ctlEmployee.Enabled = false;
if (oJVSetup.IsNew)
{
this.Text = "Add New JV Setup";
cboJVType.Focus();
}
else
{
this.Text = "Edit JV Setup";
RefreshControl();
}
this.ShowDialog();
}
private void RefreshJVTypes()
{
_jvTypes = JVType.Get();
cboJVType.Items.Clear();
foreach (JVType jvType in _jvTypes)
{
cboJVType.Items.Add(jvType);
}
cboJVType.DisplayMember = "Name";
cboJVType.ValueMember = "ID";
if (cboJVType.Items.Count > 0) cboJVType.SelectedIndex = 0;
}
private void RefreshList()
{
lsvDescription.Items.Clear();
foreach (JVSetupDetail oDetail in allItems)
{
ListViewItem oItem = new ListViewItem();
oItem.SubItems.Add(oDetail.Name);
oItem.SubItems.Add(oDetail.JVItemType.ToString());
oItem.Checked = false;
oItem.Tag = oDetail;
lsvDescription.Items.Add(oItem);
}
}
private bool ValidateInput()
{
if (cboJVType.SelectedIndex < 0)
{
MessageBox.Show("Please select JV Type", "Save JV Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
cboJVType.Focus();
return false;
}
if (txtDescription.Text.Trim().Length == 0)
{
MessageBox.Show("Enter Description", "Save JV Setup.", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtDescription.Focus();
return false;
}
if (txtGLCode.Text.Trim().Length == 0)
{
MessageBox.Show("Enter GL Code", "Save JV Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtGLCode.Focus();
return false;
}
if (cboSide.SelectedIndex < 0)
{
MessageBox.Show("Please select Side", "Save JV Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
cboSide.Focus();
return false;
}
if (txtSideCode.Text.Trim().Length == 0)
{
MessageBox.Show("Enter Side Code", "Save JV Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSideCode.Focus();
return false;
}
//if (dtpMonth.Value < GlobalFunctions.FirstDateOfMonth(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate))
//{
// MessageBox.Show("Month can't be less than Current Pay Process Month", "Save JV Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
// dtpMonth.Focus();
// return false;
//}
return true;
}
private void RefreshObject()
{
if (_jvSetup == null)
{
_jvSetup = new JVSetup();
}
_jvSetup.JVTypeID = ((JVType)cboJVType.SelectedItem).ID;
_jvSetup.Description = txtDescription.Text;
_jvSetup.GLCode = txtGLCode.Text;
int nSequenceNo = _jvSetup.GetSequenceNo();
if (_jvSetup.IsNew)
{
_jvSetup.SequenceNo = nSequenceNo + 1;
}
else
{
_jvSetup.SequenceNo = nSequenceNo;
}
if (cboSide.Text.ToLower() == "debit")
{
_jvSetup.Side = (int)EnumTranSide.Debit;
}
else if (cboSide.Text.ToLower() == "credit")
{
_jvSetup.Side = (int)EnumTranSide.Credit;
}
if (rdoRegardless.Checked)
{
_jvSetup.EMPLOYEETYPE = EnumJVEmpType.RegardLess;
}
else if ( rdoExpat.Checked)
{
_jvSetup.EMPLOYEETYPE = EnumJVEmpType.Expat;
}
else if (rdoLocal.Checked)
{
_jvSetup.EMPLOYEETYPE = EnumJVEmpType.Local;
}
if (ctlEmployee.SelectedEmployee != null)
{
_jvSetup.EmployeeID = ctlEmployee.SelectedEmployee.EmployeeID;
}
_jvSetup.SideCode = txtSideCode.Text;
_jvSetup.GroupCode = txtGroupCode.Text.Length>0?txtGroupCode.Text:" ";
_jvSetup.MonthDate = GlobalFunctions.LastDateOfMonth(dtpMonth.Value);
//_jvSetup.MonthDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;
_jvSetup.IsEmployeeDetail = chkEmpDetailPage.Checked;
//if (!rdoPark.Checked)
//{
_jvSetup.BookToCC = rdoIsSpecificCost.Checked;
if (_fromSap == true)
{
_jvSetup.IsConfirmed = false;
_jvSetup.ShowCC = false;
//if (rdoBookToDepartment.Checked)
// _jvSetup.BookToCC = rdoBookToDepartment.Checked;
//else if (rdoBookToProfitCenter.Checked)
// _jvSetup.BookToPC = rdoBookToProfitCenter.Checked;
}
else
{
_jvSetup.IsConfirmed = chkIsConfirmed.Checked;
_jvSetup.ShowCC = rdoCCWiseCumulative.Checked;
}
//}
//else
//{
// _jvSetup.BookToCC = rdoPark.Checked;
// if (_fromSap == true)
// {
// _jvSetup.IsConfirmed = false;
// _jvSetup.ShowCC = false;
// //if (rdoBookToDepartment.Checked)
// // _jvSetup.BookToCC = rdoBookToDepartment.Checked;
// //else if (rdoBookToProfitCenter.Checked)
// // _jvSetup.BookToPC = rdoBookToProfitCenter.Checked;
// }
// else
// {
// _jvSetup.IsConfirmed = chkIsConfirmed.Checked;
// _jvSetup.ShowCC = rdoPark.Checked;
// }
//}
_jvSetup.JVSetupDetails.Clear();
foreach (ListViewItem oItem in lsvDescription.Items)
{
if (oItem.Checked)
{
JVSetupDetail jvSetupDetail = new JVSetupDetail();
jvSetupDetail.ItemID = ((JVSetupDetail)oItem.Tag).ItemID;
jvSetupDetail.JVItemType = (enumPayrollComponentType)(((JVSetupDetail)oItem.Tag).JVItemType);
jvSetupDetail.Name = ((JVSetupDetail)oItem.Tag).Name;
_jvSetup.JVSetupDetails.Add(jvSetupDetail);
}
}
_jvSetup.JVSetupCC = new ObjectsTemplate<JVSetupCC>();
_jvSetup.JVSetupCC.Clear();
if (cbcDepartment.IsItemSelected == true)
{
ObjectsTemplate<Department> oSetupCCs = new ObjectsTemplate<Department>();
oSetupCCs = cbcDepartment.GetSelectedObjects<Department>();
foreach (Department oCC in oSetupCCs)
{
JVSetupCC osetupCC = new JVSetupCC();
osetupCC.CCID = oCC.ID;
_jvSetup.JVSetupCC.Add(osetupCC);
}
}
}
private void RefreshControl()
{
cboJVType.SelectedItem = _jvSetup.JVType;
txtDescription.Text = _jvSetup.Description;
txtGLCode.Text = _jvSetup.GLCode;
dtpMonth.Value = _jvSetup.MonthDate;
cboSide.SelectedIndex = (int)_jvSetup.Side - 1; //collection value is hard coded
txtSideCode.Text = _jvSetup.SideCode;
txtGroupCode.Text = _jvSetup.GroupCode;
chkEmpDetailPage.Checked = _jvSetup.IsEmployeeDetail;
rdoIsSpecificCost.Checked = _jvSetup.BookToCC;
rdoCCWiseCumulative.Checked = _jvSetup.ShowCC;
if (_jvSetup.EMPLOYEETYPE == EnumJVEmpType.RegardLess)
{
rdoRegardless.Checked = true;
}
else if (_jvSetup.EMPLOYEETYPE == EnumJVEmpType.Expat)
{
rdoExpat.Checked = true;
}
else if (_jvSetup.EMPLOYEETYPE == EnumJVEmpType.Local)
{
rdoLocal.Checked = true;
}
if(!_jvSetup.BookToCC && !_jvSetup.ShowCC)
{
rdoPark.Checked = true;
}
List<Department> oCCs = new List<Department>();
foreach (JVSetupCC oItem in _jvSetup.JVSetupCC)
{
Department oCC = Department.Get(oItem.CCID);
oCCs.Add(oCC);
}
cbcDepartment.SetSelectedObjects<Department>(oCCs);
if (_jvSetup.JVSetupCC.Count > 0)
{
lsvDepartment.Items.Clear();
ListViewItem lsvItem = null;
foreach (JVSetupCC oItem in _jvSetup.JVSetupCC)
{
lsvItem = new ListViewItem();
Department oCC = Department.Get(oItem.CCID);
lsvItem.Text = oCC.Code;
lsvItem.SubItems.Add(oCC.Name);
lsvDepartment.Items.Add(lsvItem);
}
}
if (_jvSetup.EmployeeID!=null)
{
ctlEmployee.SetSelectedEmployee(SearchEmployee.GetSearchEmployeeFromEmployee(Employee.Get(_jvSetup.EmployeeID)));
rdoEmployee.Checked = true;
}
if (_fromSap == true)
{
//rdoBookToDepartment.Checked = _jvSetup.BookToCC;
//rdoBookToProfitCenter.Checked = _jvSetup.BookToPC;
}
else
{
chkIsConfirmed.Checked = _jvSetup.IsConfirmed;
}
if (_jvSetup.JVSetupDetails != null && lsvDescription.Items.Count > 0)
{
foreach (JVSetupDetail oDetail in _jvSetup.JVSetupDetails)
{
foreach (ListViewItem oItem in lsvDescription.Items)
{
if (oDetail.ItemID == ((JVSetupDetail)oItem.Tag).ItemID)
{
if (oDetail.JVItemType == ((JVSetupDetail)oItem.Tag).JVItemType)
{
oItem.Checked = true;
break;
}
}
}
}
}
}
private void ResetControls()
{
cboJVType.SelectedIndex = 0;
txtDescription.Text = string.Empty;
txtGLCode.Text = string.Empty;
cboSide.SelectedIndex = 0;
txtSideCode.Text = string.Empty;
chkIsConfirmed.Checked = false;
chkEmpDetailPage.Checked = false;
//chkCCWiseCumulative.Checked = false;
//chkIsSpecificCost.Checked = false;
foreach (ListViewItem oItem in lsvDescription.Items)
{
oItem.Checked = false;
}
}
private void AdjustControlLocation()
{
if (_fromSap != true)
{
grpJVSetupDescription.Height = grpJVSetupDescription.Height - grpCCPC.Height;
grpCC.Top = grpJVSetupDescription.Bottom + 3;
grpJVSetupDetail.Top = grpCC.Bottom + 3;
grpCancel.Top = grpJVSetupDetail.Bottom + 3;
this.Height = this.Height - grpCCPC.Height + 2;
}
}
private void EnableDisable(string jvType)
{
switch (jvType.ToLower())
{
case "salary":
lblMonth.Visible = true;
dtpMonth.Visible = true;
lblDescription.Visible = true;
txtDescription.Visible = true;
lblGLCode.Visible = true;
txtGLCode.Visible = true;
lblSide.Visible = true;
cboSide.Visible = true;
txtSideCode.Visible = true;
lblSideCode.Visible = true;
chkEmpDetailPage.Visible = true;
chkIsConfirmed.Visible = false;
rdoCCWiseCumulative.Visible = true;
grpCCPC.Visible = true;
break;
case "loan":
lblMonth.Visible = true;
dtpMonth.Visible = true;
lblDescription.Visible = true;
txtDescription.Visible = true;
lblGLCode.Visible = true;
txtGLCode.Visible = true;
lblSide.Visible = true;
cboSide.Visible = true;
txtSideCode.Visible = true;
lblSideCode.Visible = true;
chkEmpDetailPage.Visible = false;
chkIsConfirmed.Visible = false;
rdoCCWiseCumulative.Visible = true;
grpCCPC.Visible = false;
break;
case "provision":
lblMonth.Visible = true;
dtpMonth.Visible = true;
lblDescription.Visible = true;
txtDescription.Visible = true;
lblGLCode.Visible = true;
txtGLCode.Visible = true;
lblSide.Visible = true;
cboSide.Visible = true;
txtSideCode.Visible = true;
lblSideCode.Visible = true;
chkEmpDetailPage.Visible = true;
chkIsConfirmed.Visible = false;
rdoCCWiseCumulative.Visible = true;
grpCCPC.Visible = true;
break;
case "treasury":
lblMonth.Visible = true;
dtpMonth.Visible = true;
lblDescription.Visible = true;
txtDescription.Visible = true;
lblGLCode.Visible = true;
txtGLCode.Visible = true;
lblSide.Visible = true;
cboSide.Visible = true;
txtSideCode.Visible = true;
lblSideCode.Visible = true;
chkEmpDetailPage.Visible = false;
chkIsConfirmed.Visible = false;
rdoCCWiseCumulative.Visible = true;
grpCCPC.Visible = false;
break;
}
}
#endregion
#region Events
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (!ValidateInput()) return;
RefreshObject();
if (MessageBox.Show("Are you sure to save", "Confirm Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
_jvSetup.Save();
ResetControls();
if (ItemChanged != null)
{
ItemChanged();
}
if (_jvSetup.IsNew)
{
MessageBox.Show("Data Saved Successfully", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
cboJVType.Focus();
}
else
{
MessageBox.Show("Data Updated Successfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
catch (Exception ex)
{
if (ex.InnerException == null)
MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
private void cboJVType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
EnableDisable(((JVType)cboJVType.SelectedItem).Name);
}
catch (Exception Ex)
{
MessageBox.Show("Failed to Enable or Disable controls due to " + Ex.Message, "Enable/Disable Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void lsvDescription_ColumnClick(object sender, ColumnClickEventArgs e)
{
this.Cursor = Cursors.WaitCursor;
SortOrder order = SortOrder.Ascending;
if (order == lsvDescription.Sorting)
order = SortOrder.Descending;
else
order = SortOrder.Ascending;
lsvDescription.ListViewItemSorter = new Global.ItemSorter(e.Column, order);
lsvDescription.Sorting = order;
this.Cursor = Cursors.Default;
}
private void rdoIsSpecificCost_CheckedChanged(object sender, EventArgs e)
{
cbcDepartment.Enabled = rdoIsSpecificCost.Checked;
}
private void rdoEmployee_CheckedChanged(object sender, EventArgs e)
{
ctlEmployee.Enabled = rdoEmployee.Checked;
}
}
}