mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: adjustments.
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import React from 'react';
|
||||
import { FastField, ErrorMessage } from 'formik';
|
||||
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';
|
||||
|
||||
function IncrementAdjustmentFields() {
|
||||
return (
|
||||
<Row>
|
||||
{/*------------ Quantity on hand -----------*/}
|
||||
<Col sm={3}>
|
||||
<FastField name={'quantity'}>
|
||||
<FastField name={'quantity_on_hand'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'qty_on_hand'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="quantity" />}
|
||||
helperText={<ErrorMessage name="quantity_on_hand" />}
|
||||
>
|
||||
<InputGroup disabled={true} medium={'true'} {...field} />
|
||||
</FormGroup>
|
||||
@@ -24,15 +26,28 @@ function IncrementAdjustmentFields() {
|
||||
</Col>
|
||||
{/*------------ Increment -----------*/}
|
||||
<Col sm={2}>
|
||||
<FastField name={'increment'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FastField name={'quantity'}>
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field,
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={<T id={'increment'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="increment" />}
|
||||
helperText={<ErrorMessage name="quantity" />}
|
||||
fill={true}
|
||||
>
|
||||
<InputGroup medium={'true'} {...field} />
|
||||
<InputGroup
|
||||
medium={'true'}
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue(
|
||||
'new_quantity',
|
||||
calculate(values, event.currentTarget.value),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
@@ -54,13 +69,26 @@ function IncrementAdjustmentFields() {
|
||||
{/*------------ New quantity -----------*/}
|
||||
<Col sm={4}>
|
||||
<FastField name={'new_quantity'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field,
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={<T id={'new_quantity'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="new_quantity" />}
|
||||
>
|
||||
<InputGroup medium={'true'} {...field} />
|
||||
<InputGroup
|
||||
medium={'true'}
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue(
|
||||
'quantity',
|
||||
subtract(field.value, values.quantity_on_hand),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
Reference in New Issue
Block a user