import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/drivers/driversSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";

import {hasPermission} from "../../helpers/userPermissions";


const DriversView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { drivers } = useAppSelector((state) => state.drivers)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

    const { id } = router.query;
    
    function removeLastCharacter(str) {
      console.log(str,`str`)
      return str.slice(0, -1);
    }

    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);


    return (
      <>
          <Head>
              <title>{getPageTitle('View drivers')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View drivers')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/drivers/drivers-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Company</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{drivers?.company?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DriverCode</p>
                    <p>{drivers?.driver_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DriverName</p>
                    <p>{drivers?.driver_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Phone</p>
                    <p>{drivers?.phone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Email</p>
                    <p>{drivers?.email}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={drivers?.address} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LicenseNumber</p>
                    <p>{drivers?.license_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='LicenseExpiryDate'>
                    {drivers.license_expiry_date ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={drivers.license_expiry_date ?
                        new Date(
                          dayjs(drivers.license_expiry_date).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No LicenseExpiryDate</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>NationalID</p>
                    <p>{drivers?.national_id}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TRN/TaxID</p>
                    <p>{drivers?.trn_tax_id}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SecurityDeposit</p>
                  <p>{drivers?.security_deposit || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CreditLimit</p>
                  <p>{drivers?.credit_limit || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{drivers?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={drivers?.notes} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='CreatedOn'>
                    {drivers.created_on ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={drivers.created_on ?
                        new Date(
                          dayjs(drivers.created_on).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No CreatedOn</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='ModifiedOn'>
                    {drivers.modified_on ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={drivers.modified_on ?
                        new Date(
                          dayjs(drivers.modified_on).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No ModifiedOn</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicles CurrentDriver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>VehicleCode</th>
                                
                                
                                
                                <th>PlateNo</th>
                                
                                
                                
                                <th>EngineNo</th>
                                
                                
                                
                                <th>ChassisNo</th>
                                
                                
                                
                                <th>Make</th>
                                
                                
                                
                                <th>Model</th>
                                
                                
                                
                                <th>Year</th>
                                
                                
                                
                                <th>Colour</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                <th>PurchaseDate</th>
                                
                                
                                
                                <th>PurchaseCost</th>
                                
                                
                                
                                <th>OwnershipType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                <th>Branch</th>
                                
                                
                                
                                <th>Odometer</th>
                                
                                
                                
                                <th>InsurancePolicyNo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                                
                                <th>ModifiedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.vehicles_current_driver && Array.isArray(drivers.vehicles_current_driver) &&
                              drivers.vehicles_current_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicles/vehicles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="vehicle_code">
                                        { item.vehicle_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="plate_no">
                                        { item.plate_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="engine_no">
                                        { item.engine_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chassis_no">
                                        { item.chassis_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="make">
                                        { item.make }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="model">
                                        { item.model }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="year">
                                        { item.year }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="colour">
                                        { item.colour }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="purchase_date">
                                        { dataFormatter.dateTimeFormatter(item.purchase_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="purchase_cost">
                                        { item.purchase_cost }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ownership_type">
                                        { item.ownership_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="branch">
                                        { item.branch }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="odometer">
                                        { item.odometer }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="insurance_policy_no">
                                        { item.insurance_policy_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="modified_on">
                                        { dataFormatter.dateTimeFormatter(item.modified_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.vehicles_current_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Agreements Driver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>AgreementNumber</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>AgreementType</th>
                                
                                
                                
                                <th>BillingFrequency</th>
                                
                                
                                
                                <th>DailyRate</th>
                                
                                
                                
                                <th>WeeklyRate</th>
                                
                                
                                
                                <th>MonthlyRate</th>
                                
                                
                                
                                <th>DepositRequired</th>
                                
                                
                                
                                <th>DepositAmount</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>RecurringInvoiceEnabled</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.agreements_driver && Array.isArray(drivers.agreements_driver) &&
                              drivers.agreements_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/agreements/agreements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="agreement_number">
                                        { item.agreement_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="agreement_type">
                                        { item.agreement_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="billing_frequency">
                                        { item.billing_frequency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="daily_rate">
                                        { item.daily_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="weekly_rate">
                                        { item.weekly_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="monthly_rate">
                                        { item.monthly_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deposit_required">
                                        { dataFormatter.booleanFormatter(item.deposit_required) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deposit_amount">
                                        { item.deposit_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recurring_invoice_enabled">
                                        { dataFormatter.booleanFormatter(item.recurring_invoice_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.agreements_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Invoices Driver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>InvoiceNo</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IssueDate</th>
                                
                                
                                
                                <th>DueDate</th>
                                
                                
                                
                                <th>WeekStart</th>
                                
                                
                                
                                <th>WeekEnd</th>
                                
                                
                                
                                <th>BillingDays</th>
                                
                                
                                
                                <th>HolidayDays</th>
                                
                                
                                
                                <th>BillableDays</th>
                                
                                
                                
                                <th>DailyRate</th>
                                
                                
                                
                                <th>GrossAmount</th>
                                
                                
                                
                                <th>ExpenseDeductions</th>
                                
                                
                                
                                <th>NetAmount</th>
                                
                                
                                
                                <th>AmountPaid</th>
                                
                                
                                
                                <th>BalanceDue</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.invoices_driver && Array.isArray(drivers.invoices_driver) &&
                              drivers.invoices_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/invoices/invoices-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="invoice_no">
                                        { item.invoice_no }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="issue_date">
                                        { dataFormatter.dateTimeFormatter(item.issue_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_date">
                                        { dataFormatter.dateTimeFormatter(item.due_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="week_start">
                                        { dataFormatter.dateTimeFormatter(item.week_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="week_end">
                                        { dataFormatter.dateTimeFormatter(item.week_end) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="billing_days">
                                        { item.billing_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="holiday_days">
                                        { item.holiday_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="billable_days">
                                        { item.billable_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="daily_rate">
                                        { item.daily_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_amount">
                                        { item.gross_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expense_deductions">
                                        { item.expense_deductions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="net_amount">
                                        { item.net_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount_paid">
                                        { item.amount_paid }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="balance_due">
                                        { item.balance_due }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.invoices_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payments Driver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PaymentRef</th>
                                
                                
                                
                                <th>PaymentDate</th>
                                
                                
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>AllocatedAmount</th>
                                
                                
                                
                                <th>UnallocatedAmount</th>
                                
                                
                                
                                <th>Method</th>
                                
                                
                                
                                <th>ReferenceNo</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.payments_driver && Array.isArray(drivers.payments_driver) &&
                              drivers.payments_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payments/payments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="payment_ref">
                                        { item.payment_ref }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payment_date">
                                        { dataFormatter.dateTimeFormatter(item.payment_date) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allocated_amount">
                                        { item.allocated_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unallocated_amount">
                                        { item.unallocated_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="method">
                                        { item.method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reference_no">
                                        { item.reference_no }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.payments_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Driver_expenses Driver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Date</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ExpenseCategory</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ChargeToDriver</th>
                                
                                
                                
                                <th>BillableToDriver</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.driver_expenses_driver && Array.isArray(drivers.driver_expenses_driver) &&
                              drivers.driver_expenses_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/driver_expenses/driver_expenses-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="date">
                                        { dataFormatter.dateTimeFormatter(item.date) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="expense_category">
                                        { item.expense_category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="charge_to_driver_flag">
                                        { dataFormatter.booleanFormatter(item.charge_to_driver_flag) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="billable_to_driver_flag">
                                        { dataFormatter.booleanFormatter(item.billable_to_driver_flag) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.driver_expenses_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ledger_entries Driver</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>EntryNo</th>
                                
                                
                                
                                <th>TransactionDate</th>
                                
                                
                                
                                <th>SourceModule</th>
                                
                                
                                
                                <th>SourceRef</th>
                                
                                
                                
                                
                                
                                <th>Debit</th>
                                
                                
                                
                                <th>Credit</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {drivers.ledger_entries_driver && Array.isArray(drivers.ledger_entries_driver) &&
                              drivers.ledger_entries_driver.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ledger_entries/ledger_entries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="entry_no">
                                        { item.entry_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="transaction_date">
                                        { dataFormatter.dateTimeFormatter(item.transaction_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source_module">
                                        { item.source_module }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source_ref">
                                        { item.source_ref }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="debit">
                                        { item.debit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="credit">
                                        { item.credit }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!drivers?.ledger_entries_driver?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                

                <BaseDivider />

                <BaseButton
                    color='info'
                    label='Back'
                    onClick={() => router.push('/drivers/drivers-list')}
                />
              </CardBox>
          </SectionMain>
      </>
    );
};

DriversView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated
        
        permission={'READ_DRIVERS'}
        
      >
          {page}
      </LayoutAuthenticated>
    )
}

export default DriversView;