<?php $__env->startSection('css'); ?>
<link href="<?php echo e(asset('css/dataTables.bootstrap4.min.css')); ?>" rel="stylesheet" />
<link href="<?php echo e(asset('css/sweetalert2.min.css')); ?>" rel="stylesheet" />
<link href="<?php echo e(asset('css/bootstrap-datepicker.min.css')); ?>" rel="stylesheet" />
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid pt-3">

    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('isSuperadmin')): ?>
    <div class="row justify-content-between">
        <div class="col-4">
            <form action="<?php echo e(route('finance.submit')); ?>"
            novalidate class="<?php echo e(($errors->any()) ? 'was-validated' : 'needs-validation'); ?>"
            method="post"
            >
            <?php echo csrf_field(); ?>
                <div class="form-group">
                    <label for="monthYear">รายรับ - รายจ่าย ประจำเดือน <span class="text-red">*</span></label>
                    <div class="input-group mb-3">
                        <input type="text" class="form-control datepiacker" id="monthYear" name="monthYear" placeholder="รายรับ - รายจ่าย ประจำเดือน" autocomplete="off" value="<?php echo e($month . '/'. $year); ?>" required>
                        <div class="input-group-append">
                            <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                        </div>
                        <button type="submit" class="btn btn-outline-success show-outline-btn ml-2" value="add-student">แสดง</button>
                    </div>
                    <?php $__errorArgs = ['monthYear'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div class="text-danger"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            </form>
        </div>
        <div class="col-4 text-right">
            <a href="#printModal" data-toggle="modal" data-target="#printModal" class="btn btn-outline-secondary"><i class="fas fa-print"></i> พิมพ์</a>
            <!-- Modal -->
            <div class="modal fade" id="printModal" tabindex="-1" role="dialog" aria-labelledby="printModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered" style="width:450px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title-card" id="printModalLabel">พิมพ์รายงาน</h5>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-6 text-left">
                                    รายงานรวมทุกสาขา
                                </div>
                                <div class="col-6">
                                    <a href="<?php echo e(route('pdf.finance', ['0', $month, $year, 'รายได้'])); ?>" target="_blank" class="btn btn-outline-success show-outline-btn"><i class="fas fa-print"></i> รายได้</a>
                                    <a href="<?php echo e(route('pdf.finance', ['0', $month, $year, 'รายจ่าย'])); ?>" target="_blank" class="btn btn-outline-danger ml-3"><i class="fas fa-print"></i> รายจ่าย</a>
                                </div>
                            </div>
                            <hr>
                            <?php $__currentLoopData = $branchs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $keyIndex => $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="row">
                                    <div class="col-6 text-left">
                                        รายงานสาขา<?php echo e($branch->name); ?>

                                    </div>
                                    <div class="col-6">
                                        <a href="<?php echo e(route('pdf.finance', [$branch->id, $month, $year, 'รายได้'])); ?>" target="_blank" class="btn btn-outline-success show-outline-btn"><i class="fas fa-print"></i> รายได้</a>
                                        <a href="<?php echo e(route('pdf.finance', [$branch->id, $month, $year, 'รายจ่าย'])); ?>" target="_blank" class="btn btn-outline-danger ml-3"><i class="fas fa-print"></i> รายจ่าย</a>
                                    </div>
                                </div>
                                <?php if(!$loop->last): ?>
                                <hr>
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">ปิด</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End modal -->
        </div>
    </div>
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#all" >ทุกสาขา</a>
            </li>
            <?php $__currentLoopData = $branchs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $keyIndex => $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <li>
                <a class="nav-link " href="#branch<?php echo e($keyIndex); ?>" data-toggle="tab"><?php echo e($branch->name); ?></a>
            </li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </ul>

        <div class="tab-content">
        <!-- All branch -->
        <div class="tab-pane active" id="all" >
            <div class="row mt-3" >
            <div class="col-6">
                <div class="card card-outline card-success">
                    <div class="card-header">
                        <h3 class="card-title">รายรับประจำเดือน : <?php if($total_income_all_branch!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_all_branch)); ?></span> บาท <?php endif; ?></h3>
                        <br>
                        <div class="row mt-2">
                            <div class="col-2">
                                <h6>เงินสด</h6>
                            </div>
                            <div class="col-10">
                                <h6>: <?php if($total_income_all_branch_cash!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_all_branch_cash)); ?></span> บาท <?php endif; ?></h6>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-2">
                                <h6>โอน</h6>
                            </div>
                            <div class="col-10">
                                <h6>: <?php if($total_income_all_branch_transfer!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_all_branch_transfer)); ?></span> บาท <?php endif; ?></h6>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-2">
                                <h6>บัตรเครดิต</h6>
                            </div>
                            <div class="col-10">
                                <h6>: <?php if($total_income_all_branch_credit!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_all_branch_credit)); ?></span> บาท <?php endif; ?></h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <table class="table finance-table" id="income-table">
                        <thead>
                            <tr>
                                <th scope="col" width="10%">#</th>
                                <th scope="col" width="20%">วันที่</th>
                                <th scope="col" width="30%">สาขา</th>
                                <th scope="col" width="20%">ประเภท</th>
                                <th scope="col" width="20%">รายรับ</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $income_all_branch; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $income): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                                <td class="align-middle"><?php echo e(formatDateFromDB($income->billDate)); ?></td>
                                <td class="align-middle"><?php echo e($income->name); ?></td>
                                <td class="align-middle"><?php echo e($income->method); ?></td>
                                <td class="align-middle"><?php echo e(number_format($income->amount)); ?></td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                      </table>
                    </div>
                </div>
            </div>
            <div class="col-6">
                <div class="card card-outline card-success">
                    <div class="card-header">
                        <h3 class="card-title">รายจ่ายประจำเดือน : <span class="text-bold text-danger"><?php echo e(number_format($total_expense_all_branch)); ?></span> บาท</h3>
                        <br>
                        <div class="row mt-2">
                            <div class="col-2">
                                <h6>เงินสด</h6>
                            </div>
                            <div class="col-10">
                                <h6>: <?php if($total_expense_all_branch_cash!=""): ?><span class="text-bold text-danger"><?php echo e(number_format($total_expense_all_branch_cash)); ?></span> บาท <?php endif; ?></h6>
                            </div>
                        </div>
                        <div class="row mb-4">
                            <div class="col-2">
                                <h6>โอน</h6>
                            </div>
                            <div class="col-10">
                                <h6>: <?php if($total_expense_all_branch_transfer!=""): ?><span class="text-bold text-danger"><?php echo e(number_format($total_expense_all_branch_transfer)); ?></span> บาท <?php endif; ?></h6>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <table class="table finance-table" id="outcome-table">
                            <thead>
                                <tr>
                                    <th scope="col" width="10%">#</th>
                                    <th scope="col" width="20%">วันที่</th>
                                    <th scope="col" width="30%">สาขา</th>
                                    <th scope="col" width="20%">ประเภท</th>
                                    <th scope="col" width="20%">รายจ่าย</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php $__currentLoopData = $expense_all_branch; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $expense): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                                    <td class="align-middle"><?php echo e(formatDateFromDB($expense->date)); ?></td>
                                    <td class="align-middle"><?php echo e($expense->name); ?></td>
                                    <td class="align-middle"><?php echo e($expense->method); ?></td>
                                    <td class="align-middle"><?php echo e(number_format($expense->amount)); ?></td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php $__currentLoopData = $income_branchs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x => $income_branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="tab-pane" id="branch<?php echo e($x); ?>" >
            <div class="row mt-3">
                <div class="col-6">
                    <div class="card card-outline card-success">
                        <div class="card-header">
                            <h3 class="card-title">รายรับประจำเดือน : <?php if($total_income_branch[$x]!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_branch[$x])); ?></span> บาท <?php endif; ?></h3>
                            <br>
                            <div class="row mt-2">
                                <div class="col-2">
                                    <h6>เงินสด</h6>
                                </div>
                                <div class="col-10">
                                    <h6>: <?php if($total_income_branch_cash[$x]!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_branch_cash[$x])); ?></span> บาท <?php endif; ?></h6>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-2">
                                    <h6>โอน</h6>
                                </div>
                                <div class="col-10">
                                    <h6>: <?php if($total_income_branch_transfer[$x]!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_branch_transfer[$x])); ?></span> บาท <?php endif; ?></h6>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-2">
                                    <h6>บัตรเครดิต</h6>
                                </div>
                                <div class="col-10">
                                    <h6>: <?php if($total_income_branch_credit[$x]!=""): ?><span class="text-bold text-primary"><?php echo e(number_format($total_income_branch_credit[$x])); ?></span> บาท <?php endif; ?></h6>
                                </div>
                            </div>
                        </div>
                        <div class="card-body">
                            <table class="table finance-table" id="income-table">
                                <thead>
                                    <tr>
                                        <th scope="col" width="10%">#</th>
                                        <th scope="col" width="20%">วันที่</th>
                                        <th scope="col" width="30%">สาขา</th>
                                        <th scope="col" width="20%">ประเภท</th>
                                        <th scope="col" width="20%">รายรับ</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $income_branch; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $income): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                                        <td class="align-middle"><?php echo e(formatDateFromDB($income->billDate)); ?></td>
                                        <td class="align-middle"><?php echo e($income->name); ?></td>
                                        <td class="align-middle"><?php echo e($income->method); ?></td>
                                        <td class="align-middle"><?php echo e(number_format($income->amount)); ?></td>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="col-6">
                    <div class="card card-outline card-success">
                        <div class="card-header">
                            <h3 class="card-title">รายจ่ายประจำเดือน : <?php if($total_expense_branch[$x]->total!=""): ?><span class="text-bold text-danger"><?php echo e(number_format($total_expense_branch[$x]->total)); ?></span> บาท <?php endif; ?></h3>
                            <br>
                            <div class="row mt-2">
                                <div class="col-2">
                                    <h6>เงินสด</h6>
                                </div>
                                <div class="col-10">
                                    <h6>: <?php if($total_expense_branch_cash[$x]->total!=""): ?><span class="text-bold text-danger"><?php echo e(number_format($total_expense_branch_cash[$x]->total)); ?></span> บาท <?php endif; ?></h6>
                                </div>
                            </div>
                            <div class="row mb-4">
                                <div class="col-2">
                                    <h6>โอน</h6>
                                </div>
                                <div class="col-10">
                                    <h6>: <?php if($total_expense_branch_transfer[$x]->total!=""): ?><span class="text-bold text-danger"><?php echo e(number_format($total_expense_branch_transfer[$x]->total)); ?></span> บาท <?php endif; ?></h6>
                                </div>
                            </div>
                        </div>
                        <div class="card-body">
                            <table class="table finance-table" id="income-table">
                                <thead>
                                    <tr>
                                        <th scope="col" width="10%">#</th>
                                        <th scope="col" width="20%">วันที่</th>
                                        <th scope="col" width="30%">สาขา</th>
                                        <th scope="col" width="20%">ประเภท</th>
                                        <th scope="col" width="20%">รายจ่าย</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $expense_branch[$x]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $expense): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                                        <td class="align-middle"><?php echo e(formatDateFromDB($expense->date)); ?></td>
                                        <td class="align-middle"><?php echo e($expense->name); ?></td>
                                        <td class="align-middle"><?php echo e($expense->method); ?></td>
                                        <td class="align-middle"><?php echo e(number_format($expense->amount)); ?></td>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div> <!-- end tab-content -->
    <?php endif; ?>

    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('isAdminOrUser')): ?>
    <div class="row">
        <div class="col-3">
            <form action="<?php echo e(route('finance.submit')); ?>"
            novalidate class="<?php echo e(($errors->any()) ? 'was-validated' : 'needs-validation'); ?>"
            method="post"
            >
            <?php echo csrf_field(); ?>
                <div class="form-group">
                    <label for="date">รายรับ - รายจ่าย ประจำวัน<span class="text-red">*</span></label>
                    <div class="input-group mb-3">
                        <input type="text" class="form-control datepiacker" id="monthYear" name="monthYear" placeholder="รายรับ - รายจ่าย ประจำวัน" autocomplete="off" value="<?php echo e($month . '/'. $year); ?>" required>
                        <div class="input-group-append">
                            <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                        </div>
                        <button type="submit" class="btn btn-outline-success show-outline-btn ml-2" value="add-student">แสดง</button>
                    </div>
                    <?php $__errorArgs = ['date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                    <div class="text-danger"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
            </form>
        </div>
    </div>
    <div class="row mt-3" >
        <div class="col-6">
            <div class="card card-outline card-success">
                <div class="card-header">
                    <h3 class="card-title">รายรับประจำวัน : <span class="text-bold text-primary"><?php if($total_income!=""): ?><?php echo e(number_format($total_income)); ?><?php else: ?> 0 <?php endif; ?></span> บาท</h3>
                    <br>
                    <div class="row mt-2">
                        <div class="col-2">
                            <h6>เงินสด</h6>
                        </div>
                        <div class="col-10">
                            <h6>: <span class="text-bold text-primary"><?php if($total_income_cash!=""): ?><?php echo e(number_format($total_income_cash)); ?> <?php else: ?> 0 <?php endif; ?></span> บาท</h6>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-2">
                            <h6>โอน</h6>
                        </div>
                        <div class="col-10">
                            <h6>: <span class="text-bold text-primary"><?php if($total_income_transfer!=""): ?><?php echo e(number_format($total_income_transfer)); ?> <?php else: ?> 0 <?php endif; ?></span> บาท</h6>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-2">
                            <h6>บัตรเครดิต</h6>
                        </div>
                        <div class="col-10">
                            <h6>: <span class="text-bold text-primary"><?php if($total_income_credit!=""): ?><?php echo e(number_format($total_income_credit)); ?> <?php else: ?> 0 <?php endif; ?></span> บาท </h6>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <table class="table finance-table" id="income-table">
                    <thead>
                        <tr>
                            <th scope="col" width="10%">#</th>
                            <th scope="col" width="30%">วันที่</th>
                            <th scope="col" width="40%">ประเภท</th>
                            <th scope="col" width="20%">รายรับ</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $incomes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $income): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                            <td class="align-middle"><?php echo e(formatDateFromDB($income->billDate)); ?></td>
                            <td class="align-middle"><?php echo e($income->method); ?></td>
                            <td class="align-middle"><?php echo e(number_format($income->amount)); ?></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                  </table>
                </div>
            </div>
        </div>
        <div class="col-6">
            <div class="card card-outline card-success">
                <div class="card-header">
                    <h3 class="card-title">รายจ่ายประจำเดือน : <span class="text-bold text-danger"><?php if($total_expense!=""): ?><?php echo e(number_format($total_expense)); ?><?php else: ?> 0 <?php endif; ?></span> บาท</h3>
                    <br>
                    <div class="row mt-2">
                        <div class="col-2">
                            <h6>เงินสด</h6>
                        </div>
                        <div class="col-10">
                            <h6>: <span class="text-bold text-danger"><?php if($total_expense_cash!=""): ?><?php echo e(number_format($total_expense_cash)); ?><?php else: ?> 0 <?php endif; ?></span> บาท</h6>
                        </div>
                    </div>
                    <div class="row mb-4">
                        <div class="col-2">
                            <h6>โอน</h6>
                        </div>
                        <div class="col-10">
                            <h6>: <span class="text-bold text-danger"><?php if($total_expense_transfer!=""): ?><?php echo e(number_format($total_expense_transfer)); ?><?php else: ?> 0 <?php endif; ?></span> บาท</h6>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <table class="table finance-table" id="outcome-table">
                        <thead>
                            <tr>
                                <th scope="col" width="10%">#</th>
                                <th scope="col" width="30%">วันที่</th>
                                <th scope="col" width="40%">ประเภท</th>
                                <th scope="col" width="20%">รายจ่าย</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $indexKey => $expense): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="align-middle"><?php echo e($indexKey + 1); ?>.</td>
                                <td class="align-middle"><?php echo e(formatDateFromDB($expense->date)); ?></td>
                                <td class="align-middle"><?php echo e($expense->method); ?></td>
                                <td class="align-middle"><?php echo e(number_format($expense->amount)); ?></td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('footerscript'); ?>
<script src="<?php echo e(asset('js/sweetalert2.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/jquery.dataTables.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/dataTables.bootstrap4.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/bootstrap-datepicker.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/bootstrap-datepicker.th.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/custom.js')); ?>"></script>
<script src="<?php echo e(asset('js/finance.js')); ?>"></script>
<?php $__env->stopSection(); ?>



<?php echo $__env->make('layouts.web', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/pongpetch/resources/views/finance/index.blade.php ENDPATH**/ ?>