From fabc8d3b4ec930ec7d7188207d63b9f44f4815c3 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 24 Jul 2021 13:16:44 +0200 Subject: [PATCH 1/4] feat: bill Drawer. --- .../Drawers/BillDrawer/BillDrawerAlerts.js | 13 +++++++++++++ .../Drawers/BillDrawer/BillDrawerContent.js | 7 +++++-- .../Drawers/BillDrawer/BillDrawerProvider.js | 13 +++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 client/src/containers/Drawers/BillDrawer/BillDrawerAlerts.js diff --git a/client/src/containers/Drawers/BillDrawer/BillDrawerAlerts.js b/client/src/containers/Drawers/BillDrawer/BillDrawerAlerts.js new file mode 100644 index 000000000..278671574 --- /dev/null +++ b/client/src/containers/Drawers/BillDrawer/BillDrawerAlerts.js @@ -0,0 +1,13 @@ +import React from 'react'; +import BillTransactionDeleteAlert from 'containers/Alerts/Bills/BillTransactionDeleteAlert'; + +/** + * Bill drawer alert. + */ +export default function BillDrawerAlerts() { + return ( +
+ +
+ ); +} diff --git a/client/src/containers/Drawers/BillDrawer/BillDrawerContent.js b/client/src/containers/Drawers/BillDrawer/BillDrawerContent.js index 0e93746a5..ec1579009 100644 --- a/client/src/containers/Drawers/BillDrawer/BillDrawerContent.js +++ b/client/src/containers/Drawers/BillDrawer/BillDrawerContent.js @@ -1,16 +1,19 @@ import React from 'react'; import { BillDrawerProvider } from './BillDrawerProvider'; import BillDrawerDetails from './BillDrawerDetails'; +import BillDrawerAlerts from './BillDrawerAlerts'; + /** * Bill drawer content. */ export default function BillDrawerContent({ // #ownProp - billId, + bill, }) { return ( - + + ); } diff --git a/client/src/containers/Drawers/BillDrawer/BillDrawerProvider.js b/client/src/containers/Drawers/BillDrawer/BillDrawerProvider.js index 689508ad0..5bd4a8246 100644 --- a/client/src/containers/Drawers/BillDrawer/BillDrawerProvider.js +++ b/client/src/containers/Drawers/BillDrawer/BillDrawerProvider.js @@ -1,6 +1,7 @@ import React from 'react'; import intl from 'react-intl-universal'; import { DrawerHeaderContent, DashboardInsider } from 'components'; +import { useBillLocatedLandedCost } from 'hooks/query'; const BillDrawerContext = React.createContext(); @@ -8,10 +9,18 @@ const BillDrawerContext = React.createContext(); * Bill drawer provider. */ function BillDrawerProvider({ billId, ...props }) { + // Handle fetch bill located landed cost transaction. + const { isLoading: isLandedCostLoading, data: transactions } = + useBillLocatedLandedCost(billId, { + enabled: !!billId, + }); + //provider. - const provider = {}; + const provider = { + transactions, + }; return ( - + Date: Sat, 24 Jul 2021 15:03:13 +0200 Subject: [PATCH 2/4] feat: catch error. --- .../Alerts/Expenses/ExpenseDeleteAlert.js | 47 ++++++++++++------- .../Purchases/Bills/BillForm/utils.js | 10 ++++ client/src/lang/en/index.json | 5 +- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js b/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js index b367fec84..f8604be99 100644 --- a/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js +++ b/client/src/containers/Alerts/Expenses/ExpenseDeleteAlert.js @@ -21,11 +21,7 @@ function ExpenseDeleteAlert({ isOpen, payload: { expenseId }, }) { - - const { - mutateAsync: deleteExpenseMutate, - isLoading, - } = useDeleteExpense(); + const { mutateAsync: deleteExpenseMutate, isLoading } = useDeleteExpense(); // Handle cancel expense journal. const handleCancelExpenseDelete = () => { @@ -34,17 +30,34 @@ function ExpenseDeleteAlert({ // Handle confirm delete expense. const handleConfirmExpenseDelete = () => { - deleteExpenseMutate(expenseId).then(() => { - AppToaster.show({ - message: intl.get( - 'the_expense_has_been_deleted_successfully', - { number: expenseId }, - ), - intent: Intent.SUCCESS, - }); - }).finally(() => { - closeAlert('expense-delete'); - }); + deleteExpenseMutate(expenseId) + .then(() => { + AppToaster.show({ + message: intl.get('the_expense_has_been_deleted_successfully', { + number: expenseId, + }), + intent: Intent.SUCCESS, + }); + closeAlert('expense-delete'); + }) + .catch( + ({ + response: { + data: { errors }, + }, + }) => { + if ( + errors.find((e) => e.type === 'EXPENSE_HAS_ASSOCIATED_LANDED_COST') + ) { + AppToaster.show({ + intent: Intent.DANGER, + message: intl.get( + 'couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction', + ), + }); + } + }, + ); }; return ( @@ -68,4 +81,4 @@ function ExpenseDeleteAlert({ export default compose( withAlertStoreConnect(), withAlertActions, -)(ExpenseDeleteAlert); \ No newline at end of file +)(ExpenseDeleteAlert); diff --git a/client/src/containers/Purchases/Bills/BillForm/utils.js b/client/src/containers/Purchases/Bills/BillForm/utils.js index 47ebec4a2..dba011cf7 100644 --- a/client/src/containers/Purchases/Bills/BillForm/utils.js +++ b/client/src/containers/Purchases/Bills/BillForm/utils.js @@ -51,4 +51,14 @@ export const handleDeleteErrors = (errors) => { intent: Intent.DANGER, }); } + if ( + errors.find((error) => error.type === 'BILL_HAS_ASSOCIATED_LANDED_COSTS') + ) { + AppToaster.show({ + message: intl.get( + 'cannot_delete_bill_that_has_associated_landed_cost_transactions', + ), + intent: Intent.DANGER, + }); + } }; diff --git a/client/src/lang/en/index.json b/client/src/lang/en/index.json index 1643a7891..6ad074587 100644 --- a/client/src/lang/en/index.json +++ b/client/src/lang/en/index.json @@ -1136,5 +1136,8 @@ "select_transaction":"Select transaction account", "details":"Details", "located_landed_cost":"Located Landed Cost", - "delete_transaction":"Delete transaction" + "delete_transaction":"Delete transaction", + "cannot_delete_bill_that_has_associated_landed_cost_transactions":"Cannot delete bill that has associated landed cost transactions.", + "couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction":"Couldn't delete expense transaction has associated located landed cost transaction" + } \ No newline at end of file From c72918fb1f4c0cf67c3c88928d8ea7b48f197e27 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 24 Jul 2021 16:32:18 +0200 Subject: [PATCH 3/4] feat: checkbox field cell. --- .../DataTableCells/CheckBoxFieldCell.js | 41 +++++++++++++++++++ client/src/components/DataTableCells/index.js | 4 +- .../Expenses/ExpenseForm/ExpenseForm.js | 5 ++- .../Expenses/ExpenseForm/components.js | 16 +------- .../containers/Expenses/ExpenseForm/utils.js | 2 +- 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 client/src/components/DataTableCells/CheckBoxFieldCell.js diff --git a/client/src/components/DataTableCells/CheckBoxFieldCell.js b/client/src/components/DataTableCells/CheckBoxFieldCell.js new file mode 100644 index 000000000..4cb58ffa1 --- /dev/null +++ b/client/src/components/DataTableCells/CheckBoxFieldCell.js @@ -0,0 +1,41 @@ +import React from 'react'; +import classNames from 'classnames'; +import { Classes, Checkbox, FormGroup, Intent } from '@blueprintjs/core'; + +const CheckboxEditableCell = ({ + row: { index }, + column: { id }, + cell: { value: initialValue }, + payload, +}) => { + const [value, setValue] = React.useState(initialValue); + + const onChange = (e) => { + setValue(e.target.value); + }; + const onBlur = () => { + payload.updateData(index, id, value); + }; + React.useEffect(() => { + setValue(initialValue); + }, [initialValue]); + + const error = payload.errors?.[index]?.[id]; + + return ( + + + + ); +}; + +export default CheckboxEditableCell; diff --git a/client/src/components/DataTableCells/index.js b/client/src/components/DataTableCells/index.js index 8cde83de0..2a0688ad2 100644 --- a/client/src/components/DataTableCells/index.js +++ b/client/src/components/DataTableCells/index.js @@ -6,6 +6,7 @@ import ItemsListCell from './ItemsListCell'; import PercentFieldCell from './PercentFieldCell'; import { DivFieldCell, EmptyDiv } from './DivFieldCell'; import NumericInputCell from './NumericInputCell'; +import CheckBoxFieldCell from './CheckBoxFieldCell' export { AccountsListFieldCell, @@ -16,5 +17,6 @@ export { PercentFieldCell, DivFieldCell, EmptyDiv, - NumericInputCell + NumericInputCell, + CheckBoxFieldCell }; diff --git a/client/src/containers/Expenses/ExpenseForm/ExpenseForm.js b/client/src/containers/Expenses/ExpenseForm/ExpenseForm.js index a75fd5dd6..2f0472447 100644 --- a/client/src/containers/Expenses/ExpenseForm/ExpenseForm.js +++ b/client/src/containers/Expenses/ExpenseForm/ExpenseForm.js @@ -79,7 +79,10 @@ function ExpenseForm({ } const categories = values.categories.filter( (category) => - category.amount && category.index && category.expense_account_id, + category.amount && + category.index && + category.expense_account_id && + category.landed_cost, ); const form = { diff --git a/client/src/containers/Expenses/ExpenseForm/components.js b/client/src/containers/Expenses/ExpenseForm/components.js index b60949896..21d71cf20 100644 --- a/client/src/containers/Expenses/ExpenseForm/components.js +++ b/client/src/containers/Expenses/ExpenseForm/components.js @@ -7,6 +7,7 @@ import { InputGroupCell, MoneyFieldCell, AccountsListFieldCell, + CheckBoxFieldCell, } from 'components/DataTableCells'; import { formattedAmount, safeSumBy } from 'utils'; @@ -49,19 +50,6 @@ const ActionsCellRenderer = ({ ); }; -/** - * Landed cost cell. - */ -const LandedCostCell = ({ - row: { index }, - column: { id }, - cell: { value: initialValue }, - data, - payload, -}) => { - return ; -}; - /** * Landed cost header cell. */ @@ -142,7 +130,7 @@ export function useExpenseFormTableColumns() { { Header: LandedCostHeaderCell, accessor: 'landed_cost', - Cell: LandedCostCell, + Cell: CheckBoxFieldCell, disableSortBy: true, disableResizing: true, width: 70, diff --git a/client/src/containers/Expenses/ExpenseForm/utils.js b/client/src/containers/Expenses/ExpenseForm/utils.js index 36653842c..d418c42a3 100644 --- a/client/src/containers/Expenses/ExpenseForm/utils.js +++ b/client/src/containers/Expenses/ExpenseForm/utils.js @@ -27,7 +27,7 @@ export const defaultExpenseEntry = { amount: '', expense_account_id: '', description: '', - landed_cost: false, + landed_cost: 0, }; export const defaultExpense = { From cd27864f6df3599bded5300333fb47ab49d3cf19 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sun, 25 Jul 2021 01:16:24 +0200 Subject: [PATCH 4/4] feat : allocate landed cost. --- .../AllocateLandedCostDialogProvider.js | 31 ++++- .../AllocateLandedCostEntriesTable.js | 49 +++----- .../AllocateLandedCostFloatingActions.js | 1 - .../AllocateLandedCostForm.js | 56 +++++++-- .../AllocateLandedCostFormBody.js | 14 ++- .../AllocateLandedCostFormContent.js | 1 + .../AllocateLandedCostFormFields.js | 109 +++++++++--------- .../Dialogs/AllocateLandedCostDialog/utils.js | 4 + client/src/hooks/query/landedCost.js | 7 +- client/src/lang/en/index.json | 4 +- 10 files changed, 161 insertions(+), 115 deletions(-) create mode 100644 client/src/containers/Dialogs/AllocateLandedCostDialog/utils.js diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostDialogProvider.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostDialogProvider.js index aec4f85eb..ba4be03fa 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostDialogProvider.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostDialogProvider.js @@ -1,27 +1,50 @@ import React from 'react'; import { DialogContent } from 'components'; -import { useBill } from 'hooks/query'; +import { useBill, useCreateLandedCost } from 'hooks/query'; -import { pick } from 'lodash'; +import { map, omit, pick } from 'lodash'; +import * as R from 'ramda'; const AllocateLandedCostDialogContext = React.createContext(); /** * Allocate landed cost provider. */ -function AllocateLandedCostDialogProvider({ billId, dialogName, ...props }) { +function AllocateLandedCostDialogProvider({ + billId, + query, + dialogName, + ...props +}) { // Handle fetch bill details. const { isLoading: isBillLoading, data: bill } = useBill(billId, { enabled: !!billId, }); + // Create landed cost mutations. + const { mutateAsync: createLandedCostMutate } = useCreateLandedCost(); + + // const L = [bill].map(({ entries: items }) => ({ + // items, + // })); + // let obj = { oldKey: 1, b: 2, c: 3 }; + // const { oldKey: newKey, ...rest } = obj; + // obj = { newKey, ...rest }; + + // const obj = { ...pick(bill, ['entries']).map((index) => index) }; + + // provider payload. const provider = { - bill: { + items: { ...pick(bill, ['entries']), }, dialogName, + query, + createLandedCostMutate, + billId, }; + return ( diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostEntriesTable.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostEntriesTable.js index 171d88ce1..4400b0124 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostEntriesTable.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostEntriesTable.js @@ -1,6 +1,6 @@ import React from 'react'; import intl from 'react-intl-universal'; -import { DataTable, MoneyFieldCell, DataTableEditable } from 'components'; +import { MoneyFieldCell, DataTableEditable } from 'components'; import { compose, updateTableRow } from 'utils'; /** @@ -10,12 +10,13 @@ export default function AllocateLandedCostEntriesTable({ onUpdateData, entries, }) { + // allocate landed cost entries table columns. const columns = React.useMemo( () => [ { Header: intl.get('item'), - accessor: 'item_id', + accessor: 'item.name', disableSortBy: true, width: '150', }, @@ -59,38 +60,14 @@ export default function AllocateLandedCostEntriesTable({ [onUpdateData, entries], ); - const LL = [ - { - item_id: 'ITEM', - quantity: '30000', - rate: '100000', - amount: '400', - }, - { - item_id: 'ITEM', - quantity: '30000', - rate: '100000', - amount: '400', - }, - { - item_id: 'ITEM', - quantity: '30000', - rate: '100000', - amount: '400', - }, - { - item_id: 'ITEM', - quantity: '30000', - rate: '100000', - amount: '400', - }, - { - item_id: 'ITEM', - quantity: '30000', - rate: '100000', - amount: '400', - }, - ]; - - return ; + return ( + + ); } diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFloatingActions.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFloatingActions.js index ddc400903..8f16e5ec2 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFloatingActions.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFloatingActions.js @@ -13,7 +13,6 @@ function AllocateLandedCostFloatingActions({ }) { // Formik context. const { isSubmitting } = useFormikContext(); - const { dialogName } = useAllocateLandedConstDialogContext(); // Handle cancel button click. diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostForm.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostForm.js index 5ccffca48..d3f5ef983 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostForm.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostForm.js @@ -1,24 +1,27 @@ import React from 'react'; import { Formik } from 'formik'; +import { Intent } from '@blueprintjs/core'; +import intl from 'react-intl-universal'; import moment from 'moment'; +import { pick, omit } from 'lodash'; import 'style/pages/AllocateLandedCost/AllocateLandedCostForm.scss'; +import { AppToaster } from 'components'; import { AllocateLandedCostFormSchema } from './AllocateLandedCostForm.schema'; import { useAllocateLandedConstDialogContext } from './AllocateLandedCostDialogProvider'; import AllocateLandedCostFormContent from './AllocateLandedCostFormContent'; import withDialogActions from 'containers/Dialog/withDialogActions'; - import { compose } from 'utils'; const defaultInitialValues = { - transaction_type: 'bills', + transaction_type: 'Bill', transaction_date: moment(new Date()).format('YYYY-MM-DD'), transaction_id: '', transaction_entry_id: '', amount: '', allocation_method: 'quantity', - entries: { + items: { entry_id: '', cost: '', }, @@ -31,26 +34,59 @@ function AllocateLandedCostForm({ // #withDialogActions closeDialog, }) { - const { bill, dialogName } = useAllocateLandedConstDialogContext(); + const { items, dialogName, createLandedCostMutate } = + useAllocateLandedConstDialogContext(); // Initial form values. const initialValues = { ...defaultInitialValues, - ...bill, + ...items, }; - // Handle form submit. - const handleFormSubmit = (values, { setSubmitting }) => {}; + const handleFormSubmit = (values, { setSubmitting }) => { + setSubmitting(false); + closeDialog(dialogName); + + const entries = [values] + .filter((entry) => entry.id && entry.cost) + .map((entry) => ({ + entry_id: entry.id, + ...pick(entry, ['cost']), + })); + + const form = { + ...values, + // items:{entries}, + }; + + // Handle the request success. + const onSuccess = (response) => { + AppToaster.show({ + message: intl.get('the_landed_cost_has_been_created_successfully'), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + }; + + // Handle the request error. + const onError = ({ + response: { + data: { errors }, + }, + }) => { + setSubmitting(false); + }; + createLandedCostMutate(form).then(onSuccess).catch(onError); + }; return ( - - + component={AllocateLandedCostFormContent} + /> ); } diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormBody.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormBody.js index 13029efd5..a0df6980a 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormBody.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormBody.js @@ -13,12 +13,14 @@ export default function AllocateLandedCostFormBody() { field: { value }, meta: { error, touched }, }) => ( - { - setFieldValue('entries', newEntries); - }} - /> + <> + { + setFieldValue('entries', newEntries); + }} + /> + )} diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormContent.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormContent.js index c06d05a67..e1f5f08c0 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormContent.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormContent.js @@ -2,6 +2,7 @@ import React from 'react'; import { Form } from 'formik'; import AllocateLandedCostFormFields from './AllocateLandedCostFormFields'; import AllocateLandedCostFloatingActions from './AllocateLandedCostFloatingActions'; + /** * Allocate landed cost form content. */ diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormFields.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormFields.js index a1639ca96..ea7b76a2f 100644 --- a/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormFields.js +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/AllocateLandedCostFormFields.js @@ -1,34 +1,39 @@ import React from 'react'; -import { FastField, ErrorMessage } from 'formik'; +import { FastField, Field, ErrorMessage, useFormikContext } from 'formik'; import { Classes, FormGroup, RadioGroup, Radio, InputGroup, - Position, } from '@blueprintjs/core'; -import { DateInput } from '@blueprintjs/datetime'; import classNames from 'classnames'; import { FormattedMessage as T } from 'components'; import intl from 'react-intl-universal'; -import { - inputIntent, - momentFormatter, - tansformDateValue, - handleDateChange, - handleStringChange, -} from 'utils'; +import { inputIntent, handleStringChange } from 'utils'; import { FieldRequiredHint, ListSelect } from 'components'; import { CLASSES } from 'common/classes'; import allocateLandedCostType from 'common/allocateLandedCostType'; -import AccountsSuggestField from 'components/AccountsSuggestField'; +import { useLandedCostTransaction } from 'hooks/query'; + import AllocateLandedCostFormBody from './AllocateLandedCostFormBody'; +import { getEntriesByTransactionId } from './utils'; /** * Allocate landed cost form fields. */ export default function AllocateLandedCostFormFields() { + const { values } = useFormikContext(); + + const { + data: { transactions }, + } = useLandedCostTransaction(values.transaction_type); + + const transactionEntry = getEntriesByTransactionId( + transactions, + values.transaction_id, + ); + return (
{/*------------Transaction type -----------*/} @@ -61,69 +66,64 @@ export default function AllocateLandedCostFormFields() { )} - {/*------------Transaction date -----------*/} - - {({ form, field: { value }, meta: { error, touched } }) => ( - } - // labelInfo={} - intent={inputIntent({ error, touched })} - helperText={} - minimal={true} - className={classNames(CLASSES.FILL, 'form-group--transaction_date')} - inline={true} - > - { - form.setFieldValue('transaction_date', formattedDate); - })} - value={tansformDateValue(value)} - popoverProps={{ - position: Position.BOTTOM, - minimal: true, - }} - /> - - )} - {/*------------ Transaction -----------*/} - - {({ form, field, meta: { error, touched } }) => ( + + {({ form, field: { value }, meta: { error, touched } }) => ( } // labelInfo={} intent={inputIntent({ error, touched })} helperText={} - className={'form-group--transaction_id'} + className={classNames(CLASSES.FILL, 'form-group--transaction_id')} inline={true} > - - form.setFieldValue('transaction_id', id) - } - inputProps={{ - placeholder: intl.get('select_transaction'), + { + form.setFieldValue('transaction_id', id); }} + filterable={false} + selectedItem={value} + selectedItemProp={'id'} + textProp={'name'} + labelProp={'id'} + defaultText={intl.get('select_transaction')} + popoverProps={{ minimal: true }} /> )} - + + {/*------------ Transaction line -----------*/} - - {({ form, field, meta: { error, touched } }) => ( + + {({ form, field: { value }, meta: { error, touched } }) => ( } intent={inputIntent({ error, touched })} helperText={} - className={'form-group--transaction_entry_id'} + className={classNames( + CLASSES.FILL, + 'form-group--transaction_entry_id', + )} inline={true} > - + { + form.setFieldValue('transaction_entry_id', id); + }} + filterable={false} + selectedItem={value} + selectedItemProp={'id'} + textProp={'name'} + labelProp={'id'} + defaultText={intl.get('select_transaction')} + popoverProps={{ minimal: true }} + /> )} - + + {/*------------ Amount -----------*/} {({ form, field, meta: { error, touched } }) => ( @@ -138,6 +138,7 @@ export default function AllocateLandedCostFormFields() { )} + {/*------------ Allocation method -----------*/} {({ form, field: { value }, meta: { touched, error } }) => ( @@ -158,7 +159,7 @@ export default function AllocateLandedCostFormFields() { inline={true} > } value="quantity" /> - } value="valuation" /> + } value="value" /> )} diff --git a/client/src/containers/Dialogs/AllocateLandedCostDialog/utils.js b/client/src/containers/Dialogs/AllocateLandedCostDialog/utils.js new file mode 100644 index 000000000..b906a6ba0 --- /dev/null +++ b/client/src/containers/Dialogs/AllocateLandedCostDialog/utils.js @@ -0,0 +1,4 @@ +export function getEntriesByTransactionId(transactions, id) { + const transaction = transactions.find((trans) => trans.id === id); + return transaction ? transaction.entries : []; +} diff --git a/client/src/hooks/query/landedCost.js b/client/src/hooks/query/landedCost.js index 860835f4c..f9bb28497 100644 --- a/client/src/hooks/query/landedCost.js +++ b/client/src/hooks/query/landedCost.js @@ -63,8 +63,11 @@ export function useLandedCostTransaction(query, props) { params: { transaction_type: query }, }, { - select: (res) => res.data.transactions, - defaultData: [], + select: (res) => res.data, + + defaultData: { + transactions: [], + }, ...props, }, ); diff --git a/client/src/lang/en/index.json b/client/src/lang/en/index.json index 6ad074587..8e4e8053e 100644 --- a/client/src/lang/en/index.json +++ b/client/src/lang/en/index.json @@ -1138,6 +1138,6 @@ "located_landed_cost":"Located Landed Cost", "delete_transaction":"Delete transaction", "cannot_delete_bill_that_has_associated_landed_cost_transactions":"Cannot delete bill that has associated landed cost transactions.", - "couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction":"Couldn't delete expense transaction has associated located landed cost transaction" - + "couldn_t_delete_expense_transaction_has_associated_located_landed_cost_transaction":"Couldn't delete expense transaction has associated located landed cost transaction", + "the_landed_cost_has_been_created_successfully":"The landed cost has been created successfully" } \ No newline at end of file