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/invoices/invoicesSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    quote: '',
    
    
    
    
    invoice_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    invoice_type: 'standard',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    issue_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_date: '',
    
    
    
    
    
    
    
    
    
    
    currency_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exchange_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    subtotal_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amount_paid: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    balance_due: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    terms_and_conditions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    invoice_lines: [],
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/invoices/invoices-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="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>



























  <FormField label="Customer" labelFor="customer">
      <Field name="customer" id="customer" component={SelectField} options={[]} itemRef={'contacts'}></Field>
  </FormField>



























  <FormField label="SourceQuote" labelFor="quote">
      <Field name="quote" id="quote" component={SelectField} options={[]} itemRef={'quotes'}></Field>
  </FormField>









  <FormField
      label="InvoiceNumber"
  >
      <Field
          name="invoice_number"
          placeholder="InvoiceNumber"
      />
  </FormField>









































  <FormField label="InvoiceType" labelFor="invoice_type">
      <Field name="invoice_type" id="invoice_type" component="select">
      
        <option value="standard">standard</option>
      
        <option value="credit_note">credit_note</option>
      
        <option value="debit_note">debit_note</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="sent">sent</option>
      
        <option value="partially_paid">partially_paid</option>
      
        <option value="paid">paid</option>
      
        <option value="overdue">overdue</option>
      
        <option value="void">void</option>
      
      </Field>
  </FormField>























  <FormField
      label="IssueDate"
  >
      <Field
          type="datetime-local"
          name="issue_date"
          placeholder="IssueDate"
      />
  </FormField>



























  <FormField
      label="DueDate"
  >
      <Field
          type="datetime-local"
          name="due_date"
          placeholder="DueDate"
      />
  </FormField>

















  <FormField
      label="CurrencyCode"
  >
      <Field
          name="currency_code"
          placeholder="CurrencyCode"
      />
  </FormField>

































    <FormField
        label="ExchangeRate"
    >
        <Field
            type="number"
            name="exchange_rate"
            placeholder="ExchangeRate"
        />
    </FormField>



























    <FormField
        label="SubtotalAmount"
    >
        <Field
            type="number"
            name="subtotal_amount"
            placeholder="SubtotalAmount"
        />
    </FormField>



























    <FormField
        label="TaxAmount"
    >
        <Field
            type="number"
            name="tax_amount"
            placeholder="TaxAmount"
        />
    </FormField>



























    <FormField
        label="DiscountAmount"
    >
        <Field
            type="number"
            name="discount_amount"
            placeholder="DiscountAmount"
        />
    </FormField>



























    <FormField
        label="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>



























    <FormField
        label="AmountPaid"
    >
        <Field
            type="number"
            name="amount_paid"
            placeholder="AmountPaid"
        />
    </FormField>



























    <FormField
        label="BalanceDue"
    >
        <Field
            type="number"
            name="balance_due"
            placeholder="BalanceDue"
        />
    </FormField>

























      <FormField label='CustomerNotes' hasTextareaHeight>
          <Field
              name='customer_notes'
              id='customer_notes'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='TermsandConditions' hasTextareaHeight>
          <Field
              name='terms_and_conditions'
              id='terms_and_conditions'
              component={RichTextField}
          ></Field>
      </FormField>














































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
























    <FormField label='InvoiceLines' labelFor='invoice_lines'>
        <Field
            name='invoice_lines'
            id='invoice_lines'
            itemRef={'invoice_lines'}
            options={[]}
            component={SelectFieldMany}>
        </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('/invoices/invoices-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default InvoicesNew
