Ejemplo n.º 1
0
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {
            // Get version of model from document
            CalculationModel model = new CalculationModel();

            LabelVersion.Label = model.Version;

            // Disable publish and test buttons if appropriate settings are not configured
            ButtonPublish.Enabled = !(Globals.ThisWorkbook.ReadDocumentProperty("OLM_UrlTest") == "") && !(Globals.ThisWorkbook.ReadDocumentProperty("OLM_NetworkLocation") == "");
            ButtonTest.Enabled    = !(Globals.ThisWorkbook.ReadDocumentProperty("OLM_UrlTest") == "");

            // Hide Link-to-Assessment Button for third parties
            if (Globals.ThisWorkbook.ReadDocumentProperty("OLM_ShowLinkButton") != "Y")
            {
                ButtonLinkToAssessment.Visible = false;
            }

            // TODO: Check server version compatibility
            // Check compatibility with server version#
            if (!model.CompatibleWithServer())
            {
                // The method will display dialogs
                // If we failed, then close application
                Globals.ThisWorkbook.Close();
            }
        }
Ejemplo n.º 2
0
        public IActionResult Calculate(CalculationModel dataModel)
        {
            ViewBag.Message = dataModel.FirstNumber + dctOperator[dataModel.Operation] + dataModel.SecondNumber + " = "
                              + dctOperation[dataModel.Operation].DynamicInvoke(Decimal.Parse(dataModel.FirstNumber), Decimal.Parse(dataModel.SecondNumber));

            return(View("Index"));
        }
Ejemplo n.º 3
0
        public IActionResult Calculate(CalculationModel dataModel)
        {
            ViewBag.Message = dctOperator[dataModel.Operation] + "(" + dataModel.FirstNumber + ") = "
                              + dctOperation[dataModel.Operation].DynamicInvoke(Double.Parse(dataModel.FirstNumber));

            return(View("Index"));
        }
Ejemplo n.º 4
0
        private void ResetButton_Click(object sender, RibbonControlEventArgs e)
        {
            // Reset all input form values to defaults
            CalculationModel model = new CalculationModel();

            model.Reset();
        }
Ejemplo n.º 5
0
        public void ModuleCalculationByProffixMode(string[] arguments)
        {
            settingTabPage.PageVisible     = false;
            generalTabPage.PageVisible     = true;
            calculationTabPage.PageVisible = false;
            mainTabControl.SelectedTabPage = generalTabPage;

            //if call from proffix, arguments should not null
            ProffixModel oProffix = new ProffixModel();

            oProffix.SetModel(arguments);
            generalCtrl1.SetProffixParam(oProffix, _PriceCalculationSetting.ProffixConnection);

            if (oProffix.IsLoad)
            {
                //load cal setting from db
                CalculationModel oCal = StorageOperator.CalPriceLoadByID(Convert.ToInt64(oProffix.CalculationID));
                calculationTabPage.PageVisible = true;

                generalCtrl1.LoadCalculation(oCal);

                ReloadPriceCalculationSetting(true);
                calculationBasicCtrl1.LoadCalculation(oCal, _PriceCalculationSetting);
            }
        }
Ejemplo n.º 6
0
        public void UpdateRowAmountFix(CalculationModel model, CalculationItemModel calRow, decimal value, bool skipBaseGroupRows = false)
        {
            //decimal iBaseAmount = model.MasterAmount;
            decimal iBaseAmount = model.CalculationViewItems.Where(item => item.Group == calRow.Group && item.IsSummary).LastOrDefault().Total;

            //if (!skipBaseGroupRows)
            //{
            //    //get summary from group's total row
            //    iBaseAmount = GetCalculationBaseSummaryGroups(model, calRow);
            //}

            //calculate
            //must set value first
            calRow.AmountFix = value;
            if (iBaseAmount > 0)
            {
                //get summary from all item by particular group
                decimal iSummaryAllItems = model.CalculationViewItems.FindAll(item => item.Group == calRow.Group && !item.IsSummary).Sum(item => item.AmountFix);

                //(x / (99 - x) * 100) = y
                //x is value
                //99 is base amount
                //y is resut (amount percent0
                calRow.AmountPercent = (value / (iBaseAmount - iSummaryAllItems)) * 100;
                //calRow.AmountPercent = (value / (iBaseAmount - value)) * 100;
            }
            calRow.Total = calRow.AmountFix;
        }
Ejemplo n.º 7
0
        static void SaveLAG_Artikel(CalculationModel model)
        {
            //save or update
            //update value
            DataTable dt = new DataTable();

            dt.TableName = "LAG_Artikel";
            dt.Columns.Add(new DataColumn("ArtikelNrLAG", typeof(string)));
            dt.Columns.Add(new DataColumn("Verkauf5", typeof(float)));
            DataRow dr = dt.NewRow();

            dt.Rows.Add(dr);

            //scale calculation note id start from 1
            dr["ArtikelNrLAG"] = model.ProffixModel.LAGDokumenteArtikelNrLAG;
            dr["Verkauf5"]     = model.CalculationNotes[1].CalculationItems.Where(item => item.Tag == "VK(liste)").FirstOrDefault().Total;

            //update proffix
            UpdateRow(
                dr,
                dt.Columns["ArtikelNrLAG"],
                new List <DataColumn>()
            {
                dt.Columns["Verkauf5"]
            },
                connectionString: model.ProffixConnection);
        }
Ejemplo n.º 8
0
        public IActionResult Calculate(CalculationModel calculationModel)
        {
            ViewData["Message"] = "Select your calculation type and provide two probabilities...";

            // Ensure that subsequent don't mislead by showing old results.
            calculationModel.Output = null;

            if (ModelState.IsValid)
            {
                var result = _calculatorService.PerformCalculation(calculationModel.Type, calculationModel.Probability1, calculationModel.Probability2);

                if (result.Success)
                {
                    calculationModel.Output = result.Output;
                    return(View(calculationModel));
                }
                else
                {
                    foreach (string error in result.Errors)
                    {
                        ModelState.AddModelError("CalculationFailure", error);
                    }
                }
            }

            return(View(calculationModel));
        }
Ejemplo n.º 9
0
        public void OnDialogOpened(IDialogParameters parameters)
        {
            var list = parameters.GetValue <List <BookIraModel> >("collection");

            Calculation = new CalculationModel
            {
                IznosSPdv            = list.Sum(x => x.IznosSPdv),
                OslobodjenoPdvEU     = list.Sum(x => x.OslobodjenoPdvEU),
                OslobodjenoPdvOstalo = list.Sum(x => x.OslobodjenoPdvOstalo),
                ProlaznaStavka       = list.Sum(x => x.ProlaznaStavka),
                PoreznaOsnovica0     = list.Sum(x => x.PoreznaOsnovica0),
                PoreznaOsnovica5     = list.Sum(x => x.PoreznaOsnovica5),
                PoreznaOsnovica10    = list.Sum(x => x.PoreznaOsnovica10),
                PoreznaOsnovica13    = list.Sum(x => x.PoreznaOsnovica13),
                PoreznaOsnovica23    = list.Sum(x => x.PoreznaOsnovica23),
                PoreznaOsnovica25    = list.Sum(x => x.PoreznaOsnovica25),
                Pdv5      = list.Sum(x => x.Pdv5),
                Pdv10     = list.Sum(x => x.Pdv10),
                Pdv13     = list.Sum(x => x.Pdv13),
                Pdv23     = list.Sum(x => x.Pdv23),
                Pdv25     = list.Sum(x => x.Pdv25),
                UkupniPdv = list.Sum(x => x.UkupniPdv)
            };
            Calculation.OsnovicaUkupno = Calculation.PoreznaOsnovica5
                                         + Calculation.PoreznaOsnovica13
                                         + Calculation.PoreznaOsnovica25;
        }
Ejemplo n.º 10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CalculationModel model       = new CalculationModel();
            List <string[]>  resultsList = new List <string[]>();

            // Test model and return list of results
            resultsList = model.Test();

            if (resultsList == null)
            {
                this.Close();
                this.Dispose();
            }
            else
            {
                // Bind list to datagridview
                foreach (string[] rowArray in resultsList)
                {
                    this.DataGridViewResults.Rows.Add(rowArray);
                }

                // Highlight errors
                foreach (DataGridViewRow dgvrow in DataGridViewResults.Rows)
                {
                    if ((string)dgvrow.Cells[3].Value == model.NotMatchText)
                    {
                        dgvrow.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void OnDialogOpened(IDialogParameters parameters)
        {
            var list = parameters.GetValue <List <BookUraRestModel> >("collection");

            Calculation = new CalculationModel
            {
                ZaUplatu          = list.Sum(x => x.ZaUplatu),
                PoreznaOsnovica0  = list.Sum(x => x.PoreznaOsnovica0),
                PoreznaOsnovica5  = list.Sum(x => x.PoreznaOsnovica5),
                PoreznaOsnovica10 = list.Sum(x => x.PoreznaOsnovica10),
                PoreznaOsnovica13 = list.Sum(x => x.PoreznaOsnovica13),
                PoreznaOsnovica23 = list.Sum(x => x.PoreznaOsnovica23),
                PoreznaOsnovica25 = list.Sum(x => x.PoreznaOsnovica25),
                PretporezT5       = list.Sum(x => x.PretporezT5),
                PretporezT10      = list.Sum(x => x.PretporezT10),
                PretporezT13      = list.Sum(x => x.PretporezT13),
                PretporezT23      = list.Sum(x => x.PretporezT23),
                PretporezT25      = list.Sum(x => x.PretporezT25),
                UkupniPretporez   = list.Sum(x => x.UkupniPretporez),
                IznosSPorezom     = list.Sum(x => x.IznosSPorezom)
            };
            Calculation.OsnovicaUkupno = Calculation.PoreznaOsnovica5
                                         + Calculation.PoreznaOsnovica13
                                         + Calculation.PoreznaOsnovica25;
        }
Ejemplo n.º 12
0
        public double CalculateNetPresentValue(CalculationModel calculationModel)
        {
            if (calculationModel.CashFlows == null || calculationModel.CashFlows.Count == 0)
            {
                return(0);
            }

            double netPresentValue = 0;

            double discountRateIncrement = 0;

            foreach (var cashFlow in calculationModel.CashFlows)
            {
                var discountRate = cashFlow.Year == 1 ? calculationModel.LowerBoundDiscountRate : calculationModel.LowerBoundDiscountRate + discountRateIncrement;

                netPresentValue += cashFlow.Value / Math.Pow(1 + discountRate / 100d, cashFlow.Year);

                discountRateIncrement += calculationModel.DiscountRateIncrement;

                if (calculationModel.UpperBoundDiscountRate == discountRateIncrement)
                {
                    break;
                }
            }

            var netPresentValueResult = Math.Round(netPresentValue - Convert.ToDouble(Math.Abs(calculationModel.InitialCost)), 2);

            return(netPresentValueResult);
        }
Ejemplo n.º 13
0
        // Calculates recommended intake and returns it as result.
        public ActionResult Index(CalculationModel cm)
        {

            if (ModelState.IsValid)
            {
                if (cm.Gender == "Male")
                {
                    cm.Result = 10 * cm.Weight + 6.25 * cm.Height - 5 * cm.Age + 5;
                }
                else
                {
                    cm.Result = 10 * cm.Weight + 6.25 * cm.Height - 5 * cm.Age - 161;
                }
            }

            if (cm.Age <= 0)
            {
                cm.ResultAdd1000 = cm.Result + 1000;
                cm.ResultAdd500 = cm.Result + 800;
                cm.ResultMinus1000 = cm.Result + 600;
                cm.ResultMinus500 = cm.Result + 500;
                cm.Result = cm.Result + 700;     
            }
            else
            {
                cm.ResultAdd1000 = cm.Result + 1000;
                cm.ResultAdd500 = cm.Result + 500;
                cm.ResultMinus1000 = cm.Result - 1000;
                cm.ResultMinus500 = cm.Result - 500;
            }
            return View(cm);
        }
        public CalculationModel Calculate(List <QuoteDTO> quotes)
        {
            var symbol = quotes.FirstOrDefault()?.Symbol;

            if (string.IsNullOrEmpty(symbol))
            {
                throw new ArgumentException("Symbol can not be null.");
            }

            var orderedQuotes = quotes
                                .OrderBy(x => x.Date)
                                .ToList();

            var result = new CalculationModel(symbol);

            decimal based = 0;

            for (int i = 0; i < orderedQuotes.Count; i++)
            {
                if (i == 0)
                {
                    result.Items.Add(new CalculationItem(orderedQuotes[0].Date, 0));

                    based = orderedQuotes[0].Close;

                    continue;
                }

                result.Items.Add(new CalculationItem(orderedQuotes[i].Date, (orderedQuotes[i].Close - based) / based * 100));
            }

            return(result);
        }
Ejemplo n.º 15
0
        public void UpdateRowAmountPercent(CalculationModel model, CalculationItemModel calRow, decimal value, bool skipBaseGroupRows = false)
        {
            //decimal iBaseAmount = model.MasterAmount;
            decimal iBaseAmount = model.CalculationViewItems.Where(item => item.Group == calRow.Group && item.IsSummary).LastOrDefault().Total;

            //x*100 + 0.01*100 = 9900
            //x is value
            //100 is fix number (from 100 percent)
            //0.01 is x as percentage (eg 1/100)
            //9900 is base amount

            //101x = 9900
            //x = 9900 / 101 = 98.0198
            if (value > 0)
            {
                //must set value first
                calRow.AmountPercent = value;

                //get summary from all item by particular group
                decimal iSummaryAllItems = model.CalculationViewItems.FindAll(item => item.Group == calRow.Group && !item.IsSummary).Sum(item => item.AmountPercent);

                //calculation
                decimal iCalculation = (iBaseAmount * 100) / (100 + iSummaryAllItems) * (value / 100);
                calRow.AmountFix = iCalculation;
                calRow.Total     = iCalculation;
            }
        }
        public static void SaveProffix(CalculationModel model)
        {
            if (model.ProffixModel == null)
            {
                return;
            }

            if (String.IsNullOrWhiteSpace(model.ProffixModel.LAGDokumenteArtikelNrLAG))
            {
                return;
            }

            //1. save LAG_Dokumente
            SaveLAG_Dokumente(model);

            //2. save LAG_Artikel
            if (model.GeneralSetting.PriceScale.Scale == 1 && model.GeneralSetting.Options.Contains("A"))
            {
                SaveLAG_Artikel(model);
            }

            //3. save scale if needed
            if (model.GeneralSetting.PriceScale.Scale > 1 && model.GeneralSetting.Options.Contains("A"))
            {
                SavePRE_PreisStaffel(model);
            }
        }
Ejemplo n.º 17
0
        private void Init()
        {
            // Set flag to hide integration properties settings
            //bool showIntegration = true;

            //Initialise grid headers
            this.DataGridViewConfig.ColumnCount           = 2;
            this.DataGridViewConfig.ColumnHeadersVisible  = true;
            this.DataGridViewConfig.Columns[0].HeaderText = "Property";
            this.DataGridViewConfig.Columns[1].HeaderText = "Value";

            //And col widths
            this.DataGridViewConfig.Columns[0].Width = 200;
            this.DataGridViewConfig.Columns[1].Width = 200;

            // Update document properties with editted values
            CalculationModel model       = new CalculationModel();
            List <string[]>  configTable = new List <string[]>();

            // Get list of properties
            configTable = Globals.ThisWorkbook.GetAllConfigProperties();

            // Bind list to DataGridView
            foreach (string[] row in configTable)
            {
                // If ShowLinkButton is not 'Y' then don't show Integration Properties
                if ((row[0] == "OLM_ShowLinkButton") && (row[1] != "Y"))
                {
                    ShowIntegration = false;
                }
                this.DataGridViewConfig.Rows.Add(row);
            }

            // Remove integration properties
            if (ShowIntegration == false)
            {
                removeIntegrationSettings();
            }

            // Highlight unset values
            foreach (DataGridViewRow row in DataGridViewConfig.Rows)
            {
                if ((string)row.Cells[1].Value == "")
                {
                    // Highlight the row
                    row.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
                }
            }

            // Make column [1] in grid editable
            this.DataGridViewConfig.EditMode            = DataGridViewEditMode.EditOnEnter;
            this.DataGridViewConfig.Columns[0].ReadOnly = true;

            // Disallow adding new rows
            this.DataGridViewConfig.AllowUserToAddRows = false;

            // Disable OK button if any cells are still empty
            int emptyRowCount = EmptyRowCount();
        }
        private static decimal CalculatePackage(int year, decimal consumption, CalculationModel calculationModel)
        {
            decimal result = GetBaseCost(year, calculationModel);

            result += GetPackageConsumption(consumption, calculationModel);

            return(result);
        }
Ejemplo n.º 19
0
        private void getVersion()
        {
            CalculationModel model = new CalculationModel();

            LabelProductVersion.Text = model.ProductVersion;
            LabelServerVersion.Text  = "Contacting Server...";
            this.Refresh();
        }
        private static decimal CalculateBasic(int year, decimal consumption, CalculationModel calculationModel)
        {
            decimal baseCost = GetBaseCost(year, calculationModel);

            decimal basicConsumption = GetBasicConsumption(consumption, calculationModel.ConsumptionCost);

            return(baseCost + basicConsumption);
        }
Ejemplo n.º 21
0
        public ActionResult Index()
        {
            var model     = new CalculationModel();
            var customers = customerService.GetAllCustomer();

            customerSearchModels = customers.Select(p => mapper.Map <CustomerDto, CustomerSearchModel>(p)).ToList();
            return(View(model));
        }
Ejemplo n.º 22
0
        public void LoadCalculation(CalculationModel model)
        {
            if (model == null)
            {
                return;
            }

            if (model != null)
            {
                rdoCostTypeList.EditValue = model.GeneralSetting.CostType;
                rdoCostTypeList.Enabled   = true;

                // M R A
                chkOptionList.Items["M"].Enabled    = false;
                chkOptionList.Items["M"].CheckState = model.GeneralSetting.Options.Contains("M") ? CheckState.Checked : CheckState.Unchecked;
                chkOptionList.Items["R"].CheckState = model.GeneralSetting.Options.Contains("R") ? CheckState.Checked : CheckState.Unchecked;
                chkOptionList.Items["A"].CheckState = model.GeneralSetting.Options.Contains("A") ? CheckState.Checked : CheckState.Unchecked;

                //text line group
                layoutControlGroup3.Enabled = false;

                //price scale group
                layoutControlGroup5.Enabled   = false;
                rdoAmountMarkupList.EditValue = model.GeneralSetting.PriceScale.MarkUp;
                numPriceScale.Value           = model.GeneralSetting.PriceScale.Scale;
                txtMinProfit.Text             = model.GeneralSetting.PriceScale.MinProfit.ToString();
                txtMaxProfit.Text             = model.GeneralSetting.PriceScale.MaxProfit.ToString();

                //convert
                rdoUnitList.EditValue = model.GeneralSetting.Convert.Mode;
                txtSaleUnit.Text      = model.GeneralSetting.Convert.SaleUnit;
                txtShopUnit.Text      = model.GeneralSetting.Convert.ShopUnit;
                txtUnitNumber.Text    = model.GeneralSetting.Convert.UnitNumber.ToString();

                //currency
                rdoCurrencyList.EditValue = model.GeneralSetting.Currency.Mode;
                txtConvertCurrency.Text   = model.GeneralSetting.Currency.Currency != "CHF" ? model.GeneralSetting.Currency.Currency : txtConvertCurrency.Text;
                txtExchangeRate.Text      = model.GeneralSetting.Currency.Rate.ToString();

                //txtRemark.Text = oCal.GeneralSetting.Remark;
                txtInfo.Text       = model.GeneralSetting.Info;
                txtEmployee.Text   = model.GeneralSetting.Employee;
                dtCreate.EditValue = model.GeneralSetting.CreateDate;

                try
                {
                    for (int i = 0; i < ddSupplier.Properties.Items.Count; i++)
                    {
                        if (((ComboboxItemModel)ddSupplier.Properties.Items[i]).Caption == model.GeneralSetting.Supplier)
                        {
                            ddSupplier.SelectedIndex = i;
                            break;
                        }
                    }
                }
                catch { }
            }
        }
 public async Task WriteCalculationLogAsync(CalculationModel calculationModel)
 {
     using (var sw = new StreamWriter(calculationLogPath, true))
     {
         await sw.WriteLineAsync($"Operation {calculationModel.FirstNumber} {calculationModel.OperationSign}" +
                                 $" {calculationModel.SecondNumber} = {calculationModel.Result} " +
                                 $"was executed on {DateTime.Now.ToLongDateString()}, at {DateTime.Now.ToShortTimeString()}");
     }
 }
Ejemplo n.º 24
0
        public void ConstructorTestParams_InitialisesCorrectly()
        {
            Models.CalculationModel model = new CalculationModel("3", "500", "+");

            Assert.AreEqual(model.FirstOperand, "3");
            Assert.AreEqual(model.SecondOperand, "500");
            Assert.AreEqual(model.Operation, "+");
            Assert.AreEqual(model.Result, string.Empty);
        }
Ejemplo n.º 25
0
        void UpdateRowAmountPercentSpecial(CalculationModel model, CalculationItemModel calRow, decimal value)
        {
            //decimal iBaseAmount = model.MasterAmount;
            decimal iBaseAmount = model.CalculationViewItems.Where(item => item.Group == calRow.Group && item.IsSummary).LastOrDefault().Total;

            calRow.AmountPercent = value;
            calRow.AmountFix     = (value / 100) * iBaseAmount;
            calRow.Total         = calRow.AmountFix;
        }
Ejemplo n.º 26
0
        public void UpdateGroupAmountAll(CalculationModel model, bool updateGroupOnly)
        {
            var oModels = model.CalculationViewItems.FindAll(item => item.IsSummary);

            foreach (CalculationItemModel item in oModels)
            {
                UpdateGroupAmount(model, item.Group, item.ItemOrder, updateGroupOnly);
            }
        }
Ejemplo n.º 27
0
        public async Task SaveCalculation(CalculationModel calculation, string userId)
        {
            var user = await _oktaClient.Users.GetUserAsync(userId);

            var json = JsonConvert.SerializeObject(calculation);

            user.Profile[ProfileCustomKey] = json;
            await user.UpdateAsync();
        }
Ejemplo n.º 28
0
        public void LoadCalculation(CalculationModel model, PriceCalculationSetting moduleSetting)
        {
            model.ProffixConnection = moduleSetting.ProffixConnection;

            _Model = model;

            //setup everythings
            SetUpCalculation();
        }
Ejemplo n.º 29
0
        /// <inheritdoc />
        public Task LogCalculation(CalculationModel model)
        {
            string log = CreateLog(model);

            using (StreamWriter sw = File.AppendText(_fileLocation))
            {
                return(sw.WriteLineAsync(log));
            }
        }
Ejemplo n.º 30
0
        public void UpdateGroupAmountAll(CalculationModel model, bool updateGroupOnly)
        {
            var oModels = model.CalculationViewItems.FindAll(item => item.CostCalculatonGroup != null);

            //reverse group
            for (int i = oModels.Count(); i > 0; i--)
            {
                UpdateGroupAmount(model, oModels[i - 1], updateGroupOnly);
            }
        }
Ejemplo n.º 31
0
 public ActionResult Index(CalculationModel model)
 {
     model.ResultValue = model.FirstValue + model.SecondValue;
     return View(model);
 }