<?php $__env->startSection('title'); ?>
    Edit Transaction #<?php echo e($transaction->id); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('pageScripts'); ?>
    <script type="text/javascript">
        function updateCapacityInput(enabled, label) {
            if (enabled)
            {
                $('#expiry_holder').hide();
                $('#capacity_holder').show();
            }
            else
                $('#capacity_holder').hide();
            $('label[for="capacity"]').text(label);
        }
        $('#type').on('change', function () {
            if ($(this).val() == 'increase') {
                updateCapacityInput(true, 'Increase User Capacity By');
            }
            else if ($(this).val() == 'decrease') {
                updateCapacityInput(true, 'Decrease User Capacity By');
            }
            else if ($(this).val() == 'charge') {
                updateCapacityInput(false, '');
                $('#expiry_holder').show();
            }
            else {
                updateCapacityInput(false, '');
                $('#expiry_holder').hide();
            }
        })
    </script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <form action="<?php echo e(URL::action('CompaniesController@postUpdateTransaction')); ?>" method="POST">
        <input type="hidden" value="<?php echo e($transaction->id); ?>" name="transaction_id">
        <input type="hidden" value="<?php echo e($transaction->company_id); ?>" name="company_id">
        <?php echo csrf_field(); ?>

        <div class="form-group">
            <label for="type" class="control-label">Transaction Type</label>
            <?php if($transaction->type == "Registration Transaction"): ?>
                <input type="text" class="form-control form-control-static"
                value="Registration Transaction" disabled>
                <input type="hidden" name="transaction[type]" value="Registration Transaction">
            <?php else: ?>
                <select id="type" name="transaction[type]" class="form-control">
                    <?php foreach([
                    'increase'=>'Increase User Capacity',
                    'decrease'=>'Decrease User Capacity',
                    'charge'=>'Charge',
                    'other'=>'Other'
                    ] as $key=>$value): ?>
                        <?php if($transaction->type == $value): ?>
                            <option value="<?php echo e($key); ?>" selected><?php echo e($value); ?></option>
                        <?php else: ?>
                            <option value="<?php echo e($key); ?>"><?php echo e($value); ?></option>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </select>
            <?php endif; ?>
        </div>
        <div class="form-group" id="capacity_holder"
             <?php if(!in_array($transaction->type,['Increase User Capacity','Decrease User Capacity','Registration Transaction'])): ?>
             style="display: none;"
                <?php endif; ?>>
            <?php if($transaction->type != 'Registration Transaction'): ?>
                <label for="capacity"><?php echo e($transaction->type); ?> by</label>
            <?php else: ?>
                <label for="capacity">User Capacity</label>
            <?php endif; ?>
            <input id="capacity" type="number" class="form-control" name="transaction[capacity]"
                   value="<?php echo e($transaction->capacity); ?>" min="1">
        </div>
        <div class="form-group">
            <label for="fees" class="control-label">Fees</label>
            <input id="fees" type="text" class="form-control" name="transaction[fees]" value="<?php echo e($transaction->amount); ?>">
        </div>
        <div class="form-group" id="expiry_holder" <?php if($transaction->type != 'Charge'): ?> style="display: none;" <?php endif; ?>>
            <label for="expiry">Expiry Date</label>
            <input type="text" class="form-control has-date-picker" name="transaction[expires_at]" value="<?php echo e($transaction->expires_at); ?>">
        </div>
        <div class="form-group">
            <label for="currency" class="control-label">Currency</label>
            <select id="currency" name="transaction[currency]" class="form-control">
                <?php foreach(\App\Util::getCurrencies() as $opt): ?>
                    <?php if($transaction->currency == $opt): ?>
                        <option value="<?php echo e($opt); ?>" selected><?php echo e($opt); ?></option>
                    <?php else: ?>
                        <option value="<?php echo e($opt); ?>"><?php echo e($opt); ?></option>
                    <?php endif; ?>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-group">
            <label for="details" class="control-label">Details</label>
            <textarea name="transaction[details]" id="details" cols="30" rows="10"
                      class="form-control"><?php echo e($transaction->details); ?></textarea>
        </div>
        <div class="form-group">
            <label for="transaction_status" class="control-label">Status</label>
            <select name="transaction[status]" id="transaction_status" class="form-control">
                <?php foreach(['pending','closed'] as $opt): ?>
                    <?php if($transaction->status == $opt): ?>
                        <option value="<?php echo e($opt); ?>" selected><?php echo e(ucfirst($opt)); ?></option>
                    <?php else: ?>
                        <option value="<?php echo e($opt); ?>"><?php echo e(ucfirst($opt)); ?></option>
                    <?php endif; ?>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-actions">
            <a href="<?php echo e(URL::action('CompaniesController@getDetails',['id'=>$transaction->company_id])); ?>"
               class="btn btn-dark">
                Cancel
            </a>
            <button type="submit" class="btn btn-green">
                Update
            </button>
        </div>
    </form>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>