<?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>Site Setings</h2>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <form method="post" class="form-horizontal">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Company Name</label>
                            <div class="col-sm-10">
                                <input type="text" name="company_name" id="company_name" class="form-control" placeholder="Company Name" value="<?php echo !empty($setings->company_name) ? $setings->company_name : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Company Address</label>
                            <div class="col-sm-10">
                                <input type="text" name="company_address" id="company_address" class="form-control" placeholder="Company Address" value="<?php echo !empty($setings->company_address) ? $setings->company_address : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">GSTIN</label>
                            <div class="col-sm-10">
                                <input type="text" name="gst_no" id="gst_no" class="form-control" placeholder="GST Number" value="<?php echo !empty($setings->gst_no) ? $setings->gst_no : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Bank Acc.No.</label>
                            <div class="col-sm-10">
                                <input type="text" name="bank_account" id="bank_account" class="form-control" placeholder="Bank Acc.No." value="<?php echo !empty($setings->bank_account) ? $setings->bank_account : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">IFSC Code</label>
                            <div class="col-sm-10">
                                <input type="text" name="ifsc_code" id="ifsc_code" class="form-control" placeholder="IFSC Code" value="<?php echo !empty($setings->ifsc_code) ? $setings->ifsc_code : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Terms & Conditions</label>
                            <div class="col-sm-10">
                                <textarea name="tac" id="tac" class="form-control" placeholder="Terms and condition"><?php echo !empty($setings->tac) ? $setings->tac : '';?></textarea>
                            </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_setings" type="button"><span class="m-l-xs">Save Settings</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_setings').on('click',function(){
            if ($('#company_name').val() == '') {
                $('#company_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#company_name').parent().parent().removeClass('has-error');
            }

            if ($('#company_address').val() == '') {
                $('#company_address').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#company_address').parent().parent().removeClass('has-error');
            }

            if ($('#gst_no').val() == '') {
                $('#gst_no').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#gst_no').parent().parent().removeClass('has-error');
            }

            if ($('#bank_account').val() == '') {
                $('#bank_account').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#bank_account').parent().parent().removeClass('has-error');
            }

            if ($('#ifsc_code').val() == '') {
                $('#ifsc_code').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#ifsc_code').parent().parent().removeClass('has-error');
            }
            var company_name = $('#company_name').val();
            var company_address = $('#company_address').val();
            var gst_no = $('#gst_no').val();
            var bank_account = $('#bank_account').val();
            var ifsc_code = $('#ifsc_code').val();
            var tac = $('#tac').val();
            $.ajax({
                url: '<?php echo site_url('setings/update_setings');?>',
                type: "POST",
                data:{
                    'company_name'      : company_name,
                    'company_address'   : company_address,
                    'gst_no'            : gst_no,
                    'bank_account'      : bank_account,
                    'ifsc_code'         : ifsc_code,
                    'tac'               : tac
                },
                success: function(data){ 
                    window.location.href = '<?php echo site_url("setings");?>';
                }
            });
        });
    });
</script>