<?php
$this->load->view($left);
$this->load->view($header);
?>
<style type="text/css">
    .ibox-content {
        border-style : none;
    }

    .hr-line-dashed {
        margin: 5px 0;
    }
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2><?php echo (@$vendor->id == '') ? 'New Vendor' : 'Edit Vendor'; ?></h2>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
            <form method="post" class="form-horizontal" id="vendor_data">
                <input type="hidden" name="id" id="id" class="form-control" value="<?= @$vendor->id ?>">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Vendor</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="vendor_name" id="vendor_name" class="form-control" placeholder="Vendor Name" value="<?= @$vendor->vendor_name ?>" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Prefix code</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="prefix_code" id="prefix_code" class="form-control" placeholder="Prefix Code" value="<?= @$vendor->prefix_code ?>" required="">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Account Number</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="account_number" id="account_number" class="form-control" placeholder="Account Number" value="<?= @$vendor->account_number ?>" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Phone</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="phone1" id="phone1" class="form-control" placeholder="Phone" value="<?= @$vendor->phone1 ?>" required="">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Contact Name</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="contact_name" id="contact_name" class="form-control" placeholder="Contact Name" value="<?= @$vendor->contact_name ?>" required="">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Email</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="contact_email" id="contact_email" class="form-control" placeholder="Email" value="<?= @$vendor->contact_email ?>" required="">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">Country Name</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="WH_Country" id="WH_Country" class="form-control" placeholder="Country Name" value="<?= @$vendor->WH_Country ?>" required="">
                                    </div>
                                </div>
                            </div>                           
                        </div>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-lg-6 pull-right">
                                <div class="form-group">
                                    <div class="col-sm-12 col-sm-offset-2">
                                        <button class="btn btn-primary save_bank_details" type="button" data-status="1"><span class="m-l-xs">Save</span></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view($footer); ?>
<script type="text/javascript">
    $(document).ready(function () {
        $('.save_bank_details').on('click', function () {
            if ($('#vendor_name').val() == '') {
                $('#vendor_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#vendor_name').parent().parent().removeClass('has-error');
            }
           
            if ($('#prefix_code ').val() == '') {
                $('#prefix_code ').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#prefix_code ').parent().parent().removeClass('has-error');
            }
            if ($('#account_number').val() == '') {
                $('#account_number').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#account_number').parent().parent().removeClass('has-error');
            }
            if ($('#phone1').val() == '') {
                $('#phone1').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#phone1').parent().parent().removeClass('has-error');
            }
            if ($('#contact_name').val() == '') {
                $('#contact_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#contact_name').parent().parent().removeClass('has-error');
            }
            if ($('#contact_email').val() == '') {
                $('#contact_email').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#contact_email').parent().parent().removeClass('has-error');
            }
            if ($('#WH_Country').val() == '') {
                $('#WH_Country').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#WH_Country').parent().parent().removeClass('has-error');
            }
            $.ajax({
                url: '<?php echo site_url('vendor/savevendor'); ?>',
                type: "POST",
                data: $('#vendor_data').serialize(),
                success: function (data) {
                    
                    window.location.href = '<?php echo site_url("vendor"); ?>';
                }
            });
        });
    });
</script>
