Ejemplo n.º 1
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        ArrayList list = new ArrayList();

        foreach (RepeaterItem i in Repeater.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("ItemSelect");
            if (cb.Checked)
            {
                EEmpPayroll o = (EEmpPayroll)EEmpPayroll.db.createObject();
                WebFormUtils.GetKeys(EEmpPayroll.db, o, cb);
                list.Add(o);
            }
        }

        DateTime processDateTime = AppUtils.ServerDateTime();


        if (list.Count > 0)
        {
            int UserID = WebUtils.GetCurUser(Session).UserID;


            EPayrollPeriod payPeriod = new EPayrollPeriod();
            payPeriod.PayPeriodID          = CurPayPeriodID;
            payPeriod.PayPeriodStatus      = "C";
            payPeriod.PayPeriodConfirmDate = processDateTime;
            payPeriod.PayPeriodConfirmBy   = UserID;
            EPayrollPeriod.db.update(dbConn, payPeriod);

            EPayrollBatch payBatch = new EPayrollBatch();
            payBatch.PayBatchConfirmDate = processDateTime;
            payBatch.PayBatchRemark      = txtRemark.Text;
            EPayrollBatch.db.insert(dbConn, payBatch);

            PayrollProcess payrollProcess = new PayrollProcess(dbConn);
            WebUtils.StartFunction(Session, FUNCTION_CODE, 0, true);
            foreach (EEmpPayroll o in list)
            {
                if (EEmpPayroll.db.select(dbConn, o))
                {
                    AppUtils.StartChildFunction(dbConn, o.EmpID);
                    payrollProcess.PayrollConfirm(o, payBatch.PayBatchID, UserID);
                    AppUtils.EndChildFunction(dbConn);
                }
            }
            WebUtils.EndFunction(dbConn);
            PageErrors.getErrors(db, Page).addError("Complete");
            txtRemark.Text = string.Empty;
            //Response.Write("<script>alert('Completed'); </script>");
        }
        loadObject();
        loadData(info, EEmpPayroll.db, Repeater);
    }
    protected void payBatchRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        HROne.Common.WebUtility.WebControlsLocalization(Session, e.Item.Controls);
        DataRowView row = (DataRowView)e.Item.DataItem;
        CheckBox    cb  = (CheckBox)e.Item.FindControl("ItemSelect");

        if (PayrollBatchCheckBoxDefaultCheckedOption == PayrollBatchCheckBoxDefaultCheckedOptionEnum.All)
        {
            cb.Checked = true;
        }
        else
        {
            cb.Checked = false;
        }

        if (PayrollStatus.SelectedValue.Equals("C"))
        {
            EPayrollBatch obj = new EPayrollBatch();
            EPayrollBatch.db.toObject(row.Row, obj);
            if (EPayrollBatch.db.select(dbConn, obj))
            {
                Hashtable values = new Hashtable();
                EPayrollBatch.db.populate(obj, values);

                WebFormUtils.LoadKeys(EPayrollBatch.db, row, cb);
                Binding ebinding = new Binding(dbConn, EPayrollBatch.db);
                ebinding.add(new BlankZeroLabelVLBinder(EPayrollBatch.db, (Label)e.Item.FindControl("PayBatchFileGenBy"), EUser.VLUserName));
                ebinding.init(Request, Session);
                ebinding.toControl(values);
                if (PayrollBatchCheckBoxDefaultCheckedOption == PayrollBatchCheckBoxDefaultCheckedOptionEnum.ReleasePaySlipToESS)
                {
                    cb.Checked = obj.PayBatchIsESSPaySlipRelease;
                }
                else if (row.Row.IsNull("PayBatchFileGenDate") && PayrollBatchCheckBoxDefaultCheckedOption == PayrollBatchCheckBoxDefaultCheckedOptionEnum.ExcludeBankFileGenerated)
                {
                    cb.Checked = true;
                }
            }
        }
        else if (PayrollStatus.SelectedValue.Equals("T"))
        {
            WebFormUtils.LoadKeys(EPayrollPeriod.db, row, cb);
        }

        //if (row["PayBatchFileGenDate"] != DBNull.Value)
        //    cb.Checked = false;
    }
 public void SaveAsReleaseESSPaySlip()
 {
     foreach (RepeaterItem i in payBatchRepeater.Items)
     {
         CheckBox      cb = (CheckBox)i.FindControl("ItemSelect");
         EPayrollBatch o  = new EPayrollBatch();
         WebFormUtils.GetKeys(EPayrollBatch.db, o, cb);
         if (EPayrollBatch.db.select(dbConn, o))
         {
             if (o.PayBatchIsESSPaySlipRelease != cb.Checked)
             {
                 o.PayBatchIsESSPaySlipRelease = cb.Checked;
                 EPayrollBatch.db.update(dbConn, o);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public virtual void LoadBankFileDetail(ArrayList PayrollBatchList, ArrayList EmpList)
        {
            BankFileDetails.Clear();
            m_TotalAmount = 0;

            //  Move autoPayList out of the EmpList loop for sharing bank account feature between roles
            Dictionary <EmpBankTransactionBreakDownKey, GenericBankFileDetail> autoPayList = new Dictionary <EmpBankTransactionBreakDownKey, GenericBankFileDetail>();
            List <int> PayPeriodIDList = new List <int>();

            foreach (EEmpPersonalInfo empInfo in EmpList)
            {
                Dictionary <EmpBankTransactionBreakDownKey, GenericBankFileDetail> chequePaymentList = new Dictionary <EmpBankTransactionBreakDownKey, GenericBankFileDetail>();

                DBFilter empPayrollFilter = new DBFilter();
                empPayrollFilter.add(new Match("EmpID", empInfo.EmpID));
                OR orPayrollBatch = new OR();
                foreach (EPayrollBatch payBatch in PayrollBatchList)
                {
                    orPayrollBatch.add(new Match("PayBatchID", payBatch.PayBatchID));
                }
                empPayrollFilter.add(orPayrollBatch);

                ArrayList empPayrollList = EEmpPayroll.db.select(dbConn, empPayrollFilter);

                foreach (EEmpPayroll empPayroll in empPayrollList)
                {
                    if (!PayPeriodIDList.Contains(empPayroll.PayPeriodID))
                    {
                        PayPeriodIDList.Add(empPayroll.PayPeriodID);
                    }

                    if (!m_ValueDate.Ticks.Equals(0))
                    {
                        empPayroll.EmpPayValueDate = m_ValueDate;
                    }
                    if (empPayroll.EmpPayValueDate.Ticks.Equals(0))
                    {
                        EPayrollBatch payBatch = new EPayrollBatch();
                        payBatch.PayBatchID = empPayroll.PayBatchID;
                        if (EPayrollBatch.db.select(dbConn, payBatch))
                        {
                            empPayroll.EmpPayValueDate = payBatch.PayBatchValueDate;
                        }
                    }

                    DBFilter paymentRecordFilter = new DBFilter();
                    paymentRecordFilter.add(new Match("EmpPayrollID", empPayroll.EmpPayrollID));
                    OR orPaymentMethodTerm = new OR();
                    orPaymentMethodTerm.add(new Match("PayRecMethod", "A"));
                    if (m_IsGenerateChequePayment)
                    {
                        orPaymentMethodTerm.add(new Match("PayRecMethod", "Q"));
                    }
                    paymentRecordFilter.add(orPaymentMethodTerm);

                    ArrayList paymentRecordList = EPaymentRecord.db.select(dbConn, paymentRecordFilter);
                    foreach (EPaymentRecord paymentRecord in paymentRecordList)
                    {
                        if (paymentRecord.PayRecMethod.Equals("A"))
                        {
                            EEmpBankAccount empAcc = new EEmpBankAccount();
                            empAcc.EmpBankAccountID = paymentRecord.EmpAccID;
                            if (!EEmpBankAccount.db.select(dbConn, empAcc))
                            {
                                empAcc = EEmpBankAccount.GetDefaultBankAccount(dbConn, empInfo.EmpID);
                                if (empAcc == null)
                                {
                                    EEmpPersonalInfo.db.select(dbConn, empInfo);
                                    throw new InvalidEEBankAccountException(empInfo.EmpNo, empInfo.EmpEngFullName);
                                }
                            }
                            EmpBankTransactionBreakDownKey key = new EmpBankTransactionBreakDownKey(empAcc.EmpBankAccountID, empPayroll.EmpPayValueDate);

                            GenericBankFileDetail BankFileDetail;
                            if (autoPayList.ContainsKey(key))
                            {
                                BankFileDetail = autoPayList[key];
                            }
                            else
                            {
                                BankFileDetail = CreateBankFileDetail(empAcc.EmpID);
                                BankFileDetail.EmpBankAccountHolderName = empAcc.EmpBankAccountHolderName.Trim();
                                BankFileDetail.BankCode   = empAcc.EmpBankCode;
                                BankFileDetail.BranchCode = empAcc.EmpBranchCode;
                                BankFileDetail.AccountNo  = empAcc.EmpAccountNo;
                                BankFileDetail.ValueDate  = empPayroll.EmpPayValueDate;
                                autoPayList.Add(key, BankFileDetail);
                            }
                            BankFileDetail.Amount += paymentRecord.PayRecActAmount;
                            BankFileDetail.Amount  = Math.Round(BankFileDetail.Amount, 2, MidpointRounding.AwayFromZero);
                            m_TotalAmount         += paymentRecord.PayRecActAmount;
                        }
                        else if (paymentRecord.PayRecMethod.Equals("Q") && m_IsGenerateChequePayment)
                        {
                            EmpBankTransactionBreakDownKey key = new EmpBankTransactionBreakDownKey(0, empPayroll.EmpPayValueDate);
                            GenericBankFileDetail          BankFileDetail;
                            if (chequePaymentList.ContainsKey(key))
                            {
                                BankFileDetail = chequePaymentList[key];
                            }
                            else
                            {
                                BankFileDetail                 = CreateBankFileDetail(empInfo.EmpID);
                                BankFileDetail.ValueDate       = empPayroll.EmpPayValueDate;
                                BankFileDetail.IsChequePayment = true;
                                chequePaymentList.Add(key, BankFileDetail);
                            }
                            BankFileDetail.Amount += paymentRecord.PayRecActAmount;
                            BankFileDetail.Amount  = Math.Round(BankFileDetail.Amount, 2, MidpointRounding.AwayFromZero);
                            m_TotalAmount         += paymentRecord.PayRecActAmount;
                        }
                    }
                }

                BankFileDetails.AddRange(chequePaymentList.Values);
                chequePaymentList.Clear();
            }
            BankFileDetails.AddRange(autoPayList.Values);
            autoPayList.Clear();

            List <GenericBankFileDetail> NegativeBankFileDetailList = new List <GenericBankFileDetail>();
            List <GenericBankFileDetail> zeroAmountBankFileDetails  = new List <GenericBankFileDetail>();

            foreach (GenericBankFileDetail bankFileDetail in BankFileDetails)
            {
                if (bankFileDetail != null)
                {
                    if (bankFileDetail.Amount < 0)
                    {
                        NegativeBankFileDetailList.Add(bankFileDetail);
                    }
                    else if (Math.Abs(bankFileDetail.Amount) <= 0.005)
                    {
                        zeroAmountBankFileDetails.Add(bankFileDetail);
                    }
                }
            }
            foreach (GenericBankFileDetail bankFileDetail in zeroAmountBankFileDetails)
            {
                BankFileDetails.Remove(bankFileDetail);
                ZeroBankFileDetails.Add(bankFileDetail);
            }
            foreach (int PayPeriodID in PayPeriodIDList)
            {
                EPayrollPeriod payPeriod = new EPayrollPeriod();
                payPeriod.PayPeriodID = PayPeriodID;
                if (EPayrollPeriod.db.select(dbConn, payPeriod))
                {
                    if (m_PayPeriodFr.Ticks.Equals(0) || m_PayPeriodFr > payPeriod.PayPeriodFr)
                    {
                        m_PayPeriodFr = payPeriod.PayPeriodFr;
                    }
                    if (m_PayPeriodTo.Ticks.Equals(0) || m_PayPeriodTo < payPeriod.PayPeriodTo)
                    {
                        m_PayPeriodTo = payPeriod.PayPeriodTo;
                    }
                }
            }
            if (NegativeBankFileDetailList.Count > 0)
            {
                throw new NegativeAmountException(new ArrayList(NegativeBankFileDetailList));
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!WebUtils.CheckAccess(Response, Session, TRIALRUN_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite))
        {
            return;
        }
        if (!WebUtils.CheckAccess(Response, Session, CONFIRM_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite))
        {
            return;
        }
        if (!WebUtils.CheckAccess(Response, Session, PROCESSEND_FUNCTION_CODE, WebUtils.AccessLevel.ReadWrite))
        {
            return;
        }

        DateTime dtPayPeriodFr = new DateTime(long.Parse(DecryptedRequest["PayPeriodFr"]));
        DateTime dtPayPeriodTo = new DateTime(long.Parse(DecryptedRequest["PayPeriodTo"]));

        DateTime NextPayPeriodFr   = dtPayPeriodTo.AddDays(1);
        long     nextPayPeriodTick = 0;

        if (long.TryParse(DecryptedRequest["NextPayPeriodFr"], out nextPayPeriodTick))
        {
            NextPayPeriodFr = new DateTime(nextPayPeriodTick);
        }

        int PayBatchID = 0;

        if (!int.TryParse(DecryptedRequest["PayBatchID"], out PayBatchID))
        {
            PayBatchID = 0;
        }

        string[] payGroupStringList         = DecryptedRequest["PayGroupIDList"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
        int      currentSelectedPayGroupSeq = 0;

        if (!int.TryParse(DecryptedRequest["SelectedPayGroupSeq"], out currentSelectedPayGroupSeq))
        {
            currentSelectedPayGroupSeq = 0;
        }
        else
        {
            if (currentSelectedPayGroupSeq > payGroupStringList.GetUpperBound(0))
            {
                currentSelectedPayGroupSeq = 0;
                dtPayPeriodFr   = NextPayPeriodFr;
                NextPayPeriodFr = dtPayPeriodTo.AddDays(1);
                PayBatchID      = 0;
            }
        }

        bool SkipRecurringPaymentProcess       = DecryptedRequest["SkipRecurringPaymentProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
        bool SkipClaimsAndDeductionsProcess    = DecryptedRequest["SkipClaimsAndDeductionsProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
        bool SkipYearEndBonusProcess           = DecryptedRequest["SkipYearEndBonusProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase);
        bool SkipAdditionalRenumerationProcess = DecryptedRequest["SkipAdditionalRenumerationProcess"].Equals("Yes", StringComparison.CurrentCultureIgnoreCase);

        if (dtPayPeriodFr <= dtPayPeriodTo)
        {
            EPayrollPeriod currentPayPeriod   = null;
            int            currentPayPeriodID = 0;
            if (!int.TryParse(DecryptedRequest["PayPeriodID"], out currentPayPeriodID))
            {
                DBFilter payPeriodFilter = new DBFilter();
                payPeriodFilter.add(new Match("PayGroupID", payGroupStringList[currentSelectedPayGroupSeq]));
                payPeriodFilter.add(new Match("PayPeriodFr", "<=", dtPayPeriodFr));
                payPeriodFilter.add(new Match("PayPeriodTo", ">=", dtPayPeriodFr));
                //  Skip checking payperiodstatus since the next step will check if payroll is being processed
                //payPeriodFilter.add(new Match("PayPeriodStatus", "<>", EPayrollPeriod.PAYPERIOD_STATUS_PROCESSEND_FLAG));
                ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter);
                if (payPeriodList.Count > 0)
                {
                    currentPayPeriod   = ((EPayrollPeriod)payPeriodList[0]);
                    currentPayPeriodID = currentPayPeriod.PayPeriodID;
                    if (NextPayPeriodFr > currentPayPeriod.PayPeriodTo.AddDays(1))
                    {
                        NextPayPeriodFr = currentPayPeriod.PayPeriodTo.AddDays(1);
                    }
                }
            }
            else
            {
                currentPayPeriod = new EPayrollPeriod();
                currentPayPeriod.LoadDBObject(dbConn, currentPayPeriodID);
            }
            int intTotal;
            if (int.TryParse(DecryptedRequest["Total"], out intTotal))
            {
                intTotal = 0;
            }
            if (Session["PayrollContinuousProcess_EmpList"] == null)
            {
                DBFilter empPayrollCountFilter = new DBFilter();
                empPayrollCountFilter.add(new Match("PayPeriodID", currentPayPeriodID));

                if (EEmpPayroll.db.count(dbConn, empPayrollCountFilter) > 0)
                {
                    lblProgressMessage.Text = "Payroll has been processed manually. Please complete this payroll cycle manually.";
                    return;
                }

                EPayrollPeriod payPeriod = new EPayrollPeriod();
                payPeriod.PayPeriodID          = currentPayPeriodID;
                payPeriod.PayPeriodStatus      = "C";
                payPeriod.PayPeriodConfirmDate = AppUtils.ServerDateTime();
                payPeriod.PayPeriodConfirmBy   = WebUtils.GetCurUser(Session).UserID;
                EPayrollPeriod.db.update(dbConn, payPeriod);

                EPayrollBatch payBatch = new EPayrollBatch();
                payBatch.PayBatchConfirmDate = AppUtils.ServerDateTime();
                EPayrollBatch.db.insert(dbConn, payBatch);

                PayBatchID = payBatch.PayBatchID;


                DBFilter filter = new DBFilter();

                IN inTerm = new IN("EmpID", "Select epi.EmpID from [EmpPositionInfo] epi, [PayrollPeriod] pp ", filter);

                filter.add(new MatchField("EmpID", "epi.EmpID"));
                filter.add(new MatchField("epi.PayGroupID", "pp.PayGroupID"));
                filter.add(new MatchField("epi.EmpPosEffFr", "<=", "pp.PayPeriodTo"));
                filter.add(new Match("pp.PayPeriodID", currentPayPeriodID));
                filter.add(WebUtils.AddRankFilter(Session, "EmpID", true));

                OR orFilter = new OR();
                orFilter.add(new MatchField("epi.EmpPosEffTo", ">=", "pp.PayPeriodFr"));
                orFilter.add(new NullTerm("epi.EmpPosEffTo"));

                filter.add(orFilter);

                filter.add(new MatchField("EmpDateOfJoin", "<=", "pp.PayPeriodTo "));

                OR otherConstraint = new OR();

                OR orIncludeEmployeeTermination = new OR();

                DBFilter empTerminationFilter = new DBFilter();
                empTerminationFilter.add(new MatchField("et.EmpTermLastDate", ">=", "pp.PayPeriodFr"));
                orIncludeEmployeeTermination.add(new IN(" empid", "Select et.empid from " + EEmpTermination.db.dbclass.tableName + " et ", empTerminationFilter));

                orIncludeEmployeeTermination.add(new IN("NOT empid", "Select et.empid from " + EEmpTermination.db.dbclass.tableName + " et ", new DBFilter()));

                otherConstraint.add(orIncludeEmployeeTermination);

                //OR orIncludeBackPay = new OR();
                DBFilter empCNDFilter = new DBFilter();
                empCNDFilter.add(new MatchField("CNDEffDate", "<=", "pp.PayperiodTo"));
                empCNDFilter.add(new MatchField("CNDEffDate", ">=", "epi.EmpPosEffFr"));

                OR orCNDPos = new OR();
                orCNDPos.add(new MatchField("CNDEffDate", "<=", "epi.EmpPosEffTo"));
                orCNDPos.add(new NullTerm("epi.EmpPosEffTo"));

                empCNDFilter.add(orCNDPos);
                OR orCNDPayRecID = new OR();
                orCNDPayRecID.add(new Match("PayRecID", 0));
                orCNDPayRecID.add(new NullTerm("PayRecID"));
                empCNDFilter.add(orCNDPayRecID);
                otherConstraint.add(new IN(" empid", "Select cnd.empid from " + EClaimsAndDeductions.db.dbclass.tableName + " cnd ", empCNDFilter));
                //otherConstraint.add(orIncludeBackPay);

                filter.add(otherConstraint);

                DBFilter resultFilter = new DBFilter();
                resultFilter.add(inTerm);
                ArrayList empList = EEmpPersonalInfo.db.select(dbConn, resultFilter);
                Session["PayrollContinuousProcess_EmpList"] = empList;
                intTotal = empList.Count;
            }


            ArrayList list = (ArrayList)Session["PayrollContinuousProcess_EmpList"];
            if (list.Count > 0)
            {
                //string[] strEmpIDListArray;
                //int intProgress = 0;

                //strEmpIDListArray = strEmpIDList.Split(new char[] { '_' });

                //intProgress = 0;
                DateTime dtStartTime = AppUtils.ServerDateTime();
                int      UserID      = WebUtils.GetCurUser(Session).UserID;

                HROne.Payroll.PayrollProcess payrollProcess = new HROne.Payroll.PayrollProcess(dbConn);

                while (AppUtils.ServerDateTime().Subtract(dtStartTime).Seconds < 30 && list.Count > 0)
                {
                    EEmpPersonalInfo empInfo = (EEmpPersonalInfo)list[0];

                    //int intEmpID;
                    //if (int.TryParse(strEmpIDListArray[intProgress], out intEmpID))
                    //{
                    DBFilter filter = new DBFilter();
                    filter.add(new Match("EmpID", empInfo.EmpID));
                    filter.add(WebUtils.AddRankFilter(new Page().Session, "EmpID", true));
                    if (EEmpPersonalInfo.db.count(dbConn, filter) > 0)
                    {
                        bool ActualRecurringPaymentProcess = !SkipRecurringPaymentProcess;
                        bool ActualYearEndBonusProcess     = !SkipYearEndBonusProcess;

                        EEmpTermination empTerm = EEmpTermination.GetObjectByEmpID(dbConn, empInfo.EmpID);
                        if (empTerm != null)
                        {
                            if (empTerm.EmpTermLastDate < dtPayPeriodFr)
                            {
                                ActualRecurringPaymentProcess = false;
                                ActualYearEndBonusProcess     = false;
                            }
                        }
                        WebUtils.StartFunction(Session, CONFIRM_FUNCTION_CODE, empInfo.EmpID, false);
                        payrollProcess.PayrollConfirm(payrollProcess.PayrollTrialRun(currentPayPeriodID, empInfo.EmpID, ActualRecurringPaymentProcess, !SkipClaimsAndDeductionsProcess, !SkipAdditionalRenumerationProcess, ActualYearEndBonusProcess, false, UserID), PayBatchID, UserID);
                        WebUtils.EndFunction(dbConn);
                    }
                    //}
                    //intProgress++;
                    //if (intProgress == strEmpIDListArray.GetLength(0))
                    //    break;
                    list.Remove(empInfo);
                }
            }
            lblProgress.Text = (intTotal - list.Count).ToString() + " of " + intTotal.ToString();
            if (list.Count == 0)
            {
                Session.Remove("PayrollContinuousProcess_EmpList");

                EPayrollPeriod payPeriod = new EPayrollPeriod();
                payPeriod.PayPeriodID = currentPayPeriodID;
                EPayrollPeriod.db.select(dbConn, payPeriod);
                HROne.Payroll.PayrollProcess payrollProcess = new HROne.Payroll.PayrollProcess(dbConn);
                WebUtils.StartFunction(Session, PROCESSEND_FUNCTION_CODE, false);
                payrollProcess.PayrollProcessEnd(payPeriod.PayPeriodID, WebUtils.GetCurUser(Session).UserID);
                payrollProcess.GenerateNextPayrollPeriod(payPeriod.PayGroupID);
                WebUtils.EndFunction(dbConn);

                currentSelectedPayGroupSeq++;
                string url = Request.Url.AbsolutePath + "?PayGroupIDList=" + string.Join("|", payGroupStringList)
                             + "&PayPeriodFr=" + dtPayPeriodFr.Ticks
                             + "&PayPeriodTo=" + dtPayPeriodTo.Ticks
                             + "&NextPayPeriodFr=" + NextPayPeriodFr.Ticks
                             + "&SelectedPayGroupSeq=" + currentSelectedPayGroupSeq
                             + "&SkipRecurringPaymentProcess=" + (SkipRecurringPaymentProcess ? "Yes" : "No")
                             + "&SkipClaimsAndDeductionsProcess=" + (SkipClaimsAndDeductionsProcess ? "Yes" : "No")
                             + "&SkipYearEndBonusProcess=" + (SkipYearEndBonusProcess ? "Yes" : "No")
                             + "&SkipAdditionalRenumerationProcess=" + (SkipAdditionalRenumerationProcess ? "Yes" : "No")
                ;
                WebUtils.RegisterRedirectJavaScript(this, url, 500);
                //payPeriod = HROne.Payroll.PayrollProcess.GenerateNextPayrollPeriod(payPeriod.PayGroupID);

                //noOfCycleLeft--;

                //if (noOfCycleLeft > 0)
                //{
                //    if (payPeriod != null)
                //    {
                //        Response.Write(@"<script language='javascript'>");
                //        Response.Write(@"setTimeout('Redirect()',500);");
                //        Response.Write(@"function Redirect()");
                //        Response.Write(@"{");
                //        Response.Write(@"window.location = 'Payroll_ProcessContinuous_Process.aspx?"
                //            + "PayPeriodID=" + payPeriod.PayPeriodID
                //            + "&PayBatchID=" + 0
                //            + "&NoOfCycleLeft=" + noOfCycleLeft
                //            + "&Total=" + 0
                //            //+ "&EmpID=" + strRemainder
                //            + "';");
                //        Response.Write(@"}");
                //        Response.Write(@"</script>");
                //    }
                //}
            }
            else
            {
                string url = Request.Url.AbsolutePath + "?PayGroupIDList=" + string.Join("|", payGroupStringList)
                             + "&PayPeriodFr=" + dtPayPeriodFr.Ticks
                             + "&PayPeriodTo=" + dtPayPeriodTo.Ticks
                             + "&PayPeriodID=" + currentPayPeriodID
                             + "&PayBatchID=" + PayBatchID
                             + "&Total=" + intTotal
                             + "&NextPayPeriodFr=" + NextPayPeriodFr.Ticks
                             + "&SelectedPayGroupSeq=" + currentSelectedPayGroupSeq
                             + "&SkipRecurringPaymentProcess=" + (SkipRecurringPaymentProcess ? "Yes" : "No")
                             + "&SkipClaimsAndDeductionsProcess=" + (SkipClaimsAndDeductionsProcess ? "Yes" : "No")
                             + "&SkipYearEndBonusProcess=" + (SkipYearEndBonusProcess ? "Yes" : "No")
                             + "&SkipAdditionalRenumerationProcess=" + (SkipAdditionalRenumerationProcess ? "Yes" : "No")
                ;
                WebUtils.RegisterRedirectJavaScript(this, url, 500);
            }

            EPayrollGroup payGroup = new EPayrollGroup();
            payGroup.LoadDBObject(dbConn, currentPayPeriod.PayGroupID);
            lblProgressMessage.Text = "Payroll process is in progress (" + payGroup.PayGroupCode + ":" + currentPayPeriod.PayPeriodFr.ToString("yyyy-MM-dd") + " To " + currentPayPeriod.PayPeriodTo.ToString("yyyy-MM-dd") + ")";
        }
        else
        {
            lblProgressMessage.Text = "Payroll process is completed";
        }
        HROne.Common.WebUtility.WebControlsLocalization(this, this.Controls);
    }
        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);
            }
        }
Ejemplo n.º 8
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        ArrayList empList      = new ArrayList();
        ArrayList payBatchList = new ArrayList();

        foreach (RepeaterItem i in empRepeater.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("ItemSelect");
            if (cb.Checked)
            {
                EEmpPersonalInfo o = (EEmpPersonalInfo)EEmpPersonalInfo.db.createObject();
                WebFormUtils.GetKeys(EEmpPersonalInfo.db, o, cb);
                empList.Add(o);
            }
        }
        foreach (RepeaterItem i in payBatchRepeater.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("ItemSelect");
            if (cb.Checked)
            {
                EPayrollBatch o = (EPayrollBatch)EPayrollBatch.db.createObject();
                WebFormUtils.GetKeys(EPayrollBatch.db, o, cb);
                payBatchList.Add(o);
            }
        }

        //string strEmpIDList = string.Empty;
        //string strPayBatchIDList = string.Empty;

        if (empList.Count > 0 && payBatchList.Count > 0)
        {
            //foreach (EEmpPersonalInfo o in empList)
            //{
            //    if (strEmpIDList == string.Empty)
            //        strEmpIDList = o.EmpID.ToString();
            //    else
            //        strEmpIDList += "_" + o.EmpID.ToString();

            //}
            //foreach (EPayrollBatch  o in payBatchList)
            //{
            //    if (strPayBatchIDList == string.Empty)
            //        strPayBatchIDList = o.PayBatchID.ToString();
            //    else
            //        strPayBatchIDList += "_" + o.PayBatchID.ToString();

            //}
        }
        else
        {
            errors.addError("Employee or Payroll Batch not selected");
        }

        if (errors.isEmpty())
        {
            HROne.Reports.Payroll.NetPaymentListByPaymentMethodProcess rpt = new HROne.Reports.Payroll.NetPaymentListByPaymentMethodProcess(dbConn, empList, payBatchList, chkAutoPay.Checked, chkCheque.Checked, chkCash.Checked, chkOthers.Checked);

            string reportFileName = WebUtils.GetLocalizedReportFile(Server.MapPath("~/Report_Payroll_NetPaymentListByPaymentMethod.rpt"));

            WebUtils.ReportExport(dbConn, user, errors, lblReportHeader.Text, Response, rpt, reportFileName, ((Button)sender).CommandArgument, "NetPaymentList", true);
        }
    }
Ejemplo n.º 9
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.º 10
0
        private void GeneratePayrollData(int PaySlipID, ArrayList paymentRecords, out DateTime LastValueDate)
        {
            LastValueDate = new DateTime();
            DataSet.Payroll_PaySlip.PaySlipRow row = null;
            foreach (EPaymentRecord paymentRecord in paymentRecords)
            {
                string paymentMethod = string.Empty;
                if (paymentRecord.PayRecMethod.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                {
                    paymentMethod = "Autopay";
                }
                else if (paymentRecord.PayRecMethod.Equals("Q", StringComparison.CurrentCultureIgnoreCase))
                {
                    paymentMethod = "Cheque";
                }
                else if (paymentRecord.PayRecMethod.Equals("C", StringComparison.CurrentCultureIgnoreCase))
                {
                    paymentMethod = "Cash";
                }
                else if (paymentRecord.PayRecMethod.Equals("O", StringComparison.CurrentCultureIgnoreCase))
                {
                    paymentMethod = "Others";
                }
                else
                {
                    paymentMethod = paymentRecord.PayRecMethod;
                }


                EPaymentCode paymentCode = new EPaymentCode();
                paymentCode.PaymentCodeID = paymentRecord.PaymentCodeID;
                EPaymentCode.db.select(dbConn, paymentCode);

                DateTime    valueDate  = new DateTime();
                EEmpPayroll empPayroll = new EEmpPayroll();
                empPayroll.EmpPayrollID = paymentRecord.EmpPayrollID;
                if (EEmpPayroll.db.select(dbConn, empPayroll))
                {
                    EPayrollBatch payBatch = new EPayrollBatch();
                    payBatch.PayBatchID = empPayroll.PayBatchID;
                    if (EPayrollBatch.db.select(dbConn, payBatch))
                    {
                        if (!payBatch.PayBatchValueDate.Ticks.Equals(0))
                        {
                            valueDate = payBatch.PayBatchValueDate;
                        }
                    }
                    if (!empPayroll.EmpPayValueDate.Ticks.Equals(0))
                    {
                        if (valueDate.Ticks.Equals(0))
                        {
                            valueDate = empPayroll.EmpPayValueDate;
                        }
                        else
                        {
                            valueDate = empPayroll.EmpPayValueDate > valueDate ? empPayroll.EmpPayValueDate : valueDate;
                        }
                    }
                }

                //  Hide payment if payment code is chosen for hidden under payslip
                if (!this.reportType.Equals(ReportType.PaySlip) || !paymentCode.PaymentCodeHideInPaySlip)
                {
                    //                    string paymentCodeFullName = paymentCode.PaymentCode + " - " + paymentCode.PaymentCodeDesc;
                    if (row == null)
                    {
                        row = dataSet.PaySlip.NewPaySlipRow();
                    }
                    else if (!(row.EmpID == PaySlipID && row.PayMethod == paymentMethod && row.PaymentCode == paymentCode.PaymentCode && (valueDate.Equals(row.ValueDate) || !this.reportType.Equals(ReportType.PaySlip))))
                    {
                        if (row.ValueDate.Ticks.Equals(0))
                        {
                            row.SetValueDateNull();
                        }
                        dataSet.PaySlip.Rows.Add(row);
                        row = dataSet.PaySlip.NewPaySlipRow();
                    }
                    if (row.IsNull("EmpID"))
                    {
                        row.EmpID                   = PaySlipID;
                        row.PaymentCode             = paymentCode.PaymentCode;
                        row.PaymentCodeDesc         = paymentCode.PaymentCodeDesc;
                        row.PaymentCodeDisplaySeqNo = paymentCode.PaymentCodeDisplaySeqNo;
                        row.PayMethod               = paymentMethod;
                        row.PayAmount               = 0;
                        //if (!valueDate.Ticks.Equals(0))
                        row.ValueDate = valueDate;
                    }
                    row.PayAmount += paymentRecord.PayRecActAmount;
                    if (!string.IsNullOrEmpty(paymentRecord.PayRecRemark))
                    {
                        if (row.IsRemarkNull())
                        {
                            row.Remark = paymentRecord.PayRecRemark;
                        }
                        else
                        {
                            row.Remark += "\r\n" + paymentRecord.PayRecRemark;
                        }
                    }
                }
                if (valueDate > LastValueDate)
                {
                    LastValueDate = valueDate;
                }
            }
            if (row != null)
            {
                if (row.ValueDate.Ticks.Equals(0))
                {
                    row.SetValueDateNull();
                }
                dataSet.PaySlip.Rows.Add(row);
            }
        }