<?php Fun::lang() ?>

<?php $__env->startSection('css'); ?>
<style>
    /* .table-striped>tbody>tr:nth-child(odd){
        background-color: #c8e9ff;
    } */
</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="title-page">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="#">Reports</a></li>
            <li><a href="#">Reports Accounting</a></li>
            <li><a href="#">Ledger</a></li>
        </ul>
    </div>
</div>
<div class="page">
    <div class="top-content">
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="title-add">
                    <div class="pull-left">
                        <h3>Ledger List</h3>
                    </div>
                    <div class="pull-right">
                        <!-- <a href="<?php echo e(route('journal.create')); ?>" class="btn btn-info fa fa-plus"> Add New</a> -->
                    </div>
                </div>
            </div>
            <div class="col-sm-12 block-action">
                <p class="pull-right btn-action btn btn-xs btn-info" data-toggle="tooltip" data-placement="top" title="Hide/Show"><i class="fa fa-caret-down" aria-hidden="true"></i></p>
                
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12" id="block-action" style="display:none">
                <div class="content-action">
                    <div class="col-sm-5">
                        <div class="col-sm-4">
                            <label for="">Reference Number</label>
                        </div>
                        <div class="col-sm-8">
                            <div class="form-group">
                                <?php if(isset($acc_code)): ?>
                                <?php echo Form::select('acc_chart', $account_chart, $acc_code, ['class' => 'form-control select2 acc_type','required','id'=>'acc_code']); ?>

                                <?php else: ?>
                                <?php echo Form::select('acc_chart', $account_chart, null, ['class' => 'form-control select2 acc_type','required','id'=>'acc_code']); ?>

                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="col-sm-4">
                            <label for="">Start Date</label>
                        </div>
                        <?php
                            $from = (isset($start_date)&&!empty($start_date)) ? date('d-m-Y',strtotime($start_date)) : '';
                            $to = (isset($end_date)&&!empty($end_date)) ? date('d-m-Y',strtotime($end_date)) : '';
                        ?>
                        <div class="col-sm-8">
                            <input type="text" class="form-control date_picker start_date" value="<?php echo e($from); ?>">
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="col-sm-4">
                            <label for="">End Date</label>
                        </div>
                        <div class="col-sm-8">
                            <input type="text" class="form-control date_picker end_date" value="<?php echo e($to); ?>">
                        </div>
                    </div>
                    <div class="col-sm-1">
                        <button type="button" class="btn btn-warning btn-lg fa fa-search" onclick="search_ledger()"> Search</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">
            <div class="form-wrapper">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-responsive">
                            <table id="table_journal" class="table table-bordered table-striped table table-condensed table-hover">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>Project</th>
                                        <th>Type</th>
                                        <th>Date</th>
                                        <th>Reference Number</th>
                                        <th>Name</th>
                                        <th>Description</th>
                                        <th>Created By</th>
                                        <th>Debit</th>
                                        <th>Credit</th>
                                        <th>Amount</th>
                                    </tr>
                                </thead>
                                <tbody id="tbody"></tbody>
                                <tfoot id="tfoot">
                                    <tr>

                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade bs-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h3 class="modal-title text-danger">Warning...!</h3>
            </div>
            <br />
            <div class="row">
                <div class="col-md-12">
                    <div class="col-md-10">
                        <h4>Receivable amount must be smaller than or equal available amount.</h4>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" data-dismiss="modal" class="button_primary"><i class="fa fa-close"></i> Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
<script type="text/javascript">
    $(document).on('click', '.btn-action', function() {
        $('#block-action').toggle("fast");
    });
    $("form").submit(function(e) {

    });
    $(document).ready(function() {
        var acc_code = $('#acc_code').val();
        var end_date = $('.end_date').val();
        var start_date = $('.start_date').val();

        var tr = "";
        var total_debit = 0;
        var total_credit = 0;
        $('#tbody').empty();
        $('#tfoot').empty();
        disable_datatable_features();
        $.ajax({
            url: "<?php echo e(route('get-accounting-report.ledger')); ?>",
            method: "GET",
            dataType: "text",
            data: {
                acc_code: acc_code,
                start_date: start_date,
                end_date: end_date,
                _token: '<?php echo e(csrf_token()); ?>',
            },
            success: function(data) {
                $('#tbody').append(data);
            }
        });

        /*if (acc_code != "" && end_date != "" && start_date != "") {
            var tr = "";
            var total_debit = 0;
            var total_credit = 0;
            $('#tbody').empty();
            $('#tfoot').empty();
            disable_datatable_features();
            $.ajax({
                url: "<?php echo e(route('get-accounting-report.ledger')); ?>",
                method: "POST",
                dataType: "text",
                data: {
                    acc_code: acc_code,
                    start_date: start_date,
                    end_date: end_date,
                    _token: '<?php echo e(csrf_token()); ?>',
                },
                success: function(data) {
                    $('#tbody').append(data);
                }
            });
        } else {
            $.ajax({
                url: "<?php echo e(route('get-accounting-report.ledger')); ?>",
                method: "get",
                dataType: "text",
                data: {
                    _token: '<?php echo e(csrf_token()); ?>',
                },
                success: function(data) {
                    $('#tbody').append(data);
                }
            });
        }*/

    });

    function search_ledger() {

        var acc_code        = $('#acc_code').val();
        var end_date        = $('.end_date').val();
        var start_date      = $('.start_date').val();
        var tr              = "";
        var total_debit     = 0;
        var total_credit    = 0;
        $('#tbody').empty();
        $('#tfoot').empty();
        disable_datatable_features();
        $.ajax({
            url: "<?php echo e(route('get-accounting-report.ledger')); ?>",
            method: "GET",
            dataType: "text",
            data: {
                acc_code: acc_code,
                start_date: start_date,
                end_date: end_date,
                _token: '<?php echo e(csrf_token()); ?>',
            },
            success: function(data) {
                $('#tbody').append(data);
            }
        });
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>