3 Replies Latest reply: Feb 24, 2014 9:52 AM by bregent RSS

    How do i transfer funds from one account to another in the same table?

    gurroby

      24-02-2014 01-54-39.jpg

      Say for example i want to transfer funds from UserID 1111101 to UserID  1111103.

       

      Anyone know the procedure for this. I use php/mysql and dreamweaver.

        • 1. Re: How do i transfer funds from one account to another in the same table?
          bregent MVP

          In a basic accounting scenario, you first insert a transaction in a transaction table. That table contains the amount of the transaction, as well as the credit and debit accounts. You then update the balance of each account using two update statements. All of these operations need to be atomic - that is -they all must succeed or else be rolled back. So you need to incorporate transaction management.

          • 2. Re: How do i transfer funds from one account to another in the same table?
            gurroby Community Member

            Thanks...i have an idea of this. But i would like to know how you transfer it into coding and usually a webpage where i can do manual transactions transfers for any desired amount and this should update into the users balance table.

            • 3. Re: How do i transfer funds from one account to another in the same table?
              bregent MVP

              Here's a very basic method. Note that this is just pseudocode - you'll need to work out the actual code (I assume you've learned how in your course studies). Keep in mind this is a very simplified workflow - a real bank transaction would be MUCH more complex.

               

              Create a form that has fields for debit account, credit account, amount

               

              In your script, assign the values from the form to local variables

              $debit_acct

              $credit_acct

              $amount

               

              I'll assume you have an account balance table 'acct_bal'. Have a journal table to store those values along with the date and autonumber transaction id.

               

              Begin Trans

              INSERT into journal (credit_acct, debit_acct, amount, trans_date) VALUES ($credit_acct, $debit_acct, $amount, NOW())

              Get the transaction_id ($trans_id) from the INSERT statement- the method depends on which MySQL interface you are using.

              UPDATE acct_bal SET balance = (balance + $amount) WHERE acct_id = $debit_acct

              UPDATE acct_bal SET balance = (balance - $amount) WHERE acct_id = $credit_acct

               

              Rollback on any SQL error else Commit Trans.