mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
Merge branch 'feature/landed-cost' of https://github.com/abouolia/Ratteb into feature/landed-cost
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{ name: intl.get('bills'), value: 'bills' },
|
{ name: intl.get('bills'), value: 'Bill' },
|
||||||
{ name: intl.get('expenses'), value: 'expenses' },
|
{ name: intl.get('expenses'), value: 'Expense' },
|
||||||
]
|
];
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'components';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { useDeleteLandedCost } from 'hooks/query';
|
||||||
|
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
|
||||||
|
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||||
|
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bill transaction delete alert.
|
||||||
|
*/
|
||||||
|
function BillTransactionDeleteAlert({
|
||||||
|
name,
|
||||||
|
// #withAlertStoreConnect
|
||||||
|
isOpen,
|
||||||
|
payload: { BillId },
|
||||||
|
// #withAlertActions
|
||||||
|
closeAlert,
|
||||||
|
}) {
|
||||||
|
const { mutateAsync: deleteLandedCostMutate, isLoading } =
|
||||||
|
useDeleteLandedCost();
|
||||||
|
|
||||||
|
// Handle cancel delete.
|
||||||
|
const handleCancelAlert = () => {
|
||||||
|
closeAlert(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle confirm delete .
|
||||||
|
const handleConfirmLandedCostDelete = () => {
|
||||||
|
deleteLandedCostMutate(BillId)
|
||||||
|
.then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('the_landed_cost_has_been_deleted_successfully'),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
closeAlert(name);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
closeAlert(name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon="trash"
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={isOpen}
|
||||||
|
onCancel={handleCancelAlert}
|
||||||
|
onConfirm={handleConfirmLandedCostDelete}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
<p>{/* <T id={''}/> */}</p>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withAlertStoreConnect(),
|
||||||
|
withAlertActions,
|
||||||
|
)(BillTransactionDeleteAlert);
|
||||||
@@ -1,22 +1,37 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DataTable } from 'components';
|
import { DataTable } from 'components';
|
||||||
import { useLocatedLandedCostColumns, ActionsMenu } from './components';
|
import { useLocatedLandedCostColumns, ActionsMenu } from './components';
|
||||||
|
import { useBillDrawerContext } from './BillDrawerProvider';
|
||||||
|
|
||||||
|
import withAlertsActions from 'containers/Alert/withAlertActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Located landed cost table.
|
* Located landed cost table.
|
||||||
*/
|
*/
|
||||||
function LocatedLandedCostTable() {
|
function LocatedLandedCostTable({
|
||||||
|
// #withAlertsActions
|
||||||
|
openAlert,
|
||||||
|
}) {
|
||||||
const columns = useLocatedLandedCostColumns();
|
const columns = useLocatedLandedCostColumns();
|
||||||
|
const { transactions } = useBillDrawerContext();
|
||||||
|
|
||||||
const DATA = [
|
// Handle the transaction delete action.
|
||||||
{
|
const handleDeleteTransaction = ({ id }) => {
|
||||||
name: 'INV-1000',
|
openAlert('transaction-delete', { BillId: id });
|
||||||
amount: '10.000.000',
|
};
|
||||||
allocation_method: 'Bill',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return <DataTable columns={columns} data={DATA} ContextMenu={ActionsMenu} />;
|
return (
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={transactions}
|
||||||
|
ContextMenu={ActionsMenu}
|
||||||
|
payload={{
|
||||||
|
onDelete: handleDeleteTransaction,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LocatedLandedCostTable;
|
export default compose(withAlertsActions)(LocatedLandedCostTable);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function ActionsMenu({ row: { original }, payload: { onDelete } }) {
|
|||||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
text={intl.get('delete_transaction')}
|
text={intl.get('delete_transaction')}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
// onClick={safeCallback(onDelete, original)}
|
onClick={safeCallback(onDelete, original)}
|
||||||
/>
|
/>
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
@@ -24,7 +24,7 @@ export function useLocatedLandedCostColumns() {
|
|||||||
return React.useMemo(() => [
|
return React.useMemo(() => [
|
||||||
{
|
{
|
||||||
Header: intl.get('name'),
|
Header: intl.get('name'),
|
||||||
accessor: 'name',
|
accessor: 'description',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,3 +23,4 @@ export * from './exchangeRates';
|
|||||||
export * from './contacts';
|
export * from './contacts';
|
||||||
export * from './subscriptions';
|
export * from './subscriptions';
|
||||||
export * from './organization';
|
export * from './organization';
|
||||||
|
export * from './landedCost';
|
||||||
|
|||||||
86
client/src/hooks/query/landedCost.js
Normal file
86
client/src/hooks/query/landedCost.js
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import { useQueryClient, useMutation } from 'react-query';
|
||||||
|
import useApiRequest from '../useRequest';
|
||||||
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
|
|
||||||
|
import t from './types';
|
||||||
|
|
||||||
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
|
// Invalidate bills.
|
||||||
|
queryClient.invalidateQueries(t.BILLS);
|
||||||
|
queryClient.invalidateQueries(t.BILL);
|
||||||
|
// Invalidate landed cost.
|
||||||
|
queryClient.invalidateQueries(t.LANDED_COST);
|
||||||
|
queryClient.invalidateQueries(t.LANDED_COST_TRANSACTION);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new landed cost.
|
||||||
|
*/
|
||||||
|
export function useCreateLandedCost(props) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useMutation(
|
||||||
|
(id) => apiRequest.post(`purchases/landed-cost/bills/${id}/allocate`),
|
||||||
|
{
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Common invalidate queries.
|
||||||
|
commonInvalidateQueries(queryClient);
|
||||||
|
},
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the given landed cost.
|
||||||
|
*/
|
||||||
|
export function useDeleteLandedCost(props) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
return useMutation(
|
||||||
|
(landedCostId) =>
|
||||||
|
apiRequest.delete(`purchases/landed-cost/${landedCostId}`),
|
||||||
|
{
|
||||||
|
onSuccess: (res, id) => {
|
||||||
|
// Common invalidate queries.
|
||||||
|
commonInvalidateQueries(queryClient);
|
||||||
|
},
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the landed cost transactions.
|
||||||
|
*/
|
||||||
|
export function useLandedCostTransaction(query, props) {
|
||||||
|
return useRequestQuery(
|
||||||
|
[t.LANDED_COST, query],
|
||||||
|
{
|
||||||
|
method: 'get',
|
||||||
|
url: 'purchases/landed-cost/transactions',
|
||||||
|
params: { transaction_type: query },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
select: (res) => res.data.transactions,
|
||||||
|
defaultData: [],
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the bill located landed cost transactions.
|
||||||
|
*/
|
||||||
|
export function useBillLocatedLandedCost(id, props) {
|
||||||
|
return useRequestQuery(
|
||||||
|
[t.LANDED_COST_TRANSACTION, id],
|
||||||
|
{ method: 'get', url: `purchases/landed-cost/bills/${id}/transactions` },
|
||||||
|
{
|
||||||
|
select: (res) => res.data.transactions,
|
||||||
|
defaultData: {},
|
||||||
|
...props,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ const FINANCIAL_REPORTS = {
|
|||||||
PURCHASES_BY_ITEMS: 'PURCHASES_BY_ITEMS',
|
PURCHASES_BY_ITEMS: 'PURCHASES_BY_ITEMS',
|
||||||
INVENTORY_VALUATION: 'INVENTORY_VALUATION',
|
INVENTORY_VALUATION: 'INVENTORY_VALUATION',
|
||||||
CASH_FLOW_STATEMENT: 'CASH_FLOW_STATEMENT',
|
CASH_FLOW_STATEMENT: 'CASH_FLOW_STATEMENT',
|
||||||
INVENTORY_ITEM_DETAILS:'INVENTORY_ITEM_DETAILS'
|
INVENTORY_ITEM_DETAILS: 'INVENTORY_ITEM_DETAILS',
|
||||||
};
|
};
|
||||||
|
|
||||||
const BILLS = {
|
const BILLS = {
|
||||||
@@ -117,6 +117,13 @@ const MANUAL_JOURNALS = {
|
|||||||
MANUAL_JOURNALS: 'MANUAL_JOURNALS',
|
MANUAL_JOURNALS: 'MANUAL_JOURNALS',
|
||||||
MANUAL_JOURNAL: 'MANUAL_JOURNAL',
|
MANUAL_JOURNAL: 'MANUAL_JOURNAL',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const LANDED_COSTS = {
|
||||||
|
LANDED_COST: 'LANDED_COST',
|
||||||
|
LANDED_COSTS: 'LANDED_COSTS',
|
||||||
|
LANDED_COST_TRANSACTION: 'LANDED_COST_TRANSACTION',
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...ACCOUNTS,
|
...ACCOUNTS,
|
||||||
...BILLS,
|
...BILLS,
|
||||||
@@ -137,4 +144,5 @@ export default {
|
|||||||
...SUBSCRIPTIONS,
|
...SUBSCRIPTIONS,
|
||||||
...EXPENSES,
|
...EXPENSES,
|
||||||
...MANUAL_JOURNALS,
|
...MANUAL_JOURNALS,
|
||||||
|
...LANDED_COSTS,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user