diff --git a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/DecrementAdjustmentFields.js b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/DecrementAdjustmentFields.js index 56564d374..4e1820f83 100644 --- a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/DecrementAdjustmentFields.js +++ b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/DecrementAdjustmentFields.js @@ -1,11 +1,10 @@ -import React from 'react'; -import { sumBy, subtract, add } from 'lodash'; +import React, { useRef } from 'react'; import { FastField, ErrorMessage, useFormikContext } from 'formik'; import { FormGroup, InputGroup, Intent } from '@blueprintjs/core'; import { inputIntent } from 'utils'; import { Row, Col, If, FieldRequiredHint } from 'components'; import { FormattedMessage as T } from 'react-intl'; -import { calculate } from './utils'; +import { decrementCalc, dec } from './utils'; function DecrementAdjustmentFields() { return ( @@ -41,7 +40,7 @@ function DecrementAdjustmentFields() { { - setFieldValue('new_quantity', calculate(values, field.value)); + setFieldValue('new_quantity', decrementCalc(values, event)); }} /> @@ -62,13 +61,9 @@ function DecrementAdjustmentFields() { helperText={} > { - setFieldValue( - 'quantity', - subtract(field.value, values.quantity_on_hand), - ); + setFieldValue('quantity', decrementCalc(values, event)); }} /> diff --git a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/IncrementAdjustmentFields.js b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/IncrementAdjustmentFields.js index 558a58a9f..286bea519 100644 --- a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/IncrementAdjustmentFields.js +++ b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/IncrementAdjustmentFields.js @@ -1,11 +1,10 @@ import React from 'react'; import { FastField, ErrorMessage, useFormikContext } from 'formik'; -import { add, sumBy, subtract } from 'lodash'; import { FormGroup, InputGroup, Intent } from '@blueprintjs/core'; import { Row, Col, FieldRequiredHint } from 'components'; import { inputIntent } from 'utils'; import { FormattedMessage as T } from 'react-intl'; -import { calculate } from './utils'; +import { decrementCalc, incrementCalc } from './utils'; function IncrementAdjustmentFields() { return ( @@ -39,13 +38,9 @@ function IncrementAdjustmentFields() { fill={true} > { - setFieldValue( - 'new_quantity', - calculate(values, event.currentTarget.value), - ); + setFieldValue('new_quantity', incrementCalc(values, event)); }} /> @@ -80,13 +75,9 @@ function IncrementAdjustmentFields() { helperText={} > { - setFieldValue( - 'quantity', - subtract(field.value, values.quantity_on_hand), - ); + setFieldValue('quantity', decrementCalc(values, event)); }} /> diff --git a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.js b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.js index a6dd528e6..c950dc918 100644 --- a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.js +++ b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/InventoryAdjustmentFormDialogFields.js @@ -10,7 +10,7 @@ import { import classNames from 'classnames'; import { FormattedMessage as T, useIntl } from 'react-intl'; import { DateInput } from '@blueprintjs/datetime'; -import { ListSelect, Choose, FieldRequiredHint } from 'components'; +import { ListSelect, Choose, If, FieldRequiredHint } from 'components'; import { inputIntent, momentFormatter, @@ -24,6 +24,7 @@ import DecrementAdjustmentFields from './DecrementAdjustmentFields'; import AccountsSuggestField from 'components/AccountsSuggestField'; import withAccounts from 'containers/Accounts/withAccounts'; import { compose } from 'redux'; +import { decrementCalc, incrementCalc, dec } from './utils'; /** * Inventory adjustment form dialogs fields. @@ -34,7 +35,7 @@ function InventoryAdjustmentFormDialogFields({ }) { const { values } = useFormikContext(); const { formatMessage } = useIntl(); - // console.log(values, 'EE'); + return (
{/*------------ Date -----------*/} @@ -77,6 +78,12 @@ function InventoryAdjustmentFormDialogFields({ items={adjustmentType} onItemSelect={(type) => { form.setFieldValue('type', type.value); + type?.value == 'increment' + ? form.setFieldValue('new_quantity', incrementCalc(values)) + : form.setFieldValue( + 'new_quantity', + values.quantity_on_hand - values.quantity, + ); }} filterable={false} selectedItem={value} diff --git a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.js b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.js index 0394d80d4..5585d3707 100644 --- a/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.js +++ b/client/src/containers/Dialogs/InventoryAdjustmentFormDialog/utils.js @@ -1,20 +1,11 @@ -import { add, sumBy, subtract } from 'lodash'; - -export const calculate = ({ type, quantity_on_hand }, operator) => { - const qty = parseInt(quantity_on_hand); - const quantity = parseInt(operator); - +export const decrementCalc = ({ quantity_on_hand, type }, e) => { if (type == 'decrement') { - return subtract(qty, quantity); + return parseInt(quantity_on_hand, 10) - parseInt(e.currentTarget.value, 10); } else { - return add(qty, quantity); + return e.currentTarget.value - quantity_on_hand; } }; -// function calculate(qty, operator) { -// return operator > 0 -// ? calculate(qty + 1, operator - 1) -// : operator < 0 -// ? calculate(qty - 1, operator + 1) -// : qty; -// } +export const incrementCalc = ({ quantity_on_hand, quantity }, e) => { + return parseInt(quantity_on_hand, 10) + parseInt(quantity, 10); +};