<script type="text/javascript">
    $(document).ready(function(){
        $('.thisYearDatepicker').datetimepicker({
                viewMode: 'years',
                format: 'YYYY'
            });

        $('#expenseList').find(':checkbox').prop('checked', false)
    });

    function printLoanReport(){
    var year = $('#year').val();
    var urls = "<?php echo base_url();?>report/loanReportPrint/"+year;
    window.location = urls;
    }

</script>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1 class="module-highlight">
            <span class="number">5.4</span>
            <?php echo $this->lang->line('loanReportTitle'); ?>
            <small><?php echo $this->lang->line('moduleT'); ?></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('module'); ?></a></li>
            <li class="active"><?php echo $this->lang->line('loanReportTitle'); ?></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <label class="box-title"><?php echo $this->lang->line('loanReportTitle')." ".$year; ?></label>
                        <div class="box-title pull-right">
                            <!-- <a href="<?php echo base_url().'expenses/addNew/'.$type; ?>" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon glyphicon-plus"></span></a>
                                <button id="btn_delete_expense" class="btn btn-primary btn-sm" disabled="disabled" onclick="conf_delete_sales(this)"><span class="glyphicon glyphicon glyphicon-minus"></span></button>
                                <a href="<?php echo base_url().'expenses/printAll/'.$type.'/'.$dateFrom.'/'.$dateTo; ?>" class="btn btn-primary btn-sm <?php echo (count($datatbls))?'':'disabled'; ?>"><span class="glyphicon glyphicon glyphicon-print"></span></a> -->
                            <button onclick="printLoanReport()" class="btn bg-orange btn-sm"><span class="fa fa-print fa-fw"></span> <?php echo $this->lang->line("printReport"); ?></button>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-header with-border">
                        <form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post">
                            <fieldset class="fsStyle">
                                <legend class="legendStyle">
                                    <a href="javascript:void(0);" data-toggle="collapse" data-target="#filter"><?php echo $this->lang->line('filter'); ?></a>
                                </legend>
                                <div id="filter" class="row collapse in">
                                    <div class="form-group col-sm-7">
                                        <label for="year" class="col-sm-5 control-label"><?php echo $this->lang->line('year'); ?>: </label>
                                        <div class="col-sm-7">
                                            <input type="text" class="form-control thisYearDatepicker" name="year" id="year" placeholder="<?php echo $this->lang->line('year'); ?>" value="<?php echo $year; ?>">
                                        </div>
                                    </div>
                                    <div class="form-group col-sm-2">
                                        <button type="submit" class="btn btn-primary pull-right"><?php echo $this->lang->line('submit'); ?></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                    <div class="box-body table-scroll-xs">
                        <table id="expenseList" class="table table-bordered table-striped datatables">
                            <thead>
                                <tr>
                                    <th class=''><?php echo $this->lang->line('loan/month'); ?></th>
                                    <th class='text-right'><?php echo $this->lang->line('balanceLoan'); ?></th>
                                    <th class='text-right'><?php echo $this->lang->line('openingBalance'); ?></th>
                                    <th class='text-right'><?php echo $this->lang->line('newLoan'); ?></th>
                                    <th class=''><?php echo $this->lang->line('jan'); ?></th>
                                    <th class=''><?php echo $this->lang->line('feb'); ?></th>
                                    <th class=''><?php echo $this->lang->line('mar'); ?></th>
                                    <th class=''><?php echo $this->lang->line('apr'); ?></th>
                                    <th class=''><?php echo $this->lang->line('may'); ?></th>
                                    <th class=''><?php echo $this->lang->line('jun'); ?></th>
                                    <th class=''><?php echo $this->lang->line('jul'); ?></th>
                                    <th class=''><?php echo $this->lang->line('aug'); ?></th>
                                    <th class=''><?php echo $this->lang->line('sep'); ?></th>
                                    <th class=''><?php echo $this->lang->line('oct'); ?></th>
                                    <th class=''><?php echo $this->lang->line('nov'); ?></th>
                                    <th class=''><?php echo $this->lang->line('dec'); ?></th>
                                    <th class='text-right'><?php echo $this->lang->line('lastPayment'); ?></th>
                                    <th class='text-right'><?php echo $this->lang->line('lastPaymentAmount'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    if(!empty($loans)):
                                      $i = 1;
                                      foreach($loans as $row):
                                    ?>
                                <tr>
                                    <th class=''><?php echo $row->acctName; ?></th>
                                    <th class='text-right'><?php echo number_format($row->balanceLoan,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->openingBalanceCr,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->newloan,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->january,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->february,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->march,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->april,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->may,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->june,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->july,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->august,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->september,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->october,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->november,2); ?></th>
                                    <th class='text-right'><?php echo number_format($row->december,2); ?></th>
                                    <th class='text-right'><?php echo (!empty($row->lastPaymentDate))?date("d-m-Y",strtotime($row->lastPaymentDate)):''; ?></th>
                                    <th class='text-right'><?php echo number_format($row->lastPaymentAmount,2); ?></th>
                                </tr>
                                <?php
                                    endforeach;
                                    endif;
                                    ?>
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
