Help with searching a database

Side note, how did you integrate the redemption of the cards and how does it subtract the balance and apply to purchase total?