<?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 ($expence_id == 0) ? 'New Expence Type' : 'Edit Expence Type';?></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="bank_data">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Expence Name</label>
                            <div class="col-sm-10">
                                <input type="text" name="account_name" id="account_name" class="form-control" placeholder="Account Name" value="<?php echo !empty($expence_data->expence_acc_name) ? $expence_data->expence_acc_name : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Description</label>
                            <div class="col-sm-10">
                                <input type="text" name="description" id="description" class="form-control" placeholder="Description" value="<?php echo !empty($expence_data->expence_acc_desc) ? $expence_data->expence_acc_desc : '';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Status</label>
                            <div class="col-sm-10">
                                <select name="status" id="status" class="form-control">
                                    <option value="1" <?php echo (isset($expence_data->status) && ($expence_data->status == 1)) ? 'selected="selected"' : '';?>>Active</option>
                                    <option value="0" <?php echo (isset($expence_data->status) && ($expence_data->status == 0)) ? 'selected="selected"' : '';?>>In-Active</option>
                                </select>
                            </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_expence_details" type="button" data-status="1"><i class="fa fa-download"></i><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_expence_details').on('click',function(){

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

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

            var expence_id         = '<?php echo $expence_id; ?>';
            var account_name    = $('#account_name').val();
            var description     = $('#description').val();
            var status          = $('#status').val();

            $.ajax({
                url: '<?php echo site_url('Expence/save_expence_type');?>',
                type: "POST",
                data:{
                    'expence_id'       : expence_id,
                    'account_name'  : account_name,
                    'description'   : description,
                    'status'        : status
                },
                success: function(data){ 
                    window.location.href = '<?php echo site_url("expence");?>';
                }
            });
        });
    });
</script>
