<script type="text/javascript">
    $(document).ready(function () {
    <!-- page script -->
        $('.datatables').DataTable();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD-MM-YYYY',
        });
    });

    function editTransfer(me){
         //alert(id);
        tr = $(me).parents("tr");
        id = $(tr).find("td:eq(0)").text();
        detailid = $(tr).find("td:eq(0)").attr("data-detailid");
        date = $(tr).find("td:eq(2)").text();
        formno = $(tr).find("td:eq(3)").text();
		typeOfLoan = $(tr).find("td:eq(4)").text();
        transfrom = $(tr).find("td:eq(5)").text();
        transto = $(tr).find("td:eq(6)").text();
        desc = $(tr).find("td:eq(7)").text();
        amt = $(tr).find("td:eq(8)").text();
        //alert(transfrom);

        $('#editTransferModal').modal('show');

        $("#edittransID").val(id);

        $("#edittransID").attr("data-detail", $(tr).find("td:eq(0)").attr("data-detailid"));
        $("#edittransID").attr("data-journalID", $(tr).find("td:eq(0)").attr("data-journalID"));

        $("#edittransDate").val(date);
        $("#edittransformNo").val(formno);
        $("#edittransFrom").val(transfrom);
        $("#edittransTo").val(transto);
        $("#edittransDesc").val(desc);
        $("#edittransAmount").val(amt);

        $("#href_journalentry").attr("href","<?php echo base_url() ?>report/journalDetails/"+$(tr).find("td:eq(0)").attr("data-journalNo"));
        $("#href_printdetails").attr("href","<?php echo base_url() ?>loanReceive/print_loanReceive/"+id);
    }

    function newTransfer(){
        $('#addtransferForm').trigger("reset");
        $('#newTransferModal').modal('show');
    }

    function print_loan_list(){
        var dateFrom = $("#dateFrom").val();
        var dateTo = $("#dateTo").val();
        window.location = "<?php echo base_url(); ?>loanReceive/print_loanReceives/" + dateFrom + "/" + dateTo;
    }

    function select_or_unselect_all(me){
         var oTable = $("#datatable_loanlist").dataTable();
        if($(me).is(":checked")){
            $(oTable.fnGetNodes()).find(':checkbox').prop('checked', true);
            $("#btn_delete_transfer").removeAttr("disabled");
        }else{
            $(oTable.fnGetNodes()).find(':checkbox').prop('checked', false);
            $("#btn_delete_transfer").attr("disabled","disabled");
        }
    }

    function enabled_or_disabled_delete_btn(me){

        if($(me).is(":checked")){
            $("#btn_delete_transfer").removeAttr("disabled");
        }else{
            var oTable = $("#datatable_loanlist").dataTable();
            $(oTable.fnGetNodes()).find('input[type=checkbox] :checked');
            var notfind = true;
            $(oTable.fnGetNodes()).find(':checkbox:checked').each(function(){
                $("#btn_delete_transfer").removeAttr("disabled");
                notfind = false;
               return true;
            });
            if(notfind){
                 $("#btn_delete_transfer").attr("disabled","disabled");
            }

        }
    }

    function conf_delete_loan(me){
        confirmBox('delete_selected_loan()', '<?php echo $this->lang->line('msgconfirm'); ?>');
    }

    function delete_selected_loan(){
       $('#frm_submit_delete_loan').submit();
    }

</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>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1 class="module-highlight">
        <span class="number">4.3</span>
        <?php echo $this->lang->line('module'); ?>
        <small><?php echo $this->lang->line('moduleGeneral'); ?></small>
      </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-home"></i> <?php echo $this->lang->line('home'); ?></a></li>
            <li><a href="#"><?php echo $this->lang->line('module'); ?></a></li>
            <li class="active"><?php echo $this->lang->line('loanreceivelist'); ?></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- Horizontal Form -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <label class="box-title"><?php echo $this->lang->line('loanreceivelist'); ?></label>
                        <div class="pull-right">
                            <button onclick="newTransfer()" class="btn btn-sm bg-olive"><span class="fa fa-plus fa-fw"></span> <?php echo $this->lang->line('addNewLoanReceived'); ?></button>
                            <button id="btn_delete_transfer" class="btn bg-red btn-sm" disabled="disabled" onclick="conf_delete_loan(this)"><span class="fa fa-trash fa-fw"></span> <?php echo $this->lang->line('delLoanReceived'); ?></button>
                            <button <?php echo ($datatbls)?'':'disabled="disabled"'; ?> onclick="print_loan_list(this)" class="btn bg-orange btn-sm"><span class="fa fa-print fa-fw"></span> <?php echo $this->lang->line('printLoanReceived'); ?></button>
                        </div>
                    </div>
                    <div class="box-header with-border">
                        <form id="datepicker" method="post" action="<?php echo base_url() ?>loanReceive/loanReceiveList" class="form-horizontal">
                            <fieldset class="fsStyle">
                                <legend class="legendStyle">
                                    <a href="javascript:void(0);" data-toggle="collapse" data-target="#filter"><?php echo $this->lang->line('selectDate'); ?></a>
                                </legend>
                                <div id="filter" class="row collapse in">
                                    <div class="form-group col-sm-5">
                                        <label for="dateFrom" class="col-sm-4 col-sm-offset-2 control-label"><?php echo $this->lang->line('dateFrom'); ?>: </label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control datetimepicker" id="dateFrom" name="dateFrom" value="<?php echo date("d-m-Y", strtotime($dateFrom)); ?>" placeholder="<?php echo $this->lang->line('dateFrom'); ?>" />
                                        </div>
                                    </div>
                                    <div class="form-group col-sm-5">
                                        <label for="dateTo" class="col-sm-4 col-sm-offset-2 control-label"><?php echo $this->lang->line('dateTo'); ?>: </label>
                                        <div class="col-sm-6">
                                            <input type="text" id="dateTo" name="dateTo" class="form-control datetimepicker" value="<?php echo date("d-m-Y", strtotime($dateTo)); ?>" placeholder="<?php echo $this->lang->line('dateTo'); ?>">
                                        </div>
                                    </div>
                                    <div class="form-group col-sm-2">
                                        <button type="submit" class="btn btn-primary search hidden-xs"><?php echo $this->lang->line('search'); ?></button>
                                        <button type="submit" class="btn btn-primary search hidden-lg hidden-sm hidden-md pull-right" style="margin-right:20px;"><?php echo $this->lang->line('search'); ?></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-scroll-xs">
                        <form id="frm_submit_delete_loan" method="post" action="<?php echo base_url(); ?>loanReceive/deleteLoan">
                            <table id="datatable_loanlist" class="table table-bordered table-striped datatables">
                                <thead>
                                    <tr>
                                        <th style="display:none"></th>
                                        <th class="text-center"><?php echo $this->lang->line('no'); ?></th>
                                        <th class="text-center"><?php echo $this->lang->line('date'); ?></th>
                                        <th><?php echo $this->lang->line('formno'); ?></th>
										<th><?php echo $this->lang->line('typeofLoan'); ?></th>
                                        <th style="display:none"></th>
                                        <th style="display:none"></th>
                                        <th><?php echo $this->lang->line('description'); ?></th>
                                        <th class="text-right"><?php echo $this->lang->line('amount'); ?></th>
                                        <th class="text-center"><?php echo $this->lang->line('print'); ?></th>
                                        <th class="text-center"><input type="checkbox" onchange="select_or_unselect_all(this)" /></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $bil = 0;
                                        if($datatbls){
                                            foreach($datatbls as $datatbl):
                                                $bil++?>
                                    <tr>
                                        <td data-journalID ="<?php echo $datatbl->journal_no; ?>" data-detailid="<?php echo $datatbl->detailid; ?>" data-journalNo="<?php echo $datatbl->journal_id; ?>" style="display:none" id="<?php echo $datatbl->ID; ?>"><?php echo $datatbl->ID; ?></td>
                                        <td class="text-center" id="<?php echo "transfer".$datatbl->ID; ?>"><?php echo $bil; ?></td>
                                        <td class="text-center" id="<?php echo "transferDate".$datatbl->ID; ?>"><?php echo date("d-m-Y", strtotime($datatbl->paymentDate)) ?></td>
                                        <td id="<?php echo "transferformNo".$datatbl->ID; ?>"><a href="javascript:" title="" class="text-center" onclick="editTransfer(this)"><?php echo $datatbl->formNo ?></a></td>
										<td id="typeOfLoan"><?php echo $datatbl->acctName; ?></td>
                                        <td style="display:none" id="<?php echo "transferFrom".$datatbl->ID; ?>"><?php echo $datatbl->transferFrom; ?></td>
                                        <td style="display:none" id="<?php echo "transferTo".$datatbl->ID; ?>"><?php echo $datatbl->transferTo; ?></td>
                                        <td id="<?php echo "transferDesc".$datatbl->ID; ?>"><?php echo $datatbl->description; ?></td>
                                        <td class="text-right" id="<?php echo "transferAmount".$datatbl->ID; ?>"><?php echo number_format($datatbl->amountPaid, 2); ?></td>
                                        <td class="text-center"><a class="btn btn-primary btn-sm" href="<?php echo base_url().'loanReceive/print_loanReceive/'.$datatbl->ID; ?>"><i class="fa fa-print"></a></td>
                                        <td class="text-center"><input onchange="enabled_or_disabled_delete_btn(this)" name="loan_id[]" value="<?php echo $datatbl->ID."_".$datatbl->journal_no; ?>" type="checkbox" /></td>
                                    </tr>
                                    <?php endforeach; }?>
                                </tbody>
                            </table>
                        </form>
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php $this->load->view('loanReceives/add_loan');
    $this->load->view('loanReceives/edit_loan'); ?>
