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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Name</p>
                    <p>{organizations?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                <>
                    <p className={'block font-bold mb-2'}>Users Organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>First Name</th>
                                
                                
                                
                                <th>Last Name</th>
                                
                                
                                
                                <th>Phone Number</th>
                                
                                
                                
                                <th>E-Mail</th>
                                
                                
                                
                                <th>Disabled</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.users_organizations && Array.isArray(organizations.users_organizations) &&
                              organizations.users_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/users/users-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="firstName">
                                        { item.firstName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lastName">
                                        { item.lastName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phoneNumber">
                                        { item.phoneNumber }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disabled">
                                        { dataFormatter.booleanFormatter(item.disabled) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.users_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Firms organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>FirmName</th>
                                
                                
                                
                                <th>LegalName</th>
                                
                                
                                
                                <th>TaxIDNumber</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>ContactEmail</th>
                                
                                
                                
                                <th>ContactPhone</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>TrialEndsAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.firms_organizations && Array.isArray(organizations.firms_organizations) &&
                              organizations.firms_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/firms/firms-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="legal_name">
                                        { item.legal_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_id_number">
                                        { item.tax_id_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contact_email">
                                        { item.contact_email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contact_phone">
                                        { item.contact_phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="trial_ends_at">
                                        { dataFormatter.dateTimeFormatter(item.trial_ends_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.firms_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Merchants organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>BusinessName</th>
                                
                                
                                
                                <th>LegalName</th>
                                
                                
                                
                                <th>TINNumber</th>
                                
                                
                                
                                <th>VATRegistrationNumber</th>
                                
                                
                                
                                <th>TaxpayerType</th>
                                
                                
                                
                                <th>Industry</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>ContactName</th>
                                
                                
                                
                                <th>ContactPhone</th>
                                
                                
                                
                                <th>ContactEmail</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>OnboardedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.merchants_organizations && Array.isArray(organizations.merchants_organizations) &&
                              organizations.merchants_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/merchants/merchants-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="business_name">
                                        { item.business_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="legal_name">
                                        { item.legal_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tin_number">
                                        { item.tin_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_registration_number">
                                        { item.vat_registration_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="taxpayer_type">
                                        { item.taxpayer_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="industry">
                                        { item.industry }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contact_name">
                                        { item.contact_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contact_phone">
                                        { item.contact_phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contact_email">
                                        { item.contact_email }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="onboarded_at">
                                        { dataFormatter.dateTimeFormatter(item.onboarded_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.merchants_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Customers organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CustomerName</th>
                                
                                
                                
                                <th>TINNumber</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>Email</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.customers_organizations && Array.isArray(organizations.customers_organizations) &&
                              organizations.customers_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/customers/customers-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tin_number">
                                        { item.tin_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.customers_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Suppliers organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SupplierName</th>
                                
                                
                                
                                <th>TINNumber</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>Email</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.suppliers_organizations && Array.isArray(organizations.suppliers_organizations) &&
                              organizations.suppliers_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/suppliers/suppliers-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tin_number">
                                        { item.tin_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.suppliers_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Products organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ProductName</th>
                                
                                
                                
                                <th>SKU</th>
                                
                                
                                
                                <th>TaxCategory</th>
                                
                                
                                
                                <th>DefaultUnitPrice</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.products_organizations && Array.isArray(organizations.products_organizations) &&
                              organizations.products_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/products/products-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sku">
                                        { item.sku }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_category">
                                        { item.tax_category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="default_unit_price">
                                        { item.default_unit_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.products_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Receipts organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ReceiptKind</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>SourceChannel</th>
                                
                                
                                
                                <th>CapturedAt</th>
                                
                                
                                
                                <th>OCRStatus</th>
                                
                                
                                
                                <th>OCRConfidence</th>
                                
                                
                                
                                <th>NeedsReview</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.receipts_organizations && Array.isArray(organizations.receipts_organizations) &&
                              organizations.receipts_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/receipts/receipts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="receipt_kind">
                                        { item.receipt_kind }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="source_channel">
                                        { item.source_channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="captured_at">
                                        { dataFormatter.dateTimeFormatter(item.captured_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ocr_status">
                                        { item.ocr_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ocr_confidence">
                                        { item.ocr_confidence }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="needs_review">
                                        { dataFormatter.booleanFormatter(item.needs_review) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.receipts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Ocr_extractions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ProcessedAt</th>
                                
                                
                                
                                <th>OCREngine</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>InvoiceNumber(Text)</th>
                                
                                
                                
                                <th>SellerName(Text)</th>
                                
                                
                                
                                <th>BuyerName(Text)</th>
                                
                                
                                
                                <th>TINNumber(Text)</th>
                                
                                
                                
                                <th>InvoiceDate</th>
                                
                                
                                
                                <th>SubtotalAmount</th>
                                
                                
                                
                                <th>VATAmount</th>
                                
                                
                                
                                <th>TOTAmount</th>
                                
                                
                                
                                <th>TotalAmount</th>
                                
                                
                                
                                <th>RawText</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.ocr_extractions_organizations && Array.isArray(organizations.ocr_extractions_organizations) &&
                              organizations.ocr_extractions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/ocr_extractions/ocr_extractions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="processed_at">
                                        { dataFormatter.dateTimeFormatter(item.processed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="engine">
                                        { item.engine }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invoice_number_text">
                                        { item.invoice_number_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="seller_name_text">
                                        { item.seller_name_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="buyer_name_text">
                                        { item.buyer_name_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tin_number_text">
                                        { item.tin_number_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invoice_date">
                                        { dataFormatter.dateTimeFormatter(item.invoice_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subtotal_amount">
                                        { item.subtotal_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_amount">
                                        { item.vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tot_amount">
                                        { item.tot_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="raw_text">
                                        { item.raw_text }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.ocr_extractions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sales_invoices organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>InvoiceNumber</th>
                                
                                
                                
                                <th>InvoiceDate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>VATTreatment</th>
                                
                                
                                
                                <th>SubtotalAmount</th>
                                
                                
                                
                                <th>VATAmount</th>
                                
                                
                                
                                <th>TotalAmount</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                <th>ReviewNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.sales_invoices_organizations && Array.isArray(organizations.sales_invoices_organizations) &&
                              organizations.sales_invoices_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sales_invoices/sales_invoices-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="invoice_number">
                                        { item.invoice_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invoice_date">
                                        { dataFormatter.dateTimeFormatter(item.invoice_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_treatment">
                                        { item.vat_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subtotal_amount">
                                        { item.subtotal_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_amount">
                                        { item.vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="review_notes">
                                        { item.review_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.sales_invoices_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sales_invoice_lines organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>UnitPrice</th>
                                
                                
                                
                                <th>LineSubtotal</th>
                                
                                
                                
                                <th>VATTreatment</th>
                                
                                
                                
                                <th>VATAmount</th>
                                
                                
                                
                                <th>LineTotal</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.sales_invoice_lines_organizations && Array.isArray(organizations.sales_invoice_lines_organizations) &&
                              organizations.sales_invoice_lines_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sales_invoice_lines/sales_invoice_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price">
                                        { item.unit_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_subtotal">
                                        { item.line_subtotal }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_treatment">
                                        { item.vat_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_amount">
                                        { item.vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total">
                                        { item.line_total }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.sales_invoice_lines_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Purchase_invoices organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>InvoiceNumber</th>
                                
                                
                                
                                <th>InvoiceDate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>VATTreatment</th>
                                
                                
                                
                                <th>SubtotalAmount</th>
                                
                                
                                
                                <th>VATAmount</th>
                                
                                
                                
                                <th>WithholdingTaxAmount</th>
                                
                                
                                
                                <th>TotalAmount</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                <th>ReviewNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.purchase_invoices_organizations && Array.isArray(organizations.purchase_invoices_organizations) &&
                              organizations.purchase_invoices_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/purchase_invoices/purchase_invoices-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="invoice_number">
                                        { item.invoice_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invoice_date">
                                        { dataFormatter.dateTimeFormatter(item.invoice_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_treatment">
                                        { item.vat_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subtotal_amount">
                                        { item.subtotal_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_amount">
                                        { item.vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="withholding_tax_amount">
                                        { item.withholding_tax_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="review_notes">
                                        { item.review_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.purchase_invoices_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Purchase_invoice_lines organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Quantity</th>
                                
                                
                                
                                <th>UnitPrice</th>
                                
                                
                                
                                <th>LineSubtotal</th>
                                
                                
                                
                                <th>VATTreatment</th>
                                
                                
                                
                                <th>VATAmount</th>
                                
                                
                                
                                <th>LineTotal</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.purchase_invoice_lines_organizations && Array.isArray(organizations.purchase_invoice_lines_organizations) &&
                              organizations.purchase_invoice_lines_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/purchase_invoice_lines/purchase_invoice_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity">
                                        { item.quantity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit_price">
                                        { item.unit_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_subtotal">
                                        { item.line_subtotal }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_treatment">
                                        { item.vat_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_amount">
                                        { item.vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="line_total">
                                        { item.line_total }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.purchase_invoice_lines_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Expenses organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>ExpenseDate</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>TaxTreatment</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                <th>ReviewNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.expenses_organizations && Array.isArray(organizations.expenses_organizations) &&
                              organizations.expenses_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/expenses/expenses-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expense_date">
                                        { dataFormatter.dateTimeFormatter(item.expense_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_treatment">
                                        { item.tax_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="review_notes">
                                        { item.review_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.expenses_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tax_periods organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PeriodType</th>
                                
                                
                                
                                <th>YearNumber</th>
                                
                                
                                
                                <th>PeriodNumber</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>DueDate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.tax_periods_organizations && Array.isArray(organizations.tax_periods_organizations) &&
                              organizations.tax_periods_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tax_periods/tax_periods-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="period_type">
                                        { item.period_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="year_number">
                                        { item.year_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_number">
                                        { item.period_number }
                                    </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="due_date">
                                        { dataFormatter.dateTimeFormatter(item.due_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.tax_periods_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vat_declarations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>TotalSalesAmount</th>
                                
                                
                                
                                <th>TaxableSalesAmount</th>
                                
                                
                                
                                <th>OutputVATAmount</th>
                                
                                
                                
                                <th>TotalPurchasesAmount</th>
                                
                                
                                
                                <th>InputVATAmount</th>
                                
                                
                                
                                <th>VATPayableAmount</th>
                                
                                
                                
                                
                                
                                <th>GeneratedAt</th>
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.vat_declarations_organizations && Array.isArray(organizations.vat_declarations_organizations) &&
                              organizations.vat_declarations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vat_declarations/vat_declarations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_sales_amount">
                                        { item.total_sales_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="taxable_sales_amount">
                                        { item.taxable_sales_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="output_vat_amount">
                                        { item.output_vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_purchases_amount">
                                        { item.total_purchases_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="input_vat_amount">
                                        { item.input_vat_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vat_payable_amount">
                                        { item.vat_payable_amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="generated_at">
                                        { dataFormatter.dateTimeFormatter(item.generated_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.vat_declarations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tot_declarations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>GrossSalesAmount</th>
                                
                                
                                
                                <th>TOTRatePercent</th>
                                
                                
                                
                                <th>TOTPayableAmount</th>
                                
                                
                                
                                
                                
                                <th>GeneratedAt</th>
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.tot_declarations_organizations && Array.isArray(organizations.tot_declarations_organizations) &&
                              organizations.tot_declarations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tot_declarations/tot_declarations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_sales_amount">
                                        { item.gross_sales_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tot_rate_percent">
                                        { item.tot_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tot_payable_amount">
                                        { item.tot_payable_amount }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="generated_at">
                                        { dataFormatter.dateTimeFormatter(item.generated_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.tot_declarations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Declaration_submissions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>DeclarationType</th>
                                
                                
                                
                                <th>SubmissionReference</th>
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>ResponseMessage</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.declaration_submissions_organizations && Array.isArray(organizations.declaration_submissions_organizations) &&
                              organizations.declaration_submissions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/declaration_submissions/declaration_submissions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="declaration_type">
                                        { item.declaration_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submission_reference">
                                        { item.submission_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="response_message">
                                        { item.response_message }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.declaration_submissions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Messages organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Channel</th>
                                
                                
                                
                                <th>Subject</th>
                                
                                
                                
                                <th>Body</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.messages_organizations && Array.isArray(organizations.messages_organizations) &&
                              organizations.messages_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/messages/messages-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="channel">
                                        { item.channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subject">
                                        { item.subject }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="body">
                                        { item.body }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.messages_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Audit_events organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Action</th>
                                
                                
                                
                                <th>EntityName</th>
                                
                                
                                
                                <th>RecordKey</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>Details</th>
                                
                                
                                
                                <th>IPAddress</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.audit_events_organizations && Array.isArray(organizations.audit_events_organizations) &&
                              organizations.audit_events_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/audit_events/audit_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="action">
                                        { item.action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_name">
                                        { item.entity_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="record_key">
                                        { item.record_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="details">
                                        { item.details }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ip_address">
                                        { item.ip_address }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.audit_events_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default OrganizationsView;