Пример #1
0
        //private static double CalculateERAmount(DatabaseConnection dbConn, EEmpPersonalInfo empInfo, int ORSOPlanID, double TotalVCRI, EPayrollPeriod payrollPeriod)
        //{
        //    double totalVC = 0;

        //    EORSOPlan orsoPlan = new EORSOPlan();
        //    orsoPlan.ORSOPlanID = ORSOPlanID;
        //    if (EORSOPlan.db.select(dbConn, orsoPlan))
        //    {
        //        //  Use Service Year to Compare
        //        double YearOfService = HROne.Payroll.PayrollProcess.GetYearOfServer(dbConn, empInfo.EmpID, payrollPeriod.PayPeriodFr);
        //        EORSOPlanDetail orsoPlanDetailFrom = orsoPlan.GetORSOPlanDetail(dbConn, YearOfService);

        //        if (TotalVCRI <= 0)
        //            return 0;
        //        else
        //        {
        //            totalVC = TotalVCRI * orsoPlanDetailFrom.ORSOPlanDetailER / 100;
        //            totalVC += orsoPlanDetailFrom.ORSOPlanDetailERFix;
        //            return totalVC < orsoPlan.ORSOPlanMaxEmployerVC ? totalVC : orsoPlan.ORSOPlanMaxEmployerVC;
        //        }
        //    }
        //    else
        //        return 0;
        //}
        // End 0000084, Ricky So, 2014-08-22

        public static ArrayList GenerateORSOEEPaymentRecords(DatabaseConnection dbConn, int EmpID, ArrayList ORSORecords, ArrayList paymentRecords)
        {
            ArrayList ORSOPaymentRecords = new ArrayList();

            if (ORSORecords.Count > 0)
            {
                ArrayList ORSOPaymentCodes = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployeeContributionPaymentType(dbConn).PaymentTypeCode);
                if (ORSOPaymentCodes.Count > 0)
                {
                    EPaymentCode ORSOPaymentCode = (EPaymentCode)ORSOPaymentCodes[0];
                    double       ORSOAmount      = 0;
                    foreach (EORSORecord ORSORecord in ORSORecords)
                    {
                        if (ORSORecord != null)
                        {
                            ORSOAmount -= ORSORecord.ORSORecActEE;
                        }
                    }
                    if (Math.Abs(ORSOAmount) >= 0.01)
                    {
                        ORSOPaymentRecords.AddRange(PayrollProcess.GetDeductablePaymentRecord(dbConn, EmpID, paymentRecords, ORSOAmount, ORSOPaymentCode.PaymentCodeID));
                    }
                }
                foreach (EPaymentRecord paymentRecord in ORSOPaymentRecords)
                {
                    paymentRecord.PayRecType = PaymentRecordType.PAYRECORDTYPE_PENSION;
                }


                return(ORSOPaymentRecords);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public void TrialRun(int EmpPayrollID, EUser user)
        {
            EEmpPayroll empPayroll = new EEmpPayroll();

            empPayroll.EmpPayrollID = EmpPayrollID;
            if (EEmpPayroll.db.select(dbConn, empPayroll))
            {
                EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                empInfo.EmpID = empPayroll.EmpID;
                if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                {
                    EPayrollPeriod payPeriod = new EPayrollPeriod();
                    payPeriod.PayPeriodID = empPayroll.PayPeriodID;
                    if (EPayrollPeriod.db.select(dbConn, payPeriod))
                    {
                        DateTime startDate = payPeriod.PayPeriodFr;
                        DateTime endDate   = payPeriod.PayPeriodTo;

                        if (empInfo.EmpDateOfJoin > payPeriod.PayPeriodFr && empInfo.EmpDateOfJoin < payPeriod.PayPeriodTo)
                        {
                            startDate = empInfo.EmpDateOfJoin;
                        }

                        DBFilter empTerminationFilter = new DBFilter();
                        empTerminationFilter.add(new Match("EmpID", empPayroll.EmpID));
                        ArrayList empTerminationList = EEmpTermination.db.select(dbConn, empTerminationFilter);
                        foreach (EEmpTermination empTerm in empTerminationList)
                        {
                            if (empTerm.EmpTermLastDate > payPeriod.PayPeriodFr && empTerm.EmpTermLastDate < payPeriod.PayPeriodTo)
                            {
                                endDate = empTerm.EmpTermLastDate;
                            }
                        }

                        DBFilter empPosFilter = new DBFilter();
                        empPosFilter.add(new Match("EmpID", empPayroll.EmpID));
                        empPosFilter.add(new Match("EmpPosEffFr", "<=", payPeriod.PayPeriodTo));
                        OR orEmpPosEffToTerms = new OR();
                        orEmpPosEffToTerms.add(new Match("EmpPosEffTo", ">=", payPeriod.PayPeriodFr));
                        orEmpPosEffToTerms.add(new NullTerm("EmpPosEffTo"));
                        empPosFilter.add(orEmpPosEffToTerms);
                        empPosFilter.add(new Match("PayGroupID", payPeriod.PayGroupID));

                        ArrayList empPosList = EEmpPositionInfo.db.select(dbConn, empPosFilter);

                        DBFilter empCostCenterFilter = new DBFilter();
                        empCostCenterFilter.add(new Match("EmpID", empPayroll.EmpID));
                        empCostCenterFilter.add(new Match("EmpCostCenterEffFr", "<=", payPeriod.PayPeriodTo));
                        OR orEmpCostCenterEffToTerms = new OR();
                        orEmpCostCenterEffToTerms.add(new Match("EmpCostCenterEffTo", ">=", payPeriod.PayPeriodFr));
                        orEmpCostCenterEffToTerms.add(new NullTerm("EmpCostCenterEffTo"));
                        empCostCenterFilter.add(orEmpCostCenterEffToTerms);

                        ArrayList empCostCenterList = EEmpCostCenter.db.select(dbConn, empCostCenterFilter);



                        ArrayList costAllocationDetailList          = new ArrayList();
                        ArrayList costAllocationDetailHierarchyLIst = new ArrayList();

                        DBFilter paymentRecordFilter = new DBFilter();
                        paymentRecordFilter.add(new Match("EmpPayrollID", EmpPayrollID));

                        ArrayList paymentRecordList = EPaymentRecord.db.select(dbConn, paymentRecordFilter);

                        if (empCostCenterList.Count == 0 && paymentRecordList.Count > 0)
                        {
                            errorLogBuiler.AppendLine(
                                string.Format(
                                    HROne.Common.WebUtility.GetLocalizedStringByCode(MESSAGE_COST_CENTER_NOT_FOUND, "Cost Center for Employee ({0}) has not been set.")
                                    , new string[] { empInfo.EmpNo })
                                );
                            return;
                        }

                        foreach (EPaymentRecord paymentRecord in paymentRecordList)
                        {
                            try
                            {
                                costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, paymentRecord.PaymentCodeID, paymentRecord.PayRecActAmount, paymentRecord.PayRecID, false, paymentRecord.CostCenterID));
                            }
                            catch (Exception e)
                            {
                                errorLogBuiler.AppendLine(
                                    string.Format(
                                        e.Message
                                        , new string[] { empInfo.EmpNo })
                                    );
                            }
                            //ArrayList costAllocationDetailListByPaymentRecord = new ArrayList();
                            //int daysTotal = 0;
                            //foreach (EEmpPositionInfo empPos in empPosList)
                            //{
                            //    DateTime posStartDate = startDate;
                            //    DateTime posEndDate = endDate;

                            //    if (empPos.EmpPosEffFr > posStartDate)
                            //        posStartDate = empPos.EmpPosEffFr;

                            //    if (empPos.EmpPosEffTo < posEndDate && empPos.EmpPosEffTo > posStartDate)
                            //        posEndDate = empPos.EmpPosEffTo;

                            //    DBFilter empHierarchyElementFilter = new DBFilter();
                            //    empHierarchyElementFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                            //    ArrayList empHiererchyElementList = EEmpHierarchy.db.select(dbConn, empHierarchyElementFilter);

                            //    double percentagePaymentTotal = 0;

                            //    foreach (EEmpCostCenter empCostCenter in empCostCenterList)
                            //    {
                            //        DateTime costStartDate = posStartDate;
                            //        DateTime costEndDate = posEndDate;

                            //        if (empCostCenter.EmpCostCenterEffFr > costStartDate)
                            //            costStartDate = empCostCenter.EmpCostCenterEffFr;

                            //        if (empCostCenter.EmpCostCenterEffTo < costEndDate && empCostCenter.EmpCostCenterEffTo > costStartDate)
                            //            costEndDate = empCostCenter.EmpCostCenterEffTo;

                            //        if (costStartDate > costEndDate)
                            //            continue;

                            //        int numOfDays = ((TimeSpan)costEndDate.Subtract(costStartDate)).Days;
                            //        daysTotal += numOfDays;

                            //        DBFilter empCostCenterDetailFilter = new DBFilter();
                            //        empCostCenterDetailFilter.add(new Match("EmpCostCenterID", empCostCenter.EmpCostCenterID));
                            //        ArrayList empCostCenterDetailList = EEmpCostCenterDetail.db.select(dbConn, empCostCenterDetailFilter);

                            //        double percentageCostCenterTotal = 0;
                            //        foreach (EEmpCostCenterDetail empCostCenterDetail in empCostCenterDetailList)
                            //        {

                            //            ECostAllocationDetail costAllocDetail = new ECostAllocationDetail();
                            //            costAllocDetail.CostCenterID = empCostCenterDetail.CostCenterID;
                            //            costAllocDetail.CostAllocationDetailRoundCalAmount = paymentRecord.PayRecActAmount * daysTotal * empCostCenterDetail.EmpCostCenterPercentage;
                            //            costAllocDetail.PaymentCodeID = paymentRecord.PaymentCodeID;
                            //            costAllocDetail.PayRecID = paymentRecord.PayRecID;
                            //            costAllocDetail.CompanyID = empPos.CompanyID;
                            //            costAllocationDetailListByPaymentRecord.Add(costAllocDetail);

                            //            foreach (EEmpHierarchy empHierarchy in empHiererchyElementList)
                            //            {
                            //                ECostAllocationDetailHElement costAllocHierarchy = new ECostAllocationDetailHElement();
                            //                costAllocHierarchy.HElementID = empHierarchy.HElementID;
                            //                costAllocHierarchy.HLevelID = empHierarchy.HLevelID;
                            //                costAllocHierarchy.RelatedCostAllocationDetailObject = costAllocDetail;
                            //                costAllocationDetailHierarchyLIst.Add(costAllocHierarchy);
                            //            }

                            //            percentageCostCenterTotal += empCostCenterDetail.EmpCostCenterPercentage;


                            //        }

                            //        if (Math.Round(Math.Abs(percentageCostCenterTotal - 100), 2, MidpointRounding.AwayFromZero) > 0)
                            //        {
                            //            errorLogBuiler.AppendLine(
                            //                string.Format(
                            //                HROne.Common.WebUtility.GetLocalizedStringByCode(MESSAGE_NOT_100_PERCENTAGE, "Total Percentage of Employee ({0}) is not 100%.")
                            //                , new string[] { empInfo.EmpNo })
                            //            );
                            //        }
                            //    }

                            //}

                            ////SortedList sortedCostAllocationDetailbyDecimalPlaceRoundDown = new SortedList();
                            ////SortedList sortedCostAllocationDetailbyDecimalPlaceRoundUp = new SortedList();

                            //double totalCostAllocPayment = 0;
                            //foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord)
                            //{
                            //    costAllocationDetail.CostAllocationDetailRoundCalAmount = costAllocationDetail.CostAllocationDetailRoundCalAmount / (100 * daysTotal);
                            //    costAllocationDetail.CostAllocationDetailAmount = Math.Round(costAllocationDetail.CostAllocationDetailRoundCalAmount, 2, MidpointRounding.AwayFromZero);
                            //    totalCostAllocPayment += costAllocationDetail.CostAllocationDetailAmount;

                            //    //sortedCostAllocationDetailbyDecimalPlaceRoundDown.Add(costAllocationDetail.CostAllocationDetailAmount - originalCostAllocationAmount, costAllocationDetail.CostAllocationDetailAmount);
                            //    //sortedCostAllocationDetailbyDecimalPlaceRoundUp.Add(originalCostAllocationAmount - costAllocationDetail.CostAllocationDetailAmount, costAllocationDetail.CostAllocationDetailAmount);

                            //}
                            //double diff = Math.Round(paymentRecord.PayRecActAmount - totalCostAllocPayment, 2, MidpointRounding.AwayFromZero);
                            //if (Math.Abs(diff) >= 0.01 && costAllocationDetailListByPaymentRecord.Count>0)
                            //{
                            //    if (diff > 0)
                            //    {
                            //        while (Math.Abs(diff) >= 0.01)
                            //        {
                            //            ECostAllocationDetail minCostAllocationDetail = null;
                            //            double minDiff = 1;
                            //            foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord)
                            //            {
                            //                double costAllocDiff= costAllocationDetail.CostAllocationDetailAmount -costAllocationDetail.CostAllocationDetailRoundCalAmount;
                            //                if (costAllocDiff < minDiff)
                            //                {
                            //                    minDiff = costAllocDiff;
                            //                    minCostAllocationDetail = costAllocationDetail;
                            //                }
                            //            }
                            //            if (minCostAllocationDetail != null)
                            //            {
                            //                minCostAllocationDetail.CostAllocationDetailAmount += 0.01;
                            //                diff -= 0.01;
                            //            }
                            //        }
                            //    }
                            //    else
                            //    {
                            //        while (Math.Abs(diff) >= 0.01)
                            //        {
                            //            ECostAllocationDetail maxCostAllocationDetail = null;
                            //            double maxDiff = 1;
                            //            foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailListByPaymentRecord)
                            //            {
                            //                double costAllocDiff = costAllocationDetail.CostAllocationDetailAmount - costAllocationDetail.CostAllocationDetailRoundCalAmount;
                            //                if (costAllocDiff > maxDiff)
                            //                {
                            //                    maxDiff = costAllocDiff;
                            //                    maxCostAllocationDetail = costAllocationDetail;
                            //                }
                            //            }
                            //            if (maxCostAllocationDetail != null)
                            //            {
                            //                maxCostAllocationDetail.CostAllocationDetailAmount -= 0.01;
                            //                diff += 0.01;
                            //            }
                            //        }
                            //    }
                            //}
                            //costAllocationDetailList.AddRange(costAllocationDetailListByPaymentRecord);
                        }

                        ArrayList mpfRecordList = EMPFRecord.db.select(dbConn, paymentRecordFilter);

                        foreach (EMPFRecord mpfRecord in mpfRecordList)
                        {
                            try
                            {
                                ArrayList paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployeeMandatoryContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActMCEE, mpfRecord.MPFRecordID, true));
                                }
                                paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployerMandatoryContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActMCER, mpfRecord.MPFRecordID, true));
                                }
                                paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployeeVoluntaryContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActVCEE, mpfRecord.MPFRecordID, true));
                                }
                                paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.MPFEmployerVoluntaryContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, mpfRecord.MPFRecActVCER, mpfRecord.MPFRecordID, true));
                                }
                            }
                            catch (Exception e)
                            {
                                errorLogBuiler.AppendLine(
                                    string.Format(
                                        e.Message
                                        , new string[] { empInfo.EmpNo })
                                    );
                            }
                        }

                        ArrayList orsoRecordList = EORSORecord.db.select(dbConn, paymentRecordFilter);

                        foreach (EORSORecord orsoRecord in orsoRecordList)
                        {
                            try
                            {
                                ArrayList paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployeeContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, orsoRecord.ORSORecActEE, orsoRecord.ORSORecordID, true));
                                }
                                paymentList = PayrollProcess.GetPaymentCodeByPaymentType(dbConn, EPaymentType.SystemPaymentType.PFundEmployerContributionPaymentType(dbConn).PaymentTypeCode);
                                if (paymentList.Count > 0)
                                {
                                    costAllocationDetailList.AddRange(CreateCostAllocationRecordList(startDate, endDate, empPosList, empCostCenterList, ((EPaymentCode)paymentList[0]).PaymentCodeID, orsoRecord.ORSORecActER, orsoRecord.ORSORecordID, true));
                                }
                            }
                            catch (Exception e)
                            {
                                errorLogBuiler.AppendLine(
                                    string.Format(
                                        e.Message
                                        , new string[] { empInfo.EmpNo })
                                    );
                            }
                        }

                        ECostAllocation costAllocation = new ECostAllocation();
                        costAllocation.EmpID = empInfo.EmpID;
                        costAllocation.CostAllocationStatus       = "T";
                        costAllocation.CostAllocationTrialRunDate = AppUtils.ServerDateTime();
                        costAllocation.CostAllocationTrialRunBy   = user.UserID;
                        costAllocation.EmpPayrollID = EmpPayrollID;
                        ECostAllocation.db.insert(dbConn, costAllocation);
                        foreach (ECostAllocationDetail costAllocationDetail in costAllocationDetailList)
                        {
                            costAllocationDetail.CostAllocationID = costAllocation.CostAllocationID;
                            ECostAllocationDetail.db.insert(dbConn, costAllocationDetail);
                            foreach (ECostAllocationDetailHElement costAllocationDetailHierarchy in costAllocationDetail.HierarchyElementList)
                            {
                                costAllocationDetailHierarchy.CostAllocationDetailID = costAllocationDetail.CostAllocationDetailID;
                                ECostAllocationDetailHElement.db.insert(dbConn, costAllocationDetailHierarchy);
                            }
                        }
                    }
                }
            }
        }