mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
increment & decrement adjustment.
This commit is contained in:
@@ -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() {
|
||||
<InputGroup
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue('new_quantity', calculate(values, field.value));
|
||||
setFieldValue('new_quantity', decrementCalc(values, event));
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
@@ -62,13 +61,9 @@ function DecrementAdjustmentFields() {
|
||||
helperText={<ErrorMessage name="new_quantity" />}
|
||||
>
|
||||
<InputGroup
|
||||
medium={'true'}
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue(
|
||||
'quantity',
|
||||
subtract(field.value, values.quantity_on_hand),
|
||||
);
|
||||
setFieldValue('quantity', decrementCalc(values, event));
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
@@ -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}
|
||||
>
|
||||
<InputGroup
|
||||
medium={'true'}
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue(
|
||||
'new_quantity',
|
||||
calculate(values, event.currentTarget.value),
|
||||
);
|
||||
setFieldValue('new_quantity', incrementCalc(values, event));
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
@@ -80,13 +75,9 @@ function IncrementAdjustmentFields() {
|
||||
helperText={<ErrorMessage name="new_quantity" />}
|
||||
>
|
||||
<InputGroup
|
||||
medium={'true'}
|
||||
{...field}
|
||||
onBlur={(event) => {
|
||||
setFieldValue(
|
||||
'quantity',
|
||||
subtract(field.value, values.quantity_on_hand),
|
||||
);
|
||||
setFieldValue('quantity', decrementCalc(values, event));
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
@@ -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 (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ 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}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user