@extends('layouts.master')
@section('content')
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>

.user-info {
            margin: 0 auto;
            max-width: 100%;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 10px;
            margin: 0 0 10px 0;
        }
  </style>

 <div class="container-xxl flex-grow-1 container-p-y">
              <div class="row">
                <div class="col-lg-12 mb-4 order-0">
                  <div class="card">
                        <div class="card-body">
                            <div>
                                <h3>{{__('Accounting')}}</h3>
                                @if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif
                            </div>
                        </div>
                  </div>
                </div>
              </div>
              <div class="card">
                <div class="card-body">

                  <div class="table-responsive text-nowrap">
                    <table id="myDataTable" class="table" width="100%" cellspacing="0">
                      <thead>
                          <tr>
                              <th>{{__('shopname')}}</th>
                              <th>{{__('contactdetails')}}</th>
                              <th>{{__('plantype')}}</th>
                              <th>{{__('dues')}}</th>
                              <th>{{__('action')}}</th>


                          </tr>
                      </thead>
                      <tbody  class="table-border-bottom-0">
                          <!-- Table rows -->
                          @foreach($adminList as $admin)
                          <tr>
                              <td>
                                <img src="{{ asset($admin->shopimage)}}" width="40px" height="40px" alt="Img">
                                <br>
                              <b>  {{ $admin->shopname }}</b>

                              </td>
                              <td>
                                <p><strong>{{__('name')}}:</strong> {{ $admin->name }}</p>
                                <p>{{ substr($admin->adress, 0, 50) . (strlen($admin->adress) > 50 ? '...' : '') }}</p>
                                <p><strong>{{__('Phone')}}:</strong> {{ $admin->shopnumber }}</p>
                                <p><strong>{{__('Email')}}:</strong> {{ $admin->email }}</p>
                            </td>
                              <td>
                                @if ($admin->plan_type == 0 )
                                <span class="badge rounded-pill bg-primary">{{__('free')}}</span>
                            @elseif($admin->plan_type == 1)
                            <span class="badge rounded-pill bg-primary">{{__('standard')}}</span>
                            @else
                            <span class="badge rounded-pill bg-primary">{{__('premium')}}</span>

                            @endif
                              </td>
                              <td>{{ $admin->dues."¥" }}</td>
                              <td>
                                @if( $admin->dues !=0 )

                                {{-- <button data-bs-toggle="modal" data-bs-target="#medicineallModal" type="button" class="btn btn-primary">{{__('emailInvoice')}}</button> --}}

                                <a href="{{url('super-admin/email-admin/'.$admin->id)}}"  class="btn btn-primary"> {{__('emailInvoice')}}</a><br>
                                <button style="margin-top: 5px" data-bs-toggle="modal"
                                data-bs-target="#exampleModal" onclick="adminInfo({{ $admin }})"
                                type="button"class="btn btn-success">{{__('transactions')}}</button>
                                @else
                                <button data-bs-toggle="modal"
                                data-bs-target="#exampleModal" onclick="adminInfo({{ $admin }})"
                                type="button"class="btn btn-success">{{__('transactions')}}</button>


                                @endif

                              </td>

                          </tr>
                          @endforeach
                      </tbody>

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


        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">

          <div class="modal-dialog modal-xl modal-dialog-centered">
              <div class="modal-content">
                    <div class="modal-header text-center">
                      <div class="d-flex justify-content-center align-items-center">
                      </div>
                      <div class="buttons-container">
                          <button type="button" class="btn btn-primary" id="printButton">{{__('print')}}</button>
                          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                  </div>


                  <div class="modal-body">

                      <div class="user-info">
                        <p id="shop_name">Shop Name: ----</p>
                          <p id="repersent_name">Name: ----</p>
                          <p id="adress_name">Name: ----</p>
                          <p class="usernumber" id="usernumber">Mobile Number: ----</p>
                          <p class="ad_email" id="ad_email"> Email: ----</p>
                          <p class="regdate" id="regdate"> REG DAte: ----</p>

                      </div>


                      <div id="cart-section">
                      <div class="card"  style="padding: 0 10px">



                        <h3 class="text-center">{{__('transactions')}}</h3>

                              <div class="card">

                                  <div class="table-wrapper">
                                      <table class="table" id="cart-table">
                                          <thead>
                                            <tr>
                                              <th>{{__('id')}}</th>
                                              <th>{{__('invoice no')}}</th>
                                              <th>{{__('month')}}</th>
                                              <th>{{__('payment Date')}}</th>
                                              <th>{{__('ammount')}}</th>
                                              <th>{{__('pay method')}}</th>
                                              <th>{{__('Trans ID')}}</th>


                                          </tr>
                                          </thead>

                                          <tbody id="cart-table-body" class="table-border-bottom-0">
                                          </tbody>
                                      </table>

                                  </div>

                              </div>







                  </div>
                      </div>
                  </div>
              </div>
              <script>
                $('#myDataTable').hide(); // Hide the table initially
                  $(document).ready(function() {
                      $('#myDataTable').DataTable({
                          order: [
                              [0, 'desc']
                          ], // Sort by the first column (index 0) in descending order
                          orderMulti: false, // Disable multi-column ordering
                          initComplete: function(settings, json) {
                              $('#myDataTable')
                                  .show(); // Show the table after DataTable initialization
                          }
                      });
                  });
          </script>
          </div>
    <script>
        function adminInfo(admin) {
          document.getElementById('repersent_name').textContent = " {{__('name')}} : " + admin.name;
          document.getElementById('shop_name').textContent = " {{__('Shop Name')}} : " + admin.shopname;
          document.getElementById('adress_name').textContent = " {{__('adress')}} : " + admin.adress;
          document.getElementById('usernumber').textContent = " {{__('Phone')}} : " + admin.shopnumber;
          document.getElementById('ad_email').textContent = " {{__('Email')}} : " + admin.email;
          document.getElementById('regdate').textContent = " {{__('RegDate')}} : " + admin.created_at.split('T')[0];
           var admin_id = admin.id;
          $.ajax({
            url: "{{ route('billingdetails') }}",
            type: 'GET',
            data: {admin_id: admin_id},
            success: function(response) {
            console.log(response);

                const tbody = document.getElementById('cart-table-body');

// Clear any existing rows from the table
tbody.innerHTML = '';
response.forEach(rowData => {
                const row = `<tr>
                                <td>${rowData.id}</td>
                                <td>${rowData.inv_no}</td>
                                <td>${rowData.month}</td>
                                <td>${rowData.pay_date}</td>
                                <td>${rowData.amount}¥</td>
                                <td>${rowData.pay_method}</td>
                                <td>${rowData.transaction_code}</td>
                            </tr>`;
                tbody.innerHTML += row;
            });

            },
            error: function(xhr) {
                // Handle any errors
                console.log(xhr.responseText);
            }
        });


        }
        function sendemail(admin){

        }
    </script>

@endsection
