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/vehicles/vehiclesSlice'
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 VehiclesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { vehicles } = useAppSelector((state) => state.vehicles)
    
    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 vehicles')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View vehicles')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/vehicles/vehicles-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

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

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>VehicleCode</p>
                    <p>{vehicles?.vehicle_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PlateNo</p>
                    <p>{vehicles?.plate_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>EngineNo</p>
                    <p>{vehicles?.engine_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ChassisNo</p>
                    <p>{vehicles?.chassis_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Make</p>
                    <p>{vehicles?.make}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Model</p>
                    <p>{vehicles?.model}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Year</p>
                  <p>{vehicles?.year || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Colour</p>
                    <p>{vehicles?.colour}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Category</p>
                    <p>{vehicles?.category}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>PurchaseCost</p>
                  <p>{vehicles?.purchase_cost || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>OwnershipType</p>
                    <p>{vehicles?.ownership_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CurrentDriver</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{vehicles?.current_driver?.driver_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Branch</p>
                    <p>{vehicles?.branch}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Odometer</p>
                  <p>{vehicles?.odometer || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>InsurancePolicyNo</p>
                    <p>{vehicles?.insurance_policy_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Agreements Vehicle</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>
                            {vehicles.agreements_vehicle && Array.isArray(vehicles.agreements_vehicle) &&
                              vehicles.agreements_vehicle.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>
                        {!vehicles?.agreements_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Invoices Vehicle</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>
                            {vehicles.invoices_vehicle && Array.isArray(vehicles.invoices_vehicle) &&
                              vehicles.invoices_vehicle.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>
                        {!vehicles?.invoices_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Invoice_lines Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>LineType</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>Rate</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.invoice_lines_vehicle && Array.isArray(vehicles.invoice_lines_vehicle) &&
                              vehicles.invoice_lines_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/invoice_lines/invoice_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="line_type">
                                        { item.line_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rate">
                                        { item.rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.invoice_lines_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_expenses Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ExpenseNo</th>
                                
                                
                                
                                <th>Date</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ExpenseCategory</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>TaxAmount</th>
                                
                                
                                
                                <th>GrossAmount</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_expenses_vehicle && Array.isArray(vehicles.vehicle_expenses_vehicle) &&
                              vehicles.vehicle_expenses_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_expenses/vehicle_expenses-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="expense_no">
                                        { item.expense_no }
                                    </td>
                                    
                                    
                                    
                                    <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="tax_amount">
                                        { item.tax_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_amount">
                                        { item.gross_amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_expenses_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Driver_expenses Vehicle</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>
                            {vehicles.driver_expenses_vehicle && Array.isArray(vehicles.driver_expenses_vehicle) &&
                              vehicles.driver_expenses_vehicle.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>
                        {!vehicles?.driver_expenses_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bills Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>BillNo</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>BillDate</th>
                                
                                
                                
                                <th>DueDate</th>
                                
                                
                                
                                <th>GrossAmount</th>
                                
                                
                                
                                <th>AmountPaid</th>
                                
                                
                                
                                <th>BalanceDue</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.bills_vehicle && Array.isArray(vehicles.bills_vehicle) &&
                              vehicles.bills_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/bills/bills-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="bill_no">
                                        { item.bill_no }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="bill_date">
                                        { dataFormatter.dateTimeFormatter(item.bill_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_date">
                                        { dataFormatter.dateTimeFormatter(item.due_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_amount">
                                        { item.gross_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>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.bills_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ledger_entries Vehicle</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>
                            {vehicles.ledger_entries_vehicle && Array.isArray(vehicles.ledger_entries_vehicle) &&
                              vehicles.ledger_entries_vehicle.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>
                        {!vehicles?.ledger_entries_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Loan_schedules Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>BankName</th>
                                
                                
                                
                                <th>PaymentNo</th>
                                
                                
                                
                                <th>PaymentDate</th>
                                
                                
                                
                                <th>PaymentAmount</th>
                                
                                
                                
                                <th>Principal</th>
                                
                                
                                
                                <th>Interest</th>
                                
                                
                                
                                <th>RemainingBalance</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.loan_schedules_vehicle && Array.isArray(vehicles.loan_schedules_vehicle) &&
                              vehicles.loan_schedules_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/loan_schedules/loan_schedules-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="bank_name">
                                        { item.bank_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payment_no">
                                        { item.payment_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payment_date">
                                        { dataFormatter.dateTimeFormatter(item.payment_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payment_amount">
                                        { item.payment_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="principal">
                                        { item.principal }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="interest">
                                        { item.interest }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remaining_balance">
                                        { item.remaining_balance }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.loan_schedules_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_compliance Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RegistrationExpiry</th>
                                
                                
                                
                                <th>FitnessExpiry</th>
                                
                                
                                
                                <th>InsuranceExpiry</th>
                                
                                
                                
                                <th>InsurancePolicyNo</th>
                                
                                
                                
                                <th>CertificateNo</th>
                                
                                
                                
                                <th>Mileage</th>
                                
                                
                                
                                <th>RegistrationStatus</th>
                                
                                
                                
                                <th>InsuranceStatus</th>
                                
                                
                                
                                <th>FitnessStatus</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_compliance_vehicle && Array.isArray(vehicles.vehicle_compliance_vehicle) &&
                              vehicles.vehicle_compliance_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_compliance/vehicle_compliance-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="registration_expiry">
                                        { dataFormatter.dateTimeFormatter(item.registration_expiry) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fitness_expiry">
                                        { dataFormatter.dateTimeFormatter(item.fitness_expiry) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="insurance_expiry">
                                        { dataFormatter.dateTimeFormatter(item.insurance_expiry) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="insurance_policy_no">
                                        { item.insurance_policy_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="certificate_no">
                                        { item.certificate_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="mileage">
                                        { item.mileage }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="registration_status">
                                        { item.registration_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="insurance_status">
                                        { item.insurance_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fitness_status">
                                        { item.fitness_status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_compliance_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default VehiclesView;