mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: add project to expenses
This commit is contained in:
@@ -33,6 +33,7 @@ const Schema = Yup.object().shape({
|
|||||||
}),
|
}),
|
||||||
landed_cost: Yup.boolean(),
|
landed_cost: Yup.boolean(),
|
||||||
description: Yup.string().max(DATATYPES_LENGTH.TEXT).nullable(),
|
description: Yup.string().max(DATATYPES_LENGTH.TEXT).nullable(),
|
||||||
|
project_id: Yup.number().nullable(),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import { defaultExpenseEntry, accountsFieldShouldUpdate } from './utils';
|
|||||||
*/
|
*/
|
||||||
export default function ExpenseFormEntriesField({ linesNumber = 4 }) {
|
export default function ExpenseFormEntriesField({ linesNumber = 4 }) {
|
||||||
// Expense form context.
|
// Expense form context.
|
||||||
const { accounts } = useExpenseFormContext();
|
const { accounts, projects } = useExpenseFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FastField
|
<FastField
|
||||||
name={'categories'}
|
name={'categories'}
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
|
projects={projects}
|
||||||
shouldUpdate={accountsFieldShouldUpdate}
|
shouldUpdate={accountsFieldShouldUpdate}
|
||||||
>
|
>
|
||||||
{({
|
{({
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default function ExpenseFormEntriesTable({
|
|||||||
minLines,
|
minLines,
|
||||||
}) {
|
}) {
|
||||||
// Expense form context.
|
// Expense form context.
|
||||||
const { accounts } = useExpenseFormContext();
|
const { accounts, projects } = useExpenseFormContext();
|
||||||
|
|
||||||
// Memorized data table columns.
|
// Memorized data table columns.
|
||||||
const columns = useExpenseFormTableColumns({ landedCost });
|
const columns = useExpenseFormTableColumns({ landedCost });
|
||||||
@@ -69,11 +69,12 @@ export default function ExpenseFormEntriesTable({
|
|||||||
sticky={true}
|
sticky={true}
|
||||||
payload={{
|
payload={{
|
||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
|
projects: projects,
|
||||||
errors: error,
|
errors: error,
|
||||||
updateData: handleUpdateData,
|
updateData: handleUpdateData,
|
||||||
removeRow: handleRemoveRow,
|
removeRow: handleRemoveRow,
|
||||||
autoFocus: ['expense_account_id', 0],
|
autoFocus: ['expense_account_id', 0],
|
||||||
currencyCode
|
currencyCode,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -81,4 +82,4 @@ export default function ExpenseFormEntriesTable({
|
|||||||
|
|
||||||
ExpenseFormEntriesTable.defaultProps = {
|
ExpenseFormEntriesTable.defaultProps = {
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
useCreateExpense,
|
useCreateExpense,
|
||||||
useEditExpense,
|
useEditExpense,
|
||||||
} from '@/hooks/query';
|
} from '@/hooks/query';
|
||||||
|
import { useProjects } from '@/containers/Projects/hooks';
|
||||||
|
|
||||||
const ExpenseFormPageContext = createContext();
|
const ExpenseFormPageContext = createContext();
|
||||||
|
|
||||||
@@ -45,6 +46,12 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
|||||||
// Fetch accounts list.
|
// Fetch accounts list.
|
||||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||||
|
|
||||||
|
// Fetch the projects list.
|
||||||
|
const {
|
||||||
|
data: { projects },
|
||||||
|
isLoading: isProjectsLoading,
|
||||||
|
} = useProjects();
|
||||||
|
|
||||||
// Create and edit expense mutate.
|
// Create and edit expense mutate.
|
||||||
const { mutateAsync: createExpenseMutate } = useCreateExpense();
|
const { mutateAsync: createExpenseMutate } = useCreateExpense();
|
||||||
const { mutateAsync: editExpenseMutate } = useEditExpense();
|
const { mutateAsync: editExpenseMutate } = useEditExpense();
|
||||||
@@ -66,7 +73,8 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
|||||||
expense,
|
expense,
|
||||||
accounts,
|
accounts,
|
||||||
branches,
|
branches,
|
||||||
|
projects,
|
||||||
|
|
||||||
isCurrenciesLoading,
|
isCurrenciesLoading,
|
||||||
isExpenseLoading,
|
isExpenseLoading,
|
||||||
isCustomersLoading,
|
isCustomersLoading,
|
||||||
@@ -84,7 +92,8 @@ function ExpenseFormPageProvider({ query, expenseId, ...props }) {
|
|||||||
isCurrenciesLoading ||
|
isCurrenciesLoading ||
|
||||||
isExpenseLoading ||
|
isExpenseLoading ||
|
||||||
isCustomersLoading ||
|
isCustomersLoading ||
|
||||||
isAccountsLoading
|
isAccountsLoading ||
|
||||||
|
isProjectsLoading
|
||||||
}
|
}
|
||||||
name={'expense-form'}
|
name={'expense-form'}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ import {
|
|||||||
InputGroupCell,
|
InputGroupCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
AccountsListFieldCell,
|
AccountsListFieldCell,
|
||||||
|
ProjectsListFieldCell,
|
||||||
CheckBoxFieldCell,
|
CheckBoxFieldCell,
|
||||||
} from '@/components/DataTableCells';
|
} from '@/components/DataTableCells';
|
||||||
import { CellType, Align } from '@/constants';
|
import { CellType, Features, Align } from '@/constants';
|
||||||
|
|
||||||
import { useCurrentOrganization } from '@/hooks/state';
|
import { useCurrentOrganization, useFeatureCan } from '@/hooks/state';
|
||||||
import { useExpensesIsForeign } from './utils';
|
import { useExpensesIsForeign } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +91,8 @@ export function ExpenseAmountHeaderCell({ payload: { currencyCode } }) {
|
|||||||
* Retrieve expense form table entries columns.
|
* Retrieve expense form table entries columns.
|
||||||
*/
|
*/
|
||||||
export function useExpenseFormTableColumns({ landedCost }) {
|
export function useExpenseFormTableColumns({ landedCost }) {
|
||||||
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -118,6 +121,20 @@ export function useExpenseFormTableColumns({ landedCost }) {
|
|||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
},
|
},
|
||||||
|
...(featureCan(Features.Branches)
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
Header: intl.get('project'),
|
||||||
|
id: 'project_id',
|
||||||
|
accessor: 'project_id',
|
||||||
|
Cell: ProjectsListFieldCell,
|
||||||
|
className: 'project_id',
|
||||||
|
disableSortBy: true,
|
||||||
|
width: 40,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
|
||||||
...(landedCost
|
...(landedCost
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const defaultExpenseEntry = {
|
|||||||
expense_account_id: '',
|
expense_account_id: '',
|
||||||
description: '',
|
description: '',
|
||||||
landed_cost: 0,
|
landed_cost: 0,
|
||||||
|
project_id: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultExpense = {
|
export const defaultExpense = {
|
||||||
|
|||||||
@@ -2190,7 +2190,8 @@
|
|||||||
"receipt.project_name.label": "Project Name",
|
"receipt.project_name.label": "Project Name",
|
||||||
"bill.project_name.label": "Project Name",
|
"bill.project_name.label": "Project Name",
|
||||||
"payment_receive.project_name.label": "Project Name",
|
"payment_receive.project_name.label": "Project Name",
|
||||||
"select_project": "Select Project",
|
"select_project": "Select project",
|
||||||
|
"project":"Project",
|
||||||
"projects_multi_select.label":"Projects",
|
"projects_multi_select.label":"Projects",
|
||||||
"projects_multi_select.placeholder": "Filter by projects…",
|
"projects_multi_select.placeholder": "Filter by projects…",
|
||||||
"project_profitability_summary": "Project Profitability Summary",
|
"project_profitability_summary": "Project Profitability Summary",
|
||||||
|
|||||||
Reference in New Issue
Block a user