Update balance with debit/credit; return T/F if script can continue.
327470
function ok(inst, transaction) {
    if (transaction === undefined) transaction = 0;
    inst.balance = inst.balance + transaction;
    var _ok = inst.balance > 0 && Date.now() < inst.timeout;
    return _ok;
}
363639
def debit(self, amount, credit_account, description, debit_memo="", credit_memo="", datetime=None):
        

        assert amount >= 0
        return self.post(amount, credit_account, description, self_memo=debit_memo, other_memo=credit_memo, datetime=datetime)
1324686
def get_amount_arrears_balance(self, billing_cycle):
        """"""
        return self.to_account.balance(
            transaction__date__lt=billing_cycle.date_range.lower,
        )
1063275
def _update(self, metadata, tx_id, resource_id):
        
        try:
            if not tx_id:
                sent_tx = self.write(metadata, resource_id)
                self.logger.debug('bdb::put::{}'.format(sent_tx['id']))
                return sent_tx
            else:
                txs = self.driver.instance.transactions.get(asset_id=self.get_asset_id(tx_id))
                unspent = txs[-1]
                sent_tx = self._put(metadata, unspent, resource_id)
                self.logger.debug('bdb::put::{}'.format(sent_tx))
                return sent_tx

        except BadRequest as e:
            logging.error(e)
335108
def getbalance(self, account=None, minconf=6):
        """"""
        if account:
            return self.req("getbalance", [account, minconf])
        else:
            return self.req("getbalance")
748874
def updateratio(ctx, symbol, ratio, account):
    
    from bitshares.dex import Dex

    dex = Dex(bitshares_instance=ctx.bitshares)
    print_tx(dex.adjust_collateral_ratio(symbol, ratio, account=account))
263814
def SetBalanceFor(self, assetId, fixed8_val):
        
        found = False
        for key, val in self.Balances.items():
            if key == assetId:
                self.Balances[key] = fixed8_val
                found = True

        if not found:
            self.Balances[assetId] = fixed8_val
410394
def get_account_balance(self, account):
        
        balance = namedb_get_account_balance(account)
        assert isinstance(balance, (int,long)), 'BUG: account balance of {} is {} (type {})'.format(account['address'], balance, type(balance))
        return balance
955472
function apply_credit() {
    global $db, $order, $messageStack;
    // check for valid redemption amount vs available credit for current customer
    if ($_SESSION['cot_gv'] != 0) {
      $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
      // obtain final "deduction" amount
      $gv_payment_amount = $this->deduction;
      // determine amount of GV to redeem based on available balance minus qualified/calculated deduction suitable to this order
      $gv_amount = $gv_result->fields['amount'] - $gv_payment_amount;
      // reduce customer's GV balance by the amount redeemed
      $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
    }
    // clear GV redemption flag since it's already been claimed and deducted
    $_SESSION['cot_gv'] = false;
    // send back the amount of GV used for payment on this order
    return $gv_payment_amount;
  }
1282740
def update_progress(total, done)
      percentage = total.zero? ? 100 : ((done.to_f / total) * 100).to_i
      progress(percentage)
    end
1244183
def deposit(self, account_id, **params):
        """"""
        for required in ['payment_method', 'amount', 'currency']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'accounts', account_id, 'deposits', data=params)
        return self._make_api_object(response, Deposit)
943260
def balance(self):
        """"""
        self.check()
        if not sum(map(lambda x: x.amount, self.src)) == -self.amount:
            raise XnBalanceError("Sum of source amounts "
                                 "not equal to transaction amount")
        if not sum(map(lambda x: x.amount, self.dst)) == self.amount:
            raise XnBalanceError("Sum of destination amounts "
                                 "not equal to transaction amount")
        return True
1037653
def get_deposit(self, account_id, deposit_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'deposits', deposit_id, params=params)
        return self._make_api_object(response, Deposit)
1288912
def update_balances(self, recursive=True):
        
        if self.node:
            if recursive:
                if self.node.left:
                    self.node.left.update_balances()
                if self.node.right:
                    self.node.right.update_balances()

            self.balance = self.node.left.height - self.node.right.height
        else:
            self.balance = 0
498955
def credit(self, amount, debit_account, description, debit_memo="", credit_memo="", datetime=None):
        
        assert amount >= 0
        return self.post(-amount, debit_account, description, self_memo=credit_memo, other_memo=debit_memo, datetime=datetime)
1023589
def sync(self, data):
        """"""
        for k, v in data.get('billing', {}).items():
            setattr(self, k, v)
        self.card_number = data.get('credit_card', {}).get('card_number',
                                                           self.card_number)
        self.save(sync=False)
1012176
def get_balance(self, t: datetime):
        
        return sum_queryset(self.accountentry_set.all().filter(timestamp__lt=t))