예제 #1
0
        public async Task <IActionResult> Create([FromBody] CreateExchangeCurrencyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ExchangeCurrency modelo = new ExchangeCurrency
            {
                Description = model.Description,
                CompanyId   = model.CompanyId,
                Quote       = model.Quote,
                Enabled     = true
            };


            _context.ExchangeCurrencies.Add(modelo);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #2
0
        public void Equals_WithSameCurrencyToButNotFrom_ShouldReturnFalse()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);
            var exchangeRate2 = ExchangeCurrency.Create(CURRENCY_NAME_3, CURRENCY_NAME_2, 0);

            Assert.IsFalse(exchangeRate1.Equals(exchangeRate2));
            Assert.IsFalse(exchangeRate2.Equals(exchangeRate1));
        }
예제 #3
0
        public void CanChangeFrom_TargetCurrencyCorrespond_ShouldReturnTrue()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            Assert.IsTrue(exchangeRate.CanChangeFrom(CURRENCY_NAME_2, out changeTo));
        }
예제 #4
0
        public void CanChangeFrom_CurrencyNotManaged_ShouldReturnFalse()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            Assert.IsFalse(exchangeRate.CanChangeFrom(CURRENCY_NAME_3, out changeTo));
        }
예제 #5
0
        public void Equals_WithSameCurrencyFromAndTo_ShouldReturnTrue()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);
            var exchangeRate2 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsTrue(exchangeRate1.Equals(exchangeRate2));
            Assert.IsTrue(exchangeRate2.Equals(exchangeRate1));
        }
예제 #6
0
        public void ToString_ThroughExchange_ShoudReturnPath()
        {
            var directExchange = ThroughExchange.Create(ExchangeCurrency.Create("INI", "INT", 1), "INI", "TAR", new List <IExchangeCurrency>()
            {
                ExchangeCurrency.Create("INT", "TAR", 1),
            });

            Assert.AreEqual("INI;INT;TAR", directExchange.ToString());
        }
예제 #7
0
        public void CanChangeFrom_TargetCurrencyCorrespond_OutParamShouldBeEqualToInitialCurrency()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            exchangeRate.CanChangeFrom(CURRENCY_NAME_2, out changeTo);

            Assert.AreEqual(CURRENCY_NAME_1, changeTo);
        }
예제 #8
0
        public void CanChangeFrom_CurrencyNotManaged_OutParamShouldBeNull()
        {
            var exchangeRate = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            string changeTo;

            exchangeRate.CanChangeFrom(CURRENCY_NAME_3, out changeTo);

            Assert.IsNull(changeTo);
        }
예제 #9
0
        public void Change_InitialSecondTargetFirst_ShouldReturnChangeExhangeRateValue()
        {
            const double expectedChangeResult = 3.14;
            var          exchangeRate         = (ExchangeCurrency)ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            exchangeRate.SetNewRate(new ExchangeRateStub {
                ChangeBackResult = expectedChangeResult
            });

            Assert.AreEqual(expectedChangeResult, exchangeRate.Change(CURRENCY_NAME_2, CURRENCY_NAME_1, 0));
        }
예제 #10
0
        public void TestGetExchangeRate()
        {
            Currency cur = new Currency();

            cur.id   = 1;
            cur.name = "usd";
            ExchangeCurrency exc  = new ExchangeCurrency();
            decimal          rate = exc.getExchangeRate(cur);

            Assert.AreEqual(1.3574, rate);
        }
예제 #11
0
        public void TestGetExchangeRate()
        {
            Currency cur = new Currency();

            cur.id   = 1;
            cur.name = "usd";
            ExchangeCurrency exc  = new ExchangeCurrency();
            double           rate = exc.getExchangeRate(cur);

            Assert.AreEqual(0.742164, rate);
        }
예제 #12
0
        public void TestGetExchangeAmount()
        {
            Currency cur = new Currency();

            cur.id     = 1;
            cur.name   = "usd";
            cur.amount = 1;
            ExchangeCurrency exc  = new ExchangeCurrency();
            double           rate = exc.getExchangedAmount(cur);

            Assert.AreEqual(1, rate);
        }
예제 #13
0
        public void FactoryCreate_SameCurrencyTwice_ShouldReturnRightPath()
        {
            var availableExchangeCurrency = new List <IExchangeCurrency>
            {
                ExchangeCurrency.Create("AAA", "BBB", 1),
                ExchangeCurrency.Create("BBB", "CCC", 1),
                ExchangeCurrency.Create("CCC", "BBB", 1)
            };

            var chainFactory = new ExchangeChainFactory(availableExchangeCurrency);

            Assert.AreEqual("AAA;BBB;CCC", chainFactory.Create("AAA", "CCC").ToString());
        }
예제 #14
0
        public void PriceUpdate(PriceUpdate update)
        {
            lock (lockTheEntireGraph)
            {
                var    from   = new ExchangeCurrency(update.Exchange, update.SourceCurrency);
                var    to     = new ExchangeCurrency(update.Exchange, update.DestinationCurrency);
                double weight = -Math.Log(update.Factor);

                var oldEdge = graph.Adj(from).Where(e => e.To().CompareTo(to) == 0).SingleOrDefault();
                var newEdge = new Edge <ExchangeCurrency>(from, to, weight, update.Timestamp);
                if (oldEdge != null && oldEdge.TimeStamp < update.Timestamp)
                {
                    graph.RemoveEdge(oldEdge);
                    graph.AddEdge(newEdge);
                }
                else if (oldEdge == null) // add 1<-->1 edges by currency
                {
                    graph.AddEdge(newEdge);
                    foreach (var v in graph.Vertexes()
                             .Where(v => v.Currency == update.SourceCurrency)
                             .Where(v => v.CompareTo(from) != 0))
                    {
                        if (!graph.HasEdgeBetween(v, from))
                        {
                            graph.AddEdge(new Edge <ExchangeCurrency>(v, from, -Math.Log(1)));
                        }
                        if (!graph.HasEdgeBetween(from, v))
                        {
                            graph.AddEdge(new Edge <ExchangeCurrency>(from, v, -Math.Log(1)));
                        }
                    }

                    foreach (var v in graph.Vertexes()
                             .Where(v => v.Currency == update.DestinationCurrency)
                             .Where(v => v.CompareTo(to) != 0))
                    {
                        if (!graph.HasEdgeBetween(v, to))
                        {
                            graph.AddEdge(new Edge <ExchangeCurrency>(v, to, -Math.Log(1)));
                        }
                        if (!graph.HasEdgeBetween(to, v))
                        {
                            graph.AddEdge(new Edge <ExchangeCurrency>(to, v, -Math.Log(1)));
                        }
                    }
                }
            }
        }
        // GET: ExchangeCurrency
        public decimal GetExchangeAmount(Currency curr)
        {
            ExchangeCurrency exc = new ExchangeCurrency();

            decimal amount = 0;

            if (exc.getExchangeRate(curr) == 0)
            {
            }
            else
            {
                amount = (int)exc.getExchangedAmount(curr);
            }

            return(amount);
        }
예제 #16
0
        public void Change_ExchangeRateChainExist_ShouldReturnExchangeRateResultRounded()
        {
            const int expectedChangeResult = 59033;
            var       bank = new Bank();

            bank.AddExchangeRate(ExchangeCurrency.Create("AUD", "CHF", 0.9661));
            bank.AddExchangeRate(ExchangeCurrency.Create("JPY", "KRW", 13.1151));
            bank.AddExchangeRate(ExchangeCurrency.Create("EUR", "CHF", 1.2053));
            bank.AddExchangeRate(ExchangeCurrency.Create("AUD", "JPY", 86.0305));
            bank.AddExchangeRate(ExchangeCurrency.Create("EUR", "USD", 1.2989));
            bank.AddExchangeRate(ExchangeCurrency.Create("JPY", "INR", 0.6571));

            var changeResult = bank.Change("EUR", "JPY", 550);

            Assert.AreEqual(expectedChangeResult, changeResult);
        }
예제 #17
0
        public void FactoryCreate_Loop_ShouldReturnRightPath()
        {
            var availableExchangeCurrency = new List <IExchangeCurrency>
            {
                ExchangeCurrency.Create("EUR", "USD", 1),
                ExchangeCurrency.Create("USD", "LIV", 1),
                ExchangeCurrency.Create("USD", "CHF", 1),
                ExchangeCurrency.Create("USD", "AUD", 1),
                ExchangeCurrency.Create("CHF", "LIV", 1),
                ExchangeCurrency.Create("CHF", "AUD", 1),
                ExchangeCurrency.Create("CHF", "AUD", 1),
                ExchangeCurrency.Create("LIV", "AUD", 1),
                ExchangeCurrency.Create("JPY", "LIV", 1)
            };

            var chainFactory = new ExchangeChainFactory(availableExchangeCurrency);

            Assert.AreEqual("EUR;USD;LIV;JPY", chainFactory.Create("EUR", "JPY").ToString());
        }
        public string GetRecommendationExchange(Currency curr)
        {
            string res = "";

            ExchangeCurrency exc = new ExchangeCurrency();
            decimal          dec = exc.getExchangedAmount(curr);

            // get the nearest hundreds
            int decint = (int)dec;

            int rounded = ((decint + 99) / 100) * 100;

            decimal rate = exc.getExchangeRate(curr);

            decimal res1 = rounded * rate;

            res = "recommeded to get " + curr.name.ToUpper() + rounded + " by exchanging: SGD" + (int)res1;

            return(res);
        }
예제 #19
0
        public ActionResult CreateExchange(Exchange Exchange, string[] CurrencyCheckBox)
        {
            if (ModelState.IsValid)
            {
                var UserID  = Session["UserID"].ToString();
                var NowTime = DateTime.Now;
                var NewGuid = Guid.NewGuid();

                Exchange.id       = NewGuid;
                Exchange.CreateID = UserID;
                Exchange.Createdt = NowTime;
                Exchange.UpdateID = UserID;
                Exchange.Updatedt = NowTime;
                Exchange.Status   = 1;
                db.Exchange.Add(Exchange);

                if (CurrencyCheckBox != null)
                {
                    foreach (var item in CurrencyCheckBox)
                    {
                        ExchangeCurrency AddExchangeCurrency = new ExchangeCurrency
                        {
                            ExchangeId  = NewGuid,
                            CurrencyVal = item,
                            CreateID    = UserID,
                            Createdt    = NowTime
                        };
                        db.ExchangeCurrency.Add(AddExchangeCurrency);
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("MainExchange"));
            }
            else
            {
                return(RedirectToAction("Error", "Base", new { msg = "新增交易所時發生錯誤" }));
            }
        }
        public decimal GetExchangeRate(Currency curr)
        {
            ExchangeCurrency exc = new ExchangeCurrency();

            return(exc.getExchangeRate(curr));
        }
예제 #21
0
 private static double GetBidPrice(ExchangeCurrency coin)
 {
     return(coin.bid ?? 0);
 }
예제 #22
0
 public void Create_WithOnlyWhiteSpaceToCurrencyName_ShouldThrowArgumentNullException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, " ", 0);
 }
예제 #23
0
 public void Create_WithSameFromAndToCurrencyName_ShouldThrowArgumentException()
 {
     ExchangeCurrency.Create(CURRENCY_NAME, CURRENCY_NAME, 0);
 }
예제 #24
0
        protected override System.Data.DataSet CreateDataSource()
        {
            System.Data.DataSet dataSet = new System.Data.DataSet();

            DataTable empInfoTable   = new DataTable("EmpInfo");
            DataTable payrollTable   = new DataTable("Payment");
            DataTable hierarchyTable = new DataTable("hierarchy");
            DataTable payPeriodTable = new DataTable("payPeriod");

            dataSet.Tables.Add(empInfoTable);
            dataSet.Tables.Add(payrollTable);
            dataSet.Tables.Add(hierarchyTable);
            dataSet.Tables.Add(payPeriodTable);

            payPeriodTable.Columns.Add("payPeriodFr", typeof(DateTime));

            hierarchyTable.Columns.Add("LevelDesc", typeof(string));

            payrollTable.Columns.Add("EmpPayrollID", typeof(int));
            payrollTable.Columns.Add("empID", typeof(int));
            payrollTable.Columns.Add("payPeriodFr", typeof(DateTime));
            payrollTable.Columns.Add("netAmount", typeof(double));
            payrollTable.Columns.Add("EE", typeof(double));
            payrollTable.Columns.Add("ER", typeof(double));

            int firstDetailColumnPos = payrollTable.Columns.Count;

            empInfoTable.Columns.Add("Employee No.", typeof(string));
            empInfoTable.Columns.Add("EmpPayrollID", typeof(int));
            empInfoTable.Columns.Add("Employee Name", typeof(string));
            empInfoTable.Columns.Add("Alias", typeof(string));
            empInfoTable.Columns.Add("Chinese Name", typeof(string));

            empInfoTable.Columns.Add("Company", typeof(string));
            DBFilter  hierarchyLevelFilter    = new DBFilter();
            Hashtable hierarchyLevelHashTable = new Hashtable();

            hierarchyLevelFilter.add("HLevelSeqNo", true);
            ArrayList hierarchyLevelList = EHierarchyLevel.db.select(dbConn, hierarchyLevelFilter);

            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                if (hlevel.HLevelID.Equals(intHierarchyLevelID))
                {
                    hierarchyLevelGroupingFieldName = hlevel.HLevelDesc;
                }
                empInfoTable.Columns.Add(hlevel.HLevelDesc, typeof(string));
                hierarchyLevelHashTable.Add(hlevel.HLevelID, hlevel);

                DataRow m_hierarchyRow = hierarchyTable.NewRow();
                m_hierarchyRow["LevelDesc"] = hlevel.HLevelDesc;
                hierarchyTable.Rows.Add(m_hierarchyRow);
            }

            empInfoTable.Columns.Add("EmpID", typeof(int));
            empInfoTable.Columns.Add("Payroll Group", typeof(string));
            empInfoTable.Columns.Add("Date Join", typeof(DateTime));
            empInfoTable.Columns.Add("Date Left", typeof(DateTime));
            empInfoTable.Columns.Add("Net Payable", typeof(double));
            empInfoTable.Columns.Add("MCEE", typeof(double));
            empInfoTable.Columns.Add("MCER", typeof(double));
            empInfoTable.Columns.Add("VCEE", typeof(double));
            empInfoTable.Columns.Add("VCER", typeof(double));
            empInfoTable.Columns.Add("PFundEE", typeof(double));
            empInfoTable.Columns.Add("PFundER", typeof(double));

            DBFilter payPeriodFilter = new DBFilter();

            if (!PeriodFrom.Ticks.Equals(0))
            {
                payPeriodFilter.add(new Match("PayPeriodTo", ">=", PeriodFrom));
            }
            if (!PeriodTo.Ticks.Equals(0))
            {
                payPeriodFilter.add(new Match("PayPeriodTo", "<=", PeriodTo));
            }


            ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter);

            if (payPeriodList.Count > 0)
            {
                // reset period
                PeriodFrom = new DateTime();
                PeriodTo   = new DateTime();
            }

            DBFilter m_userCompanyFilter = new DBFilter();

            m_userCompanyFilter.add(new Match("UserID", currentUser.UserID));

            DBFilter m_userRankFilter = new DBFilter();

            m_userRankFilter.add(new Match("UserID", currentUser.UserID));

            Hashtable m_userCompanyList = new Hashtable();

            foreach (EUserCompany m_userCompany in EUserCompany.db.select(dbConn, m_userCompanyFilter))
            {
                m_userCompanyList.Add(m_userCompany.CompanyID, m_userCompany.CompanyID);
            }

            Hashtable m_userRankList = new Hashtable();

            foreach (EUserRank m_userRank in EUserRank.db.select(dbConn, m_userRankFilter))
            {
                m_userRankList.Add(m_userRank.RankID, m_userRank.RankID);
            }


            int[] m_EmpIDList = new int[empList.Count];
            int   i           = 0;

            foreach (EEmpPersonalInfo m_info in empList)
            {
                m_EmpIDList[i] = m_info.EmpID;
                i++;
            }


            foreach (EPayrollPeriod payPeriod in payPeriodList)
            {
                DataRow[] m_payPeriodRows = payPeriodTable.Select("payPeriodFr = '" + ((DateTime)payPeriod.PayPeriodFr).ToString("yyyy-MM-dd") + "' ");
                if (m_payPeriodRows.Length <= 0)
                {
                    DataRow m_payPeriodRow = payPeriodTable.NewRow();
                    m_payPeriodRow["payPeriodFr"] = payPeriod.PayPeriodFr;
                    payPeriodTable.Rows.Add(m_payPeriodRow);
                }

                if (PeriodFrom > payPeriod.PayPeriodFr || PeriodFrom.Ticks.Equals(0))
                {
                    PeriodFrom = payPeriod.PayPeriodFr;
                }
                if (PeriodTo < payPeriod.PayPeriodTo || PeriodTo.Ticks.Equals(0))
                {
                    PeriodTo = payPeriod.PayPeriodTo;
                }

                DBFilter empPayrollFilter = new DBFilter();
                empPayrollFilter.add(new Match("PayPeriodID", payPeriod.PayPeriodID));
                empPayrollFilter.add(new IN("EmpID", m_EmpIDList));
                ArrayList empPayrollList = EEmpPayroll.db.select(dbConn, empPayrollFilter);

                foreach (EEmpPayroll empPayroll in empPayrollList)
                {
                    DataRow   paymentRow      = payrollTable.NewRow();
                    DataRow[] m_existingEmpID = payrollTable.Select("EmpID = " + empPayroll.EmpID.ToString());
                    if (m_existingEmpID.Length == 0)
                    {
                        EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                        empInfo.EmpID = empPayroll.EmpID;
                        if (EEmpPersonalInfo.db.select(dbConn, empInfo) == false)
                        {
                            continue;
                        }

                        DataRow row = empInfoTable.NewRow();

                        row["EmpID"]         = empInfo.EmpID;
                        row["Employee No."]  = empInfo.EmpNo;
                        row["EmpPayrollID"]  = empPayroll.EmpPayrollID;
                        row["Employee Name"] = empInfo.EmpEngFullName;
                        row["Alias"]         = empInfo.EmpAlias;
                        row["Chinese Name"]  = empInfo.EmpChiFullName;
                        row["Date Join"]     = empInfo.EmpDateOfJoin;

                        DBFilter empTerminationFilter = new DBFilter();
                        empTerminationFilter.add(new Match("EmpID", empInfo.EmpID));
                        ArrayList empTerminationList = EEmpTermination.db.select(dbConn, empTerminationFilter);
                        if (empTerminationList.Count > 0)
                        {
                            row["Date Left"] = ((EEmpTermination)empTerminationList[0]).EmpTermLastDate;
                        }

                        DBFilter empPosFilter = new DBFilter();

                        EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, payPeriod.PayPeriodTo, empInfo.EmpID);


                        if (empPos != null)
                        {
                            if (!m_userCompanyList.Contains(empPos.CompanyID) || !m_userRankList.Contains(empPos.RankID))
                            {
                                continue;
                            }

                            if (selectedCompanyID > 0 && empPos.CompanyID != selectedCompanyID)
                            {
                                continue;
                            }

                            ECompany company = new ECompany();
                            company.CompanyID = empPos.CompanyID;
                            if (ECompany.db.select(dbConn, company))
                            {
                                row["Company"] = company.CompanyName;
                            }

                            EPayrollGroup payrollGroup = new EPayrollGroup();
                            payrollGroup.PayGroupID = empPos.PayGroupID;
                            if (EPayrollGroup.db.select(dbConn, payrollGroup))
                            {
                                row["Payroll Group"] = payrollGroup.PayGroupDesc;
                            }
                            DBFilter empHierarchyFilter = new DBFilter();
                            empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                            ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                            foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                            {
                                EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                                if (hierarchyLevel != null)
                                {
                                    EHierarchyElement hierarchyElement = new EHierarchyElement();
                                    hierarchyElement.HElementID = empHierarchy.HElementID;
                                    if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                                    {
                                        row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementDesc;
                                    }
                                }
                            }
                        }
                        empInfoTable.Rows.Add(row);
                    }

                    double netAmount = 0;

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

                    foreach (EPaymentRecord paymentRecord in EPaymentRecord.db.select(dbConn, paymentRecordFilter))
                    {
                        netAmount += paymentRecord.PayRecActAmount;
                    }

                    paymentRow["EmpID"]        = empPayroll.EmpID;
                    paymentRow["EmpPayrollID"] = empPayroll.EmpPayrollID;
                    paymentRow["payPeriodFr"]  = payPeriod.PayPeriodFr;
                    paymentRow["netAmount"]    = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(netAmount, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());

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

                    double m_ee = 0;
                    double m_er = 0;
                    foreach (EMPFRecord mpfRecord in EMPFRecord.db.select(dbConn, mpfRecordFilter))
                    {
                        m_ee += (mpfRecord.MPFRecActVCEE + mpfRecord.MPFRecActMCEE);
                        m_er += (mpfRecord.MPFRecActVCER + mpfRecord.MPFRecActMCER);
                    }

                    ArrayList orsoRecords = EORSORecord.db.select(dbConn, mpfRecordFilter);
                    foreach (EORSORecord orsoRecord in orsoRecords)
                    {
                        m_ee += orsoRecord.ORSORecActEE;
                        m_er += orsoRecord.ORSORecActER;
                    }
                    paymentRow["EE"] = m_ee;
                    paymentRow["ER"] = m_er;

                    payrollTable.Rows.Add(paymentRow);
                }
            }
            //DBFilter paymentCodeFilter = new DBFilter();
            //paymentCodeFilter.add("PaymentCodeDisplaySeqNo", false);
            //paymentCodeFilter.add("PaymentCode", false);
            //ArrayList paymentCodeList = EPaymentCode.db.select(dbConn, paymentCodeFilter);
            //foreach (EPaymentCode paymentCode in paymentCodeList)
            //{
            //    if (payrollTable.Columns.Contains(paymentCode.PaymentCodeDesc))
            //        payrollTable.Columns[paymentCode.PaymentCodeDesc].SetOrdinal(firstDetailColumnPos);
            //}
            return(dataSet);
        }
예제 #25
0
        protected override System.Data.DataSet CreateDataSource()
        {
            const string PAYMENTCODE_PREFIX = "[Payment] ";

            System.Data.DataSet dataSet   = new System.Data.DataSet(); //export.GetDataSet();
            DataTable           dataTable = new DataTable("Payroll$");

            dataSet.Tables.Add(dataTable);
            dataTable.Columns.Add("Company", typeof(string));

            DBFilter  hierarchyLevelFilter    = new DBFilter();
            Hashtable hierarchyLevelHashTable = new Hashtable();

            hierarchyLevelFilter.add("HLevelSeqNo", true);
            ArrayList hierarchyLevelList = EHierarchyLevel.db.select(dbConn, hierarchyLevelFilter);

            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                dataTable.Columns.Add(hlevel.HLevelDesc, typeof(string));
                hierarchyLevelHashTable.Add(hlevel.HLevelID, hlevel);
            }
            dataTable.Columns.Add("Payroll Group", typeof(string));
            dataTable.Columns.Add("Position", typeof(string));
            dataTable.Columns.Add("EmpNo", typeof(string));
            dataTable.Columns.Add("English Name", typeof(string));
            dataTable.Columns.Add("Chinese Name", typeof(string));
            dataTable.Columns.Add("HKID", typeof(string));
            dataTable.Columns.Add("From", typeof(DateTime));
            dataTable.Columns.Add("To", typeof(DateTime));
            int firstSummaryColumnPos = dataTable.Columns.Count;

            dataTable.Columns.Add("Net Payment", typeof(double));
            dataTable.Columns.Add("Relevant Income", typeof(double));
            dataTable.Columns.Add("Non-Relevant Income", typeof(double));
            dataTable.Columns.Add("Wages Payable for Min Wages", typeof(double));
            dataTable.Columns.Add("Total Hours Worked", typeof(double));
            dataTable.Columns.Add("Min Wages Required", typeof(double));
            dataTable.Columns.Add("Employer Mandatory Contribution", typeof(double));
            //            dataTable.Columns.Add("Employee Mandatory Contribution", typeof(double));
            dataTable.Columns.Add("Employer Voluntary Contribution", typeof(double));
            //            dataTable.Columns.Add("Employee Voluntary Contribution", typeof(double));
            dataTable.Columns.Add("Employer P-Fund Contribution", typeof(double));
            //            dataTable.Columns.Add("Employee P-Fund Contribution", typeof(double));
            dataTable.Columns.Add("Total Employer Contribution", typeof(double));
            dataTable.Columns.Add("Total Employee Contribution", typeof(double));
            dataTable.Columns.Add("Total Taxable Payment", typeof(double));
            dataTable.Columns.Add("Total Non-Taxable Payment", typeof(double));
            int firstDetailColumnPos = dataTable.Columns.Count;


            foreach (EEmpPersonalInfo empInfo in EmpList)
            {
                EEmpPersonalInfo.db.select(dbConn, empInfo);



                //DBFilter empPayrollFilterForPayrollPeriod = new DBFilter();
                //empPayrollFilterForPayrollPeriod.add(new Match("ep.EmpID", empInfo.EmpID));
                //empPayrollFilterForPayrollPeriod.add(Payroll_PeriodSelectionList1.GetEmpPayrollDBTerm());

                //DBFilter payPeriodFilter = new DBFilter();
                //payPeriodFilter.add(new IN("PayPeriodID", "SELECT PayPeriodID from " + EEmpPayroll.db.dbclass.tableName + " ep", empPayrollFilterForPayrollPeriod));
                //ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter);
                if (PayPeriodList == null)
                {
                    OR orPayBatchIDTerms = new OR();
                    foreach (EPayrollBatch payBatch in PayBatchList)
                    {
                        orPayBatchIDTerms.add(new Match("ep.PayBatchID", payBatch.PayBatchID));
                    }

                    DBFilter empPayrollFilter = new DBFilter();
                    empPayrollFilter.add(orPayBatchIDTerms);

                    DBFilter payPeriodFilter = new DBFilter();
                    payPeriodFilter.add(new IN(EPayrollPeriod.db.dbclass.tableName + ".PayPeriodID ", "SELECT DISTINCT PayPeriodID FROM " + EEmpPayroll.db.dbclass.tableName + " ep", empPayrollFilter));

                    PayPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter);
                }

                foreach (EPayrollPeriod payPeriod in PayPeriodList)
                {
                    DBFilter empPayrollFilter = new DBFilter();
                    empPayrollFilter.add(new Match("EmpID", empInfo.EmpID));

                    if (reportType.Equals(ReportType.TrialRun))
                    {
                        empPayrollFilter.add(new Match("EmpPayStatus", "=", "T"));
                    }
                    else
                    {
                        empPayrollFilter.add(new Match("EmpPayStatus", "<>", "T"));
                    }

                    if (PayBatchList != null)
                    {
                        OR orPayrollBatch = new OR();
                        foreach (EPayrollBatch payrollBatch in PayBatchList)
                        {
                            orPayrollBatch.add(new Match("PayBatchID", payrollBatch.PayBatchID));
                        }
                        empPayrollFilter.add(orPayrollBatch);
                    }
                    empPayrollFilter.add(new Match("PayPeriodID", payPeriod.PayPeriodID));

                    //  Check if the EmpPayroll record for that payroll period exists
                    if (EEmpPayroll.db.count(dbConn, empPayrollFilter) > 0 && EPayrollPeriod.db.select(dbConn, payPeriod))
                    {
                        EPayrollGroup payrollGroup = new EPayrollGroup();
                        payrollGroup.PayGroupID = payPeriod.PayGroupID;
                        EPayrollGroup.db.select(dbConn, payrollGroup);

                        DataRow row = dataTable.NewRow();
                        row["EmpNo"]         = empInfo.EmpNo;
                        row["English Name"]  = empInfo.EmpEngFullName;
                        row["Chinese Name"]  = empInfo.EmpChiFullName;
                        row["HKID"]          = empInfo.EmpHKID;
                        row["From"]          = payPeriod.PayPeriodFr;
                        row["To"]            = payPeriod.PayPeriodTo;
                        row["Payroll Group"] = payrollGroup.PayGroupDesc;
                        DBFilter empPosFilter = new DBFilter();

                        EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, payPeriod.PayPeriodTo, empInfo.EmpID);
                        if (empPos != null)
                        {
                            ECompany company = new ECompany();
                            company.CompanyID = empPos.CompanyID;
                            if (ECompany.db.select(dbConn, company))
                            {
                                row["Company"] = company.CompanyCode;
                            }

                            DBFilter empHierarchyFilter = new DBFilter();
                            empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                            ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                            foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                            {
                                EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                                if (hierarchyLevel != null)
                                {
                                    EHierarchyElement hierarchyElement = new EHierarchyElement();
                                    hierarchyElement.HElementID = empHierarchy.HElementID;
                                    if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                                    {
                                        row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementDesc;
                                    }
                                }
                            }
                            EPosition position = new EPosition();
                            position.PositionID = empPos.PositionID;
                            if (EPosition.db.select(dbConn, position))
                            {
                                row["Position"] = position.PositionDesc;
                            }
                        }

                        double netAmount = 0, releventIncome = 0, nonRelevantIncome = 0, taxableAmount = 0, nonTaxableAmount = 0;
                        double mcER = 0, mcEE = 0;
                        double vcER = 0, vcEE = 0;
                        double pFundER = 0, pFundEE = 0;

                        //DBFilter empPayrollFilterForPaymentRecord = new DBFilter(empPayrollFilterForPayrollPeriod);
                        //empPayrollFilterForPaymentRecord.add(new Match("PayPeriodID", payPeriod.PayPeriodID));
                        //DBFilter paymentRecordFilter = new DBFilter();
                        //paymentRecordFilter.add(new IN("EmpPayrollID", "Select EmpPayrollID from " + EEmpPayroll.db.dbclass.tableName + " ep ", empPayrollFilterForPaymentRecord));
                        //paymentRecordFilter.add(new Match("PayRecStatus", "A"));


                        IN inEmpPayroll = new IN("EmpPayrollID", "Select ep.EmpPayrollID from " + EEmpPayroll.db.dbclass.tableName + " ep", empPayrollFilter);

                        DBFilter empPayrollFilterForPaymentRecord = new DBFilter();
                        empPayrollFilterForPaymentRecord.add(inEmpPayroll);
                        ArrayList paymentRecords = EPaymentRecord.db.select(dbConn, empPayrollFilterForPaymentRecord);

                        foreach (EPaymentRecord paymentRecord in paymentRecords)
                        {
                            EPaymentCode payCode = new EPaymentCode();
                            payCode.PaymentCodeID = paymentRecord.PaymentCodeID;
                            EPaymentCode.db.select(dbConn, payCode);
                            //  Always Use Payment Code Description for grouping payment code with same description
                            string fieldName = PAYMENTCODE_PREFIX + payCode.PaymentCodeDesc;
                            if (dataTable.Columns[fieldName] == null)
                            {
                                dataTable.Columns.Add(new DataColumn(fieldName, typeof(double)));
                            }
                            if (row[fieldName] == null || row[fieldName] == DBNull.Value)
                            {
                                row[fieldName] = 0;
                            }
                            row[fieldName] = (double)row[fieldName] + paymentRecord.PayRecActAmount;


                            netAmount += paymentRecord.PayRecActAmount;
                            if (payCode.PaymentCodeIsMPF)
                            {
                                releventIncome += paymentRecord.PayRecActAmount;
                            }
                            else
                            {
                                nonRelevantIncome += paymentRecord.PayRecActAmount;
                            }

                            DBFilter taxPaymentMapFilter = new DBFilter();
                            taxPaymentMapFilter.add(new Match("PaymentCodeID", paymentRecord.PaymentCodeID));
                            if (ETaxPaymentMap.db.count(dbConn, taxPaymentMapFilter) > 0)
                            {
                                taxableAmount += paymentRecord.PayRecActAmount;
                            }
                            else
                            {
                                nonTaxableAmount += paymentRecord.PayRecActAmount;
                            }
                        }

                        row["Net Payment"]                 = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(netAmount, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        row["Relevant Income"]             = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(releventIncome, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        row["Non-Relevant Income"]         = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(nonRelevantIncome, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        row["Wages Payable for Min Wages"] = HROne.Payroll.PayrollProcess.GetTotalWagesWithoutRestDayPayment(dbConn, empInfo.EmpID, payPeriod.PayPeriodFr, payPeriod.PayPeriodTo, null);
                        row["Total Hours Worked"]          = HROne.Payroll.PayrollProcess.GetTotalEmpPayrollWorkingHours(dbConn, empInfo.EmpID, payPeriod.PayPeriodID);
                        row["Min Wages Required"]          = (double)row["Total Hours Worked"] * HROne.Payroll.PayrollProcess.GetMinimumWages(dbConn, empInfo.EmpID, payPeriod.PayPeriodTo);
                        row["Total Taxable Payment"]       = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(taxableAmount, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        row["Total Non-Taxable Payment"]   = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(nonTaxableAmount, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());

                        ArrayList mpfRecords = EMPFRecord.db.select(dbConn, empPayrollFilterForPaymentRecord);
                        foreach (EMPFRecord mpfRecord in mpfRecords)
                        {
                            vcER += mpfRecord.MPFRecActVCER;
                            mcER += +mpfRecord.MPFRecActMCER;
                            vcEE += mpfRecord.MPFRecActVCEE;
                            mcEE += mpfRecord.MPFRecActMCEE;
                        }
                        ArrayList orsoRecords = EORSORecord.db.select(dbConn, empPayrollFilterForPaymentRecord);
                        foreach (EORSORecord orsoRecord in orsoRecords)
                        {
                            pFundER += orsoRecord.ORSORecActER;
                            pFundEE += orsoRecord.ORSORecActEE;
                        }
                        row["Employer Mandatory Contribution"] = mcER;
                        //                        row["Employee Mandatory Contribution"] = mcEE;
                        row["Employer Voluntary Contribution"] = vcER;
                        //                        row["Employee Voluntary Contribution"] = vcEE;
                        row["Employer P-Fund Contribution"] = pFundER;
                        //                        row["Employee P-Fund Contribution"] = pFundEE;

                        row["Total Employer Contribution"] = mcER + vcER + pFundER;
                        row["Total Employee Contribution"] = mcEE + vcEE + pFundEE;

                        dataTable.Rows.Add(row);
                    }
                }
            }

            DBFilter paymentCodeFilter = new DBFilter();

            paymentCodeFilter.add("PaymentCodeDisplaySeqNo", false);
            paymentCodeFilter.add("PaymentCode", false);
            ArrayList paymentCodeList = EPaymentCode.db.select(dbConn, paymentCodeFilter);

            foreach (EPaymentCode paymentCode in paymentCodeList)
            {
                if (dataTable.Columns.Contains(PAYMENTCODE_PREFIX + paymentCode.PaymentCodeDesc))
                {
                    DataColumn paymentColumn = dataTable.Columns[PAYMENTCODE_PREFIX + paymentCode.PaymentCodeDesc];
                    paymentColumn.SetOrdinal(firstDetailColumnPos);
                    if (!dataTable.Columns.Contains(paymentCode.PaymentCodeDesc))
                    {
                        paymentColumn.ColumnName = paymentCode.PaymentCodeDesc;
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write("System reserved payment column is used");
                    }
                }
            }
            for (int i = 0; i < firstDetailColumnPos; i++)
            {
                dataTable.Columns[i].ColumnName = HROne.Common.WebUtility.GetLocalizedString(dataTable.Columns[i].ColumnName);
            }

            for (int i = firstSummaryColumnPos; i < firstDetailColumnPos; i++)
            {
                dataTable.Columns[firstSummaryColumnPos].SetOrdinal(dataTable.Columns.Count - 1);
            }


            return(dataSet);
        }
예제 #26
0
        //private static double CalculateProrataFactor(int EmpID, EPayrollPeriod payrollPeriod)
        //{
        //    EEmpPersonalInfo oEmp = new EEmpPersonalInfo();
        //    oEmp.EmpID = EmpID;
        //    EEmpPersonalInfo.db.select(dbConn, oEmp);

        //    DateTime dt1AgeMin = oEmp.EmpDateOfBirth.AddYears(AGE_MINIMUM);
        //    DateTime dt1AgeMax = oEmp.EmpDateOfBirth.AddYears(AGE_MAXIMUM);

        //    EEmpTermination empTermination = EEmpTermination.GetObjectByEmpID(dbConn, EmpID);
        //    bool blnTerminated;
        //    if (empTermination != null)
        //    {
        //        if (empTermination.EmpTermLastDate <= payrollPeriod.PayPeriodTo && empTermination.EmpTermLastDate >= payrollPeriod.PayPeriodFr)
        //            blnTerminated = true;
        //        else
        //            blnTerminated = false;
        //    }
        //    else
        //        blnTerminated = false;

        //    double prorataFactor = 1;
        //    if (oEmp.EmpDateOfJoin < dt1AgeMin)
        //    {
        //        if (dt1AgeMin <= payrollPeriod.PayPeriodTo && dt1AgeMin >= payrollPeriod.PayPeriodFr)
        //        {
        //            if (blnTerminated)
        //                prorataFactor = (double)(empTermination.EmpTermLastDate.Subtract(dt1AgeMin).Days + 1) / (empTermination.EmpTermLastDate.Subtract(payrollPeriod.PayPeriodFr > oEmp.EmpDateOfJoin ? payrollPeriod.PayPeriodFr : oEmp.EmpDateOfJoin).Days + 1);
        //            else
        //                prorataFactor = (double)(payrollPeriod.PayPeriodTo.Subtract(dt1AgeMin).Days + 1) / (payrollPeriod.PayPeriodTo.Subtract(payrollPeriod.PayPeriodFr > oEmp.EmpDateOfJoin ? payrollPeriod.PayPeriodFr : oEmp.EmpDateOfJoin).Days + 1);
        //        }
        //        if (dt1AgeMin >= payrollPeriod.PayPeriodTo)
        //            prorataFactor = 0;
        //    }

        //    if (dt1AgeMax <= payrollPeriod.PayPeriodTo && dt1AgeMax >= payrollPeriod.PayPeriodFr)
        //    {
        //        if (blnTerminated)
        //        {
        //            if (empTermination.EmpTermLastDate < dt1AgeMax)
        //                prorataFactor = 1;
        //            else
        //                prorataFactor = 1.0 - (double)(empTermination.EmpTermLastDate.Subtract(dt1AgeMax).Days + 1) / (empTermination.EmpTermLastDate.Subtract(payrollPeriod.PayPeriodFr > oEmp.EmpDateOfJoin ? payrollPeriod.PayPeriodFr : oEmp.EmpDateOfJoin).Days + 1);
        //        }
        //        else
        //            prorataFactor = 1.0 - (double)(payrollPeriod.PayPeriodTo.Subtract(dt1AgeMax).Days + 1) / (payrollPeriod.PayPeriodTo.Subtract(payrollPeriod.PayPeriodFr > oEmp.EmpDateOfJoin ? payrollPeriod.PayPeriodFr : oEmp.EmpDateOfJoin).Days + 1);
        //    }
        //    if (dt1AgeMax <= payrollPeriod.PayPeriodFr)
        //        prorataFactor = 0;

        //    return prorataFactor;
        //}

        private static EORSORecord CreateORSORecord(DatabaseConnection dbConn, int EmpID, EPayrollPeriod payrollPeriod, ArrayList paymentRecords, DateTime ORSOJoinDate, ORSOJoinType ORSOJoinType, EMPFRecord mpfRecord)
        {
            //double RIProrateFactor = CalculateProrataFactor(EmpID, payrollPeriod);
            EORSORecord orsoRecord = new EORSORecord();

            switch (ORSOJoinType)
            {
            case ORSOJoinType.NewJoin:
                orsoRecord.ORSORecType = "N";
                break;

            case ORSOJoinType.Existing:
                orsoRecord.ORSORecType = "E";
                break;
                //case ORSOJoinType.Terminated:
                //    ORSORecord.ORSORecType = "T";
                //break;
            }
            orsoRecord.ORSORecCalRI = 0;
            orsoRecord.ORSOPlanID   = GetORSOPlanID(dbConn, EmpID, payrollPeriod.PayPeriodTo);

            if (orsoRecord.ORSOPlanID > 0)
            {
                EEmpPersonalInfo oEmp = new EEmpPersonalInfo();
                oEmp.EmpID = EmpID;
                EEmpPersonalInfo.db.select(dbConn, oEmp);

                //DateTime dt1Age18 = oEmp.EmpDateOfBirth.AddYears(18);
                //DateTime dt1Age65 = oEmp.EmpDateOfBirth.AddYears(65);

                EEmpTermination empTermination = EEmpTermination.GetObjectByEmpID(dbConn, EmpID);

                orsoRecord.ORSORecPeriodFr = payrollPeriod.PayPeriodFr;
                orsoRecord.ORSORecPeriodTo = payrollPeriod.PayPeriodTo;

                if (orsoRecord.ORSORecPeriodFr > oEmp.EmpDateOfJoin && orsoRecord.ORSORecPeriodTo < oEmp.EmpDateOfJoin)
                {
                    orsoRecord.ORSORecPeriodFr = oEmp.EmpDateOfJoin;
                }
                //if (ORSORecord.ORSORecPeriodFr > dt1Age18 && ORSORecord.ORSORecPeriodTo < dt1Age18)
                //    ORSORecord.ORSORecPeriodFr = dt1Age18;
                if (empTermination != null)
                {
                    // Start 0000186, Ricky So, 2016/04/15
                    // incomplete month --> no orso contribution
                    if (orsoRecord.ORSORecPeriodTo > empTermination.EmpTermLastDate && orsoRecord.ORSORecPeriodFr <= empTermination.EmpTermLastDate)
                    {
                        orsoRecord.ORSORecPeriodTo = empTermination.EmpTermLastDate;
                        orsoRecord.ORSORecActEE    = 0;
                        orsoRecord.ORSORecActER    = 0;
                        orsoRecord.ORSORecActRI    = 0;
                        orsoRecord.ORSORecCalEE    = 0;
                        orsoRecord.ORSORecCalER    = 0;
                        orsoRecord.ORSORecCalRI    = 0;
                        return(orsoRecord);
                    }
                    // End 0000186, Ricky So, 2016/04/15
                    if (orsoRecord.ORSORecPeriodTo < empTermination.EmpTermLastDate && orsoRecord.ORSORecPeriodFr >= empTermination.EmpTermLastDate)
                    {
                        orsoRecord.ORSORecPeriodTo = empTermination.EmpTermLastDate;
                    }
                }
                //if (ORSORecord.ORSORecPeriodTo < dt1Age65 && ORSORecord.ORSORecPeriodFr > dt1Age65)
                //    ORSORecord.ORSORecPeriodTo = dt1Age65;


                foreach (EPaymentRecord paymentRecord in paymentRecords)
                {
                    EPaymentCode paymentCode = new EPaymentCode();
                    paymentCode.PaymentCodeID = paymentRecord.PaymentCodeID;
                    EPaymentCode.db.select(dbConn, paymentCode);
                    if (paymentCode.PaymentCodeIsORSO)
                    {
                        orsoRecord.ORSORecCalRI += paymentRecord.PayRecActAmount;
                    }
                }
                orsoRecord.ORSORecActRI = orsoRecord.ORSORecCalRI;

                if (orsoRecord.ORSOPlanID > 0)
                {
                    DBFilter oldORSORecordFilter = new DBFilter();

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

                    oldORSORecordFilter.add(new IN("EmpPayrollID", "Select EmpPayrollID from EMPPayroll ", empIDFilter));
                    oldORSORecordFilter.add(new Match("ORSORecPeriodFr", "<=", orsoRecord.ORSORecPeriodTo));
                    oldORSORecordFilter.add(new Match("ORSORecPeriodTo", ">=", orsoRecord.ORSORecPeriodFr));
                    ArrayList oldORSORecords = EORSORecord.db.select(dbConn, oldORSORecordFilter);

                    EORSORecord oldTotalORSORecord = new EORSORecord();
                    EORSORecord newTotalORSORecord = new EORSORecord();

                    foreach (EORSORecord oldORSORecord in oldORSORecords)
                    {
                        oldTotalORSORecord.ORSORecActRI += oldORSORecord.ORSORecActRI;
                        oldTotalORSORecord.ORSORecActER += oldORSORecord.ORSORecActER;
                        oldTotalORSORecord.ORSORecActEE += oldORSORecord.ORSORecActEE;
                    }


                    newTotalORSORecord.ORSORecCalRI = oldTotalORSORecord.ORSORecActRI + orsoRecord.ORSORecCalRI;

                    newTotalORSORecord.ORSORecCalER = CalculateERAmount(dbConn, oEmp, orsoRecord.ORSOPlanID, newTotalORSORecord.ORSORecCalRI, payrollPeriod, mpfRecord);
                    newTotalORSORecord.ORSORecCalEE = CalculateEEAmount(dbConn, oEmp, orsoRecord.ORSOPlanID, newTotalORSORecord.ORSORecCalRI, payrollPeriod, ORSOJoinDate, mpfRecord);

                    orsoRecord.ORSORecCalER = newTotalORSORecord.ORSORecCalER - oldTotalORSORecord.ORSORecActER;
                    orsoRecord.ORSORecCalEE = newTotalORSORecord.ORSORecCalEE - oldTotalORSORecord.ORSORecActEE;



                    orsoRecord.ORSORecActER = Math.Round(orsoRecord.ORSORecCalER, 2, MidpointRounding.AwayFromZero);
                    orsoRecord.ORSORecActEE = Math.Round(orsoRecord.ORSORecCalEE, 2, MidpointRounding.AwayFromZero);

                    EORSOPlan orsoPlan = new EORSOPlan();
                    orsoPlan.ORSOPlanID = orsoRecord.ORSOPlanID;
                    if (EORSOPlan.db.select(dbConn, orsoPlan))
                    {
                        if (string.IsNullOrEmpty(orsoPlan.ORSOPlanEmployerRoundingRule))
                        {
                            orsoPlan.ORSOPlanEmployerRoundingRule = Values.ROUNDING_RULE_ROUND_TO;
                            orsoPlan.ORSOPlanEmployerDecimalPlace = 2;
                        }
                        if (orsoPlan.ORSOPlanEmployerRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_TO))
                        {
                            orsoRecord.ORSORecActER = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(orsoRecord.ORSORecCalER, orsoPlan.ORSOPlanEmployerDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }
                        else if (orsoPlan.ORSOPlanEmployerRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_UP))
                        {
                            orsoRecord.ORSORecActER = HROne.CommonLib.GenericRoundingFunctions.RoundingUp(orsoRecord.ORSORecCalER, orsoPlan.ORSOPlanEmployerDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }
                        else if (orsoPlan.ORSOPlanEmployerRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_DOWN))
                        {
                            orsoRecord.ORSORecActER = HROne.CommonLib.GenericRoundingFunctions.RoundingDown(orsoRecord.ORSORecCalER, orsoPlan.ORSOPlanEmployerDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }

                        if (string.IsNullOrEmpty(orsoPlan.ORSOPlanEmployeeRoundingRule))
                        {
                            orsoPlan.ORSOPlanEmployeeRoundingRule = Values.ROUNDING_RULE_ROUND_TO;
                            orsoPlan.ORSOPlanEmployeeDecimalPlace = 2;
                        }
                        if (orsoPlan.ORSOPlanEmployeeRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_TO))
                        {
                            orsoRecord.ORSORecActEE = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(orsoRecord.ORSORecCalEE, orsoPlan.ORSOPlanEmployeeDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }
                        else if (orsoPlan.ORSOPlanEmployeeRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_UP))
                        {
                            orsoRecord.ORSORecActEE = HROne.CommonLib.GenericRoundingFunctions.RoundingUp(orsoRecord.ORSORecCalEE, orsoPlan.ORSOPlanEmployeeDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }
                        else if (orsoPlan.ORSOPlanEmployeeRoundingRule.Equals(Values.ROUNDING_RULE_ROUND_DOWN))
                        {
                            orsoRecord.ORSORecActEE = HROne.CommonLib.GenericRoundingFunctions.RoundingDown(orsoRecord.ORSORecCalEE, orsoPlan.ORSOPlanEmployeeDecimalPlace, ExchangeCurrency.DefaultCurrencyDecimalPlaces());
                        }
                    }
                }

                return(orsoRecord);
            }
            else
            {
                return(null);
            }
        }
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        ArrayList list = WebUtils.SelectedRepeaterItemToBaseObjectList(EEmpPersonalInfo.db, Repeater, "ItemSelect");

        if (list.Count > 0)
        {
            const string PAYMENTCODE_PREFIX = "[Payment] ";
            string       exportFileName     = System.IO.Path.GetTempFileName();
            System.IO.File.Delete(exportFileName);
            exportFileName += ".xls";

            HROne.Export.ExcelExport export = new HROne.Export.ExcelExport(exportFileName);
            DataSet   dataSet   = new DataSet();
            DataTable dataTable = new DataTable("Payroll$");
            dataSet.Tables.Add(dataTable);
            dataTable.Columns.Add("Company", typeof(string));

            DBFilter  hierarchyLevelFilter    = new DBFilter();
            Hashtable hierarchyLevelHashTable = new Hashtable();
            hierarchyLevelFilter.add("HLevelSeqNo", true);
            ArrayList hierarchyLevelList = EHierarchyLevel.db.select(dbConn, hierarchyLevelFilter);
            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                dataTable.Columns.Add(hlevel.HLevelDesc, typeof(string));
                hierarchyLevelHashTable.Add(hlevel.HLevelID, hlevel);
            }
            dataTable.Columns.Add("Payroll Group", typeof(string));
            dataTable.Columns.Add("Position", typeof(string));
            dataTable.Columns.Add("EmpNo", typeof(string));
            dataTable.Columns.Add("English Name", typeof(string));
            dataTable.Columns.Add("Chinese Name", typeof(string));
            dataTable.Columns.Add("HKID", typeof(string));
            dataTable.Columns.Add("From", typeof(DateTime));
            dataTable.Columns.Add("To", typeof(DateTime));
            int firstSummaryColumnPos = dataTable.Columns.Count;
            dataTable.Columns.Add("Net Payment", typeof(double));
            int firstDetailColumnPos = dataTable.Columns.Count;

            foreach (EEmpPersonalInfo empInfo in list)
            {
                EEmpPersonalInfo.db.select(dbConn, empInfo);

                DBFilter empPayrollFilterForPayrollPeriod = new DBFilter();
                empPayrollFilterForPayrollPeriod.add(new Match("ep.EmpID", empInfo.EmpID));
                empPayrollFilterForPayrollPeriod.add(Payroll_PeriodSelectionList1.GetEmpPayrollDBTerm());

                DBFilter payPeriodFilter = new DBFilter();
                payPeriodFilter.add(new IN("PayPeriodID", "SELECT PayPeriodID from " + EEmpPayroll.db.dbclass.tableName + " ep", empPayrollFilterForPayrollPeriod));
                ArrayList payPeriodList = EPayrollPeriod.db.select(dbConn, payPeriodFilter);

                foreach (EPayrollPeriod payPeriod in payPeriodList)
                {
                    if (EPayrollPeriod.db.select(dbConn, payPeriod))
                    {
                        EPayrollGroup payrollGroup = new EPayrollGroup();
                        payrollGroup.PayGroupID = payPeriod.PayGroupID;
                        EPayrollGroup.db.select(dbConn, payrollGroup);

                        DataRow row = dataTable.NewRow();
                        row["EmpNo"]         = empInfo.EmpNo;
                        row["English Name"]  = empInfo.EmpEngFullName;
                        row["Chinese Name"]  = empInfo.EmpChiFullName;
                        row["HKID"]          = empInfo.EmpHKID;
                        row["From"]          = payPeriod.PayPeriodFr;
                        row["To"]            = payPeriod.PayPeriodTo;
                        row["Payroll Group"] = payrollGroup.PayGroupDesc;
                        DBFilter empPosFilter = new DBFilter();

                        EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, payPeriod.PayPeriodTo, empInfo.EmpID);
                        if (empPos != null)
                        {
                            ECompany company = new ECompany();
                            company.CompanyID = empPos.CompanyID;
                            if (ECompany.db.select(dbConn, company))
                            {
                                row["Company"] = company.CompanyCode;
                            }

                            DBFilter empHierarchyFilter = new DBFilter();
                            empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                            ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                            foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                            {
                                EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                                if (hierarchyLevel != null)
                                {
                                    EHierarchyElement hierarchyElement = new EHierarchyElement();
                                    hierarchyElement.HElementID = empHierarchy.HElementID;
                                    if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                                    {
                                        row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementDesc;
                                    }
                                }
                            }
                            EPosition position = new EPosition();
                            position.PositionID = empPos.PositionID;
                            if (EPosition.db.select(dbConn, position))
                            {
                                row["Position"] = position.PositionDesc;
                            }
                        }

                        double netAmount = 0;

                        DBFilter empPayrollFilterForPaymentRecord = new DBFilter(empPayrollFilterForPayrollPeriod);
                        empPayrollFilterForPaymentRecord.add(new Match("PayPeriodID", payPeriod.PayPeriodID));
                        DBFilter paymentRecordFilter = new DBFilter();
                        paymentRecordFilter.add(new IN("EmpPayrollID", "Select EmpPayrollID from " + EEmpPayroll.db.dbclass.tableName + " ep ", empPayrollFilterForPaymentRecord));
                        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);
                            //  Always Use Payment Code Description for grouping payment code with same description
                            string fieldName = PAYMENTCODE_PREFIX + payCode.PaymentCodeDesc;
                            if (dataTable.Columns[fieldName] == null)
                            {
                                dataTable.Columns.Add(new DataColumn(fieldName, typeof(double)));
                            }
                            if (row[fieldName] == null || row[fieldName] == DBNull.Value)
                            {
                                row[fieldName] = 0;
                            }
                            row[fieldName] = (double)row[fieldName] + paymentRecord.PayRecActAmount;

                            netAmount += paymentRecord.PayRecActAmount;
                        }

                        row["Net Payment"] = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(netAmount, ExchangeCurrency.DefaultCurrencyDecimalPlaces(), ExchangeCurrency.DefaultCurrencyDecimalPlaces());

                        dataTable.Rows.Add(row);
                    }
                }
            }

            DBFilter paymentCodeFilter = new DBFilter();
            paymentCodeFilter.add("PaymentCodeDisplaySeqNo", false);
            paymentCodeFilter.add("PaymentCode", false);
            ArrayList paymentCodeList = EPaymentCode.db.select(dbConn, paymentCodeFilter);
            foreach (EPaymentCode paymentCode in paymentCodeList)
            {
                if (dataTable.Columns.Contains(PAYMENTCODE_PREFIX + paymentCode.PaymentCodeDesc))
                {
                    DataColumn paymentColumn = dataTable.Columns[PAYMENTCODE_PREFIX + paymentCode.PaymentCodeDesc];
                    paymentColumn.SetOrdinal(firstDetailColumnPos);
                    if (!dataTable.Columns.Contains(paymentCode.PaymentCodeDesc))
                    {
                        paymentColumn.ColumnName = paymentCode.PaymentCodeDesc;
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write("System reserved payment column is used");
                    }
                }
            }
            for (int i = 0; i < firstDetailColumnPos; i++)
            {
                dataTable.Columns[i].ColumnName = HROne.Common.WebUtility.GetLocalizedString(dataTable.Columns[i].ColumnName);
            }

            for (int i = firstSummaryColumnPos; i < firstDetailColumnPos; i++)
            {
                dataTable.Columns[firstSummaryColumnPos].SetOrdinal(dataTable.Columns.Count - 1);
            }

            export.Update(dataSet);
            WebUtils.TransmitFile(Response, exportFileName, "PaymentListWaiJi_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".xls", true);
            return;
        }
        else
        {
            errors.addError("Employee not selected");
        }
    }
예제 #28
0
        // GET: ExchangeCurrency
        public double GetExchangeAmount(Currency curr)
        {
            ExchangeCurrency exc = new ExchangeCurrency();

            return(exc.getExchangedAmount(curr));
        }
예제 #29
0
        public ActionResult EditExchange(Exchange Exchange, string[] CurrencyCheckBox)
        {
            try
            {
                var UserID      = Session["UserID"].ToString();
                var DateTimeNow = DateTime.Now;

                //編輯交易所
                var sql = db.Exchange.Find(Exchange.id);
                sql.Name          = Exchange.Name;
                sql.ExchangeUrl   = Exchange.ExchangeUrl;
                sql.ProcessingFee = Exchange.ProcessingFee;
                sql.UpdateID      = UserID;
                sql.Updatedt      = DateTimeNow;

                //找出刪除的幣別選項
                var WantDeletdCurrency = sql.ExchangeCurrency.ToList();
                if (CurrencyCheckBox != null)
                {
                    foreach (var item in CurrencyCheckBox)
                    {
                        WantDeletdCurrency = WantDeletdCurrency.Where(x => x.CurrencyVal != item).ToList();
                    }
                }

                //交易所帳號內的幣別一同刪除
                var FundsBalance = db.FundsBalance;
                foreach (var Account in sql.Account)
                {
                    var WantDeleteFundsBalance = Account.FundsBalance;
                    foreach (var item in WantDeletdCurrency)
                    {
                        WantDeleteFundsBalance.Where(x => x.CurrencyVal == item.CurrencyVal);
                    }
                    FundsBalance.RemoveRange(WantDeleteFundsBalance);
                }

                //刪除幣別關聯
                var ExchangeCurrency = db.ExchangeCurrency;
                ExchangeCurrency.RemoveRange(sql.ExchangeCurrency);

                //重新新增幣別關聯
                if (CurrencyCheckBox != null)
                {
                    foreach (var item in CurrencyCheckBox)
                    {
                        ExchangeCurrency AddExchangeCurrency = new ExchangeCurrency
                        {
                            ExchangeId  = Exchange.id,
                            CurrencyVal = item,
                            CreateID    = UserID,
                            Createdt    = DateTimeNow
                        };
                        db.ExchangeCurrency.Add(AddExchangeCurrency);
                    }
                }

                //關閉有關聯之執行程式
                var ExecutionsAccount = db.ExecutionsAccount.Where(x => x.Account.ExchangeId == Exchange.id);
                foreach (var item in ExecutionsAccount)
                {
                    item.Executions.Status = 0;
                    SetExecutions.KillProcess(item.ExecutionsId.ToString());
                }

                db.SaveChanges();

                return(RedirectToAction("MainExchange"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Base", new { msg = "編輯時發生錯誤" + ex.Message }));
            }
        }
예제 #30
0
        public void Equals_WithNull_ShouldReturnFalse()
        {
            var exchangeRate1 = ExchangeCurrency.Create(CURRENCY_NAME_1, CURRENCY_NAME_2, 0);

            Assert.IsFalse(exchangeRate1.Equals(null));
        }