Repository: GeorgeKalash/ArgusFE
Pull request #1106: AR-3022
Author: login: imtithalhalalo
Created: 2025-03-28T14:55:16Z | Merged: 2025-04-10T05:34:52Z

new screen prod-order


Diff:
diff --git a/src/pages/mf-prod-order/Forms/ProductionOrderForm.js b/src/pages/mf-prod-order/Forms/ProductionOrderForm.js
new file mode 100644
index 0000000000..1625c80727
--- /dev/null
+++ b/src/pages/mf-prod-order/Forms/ProductionOrderForm.js
@@ -0,0 +1,392 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = !obj.recordId ? platformLabels.Added : platformLabels.Edited
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    toast.success(platformLabels.Posted)
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
+
+  const columns = [
+    {
+      component: 'resourcelookup',
+      label: labels.sku,
+      name: 'sku',
+      props: {
+        endpointId: InventoryRepository.Item.snapshot,
+        valueField: 'sku',
+        displayField: 'sku',
+        mapping: [
+          { from: 'recordId', to: 'itemId' },
+          { from: 'sku', to: 'sku' },
+          { from: 'name', to: 'itemName' }
+        ],
+        columnsInDropDown: [
+          { key: 'sku', value: 'SKU' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 3
+      }
+    },
+    {
+      component: 'textfield',
+      label: labels.itemName,
+      name: 'itemName',
+      props: {
+        readOnly: true
+      }
+    },
+    {
+      component: 'numberfield',
+      name: 'qty',
+      label: labels.qty,
+      props: {
+        maxLength: 12,
+        decimalScale: 2
+      }
+    },
+    {
+      component: 'resourcecombobox',
+      label: labels.design,
+      name: 'designId',
+      props: {
+        readOnly: isPosted,
+        endpointId: ManufacturingRepository.Design.qry,
+        parameters: '_startAt=0&_pageSize=1000&_params=',
+        valueField: 'recordId',
+        displayField: 'reference',
+        mapping: [
+          { from: 'recordId', to: 'designId' },
+          { from: 'reference', to: 'designRef' },
+          { from: 'name', to: 'designName' }
+        ],
+        columnsInDropDown: [
+          { key: 'reference', value: 'Reference' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 2
+      }
+    }
+  ]
+  async function refetchForm(recordId) {
+    const res = await getRequest({
+      extension: ManufacturingRepository.ProductionOrder.get2,
+      parameters: `_recordId=${recordId}`
+    })
+
+    if (res.record.header) {
+      const modifiedList = res?.record?.items?.map((item, index) => ({
+        ...item,
+        id: index + 1
+      }))
+
+      formik.setValues({
+        ...res.record.header,
+        date: formatDateFromApi(res?.record?.header?.date),
+        rows: modifiedList
+      })
+
+      return res?.record
+    }
+  }
+
+  useEffect(() => {
+    if (recordId) refetchForm(recordId)
+  }, [])
+
+  const actions = [
+    {
+      key: 'RecordRemarks',
+      condition: true,
+      onClick: 'onRecordRemarks',
+      disabled: !editMode
+    },
+    {
+      key: 'Post',
+      condition: true,
+      onClick: onPost,
+      disabled: isPosted || !editMode
+    }
+  ]
+
+  return (
+    <FormShell
+      resourceId={ResourceIds.ProductionOrder}
+      form={formik}
+      maxAccess={maxAccess}
+      actions={actions}
+      editMode={editMode}
+      previewReport={editMode}
+      disabledSubmit={isPosted}
+    >
+      <VertLayout>
+        <Fixed>
+          <Grid container spacing={2}>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.DocumentType.qry}
+                    parameters={`_startAt=0&_pageSize=1000&_dgId=${SystemFunction.ProductionOrder}`}
+                    name='dtId'
+                    label={labels.documentType}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    readOnly={editMode}
+                    required
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    values={formik.values}
+                    maxAccess={maxAccess}
+                    onChange={async (event, newValue) => {
+                      formik.setFieldValue('dtId', newValue?.recordId || null)
+                      changeDT(newValue)
+                    }}
+                    error={formik.touched.dtId && Boolean(formik.errors.dtId)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomTextField
+                    name='reference'
+                    label={labels.reference}
+                    value={formik?.values?.reference}
+                    maxAccess={!editMode && maxAccess}
+                    maxLength='30'
+                    readOnly={isPosted}
+                    onChange={formik.handleChange}
+                    onClear={() => formik.setFieldValue('reference', '')}
+                    error={formik.touched.reference && Boolean(formik.errors.reference)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomDatePicker
+                    name='date'
+                    label={labels.date}
+                    readOnly={isPosted}
+                    value={formik?.values?.date}
+                    onChange={formik.setFieldValue}
+                    required
+                    maxAccess={maxAccess}
+                    onClear={() => formik.setFieldValue('date', null)}
+                    error={formik.touched.date && Boolean(formik.errors.date)}
+                  />
+                </Grid>
+              </Grid>
+            </Grid>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.Plant.qry}
+                    name='plantId'
+                    label={labels.plant}
+                    readOnly={isPosted}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    values={formik.values}
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    maxAccess={maxAccess}
+                    onChange={(event, newValue) => {
+                      formik.setFieldValue('plantId', newValue?.recordId)
+                    }}
+                    error={formik.touched.plantId && Boolean(formik.errors.plantId)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomTextArea
+                    name='notes'
+                    label={labels.description}
+                    value={formik?.values?.notes}
+                    rows={2.5}
+                    readOnly={isPosted}
+                    maxAccess={maxAccess}
+                    onChange={formik.handleChange}
+                    onClear={() => formik.setFieldValue('notes', '')}
+                    error={formik.touched.notes && Boolean(formik.errors.notes)}
+                  />
+                </Grid>
+              </Grid>
+            </Grid>
+          </Grid>
+        </Fixed>
+        <Grow>
+          <DataGrid
+            onChange={value => formik.setFieldValue('rows', value)}
+            value={formik.values.rows}
+            error={formik.errors.rows}
+            name='rows'
+            maxAccess={maxAccess}
+            columns={columns}
+            allowAddNewLine={!isPosted}
+            allowDelete={!isPosted}
+            disabled={isPosted}
+          />
+        </Grow>
+        <Fixed>
+          <Grid container xs={6}>
+            <CustomNumberField
+              name='totalQty'
+              label={labels.totalQty}
+              maxAccess={maxAccess}
+              value={totalQty}
+              maxLength='30'
+              readOnly
+              error={formik.touched.totalQty && Boolean(formik.errors.totalQty)}
+            />
+          </Grid>
+        </Fixed>
+      </VertLayout>
+    </FormShell>
+  )
+}
diff --git a/src/pages/mf-prod-order/index.js b/src/pages/mf-prod-order/index.js
new file mode 100644
index 0000000000..42b5ecfa5d
--- /dev/null
+++ b/src/pages/mf-prod-order/index.js
@@ -0,0 +1,150 @@
+import { useContext } from 'react'
+import { useResourceQuery } from 'src/hooks/resource'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import Table from 'src/components/Shared/Table'
+import toast from 'react-hot-toast'
+import { useWindow } from 'src/windows'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { ControlContext } from 'src/providers/ControlContext'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import RPBGridToolbar from 'src/components/Shared/RPBGridToolbar'
+import { useDocumentTypeProxy } from 'src/hooks/documentReferenceBehaviors'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import ProductionOrderForm from './Forms/ProductionOrderForm'
+
+const ProductionOrder = () => {
+  const { postRequest, getRequest } = useContext(RequestsContext)
+  const { platformLabels } = useContext(ControlContext)
+  const { stack } = useWindow()
+
+  const {
+    query: { data },
+    filterBy,
+    refetch,
+    labels,
+    access,
+    paginationParameters,
+    invalidate
+  } = useResourceQuery({
+    queryFn: fetchGridData,
+    endpointId: ManufacturingRepository.ProductionOrder.page,
+    datasetId: ResourceIds.ProductionOrder,
+    filter: {
+      filterFn: fetchWithFilter
+    }
+  })
+
+  const columns = [
+    {
+      field: 'reference',
+      headerName: labels.refernce,
+      flex: 1
+    },
+    {
+      field: 'date',
+      headerName: labels.date,
+      flex: 1,
+      type: 'date'
+    },
+    {
+      field: 'notes',
+      headerName: labels.description,
+      flex: 1
+    },
+    {
+      field: 'plantName',
+      headerName: labels.plant,
+      flex: 1
+    },
+    {
+      field: 'statusName',
+      headerName: labels.status,
+      flex: 1
+    }
+  ]
+
+  async function fetchGridData(options = {}) {
+    const { _startAt = 0, _pageSize = 50, params = [] } = options
+
+    const response = await getRequest({
+      extension: ManufacturingRepository.ProductionOrder.page,
+      parameters: `_startAt=${_startAt}&_pageSize=${_pageSize}&_params=${params}&_jobId=0&filter=`
+    })
+
+    return { ...response, _startAt: _startAt }
+  }
+
+  async function fetchWithFilter({ filters, pagination }) {
+    if (filters?.qry)
+      return await getRequest({
+        extension: ManufacturingRepository.ProductionOrder.snapshot,
+        parameters: `_filter=${filters.qry}`
+      })
+    else return fetchGridData({ _startAt: pagination._startAt || 0, params: filters?.params })
+  }
+
+  const { proxyAction } = useDocumentTypeProxy({
+    functionId: SystemFunction.ProductionOrder,
+    action: openForm
+  })
+
+  const add = async () => {
+    await proxyAction()
+  }
+
+  const edit = obj => {
+    openForm(obj.recordId)
+  }
+
+  async function openForm(recordId) {
+    stack({
+      Component: ProductionOrderForm,
+      props: {
+        labels,
+        access,
+        recordId
+      },
+      width: 850,
+      height: 680,
+      title: labels.ProductionOrder
+    })
+  }
+
+  const del = async obj => {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.del,
+      record: JSON.stringify(obj)
+    })
+    invalidate()
+    toast.success(platformLabels.Deleted)
+  }
+
+  return (
+    <VertLayout>
+      <Fixed>
+        <RPBGridToolbar onAdd={add} maxAccess={access} filterBy={filterBy} reportName={'MFPO'} />
+      </Fixed>
+      <Grow>
+        <Table
+          columns={columns}
+          gridData={data}
+          rowId={['recordId']}
+          onEdit={edit}
+          refetch={refetch}
+          onDelete={del}
+          deleteConfirmationType={'strict'}
+          isLoading={false}
+          pageSize={50}
+          maxAccess={access}
+          paginationParameters={paginationParameters}
+          paginationType='api'
+        />
+      </Grow>
+    </VertLayout>
+  )
+}
+
+export default ProductionOrder
diff --git a/src/repositories/ManufacturingRepository.js b/src/repositories/ManufacturingRepository.js
index a278d3a379..2c1cc9f100 100644
--- a/src/repositories/ManufacturingRepository.js
+++ b/src/repositories/ManufacturingRepository.js
@@ -234,6 +234,14 @@ export const ManufacturingRepository = {
     snapshot: service + 'snapshotDMR',
     post: service + 'postDMR'
   },
+  ProductionOrder: {
+    get2: service + 'get2PO',
+    set2: service + 'set2PO',
+    del: service + 'delPO',
+    page: service + 'pagePO',
+    snapshot: service + 'snapshotPO',
+    post: service + 'postPO'
+  },
   BillOfMaterials: {
     get: service + 'getBMA',
     set: service + 'setBMA',
diff --git a/src/resources/ResourceIds.js b/src/resources/ResourceIds.js
index fd4cd73946..37eb6f1f3b 100644
--- a/src/resources/ResourceIds.js
+++ b/src/resources/ResourceIds.js
@@ -391,6 +391,7 @@ export const ResourceIds = {
   SAVerifyTransIntegrity: 51601,
   PUDocumentTypeDefaults: 50103,
   SyncSalesTrx: 51603,
+  ProductionOrder: 42337,
   YearlyComparativeSales: 51550,
   SManagement: 41213,
 }


Reviews:
user: login: RebeccaFrem02
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T06:45:19Z
user: login: RebeccaFrem02
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T06:46:27Z
user: login: RebeccaFrem02
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-04T06:59:29Z
user: login: imtithalhalalo
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-04T07:45:48Z
user: login: omarZrayka23
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T13:35:58Z
user: login: imtithalhalalo
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-08T07:11:44Z
user: login: omarZrayka23
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T06:25:59Z
user: login: omarZrayka23
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T13:13:45Z
user: login: omarZrayka23
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-09T13:14:54Z

Review comments:
diff_hunk: @@ -0,0 +1,389 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = editMode ? platformLabels.Edited : platformLabels.Added
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: RebeccaFrem02
body: here use recordId instead of edit mode and insert it directli as a message, lo need for the const
created_at: 2025-04-04T06:45:19Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,389 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = editMode ? platformLabels.Edited : platformLabels.Added
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: RebeccaFrem02
body: is there a need for this useEffect?
created_at: 2025-04-04T06:46:26Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,389 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = editMode ? platformLabels.Edited : platformLabels.Added
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    window.close()
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: RebeccaFrem02
body: add toast
created_at: 2025-04-04T06:59:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,389 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = editMode ? platformLabels.Edited : platformLabels.Added
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: imtithalhalalo
body: yes to show the defaults from the document type 
created_at: 2025-04-04T07:45:48Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,390 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = !obj.recordId ? platformLabels.Added : platformLabels.Edited
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    toast.success(platformLabels.Posted)
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
+
+  const columns = [
+    {
+      component: 'resourcelookup',
+      label: labels.sku,
+      name: 'sku',
+      props: {
+        endpointId: InventoryRepository.Item.snapshot,
+        valueField: 'sku',
+        displayField: 'sku',
+        mapping: [
+          { from: 'recordId', to: 'itemId' },
+          { from: 'sku', to: 'sku' },
+          { from: 'name', to: 'itemName' }
+        ],
+        columnsInDropDown: [
+          { key: 'sku', value: 'SKU' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 3
+      }
+    },
+    {
+      component: 'textfield',
+      label: labels.itemName,
+      name: 'itemName',
+      props: {
+        readOnly: true
+      }
+    },
+    {
+      component: 'numberfield',
+      name: 'qty',
+      label: labels.qty,
+      props: {
+        maxLength: 12,
+        decimalScale: 2
+      }
+    },
+    {
+      component: 'resourcecombobox',
+      label: labels.design,
+      name: 'designId',
+      props: {
+        readOnly: isPosted,
+        endpointId: ManufacturingRepository.Design.qry,
+        parameters: '_startAt=0&_pageSize=1000&_params=',
+        valueField: 'recordId',
+        displayField: 'reference',
+        mapping: [
+          { from: 'recordId', to: 'designId' },
+          { from: 'reference', to: 'designRef' },
+          { from: 'name', to: 'designName' }
+        ],
+        columnsInDropDown: [
+          { key: 'reference', value: 'Reference' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 2
+      }
+    }
+  ]
+  async function refetchForm(recordId) {
+    const res = await getRequest({
+      extension: ManufacturingRepository.ProductionOrder.get2,
+      parameters: `_recordId=${recordId}`
+    })
+
+    const modifiedList = res?.record?.items?.map((item, index) => ({
+      ...item,
+      id: index + 1
+    }))
+
+    res.record.header.date = formatDateFromApi(res?.record?.header?.date)
+
+    formik.setValues({
+      ...res.record.header,
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: omarZrayka23
body: You can insert the date directly into setValues.
created_at: 2025-04-07T13:32:49Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,390 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = !obj.recordId ? platformLabels.Added : platformLabels.Edited
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    toast.success(platformLabels.Posted)
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
+
+  const columns = [
+    {
+      component: 'resourcelookup',
+      label: labels.sku,
+      name: 'sku',
+      props: {
+        endpointId: InventoryRepository.Item.snapshot,
+        valueField: 'sku',
+        displayField: 'sku',
+        mapping: [
+          { from: 'recordId', to: 'itemId' },
+          { from: 'sku', to: 'sku' },
+          { from: 'name', to: 'itemName' }
+        ],
+        columnsInDropDown: [
+          { key: 'sku', value: 'SKU' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 3
+      }
+    },
+    {
+      component: 'textfield',
+      label: labels.itemName,
+      name: 'itemName',
+      props: {
+        readOnly: true
+      }
+    },
+    {
+      component: 'numberfield',
+      name: 'qty',
+      label: labels.qty,
+      props: {
+        maxLength: 12,
+        decimalScale: 2
+      }
+    },
+    {
+      component: 'resourcecombobox',
+      label: labels.design,
+      name: 'designId',
+      props: {
+        readOnly: isPosted,
+        endpointId: ManufacturingRepository.Design.qry,
+        parameters: '_startAt=0&_pageSize=1000&_params=',
+        valueField: 'recordId',
+        displayField: 'reference',
+        mapping: [
+          { from: 'recordId', to: 'designId' },
+          { from: 'reference', to: 'designRef' },
+          { from: 'name', to: 'designName' }
+        ],
+        columnsInDropDown: [
+          { key: 'reference', value: 'Reference' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 2
+      }
+    }
+  ]
+  async function refetchForm(recordId) {
+    const res = await getRequest({
+      extension: ManufacturingRepository.ProductionOrder.get2,
+      parameters: `_recordId=${recordId}`
+    })
+
+    const modifiedList = res?.record?.items?.map((item, index) => ({
+      ...item,
+      id: index + 1
+    }))
+
+    res.record.header.date = formatDateFromApi(res?.record?.header?.date)
+
+    formik.setValues({
+      ...res.record.header,
+      rows: modifiedList
+    })
+
+    return res?.record
+  }
+
+  useEffect(() => {
+    if (recordId) refetchForm(recordId)
+  }, [])
+
+  const actions = [
+    {
+      key: 'RecordRemarks',
+      condition: true,
+      onClick: 'onRecordRemarks',
+      disabled: !editMode
+    },
+    {
+      key: 'Post',
+      condition: true,
+      onClick: onPost,
+      disabled: isPosted || !editMode
+    }
+  ]
+
+  return (
+    <FormShell
+      resourceId={ResourceIds.ProductionOrder}
+      form={formik}
+      maxAccess={maxAccess}
+      actions={actions}
+      editMode={editMode}
+      previewReport={editMode}
+      disabledSubmit={isPosted}
+    >
+      <VertLayout>
+        <Fixed>
+          <Grid container spacing={2}>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.DocumentType.qry}
+                    parameters={`_startAt=0&_pageSize=1000&_dgId=${SystemFunction.ProductionOrder}`}
+                    name='dtId'
+                    label={labels.documentType}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    readOnly={isPosted}
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    values={formik.values}
+                    maxAccess={!editMode && maxAccess}
+                    onChange={(event, newValue) => {
+                      formik.setFieldValue('dtId', newValue?.recordId)
+                      changeDT(newValue)
+                    }}
+                    error={formik.touched.dtId && Boolean(formik.errors.dtId)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomTextField
+                    name='reference'
+                    label={labels.reference}
+                    value={formik?.values?.reference}
+                    maxAccess={!editMode && maxAccess}
+                    maxLength='30'
+                    readOnly={isPosted}
+                    onChange={formik.handleChange}
+                    onClear={() => formik.setFieldValue('reference', '')}
+                    error={formik.touched.reference && Boolean(formik.errors.reference)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomDatePicker
+                    name='date'
+                    label={labels.date}
+                    readOnly={isPosted}
+                    value={formik?.values?.date}
+                    onChange={formik.setFieldValue}
+                    required
+                    maxAccess={maxAccess}
+                    onClear={() => formik.setFieldValue('date', null)}
+                    error={formik.touched.date && Boolean(formik.errors.date)}
+                  />
+                </Grid>
+              </Grid>
+            </Grid>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.Plant.qry}
+                    name='plantId'
+                    label={labels.plant}
+                    readOnly={isPosted}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    values={formik.values}
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    maxAccess={maxAccess}
+                    onChange={(event, newValue) => {
+                      formik.setFieldValue('plantId', newValue?.recordId)
+                    }}
+                    error={formik.touched.plantId && Boolean(formik.errors.plantId)}
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: omarZrayka23
body: we use errorCheck instead error
created_at: 2025-04-07T13:34:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,390 @@
+import CustomDatePicker from 'src/components/Inputs/CustomDatePicker'
+import { formatDateFromApi, formatDateToApi } from 'src/lib/date-helper'
+import { Grid } from '@mui/material'
+import { useContext, useEffect } from 'react'
+import * as yup from 'yup'
+import FormShell from 'src/components/Shared/FormShell'
+import toast from 'react-hot-toast'
+import { RequestsContext } from 'src/providers/RequestsContext'
+import { useInvalidate } from 'src/hooks/resource'
+import { ResourceIds } from 'src/resources/ResourceIds'
+import CustomTextField from 'src/components/Inputs/CustomTextField'
+import CustomTextArea from 'src/components/Inputs/CustomTextArea'
+import ResourceComboBox from 'src/components/Shared/ResourceComboBox'
+import { SystemRepository } from 'src/repositories/SystemRepository'
+import { InventoryRepository } from 'src/repositories/InventoryRepository'
+import { SystemFunction } from 'src/resources/SystemFunction'
+import { DataGrid } from 'src/components/Shared/DataGrid'
+import { VertLayout } from 'src/components/Shared/Layouts/VertLayout'
+import { Fixed } from 'src/components/Shared/Layouts/Fixed'
+import { Grow } from 'src/components/Shared/Layouts/Grow'
+import { useForm } from 'src/hooks/form'
+import { ControlContext } from 'src/providers/ControlContext'
+import { useDocumentType } from 'src/hooks/documentReferenceBehaviors'
+import { ManufacturingRepository } from 'src/repositories/ManufacturingRepository'
+import CustomNumberField from 'src/components/Inputs/CustomNumberField'
+
+export default function ProductionOrderForm({ labels, access, recordId, window }) {
+  const { getRequest, postRequest } = useContext(RequestsContext)
+  const { platformLabels, userDefaultsData } = useContext(ControlContext)
+
+  const { documentType, maxAccess, changeDT } = useDocumentType({
+    functionId: SystemFunction.ProductionOrder,
+    access,
+    enabled: !recordId
+  })
+
+  const plantId = parseInt(userDefaultsData?.list?.find(obj => obj.key === 'plantId')?.value)
+
+  const invalidate = useInvalidate({
+    endpointId: ManufacturingRepository.ProductionOrder.page
+  })
+
+  const { formik } = useForm({
+    maxAccess,
+    documentType: { key: 'dtId', value: documentType?.dtId },
+    initialValues: {
+      recordId,
+      dtId: null,
+      reference: '',
+      plantId,
+      notes: '',
+      date: new Date(),
+      status: 1,
+      rows: [
+        {
+          id: 1,
+          poId: recordId,
+          sku: '',
+          itemName: '',
+          qty: null,
+          pcs: null,
+          designId: null,
+          notes: '',
+          seqNo: ''
+        }
+      ]
+    },
+    validateOnChange: true,
+    validationSchema: yup.object({
+      date: yup.date().required(),
+      rows: yup
+        .array()
+        .of(
+          yup.object().shape({
+            sku: yup.string().required(),
+            qty: yup.number().required(),
+            itemName: yup.string().required()
+          })
+        )
+        .required()
+    }),
+    onSubmit: async obj => {
+      const { rows, date, ...rest } = obj
+
+      const header = {
+        ...rest,
+        date: formatDateToApi(date)
+      }
+
+      const updatedRows = formik.values.rows.map((prodDetails, index) => {
+        return {
+          ...prodDetails,
+          poId: recordId ?? 0,
+          seqNo: index + 1
+        }
+      })
+
+      const resultObject = {
+        header,
+        items: updatedRows
+      }
+
+      const res = await postRequest({
+        extension: ManufacturingRepository.ProductionOrder.set2,
+        record: JSON.stringify(resultObject)
+      })
+
+      const actionMessage = !obj.recordId ? platformLabels.Added : platformLabels.Edited
+      toast.success(actionMessage)
+      invalidate()
+      refetchForm(res?.recordId)
+    }
+  })
+
+  const editMode = !!formik.values.recordId
+  const isPosted = formik.values.status === 3
+
+  const totalQty = formik.values?.rows
+    ?.reduce((qtySum, row) => {
+      const qtyValue = parseFloat(row.qty) || 0
+
+      return qtySum + qtyValue
+    }, 0)
+    .toFixed(2)
+
+  async function onPost() {
+    await postRequest({
+      extension: ManufacturingRepository.ProductionOrder.post,
+      record: JSON.stringify({
+        ...formik.values,
+        date: formatDateToApi(formik.values.date)
+      })
+    })
+    toast.success(platformLabels.Posted)
+    window.close()
+    invalidate()
+  }
+
+  async function getDTD(dtId) {
+    if (dtId) {
+      const res = await getRequest({
+        extension: InventoryRepository.DocumentTypeDefaults.get,
+        parameters: `_dtId=${dtId}`
+      })
+
+      formik.setFieldValue('plantId', res?.record?.plantId ? res?.record?.plantId : plantId)
+
+      return res
+    }
+  }
+
+  useEffect(() => {
+    getDTD(formik?.values?.dtId)
+  }, [formik.values.dtId])
+
+  const columns = [
+    {
+      component: 'resourcelookup',
+      label: labels.sku,
+      name: 'sku',
+      props: {
+        endpointId: InventoryRepository.Item.snapshot,
+        valueField: 'sku',
+        displayField: 'sku',
+        mapping: [
+          { from: 'recordId', to: 'itemId' },
+          { from: 'sku', to: 'sku' },
+          { from: 'name', to: 'itemName' }
+        ],
+        columnsInDropDown: [
+          { key: 'sku', value: 'SKU' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 3
+      }
+    },
+    {
+      component: 'textfield',
+      label: labels.itemName,
+      name: 'itemName',
+      props: {
+        readOnly: true
+      }
+    },
+    {
+      component: 'numberfield',
+      name: 'qty',
+      label: labels.qty,
+      props: {
+        maxLength: 12,
+        decimalScale: 2
+      }
+    },
+    {
+      component: 'resourcecombobox',
+      label: labels.design,
+      name: 'designId',
+      props: {
+        readOnly: isPosted,
+        endpointId: ManufacturingRepository.Design.qry,
+        parameters: '_startAt=0&_pageSize=1000&_params=',
+        valueField: 'recordId',
+        displayField: 'reference',
+        mapping: [
+          { from: 'recordId', to: 'designId' },
+          { from: 'reference', to: 'designRef' },
+          { from: 'name', to: 'designName' }
+        ],
+        columnsInDropDown: [
+          { key: 'reference', value: 'Reference' },
+          { key: 'name', value: 'Name' }
+        ],
+        displayFieldWidth: 2
+      }
+    }
+  ]
+  async function refetchForm(recordId) {
+    const res = await getRequest({
+      extension: ManufacturingRepository.ProductionOrder.get2,
+      parameters: `_recordId=${recordId}`
+    })
+
+    const modifiedList = res?.record?.items?.map((item, index) => ({
+      ...item,
+      id: index + 1
+    }))
+
+    res.record.header.date = formatDateFromApi(res?.record?.header?.date)
+
+    formik.setValues({
+      ...res.record.header,
+      rows: modifiedList
+    })
+
+    return res?.record
+  }
+
+  useEffect(() => {
+    if (recordId) refetchForm(recordId)
+  }, [])
+
+  const actions = [
+    {
+      key: 'RecordRemarks',
+      condition: true,
+      onClick: 'onRecordRemarks',
+      disabled: !editMode
+    },
+    {
+      key: 'Post',
+      condition: true,
+      onClick: onPost,
+      disabled: isPosted || !editMode
+    }
+  ]
+
+  return (
+    <FormShell
+      resourceId={ResourceIds.ProductionOrder}
+      form={formik}
+      maxAccess={maxAccess}
+      actions={actions}
+      editMode={editMode}
+      previewReport={editMode}
+      disabledSubmit={isPosted}
+    >
+      <VertLayout>
+        <Fixed>
+          <Grid container spacing={2}>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.DocumentType.qry}
+                    parameters={`_startAt=0&_pageSize=1000&_dgId=${SystemFunction.ProductionOrder}`}
+                    name='dtId'
+                    label={labels.documentType}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    readOnly={isPosted}
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    values={formik.values}
+                    maxAccess={!editMode && maxAccess}
+                    onChange={(event, newValue) => {
+                      formik.setFieldValue('dtId', newValue?.recordId)
+                      changeDT(newValue)
+                    }}
+                    error={formik.touched.dtId && Boolean(formik.errors.dtId)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomTextField
+                    name='reference'
+                    label={labels.reference}
+                    value={formik?.values?.reference}
+                    maxAccess={!editMode && maxAccess}
+                    maxLength='30'
+                    readOnly={isPosted}
+                    onChange={formik.handleChange}
+                    onClear={() => formik.setFieldValue('reference', '')}
+                    error={formik.touched.reference && Boolean(formik.errors.reference)}
+                  />
+                </Grid>
+                <Grid item xs={12}>
+                  <CustomDatePicker
+                    name='date'
+                    label={labels.date}
+                    readOnly={isPosted}
+                    value={formik?.values?.date}
+                    onChange={formik.setFieldValue}
+                    required
+                    maxAccess={maxAccess}
+                    onClear={() => formik.setFieldValue('date', null)}
+                    error={formik.touched.date && Boolean(formik.errors.date)}
+                  />
+                </Grid>
+              </Grid>
+            </Grid>
+            <Grid item xs={6}>
+              <Grid container spacing={2}>
+                <Grid item xs={12}>
+                  <ResourceComboBox
+                    endpointId={SystemRepository.Plant.qry}
+                    name='plantId'
+                    label={labels.plant}
+                    readOnly={isPosted}
+                    columnsInDropDown={[
+                      { key: 'reference', value: 'Reference' },
+                      { key: 'name', value: 'Name' }
+                    ]}
+                    values={formik.values}
+                    valueField='recordId'
+                    displayField={['reference', 'name']}
+                    maxAccess={maxAccess}
+                    onChange={(event, newValue) => {
+                      formik.setFieldValue('plantId', newValue?.recordId)
+                    }}
+                    error={formik.touched.plantId && Boolean(formik.errors.plantId)}
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: imtithalhalalo
body: this is combobox and not lookup we are using error
created_at: 2025-04-08T07:11:44Z
author_association: COLLABORATOR
diff_hunk: @@ -108,7 +108,7 @@ export default function ProductionOrderForm({ labels, access, recordId, window }
       const actionMessage = !obj.recordId ? platformLabels.Added : platformLabels.Edited
       toast.success(actionMessage)
       invalidate()
-      refetchForm(res?.recordId)
+      await refetchForm(res?.recordId)
path: src/pages/mf-prod-order/Forms/ProductionOrderForm.js
user: login: omarZrayka23
body: Why use await here?
created_at: 2025-04-09T06:25:23Z
author_association: CONTRIBUTOR

PR comments:
user: login: vercel[bot]
created_at: 2025-03-28T14:55:21Z
body: [vc]: #Kj+yqTIF3SKfkUl07GhlWcnEFtT/P5EVbwev+i1X7Do=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJhcmd1cy1mZSIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9nZW9yZ2Uta2FsYXNocy1wcm9qZWN0cy9hcmd1cy1mZS9EWmFSdmVkVGFzNHFTckY4c3BDb0Y3ZDE0RWc5IiwicHJldmlld1VybCI6ImFyZ3VzLWZlLWdpdC1hci0zMDIyLWdlb3JnZS1rYWxhc2hzLXByb2plY3RzLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoiYXJndXMtZmUtZ2l0LWFyLTMwMjItZ2VvcmdlLWthbGFzaHMtcHJvamVjdHMudmVyY2VsLmFwcCJ9LCJyb290RGlyZWN0b3J5IjpudWxsfV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **argus-fe** | ✅ Ready ([Inspect](https://vercel.com/george-kalashs-projects/argus-fe/DZaRvedTas4qSrF8spCoF7d14Eg9)) | [Visit Preview](https://argus-fe-git-ar-3022-george-kalashs-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/argus-fe-git-ar-3022-george-kalashs-projects.vercel.app?via=pr-comment-feedback-link) | Apr 9, 2025 8:07am |


author_association: NONE
user: login: omarZrayka23
created_at: 2025-04-07T13:38:24Z
body: ![Screenshot 2025-04-07 at 4 38 01 PM](https://github.com/user-attachments/assets/f1501e2f-ea6e-4d20-bc17-59d4531289eb)


try to submit
author_association: CONTRIBUTOR
user: login: omarZrayka23
created_at: 2025-04-07T13:42:45Z
body: ![Screenshot 2025-04-07 at 4 39 58 PM](https://github.com/user-attachments/assets/0739d925-0d68-4b3a-aa7e-04cf7a43c578)

I cleared documentType +  clicked submit => the color border did not change.
author_association: CONTRIBUTOR
user: login: omarZrayka23
created_at: 2025-04-07T13:49:08Z
body: when i selected documenettype , the star to the right of the label is hidden.
author_association: CONTRIBUTOR
user: login: omarZrayka23
created_at: 2025-04-07T13:53:35Z
body: ![Screenshot 2025-04-07 at 4 53 06 PM](https://github.com/user-attachments/assets/dd67fdce-b8d2-4f0c-a266-7559348010a0)


try to delete a row
author_association: CONTRIBUTOR
user: login: omarZrayka23
created_at: 2025-04-07T13:58:43Z
body: ![Screenshot 2025-04-07 at 4 57 57 PM](https://github.com/user-attachments/assets/1e13de98-f221-419a-95ef-32e03f6cdd65)


open window in editMode
author_association: CONTRIBUTOR