
@extends('layouts.nav')
@section('title')
GL Report
@endsection
@section('content')               


<div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Accounting Report</h1>
                      </div>

                  
                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary"   id="formHeader">General Ledger Report</h6>
                        </div>
                        @if (session('success'))
                            <div class="alert alert-success" id="successMessage"  style="margin: 20px;">
                                {{ session('success') }}
                            </div>
                        @endif
                      
                        @if ($errors->any())

                                    <div class="form-group"  id="successMessage"  style="margin: 20px;">
                                        <div class="card bg-warning text-white shadow">
                                            <div class="card-body">
                                        
                                                @foreach ($errors->all() as $error)
                                                <div style="color: red; ">{{ $error }}</div>
                                                @endforeach
                                        
                                            </div>
                                        </div>
                                    </div>
                                    @endif
                            <form class="card-body" action="{{route('fetchGeneralLedger')}}" method="post"  id="accountTypeForm">
                            @csrf
                            <input type="hidden" id="accountId" name="id" value="">
                                
                                <div class="form-group row">
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                    <select class="form-control form-control-user" id="account" name="account"  value="{{ old('account') }}"  required>
                                        <option value="" disabled selected>GL Account</option>

                                        @foreach ($Accounts as $Account)
                                        
                                        <option value="{{ $Account->AccCode }}">{{ $Account->AccCode.'/'.$Account->AccName }}</option>  
                                        @endforeach
                                    </select>
                                    </div>
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="date" class="form-control form-control-user" id="from" placeholder="from" name="from" value="{{ old('date', \Carbon\Carbon::now()->format('Y-m-d')) }}" required>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="date" class="form-control form-control-user" id="to" placeholder="to" name="to"  value="{{ old('date', \Carbon\Carbon::now()->format('Y-m-d')) }}" required>
                                    </div>
                                    
                                </div>

                                <div class="form-group row">
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                    <select class="form-control form-control-user" id="curr" name="curr"  value="{{ old('curr') }}"  required>
                                        <option value="" disabled selected>Select Currency</option>

                                        @foreach ($currencys as $currency)
                                        
                                        <option value="{{ $currency->ID}}">{{ $currency->Name }}</option>
                                          
                                        @endforeach
                                    </select>
                                    </div>
                                 
                                 
                                    
                                </div>

                               <div style="display: flex;">
                               <input type="submit" style="width: 100px;height: 40px; margin-right: 10px; margin-top: 6px" value="View" class="btn btn-primary btn-user btn-block" id="submitButton"/>

                                <input style="width: 100px;"    type="reset" value="Refresh" class="btn btn-secondary btn-user btn-block"  onclick="hideMessages()"/>
                                    
                               </div>
                                
                                <hr>
                             </form>
                   
                        
                          

                        <div class="card-body">
                            <div class="table-responsive">
                            <button id="download-pdf" style="float: right; margin: 5px;" class="btn btn-primary">Download PDF</button>
 
                             <div>
    <div class="py-4">
      <div class="px-14 py-6">
        <table class="w-full border-collapse border-spacing-0">
          <tbody>
            <tr>
              <td class="w-full align-top">
              <div style="display: flex;">
                    <img style="width: 100px; height: 100px;" src="{!! asset('img/logo.png') !!}" class="h-12" />
                    <p class="whitespace-nowrap font-bold text-main text-10xl ml-4" style="margin-top: 30px; font: 30px;">{{$name}} GL Report</p>
                </div>
              </td>

              <td class="align-top">
                <div class="text-sm">
                  <table class="border-collapse border-spacing-0">
                    <tbody>
                      <tr>
                        <td class="border-r pr-4">
                          <div>
                            <p class="whitespace-nowrap text-slate-400 text-right">Date</p>
                            @php
                            use Carbon\Carbon;
                            $todayLongDate = Carbon::now()->format(' F j, Y'); 
                            @endphp
                            <p class="whitespace-nowrap font-bold text-main text-right">{{$todayLongDate}}</p>
                          </div>
                        </td>
                        <td class="pl-4">
                          <div>
                            <p class="whitespace-nowrap text-slate-400 text-right">Account</p>
                            <p class="whitespace-nowrap font-bold text-main text-right">{{$code}}</p>
                          </div>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="bg-slate-100 px-14 py-6 text-sm">
        <table class="w-full border-collapse border-spacing-0">
          <tbody>
            <tr>
              <td class="w-1/2 align-top">
                <div class="text-sm text-neutral-600">
                
                <p class="font-bold">Currency: {{$currnames}}</p>
                  <p>From: {{$from}} To: {{$to}}</p>


               
                </div>
              </td>
              <td class="w-1/2 align-top text-right">
                <div class="text-sm text-neutral-600">
               


                

                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="px-14 py-10 text-sm text-neutral-700">
        <table class="w-full border-collapse border-spacing-0">
          <thead>
            <tr>
           
              <td class="border-b-2 border-main pb-3 pl-2 font-bold text-main">Date</td> 
              <td class="border-b-2 border-main pb-3 pl-2 font-bold text-main">Description</td> 
              <td class="border-b-2 border-main pb-3 pl-2 pr-3 text-right font-bold text-main">Total</td>
            </tr>
          </thead>
          <tbody>



              
@php
             
                $b =0;
 @endphp

          @foreach ($trans as $tran)
            <tr>
              
           
               
              <td class="border-b py-3 pl-2">{{$to}}</td>
              <td class="border-b py-3 pl-2">{{$code.' '.$name}}</td>
             
            
              <td class="border-b py-3 pl-2 pr-3 text-right">
              @php
             
             $b =$tran->Total;
             @endphp
                  @if($tran->Total < 0)
                      ({{ number_format(abs($tran->Total), 2) }})
                  @else
                      {{ number_format($tran->Total, 2) }}
                  @endif
              </td>

            </tr>
            @endforeach


            <tr>
              <td colspan="9">
                <table class="w-full border-collapse border-spacing-0">
                  <tbody>
                    <tr>
                      <td class="w-full"></td>
                      <td>
                        <table class="w-full border-collapse border-spacing-0">
                          <tbody>
                        
                            
                            <tr>
                              <td class="bg-main p-3">
                                <div class="whitespace-nowrap font-bold text-white">Balance:</div>
                              </td>
                              <td class="bg-main p-3 text-right">
                                <div class="whitespace-nowrap font-bold text-white"> @if($b < 0)
                                  ({{ number_format(abs($b), 2) }})
                              @else
                                  {{ number_format($b, 2) }}
                              @endif</div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

     
     

      </div>
    </div>


 
                            </div>
                        </div>
                    
                    </div>

                    <script>
document.getElementById('download-pdf').addEventListener('click', function () {
    var element = document.querySelector('.py-4'); // Select the specific section you want to print
    var opt = {
        margin:       -0.3,
        filename:     'GLReport.pdf',
        image:        { type: 'jpeg', quality: 0.98 },
        html2canvas:  { scale: 2 },
        jsPDF:        { unit: 'in', format: 'A4', orientation: 'portrait' }
    };
    html2pdf().from(element).set(opt).save();
});
</script>

                    @endsection