mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
increment & decrement adjustment.
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import React from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { sumBy, subtract, add } from 'lodash';
|
|
||||||
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core';
|
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core';
|
||||||
import { inputIntent } from 'utils';
|
import { inputIntent } from 'utils';
|
||||||
import { Row, Col, If, FieldRequiredHint } from 'components';
|
import { Row, Col, If, FieldRequiredHint } from 'components';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { calculate } from './utils';
|
import { decrementCalc, dec } from './utils';
|
||||||
|
|
||||||
function DecrementAdjustmentFields() {
|
function DecrementAdjustmentFields() {
|
||||||
return (
|
return (
|
||||||
@@ -41,7 +40,7 @@ function DecrementAdjustmentFields() {
|
|||||||
<InputGroup
|
<InputGroup
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
setFieldValue('new_quantity', calculate(values, field.value));
|
setFieldValue('new_quantity', decrementCalc(values, event));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -62,13 +61,9 @@ function DecrementAdjustmentFields() {
|
|||||||
helperText={<ErrorMessage name="new_quantity" />}
|
helperText={<ErrorMessage name="new_quantity" />}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
medium={'true'}
|
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
setFieldValue(
|
setFieldValue('quantity', decrementCalc(values, event));
|
||||||
'quantity',
|
|
||||||
subtract(field.value, values.quantity_on_hand),
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { add, sumBy, subtract } from 'lodash';
|
|
||||||
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core';
|
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core';
|
||||||
import { Row, Col, FieldRequiredHint } from 'components';
|
import { Row, Col, FieldRequiredHint } from 'components';
|
||||||
import { inputIntent } from 'utils';
|
import { inputIntent } from 'utils';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { calculate } from './utils';
|
import { decrementCalc, incrementCalc } from './utils';
|
||||||
|
|
||||||
function IncrementAdjustmentFields() {
|
function IncrementAdjustmentFields() {
|
||||||
return (
|
return (
|
||||||
@@ -39,13 +38,9 @@ function IncrementAdjustmentFields() {
|
|||||||
fill={true}
|
fill={true}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
medium={'true'}
|
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
setFieldValue(
|
setFieldValue('new_quantity', incrementCalc(values, event));
|
||||||
'new_quantity',
|
|
||||||
calculate(values, event.currentTarget.value),
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
@@ -80,13 +75,9 @@ function IncrementAdjustmentFields() {
|
|||||||
helperText={<ErrorMessage name="new_quantity" />}
|
helperText={<ErrorMessage name="new_quantity" />}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
medium={'true'}
|
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
setFieldValue(
|
setFieldValue('quantity', decrementCalc(values, event));
|
||||||
'quantity',
|
|
||||||
subtract(field.value, values.quantity_on_hand),
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { ListSelect, Choose, FieldRequiredHint } from 'components';
|
import { ListSelect, Choose, If, FieldRequiredHint } from 'components';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
@@ -24,6 +24,7 @@ import DecrementAdjustmentFields from './DecrementAdjustmentFields';
|
|||||||
import AccountsSuggestField from 'components/AccountsSuggestField';
|
import AccountsSuggestField from 'components/AccountsSuggestField';
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
import { compose } from 'redux';
|
import { compose } from 'redux';
|
||||||
|
import { decrementCalc, incrementCalc, dec } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inventory adjustment form dialogs fields.
|
* Inventory adjustment form dialogs fields.
|
||||||
@@ -34,7 +35,7 @@ function InventoryAdjustmentFormDialogFields({
|
|||||||
}) {
|
}) {
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
// console.log(values, 'EE');
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -77,6 +78,12 @@ function InventoryAdjustmentFormDialogFields({
|
|||||||
items={adjustmentType}
|
items={adjustmentType}
|
||||||
onItemSelect={(type) => {
|
onItemSelect={(type) => {
|
||||||
form.setFieldValue('type', type.value);
|
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}
|
filterable={false}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
import { add, sumBy, subtract } from 'lodash';
|
export const decrementCalc = ({ quantity_on_hand, type }, e) => {
|
||||||
|
|
||||||
export const calculate = ({ type, quantity_on_hand }, operator) => {
|
|
||||||
const qty = parseInt(quantity_on_hand);
|
|
||||||
const quantity = parseInt(operator);
|
|
||||||
|
|
||||||
if (type == 'decrement') {
|
if (type == 'decrement') {
|
||||||
return subtract(qty, quantity);
|
return parseInt(quantity_on_hand, 10) - parseInt(e.currentTarget.value, 10);
|
||||||
} else {
|
} else {
|
||||||
return add(qty, quantity);
|
return e.currentTarget.value - quantity_on_hand;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// function calculate(qty, operator) {
|
export const incrementCalc = ({ quantity_on_hand, quantity }, e) => {
|
||||||
// return operator > 0
|
return parseInt(quantity_on_hand, 10) + parseInt(quantity, 10);
|
||||||
// ? calculate(qty + 1, operator - 1)
|
};
|
||||||
// : operator < 0
|
|
||||||
// ? calculate(qty - 1, operator + 1)
|
|
||||||
// : qty;
|
|
||||||
// }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user