EchoTex_Payroll/HRM.Report/Class/rptFStran.cs

538 lines
24 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Payroll.BO;
using Ease.CoreV35;
using Ease.Core.Model;
using Ease.Core.Utility;
using System.Windows.Forms;
using HRM.BO;
using HRM.DA;
using System.IO;
using HRM.Service;
using Microsoft.Reporting.NETCore;
using Ease.Core;
namespace HRM.Report
{
public class rptFSTran
{
int count = 1;
ReportParameter rParam = null;
private List<ReportParameter> reportParameters = new List<ReportParameter>();
public byte[] ShowFSPaymentCalculationReport(int fsTranId, int payrollTypeId)
{
double nAddCount = 0;
double nDeductCount = 0;
double nAmount = 0.0;
double nDeductAmount = 0.0;
double nTaxAmount = 0.0;
double nNetAmount = 0.0;
double nReceivable = 0.0;
double nPayable = 0.0;
double nTotal = 0.0;
double nALBalance = 0.0;
double nEncashDays = 0.0;
List<ReportDataSource> dataSource;
OPIProcess _oprocess = new OPIProcess();
Grade oGrade = new Grade();
Employee oEmp = new Employee();
DateTime? dLastSalaryMonth = null;
DateTime? dtOPI = null;
double dpf = 0;
EmployeeHistory oEmployeeHistory = new EmployeeHistory();
FSTran otran = new FSTranService().Get(fsTranId);
var resignationByEmployee = new EmpResignationRequest();
resignationByEmployee = new ResignationRequestService().GetByEmployeeId(otran.EmployeeID);
int dDateDiff = resignationByEmployee.ResignationDate.Value.Date < resignationByEmployee.LastWorkingDate.Value.Date ? (resignationByEmployee.LastWorkingDate.Value.Date - resignationByEmployee.ResignationDate.Value.Date).Days : 0;
SalaryMonthly _oSalaryMonthly = new SalaryMonthly();
otran.Details = new FSTranDetailService().GetDetailAmountType(otran.ID);
oEmp = new EmployeeService().Get(otran.EmployeeID);
oGrade = new GradeService().Get((int)oEmp.GradeID);
oEmployeeHistory = new EmployeeHistoryService().GetEmpLastHistory(oEmp.ID);
dLastSalaryMonth = new SalaryMonthlyService().GetLastPaidSalaryMonth(oEmp.ID);
dtOPI = new OPIProcessService().GetLastPaidOPIMonth(oEmp.ID);
// DateTime dtDiscontinue = oEmp.EndOfContractDate == DateTime.MinValue ? DateTime.Now : (DateTime)oEmp.EndOfContractDate;
//if (dLastSalaryMonth == null)
//{
// _oSalaryMonthly = new SalaryMonthlyService().Get(oEmp.ID, dtDiscontinue.AddMonths(-1));
//}
//else
//{
// dtDiscontinue = Convert.ToDateTime(dLastSalaryMonth);
// _oSalaryMonthly = new SalaryMonthlyService().Get(oEmp.ID, dtDiscontinue);
//}
if (dtOPI != null)
{
_oprocess = new OPIProcessService().Get(Convert.ToDateTime(dtOPI), oEmp.ID);
}
PayrollDataSet.dsCompany.DTFSSDataTable dtFSS = new PayrollDataSet.dsCompany.DTFSSDataTable();
PayrollDataSet.dsCompany.DTFSSItemsDataTable dtItems = new PayrollDataSet.dsCompany.DTFSSItemsDataTable();
PayrollDataSet.dsCompany.DTFSSItemsDataTable dtItems1 = new PayrollDataSet.dsCompany.DTFSSItemsDataTable();
DataRow orow = null;
orow = dtFSS.NewRow();
orow["Name"] = oEmp.Name;
orow["EmpID"] = oEmp.EmployeeNo;
orow["Designation"] = oEmp.Designation == null ? null : oEmp.Designation.Name;
orow["Dept"] = oEmp.Department == null ? null : oEmp.Department.Name;
orow["DOJ"] = oEmp.JoiningDate.ToString("dd MMM yyyy");
orow["SeparationMode"] = "Resignation";
foreach (SalaryMonthlyDetail oitem in _oSalaryMonthly.Details)
{
if ((int)EnumSalaryGroup.Gross == (int)oitem.itemGroupCode && (int)EnumSalaryItemCode.Basic_Salary == (int)oitem.ItemCode && (int)EnumSalaryItemCode.Basic_Salary == oitem.ItemID)
{
orow["MonthlyBasic"] = oitem.ChangedAmount;
}
else if ((int)EnumSalaryGroup.OtherItem == (int)oitem.itemGroupCode && (int)EnumSalaryItemCode.Net_Payable == (int)oitem.ItemCode && (int)EnumSalaryItemCode.Net_Payable == oitem.ItemID)
{
orow["Net"] = oitem.ChangedAmount;
}
}
//discontinue date == last working Date
orow["EffectiveDateofResigne"] = resignationByEmployee.LastWorkingDate.Value.Date.ToString("dd MMM yyyy");
orow["RequiredPeriod"] = 30; //temporary
orow["GivenPeriod"] = dDateDiff; //oItem.ShortNoticePeriod;
orow["LastWorkingDay"] = resignationByEmployee.LastWorkingDate.Value.Date.ToString("dd MMM yyyy");
orow["TerminationDate"] = resignationByEmployee.LastWorkingDate.Value.Date.ToString("dd MMM yyyy");
if ((int)oEmp.PFMemberType == (int)EnumPFMembershipType.Live)
{
orow["PFMembership"] = "Yes";
}
else
{
orow["PFMembership"] = "No";
}
TimeSpan ts = resignationByEmployee.LastWorkingDate.Value.Date - oEmp.JoiningDate;
orow["LengthOfService"] = ts.Days;
double dd = (double)ts.Days / 365;
double dYear = Math.Round(dd, 1);
dYear = dYear - (int)dYear;
if (dYear > .6)
{
orow["YearRound"] = (int)Math.Round(dd);
}
else
{
orow["YearRound"] = (int)dd;
}
orow["Year"] = Math.Round(dd, 1);
//if (!_oprocess.ID.IsUnassigned)
//{
// foreach (OPIProcessDetail item in _oprocess.OPIProcessDetails)
// {
// foreach (OPIProcessDetailItem oDetail in item.OPIProcessDetailItems)
// {
// orow["MobileBill"] = oDetail.ChangeNetAmount;
// }
// }
//}
dtFSS.Rows.Add(orow);
int nse = 6;
double FractionateSalary = 0;
double FractionateNet = 0;
double FractionateDays = 0;
double GrossSalary = 0;
double GrossNet = 0;
foreach (FSTranDetail oDetail in otran.Details)
{
if ((int)EnumValueType.Amount == (int)oDetail.AmountType)
{
orow = dtItems.NewRow();
if ((int)oDetail.FsTranType == (int)EnumFSTranType.FSReceivable && (int)oDetail.Side == (int)EnumSide.Add)
{
if ((int)EnumFSItemCode.LeaveEncashment == (int)oDetail.ItemCode && (int)EnumValueType.Amount == (int)oDetail.AmountType)
{
orow["Description"] = "Annual Leave Encashment";
orow["Amount"] = oDetail.ChangedValue;
orow["Sequence"] = 1;
}
else if ((int)EnumFSItemCode.NoticePay == (int)oDetail.ItemCode && (int)EnumValueType.Amount == (int)oDetail.AmountType)
{
orow["Description"] = "Payment inclued of Notice Priod";
orow["Amount"] = oDetail.ChangedValue;
orow["Sequence"] = 2;
}
else if ((int)EnumFSItemCode.PF == (int)oDetail.ItemCode)//||(int)EnumFSItemCode.CPF == (int)oDetail.ItemCode
{
orow["Description"] = "Provident Fund (Employer + Employee + Profit) 100%";
FSTranDetail oDetailCPF = otran.Details.FirstOrDefault(x => x.ItemCode == EnumFSItemCode.CPF && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add);
if (oDetailCPF != null)
{
dpf = oDetail.ChangedValue + oDetailCPF.ChangedValue;
}
orow["Amount"] = dpf;
orow["Sequence"] = 3;
}
else if ((int)EnumFSItemCode.FractionateSalary == (int)oDetail.ItemCode)
{
FractionateSalary += oDetail.ChangedValue;
double tmpDPamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add).Sum(x => x.ChangedValue);
double tmpDDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Deduct).Sum(x => x.ChangedValue);
double tempDNet = tmpDPamount - tmpDDamount;
FractionateNet = tempDNet;
continue;
}
else if ((int)EnumFSItemCode.Gross == (int)oDetail.ItemCode)
{
GrossSalary += oDetail.ChangedValue;
double tmpDPamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add).Sum(x => x.ChangedValue);
double tmpDDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Deduct).Sum(x => x.ChangedValue);
double tempDNet = tmpDPamount - tmpDDamount;
GrossNet = tempDNet;
continue;
}
else if ((int)EnumFSItemCode.Benifit == (int)oDetail.ItemCode)
{
orow["Description"] = "Benifit Bonus";
orow["Amount"] = oDetail.ChangedValue;
orow["Sequence"] = 4;
}
else if ((int)EnumFSItemCode.Other == (int)oDetail.ItemCode)
{
orow["Description"] = oDetail.Description;
orow["Amount"] = oDetail.ChangedValue;
orow["Sequence"] = 6;
}
else
{
if ((int)EnumFSItemCode.CPF == (int)oDetail.ItemCode)
{
continue;
}
nse++;
orow["Description"] = oDetail.Description;
orow["Amount"] = oDetail.ChangedValue;
orow["Sequence"] = nse;
}
double dPamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add).Sum(x => x.ChangedValue);
double dDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && (x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Add) || (x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Deduct)).Sum(x => x.ChangedValue);
double dNet = dPamount - dDamount;
nTotal = dNet;
orow["NetTotal"] = dNet;
orow["Group"] = "Payment Calculation";
}
else if (((int)oDetail.FsTranType == (int)EnumFSTranType.FSReceivable && (int)oDetail.Side == (int)EnumSide.Deduct) || ((int)oDetail.FsTranType == (int)EnumFSTranType.FSPayable && (int)oDetail.Side == (int)EnumSide.Add))
{
double dDamount = 0;
double dPamount = 0;
orow["Description"] = oDetail.Description;
orow["Amount"] = oDetail.ChangedValue;
//if(((int)oDetail.FsTranType == (int)EnumFSTranType.FSReceivable && (int)oDetail.Side == (int)EnumSide.Deduct)){
// dDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Deduct).Sum(x => x.ChangedValue);
//}
//else
//{
dPamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add).Sum(x => x.ChangedValue);
dDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && (x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Add) || (x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Deduct)).Sum(x => x.ChangedValue);
// dDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Deduct).Sum(x => x.ChangedValue);
// }
double dNet = dPamount - dDamount;
nTotal = dNet;
orow["NetTotal"] = dNet;
orow["Group"] = "Deduction";
nse++;
orow["Sequence"] = nse;
}
//else if ((int)oDetail.FsTranType == (int)EnumFSTranType.FSPayable && (int)oDetail.Side == (int)EnumSide.Deduct)
//{
// orow["Description"] = oDetail.Description;
// orow["Amount"] = oDetail.ChangedValue;
// double dPamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSReceivable && x.Side == EnumSide.Add).Sum(x => x.ChangedValue);
// double dDamount = otran.Details.Where(x => x.AmountType == EnumValueType.Amount && x.FsTranType == EnumFSTranType.FSPayable && x.Side == EnumSide.Deduct).Sum(x => x.ChangedValue);
// double dNet = dPamount - dDamount;
// nTotal = dNet;
// orow["NetTotal"] = dNet;
// orow["Group"] = "Deduction";
// nse++;
// orow["Sequence"] = nse;
//}
dtItems.Rows.Add(orow);
}
else
{
if ((int)EnumFSItemCode.FractionateSalary == (int)oDetail.ItemCode)
FractionateDays = oDetail.ChangedValue;
else
orow["Days"] = Convert.ToString(oDetail.ChangedValue);
}
}
//All fractionate salary to single row
if (FractionateSalary > 0)
{
orow = dtItems.NewRow();
orow["Description"] = "Fractionate Salary";
orow["Amount"] = FractionateSalary;
orow["Sequence"] = 5;
orow["NetTotal"] = FractionateNet;
orow["Group"] = "Payment Calculation";
orow["Days"] = Convert.ToString(FractionateDays);
dtItems.Rows.Add(orow);
}
if (GrossSalary > 0)
{
orow = dtItems.NewRow();
orow["Description"] = "Gross Salary";
orow["Amount"] = GrossSalary;
orow["Sequence"] = 6;
orow["NetTotal"] = GrossNet;
orow["Group"] = "Payment Calculation";
orow["Days"] = 0;
dtItems.Rows.Add(orow);
}
string sNetAmount = "BDT - " + GlobalFunctions.NumWordsWrapper(Convert.ToDouble(nTotal));
var sortedTempData = from DataRow dr in dtItems.Rows orderby dr["Sequence"] ascending select dr;
foreach (DataRow dr in dtItems.Rows)
{
if (dr["Group"] != DBNull.Value)
{
DataRow nDr = dtItems1.NewRow();
nDr.ItemArray = dr.ItemArray;
dtItems1.Rows.Add(nDr);
}
}
rParam = new ReportParameter("ReportType", "PDF");
reportParameters.Add(rParam);
rParam = new ReportParameter("Amount", sNetAmount);
reportParameters.Add(rParam);
DataSet dSet = new DataSet();
string RDLCName = "HRM.Report.RDLC.rptNewFSS.rdlc";
dtFSS.TableName = "dsCompany_DTFSS";
dtItems1.TableName = "dsCompany_DTFSSItems";
dSet.Tables.Add(dtFSS);
dSet.Tables.Add(dtItems1);
// return new ReportProcessor().ShowFSSReport(dtFSS, dtItems1, sNetAmount,payrollTypeId);
ReportProcessor reportProcessor = new ReportProcessor();
return reportProcessor.CommonReportView(null, RDLCName, dSet, null, reportParameters, true, payrollTypeId);
}
public byte[] ShowReport(int settlementAdviceId, string reportType, int payrollTypeId)
{
DataRow oDR = null;
DataSet oSettlementAdviceItems = null;
oSettlementAdviceItems = new FSTranService().GetEmpPaymentAdvice(settlementAdviceId);
PayrollDataSet.PayrollDataSet.SettlementAdviceDataTable dTSettlementAdvice = new PayrollDataSet.PayrollDataSet.SettlementAdviceDataTable();
oSettlementAdviceItems.Tables[0].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[1].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[2].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[3].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[4].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[5].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[6].Columns.Add("SequenceNo");
oSettlementAdviceItems.Tables[7].Columns.Add("SequenceNo");
int seq = 0;
foreach (DataRow dr in oSettlementAdviceItems.Tables["GrossItem"].AsEnumerable().Where(x => x.Field<string>("Description") == "Basic"))
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["GrossItem"].AsEnumerable().Where(x => (x.Field<string>("Description") == "House Rent Allowance")))
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["GrossItem"].AsEnumerable().Where(x => (x.Field<string>("Description") == "Medical Allowance")))
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["GrossItem"].AsEnumerable())
{
if (dr.Field<string>("Description") != "Basic" && dr.Field<string>("Description") != "House Rent Allowance" && dr.Field<string>("Description") != "Medical Allowance")
{
seq++;
dr["SequenceNo"] = seq;
}
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["TotalGross"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["BasicItem"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["OtherItems"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["DeductItem"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["TotalDeduction"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["TaxAmount"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
foreach (DataRow dr in oSettlementAdviceItems.Tables["NetPay"].Rows)
{
seq++;
dr["SequenceNo"] = seq;
}
#region Loop Start
foreach (DataRow source in oSettlementAdviceItems.Tables["GrossItem"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["TotalGross"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["BasicItem"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["OtherItems"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["DeductItem"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["TotalDeduction"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["TaxAmount"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
foreach (DataRow source in oSettlementAdviceItems.Tables["NetPay"].Rows)
{
oDR = dTSettlementAdvice.NewRow();
this.Copy(oDR, source);
dTSettlementAdvice.Rows.Add(oDR);
}
#endregion
#region Report Setup
string RDLCName = "HRM.Report.RDLC.SettlementAdviceSheetNew.rdlc";
DataSet resultDs = new DataSet();
dTSettlementAdvice.TableName = "PayrollDataSet_SettlementAdvice";
resultDs.Tables.Add(dTSettlementAdvice);
List<ReportParameter> rParams = new List<ReportParameter>();
ReportParameter rParam = new ReportParameter("ReportType", reportType);
rParams.Add(rParam);
#endregion
return new ReportProcessor().CommonReportView(null, RDLCName, resultDs, null, rParams, true, payrollTypeId, reportType);
}
private void Copy(DataRow source, DataRow destination)
{
source["EmpNo"] = destination["EMPLOYEENO"];
source["EmpName"] = destination["Name"];
source["JoiningDate"] = destination["JoiningDate"];
source["Department"] = destination["Department"];
source["Designation"] = destination["DESIGNATION"];
source["Description"] = destination["Description"];
source["AccountNo"] = destination["ACCOUNTNO"];
source["Bank"] = destination["Bank"];
source["Remarks"] = destination["Remarks"];
source["Amount"] = destination["Amount"];
source["Location"] = destination["Location"];
source["CTC"] = destination["ctc"];
source["CalenderDays"] = destination["calenderDays"];
source["WorkDays"] = destination["workDays"];
source["TranDate"] = destination["TranDate"];
source["SequenceNo"] = Convert.ToInt32(destination["SequenceNo"]);
source["EmpStatus"] = ((EnumEmployeeStatus)Convert.ToInt32(destination["STATUS"])).ToString();
}
}
}