Character buys reinforcements

Submitted by Brutus5000 on Fri, 07/22/2016 - 02:10

Character buys a set of reinforcements.

Input data
  • character id
  • list of
    • unit id, quantity

Check character credits > reinforcement costs

character credits:
SELECT SUM(amount) FROM credit_journal WHERE credit_journal.fk_character = <character id>

reinforcement costs:
add to sum for each tuple <unit id>, <quantity> in list from
SELECT <quantity> * units.price FROM units
--> store <reinforcement costs> for later

Database transaction

INSERT INTO unit_transactions (fk_character, type) VALUES (<character id>, 'B');
SET @transaction_id = LAST_INSERT_ID();

for each tuple <unit id>, <quantity> in list:
INSERT INTO unit_transaction_positions (fk_unit_transaction, fk_unit, quantity) VALUES (@transaction_id, <unit id>, <quantity>);

INSERT INTO credit_journal (fk_character, fk_unit_transaction, reason, amount) VALUES ( <character id>, @transaction_id, 'R', -1 * <reinforcement costs>);

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.