Esempio n. 1
0
            public List <Models.MViewModels.MViewEndingAccountsBalance> GetAll()
            {
                List <Models.MViewModels.MViewEndingAccountsBalance> Get = new List <Models.MViewModels.MViewEndingAccountsBalance>();

                Classes.CBankOfAccount     cb          = new CBankOfAccount();
                List <Models.MBankAccount> BankAccount = new List <Models.MBankAccount>();

                BankAccount = cb.GetAll();
                for (int i = 0; i < BankAccount.Count; i++)
                {
                    string AccountNumber = string.Empty;
                    string Debit         = string.Empty;
                    string Credit        = string.Empty;
                    AccountNumber = BankAccount[i].accountNumber + "-" + BankAccount[i].Accounttitle;
                    if (Convert.ToSingle(BankAccount[i].Balance) < 0)
                    {
                        Debit  = BankAccount[i].Balance.ToString();
                        Credit = "0";
                    }
                    else
                    {
                        Credit = BankAccount[i].Balance.ToString();
                        Debit  = "0";
                    }
                    Models.MViewModels.MViewEndingAccountsBalance mv = new Models.MViewModels.MViewEndingAccountsBalance();
                    mv.Accounts = AccountNumber;
                    mv.Debit    = Debit;
                    mv.Crerdit  = Credit;
                    Get.Add(mv);
                }

                return(Get);
            }
Esempio n. 2
0
            public List <Models.MViewModels.MViewPaymentHistory> GetPaymentHistory(int OrderId)
            {
                List <Models.MViewModels.MViewPaymentHistory> PaymentHistory = new List <Models.MViewModels.MViewPaymentHistory>();
                List <Models.MPayments>   Payments     = new List <Models.MPayments>();
                List <Models.PaymentLine> PaymentsLine = new List <Models.PaymentLine>()
                , tempPaymentsLine = new List <Models.PaymentLine>();

                Classes.CPayment       cp  = new CPayment();
                Classes.CPaymentLine   cpl = new CPaymentLine();
                Classes.CBankOfAccount cb  = new CBankOfAccount();
                Classes.CCashAccount   cca = new CCashAccount();
                Payments     = cp.GetAll();
                Payments     = Payments.Where(o => o.OrderId == OrderId).ToList();
                PaymentsLine = cpl.GetAll();
                for (int i = 0; i < Payments.Count; i++)
                {
                    tempPaymentsLine.Clear();
                    tempPaymentsLine = PaymentsLine.Where(o => o.PaymentId == Payments[i].id).ToList();
                    float CummulativePayment = 0;
                    for (int j = 0; j < tempPaymentsLine.Count; j++)
                    {
                        Models.MViewModels.MViewPaymentHistory ph = new Models.MViewModels.MViewPaymentHistory();
                        string AccountName = string.Empty;
                        if (tempPaymentsLine[j].ModeOfPayment == Common.Constants.ModeOfPayment.Cheque.ToString())
                        {
                            AccountName = cb.GetAccountNumberAccountTileById(tempPaymentsLine[j].BankId);
                        }
                        if (tempPaymentsLine[j].ModeOfPayment == Common.Constants.ModeOfPayment.Cash.ToString())
                        {
                            AccountName = cca.GetAccountNameById(tempPaymentsLine[j].BankId);
                        }
                        ph.AccountName        = AccountName;
                        ph.ChequeNumber       = tempPaymentsLine[j].Cheque;
                        ph.Date               = tempPaymentsLine[j].Date;
                        ph.ModeOfPayment      = tempPaymentsLine[j].ModeOfPayment;
                        ph.PaidAmount         = tempPaymentsLine[j].PaidAmount;
                        CummulativePayment   += Convert.ToSingle(tempPaymentsLine[j].PaidAmount);
                        ph.CummulativePayment = CummulativePayment.ToString();
                        PaymentHistory.Add(ph);
                    }
                }
                return(PaymentHistory);
            }
Esempio n. 3
0
        public List <Models.MAccountTransactionsView> GetAllViewAccounts()
        {
            Classes.CBankOfAccount cab = new CBankOfAccount();
            List <Models.MAccountTransactionsView> GetAccounts = new List <Models.MAccountTransactionsView>();
            var query = from o in obj.AccountTransactions select o;

            foreach (var item in query)
            {
                Models.MAccountTransactionsView mav = new Models.MAccountTransactionsView();
                mav.AccountId = item.AccountId.ToString();
                string[] AccountDetails = cab.GetAccountNumberAccountTileById(Convert.ToInt32(item.AccountId)).ToString().Split('-');
                mav.AccountNumber = AccountDetails[0];
                mav.AccountTitle  = AccountDetails[1];
                mav.Credit        = Common.DynamicCaller.ConvertToDouble(item.Credit.ToString()).ToString();
                mav.Debit         = Common.DynamicCaller.ConvertToDouble(item.Debit.ToString()).ToString();
                mav.Description   = item.Description;
                mav.Total         = Common.DynamicCaller.ConvertToDouble(item.Total.ToString()).ToString();
                mav.eDate         = item.eDate.ToString();
                mav.FiscalYearId  = item.FiscalYearId.ToString();
                GetAccounts.Add(mav);
            }
            return(GetAccounts);
        }
Esempio n. 4
0
        public int RevertSingleTransaction(int TransactionId, int Units, int ProductId)
        {
            try
            {
                var TransactionType = (from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o.TransactionType).FirstOrDefault();
                var PaymentId = (from o in obj.Payments
                                 where o.TransactionId == TransactionId
                                 select o.id).FirstOrDefault();
                var DataPaymentLine = from o in obj.PaymentLines
                                      where o.PaymentId == Convert.ToInt32(PaymentId)
                                      select o;
                var AccountType = (from o in obj.Payments
                                   join paymentLine in obj.PaymentLines
                                   on o.id equals paymentLine.PaymentId
                                   select paymentLine.ModeOfPayment);
                string AccountId = string.Empty;


                Classes.CPayment         cp        = new CPayment();
                Models.MPayments         mp        = new Models.MPayments();
                Classes.CInventory       ci        = new CInventory();
                List <Models.MInventory> Inventory = new List <Models.MInventory>();
                Classes.CProducts        cpr       = new CProducts();

                Inventory = ci.GetAll();
                string CostPrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.CostPrice).FirstOrDefault();
                string SalePrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.SalePrice).FirstOrDefault();
                switch (TransactionType)
                {
                case "Addition":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits - Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    obj.SubmitChanges();
                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = Amount;
                        mct.Debit         = "0";
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }

                    break;
                }

                case "Deduction":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits + Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);


                        //cash account transation
                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = "0";
                        mct.Debit         = Amount;
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }
                    break;
                }

                default:
                    break;
                }

                //deletin Transaction
                var transactions = from o in obj.Transaction1s
                                   where o.id == TransactionId
                                   select o;
                foreach (var item in transactions)
                {
                    obj.Transaction1s.DeleteOnSubmit(item);
                }
                //deleting Payment lines
                foreach (var item in DataPaymentLine)
                {
                    obj.PaymentLines.DeleteOnSubmit(item);
                }
                obj.SubmitChanges();
                //deleting payments
                mp.id = Convert.ToInt32(PaymentId);
                cp.Delete(mp);
                return(1);
            }
            catch
            {
                return(-1);
            }
        }
Esempio n. 5
0
        public int RevertSingleTransaction(int TransactionId)
        {
            try
            {
                var TransactionType = (from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o.TransactionType).FirstOrDefault();
                var AmountPaid = (from o in obj.Payments
                                  where o.TransactionId == TransactionId
                                  select o.Paid).FirstOrDefault();
                var ProductId = (from o in obj.Transaction1s
                                 where o.id == TransactionId
                                 select o.ProductID).FirstOrDefault();
                var Units = (from o in obj.Transaction1s
                             where o.id == TransactionId
                             select o.units).FirstOrDefault();
                var PaymentId = (from o in obj.Payments
                                 where o.TransactionId == TransactionId
                                 select o.id).FirstOrDefault();
                var AccountId = (from o in obj.PaymentLines
                                 where o.PaymentId == Convert.ToInt32(PaymentId)
                                 select o.BankId).FirstOrDefault();
                var DataPaymentLine = from o in obj.PaymentLines
                                      where o.PaymentId == Convert.ToInt32(PaymentId)
                                      select o;

                //deleting Payment lines
                foreach (var item in DataPaymentLine)
                {
                    obj.PaymentLines.DeleteOnSubmit(item);
                }
                obj.SubmitChanges();

                //deleting Payments
                Classes.CPayment cp = new CPayment();
                Models.MPayments mp = new Models.MPayments();
                mp.id = Convert.ToInt32(PaymentId);
                cp.Delete(mp);



                Classes.CInventory       ci        = new CInventory();
                List <Models.MInventory> Inventory = new List <Models.MInventory>();
                Inventory = ci.GetAll();
                switch (TransactionType.ToString())
                {
                case "Addition":
                {
                    Classes.CBankOfAccount cb = new CBankOfAccount();

                    if (AccountId != null)
                    {
                        //Reverting Account
                        float OldTotal = cb.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(AmountPaid);
                        cb.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        Models.MAccountTransaction  mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = AmountPaid.ToString();
                        mat.Debit        = "0";
                        mat.Description  = "Reverted Purchase Transaction";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cb.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }



                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits - Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();

                    //deletin Transaction
                    var transactions = from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o;
                    foreach (var item in transactions)
                    {
                        obj.Transaction1s.DeleteOnSubmit(item);
                    }
                    obj.SubmitChanges();
                    break;
                }

                case "Deduction":
                {
                    Classes.CBankOfAccount cb = new CBankOfAccount();

                    if (AccountId != null)
                    {
                        //Reverting Account
                        float OldTotal = cb.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(AmountPaid);
                        cb.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        Models.MAccountTransaction  mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = AmountPaid.ToString();
                        mat.Description  = "Reverted Sale Transaction";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cb.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }


                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits + Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    //deletin Transaction
                    var transactions = from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o;
                    foreach (var item in transactions)
                    {
                        obj.Transaction1s.DeleteOnSubmit(item);
                    }
                    obj.SubmitChanges();
                    break;
                }

                default:
                    break;
                }

                return(1);
            }
            catch
            {
                return(-1);
            }
        }