CEL_Payroll/Payroll.Report/Class/rptJV.cs

1547 lines
76 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using System.Data;
using Ease.CoreV35.Model;
using System.IO;
namespace Payroll.Report
{
public class rptJV
{
DateTime _dEffectDate;
private ReportSetup _selectedParameter;
public ReportSetup SelectedParameter
{
set
{
_selectedParameter = value;
}
}
public rptJV()
{
}
public DataTable JVSalaryDetail(ID JVTypeID, DateTime dEffectDate)
{
int count = 1;
_dEffectDate = dEffectDate;
DataRow dr = null;
PayrollDataSet.PayrollDataSet.JVSalaryDetailDataTable dTJVSDetail = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVSalaryDetailDataTable();
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(_dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = new ObjectsTemplate<JVSetup>();
oJVSetups = JVSetup.GetByJVTypeAndEffectDate(JVTypeID, maxdate);
int nLocationTire = ConfigurationManager.GetIntValue("Location", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Location> oLocations = new ObjectsTemplate<Location>();
oLocations = Location.GetByTier(2); // get the last tier data and last tier is defined in Logic configuration file
int nCCTire = ConfigurationManager.GetIntValue("costcenter", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Costcenter> oCostCenters = new ObjectsTemplate<Costcenter>();
oCostCenters = Costcenter.GetByTire(nCCTire); // get the last tier data and last tier is defined in Logic configuration file
ObjectsTemplate<SalaryMonthly> salaries = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
foreach (SalaryMonthly item in salaries)
{
foreach (JVSetup osetup in oJVSetups)
{
dr = dTJVSDetail.NewRow();
dr["SLNo"] = count;
dr["EmpNo"] = item.Employee.EmployeeNo;
dr["Name"] = item.Employee.Name;
dr["Description"] = osetup.Description;
dr["Amount"] = osetup.GetAmount(item);
dr["JVMonth"] = dEffectDate;
dTJVSDetail.Rows.Add(dr);
}
count++;
}
return dTJVSDetail;
}
public DataSet MemorandumSalaryDetail(ID JVTypeID, DateTime dEffectDate, int nEmpID)
{
DataSet oDS = new DataSet();
_dEffectDate = dEffectDate;
DataRow drDebit = null;
DataRow drCredit = null;
PayrollDataSet.PayrollDataSet.MemoDebitDataTable dTMemoDebit = new Payroll.Report.PayrollDataSet.PayrollDataSet.MemoDebitDataTable();
PayrollDataSet.PayrollDataSet.MemoCreditDataTable dTMemoCredit = new Payroll.Report.PayrollDataSet.PayrollDataSet.MemoCreditDataTable();
string sEmpID = Convert.ToString(nEmpID);
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(_dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = new ObjectsTemplate<JVSetup>();
oJVSetups = JVSetup.GetByJVTypeAndEffectDate(JVTypeID, maxdate);
//sEmpID,
ObjectsTemplate<SalaryMonthly> salaries = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
string sFGLCode = "";
double dFAmount = 0.0;
ObjectsTemplate<JVSetup> oJVSetupDebits = new ObjectsTemplate<JVSetup>();
ObjectsTemplate<JVSetup> oJVSetupCredits = new ObjectsTemplate<JVSetup>();
foreach (JVSetup oJVItem in oJVSetups)
{
if (oJVItem.Side == (int)EnumTranSide.Debit)
{
oJVSetupDebits.Add(oJVItem);
}
else if (oJVItem.Side == (int)EnumTranSide.Credit)
{
oJVSetupCredits.Add(oJVItem);
}
}
double ItemDebitHeadAmount = 0.0;
foreach (JVSetup oJVDebit in oJVSetupDebits)
{
ItemDebitHeadAmount = 0.0;
if (oJVDebit.ID.Integer == 1)
{
sFGLCode = oJVDebit.GLCode;
}
drDebit = dTMemoDebit.NewRow();
drDebit["DDescription"] = oJVDebit.Description;
drDebit["DAccount"] = oJVDebit.GLCode;
drDebit["FGLDes"] = sFGLCode;
foreach (SalaryMonthly oSM in salaries)
{
//if (oJVDebit.ID.Integer == 1)
// dFAmount = oJVDebit.GetAmount(oSM);
ItemDebitHeadAmount += oJVDebit.GetAmount(oSM, oJVDebit.JVSetupDetails);
}
if (oJVDebit.ID.Integer == 1)
drDebit["FGLAmount"] = Convert.ToString(ItemDebitHeadAmount);
drDebit["DAmount"] = ItemDebitHeadAmount;
dTMemoDebit.Rows.Add(drDebit);
}
double ItemCreditHeadAmount = 0.0;
foreach (JVSetup oJVCredit in oJVSetupCredits)
{
ItemCreditHeadAmount = 0.0;
drCredit = dTMemoCredit.NewRow();
//drCredit = dTMemoCredit.NewRow();
drCredit["CDescription"] = oJVCredit.Description;
drCredit["CAccount"] = oJVCredit.GLCode;
foreach (SalaryMonthly oSM in salaries)
{
ItemCreditHeadAmount += oJVCredit.GetAmount(oSM, oJVCredit.JVSetupDetails);
}
drCredit["CAmount"] = ItemCreditHeadAmount;
dTMemoCredit.Rows.Add(drCredit);
}
//foreach (SalaryMonthly item in salaries)
//{
// foreach (JVSetup osetup in oJVSetups)
// {
// if(osetup.ID.Integer==1)
// {
// sFGLCode = osetup.GLCode;
// dFAmount = osetup.GetAmount(item);
// }
// if(osetup.Side==(int)EnumTranSide.Debit)
// {
// drDebit = dTMemoDebit.NewRow();
// drDebit["DDescription"] = osetup.Description;
// drDebit["DAccount"] = osetup.GLCode;
// drDebit["DAmount"] = osetup.GetAmount(item);
// drDebit["FGLDes"] = sFGLCode;
// drDebit["FGLAmount"] = Convert.ToString(dFAmount);
// dTMemoDebit.Rows.Add(drDebit);
// }
// else if (osetup.Side == (int)EnumTranSide.Credit)
// {
// drCredit = dTMemoCredit.NewRow();
// drCredit["CDescription"] = osetup.Description;
// drCredit["CAccount"] = osetup.GLCode;
// drCredit["CAmount"] = osetup.GetAmount(item);
// dTMemoCredit.Rows.Add(drCredit);
// }
// }
// count++;
//}
DolarRate oDRate = new DolarRate();
oDRate = oDRate.Get(GlobalFunctions.LastDateOfMonth(_dEffectDate));
if (oDRate != null)
{
drDebit = dTMemoDebit.NewRow();
drDebit["DDescription"] = oDRate.DDescription;
drDebit["DAccount"] = oDRate.DAccountNo;
drDebit["DAmount"] = (oDRate.Amount * oDRate.Rate);
dTMemoDebit.Rows.Add(drDebit);
drCredit = dTMemoCredit.NewRow();
drCredit["CDescription"] = oDRate.DDescription;
drCredit["CAccount"] = oDRate.DAccountNo;
drCredit["CAmount"] = (oDRate.Amount * oDRate.Rate);
dTMemoCredit.Rows.Add(drCredit);
}
dTMemoDebit.TableName = "PayrollDataSet_MemoDebit";
dTMemoCredit.TableName = "PayrollDataSet_MemoCredit";
oDS.Tables.Add(dTMemoDebit);
oDS.Tables.Add(dTMemoCredit);
return oDS;
}
//public DataTable JVReport(ID JVTypeID,DateTime dEffectDate)
//{
// _dEffectDate = dEffectDate;
// DataRow dr = null;
// double nAmount = 0.0;
// PayrollDataSet.PayrollDataSet.JVReportDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVReportDataTable();
// JVSetup osetp = new JVSetup();
// DateTime maxdate = osetp.GetMaxDate(_dEffectDate);
// ObjectsTemplate<JVSetup> oJVSetups = new ObjectsTemplate<JVSetup>();
// oJVSetups = JVSetup.GetByJVTypeAndEffectDate(JVTypeID, maxdate);
// ObjectsTemplate<JVSetupDetail> oJVSetupDetails = new ObjectsTemplate<JVSetupDetail>();
// int nLocationTire = ConfigurationManager.GetIntValue("Location", "tier", EnumConfigurationType.Logic);
// ObjectsTemplate<Location> oLocations = new ObjectsTemplate<Location>();
// oLocations = Location.GetByTier(2); // get the last tier data and last tier is defined in Logic configuration file
// int nCCTire = ConfigurationManager.GetIntValue("costcenter", "tier", EnumConfigurationType.Logic);
// ObjectsTemplate<Costcenter> oCostCenters = new ObjectsTemplate<Costcenter>();
// oCostCenters = Costcenter.GetByTire(nCCTire); // get the last tier data and last tier is defined in Logic configuration file
// ObjectsTemplate<SalaryMonthly> salaries = SalaryMonthly.Get(dEffectDate);
// foreach (JVSetup oJVSetup in oJVSetups)
// {
// foreach (Costcenter oCC in oCostCenters)
// {
// foreach (Location oLocation in oLocations)
// {
// nAmount = 0.0;
// nAmount = GetSalaries(oLocation.ID, oCC.ID, salaries, oJVSetup);
// if (nAmount == 0) continue;
// oJVSetupDetails = JVSetupDetail.GetByJVSetup(oJVSetup.ID);
// dr = dTJVInfo.NewRow();
// dr["GLCode"] = oJVSetup.GLCode;
// dr["GLDescription"] = oJVSetup.Description;
// dr["JType"] = "GJ";
// dr["JSource"] = "MA";
// dr["Reference"] = "110001";
// dr["JVDate"] = dEffectDate.ToString("dd MMM yyyy");
// if (oJVSetup.Side == (int)EnumTranSide.Debit)
// {
// dr["JVTranType"] = "D";
// }
// else if(oJVSetup.Side==(int)EnumTranSide.Credit)
// {
// dr["JVTranType"] = "C";
// }
// dr["Amount"] = GlobalFunctions.Round(nAmount);
// dr["Period"] = dEffectDate.ToString("dd MMM yyyy");
// if (oCC.Parent.Code == "106X")
// {
// dr["T5"] = oCC.Code;
// }
// else
// {
// dr["T5"] = "XX";
// }
// dr["CostCenter"] = oCC.Parent.Code;
// dr["Location"] = oLocation.Code;
// dTJVInfo.Rows.Add(dr);
// }
// }
// }
// return dTJVInfo;
//}
public DataTable JVReport(ID JVTypeID, DateTime dEffectDate)
{
double totalBankAmount = 0;
_dEffectDate = Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate;// dEffectDate;
//dEffectDate = _dEffectDate;
DataRow dr = null;
double nSAmount = 0;
double nOAmount = 0;
double totalDebitAmount = 0;
string rCCode = string.Empty;
PayrollDataSet.PayrollDataSet.JVReportDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVReportDataTable();
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(_dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID, maxdate);
ObjectsTemplate<JVSetup> oJVSetupsDr = oJVSetups.Where(o => o.Side == (int)1).ToObjectsTemplate();
ObjectsTemplate<JVSetup> oJVSetupsCr = oJVSetups.Where(o => o.Side == (int)2).ToObjectsTemplate();
ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
ObjectsTemplate<SalaryMonthly> sMonthlys = new ObjectsTemplate<SalaryMonthly>();
ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
ObjectsTemplate<Department> oDepartments = Department.Get();
JVType jType = JVType.Get(JVTypeID);
List<string> groupRC = oDepartments.Select(d => d.RCCode ?? d.RCCode).Distinct().ToList<string>();
if (oJVSetups.Count > 0)
{
foreach (JVSetup jvstp in oJVSetups)
{
JVSetupDetail jVSetupDetail = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).FirstOrDefault();
if (jvstp.BookToCC)
{
foreach (JVSetupCC dep in jvstp.JVSetupCC)
{
//foreach (Department dp in deptRc)
//{
sMonthlys = oSalaryMonthlys.Where(s => s.DepartmentID == dep.CCID).ToObjectsTemplate();
oOPIPDetails = oOPIProcessDetails.Where(s => s.DepartmentID == dep.CCID).ToObjectsTemplate();
if (sMonthlys != null && sMonthlys.Count > 0)
{
foreach (SalaryMonthly slrmntl in sMonthlys)
{
nSAmount += jvstp.GetAmount(slrmntl);
}
}
if (oOPIPDetails != null && oOPIPDetails.Count > 0)
{
foreach (OPIProcessDetail oPPDtl in oOPIPDetails)
{
nOAmount += GetOPIAmount(jVSetupDetail.ItemID.Integer, oPPDtl.ID);
}
}
//}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
totalDebitAmount += nSAmount;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nSAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nSAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
totalDebitAmount += nOAmount;
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nOAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nOAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
}//dept end
}
else if(jvstp.ShowCC)
{
foreach (SalaryMonthly slrmntl in oSalaryMonthlys)
{
nSAmount += jvstp.GetAmount(slrmntl);
}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
totalDebitAmount += nSAmount;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nSAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nSAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
totalDebitAmount += nOAmount;
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nOAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nOAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
}
else if (jvstp.EmployeeID != null)
{
SalaryMonthly oItem = oSalaryMonthlys.Find(x => x.EmployeeID == jvstp.EmployeeID);
if (oItem != null)
{
nSAmount = jvstp.GetAmount(oItem);
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
if (!jvstp.Description.ToLower().Contains("loan"))
dr["Reference"] = oItem.RCCode;
totalDebitAmount += nSAmount;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nSAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nSAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = "";
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
dr["Reference"] = oItem.RCCode;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
totalDebitAmount += nOAmount;
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nOAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nOAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
}
}
}
}
return dTJVInfo;
}
//public DataTable PNLReport(ID JVTypeID, DateTime dEffectDate)
//{
// _dEffectDate = dEffectDate;
// DataRow dr = null;
// PayrollDataSet.PayrollDataSet.PNLReportDataTable dTPNLReport = new Payroll.Report.PayrollDataSet.PayrollDataSet.PNLReportDataTable();
// JVSetup osetp = new JVSetup();
// DateTime maxdate = osetp.GetMaxDate(dEffectDate);
// SalaryMonthly salaryMonthly = null;
// ObjectsTemplate<JVSetupDetail> jVSetupDetails = null;
// OPIProcessDetail opiProcessDetail = null;
// ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID,maxdate);
// ObjectsTemplate<JVSetup> oJVSetupsForFS = JVSetup.GetByJVTypeAndMonth(ID.FromInteger(2), maxdate);
// ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
// ObjectsTemplate<SalaryMonthly> sMonthlys = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
// ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(dEffectDate);
// ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
// ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
// ObjectsTemplate<Department> oDepartments = Department.Get();
// Department dept = null;
// ObjectsTemplate<Department> childDepts = new ObjectsTemplate<Department>();
// ObjectsTemplate<BonusProcess.BonusProcessDetail> bonusprocesss = BonusProcess.GetBonusDetails(GlobalFunctions.LastDateOfMonth(dEffectDate));
// ObjectsTemplate<Employee> _employees = Employee.Get();
// ObjectsTemplate<BonusProcess.BonusProcessDetail> bonuspr = null;
// double salaryAndOthers = 0;
// double sumOfBonus = 0;
// double sumOfEarnLeave = 0;
// double sumOfGroupInsurance = 0;
// double sumOfMedicalInsurance = 0;
// double sumOfPFGPContrb = 0;
// double sumOfGratuity = 0;
// double jvItemAmount = 0; double fsItemAmount = 0; double provisionItemAmount = 0;
// foreach (Employee item in _employees)
// {
// salaryAndOthers = sumOfBonus = sumOfEarnLeave = sumOfGroupInsurance = sumOfMedicalInsurance = sumOfPFGPContrb = sumOfGratuity = 0;
// foreach (JVSetup jvstp in oJVSetups)
// {
// jvItemAmount = provisionItemAmount = fsItemAmount = 0;
// jVSetupDetails = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).ToObjectsTemplate();
// if (jvstp.Description.ToString() == "Salary & Others")
// {
// salaryMonthly = sMonthlys.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (salaryMonthly != null)
// {
// jvItemAmount = jvstp.GetAmount(salaryMonthly);
// }
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// JVSetup jvSetupFS = oJVSetupsForFS.Where(o => o.Description == "Salary & Others").FirstOrDefault();
// if (jvSetupFS != null)
// {
// if (salaryMonthly != null)
// {
// fsItemAmount = jvSetupFS.GetAmount(salaryMonthly);
// }
// }
// salaryAndOthers = jvItemAmount + provisionItemAmount + fsItemAmount;
// }
// if (jvstp.Description.ToString() == "Bonus")
// {
// bonuspr = bonusprocesss.Where(o => o.EmployeeID == item.ID).ToObjectsTemplate();
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// jvItemAmount += (GetBonuses(jVSetupDetail.ItemID.Integer, bonuspr));
// }
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfBonus = jvItemAmount + provisionItemAmount;
// }
// if (jvstp.Description.ToString() == "Earn Leave")
// {
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfEarnLeave = provisionItemAmount;
// }
// if (jvstp.Description.ToString() == "Group Insurance")
// {
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfGroupInsurance = provisionItemAmount;
// }
// if (jvstp.Description.ToString() == "Medical Insurance")
// {
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfMedicalInsurance = provisionItemAmount;
// }
// if (jvstp.Description.ToString() == "PF GP Contrb.")
// {
// salaryMonthly = sMonthlys.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (salaryMonthly != null)
// {
// jvItemAmount = jvstp.GetAmount(salaryMonthly);
// }
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfPFGPContrb = jvItemAmount + provisionItemAmount;
// }
// if (jvstp.Description.ToString() == "Sum of Gratuity")
// {
// opiProcessDetail = oOPIProcessDetails.Where(o => o.EmployeeID == item.ID).FirstOrDefault();
// if (opiProcessDetail != null)
// {
// foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
// {
// foreach (OPIProcessDetailItem opiItem in opiProcessDetail.OPIProcessDetailItems)
// {
// if (jVSetupDetail.JVItemType == enumJvItemType.OPI && jVSetupDetail.ItemID == opiItem.OPIItemID)
// {
// provisionItemAmount = provisionItemAmount + opiItem.NetAmount;
// }
// }
// }
// }
// sumOfGratuity = provisionItemAmount;
// }
// }
// dr = dTPNLReport.NewRow();
// dr["EmployeeNo"] = item.EmployeeNo;
// dept = oDepartments.Where(o => o.ID == item.DepartmentID).FirstOrDefault();
// string[] sDes = GlobalFunctions.FindDivisionDeparmentUnit(dept, oDepartments);
// dr["Department"] = dept == null ? "" : dept.Name;
// dr["Division"] = sDes[1];
// dr["RCCode"] = GlobalFunctions.FindRCCode(dept, oDepartments);
// dr["SalaryAmount"] = Math.Round(salaryAndOthers);
// dr["BonusAmount"] = Math.Round(sumOfBonus);
// dr["EarnLeaveAmount"] = Math.Round(sumOfEarnLeave);
// dr["GroupInsurance"] = Math.Round(sumOfGroupInsurance);
// dr["MedicalInsurance"] = Math.Round(sumOfMedicalInsurance);
// dr["PF"] = Math.Round(sumOfPFGPContrb);
// dr["Gratuity"] = Math.Round(sumOfGratuity);
// dr["BeforeCapitalization"] = Math.Round(salaryAndOthers + sumOfBonus + sumOfEarnLeave + sumOfGroupInsurance + sumOfMedicalInsurance + sumOfPFGPContrb + sumOfGratuity);
// dr["Capitalization"] = 0;
// dr["AfterCapitalization"] = Math.Round(salaryAndOthers + sumOfBonus + sumOfEarnLeave + sumOfGroupInsurance + sumOfMedicalInsurance + sumOfPFGPContrb + sumOfGratuity);
// dTPNLReport.Rows.Add(dr);
// }
// return dTPNLReport;
//}
private ObjectsTemplate<Department> GetChilds(ObjectsTemplate<Department> departments, ID deptParentID)
{
ObjectsTemplate<Department> _childs = new ObjectsTemplate<Department>();
foreach (Department dept in departments)
{
if (dept.ParentID == deptParentID)
_childs.Add(dept);
}
return _childs;
}
public DataTable JVReportNew(ID JVTypeID, DateTime dEffectDate)
{
DataSet dSetAllChilds = new DataSet();
DataSet dSetTemp = new DataSet();
DataTable dtChild = null;
_dEffectDate = dEffectDate;
DataRow dr = null;
double nSAmount = 0;
double nOAmount = 0;
string rCCode = string.Empty;
PayrollDataSet.PayrollDataSet.JVReportDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVReportDataTable();
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID, maxdate);
ObjectsTemplate<JVSetup> oJVSetupsDr = oJVSetups.Where(o => o.Side == (int)1).ToObjectsTemplate();
ObjectsTemplate<JVSetup> oJVSetupsCr = oJVSetups.Where(o => o.Side == (int)2).ToObjectsTemplate();
ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
ObjectsTemplate<SalaryMonthly> sMonthlys = new ObjectsTemplate<SalaryMonthly>();
ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
//ObjectsTemplate<Department> oDepartments = Department.Get();
ObjectsTemplate<Department> childDepts = new ObjectsTemplate<Department>();
//ObjectsTemplate<Department> rcDepartments = Department.GetBySalaryMonthAndRCCode(GlobalFunctions.LastDateOfMonth(dEffectDate)); //oDepartments.Where(o => !string.IsNullOrWhiteSpace(o.RCCode)).ToObjectsTemplate();
JVType jType = JVType.Get(JVTypeID);
DataSet dSetRcCode = Department.GetRCCodeBySalaryMonth(GlobalFunctions.LastDateOfMonth(dEffectDate));
//foreach (Department dept in rcDepartments)
//{
// dSetTemp = Department.GetAllChilds(dept.ID);
// dSetAllChilds.Merge(dSetTemp);
//}
if (oJVSetups.Count > 0 && dSetRcCode != null && dSetRcCode.Tables[0].Rows.Count>0)
{
foreach (JVSetup jvstp in oJVSetups)
{
JVSetupDetail jVSetupDetail = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).FirstOrDefault();
foreach (DataRow rcDept in dSetRcCode.Tables[0].Rows)
{
sMonthlys = new ObjectsTemplate<SalaryMonthly>();
oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
//dtChild = dSetAllChilds.Tables[0].AsEnumerable().Where(x => x["DeptParent"].ToString() == rcDept.ID.ToString()).CopyToDataTable();
//foreach (DataRow drow in dtChild.Rows)
//{
// sMonthlys.AddRange(oSalaryMonthlys.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
// oOPIPDetails.AddRange(oOPIProcessDetails.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
//}
sMonthlys = oSalaryMonthlys.Where(o => o.RCCode == rcDept["Rccode"].ToString().Trim()).ToObjectsTemplate();
if (sMonthlys != null && sMonthlys.Count > 0)
{
foreach (SalaryMonthly slrmntl in sMonthlys)
{
nSAmount += jvstp.GetAmount(slrmntl);
}
}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = rcDept["Rccode"].ToString().Trim();
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nSAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nSAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GroupCode"] = jvstp.GroupCode;
dr["GLCode"] = jvstp.GLCode;
dr["CostCenter"] = rcDept["Rccode"].ToString().Trim();
dr["GLDescription"] = jvstp.Description;
dr["JType"] = jType.Name;
dr["JVDate"] = DateTime.Today.ToString("dd MMM yyyy");
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["DrAmount"] = nOAmount.ToString("#,###");
dr["CrAmount"] = "0";
dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["DrAmount"] = "0";
dr["CrAmount"] = nOAmount.ToString("#,###");
dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
}
}
}
return dTJVInfo;
}
public DataTable ADINew(ID JVTypeID, DateTime dEffectDate)
{
DataSet dSetAllChilds = new DataSet();
DataSet dSetTemp = new DataSet();
DataTable dtChild = null;
_dEffectDate = dEffectDate;
DataRow dr = null;
double nSAmount = 0;
double nOAmount = 0;
string rCCode = string.Empty;
PayrollDataSet.dsCompany.dtCapitalizationDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.dsCompany.dtCapitalizationDataTable();
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID, maxdate);
ObjectsTemplate<JVSetup> oJVSetupsDr = oJVSetups.Where(o => o.Side == (int)1).ToObjectsTemplate();
ObjectsTemplate<JVSetup> oJVSetupsCr = oJVSetups.Where(o => o.Side == (int)2).ToObjectsTemplate();
ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
ObjectsTemplate<SalaryMonthly> sMonthlys = new ObjectsTemplate<SalaryMonthly>();
ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
//ObjectsTemplate<Department> oDepartments = Department.Get();
ObjectsTemplate<Department> childDepts = new ObjectsTemplate<Department>();
//ObjectsTemplate<Department> rcDepartments = Department.GetBySalaryMonthAndRCCode(GlobalFunctions.LastDateOfMonth(dEffectDate)); //oDepartments.Where(o => !string.IsNullOrWhiteSpace(o.RCCode)).ToObjectsTemplate();
JVType jType = JVType.Get(JVTypeID);
DataSet dSetRcCode = Department.GetRCCodeBySalaryMonth(GlobalFunctions.LastDateOfMonth(dEffectDate));
//foreach (Department dept in rcDepartments)
//{
// dSetTemp = Department.GetAllChilds(dept.ID);
// dSetAllChilds.Merge(dSetTemp);
//}
if (oJVSetups.Count > 0 && dSetRcCode != null && dSetRcCode.Tables[0].Rows.Count > 0)
{
foreach (JVSetup jvstp in oJVSetups)
{
JVSetupDetail jVSetupDetail = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).FirstOrDefault();
foreach (DataRow rcDept in dSetRcCode.Tables[0].Rows)
{
sMonthlys = new ObjectsTemplate<SalaryMonthly>();
oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
//dtChild = dSetAllChilds.Tables[0].AsEnumerable().Where(x => x["DeptParent"].ToString() == rcDept.ID.ToString()).CopyToDataTable();
//foreach (DataRow drow in dtChild.Rows)
//{
// sMonthlys.AddRange(oSalaryMonthlys.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
// oOPIPDetails.AddRange(oOPIProcessDetails.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
//}
sMonthlys = oSalaryMonthlys.Where(o => o.RCCode == rcDept["Rccode"].ToString().Trim()).ToObjectsTemplate();
if (sMonthlys != null && sMonthlys.Count > 0)
{
foreach (SalaryMonthly slrmntl in sMonthlys)
{
nSAmount += jvstp.GetAmount(slrmntl);
}
}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept["Rccode"].ToString().Trim(); ;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nSAmount.ToString("#,###");
dr["Credit"] = "0";
//dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "0";
dr["Credit"] = nSAmount.ToString("#,###");
//dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept["Rccode"].ToString().Trim(); ;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nOAmount.ToString("#,###");
dr["Credit"] = "0";
//dr["JVTranType"] = "Debit";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "0";
dr["Credit"] = nOAmount.ToString("#,###");
//dr["JVTranType"] = "Credit";
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
}
}
}
return dTJVInfo;
}
public DataTable CapitalizationReport(ID JVTypeID, DateTime dEffectDate)
{
_dEffectDate = dEffectDate;
DataRow dr = null;
double nSAmount = 0;
double nOAmount = 0;
double nBAmount = 0;
string rCCode = string.Empty;
DataSet dSetAllChilds = new DataSet();
DataSet dSetTemp = new DataSet();
DataTable dtChild = null;
PayrollDataSet.dsCompany.dtCapitalizationDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.dsCompany.dtCapitalizationDataTable();
JVSetup osetp = new JVSetup();
ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID, dEffectDate);
ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
double percent = 0;
ObjectsTemplate<SalaryMonthly> oSMonthlys = new ObjectsTemplate<SalaryMonthly>();
ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
ObjectsTemplate<Department> oDepartments = Department.Get();
ObjectsTemplate<Capitalization> oCapitalizations = Capitalization.Get();
ObjectsTemplate<Employee> emps = Employee.Get();
ObjectsTemplate<BonusProcess.BonusProcessDetail> bonusprocesss = BonusProcess.GetBonusDetails(GlobalFunctions.LastDateOfMonth(dEffectDate));
Capitalization oCapitalization = null;
ObjectsTemplate<Department> childDepts = new ObjectsTemplate<Department>();
ObjectsTemplate<Department> rcDepartments = oDepartments.Where(o => !string.IsNullOrWhiteSpace(o.RCCode)).ToObjectsTemplate();
List<string> groupRC = oDepartments.Select(d => d.RCCode ?? d.RCCode).Distinct().ToList<string>();
ObjectsTemplate<JVSetupDetail> jVSetupDetails = null;
ObjectsTemplate<BonusProcess.BonusProcessDetail> bonuspr = null;
foreach (Department dept in rcDepartments)
{
dSetTemp = Department.GetAllChilds(dept.ID);
dSetAllChilds.Merge(dSetTemp);
}
if (oJVSetups.Count > 0 && oCapitalizations != null)
{
foreach (JVSetup jvstp in oJVSetups)
{
jVSetupDetails = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).ToObjectsTemplate();
foreach (Department rcDept in rcDepartments)
{
oCapitalization = oCapitalizations.FirstOrDefault(o => o.DepartmentID == rcDept.ID);
percent = oCapitalization == null ? 0 : oCapitalization.Percent;
oSMonthlys = new ObjectsTemplate<SalaryMonthly>();
oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
bonuspr = new ObjectsTemplate<BonusProcess.BonusProcessDetail>();
dtChild = dSetAllChilds.Tables[0].AsEnumerable().Where(x => x["DeptParent"].ToString() == rcDept.ID.ToString()).CopyToDataTable();
foreach (DataRow drow in dtChild.Rows)
{
oSMonthlys.AddRange(oSalaryMonthlys.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
oOPIPDetails.AddRange(oOPIProcessDetails.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
bonuspr.AddRange(bonusprocesss.Join(emps, b => b.EmployeeID, e => e.ID, (b, e) => new { BusinessP = b, DeptID = e.DepartmentID })
.Where(x => x.DeptID.Integer == Convert.ToInt32(drow["DepartmentID"])).Select(x => x.BusinessP).ToObjectsTemplate());
}
if (oSMonthlys != null && oSMonthlys.Count > 0)
{
foreach (SalaryMonthly slrmntl in oSMonthlys)
{
nSAmount += (jvstp.GetAmount(slrmntl) * percent / 100);
}
}
if (oOPIPDetails != null && oOPIPDetails.Count > 0)
{
foreach (OPIProcessDetail oPPDtl in oOPIPDetails)
{
foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
{
nOAmount += (GetOPIAmount(jVSetupDetail.ItemID.Integer, oPPDtl.ID) * percent / 100);
}
}
}
if (bonuspr.Count > 0 && oCapitalization != null)
{
foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
{
nBAmount += (GetBonuses(jVSetupDetail.ItemID.Integer, bonuspr) * oCapitalization.Percent / 100);
}
}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nSAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nSAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nOAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nOAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
if (nBAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nBAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nBAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nBAmount = 0;
}
}
}
}
return dTJVInfo;
}
public DataTable ADIReport(ID JVTypeID, DateTime dEffectDate)
{
_dEffectDate = dEffectDate;
DataRow dr = null;
double nSAmount = 0;
double nOAmount = 0;
double nBAmount = 0;
string rCCode = string.Empty;
DataSet dSetAllChilds = new DataSet();
DataSet dSetTemp = new DataSet();
DataTable dtChild = null;
PayrollDataSet.dsCompany.dtCapitalizationDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.dsCompany.dtCapitalizationDataTable();
JVSetup osetp = new JVSetup();
ObjectsTemplate<JVSetup> oJVSetups = JVSetup.GetByJVTypeAndMonth(JVTypeID, dEffectDate);
ObjectsTemplate<JVSetupDetail> oJVSetupDetails = JVSetupDetail.Get();
ObjectsTemplate<SalaryMonthly> oSalaryMonthlys = SalaryMonthly.Get(dEffectDate);
ObjectsTemplate<OPIProcessDetail> oOPIProcessDetails = OPIProcess.GetProcessDetails(dEffectDate);
double percent = 0;
ObjectsTemplate<SalaryMonthly> oSMonthlys = new ObjectsTemplate<SalaryMonthly>();
ObjectsTemplate<OPIProcessDetail> oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
ObjectsTemplate<Department> oDepartments = Department.Get();
ObjectsTemplate<Employee> emps = Employee.Get();
ObjectsTemplate<BonusProcess.BonusProcessDetail> bonusprocesss = BonusProcess.GetBonusDetails(GlobalFunctions.LastDateOfMonth(dEffectDate));
Capitalization oCapitalization = null;
ObjectsTemplate<Department> childDepts = new ObjectsTemplate<Department>();
ObjectsTemplate<Department> rcDepartments = oDepartments.Where(o => !string.IsNullOrWhiteSpace(o.RCCode)).ToObjectsTemplate();
List<string> groupRC = oDepartments.Select(d => d.RCCode ?? d.RCCode).Distinct().ToList<string>();
ObjectsTemplate<JVSetupDetail> jVSetupDetails = null;
ObjectsTemplate<BonusProcess.BonusProcessDetail> bonuspr = null;
foreach (Department dept in rcDepartments)
{
dSetTemp = Department.GetAllChilds(dept.ID);
dSetAllChilds.Merge(dSetTemp);
}
if (oJVSetups.Count > 0)
{
foreach (JVSetup jvstp in oJVSetups)
{
jVSetupDetails = oJVSetupDetails.Where(j => j.JVSetupID == jvstp.ID).ToObjectsTemplate();
foreach (Department rcDept in rcDepartments)
{
oSMonthlys = new ObjectsTemplate<SalaryMonthly>();
oOPIPDetails = new ObjectsTemplate<OPIProcessDetail>();
bonuspr = new ObjectsTemplate<BonusProcess.BonusProcessDetail>();
dtChild = dSetAllChilds.Tables[0].AsEnumerable().Where(x => x["DeptParent"].ToString() == rcDept.ID.ToString()).CopyToDataTable();
foreach (DataRow drow in dtChild.Rows)
{
oSMonthlys.AddRange(oSalaryMonthlys.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
oOPIPDetails.AddRange(oOPIProcessDetails.Where(s => s.DepartmentID.Integer == Convert.ToInt32(drow["DepartmentID"])).ToObjectsTemplate());
bonuspr.AddRange(bonusprocesss.Join(emps, b => b.EmployeeID, e => e.ID, (b, e) => new { BusinessP = b, DeptID = e.DepartmentID })
.Where(x => x.DeptID.Integer == Convert.ToInt32(drow["DepartmentID"])).Select(x => x.BusinessP).ToObjectsTemplate());
}
if (oSMonthlys != null && oSMonthlys.Count > 0)
{
foreach (SalaryMonthly slrmntl in oSMonthlys)
{
nSAmount += (jvstp.GetAmount(slrmntl));
}
}
if (oOPIPDetails != null && oOPIPDetails.Count > 0)
{
foreach (OPIProcessDetail oPPDtl in oOPIPDetails)
{
foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
{
nOAmount += (GetOPIAmount(jVSetupDetail.ItemID.Integer, oPPDtl.ID));
}
}
}
if (bonuspr.Count > 0 && oCapitalization != null)
{
foreach (JVSetupDetail jVSetupDetail in jVSetupDetails)
{
nBAmount += (GetBonuses(jVSetupDetail.ItemID.Integer, bonuspr));
}
}
if (nSAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nSAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nSAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nSAmount = 0;
}
if (nOAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nOAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nOAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nOAmount = 0;
}
if (nBAmount > 0)
{
dr = dTJVInfo.NewRow();
dr["GLCode"] = jvstp.GLCode;
dr["RC"] = rcDept.Code;
dr["Description"] = jvstp.Description;
dr["Product"] = "00000";
dr["Project"] = "00";
dr["Motpart"] = "000";
dr["System"] = "0000000";
dr["FUNKSJON"] = "00000";
dr["Reserve"] = "00000";
if (jvstp.Side == (int)EnumTranSide.Debit)
{
dr["Debit"] = nBAmount.ToString("#,###");
dr["Credit"] = "";
}
if (jvstp.Side == (int)EnumTranSide.Credit)
{
dr["Debit"] = "";
dr["Credit"] = nBAmount.ToString("#,###");
}
dTJVInfo.Rows.Add(dr);
nBAmount = 0;
}
}
}
}
return dTJVInfo;
}
public DataTable JVLoactionWReport(ID JVTypeID, DateTime dEffectDate)
{
_dEffectDate = dEffectDate;
DataRow dr = null;
PayrollDataSet.PayrollDataSet.JVLoactionWReportDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVLoactionWReportDataTable();
JVSetup osetp = new JVSetup();
DateTime maxdate = osetp.GetMaxDate(_dEffectDate);
ObjectsTemplate<JVSetup> oJVSetups = new ObjectsTemplate<JVSetup>();
oJVSetups = JVSetup.GetByJVTypeAndEffectDate(JVTypeID, maxdate);
int nLocationTire = ConfigurationManager.GetIntValue("Location", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Location> oLocations = new ObjectsTemplate<Location>();
oLocations = Location.GetByTier(2); // get the last tier data and last tier is defined in Logic configuration file
int nCCTire = ConfigurationManager.GetIntValue("costcenter", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Costcenter> oCostCenters = new ObjectsTemplate<Costcenter>();
oCostCenters = Costcenter.GetByTire(nCCTire); // get the last tier data and last tier is defined in Logic configuration file
ObjectsTemplate<SalaryMonthly> salaries = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
foreach (Location oLocation in oLocations)
{
foreach (Costcenter oCC in oCostCenters)
{
foreach (JVSetup osetup in oJVSetups)
{
foreach (SalaryMonthly osalary in salaries)
{
if (osalary.LocationID == oLocation.ID)
{
double percent = SalaryEmpCostCenter.InvolvedPercent(osalary.CostCentersInvolments, oCC.ID);
if (percent == 0) continue;
dr = dTJVInfo.NewRow();
dr["Location"] = oLocation.Name;
dr["CostCenter"] = oCC.Name;
dr["EmpNo"] = osalary.Employee.EmployeeNo;
dr["Name"] = osalary.Employee.Name;
dr["Description"] = osetup.Description;
dr["Amount"] = osetup.GetAmount(osalary) * percent / 100;
dr["JVMonth"] = dEffectDate;
dTJVInfo.Rows.Add(dr);
}
}
}
}
}
return dTJVInfo;
}
public DataTable JVSummaryReport(ID JVTypeID, DateTime dEffectDate)
{
_dEffectDate = dEffectDate;
DataRow dr = null;
PayrollDataSet.PayrollDataSet.JVSummaryReportDataTable dTJVInfo = new Payroll.Report.PayrollDataSet.PayrollDataSet.JVSummaryReportDataTable();
ObjectsTemplate<JVSetup> oJVSetups = new ObjectsTemplate<JVSetup>();
oJVSetups = JVSetup.GetByJVType(JVTypeID);
int nLocationTire = ConfigurationManager.GetIntValue("Location", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Location> oLocations = new ObjectsTemplate<Location>();
oLocations = Location.GetByTier(2); // get the last tier data and last tier is defined in Logic configuration file
int nCCTire = ConfigurationManager.GetIntValue("costcenter", "tier", EnumConfigurationType.Logic);
ObjectsTemplate<Costcenter> oCostCenters = new ObjectsTemplate<Costcenter>();
oCostCenters = Costcenter.GetByTire(nCCTire); // get the last tier data and last tier is defined in Logic configuration file
ObjectsTemplate<SalaryMonthly> salaries = SalaryMonthly.Get(GlobalFunctions.LastDateOfMonth(dEffectDate));
foreach (Costcenter oCC in oCostCenters)
{
foreach (Location oLocation in oLocations)
{
foreach (JVSetup osetup in oJVSetups)
{
double amount = GetSalaries(oLocation.ID, oCC.ID, salaries, osetup);
if (amount == 0) continue;
dr = dTJVInfo.NewRow();
dr["Location"] = oLocation.Name;
dr["CostCenter"] = oCC.Name;
dr["Description"] = osetup.Description;
dr["Amount"] = amount;// GetSalaries(oLocation.ID, oCC.ID, salaries, osetup);
dr["JVMonth"] = dEffectDate;
dTJVInfo.Rows.Add(dr);
}
}
}
return dTJVInfo;
}
public double GetSalaries(ID LocationID, ID CrgID, ObjectsTemplate<SalaryMonthly> SalaryOfMonth, JVSetup oJvSetup)
{
ObjectsTemplate<SalaryMonthly> salaries = new ObjectsTemplate<SalaryMonthly>();
double nAmount = 0;
double Percent = 0;
foreach (SalaryMonthly item in SalaryOfMonth)
{
if (item.LocationID == LocationID)
{
Percent = SalaryEmpCostCenter.InvolvedPercent(item.CostCentersInvolments, CrgID);
if (Percent == 0) continue;
nAmount = nAmount + oJvSetup.GetAmount(item) * Percent / 100;
}
}
return nAmount;
}
public int GetEmp(ID LocationID, ID CrgID, ObjectsTemplate<SalaryMonthly> SalaryOfMonth, JVSetup oJvSetup)
{
ObjectsTemplate<SalaryMonthly> salaries = new ObjectsTemplate<SalaryMonthly>();
double Percent;
foreach (SalaryMonthly item in SalaryOfMonth)
{
if (item.LocationID == LocationID)
{
Percent = SalaryEmpCostCenter.InvolvedPercent(item.CostCentersInvolments, CrgID);
if (Percent > 0) return item.EmployeeID.Integer;
}
}
return 0;
}
public static string WriteToTxtFile(string sStringToWrite, string sFilePath, string sFileName)
{
string sSuccess = string.Empty;
try
{
DirectoryInfo oFileDirectory = new DirectoryInfo(sFilePath);
if (!oFileDirectory.Exists)
{
oFileDirectory.Create();
}
StreamWriter oSWriter = new StreamWriter(sFilePath + "/" + sFileName + ".txt", false);
oSWriter.WriteLine(sStringToWrite);
sSuccess = "You can find a file named - " + sFileName + " at " + sFilePath;
oSWriter.Flush();
oSWriter.Close();
}
catch (Exception ex)
{
throw new ServiceException(ex.Message);
}
return sSuccess;
}
public double GetOPIAmount(int itemId, ID oPPDetailID)
{
double amount = 0;
ObjectsTemplate<OPIProcessDetailItem> oPIProcessDetailItems = OPIProcess.GetProcessDetailItems(oPPDetailID);
oPIProcessDetailItems = oPIProcessDetailItems.Where(p => p.OPIProcessDetailID == oPPDetailID).ToObjectsTemplate();
foreach (OPIProcessDetailItem oItem in oPIProcessDetailItems)
{
if (oItem.OPIItemID.Integer == itemId && oItem.OPIProcessDetailID.Integer == oPPDetailID.Integer)
amount = amount + Math.Round(oItem.NetAmount);
}
return amount;
}
public double GetOPIAmount(ObjectsTemplate<OPIProcessDetailItem> oPIProcessDetailItems, int itemId, ID oPPDetailID)
{
double amount = 0;
foreach (OPIProcessDetailItem oItem in oPIProcessDetailItems)
{
if (oItem.OPIItemID.Integer == itemId && oItem.OPIProcessDetailID.Integer == oPPDetailID.Integer)
amount = amount + Math.Round(oItem.NetAmount);
}
return amount;
}
public double GetBonuses(int itemId, ObjectsTemplate<BonusProcess.BonusProcessDetail> oBProcessDetails)
{
ObjectsTemplate<SalaryMonthly> salaries = new ObjectsTemplate<SalaryMonthly>();
double nAmount = 0;
// OPIProcessDetail
foreach (BonusProcess.BonusProcessDetail item in oBProcessDetails)
{
if (item.BonusID.Integer == itemId)
{
nAmount = nAmount + item.BonusAmount;
}
}
return nAmount;
}
}
}