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.Report { public class rptCC { private ReportSetup _selectedParameter; string tempEmpID = string.Empty; public rptCC() { } public ReportSetup SelectedParameter { set { _selectedParameter = value; } } public void ShowReport() { fReportViewer form = new fReportViewer(); DateTime effectMonth = _selectedParameter.FromDate.Value; string sEmpID = _selectedParameter.ReportItem.INSQL; int count = 1; DataRow oDR = null; DataSet oEmpCC1 = EmployeeCostCenter.GetEmpCC(GlobalFunctions.LastDateOfMonth(effectMonth), sEmpID); PayrollDataSet.PayrollDataSet.CCWReportDataTable CCWReportDT = new Payroll.Report.PayrollDataSet.PayrollDataSet.CCWReportDataTable(); #region Old Code //foreach (DataRow oDRow in oEmpCC.Tables[0].Rows) //{ // oDR = CCWReportDT.NewRow(); // oDR["SLNo"] = count; // oDR["EmpNo"] = oDRow["EMPLOYEENO"]; // oDR["Name"] = oDRow["NAME"]; // //oDR["CostCenter"] = oDRow["DESCRIPTION"]; // //oDR["Percentage"] = oDRow["PERCENTAGE"]; // //if (oDRow["CostCenter"].ToString() == string.Empty) // //{ // // oDR["CostCenter"] = "Not assign"; // // oDR["Percentage"] = 0; // //} // //else // //{ // // oDR["CostCenter"] = oDRow["CostCenter"]; // // oDR["Percentage"] = oDRow["Percentage"]; // //} // if (oDRow["CurrentCC"].ToString() ==string.Empty) // { // oDR["CostCenter"] = "Not assign"; // oDR["Percentage"] = 0; // } // else // { // oDR["CostCenter"] = oDRow["CCDes"]; // oDR["Percentage"] = oDRow["Per"]; // } // oDR["EffectDate"] = effectMonth; // CCWReportDT.Rows.Add(oDR); // count++; //} #endregion #region Commented by Tamanna //foreach (DataRow oRow in oEmpCC1.Tables[0].Rows) //{ // oDR = CCWReportDT.NewRow(); // oDR["SLNo"] = count; // oDR["EmpNo"] = oRow["EMPLOYEENO"]; // oDR["Name"] = oRow["NAME"]; // DataRow[] oEmpCC = oEmpCC1.Tables["EmpCC"].Select("EmployeeID='" + oRow["EmployeeID"].ToString() + "'"); // if (oEmpCC.Length > 1) // { // foreach (DataRow oRow1 in oEmpCC) // { // if (Convert.ToInt32(oRow1["CurrentCC"]) == 1) // { // oDR["CostCenterID"] = Convert.ToInt32(oRow1["CostCenterID"]); // oDR["Percentage"] = Convert.ToInt32(oRow1["Percentage"]); // } // } // } // else // { // if (oEmpCC.Length > 0) // { // oDR["CostCenterID"] = Convert.ToInt32(oEmpCC[0]["CostCenterID"]); // oDR["Percentage"] = Convert.ToInt32(oEmpCC[0]["Percentage"]); // } // else // { // oDR["CostCenterID"] = 0; // oDR["Percentage"] = 0; // } // } // CCWReportDT.Rows.Add(oDR); // count++; //} #endregion #region Edited By Tamanna foreach (DataRow oRow in oEmpCC1.Tables[1].Rows) { oDR = CCWReportDT.NewRow(); oDR["SLNo"] = count; oDR["CostCenterID"] = Convert.ToInt32(oRow["CostCenterID"]); oDR["Percentage"] = Convert.ToInt32(oRow["Percentage"]); DataRow[] oEmpCC = oEmpCC1.Tables["Employee"].Select("EmployeeID='" + oRow["EmployeeID"].ToString() + "'"); //if (oEmpCC.Length > 1) //{ foreach (DataRow oRow1 in oEmpCC) { if (Convert.ToInt32(oRow["CurrentCC"]) == 1) { oDR["EmpNo"] = oRow1["EMPLOYEENO"]; oDR["Name"] = oRow1["NAME"]; } } //} //else //{ // if (oEmpCC.Length > 0) // { // oDR["CostCenterID"] = Convert.ToInt32(oRow["CostCenterID"]); // oDR["Percentage"] = Convert.ToInt32(oRow["Percentage"]); // } // else // { // oDR["CostCenterID"] = 0; // oDR["Percentage"] = 0; // } //} CCWReportDT.Rows.Add(oDR); count++; } #endregion foreach (DataRow oRow in CCWReportDT.Rows) { if (oRow["CostCenterID"].ToString().Length > 0) { DataRow[] oEmpCC = oEmpCC1.Tables["CRG"].Select("CRGID='" + oRow["CostCenterID"] + "'"); if (oEmpCC.Length > 0) { oRow["CostCenter"] = oEmpCC[0]["Description"]; } else { oRow["CostCenter"] = "Not assigned"; } } } form.ShowDlgForCCWReport(_selectedParameter.ReportItem, CCWReportDT); } public DataRow Copy(DataRow source, DataRow destination, DateTime dToDate, int count) { source["SLNo"] = count; source["EmpNo"] = destination["EMPLOYEENO"]; source["Name"] = destination["NAME"]; if (Convert.ToString(destination["Description"]) != string.Empty) { source["PrvCC"] = destination["Description"] + "(" + destination["Percentage"] + ")"; } source["Month"] = dToDate; count++; tempEmpID = Convert.ToString(destination["EMPLOYEENO"]); return source; } public DataRow CopyForCurrCC(DataRow source, DataRow destination, DateTime dToDate, int count) { source["SLNo"] = count; source["EmpNo"] = destination["EMPLOYEENO"]; source["Name"] = destination["NAME"]; if (Convert.ToString(destination["Description"]) != string.Empty) { source["CurCC"] = destination["Description"] + "(" + destination["Percentage"] + ")"; } source["Month"] = dToDate; count++; tempEmpID = Convert.ToString(destination["EMPLOYEENO"]); return source; } private DataRow GetItem(PayrollDataSet.PayrollDataSet.CCDetailReportDataTable Source, string sEmpNo) { foreach (DataRow odRow in Source.Rows) { if (Convert.ToString(odRow["EmpNo"]) == sEmpNo) { return odRow; } } return null; } public void ShowCCInformation() { fReportViewer form = new fReportViewer(); DateTime dToDate = _selectedParameter.FromDate.Value; DateTime dMaxDate; string sEmpID = _selectedParameter.ReportItem.INSQL; string[] sEmps = sEmpID.Split(','); PayrollDataSet.PayrollDataSet.CCDetailReportDataTable CCReportDT = new Payroll.Report.PayrollDataSet.PayrollDataSet.CCDetailReportDataTable(); DataRow oDR = null; int count = 1; ObjectsTemplate costCenters = EmployeeCostCenter.Get(); ObjectsTemplate crgs = Costcenter.Get(); ObjectsTemplate eployees = Employee.Get(); // get the object collection of previous month coscenter information ( SalaryEmpCostcenter) foreach (string sEmp in sEmps) { Employee emp = eployees.GetItem(ID.FromInteger(Convert.ToInt32(sEmp))); if (emp == null) continue; oDR = CCReportDT.NewRow(); oDR["SLNo"] = count; oDR["EmpNo"] = emp.EmployeeNo; oDR["Name"] = emp.Name; //loop the salaryempcostcenter and fill the previous costcenter column foreach (EmployeeCostCenter item in costCenters) { if (item.EmployeeID.ToString() == sEmp) { oDR["CurCC"] = oDR["CurCC"].ToString() + " " + crgs.GetItem(item.CostCenterID).Name + "(" + item.Percentage.ToString() + ")"; } } oDR["Month"] = dToDate; CCReportDT.Rows.Add(oDR); count++; } #region OldCode //DateTime dFromDate=_selectedParameter.FromDate.Value.AddMonths(-1); //string sEmpID1 = _selectedParameter.ReportItem.INSQL; //string testCCSubString = string.Empty; //int count1 = 1; //DataRow oDR1 = null; //DataSet oEmpCC1 = EmployeeCostCenter.GetEmpCCDetails(GlobalFunctions.LastDateOfMonth(dToDate), GlobalFunctions.LastDateOfMonth(dFromDate), sEmpID); //PayrollDataSet.PayrollDataSet.CCDetailReportDataTable CCReportDT1 = new Payroll.Report.PayrollDataSet.PayrollDataSet.CCDetailReportDataTable(); //testCCSubString = ""; //foreach (DataRow oDRow in oEmpCC1.Tables[0].Rows) //{ // DataRow oRow = this.GetItem(CCReportDT, Convert.ToString(oDRow["EMPLOYEENO"])); // if (oRow == null) // { // oDR = CCReportDT.NewRow(); // oRow = this.Copy(oDR, oDRow, dToDate, count); // CCReportDT.Rows.Add(oRow); // count++; // } // else // { // if (Convert.ToString(oDR["CurCC"]) != string.Empty && Convert.ToDouble(oDRow["CurrCCPer"])>0) // { // oDR["CurCC"] = oDR["CurCC"] + " " + oDRow["CurrCCName"] + "(" + oDRow["CurrCCPer"] + ")"; // } // if (Convert.ToString(oDRow["PrvCCName"]) != string.Empty && Convert.ToDouble(oDRow["PrvCCPer"])>0) // { // oDR["PrvCC"] =oDR["PrvCC"] + " " + oDRow["PrvCCName"] + "(" + oDRow["PrvCCPer"] + ")"; // } // } //} #endregion form.ShowDlgForCCDetailWReport(_selectedParameter.ReportItem, CCReportDT); } public void ShowCCInformationByMonth(DateTime startDate, DateTime startDate2) { DateTime startmonth = startDate; DateTime endmonth = startDate2; fReportViewer form = new fReportViewer(); PayrollDataSet.PayrollDataSet.CCDetailReportDataTable CCReportDT = new Payroll.Report.PayrollDataSet.PayrollDataSet.CCDetailReportDataTable(); DataRow oDR = null; int count = 1; ObjectsTemplate costCenters = EmployeeCostCenter.GetByMonthStartEnd(startmonth, endmonth); ObjectsTemplate crgs = Costcenter.Get(); ObjectsTemplate eployees = Employee.Get(); ObjectsTemplate allSalEmpCost = SalaryMonthly.GetCostCenter(GlobalFunctions.LastDateOfMonth(startDate.AddMonths(-1))); List _lifeCycles = EmpLifeCycle.Get(EnumStatus.Regardless); List _finalcialDatas = ApproveFinantialData.Get(); List _users = User.Get(EnumSystemType.Desktop); // get the object collection of previous month coscenter information ( SalaryEmpCostcenter) //ObjectsTemplate< User> allUsers =User.GetById() foreach (EmployeeCostCenter empCst in costCenters) { Employee emp = eployees.GetItem(empCst.EmployeeID); if (emp == null) continue; oDR = CCReportDT.NewRow(); oDR["SLNo"] = count; User obUser = User.GetById(empCst.CreatedBy.Integer); if (obUser != null) oDR["UserId"] = obUser.LoginID; else oDR["UserId"] = String.Empty; oDR["CreationDate"] = empCst.CreatedDate; oDR["EmpNo"] = emp.EmployeeNo; oDR["Name"] = emp.Name; oDR["CurCC"] = String.Empty; //loop the salaryempcostcenter and fill the previous costcenter column foreach(Costcenter cstCenterObj in crgs) { if(cstCenterObj.ID.Integer == empCst.CostCenterID.Integer) { oDR["CurCC"] = cstCenterObj.Code + "(" + empCst.Percentage.ToString() + ")"; break; } } oDR["Month"] = startDate.ToString("dd MMM yyyy"); if(allSalEmpCost!=null) { SalaryEmpCostCenter semp = allSalEmpCost.Find(delegate(SalaryEmpCostCenter sitem ){return sitem.EmployeeID.Integer == empCst.EmployeeID.Integer;}); if(semp!=null) { Costcenter ocrg=Costcenter.Get(semp.CostCenterID); oDR["PrvCC"] = ocrg.Code + "(100)"; } } if (Payroll.BO.SystemInformation.CurrentSysInfo.Code.Contains("007")) { if (empCst.EmployeeID.Integer > 0) { EmpLifeCycle lifeCycle = _lifeCycles.Find(delegate(EmpLifeCycle oItem) { return oItem.CostCenterID == empCst.CostCenterID && empCst.MonthDate == oItem.SalaryMonth && oItem.EmployeeID==empCst.EmployeeID; }); if (lifeCycle != null) { ApproveFinantialData finalcialData = _finalcialDatas.Find(delegate(ApproveFinantialData oItem) { return oItem.EmployeeID == empCst.EmployeeID && oItem.ObjectID == lifeCycle.ID.Integer && oItem.SalaryMonth.Year == lifeCycle.EffectDate.Year && oItem.SalaryMonth.Month == lifeCycle.EffectDate.Month && oItem.FinanatialDataType == EnumApprovalFinancialData.Lifecycle; }); if (finalcialData != null) { User user = _users.Find(delegate(User oItem) { return oItem.ID.Integer == finalcialData.Approvedby; }); if (user != null) oDR["AuthorizeBy"] = user.Name; oDR["AuthorizedDate"] = finalcialData.ApprovedDate.ToString("dd MMM yyyy hh:mm:ss tt"); } else oDR["AuthorizeBy"] = ""; } else oDR["AuthorizeBy"] = ""; } else oDR["AuthorizeBy"] = ""; } CCReportDT.Rows.Add(oDR); count++; } form.ShowDlgForCCDetailWReportByMonth(startDate,CCReportDT); } } }