<?php (defined('BASEPATH')) OR exit('No direct script access allowed'); ?>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box" style="border-top: 2.5px solid #9fc10b;">
                <!-- <div class="box-header">
                    <h3 class="box-title"><?= lang('enter_info'); ?></h3>
                </div> -->
                <div class="box-body">
                    <div class="col-lg-12">
                        <?php
                        $attrib = array('class' => 'validation', 'role' => 'form', 'id' => 'form_paymentmethods');

                        echo form_open("payment_methods/add", $attrib); ?>
                        <div class="row">
                            <div class="col-lg-2 col-md-2">
                                <div class="form-group">
                                    <?= lang("payment_methods_code", "payment_methods_code"); ?>
                                    <?php echo form_input('payment_methods_code', '', 'class="form-control" id="payment_methods_code" required="required" maxlength="10"'); ?>
                                </div>
                            </div>
                            <div class="col-lg-10 col-md-10">
                                <div class="form-group">
                                    <?= "<label>Nombre</label>"; ?>
                                    <?php echo form_input('payment_methods_name', '', 'class="form-control" id="payment_methods_name" required="required" maxlength="250"'); ?>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <?= lang('payment_methods_type', 'payment_methods_type'); ?>
                                    <?php $opciones = array('0' => 'Seleccione', '1' => 'Contado', '2' => 'Crédito'); ?>
                                    <?= form_dropdown('payment_methods_type', $opciones, set_value('payment_methods_type'), 'class="form-control tip select2" id="payment_methods_type" required="required"'); ?>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <?= lang("payment_methods_days", "payment_methods_days"); ?>
                                    <?php echo form_input('payment_methods_days', '', 'class="form-control" id="payment_methods_days" required="required" maxlength="10"'); ?>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <?= form_submit('add_payment_methods', lang('add_payment_methods'), 'class="btn btn-primary"'); ?>
                                </div>
                            </div>
                        </div>
                        <?php echo form_close(); ?>

                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
    $(document).ready(function () {
        $('#form_paymentmethods').formValidation(
            {
                framework: 'bootstrap',
                /*icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },*/
                fields: {
                    payment_methods_type: {
                        validators: {
                            callback: {
                                message: 'Ingrese un valor',
                                callback: function(value) {
                                    if( value != 0 ) {
                                        if (value == "1") { // si es al contado, desactiva el control de los días
                                            //$('#form_paymentmethods').formValidation('updateOption', 'payment_methods_days', 'notEmpty', 'asda dwqqwqw');
                                            $('#form_paymentmethods').formValidation('enableFieldValidators', 'payment_methods_days', false);
                                            return true;
                                        }
                                        //$('#form_paymentmethods').formValidation('updateOption', 'payment_methods_days', 'notEmpty', 'asda dwqqwqw');
                                        $('#form_paymentmethods').formValidation('enableFieldValidators', 'payment_methods_days', true);
                                        return true;
                                    } else {
                                        $('#form_paymentmethods').formValidation('enableFieldValidators', 'payment_methods_days', true);
                                        return false;
                                    }
                                }
                            }
                        }
                    },
                    payment_methods_days: {
                        enabled: true,
                        validators: {
                            notEmpty: {
                                message: 'Ingrese un valor'
                            }
                        }
                    }
                }
            }
        );

    });
</script>