Exemple #1
0
        private void Test3()
        {
            taxIndicators.First(p => p.NrCrt == 1).ValueField = "5";
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "10";

            string formula = "rd.(1-2)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != -5)
            {
                throw new Exception();
            }
        }
Exemple #2
0
        private void Test4()
        {
            //taxIndicators.First(p => p.NrCrt == 1).ValueField = "5";
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "10";

            //string formula = "rd.(1-2)";
            string formula = "rd.2*3/1000";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != (decimal)0.03)
            {
                throw new Exception();
            }
        }
Exemple #3
0
        private void Test9_5()
        {
            taxIndicators.First(p => p.NrCrt == 18).ValueField = "20";
            taxIndicators.First(p => p.NrCrt == 43).ValueField = "20";

            //string formula = "IF(rd.18-rd.43<0;-(rd.18-rd.43);0)";
            //string formula = "IF(rd.18-rd.43<0;rd.18-rd.43;0)";
            string formula = "IF(rd.18-rd.43<0;-rd.18+rd.43;0)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != 0)
            {
                throw new Exception();
            }

            taxIndicators.First(p => p.NrCrt == 18).ValueField = "2";
            taxIndicators.First(p => p.NrCrt == 43).ValueField = "20";

            //string formula = "IF(rd.18-rd.43<0;-(rd.18-rd.43);0)";
            //string formula = "IF(rd.18-rd.43<0;rd.18-rd.43;0)";
            formula = "IF(rd.18-rd.43<0;-rd.18+rd.43;0)";
            taxFormula = new TaxFormula(formula);
            rez = taxFormula.Execute(taxIndicators);
            if (rez != 18)
            {
                throw new Exception();
            }

            taxIndicators.First(p => p.NrCrt == 18).ValueField = "2";
            taxIndicators.First(p => p.NrCrt == 43).ValueField = "20";

            formula = "IF(rd.18-rd.43<0;-(rd.18-rd.43);0)";
            //string formula = "IF(rd.18-rd.43<0;rd.18-rd.43;0)";
            //formula = "IF(rd.18-rd.43<0;-rd.18+rd.43;0)";
            taxFormula = new TaxFormula(formula);
            rez = taxFormula.Execute(taxIndicators);
            if (rez != 18)
            {
                throw new Exception();
            }

            taxIndicators.First(p => p.NrCrt == 18).ValueField = "20";
            taxIndicators.First(p => p.NrCrt == 43).ValueField = "2";

            formula = "IF(rd.18-rd.43<0;-(rd.18-rd.43);0)";
            //string formula = "IF(rd.18-rd.43<0;rd.18-rd.43;0)";
            //formula = "IF(rd.18-rd.43<0;-rd.18+rd.43;0)";
            taxFormula = new TaxFormula(formula);
            rez = taxFormula.Execute(taxIndicators);
            if (rez != 0)
            {
                throw new Exception();
            }
        }
Exemple #4
0
        private void Test9_2()
        {
            taxIndicators.First(p => p.NrCrt == 1).ValueField = "20";
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "4";

            //string formula = "rd.(1-2)";//4 -3=1
            string formula = "IF((C1>C2);C1;C2)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != 20)
            {
                throw new Exception();
            }
        }
Exemple #5
0
        private void Test9_4()
        {
            taxIndicators.First(p => p.NrCrt == 1).ValueField = "-20";

            string formula = "IF(C1>0;0;-C1)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != 20)
            {
                throw new Exception();
            }
        }
Exemple #6
0
        private void Test62()
        {
            taxIndicators.First(p => p.NrCrt == 1).ValueField = "5";
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "11";

            //string formula = "rd.(1-2)";//4 -3=1
            string formula = "IF(C2-C1>0;C2-C1;0)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != 6)
            {
                throw new Exception();
            }
        }
Exemple #7
0
        private void Test8()
        {
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "2";
            taxIndicators.First(p => p.NrCrt == 5).ValueField = "4";

            //string formula = "rd.(1-2)";//4 -3=1
            string formula = "IF(C2*2%>0;C2*2%;0)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != (decimal)0.04)
            {
                throw new Exception();
            }
        }
        private bool ExecuteTaxCalculation(bool hasChanged, TaxIndicatorViewModel item)
        {
            TaxFormula taxFormula = null;
            try
            {
                if (string.IsNullOrEmpty(item.IndicatorFormula))
                {
                    item.SetError("formula goala");
                }
                taxFormula = new TaxFormula(item.IndicatorFormula);
            }
            catch (Exception ex)
            {
                item.SetError("eroare la interpretarea formulei");
            }
            try
            {

                var newValue = taxFormula.Execute(TaxIndicators.ToList()).ToString();
                if (item.ValueField != newValue)
                {
                    hasChanged = true;
                }
                item.ValueField = newValue;
            }
            catch (Exception ex)
            {
                item.SetError("formula invalida");
            }
            return hasChanged;
        }
Exemple #9
0
        private void Test5()
        {
            taxIndicators.First(p => p.NrCrt == 1).ValueField = "5";
            taxIndicators.First(p => p.NrCrt == 2).ValueField = "1";
            taxIndicators.First(p => p.NrCrt == 3).ValueField = "2";
            taxIndicators.First(p => p.NrCrt == 4).ValueField = "3";
            taxIndicators.First(p => p.NrCrt == 5).ValueField = "4";

            //string formula = "rd.(1-2)";//4 -3=1
            string formula = "rd.(1-2) -rd.(3-4+5)";
            TaxFormula taxFormula = new TaxFormula(formula);
            var rez = taxFormula.Execute(taxIndicators);
            if (rez != 1)
            {
                throw new Exception();
            }
        }
        private bool ExecuteTaxCalculation(bool hasChanged, TaxIndicatorViewModel item)
        {
            hasChanged = false;
            TaxFormula taxFormula = null;
            item.IsIndicatorValid();
            taxFormula = new TaxFormula(item.IndicatorFormula);
            var newValueString = DecimalConvertor.Instance.DecimalToString(taxFormula.Execute(TaxIndicators.ToList()), 0);
            if (item.ValueField != newValueString)
            {
                hasChanged = true;
            }
            item.ValueField = newValueString;

            return hasChanged;
        }
        private bool ExecuteTaxCalculation(bool hasChanged, TaxIndicatorViewModel item)
        {
            TaxFormula taxFormula = null;
            try
            {
                if (string.IsNullOrEmpty(item.IndicatorFormula))
                {
                    item.SetError("formula goala");
                }
                taxFormula = new TaxFormula(item.IndicatorFormula);
            }
            catch (Exception ex)
            {
                //item.SetError(Constants.RulesText);
                item.SetError("eroare la interpretarea formulei");
            }
            try
            {

                var newValueString = DecimalConvertor.Instance.DecimalToString(taxFormula.Execute(TaxIndicators.ToList()), nrDecimals);
                //var newValue = taxFormula.Execute(TaxIndicators.ToList()).ToString();
                if (item.ValueField != newValueString)
                {
                    hasChanged = true;
                }
                newValueString = newValueString.Replace(".", string.Empty);
                item.ValueField = newValueString;
            }
            catch (Exception ex)
            {
                item.SetError("formula invalida");
            }
            return hasChanged;
        }
 public ElseStatement(string statement)
 {
     Result = new TaxFormula(statement);
 }
        private void ParseCondition()
        {
            //C31-C33>0
            string op = "";
            string leftStr = "";
            string rightStr = "";

            //extract the condition parts
            GetOperatorAndComparisonMembers(ifCondition, ref op, ref leftStr, ref rightStr);

            Operator = op;

            Left = new TaxFormula(leftStr);
            Right = new TaxFormula(rightStr);
        }
 public ThenStatement(string statement)
 {
     Result = new TaxFormula(statement);
 }