示例#1
0
        static void Main(string[] args)
        {
            //ProductTransaction aProductTransaction = new ProductTransaction();
            //aProductTransaction.DealID = 1;
            //aProductTransaction.TransactionType = ProductTransactionType.Sale;
            //aProductTransaction.TransactionAmount = 40000;

            SqlConnection con = new ConnectionString().GetConnection();

            con.Open();

            using (con)
            {
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    //new DealDataHelper().UpdateByTransactionAmount(1, 45050, "Sale");
                    new DealHandler().ChangeByRemainingAmount(2, 90000, "Sale", tran);

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }


            Console.WriteLine("Program ended...");
            Console.ReadKey();
        }
示例#2
0
        public int Add(Investment aType)
        {
            int           returnValue = -1;
            int           returnKey;
            SqlConnection con = new ConnectionString().GetConnection();

            FinancialTransactionDataHelper financialTransactionH = new FinancialTransactionDataHelper();
            FinancialTransaction           aTransaction          = new FinancialTransaction();

            aTransaction.ContactID            = aType.InvestorDetails.ID;
            aTransaction.WalletType           = WalletType.Investment;
            aTransaction.Amount               = aType.InHand;
            aTransaction.FlowType             = FlowType.Credit;
            aTransaction.TransactionType      = TransactionType.Cash;
            aTransaction.TransactionReference = aType.Name + " Has Paid inhand amount";
            aTransaction.TransactionDate      = DateTime.Now;

            con.Open();

            using (con)
            {
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    returnKey = new InvestmentDataHelper().Insert(aType, tran);

                    aTransaction.WalletReference = returnKey;

                    new FinancialTransactionDataHelper().Insert(aTransaction, tran);

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }

            returnValue = returnKey;
            return(returnValue);
        }
示例#3
0
        public int Add(FinancialTransaction aTransaction)
        {
            int           returnValue = -1;
            SqlConnection con         = new ConnectionString().GetConnection();

            con.Open();

            using (con)
            {
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    returnValue = new FinancialTransactionDataHelper().Insert(aTransaction, tran);

                    if (aTransaction.CascadeChanges)
                    {
                        if (aTransaction.WalletType == WalletType.Investment)
                        {
                            #region Insert in Investment
                            Investment anInvestment = new Investment();
                            Investor   anInvestor   = new Investor();

                            anInvestment.ID = aTransaction.WalletReference;
                            anInvestor.ID   = aTransaction.ContactID;
                            anInvestment.InvestorDetails = anInvestor;
                            anInvestment.InHand          = (aTransaction.FlowType == FlowType.Debit) ? aTransaction.Amount * -1 : aTransaction.Amount;

                            new InvestmentDataHelper().Update(anInvestment.ID, anInvestment, tran);
                            #endregion Insert in Investment
                        }
                        else if (aTransaction.WalletType == WalletType.InvestmentGroup)
                        {
                            InvestmentGroupDetailDataHelper anInvestmentGroupDetailDH = new InvestmentGroupDetailDataHelper();
                            InvestmentGroupDetail           aInvestmentGroupDetail    = new InvestmentGroupDetail();
                            int ainvestmentID = anInvestmentGroupDetailDH.SelectByID(aTransaction.WalletReference, tran).InvestmentID;

                            aInvestmentGroupDetail.AmountDeducted = true;
                            aInvestmentGroupDetail.ID             = aTransaction.WalletReference;
                            aInvestmentGroupDetail.InHand         = (aTransaction.FlowType == FlowType.Debit) ? aTransaction.Amount * -1 : aTransaction.Amount;

                            //Update Investment/Group Tables
                            anInvestmentGroupDetailDH.Update(aInvestmentGroupDetail.ID, aInvestmentGroupDetail, tran);

                            aTransaction.WalletType = WalletType.Investment;
                            //aInvestmentGroupDetail = anInvestmentGroupDetailDH.SelectByID(aTransaction.WalletReference,tran).InvestmentID;
                            aTransaction.WalletReference = ainvestmentID; //aInvestmentGroupDetail.InvestmentID;
                            aTransaction.FlowType        = (aTransaction.FlowType == FlowType.Debit) ? FlowType.Credit : FlowType.Debit;

                            //double entry rule, 2nd entry in Investment Account
                            new FinancialTransactionDataHelper().Insert(aTransaction, tran);
                        }
                    }

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }

            return(returnValue);
        }
示例#4
0
        public int Add(ProductTransaction aProductTransaction)
        {
            int           returnValue = -1;
            SqlConnection con         = new ConnectionString().GetConnection();

            FinancialTransactionDataHelper financialTransactionH = new FinancialTransactionDataHelper();
            FinancialTransaction           aTransaction          = new FinancialTransaction();
            Deal aDeal = new Deal();

            con.Open();

            using (con)
            {
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    DataTable dt = GetFT(aProductTransaction.DealID, aProductTransaction.TransactionAmount, aProductTransaction.PartyBID);

                    //Update Remaining Amount in Deal
                    aDeal.ID = aProductTransaction.DealID;
                    new DealHandler().Change(aDeal, aProductTransaction, tran);

                    //Normal Data entry row
                    returnValue = new ProductTransactionDataHelper().Insert(aProductTransaction, tran);


                    foreach (DataRow row in dt.Rows)
                    {
                        aTransaction.ContactID            = Convert.ToInt32(row["InvestorID"]);
                        aTransaction.WalletType           = WalletType.InvestmentGroup;
                        aTransaction.WalletReference      = Convert.ToInt32(row["InvestmentGroupID"]);
                        aTransaction.Amount               = Convert.ToInt32(row["DeductionAmount"]);
                        aTransaction.FlowType             = (aProductTransaction.TransactionType == ProductTransactionType.Purchase) ? FlowType.Debit : FlowType.Credit;
                        aTransaction.TransactionType      = TransactionType.Cash;
                        aTransaction.TransactionReference = aProductTransaction.TransactionAmountType.ToString() + " is Paid against Deal " + aProductTransaction.DealID;
                        aTransaction.TransactionDate      = DateTime.Now;

                        //Update Investment Group Details table
                        if (aProductTransaction.TransactionType == ProductTransactionType.Purchase)
                        {
                            new InvestmentGroupDetailHandler().DeductDealFinancialTransaction(aTransaction.WalletReference, aTransaction.Amount, tran);
                        }

                        //Debit the Investment Group Accounts
                        new FinancialTransactionDataHelper().Insert(aTransaction, tran);

                        //Credit the PartyB Accounts
                        aTransaction.ContactID            = Convert.ToInt32(row["PartyBID"]);
                        aTransaction.WalletType           = WalletType.Self;
                        aTransaction.WalletReference      = Convert.ToInt32(row["PartyBID"]);
                        aTransaction.FlowType             = (aProductTransaction.TransactionType == ProductTransactionType.Purchase) ? FlowType.Credit : FlowType.Debit;
                        aTransaction.TransactionReference = aProductTransaction.TransactionAmountType.ToString() + " amount received against Deal " + aProductTransaction.DealID;

                        new FinancialTransactionDataHelper().Insert(aTransaction, tran);
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }
            return(returnValue);
        }
        public void DeductFinancialTransaction(int anInvestmentGroupID)
        {
            SqlConnection con = new ConnectionString().GetConnection();

            List <InvestmentGroupDetail>    anInvestmentGroupDetailList = new List <InvestmentGroupDetail>();
            InvestmentGroupDetailDataHelper aInvestmentGroupDetailDH    = new InvestmentGroupDetailDataHelper();

            Investment anInvestment = new Investment();
            Investor   anInvestor   = new Investor();


            FinancialTransactionDataHelper financialTransactionH = new FinancialTransactionDataHelper();
            FinancialTransaction           aTransaction          = new FinancialTransaction();

            aTransaction.CascadeChanges = false;



            con.Open();

            using (con)
            {
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    anInvestmentGroupDetailList = aInvestmentGroupDetailDH.SelectByGroupID(anInvestmentGroupID);

                    //Do financial Transaction
                    foreach (var item in anInvestmentGroupDetailList)
                    {
                        if (!item.AmountDeducted)
                        {
                            anInvestment = new InvestmentDataHelper().SelectByID(item.InvestmentID);
                            anInvestor   = anInvestment.InvestorDetails;

                            aTransaction.ContactID            = anInvestor.ID;
                            aTransaction.WalletType           = WalletType.Investment;
                            aTransaction.WalletReference      = item.InvestmentID;
                            aTransaction.Amount               = item.InHand;
                            aTransaction.FlowType             = FlowType.Debit;
                            aTransaction.TransactionType      = TransactionType.ApplicationTransfer;
                            aTransaction.TransactionReference = "Transfered to InvestmentGroup";
                            aTransaction.TransactionDate      = DateTime.Now;

                            // Deduct from Investment
                            financialTransactionH.Insert(aTransaction, tran);

                            //------------------------
                            // Add in InvestmentGroup
                            aTransaction.WalletType           = WalletType.InvestmentGroup;
                            aTransaction.WalletReference      = item.ID;
                            aTransaction.FlowType             = FlowType.Credit;
                            aTransaction.TransactionReference = "Transfered from Investment";

                            financialTransactionH.Insert(aTransaction, tran);
                        }
                    }

                    //do Update requied Tables
                    aInvestmentGroupDetailDH.UpdateDeductFT(anInvestmentGroupID, tran);

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
            }
        }