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'}>Outlets organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>OutletCode</th>
                                
                                
                                
                                <th>OutletName</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>GPSLatitude</th>
                                
                                
                                
                                <th>GPSLongitude</th>
                                
                                
                                
                                <th>GPSRadius(m)</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.outlets_organizations && Array.isArray(organizations.outlets_organizations) &&
                              organizations.outlets_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/outlets/outlets-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gps_lat">
                                        { item.gps_lat }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gps_lng">
                                        { item.gps_lng }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gps_radius_m">
                                        { item.gps_radius_m }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.outlets_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Job_positions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>PositionCode</th>
                                
                                
                                
                                <th>PositionName</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>PayrollWeight</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.job_positions_organizations && Array.isArray(organizations.job_positions_organizations) &&
                              organizations.job_positions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/job_positions/job_positions-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payroll_weight">
                                        { item.payroll_weight }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.job_positions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employees organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>EmployeeCode</th>
                                
                                
                                
                                <th>FullName</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>NIK</th>
                                
                                
                                
                                <th>NPWP</th>
                                
                                
                                
                                <th>BankName</th>
                                
                                
                                
                                <th>BankAccountNumber</th>
                                
                                
                                
                                <th>BankAccountName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>EmploymentStatus</th>
                                
                                
                                
                                <th>JoinDate</th>
                                
                                
                                
                                <th>ResignDate</th>
                                
                                
                                
                                <th>BaseSalary(Monthly)</th>
                                
                                
                                
                                <th>PositionAllowance(Fixed)</th>
                                
                                
                                
                                <th>MealAllowance(Daily)</th>
                                
                                
                                
                                <th>TransportAllowance(Daily)</th>
                                
                                
                                
                                <th>ProratePositionAllowanceUnder20Days</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.employees_organizations && Array.isArray(organizations.employees_organizations) &&
                              organizations.employees_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employees/employees-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="employee_code">
                                        { item.employee_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="full_name">
                                        { item.full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="nik">
                                        { item.nik }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="npwp">
                                        { item.npwp }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bank_name">
                                        { item.bank_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bank_account_number">
                                        { item.bank_account_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bank_account_name">
                                        { item.bank_account_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="employment_status">
                                        { item.employment_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="join_date">
                                        { dataFormatter.dateTimeFormatter(item.join_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="resign_date">
                                        { dataFormatter.dateTimeFormatter(item.resign_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_salary_monthly">
                                        { item.base_salary_monthly }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="position_allowance_fixed">
                                        { item.position_allowance_fixed }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="meal_allowance_daily">
                                        { item.meal_allowance_daily }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="transport_allowance_daily">
                                        { item.transport_allowance_daily }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="prorate_position_allowance_under_20_days">
                                        { dataFormatter.booleanFormatter(item.prorate_position_allowance_under_20_days) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.employees_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employee_contracts organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ContractType</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.employee_contracts_organizations && Array.isArray(organizations.employee_contracts_organizations) &&
                              organizations.employee_contracts_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employee_contracts/employee_contracts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="contract_type">
                                        { item.contract_type }
                                    </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="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.employee_contracts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Attendance_logs organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>WorkDate</th>
                                
                                
                                
                                <th>CheckInTime</th>
                                
                                
                                
                                <th>CheckOutTime</th>
                                
                                
                                
                                <th>CheckInLatitude</th>
                                
                                
                                
                                <th>CheckInLongitude</th>
                                
                                
                                
                                <th>CheckOutLatitude</th>
                                
                                
                                
                                <th>CheckOutLongitude</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LateMinutes</th>
                                
                                
                                
                                <th>GPSValid</th>
                                
                                
                                
                                <th>Remarks</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.attendance_logs_organizations && Array.isArray(organizations.attendance_logs_organizations) &&
                              organizations.attendance_logs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/attendance_logs/attendance_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="work_date">
                                        { dataFormatter.dateTimeFormatter(item.work_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_in_at">
                                        { dataFormatter.dateTimeFormatter(item.check_in_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_out_at">
                                        { dataFormatter.dateTimeFormatter(item.check_out_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_in_lat">
                                        { item.check_in_lat }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_in_lng">
                                        { item.check_in_lng }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_out_lat">
                                        { item.check_out_lat }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_out_lng">
                                        { item.check_out_lng }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="late_minutes">
                                        { item.late_minutes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gps_valid">
                                        { dataFormatter.booleanFormatter(item.gps_valid) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remarks">
                                        { item.remarks }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.attendance_logs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Attendance_requests organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RequestType</th>
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                
                                
                                <th>ApprovalStatus</th>
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>DecidedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.attendance_requests_organizations && Array.isArray(organizations.attendance_requests_organizations) &&
                              organizations.attendance_requests_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/attendance_requests/attendance_requests-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="request_type">
                                        { item.request_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="approval_status">
                                        { item.approval_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decided_at">
                                        { dataFormatter.dateTimeFormatter(item.decided_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.attendance_requests_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Overtime_logs organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>WorkDate</th>
                                
                                
                                
                                <th>OvertimeHours</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                <th>ApprovalStatus</th>
                                
                                
                                
                                
                                
                                <th>ApprovedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.overtime_logs_organizations && Array.isArray(organizations.overtime_logs_organizations) &&
                              organizations.overtime_logs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/overtime_logs/overtime_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="work_date">
                                        { dataFormatter.dateTimeFormatter(item.work_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hours">
                                        { item.hours }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="approval_status">
                                        { item.approval_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="approved_at">
                                        { dataFormatter.dateTimeFormatter(item.approved_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.overtime_logs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Disciplinary_actions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Level</th>
                                
                                
                                
                                <th>IssuedAt</th>
                                
                                
                                
                                <th>ValidUntil</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.disciplinary_actions_organizations && Array.isArray(organizations.disciplinary_actions_organizations) &&
                              organizations.disciplinary_actions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/disciplinary_actions/disciplinary_actions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="level">
                                        { item.level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="issued_at">
                                        { dataFormatter.dateTimeFormatter(item.issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_until">
                                        { dataFormatter.dateTimeFormatter(item.valid_until) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.disciplinary_actions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Kpi_periods organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>PeriodName</th>
                                
                                
                                
                                <th>PeriodStart</th>
                                
                                
                                
                                <th>PeriodEnd</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.kpi_periods_organizations && Array.isArray(organizations.kpi_periods_organizations) &&
                              organizations.kpi_periods_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/kpi_periods/kpi_periods-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_start">
                                        { dataFormatter.dateTimeFormatter(item.period_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end">
                                        { dataFormatter.dateTimeFormatter(item.period_end) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.kpi_periods_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Kpi_scores organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AbsensiScore</th>
                                
                                
                                
                                <th>DisiplinScore</th>
                                
                                
                                
                                <th>ProduktivitasScore</th>
                                
                                
                                
                                <th>AttitudeScore</th>
                                
                                
                                
                                <th>SOPScore</th>
                                
                                
                                
                                <th>FinalScore</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                                
                                <th>ScoredAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.kpi_scores_organizations && Array.isArray(organizations.kpi_scores_organizations) &&
                              organizations.kpi_scores_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/kpi_scores/kpi_scores-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="absensi_score">
                                        { item.absensi_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disiplin_score">
                                        { item.disiplin_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="produktif_score">
                                        { item.produktif_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="attitude_score">
                                        { item.attitude_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sop_score">
                                        { item.sop_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="final_score">
                                        { item.final_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scored_at">
                                        { dataFormatter.dateTimeFormatter(item.scored_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.kpi_scores_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Outlet_revenues organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>RevenueDate</th>
                                
                                
                                
                                <th>GrossRevenue</th>
                                
                                
                                
                                <th>NetRevenue</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.outlet_revenues_organizations && Array.isArray(organizations.outlet_revenues_organizations) &&
                              organizations.outlet_revenues_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/outlet_revenues/outlet_revenues-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="revenue_date">
                                        { dataFormatter.dateTimeFormatter(item.revenue_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_revenue">
                                        { item.gross_revenue }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="net_revenue">
                                        { item.net_revenue }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.outlet_revenues_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Service_charge_pools organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PeriodName</th>
                                
                                
                                
                                <th>PeriodStart</th>
                                
                                
                                
                                <th>PeriodEnd</th>
                                
                                
                                
                                <th>TotalServiceCharge</th>
                                
                                
                                
                                <th>DistributionMethod</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.service_charge_pools_organizations && Array.isArray(organizations.service_charge_pools_organizations) &&
                              organizations.service_charge_pools_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/service_charge_pools/service_charge_pools-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="period_name">
                                        { item.period_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_start">
                                        { dataFormatter.dateTimeFormatter(item.period_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end">
                                        { dataFormatter.dateTimeFormatter(item.period_end) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="distribution_method">
                                        { item.distribution_method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.service_charge_pools_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Loan_accounts organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>PrincipalAmount</th>
                                
                                
                                
                                <th>InstallmentAmount</th>
                                
                                
                                
                                <th>RemainingAmount</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.loan_accounts_organizations && Array.isArray(organizations.loan_accounts_organizations) &&
                              organizations.loan_accounts_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/loan_accounts/loan_accounts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="principal_amount">
                                        { item.principal_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="installment_amount">
                                        { item.installment_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remaining_amount">
                                        { item.remaining_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.loan_accounts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payroll_periods organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>PeriodName</th>
                                
                                
                                
                                <th>PeriodStart</th>
                                
                                
                                
                                <th>PeriodEnd</th>
                                
                                
                                
                                
                                
                                <th>StandardWorkdays</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>GeneratedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.payroll_periods_organizations && Array.isArray(organizations.payroll_periods_organizations) &&
                              organizations.payroll_periods_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payroll_periods/payroll_periods-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_start">
                                        { dataFormatter.dateTimeFormatter(item.period_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end">
                                        { dataFormatter.dateTimeFormatter(item.period_end) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="standard_workdays">
                                        { item.standard_workdays }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="generated_at">
                                        { dataFormatter.dateTimeFormatter(item.generated_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.payroll_periods_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payroll_items organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Workdays</th>
                                
                                
                                
                                <th>SickDays</th>
                                
                                
                                
                                <th>LeaveDays</th>
                                
                                
                                
                                <th>AbsentDays</th>
                                
                                
                                
                                <th>LateCount</th>
                                
                                
                                
                                <th>LateMinutesTotal</th>
                                
                                
                                
                                <th>BaseSalary(Monthly)</th>
                                
                                
                                
                                <th>DailyRate</th>
                                
                                
                                
                                <th>BaseSalaryTotal</th>
                                
                                
                                
                                <th>Meal+TransportTotal</th>
                                
                                
                                
                                <th>PositionAllowanceTotal</th>
                                
                                
                                
                                <th>KPIScore</th>
                                
                                
                                
                                <th>KPIAllowanceTotal</th>
                                
                                
                                
                                <th>OvertimeHoursTotal</th>
                                
                                
                                
                                <th>OvertimeRate</th>
                                
                                
                                
                                <th>OvertimeTotal</th>
                                
                                
                                
                                <th>RevenueBonusTotal</th>
                                
                                
                                
                                <th>ServiceChargeTotal</th>
                                
                                
                                
                                <th>DeductionTotal</th>
                                
                                
                                
                                <th>TakeHomePay</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>AdjustmentNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.payroll_items_organizations && Array.isArray(organizations.payroll_items_organizations) &&
                              organizations.payroll_items_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payroll_items/payroll_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="workdays">
                                        { item.workdays }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sick_days">
                                        { item.sick_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="leave_days">
                                        { item.leave_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="absent_days">
                                        { item.absent_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="late_count">
                                        { item.late_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="late_minutes_total">
                                        { item.late_minutes_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_salary_monthly">
                                        { item.base_salary_monthly }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="daily_rate">
                                        { item.daily_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_salary_total">
                                        { item.base_salary_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="meal_transport_total">
                                        { item.meal_transport_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="position_allowance_total">
                                        { item.position_allowance_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="kpi_score">
                                        { item.kpi_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="kpi_allowance_total">
                                        { item.kpi_allowance_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="overtime_hours_total">
                                        { item.overtime_hours_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="overtime_rate">
                                        { item.overtime_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="overtime_total">
                                        { item.overtime_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="revenue_bonus_total">
                                        { item.revenue_bonus_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="service_charge_total">
                                        { item.service_charge_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deduction_total">
                                        { item.deduction_total }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="take_home_pay">
                                        { item.take_home_pay }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adjustment_notes">
                                        { item.adjustment_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.payroll_items_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payroll_adjustments 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>AdjustmentType</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                                
                                <th>EffectiveAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.payroll_adjustments_organizations && Array.isArray(organizations.payroll_adjustments_organizations) &&
                              organizations.payroll_adjustments_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payroll_adjustments/payroll_adjustments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adjustment_type">
                                        { item.adjustment_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="effective_at">
                                        { dataFormatter.dateTimeFormatter(item.effective_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.payroll_adjustments_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payslips organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SlipNumber</th>
                                
                                
                                
                                
                                
                                <th>IssuedAt</th>
                                
                                
                                
                                <th>DeliveryStatus</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>DeliveryNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.payslips_organizations && Array.isArray(organizations.payslips_organizations) &&
                              organizations.payslips_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payslips/payslips-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="slip_number">
                                        { item.slip_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="issued_at">
                                        { dataFormatter.dateTimeFormatter(item.issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_status">
                                        { item.delivery_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_notes">
                                        { item.delivery_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.payslips_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Notification_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>MessageType</th>
                                
                                
                                
                                
                                
                                <th>Recipient</th>
                                
                                
                                
                                <th>Subject</th>
                                
                                
                                
                                <th>Body</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>QueuedAt</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>ProviderMessageID</th>
                                
                                
                                
                                <th>ErrorMessage</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.notification_messages_organizations && Array.isArray(organizations.notification_messages_organizations) &&
                              organizations.notification_messages_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/notification_messages/notification_messages-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="channel">
                                        { item.channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message_type">
                                        { item.message_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="recipient">
                                        { item.recipient }
                                    </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="queued_at">
                                        { dataFormatter.dateTimeFormatter(item.queued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_message_id">
                                        { item.provider_message_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_message">
                                        { item.error_message }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.notification_messages_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Audit_logs 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>EntityKey</th>
                                
                                
                                
                                <th>BeforeData</th>
                                
                                
                                
                                <th>AfterData</th>
                                
                                
                                
                                <th>IPAddress</th>
                                
                                
                                
                                <th>UserAgent</th>
                                
                                
                                
                                <th>LoggedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.audit_logs_organizations && Array.isArray(organizations.audit_logs_organizations) &&
                              organizations.audit_logs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/audit_logs/audit_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="action">
                                        { item.action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_name">
                                        { item.entity_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_key">
                                        { item.entity_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="before_data">
                                        { item.before_data }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="after_data">
                                        { item.after_data }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ip_address">
                                        { item.ip_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="user_agent">
                                        { item.user_agent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="logged_at">
                                        { dataFormatter.dateTimeFormatter(item.logged_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.audit_logs_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;