Exemple #1
0
        public async Task <IActionResult> AccountEntryMajorization(int accountryEntryId)
        {
            var accountingEntry = _context.AccountingEntry.SingleOrDefault(m => m.ID == accountryEntryId);
            var majorization    = new Majorization();

            majorization.AccountingEntryId = accountryEntryId;
            majorization.AccountToDebit    = accountingEntry.AccountToDebit;
            var accountToDebitHigherAccount = (from c in _context.AccountingAccount
                                               where c.ID == accountingEntry.AccountToDebit
                                               select c.HigherAccount).Single();

            majorization.AccountToDebitHigherAccount = accountToDebitHigherAccount;
            majorization.AmountToDebit   = accountingEntry.AmountToDebit * accountingEntry.MoneyCurrencyRate;
            majorization.AccountToCredit = accountingEntry.AccountToCredit;
            var accountToCreditHigherAccount = (from c in _context.AccountingAccount
                                                where c.ID == accountingEntry.AccountToDebit
                                                select c.HigherAccount).Single();

            majorization.AccountToCreditHigherAccount = accountToCreditHigherAccount;
            majorization.AmountToCredit = accountingEntry.AmountToCredit * accountingEntry.MoneyCurrencyRate;
            majorization.ProcessDate    = DateTime.Now;
            majorization.Balance        = accountingEntry.AmountToCredit * accountingEntry.MoneyCurrencyRate;

            return(View(majorization));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, Majorization majorization)
        {
            if (id != majorization.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(majorization);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MajorizationExists(majorization.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(majorization));
        }
Exemple #3
0
        public async Task <IActionResult> Create(Majorization majorization)
        {
            if (ModelState.IsValid)
            {
                _context.Add(majorization);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(majorization));
        }
Exemple #4
0
        public async Task <IActionResult> AccountEntryMajorization(Majorization majorization)
        {
            //Getting of accounting Entry by ID
            var accountingEntry = await _context.AccountingEntry
                                  .SingleOrDefaultAsync(m => m.ID.ToString() == majorization.AccountingEntryId.ToString());

            accountingEntry.IsMajorizationProcessed = 0;
            //Getting of Account to Debit by ID
            var accountToDebit =
                await _context.AccountingAccount.SingleOrDefaultAsync(
                    m => m.ID.ToString() == majorization.AccountToDebit.ToString());

            //Getting of Account to Credit by ID
            var accountToCredit =
                await _context.AccountingAccount.SingleOrDefaultAsync(
                    m => m.ID.ToString() == majorization.AccountToCredit.ToString());

            //Getting of Higher Debit Account by Id
            var higherDebitAccount = await _context.AccountingAccount
                                     .SingleOrDefaultAsync(m => m.ID.ToString() == majorization.AccountToDebitHigherAccount.ToString());

            var higherCreditAccount = await _context.AccountingAccount
                                      .SingleOrDefaultAsync(m => m.ID.ToString() == majorization.AccountToCreditHigherAccount.ToString());


            //If the Higher Debit Account is not level one you need to find the higher account of it
            if (higherDebitAccount.Level == AccountLevels.LevelTwo)
            {
                var higherDebitAccountLevelOne = await _context.AccountingAccount
                                                 .SingleOrDefaultAsync(m => m.ID.ToString() == higherDebitAccount.ID.ToString());

                accountToDebit.Balance -= majorization.AmountToDebit;
                _context.Update(higherDebitAccountLevelOne);
                _context.Update(accountToDebit);
                await _context.SaveChangesAsync();
            }
            else
            {
                accountToDebit.Balance -= majorization.AmountToDebit;
                _context.Update(accountToDebit);
                await _context.SaveChangesAsync();
            }

            //If the Higher Credit Account is not level one you need to find the higher account of it
            if (higherCreditAccount.Level == AccountLevels.LevelTwo)
            {
                var higherCreditAccountLevelOne = await _context.AccountingAccount
                                                  .SingleOrDefaultAsync(m => m.ID.ToString() == higherCreditAccount.ID.ToString());

                accountToCredit.Balance -= majorization.AmountToCredit;
                _context.Update(higherCreditAccountLevelOne);
                _context.Update(accountToCredit);
                await _context.SaveChangesAsync();
            }
            else
            {
                accountToCredit.Balance -= majorization.AmountToCredit;
                _context.Update(accountToCredit);
                await _context.SaveChangesAsync();
            }
            _context.Update(accountingEntry);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "AccountingEntries"));
        }
Exemple #5
0
    public static IEnumerable <double> Conj(int[,] d, Vector2[] positions, double eps = 0.0001, int maxIter = 1000)
    {
        int n = positions.Length;

        // first find the laplacian for the left hand side
        var laplacian_w = new double[n, n];

        Majorization.WeightLaplacian(d, laplacian_w, n);

        // cut out the first row and column
        var Lw = new double[n - 1, n - 1];

        for (int i = 1; i < n; i++)
        {
            for (int j = 1; j < n; j++)
            {
                Lw[i - 1, j - 1] = laplacian_w[i, j];
            }
        }

        // delta = w_ij * d_ij as in Majorization, Gansner et al.
        var deltas = new double[n, n];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                double dist = d[i, j];
                deltas[i, j] = 1.0 / dist;
            }
        }

        var LXt    = new double[n, n];  // the laplacian for the right hand side
        var LXt_Xt = new double[n - 1]; // skip the first position as it's fixed to (0,0)
        var Xt1    = new double[n - 1]; // X(t+1)

        // temporary variables to speed up conjugate gradient
        var r  = new double[n - 1];
        var p  = new double[n - 1];
        var Ap = new double[n - 1];

        double prevStress = GraphIO.CalculateStress(d, positions, n);

        // majorize
        for (int k = 0; k < maxIter; k++)
        {
            PositionLaplacian(deltas, positions, LXt, n);

            // solve for x axis
            Multiply_x(LXt, positions, LXt_Xt);
            ConjugateGradient.Cg(Lw, Xt1, LXt_Xt, r, p, Ap, .1, 10);
            for (int i = 1; i < n; i++)
            {
                positions[i].x = Xt1[i - 1];
            }

            // solve for y axis
            Multiply_y(LXt, positions, LXt_Xt);
            ConjugateGradient.Cg(Lw, Xt1, LXt_Xt, r, p, Ap, .1, 10);
            for (int i = 1; i < n; i++)
            {
                positions[i].y = Xt1[i - 1];
            }

            double stress = GraphIO.CalculateStress(d, positions, n);
            yield return(stress);

            if ((prevStress - stress) / prevStress < eps)
            {
                yield break;
            }
            prevStress = stress;
        }
    }