<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 bodyitem">
    <div class="row no-padding">
        <div class='col-lg-12 col-md-12 col-sm-12 col-xs-12 text-uppercase checkbox'>
            <input type="checkbox" id="showHideAddPromotion" onclick="checkBlock(this.id, 'AddNewPromotionBox')">
            <span style="color: #FFF">Add New Payment Gateway</span>
        </div>
    </div>
    <div class="row no-padding" id="AddNewPromotionBox">
        <?php echo form_open('gkpos/online/save_gateway/', array('id' => 'gateway_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>
        <fieldset>
            <div class="form-group form-group-sm">	
                <?php echo form_label('Gateway Name', 'title', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalize')); ?>
                <div class="col-sm-8">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                        <input data-error="#gatewayFormTitleError" name="title" class="form-control"  type="text" id="title" value="<?php !empty($toEdit) ? print $toEdit[0]->title : print'Stripe' ?>" <?php !empty($toEdit) && $toEdit[0]->title !== null ? print 'disabled' : print'' ?>>
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormTitleError"></div>
            </div>
            <?php if (!empty($toEdit)): ?>
                <input type="hidden" name="gateway_id" value="<?php echo $toEdit[0]->id ?>">
            <?php endif; ?>
            <div class="form-group form-group-sm">	
                <?php echo form_label('Test Publishable Key', 'merchant', array('class' => 'control-label col-sm-4 text-capitalize')); ?>
                <div class="col-sm-8">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                        <input data-error="#gatewayFormMerchantError" name="merchant" class="form-control"  type="text" id="merchant" value="<?php !empty($toEdit) ? print $toEdit[0]->merchant : print '' ?>">
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormMerchantError"></div>
            </div>
            <div class="form-group form-group-sm">	
                <?php echo form_label('Test Secret Key', 'callback_url', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalize')); ?>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                        <input data-error="#gatewayFormCallbackUrlError" name="callback_url" class="form-control"  type="text" id="callback_url" value="<?php !empty($toEdit) ? print $toEdit[0]->callback_url : print '' ?>">
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormCallbackUrlError"></div>
            </div>
            <div class="form-group form-group-sm">	
                <?php echo form_label('Live Publishable Key', 'success_url', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalize')); ?>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                        <input data-error="#gatewayFormSuccessUrlError" name="success_url" class="form-control"  type="text" id="success_url" value="<?php !empty($toEdit) ? print $toEdit[0]->success_url : print '' ?>">
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormSuccessUrlError"></div>
            </div>
            <div class="form-group form-group-sm">	
                <?php echo form_label('Live Secret Key', 'cancel_url', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalize')); ?>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                        <input data-error="#gatewayFormCancelUrlError" name="cancel_url" class="form-control"  type="text" id="cancel_url" value="<?php !empty($toEdit) ? print $toEdit[0]->cancel_url : print '' ?>" >
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormCancelUrlError"></div>
            </div>    
            <div class="form-group form-group-sm">	
                <?php echo form_label('ccFee', 'cc_fee', array('class' => 'control-label col-sm-4')); ?>
                <div class="col-sm-4 ">
                    <div class="input-group">
                        <span class="input-group-addon" style="background-color: #FF0000;"><i class="fa" aria-hidden="true"><?php echo $this->config->item('currency_symbol') ?></i></span>
                        <input data-error="#gatewayFormCcFeeError" name="cc_fee" class="form-control"  type="text" id="cc_fee" value="<?php !empty($toEdit) ? print $toEdit[0]->cc_fee : print '' ?>">
                    </div>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormCcFeeError"></div>
            </div>   
            <div class="form-group form-group-sm">	
                <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-capitalize">Type</label>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormTypeError" type="radio" name="type" id="type1" value="cod" <?php (!empty($toEdit) && $toEdit[0]->type == "cod") ? print "checked" : '' ?> >COD</label>
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormTypeError" type="radio" name="type" id="type2" value="online" <?php (!empty($toEdit) && $toEdit[0]->type == "online") ? print "checked" : '' ?> >ONLINE</label>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormTypeError"></div>
            </div>
            <div class="form-group form-group-sm">	
                <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-capitalize">Gateway Mode</label>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormModeError" type="radio" name="is_live" id="is_live1" value="2" <?php (!empty($toEdit) && $toEdit[0]->is_live == "2") ? print "checked" : '' ?> >Test</label>
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormModeError" type="radio" name="is_live" id="is_live2" value="1" <?php (!empty($toEdit) && $toEdit[0]->is_live == "1") ? print "checked" : '' ?> >Live</label>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormModeError"></div>
            </div>
            <div class="form-group form-group-sm">	
                <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-capitalize">Status</label>
                <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormStatusError" type="radio" name="status" id="status1" value="1" <?php (!empty($toEdit) && $toEdit[0]->status == "1") ? print "checked" : '' ?> >Active</label>
                    <label class="radio-inline text-uppercase"><input data-error="#gatewayFormStatusError" type="radio" name="status" id="status2" value="2" <?php (!empty($toEdit) && $toEdit[0]->status == "2") ? print "checked" : '' ?> >Inactive</label>
                </div>
                <div class="col-sm-8 col-sm-offset-4" id="gatewayFormStatusError"></div>
            </div>
            <div class="form-group form-group-md">	
                <div class="col-md-offset-4 col-md-8">
                    <ul id="promotion_error_message_box" class="error_message_box"></ul>
                    <?php
                    echo form_submit(array(
                        'name' => 'submit_form',
                        'id' => 'submit_form',
                        'value' => $this->lang->line('gkpos_numpad_key_enter'),
                        'class' => 'btn btn-block btn-danger round btn-sm'));
                    ?>
                </div>
        </fieldset>
    </div>
    <?php echo form_close(); ?>
    <div class="row voucher-list no-padding">
        <div class="modal-header">
            <div class="page-title col-md-12"><?php echo 'Payment Gateway List' ?></div>
        </div>
        <div class="clearfix"></div>
        <table class="table table-responsive table-bordered fieldset">
            <tr>
                <th class="text-center text-uppercase"><?php echo "Title" ?></th> 
                <th class="text-center text-uppercase"><?php echo "Merchant ID" ?></th> 
                <th class="text-center text-uppercase"><?php echo "Mode" ?></th> 
                <th class="text-center text-uppercase"><?php echo "Status" ?></th>
                <th class="text-center text-uppercase"><?php echo "Convert To" ?></th> 
            </tr>
            <?php if (!empty($voucher_list)): ?>
                <?php foreach ($voucher_list as $voucher): ?> 
                    <tr>
                        <td class="text-center"><?php echo $voucher->title ?></td> 
                        <td class="text-center"><?php echo $voucher->merchant ?></td> 
                        <td class="text-center"><?php $voucher->is_live == '1' ? print 'Live' : print 'Test' ?></td> 
                        <td class="text-center"><?php echo $voucher->status == '1' ? 'Active' : 'Inactive' ?></td>
                        <td class="text-center">
                            <a href='javascript:void(0)' onclick="updateGateway('<?php echo $voucher->id ?>', '<?php echo site_url('gkpos/online/update_gateway') ?>', '<?php $voucher->is_live == 1 ? print'test' : print 'live' ?>')"><?php $voucher->is_live == 1 ? print'Test' : print 'Live' ?> </a>
                            |
                            <a href='javascript:void(0)' onclick="updateGateway('<?php echo $voucher->id ?>', '<?php echo site_url('gkpos/online/update_gateway') ?>', '<?php $voucher->status == 1 ? print'deactivate' : print 'activate' ?>')"><?php $voucher->status == 1 ? print'Deactivate' : print 'Activate' ?> </a>
                            |
                            <a href='javascript:void(0)' onclick="updateGateway('<?php echo $voucher->id ?>', '<?php echo site_url('gkpos/online/update_gateway') ?>', 'delete')">Delete</a> 
                            |
                            <a href='javascript:void(0)' onclick="getOnlineSettingPage('<?php echo site_url("gkpos/online/gateway/" . $voucher->id) ?>', 'Online Gateway')">Edit</a> 
                        </td> 
                    </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="4">No Vouchers found</td> 
                </tr>
            <?php endif; ?>
        </table>                        
    </div>
</div>
<script type='text/javascript'>
    $(document).ready(function () {
<?php if (isset($toEdit) && !empty($toEdit)) { ?>
            $('#showHideAddPromotion').attr('checked', true);
<?php } ?>
        if ($('#showHideAddPromotion').is(":checked")) {
            $('#AddNewPromotionBox').show();
        } else {
            $('#AddNewPromotionBox').hide();
        }
        $('#gateway_form').validate({
            submitHandler: function () {
                var myform = document.getElementById('gateway_form');
                var formdata = new FormData(myform);
                $.ajax({
                    url: $('#gateway_form').attr('action'),
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    dataType: 'json',
                    success: function (response) {
                        if (response.success) {
                            getSettingPage('<?php echo site_url('gkpos/online/gateway') ?>', 'Payment Gateway');
                        } else {
                            ALERT_TITLE = "Warning!";
                            alert(response.message);
                        }
                    },
                });
            },
            errorClass: "has-error",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            rules: {
                title: "required",
                merchant: "required",
                cc_fee: {number: true, required: true},
                type: "required",
                status: "required",
                is_live: "required",
                callback_url: "required",
                success_url: "required",
                cancel_url: "required",
            },
            messages: {
                title: "Payment Gateway title is a required field",
                type: 'Please select gateway type',
                merchant: "Please specify Payment gateway merchant id",
                cc_fee: "Please specify credit card fee in amount",
                status: "Check status, active or in active",
                is_live: 'Mention gateway mode if it is kept live or Test mode',

            },
            errorPlacement: function (error, element) {
                errorPlacement(error, element);
            }
        });
    });

    function updateGateway(voucher_id, url, action) {
        $.ajax({
            url: url,
            data: {
                id: voucher_id,
                action: action
            },
            type: "POST",
            success: function (output) {
                getSettingPage('<?php echo site_url("gkpos/online/gateway") ?>', 'Payment Gateway');
            }
        });
    }
</script>