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

const initialValues = {
    
    
    receipt_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    branch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    register: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shift: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cashier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    sale_type: 'cash',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'completed',
    
    
    
    
    
    
    
    
    
    
    
    
    sold_at: '',
    
    
    
    
    
    
    
    
    
    
    subtotal: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amount_paid: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    change_due: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_approved_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    voided_by: '',
    
    
    
    
    
    void_reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/sales/sales-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="ReceiptNumber"
  >
      <Field
          name="receipt_number"
          placeholder="ReceiptNumber"
      />
  </FormField>













































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



























  <FormField label="Register" labelFor="register">
      <Field name="register" id="register" component={SelectField} options={[]} itemRef={'pos_registers'}></Field>
  </FormField>



























  <FormField label="Shift" labelFor="shift">
      <Field name="shift" id="shift" component={SelectField} options={[]} itemRef={'pos_shifts'}></Field>
  </FormField>



























  <FormField label="Cashier" labelFor="cashier">
      <Field name="cashier" id="cashier" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























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























  <FormField label="SaleType" labelFor="sale_type">
      <Field name="sale_type" id="sale_type" component="select">
      
        <option value="cash">cash</option>
      
        <option value="card">card</option>
      
        <option value="mobile_money">mobile_money</option>
      
        <option value="credit">credit</option>
      
        <option value="split">split</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="completed">completed</option>
      
        <option value="voided">voided</option>
      
        <option value="refunded">refunded</option>
      
        <option value="parked">parked</option>
      
      </Field>
  </FormField>























  <FormField
      label="SoldAt"
  >
      <Field
          type="datetime-local"
          name="sold_at"
          placeholder="SoldAt"
      />
  </FormField>























    <FormField
        label="Subtotal"
    >
        <Field
            type="number"
            name="subtotal"
            placeholder="Subtotal"
        />
    </FormField>



























    <FormField
        label="DiscountTotal"
    >
        <Field
            type="number"
            name="discount_total"
            placeholder="DiscountTotal"
        />
    </FormField>



























    <FormField
        label="TaxTotal"
    >
        <Field
            type="number"
            name="tax_total"
            placeholder="TaxTotal"
        />
    </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="ChangeDue"
    >
        <Field
            type="number"
            name="change_due"
            placeholder="ChangeDue"
        />
    </FormField>







































  <FormField label="DiscountApprovedBy" labelFor="discount_approved_by">
      <Field name="discount_approved_by" id="discount_approved_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























  <FormField label="VoidedBy" labelFor="voided_by">
      <Field name="voided_by" id="voided_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>











    <FormField label="VoidReason" hasTextareaHeight>
        <Field name="void_reason" as="textarea" placeholder="VoidReason" />
    </FormField>











































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

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

export default SalesNew
