<?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="#">Balance Sheet</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>Balance Sheet</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>
            <input type="hidden" value="<?php echo e($branch->branch_en); ?>" id="branch_en">
            <input type="hidden" value="<?php echo e($branch->branch_kh); ?>" id="branch_kh">
            <form action="<?php echo e(route('print.balance-sheet')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo e(method_field('POST')); ?>

                <div class="title-bar col-sm-12">
                    <?php
                    // $start  = new DateTime('first day of this month');
                    $end    = new DateTime('last day of this month');
                    // $from   = $start->format('d/m/Y');
                    $from = '';
                    $to     = $end->format('d/m/Y');
                    ?>
                    <span class="title-tab">
                        <span class="text-tab"> Balance Sheet >> <span id="start_date"><?php echo e($from); ?></span> >> <span id="end_date"><?php echo e($to); ?></span> </span>
                        <span class="btn-toggle btn btn-primary btn-xs pull-right" style="margin-left:5px"><i class="fa fa-caret-down"></i></span>
                        
                        <button type="button" class="btn btn-tab btn-xs btn-warning pull-right print_button"><i class="fa fa-print"></i></button>
                        <input type="hidden" name="report" value="Balance Sheet">
                    </span>
                </div>
                <div class="row col-sm-12">
                    <div class="col-sm-12 toggle-div" style="display:none">
                        <hr>
                        <div class="form-group  col-sm-4 col-xs-4">
                            <label>Select Project</label>
                            <?php echo Form::select('journal_by_project', $projects, null, ['class' => 'form-control select2','id'=>'project_id']); ?>

                        </div>
                        <div class="col-sm-4">
                            <label for="">Start Date</label>
                            <div class="form-group">
                                <input type="text" name="from" class="form-control start_date date_picker">
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <label for="">End Date</label>
                            <div class="form-group">
                                <input type="text" name="to" id="" class="form-control end_date date_picker">
                            </div>
                        </div>
                        <div class="col-sm-12" style="text-align: right">
                            <label for="">&nbsp;</label>
                            <div class="form-group">
                                <button type="button" class="btn btn-warning btn-md" onclick="search()"><i class="fa fa-search"></i> Search</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </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">
                                
                                <tbody id="tbody"></tbody>
                            </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).ready(function() {
        $.ajax({
            url: "<?php echo e(route('accounting-report.get-balance-sheet')); ?>",
            method: "get",
            dataType: "text",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
            },
            success: function(data) {
                $('#tbody').append(data);
            }
        });
    });
    $(document).on('click', '.clickable-row', function() {
        window.location = $(this).data("href");
    });
    $(document).on('click', '.btn-toggle', function() {
        $('.toggle-div').toggle('fast');
    });

    function search() {
        var from = $('.start_date').val();
        var to = $('.end_date').val();
        var project = $('#project_id').val();
        if (from == "" || to == "") {
            $.alert({
                title: 'Error',
                icon: 'fa fa-warning',
                type: 'orange',
                content: 'Something went wrong, please retry again.' +
                    '<hr>' +
                    'Note: No Date Selected',
            });
            return false;
        } else {
            $.ajax({
                url: "<?php echo e(route('accounting-report.get-balance-sheet')); ?>",
                method: "POST",
                dataType: "text",
                data: {
                    from: from,
                    to: to,
                    project: project,
                    _token: '<?php echo e(csrf_token()); ?>',
                },
                success: function(data) {
                    $('#start_date').text(from);
                    $('#end_date').text(to);
                    $('#tbody').empty();
                    $('#tbody').append(data);
                }
            });
        }
    }
    $(document).on('click', '.print_button', function () {
        let company_name_kh = $('#branch_kh').val();
        let company_name_en = $('#branch_en').val();
        let report_name     = 'Report Balance Sheet';
        $('#table_journal').printThis({
            importCSS: false,
            loadCSS: "<?php echo e(asset('assets/layouts/report.css')); ?>",
            afterPrint: function () {
            },
            header: `<div class="header pt_15 none_bg">
                    <div class="div2">
                        <img src="" alt="" class="logo">
                    </div>
                    <div class="div8">
                        <div class="title">
                            <h2>${company_name_kh}</h2>
                            <h2>${company_name_en}</h2>
                            <h3>${report_name}</h3>
                        </div>
                    </div>
                    <div class="div2">

                    </div>
                    <div class="div12 border-bottom">

                    </div>
                </div>`,
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>