<script type="text/javascript">
    $(document).ready(function () {
        $('.datatables').DataTable();
        $.calculator.setDefaults({showOn: 'both', buttonImageOnly: true, buttonImage: 'img/calculator.png'});
        $('.amount').calculator();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD-MM-YYYY'
        });

    });

    function addRow(id, linkAcctId){
        //alert(id);
		//alert(linkAcctId);
        // return false;
        //
        $('#bankID').val(id);
		$("#bankID").attr('data-linkID', linkAcctId);
        $('#bankLabel').text($('#bank' + id).text());
        $('#bankName').val($('#name' + id).text());
        $('#bankBalance').val($('#balance' + id).text());
        $('#bankDate').val($('#created' + id).text());
        $('#chartOfAcct').val($('#acctCode' + id).text());

        var status = $('#coa' + id).text();

        if(status == "Active"){
            document.getElementById("statusActive").checked = true;
        } else {
            document.getElementById("statusInactive").checked = true;
        }

        $('#editBankModal').modal('show');
    }



    function saveBank(){

        var bankID = $('#bankID').val();
       	//alert(bankID);
        var linkID = $('#bankID').attr('data-linkID');
		//alert(linkID);
		//return false;

        var bankName = $('#bankName').val();
        var bankBalance = $('#bankBalance').val();
        var bankDate = $('#bankDate').val();
		var linkAccountID = linkID;
		//alert(linkAccountID);
		//return false;

        var statusActive = $('#statusActive').val();
        var statusInactive = $('#statusInactive').val();

        if(document.getElementById('statusActive').checked)
        {
            var status = 0;
        }
        else if(document.getElementById('statusInactive').checked)
        {
            var status = 1;
        }
        //alert(bankName);
        //return false;

        var postData = {
            //'formNo' : formNo,
            'bankID' : bankID,
            'bankName' : bankName,
            'currentBalance' : bankBalance,
            'createdTS' : bankDate,
            'is_delete' : status,
			'linkAccountID' : linkAccountID,
        };

        $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo base_url()?>bank/saveBank",
            data: postData ,
            success: function(content){
                if(content.status == "success") {
                    alert('Data successfully saved');
                    window.location.href = "<?php echo base_url()?>bank";
                }
            }
        });
    }

</script>
<style>
    .fl{
        float:left !important;
    }
    .fr{
        float:right !important;
    }
    .al{
        text-align:left !important;
    }

    .ac{
        text-align:center !important;
    }

    .ar{
        text-align:right !important;
    }
</style>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            <?php echo $this->lang->line('module') ?>
            <!--<small>advanced tables</small>-->
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i><?php echo $this->lang->line('home') ?></a></li>
            <li><a href="#"><?php echo $this->lang->line('tables') ?></a></li>
            <li class="active"><?php echo $this->lang->line('banksetup') ?></li>
        </ol>
    </section>

    <div id="editBankModal" class="modal fade in">
        <div class="modal-dialog">
            <form role="form" action="" method="post">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                        <h2 class="modal-title"><?php echo $this->lang->line('banksetup'); ?></h2>
                    </div>
                    <div class="modal-body">
                    <!-- Main content -->
                        <section class="content">
                            <div class="row">
                                <div class="col-md-12">
                                   <!-- Horizontal Form -->

                                        <div class="box-body">
                                            <div style="margin-top:10px;" class="row form-horizontal">
                                                <div class="col-md-12 col-xs-12 col-sm-12" style="display:none">
                                                    <div class="form-group">
                                                        <div class="col-sm-6">
                                                            <input type="text" class="form-control col-sm-6" id="bankID" data-linkID="" placeholder="">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 col-sm-12">
                                                    <div class="form-group">
                                                        <label for="bankName" class="col-sm-4 control-label" id="bankLabel"><?php echo $this->lang->line('names'); ?>: </label>
                                                        <div class="col-sm-6">
                                                            <input type="text" class="form-control col-sm-6" id="bankName" placeholder="">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 col-sm-12">
                                                    <div class="form-group">
                                                        <label for="bankBalance" class="col-sm-4 control-label"><?php echo $this->lang->line('balance'); ?>: </label>
                                                        <div class="col-sm-6">
                                                            <input type="text" class="form-control col-sm-6 calculator" id="bankBalance" placeholder="">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 col-xs-12 col-sm-12">
                                                    <div class="form-group">
                                                        <label for="bankDate" class="col-sm-4 control-label"><?php echo $this->lang->line('asAtdate'); ?>: </label>
                                                        <div class="col-sm-6">
                                                            <input type="text" class="form-control col-sm-6 datetimepicker" id="bankDate" placeholder="">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 col-sm-12">
                                                    <div class="form-group">
                                                        <label for="bankCoa" class="col-sm-4 control-label"><?php echo $this->lang->line('coa'); ?>: </label>
                                                        <div class="col-sm-6">
                                                            <input type="text" disabled class="form-control col-sm-6" id="chartOfAcct" placeholder="">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 col-sm-12">
                                                    <div class="form-group">
                                                        <label for="status" class="col-sm-4 control-label"><?php echo $this->lang->line('status'); ?>: </label>
                                                        <div class="col-sm-6">
                                                            <input type="radio" id="statusActive" name="status" value="0">&nbsp&nbsp&nbsp&nbsp&nbsp<?php echo $this->lang->line('active') ?>&nbsp&nbsp&nbsp&nbsp&nbsp
                                                            <input type="radio" id="statusInactive" name="status" value="1">&nbsp&nbsp&nbsp&nbsp&nbsp<?php echo $this->lang->line('inactive') ?>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div><!-- /.box-body -->

                                </div>
                            </div>
                        </section><!-- /.content -->

                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $this->lang->line('close') ?></button>
                        <button type="button" class="btn btn-primary" onclick="saveBank()"><?php echo $this->lang->line('save'); ?></button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-dialog -->
    </div>



    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">

          <div class="box box-primary">
            <div class="box-body table-scroll-xs">
              <table id="example1" class="table table-bordered">
                 <thead>
                    <tr>
                        <th class="ac"><?php echo $this->lang->line('accNo') ?></th>
                        <th class="ac"><?php echo $this->lang->line('accName') ?></th>
                        <th class="ac"><?php echo $this->lang->line('balance') ?></th>
                        <th class="ac"><?php echo $this->lang->line('asAtdate') ?></th>
                        <th class="ac"><?php echo $this->lang->line('coa') ?></th>
                        <th class="ac"><?php echo $this->lang->line('status') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $bil = 0;
                        if($datatbls){
                            foreach($datatbls as $datatbl):
                                $bil++?>
                                <tr>
                                    <td class="ac" id="<?php echo "bank".$datatbl->ID; ?>"><?php echo "Account ".$bil; ?></td>
                                    <td id="<?php echo "name".$datatbl->ID; ?>"><a href="#" title="" class="" onclick="addRow(<?php echo $datatbl->ID; ?>, <?php echo $datatbl->linkAccountID; ?>)"><?php echo $datatbl->bankName ?></a></td>
                                    <td class="ar" id="<?php echo "balance".$datatbl->ID; ?>"><?php echo number_format($datatbl->currentBalance, 2); ?></td>
                                    <td class="ac" id="<?php echo "created".$datatbl->ID; ?>"><?php echo date("d-m-Y", strtotime($datatbl->createdTS)) ?></td>
                                    <td class="ac" id="<?php echo "acctCode".$datatbl->ID; ?>"><?php echo $datatbl->acctCode; ?></td>
                                    <?php
                                            if($datatbl->is_delete == 0)
                                            {
                                                echo "<td  class='ac' id='coa".$datatbl->ID."'>".$this->lang->line('active')."</td>";
                                            }
                                            else{
                                                echo "<td  class='ac' id='coa".$datatbl->ID."'>".$this->lang->line('inactive')."</td>";
                                            }
                                    ?>
                                    </td>
                                </tr>
                    <?php endforeach; }?>
                </tbody>
              </table>
            </div><!-- /.box-body -->
          </div><!-- /.box -->
        </div><!-- /.col -->
      </div><!-- /.row -->
    </section><!-- /.content -->
</div><!-- /.content-wrapper -->
