<?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>Bank Deposit</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_deposit">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">From Account*</label>
                            <div class="col-sm-10">
                                <select name="from_acc_id" id="from_acc_id" class="form-control">
                                    <option value="0">Others</option>
                                    <?php if(count($accounts) > 0){
                                        foreach ($accounts as $key => $value) {
                                            if($bank_id != $value->account_id){ ?>
                                            <option value="<?php echo $value->account_id;?>"><?php echo $value->account_name;?></option>    
                                        <?php }
                                        }
                                    }?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Recived Method*</label>
                            <div class="col-sm-10">
                                <select name="receive_via" id="receive_via" class="form-control">
                                    <option value="">Select Payment Mode</option>
                                    <option value="1">Cash</option>
                                    <option value="2">Check</option>
                                    <option value="3">Online</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Referance</label>
                            <div class="col-sm-10">
                                <input type="text" name="reference" id="reference" class="form-control" placeholder="Referance Id" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Amount*</label>
                            <div class="col-sm-10">
                                <input type="text" name="amount" id="amount" class="form-control" placeholder="Amount" value="0">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Note</label>
                            <div class="col-sm-10">
                                <input type="text" name="notes" id="notes" class="form-control" placeholder="Description" value="">
                            </div>
                        </div>
                      
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Date </label>
                            <div class="date_calender col-sm-10">
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" name="tran_date" id="tran_date" class="form-control" value="<?php echo date('d/m/Y'); ?>">
                                </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_deposit" 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(){
        
        $('.date_calender .input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            language: 'en',
            autoclose: true
        });
        
        
        $('.save_bank_deposit').on('click',function(){
            if ($('#from_acc_id').val() == '') {
                $('#from_acc_id').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#from_acc_id').parent().parent().removeClass('has-error');
            }

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

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

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

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

            var bank_id        = '<?php echo $bank_id; ?>';
            var from_acc_id    = $('#from_acc_id').val();
            var receive_via    = $('#receive_via').val();
            var reference      = $('#reference').val();
            var amount         = $('#amount').val();
            var notes          = $('#notes').val();
            var tran_date          = $('#tran_date').val();
            

            $.ajax({
                url: '<?php echo site_url('bank/deposit_amount');?>',
                type: "POST",
                data:{
                    'bank_id'       : bank_id,
                    'from_acc_id'   : from_acc_id,
                    'receive_via'   : receive_via,
                    'reference'     : reference,
                    'amount'        : amount,
                    'notes'         : notes,
                    'tran_date'     : tran_date
                },
                success: function(data){ 
                    window.location.href = '<?php echo site_url("bank");?>';
                }
            });
        });
    });
</script>
