Esempio n. 1
0
        // returnTotal is AFTER val
        private static void CreateReturn(decimal val, decimal resaleTotal, decimal returnTotal, int acctId, DateTime date, ApplicationDbContext context)
        {
            Transaction t = new Transaction
            {
                AccountId         = acctId,
                Amount            = val,
                Date              = date,
                NewTotal          = val + resaleTotal + returnTotal,
                TransactionTypeId = TransactionType.RETURN_ID
            };

            t = context.Add(t).Entity;
            context.SaveChanges();

            TransactionDistribution td = new TransactionDistribution
            {
                AccountId = acctId,
                Amount    = val,
                NewAccountRevenueTotal = returnTotal + val,
                TransactionId          = t.Id,
                RevenueCodeId          = RevenueCode.RETURN_ID
            };

            context.Add(td);
            context.SaveChanges();
        }
Esempio n. 2
0
        // resaleTotal/returnTotal are BEFORE val
        private static void CreatePurchase(decimal val, decimal resaleTotal, decimal returnTotal, int acctId, DateTime date, ApplicationDbContext context)
        {
            Transaction t = new Transaction
            {
                AccountId         = acctId,
                Amount            = val,
                Date              = date,
                NewTotal          = val + resaleTotal + returnTotal,
                TransactionTypeId = TransactionType.PURCHASE_ID
            };

            t = context.Add(t).Entity;
            context.SaveChanges();

            if (returnTotal + val < 0)
            {
                if (returnTotal > 0)
                {
                    TransactionDistribution td = new TransactionDistribution
                    {
                        AccountId = acctId,
                        Amount    = -returnTotal,
                        NewAccountRevenueTotal = 0,
                        TransactionId          = t.Id,
                        RevenueCodeId          = RevenueCode.RETURN_ID
                    };
                    context.Add(td);
                }

                resaleTotal += returnTotal + val;

                TransactionDistribution resaleTD = new TransactionDistribution
                {
                    AccountId = acctId,
                    Amount    = returnTotal + val,
                    NewAccountRevenueTotal = resaleTotal + returnTotal + val,
                    TransactionId          = t.Id,
                    RevenueCodeId          = RevenueCode.RESALE_ID
                };
                context.Add(resaleTD);
            }
            else
            {
                TransactionDistribution td = new TransactionDistribution
                {
                    AccountId = acctId,
                    Amount    = val,
                    NewAccountRevenueTotal = returnTotal + val,
                    TransactionId          = t.Id,
                    RevenueCodeId          = RevenueCode.RETURN_ID
                };
                context.Add(td);
            }
            context.SaveChanges();
        }
Esempio n. 3
0
        private static void CreateCashout(decimal _, decimal resaleTotal, decimal returnTotal, int acctId, DateTime date, ApplicationDbContext context)
        {
            decimal val = -resaleTotal;

            decimal     baseVal     = Math.Round(val * CASHOUT_DISCOUNT, 2);
            decimal     discountVal = val - baseVal;
            Transaction baseT       = new Transaction
            {
                AccountId         = acctId,
                Amount            = baseVal,
                Date              = date,
                NewTotal          = returnTotal - discountVal,
                TransactionTypeId = TransactionType.CASHOUT_ID
            };

            baseT = context.Add(baseT).Entity;
            context.SaveChanges();

            TransactionDistribution baseTD = new TransactionDistribution
            {
                AccountId = acctId,
                Amount    = baseVal,
                NewAccountRevenueTotal = -discountVal,
                TransactionId          = baseT.Id,
                RevenueCodeId          = RevenueCode.RESALE_ID
            };

            context.Add(baseTD);

            Transaction discountT = new Transaction
            {
                AccountId         = acctId,
                Amount            = discountVal,
                Date              = date,
                NewTotal          = returnTotal,
                TransactionTypeId = TransactionType.CASHOUT_DEDUCTION_ID
            };

            discountT = context.Add(discountT).Entity;
            context.SaveChanges();

            TransactionDistribution discountTD = new TransactionDistribution
            {
                AccountId = acctId,
                Amount    = discountVal,
                NewAccountRevenueTotal = 0M,
                TransactionId          = discountT.Id,
                RevenueCodeId          = RevenueCode.RESALE_ID
            };

            context.Add(discountTD);
            context.SaveChanges();
        }