Ejemplo n.º 1
0
        public void GenerateStandardBonusData(ArrayList pEmpList)
        {
            //double m_targetSalary = 0;
            EBonusProcess m_bonusProcess = EBonusProcess.GetObject(dbConn, m_BonusProcessID);

            if (m_bonusProcess != null)
            {
                foreach (EEmpPersonalInfo empInfo in pEmpList)
                {
                    if (EEmpPersonalInfo.db.select(dbConn, empInfo) && empInfo.EmpProbaLastDate <= m_bonusProcess.BonusProcessPeriodTo)
                    {
                        EEmpRecurringPayment m_recurringPayment = GetSalaryMonthRecurringPayment(empInfo.EmpID, m_bonusProcess.BonusProcessSalaryMonth);
                        if (m_recurringPayment != null)
                        {
                            EEmpBonusProcess m_empBonusProcess = new EEmpBonusProcess();
                            m_empBonusProcess.BonusProcessID = m_BonusProcessID;
                            m_empBonusProcess.EmpID          = empInfo.EmpID;
                            m_empBonusProcess.EmpBonusProcessTargetSalary = m_recurringPayment.EmpRPBasicSalary;

                            System.TimeSpan m_totalDaysInPeriod = m_bonusProcess.BonusProcessPeriodTo.Subtract(m_bonusProcess.BonusProcessPeriodFr);
                            System.TimeSpan m_totalDaysJoint    = m_bonusProcess.BonusProcessPeriodTo.Subtract((empInfo.EmpDateOfJoin < m_bonusProcess.BonusProcessPeriodFr) ? m_bonusProcess.BonusProcessPeriodFr : empInfo.EmpDateOfJoin);

                            m_empBonusProcess.EmpBonusProcessBonusProportion = Math.Round(Convert.ToDouble(m_totalDaysJoint.Days + 1) / Convert.ToDouble(m_totalDaysInPeriod.Days + 1), 4);
                            m_empBonusProcess.EmpBonusProcessType            = "S";
                            m_empBonusProcess.EmpBonusProcessBonusAmount     = Math.Round(m_recurringPayment.EmpRPBasicSalary *
                                                                                          m_empBonusProcess.EmpBonusProcessBonusProportion *
                                                                                          m_bonusProcess.BonusProcessStdRate, 2);

                            EEmpBonusProcess.db.insert(dbConn, m_empBonusProcess);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    protected void Delete_Click(object sender, EventArgs e)
    {
        ArrayList list = new ArrayList();

        foreach (RepeaterItem i in Repeater.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("ItemSelect");
            if (cb.Checked)
            {
                EEmpRecurringPayment o = new EEmpRecurringPayment();
                WebFormUtils.GetKeys(sdb, o, cb);
                list.Add(o);
            }
        }
        if (list.Count > 0)
        {
            WebUtils.StartFunction(Session, FUNCTION_CODE, CurrentEmpID);
            foreach (BaseObject o in list)
            {
                if (sdb.select(dbConn, o))
                {
                    sdb.delete(dbConn, o);
                }
            }
            WebUtils.EndFunction(dbConn);
        }
        loadData(info, sdb, Repeater);
    }
Ejemplo n.º 3
0
    protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView row = (DataRowView)e.Item.DataItem;
        CheckBox    cb  = (CheckBox)e.Item.FindControl("ItemSelect");

        WebFormUtils.LoadKeys(sdb, row, cb);
        e.Item.FindControl("ItemSelect").Visible = toolBar.DeleteButton_Visible;

        EEmpRecurringPayment obj = new EEmpRecurringPayment();

        sdb.toObject(((DataRowView)e.Item.DataItem).Row, obj);
        Hashtable values = new Hashtable();

        sdb.populate(obj, values);

        Binding eBinding = new Binding(dbConn, sdb);

        eBinding.add(new BlankZeroLabelVLBinder(sdb, (Label)e.Item.FindControl("CostCenterID"), ECostCenter.VLCostCenter).setTextDisplayForZero(HROne.Common.WebUtility.GetLocalizedString(ECostCenter.DEFAULT_COST_CENTER_TEXT)));

        eBinding.init(Request, Session);

        eBinding.toControl(values);

        ((HtmlTableCell)e.Item.FindControl("CostCenterDetailCell")).Visible = WebUtils.productLicense(Session).IsCostCenter;
        //((HtmlTableCell)e.Item.FindControl("RemarkCell")).ColSpan = ((HtmlTableRow)e.Item.FindControl("detailRow")).Cells.Count - 1 - (WebUtils.productLicense(Session).IsCostCenter ? 0 : 1);
    }
        public virtual void ImportToDatabase(int UploadEmpID)
        {
            DBFilter sessionFilter = new DBFilter();

            sessionFilter.add(new Match("SessionID", m_SessionID));
            if (UploadEmpID > 0)
            {
                sessionFilter.add(new Match("UploadEmpID", UploadEmpID));
            }
            ArrayList uploadEmpPayList = tempDB.select(dbConn, sessionFilter);

            foreach (EUploadEmpRecurringPayment obj in uploadEmpPayList)
            {
                EEmpRecurringPayment empRP = new EEmpRecurringPayment();

                if (obj.ImportActionStatus != ImportDBObject.ImportActionEnum.INSERT)
                {
                    empRP.EmpRPID = obj.EmpRPID;
                    uploadDB.select(dbConn, empRP);
                }

                obj.ExportToObject(empRP);

                if (obj.ImportActionStatus == ImportDBObject.ImportActionEnum.INSERT)
                {
                    empRP.EmpID = ParseTemp.GetEmpIDFromUploadEmpID(dbConn, obj.UploadEmpID);
                    AND andTerms = new AND();
                    andTerms.add(new Match("EmpRPEffFr", "<=", empRP.EmpRPEffFr));
                    andTerms.add(new Match("PayCodeID", empRP.PayCodeID));

                    EEmpRecurringPayment lastObj = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, EEmpRecurringPayment.db, "EmpRPEffFr", empRP.EmpID, andTerms);
                    if (lastObj != null)
                    {
                        if (lastObj.EmpRPEffTo.Ticks == 0)
                        {
                            lastObj.EmpRPEffTo = empRP.EmpRPEffFr.AddDays(-1);
                            uploadDB.update(dbConn, lastObj);
                        }
                    }

                    if (obj.UploadEmpAccID > 0)
                    {
                        empRP.EmpAccID = ParseTemp.GetEmpBankAccIDFromUploadEmpBankAccID(dbConn, obj.UploadEmpAccID);
                    }
                    uploadDB.insert(dbConn, empRP);
                    //DBFilter emplastPosFilter = new DBFilter();
                }
                else if (obj.ImportActionStatus == ImportDBObject.ImportActionEnum.UPDATE)
                {
                    uploadDB.update(dbConn, empRP);
                }

                tempDB.delete(dbConn, obj);
            }
        }
    protected void Delete_Click(object sender, EventArgs e)
    {
        EEmpRecurringPayment c = new EEmpRecurringPayment();

        c.EmpRPID = CurID;
        if (db.select(dbConn, c))
        {
            WebUtils.StartFunction(Session, FUNCTION_CODE, c.EmpID);
            db.delete(dbConn, c);
            WebUtils.EndFunction(dbConn);
        }
        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "EmpTab_Position_View.aspx?EmpID=" + EmpID.Value);
    }
Ejemplo n.º 6
0
    public bool Delete()
    {
        EEmpRecurringPayment c = new EEmpRecurringPayment();

        c.EmpRPID = CurrentEmpRPID;
        if (db.select(dbConn, c))
        {
            WebUtils.StartFunction(Session, FUNCTION_CODE, c.EmpID);
            db.delete(dbConn, c);
            WebUtils.EndFunction(dbConn);
        }

        return(true);
    }
    private decimal GetPayScale(EEmpRecurringPayment EmpRP)
    {
        DBFilter m_filter = new DBFilter();

        if (EmpRP.SchemeCode == null || EmpRP.SchemeCode == "" || EmpRP.Capacity == null || EmpRP.Capacity == "" || EmpRP.Point == null || EmpRP.Point < 0)
        {
            return(Decimal.Zero);
        }

        m_filter.add(new Match("SchemeCode", AppUtils.Encode(EPayScaleMap.db.getField("SchemeCode"), EmpRP.SchemeCode)));
        m_filter.add(new NullTerm("ExpiryDate"));
        m_filter.add(new Match("Point", EmpRP.Point));
        decimal m_salary = Decimal.Zero;

        ArrayList m_salaryList = EPayScaleMap.db.select(dbConn, m_filter);

        if (m_salaryList.Count > 0)
        {
            return(((EPayScaleMap)m_salaryList[0]).Salary);
        }

        return(-1);
    }
Ejemplo n.º 8
0
        public DataTable ExportDiscretionaryBonusTemplate(ArrayList pEmpList, bool IsIncludeCurrentPositionInfo)
        {
            DataTable tmpDataTable = new DataTable(TABLE_NAME_D);

            tmpDataTable.Columns.Add(HROne.Import.ImportBonusProcess.FIELD_EMP_NO, typeof(string));

            if (IsIncludeCurrentPositionInfo)
            {
                ImportEmpPersonalInfoProcess.AddEmployeeInfoHeader(tmpDataTable);
                ImportEmpPositionInfoProcess.AddEmployeePositionInfoHeader(dbConn, tmpDataTable);
            }

            tmpDataTable.Columns.Add(HROne.Import.ImportBonusProcess.FIELD_TARGET_SALARY, typeof(double));
            tmpDataTable.Columns.Add(HROne.Import.ImportBonusProcess.FIELD_RANK, typeof(string));

            EBonusProcess m_bonusProcess = EBonusProcess.GetObject(dbConn, m_BonusProcessID);

            if (m_bonusProcess != null)
            {
                foreach (EEmpPersonalInfo empInfo in pEmpList)
                {
                    if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                    {
                        DataRow row = tmpDataTable.NewRow();
                        row[FIELD_EMP_NO] = empInfo.EmpNo;

                        if (IsIncludeCurrentPositionInfo)
                        {
                            ImportEmpPersonalInfoProcess.AddEmployeeInfo(dbConn, row, empInfo.EmpID);
                            ImportEmpPositionInfoProcess.AddEmployeePositionInfo(dbConn, row, empInfo.EmpID);
                        }

                        // check if record already exists in EmpBonusProcess table
                        //DBFilter m_empBonusProcessFilter = new DBFilter();
                        //m_empBonusProcessFilter.add(new Match("EmpID", empInfo.EmpID));
                        //m_empBonusProcessFilter.add(new Match("BonusProecssID", m_bonusProcess.BonusProcessID ));
                        //m_empBonusProcessFilter.add(new Match("EmpID", empInfo.EmpID));
                        //m_empBonusProcessFilter.add(new Match("EmpBonusProcessType", "D"));

                        //ArrayList m_empBonusProcessList = EEmpBonusProcess.db.select(dbConn, m_empBonusProcessFilter);

                        //if (m_empBonusProcessList.Count > 0)
                        //{
                        //    EEmpBonusProcess m_empBonusProcess = (EEmpBonusProcess) m_empBonusProcessList[0];
                        //    row[FIELD_STD_RATE] = m_bonusProcess.BonusProcessStdRate;
                        //    row[FIELD_TARGET_SALARY] = m_empBonusProcess.EmpBonusProcessTargetSalary;
                        //    row[RANK] = m_empBonusProcess.EmpBonusProcessRank;
                        //}
                        //else
                        //{
                        EEmpRecurringPayment m_recurringPayment = GetSalaryMonthRecurringPayment(empInfo.EmpID, m_bonusProcess.BonusProcessSalaryMonth);
                        if (m_recurringPayment != null)
                        {
                            row[FIELD_TARGET_SALARY] = m_recurringPayment.EmpRPBasicSalary;
                        }
                        else
                        {
                            row[FIELD_TARGET_SALARY] = 0;
                        }
                        row[FIELD_RANK] = "";
                        //}
                        tmpDataTable.Rows.Add(row);
                    }
                }
            }

            if (IsIncludeCurrentPositionInfo)
            {
                ImportEmpPositionInfoProcess.RetriveHierarchyLevelHeader(dbConn, tmpDataTable);
            }

            return(tmpDataTable);
        }
Ejemplo n.º 9
0
        public override CrystalDecisions.CrystalReports.Engine.ReportDocument GenerateReport()
        {
            if (EmpPayrollList != null)
            {
                DataSet.PayrollTrialRunSummaryDataSet dataSet = new DataSet.PayrollTrialRunSummaryDataSet();
                DataSet.PayrollTrialRunSummaryDataSet.TrialRunSummaryDataTable dataTable = dataSet.TrialRunSummary;

                foreach (EEmpPayroll empPayroll in EmpPayrollList)
                {
                    EEmpPayroll.db.select(dbConn, empPayroll);

                    EPayrollPeriod payPeriod = new EPayrollPeriod();
                    payPeriod.PayPeriodID = empPayroll.PayPeriodID;
                    EPayrollPeriod.db.select(dbConn, payPeriod);

                    string strPayPeriod = payPeriod.PayPeriodFr.ToString("yyyy-MM-dd") + " - " + payPeriod.PayPeriodTo.ToString("yyyy-MM-dd");

                    EPayrollGroup payGroup = new EPayrollGroup();
                    payGroup.PayGroupID = payPeriod.PayGroupID;
                    EPayrollGroup.db.select(dbConn, payGroup);

                    EPayrollBatch payBatch = new EPayrollBatch();
                    payBatch.PayBatchID = empPayroll.PayBatchID;
                    EPayrollBatch.db.select(dbConn, payBatch);

                    EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                    empInfo.EmpID = empPayroll.EmpID;
                    EEmpPersonalInfo.db.select(dbConn, empInfo);


                    DataSet.PayrollTrialRunSummaryDataSet.TrialRunSummaryRow row = dataTable.NewTrialRunSummaryRow();
                    row.EmpPayrollID  = empPayroll.EmpPayrollID;
                    row.EmpID         = empPayroll.EmpID;
                    row.EmpNo         = empInfo.EmpNo;
                    row.EmpName       = empInfo.EmpEngFullName;
                    row.EmpAlias      = empInfo.EmpAlias;
                    row.PayGroupDesc  = payGroup.PayGroupCode + " - " + payGroup.PayGroupDesc;
                    row.PayGroupID    = empPayroll.PayPeriodID;
                    row.PayrollPeriod = strPayPeriod;
                    if (!payBatch.PayBatchValueDate.Ticks.Equals(0))
                    {
                        row.PayBatchValueDate = payBatch.PayBatchValueDate;
                    }
                    row.PayBatchRemark   = payBatch.PayBatchRemark;
                    row.BasicSalary      = 0;
                    row.LeaveAllowance   = 0;
                    row.PFundEE          = 0;
                    row.PFundER          = 0;
                    row.Overtime         = 0;
                    row.Bonus            = 0;
                    row.Commission       = 0;
                    row.Others           = 0;
                    row.NetIncome        = 0;
                    row.TotalIncome      = 0;
                    row.PayMethodAutoPay = 0;
                    row.PayMethodCash    = 0;
                    row.PayMethodCheque  = 0;
                    row.PayMethodOthers  = 0;

                    AND recurringBasicSalaryAndTerms = new AND();
                    recurringBasicSalaryAndTerms.add(new Match("EmpRPEffFr", "<=", payPeriod.PayPeriodTo));

                    DBFilter basicSalaryPaymentCodeFilter = new DBFilter();
                    basicSalaryPaymentCodeFilter.add(new Match("PaymentTypeID", EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeID));
                    recurringBasicSalaryAndTerms.add(new IN("PayCodeID", "Select PaymentCodeID FROM " + EPaymentCode.db.dbclass.tableName, basicSalaryPaymentCodeFilter));
                    EEmpRecurringPayment empRP = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, EEmpRecurringPayment.db, "EmpRPEffFr", empPayroll.EmpID, recurringBasicSalaryAndTerms);
                    if (empRP != null)
                    {
                        row.RecurringBasicSalary = empRP.EmpRPAmount;
                    }

                    DBFilter paymentRecordFilter = new DBFilter();
                    paymentRecordFilter.add(new Match("EmpPayrollID", empPayroll.EmpPayrollID));
                    paymentRecordFilter.add(new Match("PayRecStatus", "A"));
                    ArrayList paymentRecords = EPaymentRecord.db.select(dbConn, paymentRecordFilter);
                    foreach (EPaymentRecord paymentRecord in paymentRecords)
                    {
                        EPaymentCode payCode = new EPaymentCode();
                        payCode.PaymentCodeID = paymentRecord.PaymentCodeID;
                        EPaymentCode.db.select(dbConn, payCode);

                        EPaymentType payType = new EPaymentType();
                        payType.PaymentTypeID = payCode.PaymentTypeID;
                        EPaymentType.db.select(dbConn, payType);

                        if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.BasicSalary += paymentRecord.PayRecActAmount;
                            row.TotalIncome += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.LeaveDeductionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.LeaveAllowance += paymentRecord.PayRecActAmount;
                            row.TotalIncome    += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.LeaveAllowancePaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.LeaveAllowance += paymentRecord.PayRecActAmount;
                            row.TotalIncome    += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.MPFEmployeeMandatoryContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundEE += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.MPFEmployeeVoluntaryContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundEE += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.PFundEmployeeContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundEE += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.MPFEmployerMandatoryContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundER += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.MPFEmployerVoluntaryContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundER += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.PFundEmployerContributionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.PFundER += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.OverTimePaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.Overtime    += paymentRecord.PayRecActAmount;
                            row.TotalIncome += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.BonusPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.Bonus       += paymentRecord.PayRecActAmount;
                            row.TotalIncome += paymentRecord.PayRecActAmount;
                        }
                        else if (payType.PaymentTypeCode.Equals(EPaymentType.SystemPaymentType.CommissionPaymentType(dbConn).PaymentTypeCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            row.Commission  += paymentRecord.PayRecActAmount;
                            row.TotalIncome += paymentRecord.PayRecActAmount;
                        }
                        else
                        {
                            row.Others      += paymentRecord.PayRecActAmount;
                            row.TotalIncome += paymentRecord.PayRecActAmount;
                        }
                        if (paymentRecord.PayRecMethod.Equals("A"))
                        {
                            row.PayMethodAutoPay += paymentRecord.PayRecActAmount;
                        }
                        else if (paymentRecord.PayRecMethod.Equals("C"))
                        {
                            row.PayMethodCash += paymentRecord.PayRecActAmount;
                        }
                        else if (paymentRecord.PayRecMethod.Equals("Q"))
                        {
                            row.PayMethodCheque += paymentRecord.PayRecActAmount;
                        }
                        else
                        {
                            row.PayMethodOthers += paymentRecord.PayRecActAmount;
                        }

                        row.NetIncome += paymentRecord.PayRecActAmount;
                    }
                    row.TotalWagesForMinWages = HROne.Payroll.PayrollProcess.GetTotalWagesWithoutRestDayPayment(dbConn, empInfo.EmpID, payPeriod.PayPeriodFr, payPeriod.PayPeriodTo, null);
                    row.TotalWorkingHours     = HROne.Payroll.PayrollProcess.GetTotalEmpPayrollWorkingHours(dbConn, empInfo.EmpID, payPeriod.PayPeriodID);
                    row.MinWagesRequired      = row.TotalWorkingHours * HROne.Payroll.PayrollProcess.GetMinimumWages(dbConn, empInfo.EmpID, payPeriod.PayPeriodTo);
                    DBFilter mpfRecordFilter = new DBFilter();
                    mpfRecordFilter.add(new Match("EmpPayrollID", empPayroll.EmpPayrollID));
                    ArrayList mpfRecords = EMPFRecord.db.select(dbConn, mpfRecordFilter);
                    foreach (EMPFRecord mpfRecord in mpfRecords)
                    {
                        row.PFundER += mpfRecord.MPFRecActVCER + mpfRecord.MPFRecActMCER;
                    }
                    ArrayList orsoRecords = EORSORecord.db.select(dbConn, mpfRecordFilter);
                    foreach (EORSORecord orsoRecord in orsoRecords)
                    {
                        row.PFundER += orsoRecord.ORSORecActER;
                    }

                    DBFilter positionFilter = new DBFilter();
                    positionFilter.add(new Match("EmpID", empInfo.EmpID));
                    positionFilter.add(new Match("PayGroupID", payGroup.PayGroupID));
                    positionFilter.add(new Match("EmpPosEffFr", "<=", payPeriod.PayPeriodTo));

                    OR orPosEffToTerms = new OR();
                    orPosEffToTerms.add(new Match("EmpPosEffTo", ">=", payPeriod.PayPeriodFr));
                    orPosEffToTerms.add(new NullTerm("EmpPosEffTo"));
                    positionFilter.add(orPosEffToTerms);

                    ArrayList        positionInfos = EEmpPositionInfo.db.select(dbConn, positionFilter);
                    EEmpPositionInfo empPos        = null;
                    if (positionInfos.Count > 0)
                    {
                        empPos = (EEmpPositionInfo)positionInfos[0];
                    }
                    else
                    {
                        empPos = AppUtils.GetLastPositionInfo(dbConn, payPeriod.PayPeriodTo, empInfo.EmpID);
                    }

                    if (HLevelIDDisplayList != null && empPos != null)
                    {
                        for (int count = 0; count < HLevelIDDisplayList.Count && count < 2; count++)
                        {
                            int hLevelID = Convert.ToInt32(HLevelIDDisplayList[count]);

                            EHierarchyLevel hLevel = new EHierarchyLevel();
                            hLevel.HLevelID = hLevelID;
                            if (EHierarchyLevel.db.select(dbConn, hLevel))
                            {
                                row["HLevelDesc" + (count + 1)] = hLevel.HLevelDesc;

                                DBFilter empHierarchyFilter = new DBFilter();
                                empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                                empHierarchyFilter.add(new Match("HLevelID", hLevelID));
                                ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                                if (empHierarchyList.Count > 0)
                                {
                                    EEmpHierarchy empHierarchy = (EEmpHierarchy)empHierarchyList[0];

                                    EHierarchyElement hElement = new EHierarchyElement();
                                    hElement.HElementID = empHierarchy.HElementID;
                                    if (EHierarchyElement.db.select(dbConn, hElement))
                                    {
                                        row["HElementCode" + (count + 1)] = hElement.HElementCode;
                                        row["HElementDesc" + (count + 1)] = hElement.HElementDesc;
                                    }
                                }
                            }
                        }
                    }

                    dataTable.Rows.Add(row);
                }
                if (reportDocument == null)
                {
                    if (reportType.Equals(ReportType.TrialRun))
                    {
                        reportDocument = new ReportTemplate.Report_Payroll_TrialRunSummary();
                    }
                    else if (reportType.Equals(ReportType.History))
                    {
                        reportDocument = new ReportTemplate.Report_Payroll_HistorySummary();
                    }
                }
                else
                {
                }

                reportDocument.SetDataSource(dataSet);

                return(reportDocument);
            }
            else
            {
                return(null);
            }
        }
    private DataSet GenerateBackpayTemplate(String schemeCode, int paymentCodeID, DateTime paymentDate)
    {
        //Dictionary<int, string> m_PaymentCodeList = new Dictionary<int, string>();
        //foreach (EPaymentCode o in EPaymentCode.db.select(dbConn, new DBFilter()))
        //{
        //    m_PaymentCodeList.Add(o.PaymentCodeID, o.PaymentCode);
        //}

        string m_paymentCode = (EPaymentCode.GetObject(dbConn, paymentCodeID)).PaymentCode;

        DataSet   dataSet   = new DataSet();//export.GetDataSet();
        DataTable dataTable = new DataTable("ClaimsAndDeduction$");

        dataSet.Tables.Add(dataTable);

        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EMP_NO, typeof(string));
        dataTable.Columns.Add("English Name", typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EFFECTIVE_DATE, typeof(DateTime));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_CODE, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_BANK_ACCOUNT_NO, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_AMOUNT, typeof(double));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_NUM_OF_DAY_ADJUST, typeof(double));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REST_PAYMENT, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REMARK, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_COST_CENTER, typeof(string));

        DBFilter m_payscaleFilter = new DBFilter();

        m_payscaleFilter.add(new NullTerm("ExpiryDate"));

        if (schemeCode != "")
        {
            m_payscaleFilter.add(new Match("SchemeCode", schemeCode));
        }

        m_payscaleFilter.add("EffectiveDate", false);

        foreach (EPayScaleMap m_latestPayscale in EPayScaleMap.db.select(dbConn, m_payscaleFilter))
        {
            DBFilter m_payPeriodFilter = new DBFilter();
            m_payPeriodFilter.add(new Match("PayPeriodFr", ">=", m_latestPayscale.EffectiveDate));
            m_payPeriodFilter.add(new Match("PayPeriodStatus", "=", EPayrollPeriod.PAYPERIOD_STATUS_PROCESSEND_FLAG));
            m_payPeriodFilter.add(WebUtils.AddRankFilter(Session, "EmpID", true));

            foreach (EPayrollPeriod m_payrollPeriod in EPayrollPeriod.db.select(dbConn, m_payPeriodFilter))
            {
                DBFilter m_empPayrollFilter = new DBFilter();
                m_empPayrollFilter.add(new Match("PayPeriodID", m_payrollPeriod.PayPeriodID));

                DBFilter m_paymentRecordFilter = new DBFilter();
                DBFilter m_paymentTypeFilter   = new DBFilter();
                DBFilter m_paymentCodeFilter   = new DBFilter();

                m_paymentTypeFilter.add(new Match("PaymentTypeCode", "BASICSAL"));
                m_paymentCodeFilter.add(new IN("PaymentTypeID", "SELECT PaymentTypeID FROM PaymentType", m_paymentTypeFilter));

                m_paymentRecordFilter.add(new Match("EmpRPIDforBP", ">", 0));
                m_paymentRecordFilter.add(new IN("EmpPayrollID", "SELECT EmpPayrollID FROM EmpPayroll", m_empPayrollFilter));
                m_paymentRecordFilter.add(new IN("PaymentCodeID", "SELECT PaymentCodeID FROM PaymentCode", m_paymentCodeFilter));

                foreach (EPaymentRecord m_payRecord in EPaymentRecord.db.select(dbConn, m_paymentRecordFilter))
                {
                    EEmpRecurringPayment m_empRP = EEmpRecurringPayment.GetObject(dbConn, m_payRecord.EmpRPIDforBP);

                    if (schemeCode != "")
                    {
                        if (m_empRP.SchemeCode == null || m_empRP.SchemeCode != schemeCode)
                        {
                            break;
                        }
                    }
                    decimal m_newSalary = GetPayScale(m_empRP);
                    string  m_remarks   = "";
                    double  m_amount    = 0;
                    if (m_newSalary > 0)
                    {
//                        m_amount = Math.Round((m_payRecord.PayRecActAmount / m_empRP.EmpRPAmount) * (System.Convert.ToDouble(m_newSalary) - m_empRP.EmpRPAmount), 2);

                        int m_daysInMonth = DateTime.DaysInMonth(m_payrollPeriod.PayPeriodFr.Year, m_payrollPeriod.PayPeriodFr.Month);
                        if (m_payRecord.PayRecNumOfDayAdj != m_daysInMonth)
                        {
                            m_amount = Math.Round((System.Convert.ToDouble(m_newSalary) - m_empRP.EmpRPAmount) * m_payRecord.PayRecNumOfDayAdj / m_daysInMonth, 2);

                            m_remarks = String.Format("Backpay {0}: ({1}-{2})*{3}/{4}.", m_payrollPeriod.PayPeriodFr.ToString("yyyy-MM"),
                                                      m_newSalary.ToString("#,##0.00"),
                                                      m_empRP.EmpRPAmount.ToString("#,##0.00"),
                                                      m_payRecord.PayRecNumOfDayAdj,
                                                      m_daysInMonth);
                        }
                        else
                        {
                            m_amount  = Math.Round((System.Convert.ToDouble(m_newSalary) - m_empRP.EmpRPAmount), 2);
                            m_remarks = String.Format("Backpay {0}: {1}-{2}.", m_payrollPeriod.PayPeriodFr.ToString("yyyy-MM"),
                                                      m_newSalary.ToString("#,##0.00"),
                                                      m_empRP.EmpRPAmount.ToString("#,##0.00"));
                        }
                        if (m_amount > 0)
                        {
                            EEmpPersonalInfo m_empInfo = new EEmpPersonalInfo();
                            m_empInfo.EmpID = m_empRP.EmpID;
                            EEmpPersonalInfo.db.select(dbConn, m_empInfo);

                            DataRow m_row = dataTable.NewRow();
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EMP_NO] = m_empInfo.EmpNo;
                            m_row["English Name"] = m_empInfo.EmpEngFullName;
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EFFECTIVE_DATE] = paymentDate;
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_CODE]   = m_paymentCode;
                            switch (m_empRP.EmpRPMethod)
                            {
                            case "A":
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Autopay";
                                break;

                            case "Q":
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Cheque";
                                break;

                            case "C":
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Cash";
                                break;

                            default:
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Other";
                                break;
                            }
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_AMOUNT]            = m_amount;
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_NUM_OF_DAY_ADJUST] = 0;
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REST_PAYMENT]      = "No";
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REMARK]            = m_remarks;

                            EEmpBankAccount m_bank = new EEmpBankAccount();
                            m_bank.EmpBankAccountID = m_empRP.EmpAccID;
                            if (EEmpBankAccount.db.select(dbConn, m_bank))
                            {
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_BANK_ACCOUNT_NO] = m_bank.EmpAccountNo;
                            }

                            ECostCenter m_costCenter = new ECostCenter();
                            m_costCenter.CostCenterID = m_empRP.CostCenterID;
                            if (ECostCenter.db.select(dbConn, m_costCenter))
                            {
                                m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_COST_CENTER] = m_costCenter.CostCenterCode;
                            }
                            dataTable.Rows.Add(m_row);
                        }
                    }
                }
            }
            break;  // handle only 1 effective date
        }
        return(dataSet);
    }
        public virtual DataTable UploadToTempDatabase(DataTable rawDataTable, int UserID)
        {
            if (rawDataTable == null)
            {
                return(GetImportDataFromTempDatabase(null));
            }

            int rowCount = 1;

            foreach (DataRow row in rawDataTable.Rows)
            {
                if (rawDataTable == null)
                {
                    return(GetImportDataFromTempDatabase(null));
                }

                rowCount++;

                EUploadEmpRecurringPayment uploadEmpPay = new EUploadEmpRecurringPayment();
                EEmpRecurringPayment       lastEmpPay   = null;

                string EmpNo = row[FIELD_EMP_NO].ToString().Trim();
                uploadEmpPay.EmpID = Parse.GetEmpID(dbConn, EmpNo, UserID);
                if (uploadEmpPay.EmpID < 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                }
                try
                {
                    uploadEmpPay.EmpRPEffFr = Parse.toDateTimeObject(row[FIELD_FROM]);
                }
                catch
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_FROM + "=" + row[FIELD_FROM].ToString(), EmpNo, rowCount.ToString() });
                }
                try
                {
                    uploadEmpPay.EmpRPEffTo = Parse.toDateTimeObject(row[FIELD_TO]);
                }
                catch
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_TO + "=" + row[FIELD_TO].ToString(), EmpNo, rowCount.ToString() });
                }
                uploadEmpPay.PayCodeID = Parse.GetPaymentCodeID(dbConn, row[FIELD_PAYMENT_CODE].ToString());

                if (uploadEmpPay.PayCodeID == 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_PAYMENT_CODE + "=" + row[FIELD_PAYMENT_CODE].ToString(), EmpNo, rowCount.ToString() });
                }

                double amount = 0;
                if (double.TryParse(row[FIELD_AMOUNT].ToString(), out amount))
                {
                    uploadEmpPay.EmpRPAmount = amount;
                }
                else
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_AMOUNT + "=" + row[FIELD_AMOUNT].ToString(), EmpNo, rowCount.ToString() });
                }

                if (ESystemParameter.getParameter(dbConn, ESystemParameter.PARAM_CODE_PAYSCALE_POINT_SYSTEM) == "Y")
                {
                    if (amount > 0)
                    {
                        decimal m_point = 0;
                        if (decimal.TryParse(row[FIELD_POINT].ToString(), out m_point))
                        {
                            uploadEmpPay.Point = m_point;
                        }
                        else
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_POINT + "=" + row[FIELD_POINT].ToString(), EmpNo, rowCount.ToString() });
                        }

                        uploadEmpPay.SchemeCode = row[FIELD_SCHEME_CODE].ToString().Trim();
                        if (uploadEmpPay.SchemeCode == "")
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_SCHEME_CODE + "=" + row[FIELD_SCHEME_CODE].ToString(), EmpNo, rowCount.ToString() });
                        }

                        uploadEmpPay.Capacity = row[FIELD_CAPACITY].ToString().Trim();
                        if (uploadEmpPay.Capacity == "")
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_CAPACITY + "=" + row[FIELD_CAPACITY].ToString(), EmpNo, rowCount.ToString() });
                        }
                    }
                }

                if (ESystemParameter.getParameter(dbConn, ESystemParameter.PARAM_CODE_MONTHLY_ACHIEVEMENT_COMMISSION) == "Y")       // for F&V
                {
                    decimal m_fps;
                    decimal m_basicSalary;

                    if (decimal.TryParse(row[FIELD_FPS].ToString(), out m_fps))
                    {
                        uploadEmpPay.EmpRPFPS = System.Convert.ToDouble(m_fps);
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_FPS + "=" + row[FIELD_FPS].ToString(), EmpNo, rowCount.ToString() });
                    }

                    if (decimal.TryParse(row[FIELD_BASIC_SALARY].ToString(), out m_basicSalary))
                    {
                        uploadEmpPay.EmpRPBasicSalary = System.Convert.ToDouble(m_basicSalary);
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_BASIC_SALARY + "=" + row[FIELD_BASIC_SALARY].ToString(), EmpNo, rowCount.ToString() });
                    }
                }

                uploadEmpPay.CurrencyID = HROne.Lib.ExchangeCurrency.DefaultCurrency();

                uploadEmpPay.EmpRPUnit   = Parse.toRecurringPaymentUnit(row[FIELD_UNIT].ToString());
                uploadEmpPay.EmpRPMethod = Parse.toPaymentMethodCode(row[FIELD_METHOD].ToString());

                string BankCode = row[FIELD_ACCOUNT_NO].ToString();
                uploadEmpPay.EmpAccID = HROne.Import.Parse.GetEmpAccID(dbConn, BankCode, uploadEmpPay.EmpID);

                uploadEmpPay.UploadEmpID = ParseTemp.GetUploadEmpID(dbConn, EmpNo, m_SessionID);
                if (uploadEmpPay.UploadEmpID == 0)
                {
                    if (uploadEmpPay.EmpID == 0)
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                    }
                    else
                    {
                        uploadEmpPay.UploadEmpID = ImportEmpPersonalInfoProcess.CreateDummyUploadEmployeeInfo(dbConn, uploadEmpPay.EmpID, m_SessionID, UploadDateTime);
                    }
                }


                //  Check if the bank account no does not exist in database
                if (uploadEmpPay.EmpAccID == 0 && !BankCode.Trim().Equals(string.Empty))
                {
                    uploadEmpPay.UploadEmpAccID = ParseTemp.GetUploadEmpAccID(dbConn, BankCode, uploadEmpPay.UploadEmpID);
                    if (uploadEmpPay.UploadEmpAccID == 0)
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                    }
                }
                if ((uploadEmpPay.EmpAccID > 0 || uploadEmpPay.UploadEmpAccID > 0) && !uploadEmpPay.EmpRPMethod.Equals("A"))
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_METHOD + "=" + row[FIELD_METHOD].ToString(), EmpNo, rowCount.ToString() });
                }

                if (uploadEmpPay.EmpRPMethod.Equals("A") && uploadEmpPay.EmpAccID == 0 && uploadEmpPay.UploadEmpAccID == 0)
                {
                    EUploadEmpBankAccount uploadBankAccount = EUploadEmpBankAccount.GetDefaultBankAccount(dbConn, uploadEmpPay.EmpID, ParseTemp.GetUploadEmpID(dbConn, EmpNo, m_SessionID), m_SessionID);

                    if (uploadBankAccount != null)
                    {
                        //if (uploadBankAccount.EmpBankAccountID > 0)
                        //    uploadEmpPay.EmpAccID = uploadBankAccount.EmpBankAccountID;
                        //else
                        //    uploadEmpPay.UploadEmpAccID = uploadBankAccount.UploadEmpBankAccountID;
                    }
                    else
                    if (uploadEmpPay.EmpID > 0)
                    {
                        EEmpBankAccount bankAccount = EEmpBankAccount.GetDefaultBankAccount(dbConn, uploadEmpPay.EmpID);
                        if (bankAccount != null)
                        {
                            //uploadEmpPay.EmpAccID = bankAccount.EmpBankAccountID;
                        }
                        else
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                        }
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                    }
                }

                if (rawDataTable.Columns.Contains(FIELD_IS_NON_PAYROLL_ITEM))
                {
                    uploadEmpPay.EmpRPIsNonPayrollItem = row[FIELD_IS_NON_PAYROLL_ITEM].ToString().Equals("Yes", StringComparison.CurrentCultureIgnoreCase) || row[FIELD_IS_NON_PAYROLL_ITEM].ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase);
                }

                if (rawDataTable.Columns.Contains(FIELD_COST_CENTER))
                {
                    string CostCenter = row[FIELD_COST_CENTER].ToString();
                    if (!string.IsNullOrEmpty(CostCenter))
                    {
                        uploadEmpPay.CostCenterID = HROne.Import.Parse.GetCostCenterID(dbConn, CostCenter, false, UserID);
                        if (uploadEmpPay.CostCenterID <= 0)
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_COST_CENTER + "=" + CostCenter, EmpNo, rowCount.ToString() });
                        }
                    }
                    else
                    {
                        uploadEmpPay.CostCenterID = 0;
                    }
                }

                uploadEmpPay.EmpRPRemark = row[FIELD_REMARK].ToString().Trim();



                uploadEmpPay.SessionID       = m_SessionID;
                uploadEmpPay.TransactionDate = UploadDateTime;


                if (uploadEmpPay.EmpID != 0 && errors.List.Count <= 0)
                {
                    //if (rawDataTable.Columns.Contains(FIELD_INTERNAL_ID))
                    //{
                    //    try
                    //    {
                    //        if (!row.IsNull(FIELD_INTERNAL_ID))
                    //        {
                    //            int tmpID = FromHexDecWithCheckDigit((string)row[FIELD_INTERNAL_ID]);
                    //            EEmpRecurringPayment tmpObj = new EEmpRecurringPayment();
                    //            tmpObj.EmpRPID = tmpID;
                    //            if (EEmpRecurringPayment.db.select(dbConn, tmpObj))
                    //                uploadEmpPay.EmpRPID = tmpID;
                    //            else
                    //            {
                    //                errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_INTERNAL_ID + "=" + row[FIELD_INTERNAL_ID].ToString(), EmpNo, rowCount.ToString() });
                    //                continue;
                    //            }
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_INTERNAL_ID + "=" + row[FIELD_INTERNAL_ID].ToString(), EmpNo, rowCount.ToString() });
                    //        continue;
                    //    }
                    //}
                    if (rawDataTable.Columns.Contains(FIELD_SYNC_ID))
                    {
                        if (!row.IsNull(FIELD_SYNC_ID))
                        {
                            string strSynID = row[FIELD_SYNC_ID].ToString();
                            uploadEmpPay.SynID = strSynID;
                            if (!string.IsNullOrEmpty(strSynID))
                            {
                                DBFilter synIDFilter = new DBFilter();
                                synIDFilter.add(new Match("SynID", strSynID));
                                ArrayList objSameSynIDList = EEmpRecurringPayment.db.select(dbConn, synIDFilter);
                                if (objSameSynIDList.Count > 0)
                                {
                                    uploadEmpPay.EmpRPID = ((EEmpRecurringPayment)objSameSynIDList[0]).EmpRPID;
                                }
                            }
                        }
                    }

                    if (uploadEmpPay.EmpRPID == 0)
                    {
                        AND andTerms = new AND();
                        andTerms.add(new Match("EmpRPEffFr", "<=", uploadEmpPay.EmpRPEffFr));
                        andTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));

                        lastEmpPay = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, andTerms);


                        if (lastEmpPay != null)
                        {
                            if (uploadEmpPay.EmpAccID == lastEmpPay.EmpAccID &&
                                Math.Abs(uploadEmpPay.EmpRPAmount - lastEmpPay.EmpRPAmount) < 0.01 &&
                                uploadEmpPay.EmpRPMethod == lastEmpPay.EmpRPMethod &&
                                uploadEmpPay.EmpRPUnit == lastEmpPay.EmpRPUnit &&
                                uploadEmpPay.PayCodeID == lastEmpPay.PayCodeID &&
                                uploadEmpPay.EmpRPEffFr == lastEmpPay.EmpRPEffFr &&
                                uploadEmpPay.EmpRPEffTo == lastEmpPay.EmpRPEffTo &&
                                uploadEmpPay.SchemeCode == lastEmpPay.SchemeCode &&
                                uploadEmpPay.Capacity == lastEmpPay.Capacity &&
                                uploadEmpPay.Point == lastEmpPay.Point &&
                                uploadEmpPay.CostCenterID == lastEmpPay.CostCenterID &&
                                uploadEmpPay.EmpRPRemark == lastEmpPay.EmpRPRemark &&
                                uploadEmpPay.EmpRPIsNonPayrollItem == lastEmpPay.EmpRPIsNonPayrollItem
                                )
                            {
                                continue;
                            }
                            else
                            {
                                // add postion terms with new ID
                                if (lastEmpPay.EmpRPEffFr.Equals(uploadEmpPay.EmpRPEffFr))
                                {
                                    uploadEmpPay.EmpRPID = lastEmpPay.EmpRPID;
                                    if (uploadEmpPay.EmpRPEffTo.Ticks == 0 && lastEmpPay.EmpRPEffTo.Ticks != 0)
                                    {
                                        AND andNextTerms = new AND();
                                        andNextTerms.add(new Match("EmpRPEffFr", ">", lastEmpPay.EmpRPEffTo));
                                        andNextTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));

                                        EEmpRecurringPayment afterEmpRP = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, andNextTerms);
                                        if (afterEmpRP != null)
                                        {
                                            uploadEmpPay.EmpRPEffTo = afterEmpRP.EmpRPEffFr.AddDays(-1);
                                        }
                                    }
                                }
                                else
                                {
                                    AND lastObjAndTerms = new AND();
                                    lastObjAndTerms.add(new Match("EmpRPEffFr", ">", uploadEmpPay.EmpRPEffFr));
                                    if (!uploadEmpPay.EmpRPEffTo.Ticks.Equals(0))
                                    {
                                        lastObjAndTerms.add(new Match("EmpRPEffFr", "<=", uploadEmpPay.EmpRPEffTo));
                                    }
                                    lastObjAndTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));
                                    EEmpRecurringPayment lastObj = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, lastObjAndTerms);
                                    if (lastObj != null)
                                    {
                                        if (!lastObj.EmpRPEffTo.Ticks.Equals(0))
                                        {
                                            errors.addError(ImportErrorMessage.ERROR_DATE_FROM_OVERLAP, new string[] { uploadEmpPay.EmpRPEffFr.ToString("yyyy-MM-dd"), rowCount.ToString() });
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (uploadEmpPay.EmpRPID <= 0)
                {
                    uploadEmpPay.ImportActionStatus = ImportDBObject.ImportActionEnum.INSERT;
                }
                else
                {
                    uploadEmpPay.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;
                }


                Hashtable values = new Hashtable();
                tempDB.populate(uploadEmpPay, values);
                PageErrors pageErrors = new PageErrors(tempDB);
                tempDB.validate(pageErrors, values);
                if (pageErrors.errors.Count == 0)
                {
                    tempDB.insert(dbConn, uploadEmpPay);
                }
                else
                {
                    pageErrors.addError(rawDataTable.TableName);
                    throw new HRImportException(pageErrors.getPrompt() + "(line " + rowCount.ToString() + ")");
                }
            }
            if (errors.List.Count > 0)
            {
                ClearTempTable();
                throw (new HRImportException(rawDataTable.TableName + "\r\n" + errors.Message()));
            }
            return(GetImportDataFromTempDatabase(null));
        }
Ejemplo n.º 12
0
        protected bool GetEmpRecurringPaymentInfo(int pEmpID, DateTime pSalaryMonth, out double pTargetSalary, out string pPayMethod, out string pBankAccountCode, out string pCostCenterCode)
        {
            DBFilter m_rpFilter = new DBFilter();
            OR       m_orDate   = new OR();

            m_orDate.add(new NullTerm("EmpRPEffTo"));
            m_orDate.add(new Match("EmpRPEffTo", ">=", pSalaryMonth));

            m_rpFilter.add(m_orDate);
            m_rpFilter.add(new Match("EmpRPEffFr", "<=", pSalaryMonth));
            m_rpFilter.add(new Match("EmpID", pEmpID));
            m_rpFilter.add(new Match("EmpRPBasicSalary", ">", 0));

            DBFilter m_payCodeFilter = new DBFilter();
            DBFilter m_payTypeFilter = new DBFilter();

            m_payTypeFilter.add(new Match("PaymentTypeCode", "BASICSAL"));
            m_payCodeFilter.add(new IN("PaymentTypeID", "SELECT PaymentTypeID FROM PaymentType", m_payTypeFilter));
            m_rpFilter.add(new IN("PayCodeID", "SELECT PaymentCodeID FROM PaymentCode", m_payCodeFilter));
            m_rpFilter.add("EmpRPID", false);

            ArrayList m_rpList = EEmpRecurringPayment.db.select(dbConn, m_rpFilter);

            pPayMethod       = "";
            pBankAccountCode = "";
            pCostCenterCode  = "";
            pTargetSalary    = 0;

            if (m_rpList.Count > 0)
            {
                EEmpRecurringPayment m_empRP = (EEmpRecurringPayment)m_rpList[0];

                pTargetSalary = m_empRP.EmpRPBasicSalary;

                switch (m_empRP.EmpRPMethod)
                {
                case "A":
                    pPayMethod = "Autopay";
                    break;

                case "Q":
                    pPayMethod = "Cheque";
                    break;

                case "C":
                    pPayMethod = "Cash";
                    break;

                default:
                    pPayMethod = "Other";
                    break;
                }

                EEmpBankAccount m_bank = new EEmpBankAccount();
                m_bank.EmpBankAccountID = m_empRP.EmpAccID;
                if (EEmpBankAccount.db.select(dbConn, m_bank))
                {
                    pBankAccountCode = m_bank.EmpAccountNo;
                }

                ECostCenter m_costCenter = new ECostCenter();
                m_costCenter.CostCenterID = m_empRP.CostCenterID;
                if (ECostCenter.db.select(dbConn, m_costCenter))
                {
                    pCostCenterCode = m_costCenter.CostCenterCode;
                }
            }
            return(true);
        }
Ejemplo n.º 13
0
    protected void GenerateRecurringPayment()
    {
        DBFilter m_filter = new DBFilter();

        //ArrayList m_existing =

        m_filter.add(new NullTerm("ExpiryDate"));
        m_filter.add("SchemeCode", true);
        m_filter.add("Point", true);

        foreach (EPayScaleMap o in EPayScaleMap.db.select(dbConn, m_filter))
        {
            DBFilter m_filter2 = new DBFilter();
            m_filter2.add(new NullTerm("EmpRPEffTo"));
            m_filter2.add(new Match("SchemeCode", AppUtils.Encode(EPayScaleMap.db.getField("SchemeCode"), o.SchemeCode)));
            m_filter2.add(new Match("Point", o.Point));

            foreach (EEmpRecurringPayment p in EEmpRecurringPayment.db.select(dbConn, m_filter2))
            {
                if (p.EmpRPAmount != System.Convert.ToDouble(o.Salary))
                {
                    EEmpRecurringPayment m_newRP = new EEmpRecurringPayment();
                    m_newRP.Capacity     = p.Capacity;
                    m_newRP.CostCenterID = p.CostCenterID;
                    m_newRP.CurrencyID   = p.CurrencyID;
                    m_newRP.EmpAccID     = p.EmpAccID;
                    m_newRP.EmpID        = p.EmpID;
                    m_newRP.EmpRPAmount  = System.Convert.ToDouble(o.Salary);

                    // get employee position history -> get payroll group -> get payroll period
                    DBFilter m_filter3 = new DBFilter();
                    DBFilter m_filter4 = new DBFilter();
                    m_filter3.add(new Match("EmpID", p.EmpID));
                    m_filter3.add(new NullTerm("EmpPosEffTo"));

                    m_filter4.add(new IN("payGroupID", "SELECT payGroupID FROM EmpPositionInfo", m_filter3));
                    m_filter4.add(new Match("PayPeriodStatus", EPayrollPeriod.PAYPERIOD_STATUS_NORMAL_FLAG));

                    foreach (EPayrollPeriod m_payPeriod in EPayrollPeriod.db.select(dbConn, m_filter4))
                    {
                        m_newRP.EmpRPEffFr = m_payPeriod.PayPeriodFr;
                        p.EmpRPEffTo       = m_payPeriod.PayPeriodFr.AddDays(-1);
                    }

                    //m_newRP.EmpRPEffFr = p.
                    //m_newRP.EmpRPEffTo = null;
                    m_newRP.EmpRPIsNonPayrollItem           = p.EmpRPIsNonPayrollItem;
                    m_newRP.EmpRPMethod                     = p.EmpRPMethod;
                    m_newRP.EmpRPRemark                     = p.EmpRPRemark;
                    m_newRP.EmpRPUnit                       = p.EmpRPUnit;
                    m_newRP.EmpRPUnitPeriodAsDaily          = p.EmpRPUnitPeriodAsDaily;
                    m_newRP.EmpRPUnitPeriodAsDailyPayFormID = p.EmpRPUnitPeriodAsDailyPayFormID;
                    m_newRP.PayCodeID                       = p.PayCodeID;
                    m_newRP.Point      = p.Point;
                    m_newRP.SchemeCode = p.SchemeCode;

                    EEmpRecurringPayment.db.update(dbConn, p);
                    EEmpRecurringPayment.db.insert(dbConn, m_newRP);
                }
            }
        }
    }
    //protected void init_PaymentCodeDropdown()
    //{
    //    if (PaymentCode.Items.Count <= 0)
    //    {
    //        PaymentCode.Items.Add(new ListItem("Not Selected", "-1"));

    //        DBFilter m_filter = new DBFilter();
    //        m_filter.add("PaymentCode", true);

    //        foreach (EPaymentCode o in EPaymentCode.db.select(dbConn, m_filter))
    //        {
    //            PaymentCode.Items.Add(new ListItem(string.Format("{0} - {1}", o.PaymentCode, o.PaymentCodeDesc), o.PaymentCodeID.ToString()));
    //        }
    //    }
    //}

    protected DataSet GenerateCND(int ProcessID, DateTime PaymentDate)
    {
        EHitRateProcessImportBatch m_process = EHitRateProcessImportBatch.GetObject(dbConn, ProcessID);

        DataSet   dataSet   = new DataSet();//export.GetDataSet();
        DataTable dataTable = new DataTable("ClaimsAndDeduction$");

        dataSet.Tables.Add(dataTable);

        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EMP_NO, typeof(string));
        dataTable.Columns.Add("English Name", typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EFFECTIVE_DATE, typeof(DateTime));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_CODE, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_BANK_ACCOUNT_NO, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_AMOUNT, typeof(double));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_NUM_OF_DAY_ADJUST, typeof(double));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REST_PAYMENT, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REMARK, typeof(string));
        dataTable.Columns.Add(HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_COST_CENTER, typeof(string));

        DBFilter m_detailFilter = new DBFilter();

        m_detailFilter.add(new Match("HitRateProcessImportBatchID", ProcessID));
        m_detailFilter.add("EmpID", true);

        foreach (EHitRateProcess m_detail in EHitRateProcess.db.select(dbConn, m_detailFilter))
        {
            DBFilter m_rpFilter = new DBFilter();
            m_rpFilter.add(new NullTerm("EmpRPEffTo"));
            m_rpFilter.add(new Match("PayCodeID", m_detail.payCodeID));
            m_rpFilter.add(new Match("EmpID", m_detail.EmpID));
            m_rpFilter.add("EmpRPEffTo", true);

            ArrayList m_empRPList = EEmpRecurringPayment.db.select(dbConn, m_rpFilter);

            if (m_empRPList.Count > 0)
            {
                EEmpRecurringPayment m_empRP = (EEmpRecurringPayment)m_empRPList[0];

                double m_amount = m_empRP.EmpRPAmount * m_detail.HitRate / (double)100;
                string m_remarks;

//                if (m_amount > 0 && Math.Abs(m_amount) >= 0.01)
                {
                    m_remarks = String.Format("{0}*{1}%", m_empRP.EmpRPAmount.ToString("#,##0.00"),
                                              m_detail.HitRate.ToString("#,##0.00"));

                    EEmpPersonalInfo m_empInfo = new EEmpPersonalInfo();
                    m_empInfo.EmpID = m_empRP.EmpID;
                    EEmpPersonalInfo.db.select(dbConn, m_empInfo);

                    DataRow m_row = dataTable.NewRow();
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EMP_NO] = m_empInfo.EmpNo;
                    m_row["English Name"] = m_empInfo.EmpEngFullName;
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_EFFECTIVE_DATE] = PaymentDate;

                    EPaymentCode m_paymentCode = EPaymentCode.GetObject(dbConn, m_empRP.PayCodeID);
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_CODE] = m_paymentCode.PaymentCode;

                    switch (m_empRP.EmpRPMethod)
                    {
                    case "A":
                        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Autopay";
                        break;

                    case "Q":
                        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Cheque";
                        break;

                    case "C":
                        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Cash";
                        break;

                    default:
                        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_PAYMENT_METHOD] = "Other";
                        break;
                    }
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_AMOUNT]            = Math.Round(m_amount, 2);
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_NUM_OF_DAY_ADJUST] = 0; //DateTime.DaysInMonth(m_process.AsAtDate);
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REST_PAYMENT]      = "No";
                    m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_REMARK]            = m_remarks;

                    if (m_empRP.EmpAccID > 0)   // account number specified
                    {
                        EEmpBankAccount m_bank = new EEmpBankAccount();
                        m_bank.EmpBankAccountID = m_empRP.EmpAccID;
                        if (EEmpBankAccount.db.select(dbConn, m_bank))
                        {
                            m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_BANK_ACCOUNT_NO] = m_bank.EmpAccountNo;
                        }
                    }
                    //else
                    //{
                    //    // get default bank account
                    //    DBFilter m_bankAccFilter = new DBFilter();
                    //    m_bankAccFilter.add(new Match("EmpID", m_empRP.EmpID));
                    //    m_bankAccFilter.add(new Match("EmpAccDefault", true));
                    //    m_bankAccFilter.add("empBankAccountID", true);
                    //    ArrayList m_bankAccList = EEmpBankAccount.db.select(dbConn, m_bankAccFilter);
                    //    if (m_bankAccList.Count > 0)
                    //    {
                    //        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_BANK_ACCOUNT_NO] = ((EEmpBankAccount)m_bankAccList[0]).EmpAccountNo;
                    //    }
                    //}

                    ECostCenter m_costCenter = new ECostCenter();
                    m_costCenter.CostCenterID = m_empRP.CostCenterID;
                    if (ECostCenter.db.select(dbConn, m_costCenter))
                    {
                        m_row[HROne.Import.ImportClaimsAndDeductionsProcess.FIELD_COST_CENTER] = m_costCenter.CostCenterCode;
                    }
                    dataTable.Rows.Add(m_row);
                }
            }
        }
        return(dataSet);
    }
        public void GenerateDetailByEmpID()
        {
            //dataSet = new DataSet.Payroll_PaySlip();

            //EPayrollPeriod payPeriod = new EPayrollPeriod();
            //payPeriod.PayPeriodID = PayPeriodID;
            //EPayrollPeriod.db.select(dbConn, payPeriod);

            //EPayrollGroup payGroup = new EPayrollGroup();
            //payGroup.PayGroupID = payPeriod.PayGroupID;
            //EPayrollGroup.db.select(dbConn, payGroup);

            //string strPayPeriod = payPeriod.PayPeriodFr.ToString("yyyy-MM-dd") + " - " + payPeriod.PayPeriodTo.ToString("yyyy-MM-dd");


            DataTable empInfoTable = dataSet.Tables["EmpInfo"];
            DataTable dataTable    = dataSet.Tables["PaySlip"];
            DataTable mpfTable     = dataSet.Tables["PaySlip_MPF"];
            DataTable orsoTable    = dataSet.Tables["PaySlip_ORSO"];

            foreach (EEmpTermination empTermination in EmpList)
            {
                string empDiv = string.Empty;
                string empDep = string.Empty;

                EEmpTermination.db.select(dbConn, empTermination);

                ECessationReason cessationReason = new ECessationReason();
                cessationReason.CessationReasonID = empTermination.CessationReasonID;
                ECessationReason.db.select(dbConn, cessationReason);

                //DBFilter bankAccountFilter = new DBFilter();
                //bankAccountFilter.add(new Match("EmpID", empInfo.EmpID));
                //bankAccountFilter.add(new Match("EmpAccDefault", 1));
                //ArrayList bankAccounts = EEmpBankAccount.db.select(dbConn, bankAccountFilter);
                //EEmpBankAccount bankAccount;
                //if (bankAccounts.Count > 0)
                //    bankAccount = (EEmpBankAccount)bankAccounts[0];
                //else
                //    bankAccount = new EEmpBankAccount();

                EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                empInfo.EmpID = empTermination.EmpID;
                if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                {
                    //DBFilter positionFilter = new DBFilter();
                    //positionFilter.add(new Match("EmpID", empInfo.EmpID));
                    ////positionFilter.add(new Match("PayGroupID", payGroup.PayGroupID));
                    //positionFilter.add(new Match("EmpPosEffFr", "<=", empTermination.EmpTermLastDate));

                    //OR orPosEffToTerms = new OR();
                    //orPosEffToTerms.add(new Match("EmpPosEffTo", ">=", empTermination.EmpTermLastDate));
                    //orPosEffToTerms.add(new NullTerm("EmpPosEffTo"));
                    //positionFilter.add(orPosEffToTerms);

                    //ArrayList positionInfos = EEmpPositionInfo.db.select(dbConn, positionFilter);
                    EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, empTermination.EmpTermLastDate, empInfo.EmpID);// new EPosition();
                    if (empPos == null)
                    {
                        empPos = new EEmpPositionInfo();
                    }
                    EPosition position = new EPosition();
                    ECompany  company  = new ECompany();
                    ////if (positionInfos.Count > 0)
                    ////{
                    //    EEmpPositionInfo empPos = (EEmpPositionInfo)positionInfos[0];
                    position.PositionID = empPos.PositionID;
                    EPosition.db.select(dbConn, position);
                    company.CompanyID = empPos.CompanyID;
                    ECompany.db.select(dbConn, company);


                    DBFilter emphierarchyFilter = new DBFilter();
                    emphierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                    ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, emphierarchyFilter);
                    foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                    {
                        EHierarchyElement hElement = new EHierarchyElement();
                        hElement.HElementID = empHierarchy.HElementID;
                        if (EHierarchyElement.db.select(dbConn, hElement))
                        {
                            EHierarchyLevel hLevel = new EHierarchyLevel();
                            hLevel.HLevelID = hElement.HLevelID;
                            if (EHierarchyLevel.db.select(dbConn, hLevel))
                            {
                                if (hLevel.HLevelDesc.Equals("Division", StringComparison.CurrentCultureIgnoreCase) || hLevel.HLevelCode.Equals("DIV", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    empDiv = hElement.HElementDesc;
                                }
                                //if (hLevel.HLevelDesc.Equals("Department", StringComparison.CurrentCultureIgnoreCase) || hLevel.HLevelCode.Equals("DEP", StringComparison.CurrentCultureIgnoreCase))
                                //    empDep = hElement.HElementDesc;
                            }
                        }
                    }

                    //}

                    DBFilter basicSalaryRPFilter = new DBFilter();
                    basicSalaryRPFilter.add(new Match("EmpID", empInfo.EmpID));
                    basicSalaryRPFilter.add(new Match("EmpRPEffFr", "<=", empTermination.EmpTermLastDate));

                    OR orbasicSalaryRPToTerm = new OR();
                    orbasicSalaryRPToTerm.add(new Match("EmpRPEffTo", ">=", empTermination.EmpTermLastDate));
                    orbasicSalaryRPToTerm.add(new NullTerm("EmpRPEffTo"));
                    basicSalaryRPFilter.add(orbasicSalaryRPToTerm);

                    //filter.add(EmpRPEffFr,true);

                    DBFilter basicSalaryPaymentCodeFilter = new DBFilter();
                    basicSalaryPaymentCodeFilter.add(new Match("PaymentTypeID", EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeID));

                    basicSalaryRPFilter.add(new IN("PayCodeID", "Select PaymentCodeID from PaymentCode", basicSalaryPaymentCodeFilter));

                    ArrayList recurringPayments = EEmpRecurringPayment.db.select(dbConn, basicSalaryRPFilter);


                    EEmpRecurringPayment basicSalaryRP = new EEmpRecurringPayment();
                    if (recurringPayments.Count > 0)
                    {
                        basicSalaryRP = (EEmpRecurringPayment)recurringPayments[0];
                    }



                    DBFilter payPeriodFilter = new DBFilter();
                    payPeriodFilter.add(new Match("PayPeriodTo", ">=", empTermination.EmpTermLastDate));

                    DBFilter empPayrollFilter = new DBFilter();
                    empPayrollFilter.add(new Match("EmpID", empInfo.EmpID));


                    empPayrollFilter.add(new IN("PayPeriodID", "Select PayPeriodID from PayrollPeriod", payPeriodFilter));
                    string PayBatchInTerm = string.Empty;
                    if (payBatchList != null)
                    {
                        foreach (EPayrollBatch payrollBatch in payBatchList)
                        {
                            if (string.IsNullOrEmpty(PayBatchInTerm))
                            {
                                PayBatchInTerm = payrollBatch.PayBatchID.ToString();
                            }
                            else
                            {
                                PayBatchInTerm += "," + payrollBatch.PayBatchID.ToString();
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(PayBatchInTerm))
                    {
                        empPayrollFilter.add(new IN("PayBatchID", PayBatchInTerm, null));
                    }

                    if (PayPeriodList != null)
                    {
                        string payPeriodIDList = string.Empty;
                        foreach (EPayrollPeriod payPeriod in PayPeriodList)
                        {
                            if (string.IsNullOrEmpty(payPeriodIDList))
                            {
                                payPeriodIDList = payPeriod.PayPeriodID.ToString();
                            }
                            else
                            {
                                payPeriodIDList += "," + payPeriod.PayPeriodID.ToString();
                            }
                        }
                        if (!string.IsNullOrEmpty(payPeriodIDList))
                        {
                            empPayrollFilter.add(new IN("PayPeriodID", payPeriodIDList, null));
                        }
                    }

                    //  if ReportType.Unspecify, no filter is add (for backward compatibility with previous UI)
                    if (reportType.Equals(ReportType.TrialRun))
                    {
                        empPayrollFilter.add(new Match("EmpPayStatus", "=", "T"));
                    }
                    else if (reportType.Equals(ReportType.History))
                    {
                        empPayrollFilter.add(new Match("EmpPayStatus", "<>", "T"));
                    }

                    IN inEmpPayroll = new IN("EmpPayrollID", "Select EmpPayrollID from EmpPayroll", empPayrollFilter);

                    DBFilter paymentRecordFilter = new DBFilter();
                    paymentRecordFilter.add(inEmpPayroll);
                    paymentRecordFilter.add(new Match("PayRecStatus", "A"));
                    paymentRecordFilter.add("PaymentCodeID", true);
                    paymentRecordFilter.add("PayRecMethod", true);

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

                    DBFilter mpfRecordFilter = new DBFilter();
                    mpfRecordFilter.add(inEmpPayroll);
                    mpfRecordFilter.add("MPFRecPeriodFr", true);
                    ArrayList mpfRecords = EMPFRecord.db.select(dbConn, mpfRecordFilter);

                    DBFilter orsoRecordFilter = new DBFilter();
                    orsoRecordFilter.add(inEmpPayroll);
                    orsoRecordFilter.add("ORSORecPeriodFr", true);
                    ArrayList orsoRecords = EORSORecord.db.select(dbConn, orsoRecordFilter);

                    EPayrollBatch payBatch = null;

                    DBFilter payBatchFilter = new DBFilter();
                    payBatchFilter.add(new IN("PayBatchID", "Select PayBatchID from EmpPayroll", empPayrollFilter));
                    if (!string.IsNullOrEmpty(PayBatchInTerm))
                    {
                        payBatchFilter.add(new IN("PayBatchID", PayBatchInTerm, null));
                    }
                    payBatchFilter.add("PayBatchValueDate", false);

                    ArrayList payBatchs = EPayrollBatch.db.select(dbConn, payBatchFilter);
                    if (payBatchs.Count > 0)
                    {
                        payBatch = (EPayrollBatch)payBatchs[0];
                    }

                    bool hasMPF = false, hasORSO = false, hasLeaveBalance = false;

                    if (IsShowLeaveBalance)
                    {
                        hasLeaveBalance = GenerateLeaveBalanceData(empInfo.EmpID, empTermination.EmpTermLastDate);
                    }

                    //double intALBalance = 0;
                    //HROne.LeaveCalc.LeaveBalanceCalc calc = new HROne.LeaveCalc.LeaveBalanceCalc(empInfo.EmpID, payPeriod.PayPeriodFr.AddDays(-1));
                    //ArrayList leaveBalanceList = calc.getCurrentBalanceList();
                    //foreach (ELeaveBalance b in leaveBalanceList)
                    //{
                    //    if (b.LeaveTypeID.Equals(ELeaveType.ANNUAL_LEAVE_TYPE(dbConn).LeaveTypeID))
                    //        intALBalance = b.Balance;
                    //}
                    hasMPF  = GenerateMPFData(empInfo.EmpID, mpfRecords);
                    hasORSO = GenerateORSOData(empInfo.EmpID, orsoRecords);

                    DataRow empInfoRow = empInfoTable.NewRow();
                    empInfoRow["EmpID"]          = empInfo.EmpID;
                    empInfoRow["EmpNo"]          = empInfo.EmpNo;
                    empInfoRow["EmpName"]        = empInfo.EmpEngFullName;
                    empInfoRow["EmpChineseName"] = empInfo.EmpChiFullName;
                    empInfoRow["EmpHKID"]        = empInfo.EmpHKID;
                    empInfoRow["EmpDateOfJoin"]  = empInfo.EmpDateOfJoin;

                    //empInfoRow["PayGroupDesc"] = payGroup.PayGroupCode + " - " + payGroup.PayGroupDesc;
                    //empInfoRow["PayrollPeriod"] = strPayPeriod;
                    //empInfoRow["PeriodFr"] = payPeriod.PayPeriodFr;
                    //empInfoRow["PeriodTo"] = payPeriod.PayPeriodTo;
                    //empInfoRow["MPFDate"] = new DateTime(payPeriod.PayPeriodTo.Year, payPeriod.PayPeriodTo.Month, 10).AddMonths(1);

                    //empInfoRow["BankAccount"] = bankAccount.EmpBankCode + " - " + bankAccount.EmpBranchCode + "-" + bankAccount.EmpAccountNo;
                    empInfoRow["CompanyName"]         = company.CompanyName;
                    empInfoRow["PositionDesc"]        = position.PositionDesc;
                    empInfoRow["BasicSalary"]         = basicSalaryRP.EmpRPAmount;
                    empInfoRow["EmpTermResignDate"]   = empTermination.EmpTermResignDate;
                    empInfoRow["EmpTermLastDate"]     = empTermination.EmpTermLastDate;
                    empInfoRow["CessationReasonDesc"] = cessationReason.CessationReasonDesc;
                    empInfoRow["HasMPF"]          = hasMPF;
                    empInfoRow["HasORSO"]         = hasORSO;
                    empInfoRow["HasLeaveBalance"] = hasLeaveBalance;
                    int YearOfServiceMonth = Convert.ToInt32(Math.Truncate(HROne.CommonLib.Utility.MonthDifference(empInfo.EmpServiceDate, empTermination.EmpTermLastDate)));
                    empInfoRow["YearOfServiceYear"]  = YearOfServiceMonth / 12;
                    empInfoRow["YearOfServiceMonth"] = YearOfServiceMonth % 12;
                    if (payBatch != null)
                    {
                        if (payBatch.PayBatchValueDate.Ticks != 0)
                        {
                            empInfoRow["ValueDate"] = payBatch.PayBatchValueDate;
                        }
                    }
                    if (empDep.Equals(string.Empty) && empDiv.Equals(string.Empty))
                    {
                        empInfoRow["Department"] = empDiv;
                    }
                    else if (empDiv.Equals(string.Empty))
                    {
                        empInfoRow["Department"] = empDep;
                    }
                    else if (empDep.Equals(string.Empty))
                    {
                        empInfoRow["Department"] = empDiv;
                    }
                    else
                    {
                        empInfoRow["Department"] = empDiv + " / " + empDep;
                    }

                    //empInfoRow["AnnualLeaveBalance"] = intALBalance;
                    //empInfoRow["LeaveBalanceAsOfDate"] = payPeriod.PayPeriodFr.AddDays(-1);
                    empInfoTable.Rows.Add(empInfoRow);

                    GeneratePayrollData(empInfo.EmpID, paymentRecords);
                }
            }
            DataRow[] allowanceRows = dataSet.Tables["PaySlip"].Select("PayAmount > 0", "PaymentCodeDisplaySeqNo");
            foreach (DataRow importRow in allowanceRows)
            {
                dataSet.Tables["PaySlip_Allowance"].ImportRow(importRow);
            }

            DataRow[] deductionRows = dataSet.Tables["PaySlip"].Select("PayAmount < 0", "PaymentCodeDisplaySeqNo");
            foreach (DataRow importRow in deductionRows)
            {
                dataSet.Tables["PaySlip_Deduction"].ImportRow(importRow);
            }
        }
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        if (CurID > 0)
        {
            ESalaryIncrementBatch m_process = ESalaryIncrementBatch.GetObject(dbConn, CurID);

            if (m_process.Status == ESalaryIncrementBatch.STATUS_OPEN) // not Confirmed/Applied
            {
                DBFilter m_filterByBatchID = new DBFilter();
                m_filterByBatchID.add(new Match("BatchID", m_process.BatchID));
                m_filterByBatchID.add("EmpID", true);

                try
                {
                    WebUtils.StartFunction(Session, FUNCTION_CODE, true);
                    dbConn.BeginTransaction();
                    foreach (ESalaryIncrementBatchDetail d in ESalaryIncrementBatchDetail.db.select(dbConn, m_filterByBatchID))
                    {
                        if (d.CurrentPoint != d.NewPoint)
                        {
                            DBFilter m_cpFilter = new DBFilter();
                            m_cpFilter.add(new NullTerm("EmpRPEffTo"));
                            m_cpFilter.add(new Match("EmpID", d.EmpID));
                            m_cpFilter.add(new Match("SchemeCode", AppUtils.Encode(EEmpRecurringPayment.db.getField("SchemeCode"), d.SchemeCode)));
                            m_cpFilter.add(new Match("Capacity", AppUtils.Encode(EEmpRecurringPayment.db.getField("Capacity"), d.Capacity)));
                            m_cpFilter.add(new Match("Point", d.CurrentPoint));

                            DBFilter m_payTypeCodeFilter = new DBFilter();
                            m_payTypeCodeFilter.add(new Match("PaymentTypeCode", "BASICSAL"));

                            DBFilter m_payTypeFilter = new DBFilter();
                            m_payTypeFilter.add(new IN("PaymentTypeID", "SELECT PaymentTypeID FROM PaymentType", m_payTypeCodeFilter));
                            m_cpFilter.add(new IN("PayCodeID", "SELECT PaymentCodeID FROM PaymentCode", m_payTypeFilter));

                            foreach (EEmpRecurringPayment m_cp in EEmpRecurringPayment.db.select(dbConn, m_cpFilter))
                            {
                                DBFilter m_payScaleFilter = new DBFilter();

                                m_payScaleFilter.add(new Match("SchemeCode", AppUtils.Encode(EEmpRecurringPayment.db.getField("SchemeCode"), d.SchemeCode)));
                                m_payScaleFilter.add(new Match("EffectiveDate", "<=", m_process.AsAtDate));

                                OR m_orDate = new OR();
                                m_orDate.add(new Match("ExpiryDate", ">=", m_process.AsAtDate));
                                m_orDate.add(new NullTerm("ExpiryDate"));

                                m_payScaleFilter.add(m_orDate);
                                m_payScaleFilter.add(new Match("Point", d.NewPoint));

                                ArrayList m_payScaleMapList = EPayScaleMap.db.select(dbConn, m_payScaleFilter);
                                if (m_payScaleMapList.Count > 0)
                                {
                                    EEmpRecurringPayment m_newCp = new EEmpRecurringPayment();

                                    m_newCp.EmpRPAmount = System.Convert.ToDouble(((EPayScaleMap)m_payScaleMapList[0]).Salary);
                                    m_newCp.EmpRPAmount = Math.Round(m_newCp.EmpRPAmount, 2);
                                    m_newCp.EmpRPEffFr  = m_process.AsAtDate;
                                    m_newCp.Point       = d.NewPoint;

                                    //m_newCp.EmpRPEffTo = m_cp.EmpRPEffTo;
                                    m_newCp.Capacity                        = m_cp.Capacity;
                                    m_newCp.CostCenterID                    = m_cp.CostCenterID;
                                    m_newCp.CurrencyID                      = m_cp.CurrencyID;
                                    m_newCp.EmpAccID                        = m_cp.EmpAccID;
                                    m_newCp.EmpID                           = m_cp.EmpID;
                                    m_newCp.EmpRPID                         = m_cp.EmpRPID;
                                    m_newCp.EmpRPIsNonPayrollItem           = m_cp.EmpRPIsNonPayrollItem;
                                    m_newCp.EmpRPMethod                     = m_cp.EmpRPMethod;
                                    m_newCp.EmpRPRemark                     = m_cp.EmpRPRemark;
                                    m_newCp.EmpRPUnit                       = m_cp.EmpRPUnit;
                                    m_newCp.EmpRPUnitPeriodAsDaily          = m_cp.EmpRPUnitPeriodAsDaily;
                                    m_newCp.EmpRPUnitPeriodAsDailyPayFormID = m_cp.EmpRPUnitPeriodAsDailyPayFormID;
                                    m_newCp.PayCodeID                       = m_cp.PayCodeID;
                                    m_newCp.SchemeCode                      = m_cp.SchemeCode;

                                    m_cp.EmpRPEffTo = m_process.AsAtDate.AddDays(-1);
                                    if (EEmpRecurringPayment.db.update(dbConn, m_cp))
                                    {
                                        EEmpRecurringPayment.db.insert(dbConn, m_newCp);
                                    }
                                }
                                else
                                {
                                    errors.addError(string.Format("Cannot map salary setting (Scheme Code={0}, Capacity={1}, Point={2})", new string[] { d.SchemeCode, d.Capacity, d.NewPoint.ToString("0.00") }));
                                    dbConn.RollbackTransaction();
                                    WebUtils.EndFunction(dbConn);
                                    return;
                                }
                            }
                        }
                        EEmpPersonalInfo m_empInfo = EEmpPersonalInfo.GetObject(dbConn, d.EmpID);
                        if (m_empInfo.EmpNextSalaryIncrementDate == m_process.AsAtDate)
                        {
                            m_empInfo.EmpNextSalaryIncrementDate = m_process.AsAtDate.AddYears(1);
                            EEmpPersonalInfo.db.update(dbConn, m_empInfo);
                        }
                    }

                    m_process.Status          = ESalaryIncrementBatch.STATUS_CONFIRMED;
                    m_process.ConfirmDateTime = AppUtils.ServerDateTime();
                    m_process.ConfirmBy       = WebUtils.GetCurUser(Session).UserID;

                    ESalaryIncrementBatch.db.update(dbConn, m_process);

                    //errors.addError("Salary Increment Batch confirmed!");

                    dbConn.CommitTransaction();
                    WebUtils.EndFunction(dbConn);
                }
                catch (Exception ex)
                {
                    dbConn.RollbackTransaction();
                    errors.addError(ex.Message);
                    WebUtils.EndFunction(dbConn);
                    return;
                }
                if (errors.isEmpty())
                {
                    string m_message = "Salary Increment Batch confirmed!";
                    string m_url     = "Payroll_SalaryIncrementBatch_View.aspx?BatchID=" + CurID;

                    WebUtils.RegisterRedirectJavaScript(this, m_url, HROne.Common.WebUtility.GetLocalizedString(m_message));
                }
            }
            else
            {
                errors.addError("Batch is confirmed.");
            }
        }
    }
    protected bool loadObject()
    {
        obj = new EEmpRecurringPayment();
        bool isNew = WebFormWorkers.loadKeys(db, obj, DecryptedRequest);

        DBFilter filter = new DBFilter();

        filter.add(new Match("EmpID", CurEmpID));
        filter.add(WebUtils.AddRankFilter(Session, "EmpID", true));
        if (EEmpPersonalInfo.db.count(dbConn, filter) == 0)
        {
            if (CurEmpID <= 0)
            {
                return(false);
            }
            else
            {
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
            }
        }

        if (!db.select(dbConn, obj))
        {
            if (CurID <= 0)
            {
                return(false);
            }
            else
            {
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
            }
        }

        if (obj.EmpID != CurEmpID)
        {
            if (CurID <= 0)
            {
                return(false);
            }
            else
            {
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
            }
        }

        Emp_RecurringPayment_List1.CurrentEmpID     = obj.EmpID;
        Emp_RecurringPayment_List1.CurrentPayCodeID = obj.PayCodeID;

        CurPayCodeID = obj.PayCodeID;

        Hashtable values = new Hashtable();

        db.populate(obj, values);
        binding.toControl(values);

        if (obj.EmpRPMethod.Equals("A"))
        {
            BankAccountRow.Visible     = true;
            lblDefaultBankAccount.Text = string.Empty;
            if (obj.EmpAccID == 0)
            {
                EEmpBankAccount bankAccount = EEmpBankAccount.GetDefaultBankAccount(dbConn, CurEmpID);
                if (bankAccount != null)
                {
                    lblDefaultBankAccount.Text = bankAccount.EmpBankCode + "-" + bankAccount.EmpBranchCode + "-" + bankAccount.EmpAccountNo;
                }
            }
        }
        else
        {
            BankAccountRow.Visible = false;
        }

        if (obj.EmpRPUnit.Equals("P"))
        {
            //EmpRPUnitPeriodAsDaily.Visible = true;
            if (obj.EmpRPUnitPeriodAsDaily)
            {
                EmpRPUnitPeriodAsDaily.Visible             = true;
                EmpRPUnitPeriodAsDailyPayFormIDRow.Visible = true;
            }
            else
            {
                EmpRPUnitPeriodAsDaily.Visible             = false;
                EmpRPUnitPeriodAsDailyPayFormIDRow.Visible = false;
            }
        }
        else
        {
            EmpRPUnitPeriodAsDaily.Visible             = false;
            EmpRPUnitPeriodAsDailyPayFormIDRow.Visible = false;
        }
        // Start 0000166, KuangWei, 2015-02-04
        init_ShiftDutyCodeLabel();
        init_PayCalFormulaCodeLabel();
        // End 0000166, KuangWei, 2015-02-04
        return(true);
    }
Ejemplo n.º 18
0
    protected bool loadObject()
    {
        EEmpRecurringPayment obj = new EEmpRecurringPayment();
        bool isNew = WebFormWorkers.loadKeys(db, obj, DecryptedRequest);

        DBFilter filter = new DBFilter();

        filter.add(new Match("EmpID", CurrentEmpID));
        filter.add(WebUtils.AddRankFilter(Session, "EmpID", true));
        if (EEmpPersonalInfo.db.count(dbConn, filter) == 0)
        {
            if (CurrentEmpID <= 0)
            {
                return(false);
            }
            else
            {
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
            }
        }

        if (!db.select(dbConn, obj))
        {
            obj.EmpRPID = PrevEmpRPID;
            if (!db.select(dbConn, obj))
            {
                if (CurrentEmpRPID <= 0)
                {
                    return(false);
                }
                else
                {
                    HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
                }
            }
            else
            {
                obj.EmpRPID    = 0;
                obj.EmpRPEffFr = new DateTime();
                obj.EmpRPEffTo = new DateTime();
            }
        }

        if (obj.EmpID != CurrentEmpID)
        {
            if (CurrentEmpRPID <= 0)
            {
                return(false);
            }
            else
            {
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/AccessDeny.aspx");
            }
        }


        Hashtable values = new Hashtable();

        db.populate(obj, values);
        binding.toControl(values);

        if (obj.SchemeCode != null && obj.SchemeCode != "")
        {
            SchemeCode.Text = obj.SchemeCode;

            RefreshCapacity();
            if (obj.Capacity != null && obj.Capacity != "")
            {
                CapacitySelect.Text = obj.Capacity;

                RefreshPoint();

                if (obj.Point != null && obj.Point > -1)
                {
                    PointSelect.Text = obj.Point.ToString("0.00");
                }
            }
        }
        return(true);
    }
Ejemplo n.º 19
0
        protected bool ValidateBusinessRule(ESalaryIncrementBatchDetail inputObject, out string errorMessage)
        {
            // validate if new point is .5 or .0

            if (inputObject.NewPoint % Decimal.One != (decimal)0.5 && inputObject.NewPoint % Decimal.One != Decimal.Zero)
            {
                errorMessage = String.Format("Point({0}) must be a mupltiple of 0.5.", new string[] { inputObject.NewPoint.ToString("0.00") });
                return(false);
            }

            if (inputObject.CurrentPoint + ALLOWABLE_POINT_CHANGE_IN_BACKPAY < inputObject.NewPoint || inputObject.CurrentPoint - ALLOWABLE_POINT_CHANGE_IN_BACKPAY > inputObject.NewPoint)
            {
                errorMessage = String.Format("Point change violation. New Point ({0}) is cannot be 0.5 point more / less than the Original Point({1})", new string[] { inputObject.NewPoint.ToString("0.00"), inputObject.CurrentPoint.ToString("0.00") });
                return(false);
            }

            if (inputObject.SchemeCode != "" && inputObject.Capacity != "" && inputObject.CurrentPoint >= 0)
            {
                DBFilter m_recurringFilter = new DBFilter();

                m_recurringFilter.add(new NullTerm("EmpRPEffTo"));
                m_recurringFilter.add(new Match("EmpID", inputObject.EmpID));

                string m_schemeCode = AppUtils.Encode(EEmpRecurringPayment.db.getField("SchemeCode"), inputObject.SchemeCode);
                string m_capacity   = AppUtils.Encode(EEmpRecurringPayment.db.getField("Capacity"), inputObject.Capacity);

                m_recurringFilter.add(new Match("SchemeCode", m_schemeCode));
                m_recurringFilter.add(new Match("Capacity", m_capacity));
                m_recurringFilter.add(new Match("Point", inputObject.CurrentPoint));

                DBFilter m_paymentTypeFilter = new DBFilter();
                m_paymentTypeFilter.add(new Match("PaymentTypeCode", "BASICSAL"));

                DBFilter m_paymentCodeFilter = new DBFilter();
                m_paymentCodeFilter.add(new IN("PaymentTypeID", "SELECT PaymentTypeID FROM PaymentType", m_paymentTypeFilter));

                m_recurringFilter.add(new IN("PayCodeID", "SELECT PaymentCodeID FROM PaymentCode", m_paymentCodeFilter));
                m_recurringFilter.add("EmpRPID", false);

                ArrayList m_recurringList = EEmpRecurringPayment.db.select(dbConn, m_recurringFilter);

                if (m_recurringList.Count > 0)  // recurring payment matched
                {
                    EEmpRecurringPayment m_recurringPayment = (EEmpRecurringPayment)m_recurringList[0];

                    // cross check if payscale is out of range
                    DBFilter m_payScaleFilter = new DBFilter();
                    m_payScaleFilter.add(new Match("SchemeCode", m_schemeCode));
                    m_payScaleFilter.add(new Match("Capacity", m_capacity));

                    ArrayList m_payScaleList = EPayScale.db.select(dbConn, m_payScaleFilter);
                    if (m_payScaleList.Count > 0)
                    {
                        EPayScale m_payScale = (EPayScale)m_payScaleList[0];
                        if (inputObject.NewPoint < m_payScale.FirstPoint || inputObject.NewPoint > m_payScale.LastPoint)
                        {
                            errorMessage = string.Format("New Point({0}) is out of range({1}-{2}) according to PayScale Setup.", new string[] { inputObject.NewPoint.ToString("0.00"), m_payScale.FirstPoint.ToString("0.00"), m_payScale.LastPoint.ToString("0.00") });
                            return(false);
                        }
                    }
                }
                else
                {
                    errorMessage = string.Format("Recurring Payment not matched. (Scheme Code={0}, Capacity={1}, Point={2})", new string[] { inputObject.SchemeCode, inputObject.Capacity, inputObject.CurrentPoint.ToString("0.00") });
                    return(false);
                }
            }
            else
            {
                errorMessage = string.Format("Recurring Payment not matched. (Scheme Code={0}, Capacity={1}, Point={2})", new string[] { inputObject.SchemeCode, inputObject.Capacity, inputObject.CurrentPoint.ToString("0.00") });
                return(false);
            }
            errorMessage = "";
            return(true);
        }
Ejemplo n.º 20
0
        public void GenerateDetailByEmpID()
        {
            DataTable empInfoTable = dataSet.Tables["EmpInfo"];
            DataTable dataTable    = dataSet.Tables["PaySlip"];

            foreach (EEmpPersonalInfo empInfo in EmpList)
            {
                string empDiv = string.Empty;
                string empDep = string.Empty;

                EEmpPersonalInfo.db.select(dbConn, empInfo);

                EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, empInfo.EmpDateOfJoin, empInfo.EmpID);
                if (empPos == null)
                {
                    empPos = new EEmpPositionInfo();
                }
                EPosition position = new EPosition();
                ECompany  company  = new ECompany();
                position.PositionID = empPos.PositionID;
                EPosition.db.select(dbConn, position);
                company.CompanyID = empPos.CompanyID;
                ECompany.db.select(dbConn, company);

                DBFilter emphierarchyFilter = new DBFilter();
                emphierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, emphierarchyFilter);
                foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                {
                    EHierarchyElement hElement = new EHierarchyElement();
                    hElement.HElementID = empHierarchy.HElementID;
                    if (EHierarchyElement.db.select(dbConn, hElement))
                    {
                        EHierarchyLevel hLevel = new EHierarchyLevel();
                        hLevel.HLevelID = hElement.HLevelID;
                        if (EHierarchyLevel.db.select(dbConn, hLevel))
                        {
                            if (hLevel.HLevelDesc.Equals("Division", StringComparison.CurrentCultureIgnoreCase) || hLevel.HLevelCode.Equals("DIV", StringComparison.CurrentCultureIgnoreCase))
                            {
                                empDiv = hElement.HElementDesc;
                            }
                        }
                    }
                }

                DBFilter basicSalaryRPFilter = new DBFilter();
                basicSalaryRPFilter.add(new Match("EmpID", empInfo.EmpID));
                basicSalaryRPFilter.add(new Match("EmpRPEffFr", "<=", empInfo.EmpDateOfJoin));

                OR orbasicSalaryRPToTerm = new OR();
                orbasicSalaryRPToTerm.add(new Match("EmpRPEffTo", ">=", empInfo.EmpDateOfJoin));
                orbasicSalaryRPToTerm.add(new NullTerm("EmpRPEffTo"));
                basicSalaryRPFilter.add(orbasicSalaryRPToTerm);

                DBFilter basicSalaryPaymentCodeFilter = new DBFilter();
                basicSalaryPaymentCodeFilter.add(new Match("PaymentTypeID", EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeID));

                basicSalaryRPFilter.add(new IN("PayCodeID", "Select PaymentCodeID from PaymentCode", basicSalaryPaymentCodeFilter));

                ArrayList recurringPayments = EEmpRecurringPayment.db.select(dbConn, basicSalaryRPFilter);


                EEmpRecurringPayment basicSalaryRP = new EEmpRecurringPayment();
                if (recurringPayments.Count > 0)
                {
                    basicSalaryRP = (EEmpRecurringPayment)recurringPayments[0];
                }


                DBFilter payPeriodFilter = new DBFilter();
                payPeriodFilter.add(new Match("PayPeriodFr", "<=", empInfo.EmpDateOfJoin));
                payPeriodFilter.add(new Match("PayPeriodTo", ">=", empInfo.EmpDateOfJoin));

                DBFilter empPayrollFilter = new DBFilter();
                empPayrollFilter.add(new Match("EmpID", empInfo.EmpID));
                empPayrollFilter.add(new IN("PayPeriodID", "Select PayPeriodID from PayrollPeriod", payPeriodFilter));

                string PayBatchInTerm = string.Empty;
                if (payBatchList != null)
                {
                    foreach (EPayrollBatch payrollBatch in payBatchList)
                    {
                        if (string.IsNullOrEmpty(PayBatchInTerm))
                        {
                            PayBatchInTerm = payrollBatch.PayBatchID.ToString();
                        }
                        else
                        {
                            PayBatchInTerm += "," + payrollBatch.PayBatchID.ToString();
                        }
                    }
                }
                if (!string.IsNullOrEmpty(PayBatchInTerm))
                {
                    empPayrollFilter.add(new IN("PayBatchID", PayBatchInTerm, null));
                }

                if (PayPeriodList != null)
                {
                    string payPeriodIDList = string.Empty;
                    foreach (EPayrollPeriod payPeriod in PayPeriodList)
                    {
                        if (string.IsNullOrEmpty(payPeriodIDList))
                        {
                            payPeriodIDList = payPeriod.PayPeriodID.ToString();
                        }
                        else
                        {
                            payPeriodIDList += "," + payPeriod.PayPeriodID.ToString();
                        }
                    }
                    if (!string.IsNullOrEmpty(payPeriodIDList))
                    {
                        empPayrollFilter.add(new IN("PayPeriodID", payPeriodIDList, null));
                    }
                }

                //  if ReportType.Unspecify, no filter is add (for backward compatibility with previous UI)
                if (reportType.Equals(ReportType.TrialRun))
                {
                    empPayrollFilter.add(new Match("EmpPayStatus", "=", "T"));
                }
                else if (reportType.Equals(ReportType.History))
                {
                    empPayrollFilter.add(new Match("EmpPayStatus", "<>", "T"));
                }

                IN inEmpPayroll = new IN("EmpPayrollID", "Select EmpPayrollID from EmpPayroll", empPayrollFilter);

                DBFilter paymentRecordFilter = new DBFilter();
                paymentRecordFilter.add(inEmpPayroll);
                paymentRecordFilter.add(new Match("PayRecStatus", "A"));
                paymentRecordFilter.add("PaymentCodeID", true);
                paymentRecordFilter.add("PayRecMethod", true);

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

                EPayrollBatch payBatch = null;

                DBFilter payBatchFilter = new DBFilter();
                payBatchFilter.add(new IN("PayBatchID", "Select PayBatchID from EmpPayroll", empPayrollFilter));
                if (!string.IsNullOrEmpty(PayBatchInTerm))
                {
                    payBatchFilter.add(new IN("PayBatchID", PayBatchInTerm, null));
                }
                payBatchFilter.add("PayBatchValueDate", false);

                ArrayList payBatchs = EPayrollBatch.db.select(dbConn, payBatchFilter);
                if (payBatchs.Count > 0)
                {
                    payBatch = (EPayrollBatch)payBatchs[0];
                }

                DataRow empInfoRow = empInfoTable.NewRow();
                empInfoRow["EmpID"]          = empInfo.EmpID;
                empInfoRow["EmpNo"]          = empInfo.EmpNo;
                empInfoRow["EmpName"]        = empInfo.EmpEngFullName;
                empInfoRow["EmpChineseName"] = empInfo.EmpChiFullName;
                empInfoRow["EmpHKID"]        = empInfo.EmpHKID;
                empInfoRow["EmpDateOfJoin"]  = empInfo.EmpDateOfJoin;

                empInfoRow["CompanyName"]  = company.CompanyName;
                empInfoRow["PositionDesc"] = position.PositionDesc;
                empInfoRow["BasicSalary"]  = basicSalaryRP.EmpRPAmount;
                if (payBatch != null)
                {
                    if (payBatch.PayBatchValueDate.Ticks != 0)
                    {
                        empInfoRow["ValueDate"] = payBatch.PayBatchValueDate;
                    }
                }
                if (empDep.Equals(string.Empty) && empDiv.Equals(string.Empty))
                {
                    empInfoRow["Department"] = empDiv;
                }
                else if (empDiv.Equals(string.Empty))
                {
                    empInfoRow["Department"] = empDep;
                }
                else if (empDep.Equals(string.Empty))
                {
                    empInfoRow["Department"] = empDiv;
                }
                else
                {
                    empInfoRow["Department"] = empDiv + " / " + empDep;
                }

                empInfoTable.Rows.Add(empInfoRow);

                GeneratePayrollData(empInfo.EmpID, paymentRecords);
            }
            DataRow[] allowanceRows = dataSet.Tables["PaySlip"].Select("PayAmount > 0", "PaymentCodeDisplaySeqNo");
            foreach (DataRow importRow in allowanceRows)
            {
                dataSet.Tables["PaySlip_Allowance"].ImportRow(importRow);
            }

            DataRow[] deductionRows = dataSet.Tables["PaySlip"].Select("PayAmount < 0", "PaymentCodeDisplaySeqNo");
            foreach (DataRow importRow in deductionRows)
            {
                dataSet.Tables["PaySlip_Deduction"].ImportRow(importRow);
            }
        }
Ejemplo n.º 21
0
    public bool Save()
    {
        EEmpRecurringPayment c = new EEmpRecurringPayment();

        Hashtable values = new Hashtable();

        binding.toValues(values);

        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        db.validate(errors, values);

        if (!errors.isEmpty())
        {
            return(false);
        }

        db.parse(values, c);

        if (c.EmpRPMethod.Equals("A"))
        {
            if (c.EmpAccID == 0)
            {
                EEmpBankAccount bankAccount = EEmpBankAccount.GetDefaultBankAccount(dbConn, c.EmpID);
                if (bankAccount != null)
                {
                    //c.EmpAccID = bankAccount.EmpBankAccountID;
                }
                else
                {
                    errors.addError("EmpAccID", HROne.Translation.PageErrorMessage.ERROR_ACCOUNT_REQUIRED);
                }
            }
        }
        else
        {
            c.EmpAccID = 0;
        }

        AND andTerms = new AND();

        andTerms.add(new Match("EmpRPID", "<>", c.EmpRPID));
        andTerms.add(new Match("EmpRPEffFr", "<", c.EmpRPEffFr));
        andTerms.add(new Match("PayCodeID", c.PayCodeID));

        EEmpRecurringPayment lastObj = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, db, "EmpRPEffFr", c.EmpID, andTerms);
        //if (CurID < 0)
        //{
        //    if (lastObj != null && c.EmpRPEffFr <= lastObj.EmpRPEffFr)
        //        errors.addError("EmpRPEffFr", HROne.Translation.SystemMessage.ERROR_DATE_FROM_OVERLAP);
        //}

        DBFilter filter = new DBFilter();

        filter.add(new Match("EmpID", c.EmpID));
        filter.add(new Match("PayCodeID", c.PayCodeID));
        filter.add(new Match("EmpRPID", "<>", c.EmpRPID));
        OR  or = new OR();
        AND and;

        and = new AND();
        and.add(new Match("EmpRPEffFr", "<=", c.EmpRPEffFr));
        and.add(new Match("EmpRPEffTo", ">=", c.EmpRPEffFr));
        or.add(and);

        and = new AND();
        and.add(new NullTerm("EmpRPEffTo"));
        and.add(new Match("EmpRPEffFr", "=", c.EmpRPEffFr));
        or.add(and);

        if (c.EmpRPEffTo > DateTime.MinValue)
        {
            and = new AND();
            and.add(new Match("EmpRPEffFr", "<=", c.EmpRPEffTo));
            and.add(new Match("EmpRPEffTo", ">=", c.EmpRPEffTo));
            or.add(and);

            and = new AND();
            and.add(new Match("EmpRPEffFr", ">=", c.EmpRPEffFr));
            and.add(new Match("EmpRPEffFr", "<=", c.EmpRPEffTo));
            or.add(and);
        }

        filter.add(or);
        if (db.count(dbConn, filter) > 0)
        {
            errors.addError(HROne.Translation.PageErrorMessage.ERROR_PAY_EFF_DATE_OVERLAP);
        }
        if (!errors.isEmpty())
        {
            return(false);
        }

        c.SchemeCode = null;
        c.Capacity   = null;
        c.Point      = 0;

        if (SchemeCode.SelectedIndex > 0)
        {
            c.SchemeCode = SchemeCode.Text;
            c.Capacity   = CapacitySelect.Text;

            if (PointSelect.Text != "")
            {
                c.Point = Decimal.Parse(PointSelect.Text);
            }
        }

        WebUtils.StartFunction(Session, FUNCTION_CODE, c.EmpID);
        if (CurrentEmpRPID <= 0)
        {
            //            Utils.MarkCreate(Session, c);

            db.insert(dbConn, c);
            CurrentEmpRPID = c.EmpRPID;
            //            url = Utils.BuildURL(-1, CurID);
            if (lastObj != null && lastObj.EmpRPEffFr < c.EmpRPEffFr)
            {
                if (lastObj.EmpRPEffTo < lastObj.EmpRPEffFr)
                {
                    lastObj.EmpRPEffTo = c.EmpRPEffFr.AddDays(-1);
                    db.update(dbConn, lastObj);
                }
            }
        }
        else
        {
            //            Utils.Mark(Session, c);
            db.update(dbConn, c);
        }
        WebUtils.EndFunction(dbConn);

        return(true);
    }