import { mdiAccount, mdiChartTimelineVariant, mdiMail, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement } from 'react'
import CardBox from '../../components/CardBox'
import LayoutAuthenticated from '../../layouts/Authenticated'
import SectionMain from '../../components/SectionMain'
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
import { getPageTitle } from '../../config'

import { Field, Form, Formik } from 'formik'
import FormField from '../../components/FormField'
import BaseDivider from '../../components/BaseDivider'
import BaseButtons from '../../components/BaseButtons'
import BaseButton from '../../components/BaseButton'
import FormCheckRadio from '../../components/FormCheckRadio'
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup'
import FormFilePicker from '../../components/FormFilePicker'
import FormImagePicker from '../../components/FormImagePicker'
import { SwitchField } from '../../components/SwitchField'

import { SelectField } from '../../components/SelectField'
import { SelectFieldMany } from "../../components/SelectFieldMany";
import {RichTextField} from "../../components/RichTextField";

import { create } from '../../stores/journal_vouchers/journal_vouchersSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    business: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fiscal_year: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    branch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    voucher_type: '',
    
    
    
    
    voucher_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    voucher_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'note',
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_debit: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_credit: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_balanced: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


const Journal_vouchersNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/journal_vouchers/journal_vouchers-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Business" labelFor="business">
      <Field name="business" id="business" component={SelectField} options={[]} itemRef={'businesses'}></Field>
  </FormField>



























  <FormField label="FiscalYear" labelFor="fiscal_year">
      <Field name="fiscal_year" id="fiscal_year" component={SelectField} options={[]} itemRef={'fiscal_years'}></Field>
  </FormField>



























  <FormField label="Branch" labelFor="branch">
      <Field name="branch" id="branch" component={SelectField} options={[]} itemRef={'branches'}></Field>
  </FormField>



























  <FormField label="VoucherType" labelFor="voucher_type">
      <Field name="voucher_type" id="voucher_type" component={SelectField} options={[]} itemRef={'journal_voucher_types'}></Field>
  </FormField>









  <FormField
      label="VoucherNumber"
  >
      <Field
          name="voucher_number"
          placeholder="VoucherNumber"
      />
  </FormField>





































  <FormField
      label="VoucherDate"
  >
      <Field
          type="datetime-local"
          name="voucher_date"
          placeholder="VoucherDate"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="note">note</option>
      
        <option value="temporary">temporary</option>
      
        <option value="in_review">in_review</option>
      
        <option value="approved">approved</option>
      
        <option value="posted">posted</option>
      
        <option value="rejected">rejected</option>
      
      </Field>
  </FormField>















    <FormField label="Description" hasTextareaHeight>
        <Field name="description" as="textarea" placeholder="Description" />
    </FormField>































    <FormField
        label="TotalDebit"
    >
        <Field
            type="number"
            name="total_debit"
            placeholder="TotalDebit"
        />
    </FormField>



























    <FormField
        label="TotalCredit"
    >
        <Field
            type="number"
            name="total_credit"
            placeholder="TotalCredit"
        />
    </FormField>





































  <FormField label='IsBalanced' labelFor='is_balanced'>
      <Field
          name='is_balanced'
          id='is_balanced'
          component={SwitchField}
      ></Field>
  </FormField>


































  <FormField>
      <Field
          label='Attachments'
          color='info'
          icon={mdiUpload}
          path={'journal_vouchers/attachments'}
          name='attachments'
          id='attachments'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>


              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/journal_vouchers/journal_vouchers-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Journal_vouchersNew
