mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat(inventoryadjustment): add branch & warehouse.
This commit is contained in:
@@ -27,6 +27,8 @@ const defaultInitialValues = {
|
|||||||
reference_no: '',
|
reference_no: '',
|
||||||
quantity_on_hand: '',
|
quantity_on_hand: '',
|
||||||
publish: '',
|
publish: '',
|
||||||
|
branch_id: '',
|
||||||
|
warehouse_id: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,13 +38,8 @@ function InventoryAdjustmentForm({
|
|||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
closeDialog,
|
closeDialog,
|
||||||
}) {
|
}) {
|
||||||
const {
|
const { dialogName, item, itemId, submitPayload, createInventoryAdjMutate } =
|
||||||
dialogName,
|
useInventoryAdjContext();
|
||||||
item,
|
|
||||||
itemId,
|
|
||||||
submitPayload,
|
|
||||||
createInventoryAdjMutate,
|
|
||||||
} = useInventoryAdjContext();
|
|
||||||
|
|
||||||
// Initial form values.
|
// Initial form values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
@@ -63,7 +60,9 @@ function InventoryAdjustmentForm({
|
|||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get('the_adjustment_transaction_has_been_created_successfully'),
|
message: intl.get(
|
||||||
|
'the_adjustment_transaction_has_been_created_successfully',
|
||||||
|
),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const Schema = Yup.object().shape({
|
|||||||
reference_no: Yup.string(),
|
reference_no: Yup.string(),
|
||||||
new_quantity: Yup.number().required(),
|
new_quantity: Yup.number().required(),
|
||||||
publish: Yup.boolean(),
|
publish: Yup.boolean(),
|
||||||
|
branch_id: Yup.string(),
|
||||||
|
warehouse_id: Yup.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const CreateInventoryAdjustmentFormSchema = Schema;
|
export const CreateInventoryAdjustmentFormSchema = Schema;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
import { FastField, ErrorMessage, Field } from 'formik';
|
import { FastField, ErrorMessage, Field } from 'formik';
|
||||||
import {
|
import {
|
||||||
Classes,
|
Classes,
|
||||||
@@ -12,7 +13,17 @@ import { FormattedMessage as T } from 'components';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from 'hooks';
|
import { useAutofocus } from 'hooks';
|
||||||
import { ListSelect, FieldRequiredHint, Col, Row } from 'components';
|
import {
|
||||||
|
ListSelect,
|
||||||
|
FieldRequiredHint,
|
||||||
|
Col,
|
||||||
|
Row,
|
||||||
|
FeatureCan,
|
||||||
|
BranchSelect,
|
||||||
|
WarehouseSelect,
|
||||||
|
BranchSelectButton,
|
||||||
|
WarehouseSelectButton,
|
||||||
|
} from 'components';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
@@ -21,26 +32,76 @@ import {
|
|||||||
toSafeNumber,
|
toSafeNumber,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
import { Features } from 'common';
|
||||||
import adjustmentType from 'common/adjustmentType';
|
import adjustmentType from 'common/adjustmentType';
|
||||||
|
|
||||||
import AccountsSuggestField from 'components/AccountsSuggestField';
|
import AccountsSuggestField from 'components/AccountsSuggestField';
|
||||||
import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider';
|
import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider';
|
||||||
import { diffQuantity } from './utils';
|
import {
|
||||||
|
diffQuantity,
|
||||||
|
useSetPrimaryBranchToForm,
|
||||||
|
useSetPrimaryWarehouseToForm,
|
||||||
|
} from './utils';
|
||||||
|
import { useFeatureCan } from 'hooks/state';
|
||||||
import InventoryAdjustmentQuantityFields from './InventoryAdjustmentQuantityFields';
|
import InventoryAdjustmentQuantityFields from './InventoryAdjustmentQuantityFields';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inventory adjustment form dialogs fields.
|
* Inventory adjustment form dialogs fields.
|
||||||
*/
|
*/
|
||||||
export default function InventoryAdjustmentFormDialogFields() {
|
export default function InventoryAdjustmentFormDialogFields() {
|
||||||
|
// Features guard.
|
||||||
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
const dateFieldRef = useAutofocus();
|
const dateFieldRef = useAutofocus();
|
||||||
|
|
||||||
// Inventory adjustment dialog context.
|
// Inventory adjustment dialog context.
|
||||||
const { accounts } = useInventoryAdjContext();
|
const { accounts, branches, warehouses } = useInventoryAdjContext();
|
||||||
|
|
||||||
// Intl context.
|
// Sets the primary warehouse to form.
|
||||||
|
useSetPrimaryWarehouseToForm();
|
||||||
|
|
||||||
|
// Sets the primary branch to form.
|
||||||
|
useSetPrimaryBranchToForm();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<Row>
|
||||||
|
<FeatureCan feature={Features.Branches}>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'branch'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<BranchSelect
|
||||||
|
name={'branch_id'}
|
||||||
|
branches={branches}
|
||||||
|
input={BranchSelectButton}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</FeatureCan>
|
||||||
|
<FeatureCan feature={Features.Warehouses}>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'warehouse'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<WarehouseSelect
|
||||||
|
name={'warehouse_id'}
|
||||||
|
warehouses={warehouses}
|
||||||
|
input={WarehouseSelectButton}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</FeatureCan>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
{featureCan(Features.Warehouses) && featureCan(Features.Branches) && (
|
||||||
|
<FeatureRowDivider />
|
||||||
|
)}
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -173,3 +234,9 @@ export default function InventoryAdjustmentFormDialogFields() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const FeatureRowDivider = styled.div`
|
||||||
|
height: 2px;
|
||||||
|
background: #e9e9e9;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import React, { useState, createContext } from 'react';
|
import React, { useState, createContext } from 'react';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
|
import { Features } from 'common';
|
||||||
|
import { useFeatureCan } from 'hooks/state';
|
||||||
import {
|
import {
|
||||||
useItem,
|
useItem,
|
||||||
useAccounts,
|
useAccounts,
|
||||||
|
useBranches,
|
||||||
|
useWarehouses,
|
||||||
useCreateInventoryAdjustment,
|
useCreateInventoryAdjustment,
|
||||||
} from 'hooks/query';
|
} from 'hooks/query';
|
||||||
|
|
||||||
@@ -12,29 +16,59 @@ const InventoryAdjustmentContext = createContext();
|
|||||||
* Inventory adjustment dialog provider.
|
* Inventory adjustment dialog provider.
|
||||||
*/
|
*/
|
||||||
function InventoryAdjustmentFormProvider({ itemId, dialogName, ...props }) {
|
function InventoryAdjustmentFormProvider({ itemId, dialogName, ...props }) {
|
||||||
|
// Features guard.
|
||||||
|
const { featureCan } = useFeatureCan();
|
||||||
|
const isWarehouseFeatureCan = featureCan(Features.Warehouses);
|
||||||
|
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
// Fetches accounts list.
|
// Fetches accounts list.
|
||||||
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
||||||
|
|
||||||
// Fetches the item details.
|
// Fetches the item details.
|
||||||
const { isFetching: isItemLoading, data: item } = useItem(itemId);
|
const { isFetching: isItemLoading, data: item } = useItem(itemId);
|
||||||
|
|
||||||
|
// Fetch warehouses list.
|
||||||
const {
|
const {
|
||||||
mutateAsync: createInventoryAdjMutate,
|
data: warehouses,
|
||||||
} = useCreateInventoryAdjustment();
|
isLoading: isWarehouesLoading,
|
||||||
|
isSuccess: isWarehousesSuccess,
|
||||||
|
} = useWarehouses({}, { enabled: isWarehouseFeatureCan });
|
||||||
|
|
||||||
|
// Fetches the branches list.
|
||||||
|
const {
|
||||||
|
data: branches,
|
||||||
|
isLoading: isBranchesLoading,
|
||||||
|
isSuccess: isBranchesSuccess,
|
||||||
|
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||||
|
|
||||||
|
const { mutateAsync: createInventoryAdjMutate } =
|
||||||
|
useCreateInventoryAdjustment();
|
||||||
|
|
||||||
// Submit payload.
|
// Submit payload.
|
||||||
const [submitPayload, setSubmitPayload] = useState({});
|
const [submitPayload, setSubmitPayload] = useState({});
|
||||||
|
|
||||||
|
// Determines whether the warehouse and branches are loading.
|
||||||
|
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
|
||||||
|
|
||||||
// State provider.
|
// State provider.
|
||||||
const provider = {
|
const provider = {
|
||||||
itemId,
|
|
||||||
isAccountsLoading,
|
|
||||||
accounts,
|
|
||||||
isItemLoading,
|
|
||||||
item,
|
item,
|
||||||
submitPayload,
|
itemId,
|
||||||
|
branches,
|
||||||
|
warehouses,
|
||||||
|
accounts,
|
||||||
|
|
||||||
dialogName,
|
dialogName,
|
||||||
|
submitPayload,
|
||||||
|
|
||||||
|
isBranchesSuccess,
|
||||||
|
isWarehousesSuccess,
|
||||||
|
isAccountsLoading,
|
||||||
|
isItemLoading,
|
||||||
|
isFeatureLoading,
|
||||||
|
isWarehouesLoading,
|
||||||
|
isBranchesLoading,
|
||||||
|
|
||||||
createInventoryAdjMutate,
|
createInventoryAdjMutate,
|
||||||
setSubmitPayload,
|
setSubmitPayload,
|
||||||
};
|
};
|
||||||
@@ -46,6 +80,7 @@ function InventoryAdjustmentFormProvider({ itemId, dialogName, ...props }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const useInventoryAdjContext = () => React.useContext(InventoryAdjustmentContext);
|
const useInventoryAdjContext = () =>
|
||||||
|
React.useContext(InventoryAdjustmentContext);
|
||||||
|
|
||||||
export { InventoryAdjustmentFormProvider, useInventoryAdjContext };
|
export { InventoryAdjustmentFormProvider, useInventoryAdjContext };
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider';
|
||||||
|
import { first } from 'lodash';
|
||||||
|
|
||||||
export const decrementQuantity = (newQuantity, quantityOnHand) => {
|
export const decrementQuantity = (newQuantity, quantityOnHand) => {
|
||||||
return quantityOnHand - newQuantity;
|
return quantityOnHand - newQuantity;
|
||||||
@@ -12,3 +16,34 @@ export const diffQuantity = (newQuantity, quantityOnHand, type) => {
|
|||||||
? decrementQuantity(newQuantity, quantityOnHand)
|
? decrementQuantity(newQuantity, quantityOnHand)
|
||||||
: incrementQuantity(newQuantity, quantityOnHand);
|
: incrementQuantity(newQuantity, quantityOnHand);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSetPrimaryWarehouseToForm = () => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
const { warehouses, isWarehousesSuccess } = useInventoryAdjContext();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isWarehousesSuccess) {
|
||||||
|
const primaryWarehouse =
|
||||||
|
warehouses.find((b) => b.primary) || first(warehouses);
|
||||||
|
|
||||||
|
if (primaryWarehouse) {
|
||||||
|
setFieldValue('warehouse_id', primaryWarehouse.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isWarehousesSuccess, setFieldValue, warehouses]);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
const { branches, isBranchesSuccess } = useInventoryAdjContext();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isBranchesSuccess) {
|
||||||
|
const primaryBranch = branches.find((b) => b.primary) || first(branches);
|
||||||
|
|
||||||
|
if (primaryBranch) {
|
||||||
|
setFieldValue('branch_id', primaryBranch.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1844,6 +1844,7 @@
|
|||||||
"branches.column.code": "Code",
|
"branches.column.code": "Code",
|
||||||
"select_branch": "Select branch",
|
"select_branch": "Select branch",
|
||||||
"branch": "Branch",
|
"branch": "Branch",
|
||||||
|
"warehouse":"Warehouse",
|
||||||
"branch.dialog.label_new_branch": "New Branch",
|
"branch.dialog.label_new_branch": "New Branch",
|
||||||
"branch.dialog.label_edit_branch": "New Branch",
|
"branch.dialog.label_edit_branch": "New Branch",
|
||||||
"branch.dialog.label.branch_name": "Branch Name",
|
"branch.dialog.label.branch_name": "Branch Name",
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
.dialog--quick-payment-receive {
|
.dialog--quick-payment-receive {
|
||||||
.bp3-dialog-body {
|
|
||||||
line-height: 14px;
|
|
||||||
.bp3-form-group {
|
.bp3-form-group {
|
||||||
margin-bottom: 13px;
|
margin-bottom: 15px;
|
||||||
|
|
||||||
label.bp3-label {
|
label.bp3-label {
|
||||||
margin-bottom: 3px;
|
margin-bottom: 3px;
|
||||||
@@ -25,5 +23,4 @@
|
|||||||
|
|
||||||
.bp3-dialog-footer {
|
.bp3-dialog-footer {
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user