@extends('layouts.master')
@section('title', 'Report')

@section('page-header')
<header class="header bg-ui-general">
     <div class="header-info">
          <h1 class="header-title">
               <strong>Report</strong>
          </h1>
     </div>
</header>
@endsection

@section('content')

{{-- Top Sales Products in This Month --}}
<div class="col-12">
     <div class="card">
          <form action="#" method="GET">
               <div class="card-body">
                    <div class="form-row">
                         <div class="form-group col-md-5">
                              <input type="text" name="start_date" data-provide="datepicker"
                                   data-date-today-highlight="true" data-orientation="bottom"
                                   data-date-format="yyyy-mm-dd" data-date-autoclose="true" class="form-control"
                                   placeholder="Enter Start Date" autocomplete="off" value="{{ $start_date }}">
                         </div>
                         <div class="form-group col-md-5">
                              <input type="text" name="end_date" data-provide="datepicker"
                                   data-date-today-highlight="true" data-orientation="bottom"
                                   data-date-format="yyyy-mm-dd" data-date-autoclose="true" class="form-control"
                                   placeholder="Enter End Date" autocomplete="off" value="{{ $end_date }}">
                         </div>
                         <div class="form-group col-md-2">
                              <button class="btn btn-primary" type="submit">Filter</button>
                              <a href="{{ request()->url() }}" class="btn btn-info">Reset</a>
                              <a href="" class="btn btn-primary" onclick="window.print()">Print</a>
                         </div>
                    </div>
               </div>
          </form>
     </div>
</div>
{{-- Summary Report --}}
{{-- @dd($sells) --}}

{{-- Income this month --}}
<div class="col-12 print_area">
     <div class="card-body" style="margin-top:-40px">
          <h4 class="fw-600 text-center">{{ $pos_setting->company }}</h4>
     </div>
     <div class="row">
          <div class="col-lg-6 col-md-6 col-sm-12 grid-of-2 income">
               <div class="card">
                    <div class="card-header bg-success income-header">
                         <h5 class="card-title text-white"><strong>Income</strong></h5>
                    </div>
                    <div class="card-body">
                         <h5 class="card-title text-white expense_print"><strong>Income</strong></h5>
                         <table class="table table-bordered table-hover table-striped table-responsive"
                              data-provide="datatables">
                              <thead class="bg-light">
                                   <tr>
                                        <th>S</th>
                                        <th>Date</th>
                                        <th>Main Category</th>
                                        <th>Sub Category</th>
                                        <th>Note</th>
                                        <th>Amount</th>
                                   </tr>
                              </thead>
                              <tbody>
                                   @foreach ($incomes as $key => $income)
                                   <tr>
                                        <td>{{ ++$key }}</td>
                                        <td>{{ date('d-m-Y', strtotime($income->income_date)) }}</td>
                                        <td>
                                             {{ $income->category ? $income->category->name : 'No Category'}}
                                        </td>
                                        <td>{{ $income->sub_category ? $income->sub_category->name : '' }}</td>
                                        <td>{{ $income->note }}</td>
                                        <td>{{ $income->amount }}</td>
                                   </tr>
                                   @endforeach
                              <tfoot class="bg-light">
                                   <tr>
                                        <th colspan="5"></th>
                                        <th>
                                             <strong>
                                                  {{ number_format($totalIncome=$incomes->sum('amount')) }}
                                             </strong>
                                        </th>
                                   </tr>
                              </tfoot>
                              </tbody>
                         </table>
                    </div>
               </div>
          </div>

          {{-- Expense this month --}}
          <div class="col-lg-6 col-md-6 col-sm-12 grid-of-2 expense">
               <div class="card">
                    <div class="card-header bg-danger expense-header">
                         <h5 class="card-title text-white"><strong>Expense</strong></h5>
                    </div>
                    <div class="card-body">
                         <h5 class="card-title text-white expense_print"><strong>Expense</strong></h5>
                         <table class="table table-bordered table-hover table-striped table-responsive"
                              data-provide="datatables">
                              <thead class="bg-light">
                                   <tr>
                                        <th>S</th>
                                        <th>Date</th>
                                        <th>Main Category</th>
                                        <th>Sub Category</th>
                                        <th>Note</th>
                                        <th>Amount</th>
                                   </tr>
                              </thead>
                              <tbody>
                                   @foreach ($expenses as $key => $item)
                                   <tr>
                                        <td>{{ ++$key }}</td>
                                        <td>{{ date('d-m-Y', strtotime($item->expense_date)) }}</td>
                                        <td>
                                             {{ $item->category ? $item->category->name : 'No Category'}}
                                        </td>
                                        <td> {{ $item->sub_category ? $item->sub_category->name : '' }}</td>
                                        <td>{{ $item->note }}</td>
                                        <td>{{ $item->amount }}</td>
                                   </tr>
                                   @endforeach
                              <tfoot class="bg-light">
                                   <tr>
                                        <th colspan="5"></th>

                                        <th>
                                             <strong>
                                                  ৳
                                                  {{ number_format($totalExpense=$expenses->sum('amount')) }}
                                             </strong>
                                        </th>
                                   </tr>
                              </tfoot>
                              </tbody>
                         </table>
                    </div>
               </div>
          </div>
          <div class="col-lg-12 col-md-6 col-sm-12">
               <h3 class="text-center fw-600 balance">Balance : ৳{{ number_format($totalIncome - $totalExpense) }}</h3>
          </div>
     </div>
</div>
@endsection

@section('styles')
<style>
     .expense_print {
          display: none !important;
     }

     .income_print {
          display: none !important;
     }

     @media print {

          .dataTables_length,
          .dt-buttons,
          .dataTables_filter,
          .dataTables_info,
          .income-header,
          .expense-header {
               display: none !important;
          }

          /* .grid-of-2 {
            width: 100% !important;
            display: grid !important;
            grid-template-columns: repeat(2, minmax(100px, 1fr)) !important;
            grid-column-gap: 1.5% !important;
            /* float: left !important; */
          /* } */

          .expense_print {
               display: block !important;
               text-align: center !important;
               color: black !important;
          }

          .income_print {
               display: block !important;
               text-align: center !important;
               color: black !important;
          }

          .income {
               width: 100% !important;
               float: left !important;
          }

          .expense {
               width: 100% !important;
               float: left !important;
          }

          .balance {
               text-align: center !important;
          }

          .table-bordered td,
          .table-bordered th {
               border: 1px solid #e9ecef !important;
               padding: 5px !important;
          }
     }
</style>
@endsection

@section('scripts')

@endsection