@extends('layouts.app')

@section('content')

<div class='container'>
@include('admin.adminheader')
<div class="page-title-box">
                <div class="row align-items-center">
                    <div class="col-sm-6">
                        <h4 class="page-title">Orders</h4>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-right">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Admin</a></li>
                            <li class="breadcrumb-item active">Orders</li>
                        </ol>
                    </div>
                </div>
                <!-- end row -->
            </div>

        <div class='row d-flex justify-content-center'>
            <div class='col-md-12'>
            <table id="example" class="table table-striped data-table" style="width:100%">
        <thead>
            <tr class='dt-row'>
                <th>ID</th>
                <th>Business Name</th>
                <th>Business Email</th>
                <th>Package</th>
                <th>Order#</th>
                <th>Invoice#</th>
                <th>Payment Method</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
            </div>
        </div>
    </div>

    <script type="text/javascript">
  $(function () {
      
    var table = $('.data-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('orderslist') }}",
        columns: [
            {data: 'id'},
            {data: 'bname'},
            {data: 'bemail'},
            {data: 'productname'},
            {
            data: 'ordernumber',
            render: function (data) {
                try {
                    // Add a null check before using substr
                    return data ? '#'+data: '-'; // Example: Extract the first 5 characters
                } catch (error) {
                    // Log any errors to the console
                    console.error('Error in render function:', error);
                    return '-'; // Return an empty string in case of an error
                }
            }
        },
             {data: 'invoice_id'},
            {data: 'payment_method'},
            {
                data: 'order_status',
                className: 'status-column'
            },
            {data: 'action', name: 'action', orderable: false, searchable: false},

        ]
    });
      
  });
</script>

@endsection

  