From 5e2000d252e55a570da2d356ee9b0c4309cef8ec Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 24 Mar 2022 11:50:06 +0200 Subject: [PATCH 01/28] feat: add invalidate item warehouses. --- src/hooks/query/bills.js | 3 +++ src/hooks/query/invoices.js | 3 +++ src/hooks/query/receipts.js | 3 +++ src/hooks/query/warehouses.js | 1 - 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hooks/query/bills.js b/src/hooks/query/bills.js index 24806a3b6..e4421761d 100644 --- a/src/hooks/query/bills.js +++ b/src/hooks/query/bills.js @@ -33,6 +33,9 @@ const commonInvalidateQueries = (queryClient) => { // Invalidate items associated bills transactions. queryClient.invalidateQueries(t.ITEMS_ASSOCIATED_WITH_BILLS); + + // Invalidate item warehouses. + queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION); }; /** diff --git a/src/hooks/query/invoices.js b/src/hooks/query/invoices.js index 39513148b..ef6679313 100644 --- a/src/hooks/query/invoices.js +++ b/src/hooks/query/invoices.js @@ -34,6 +34,9 @@ const commonInvalidateQueries = (queryClient) => { // Invalidate queryClient.invalidateQueries(t.ITEM_ASSOCIATED_WITH_INVOICES); + + // Invalidate item warehouses. + queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION); }; /** diff --git a/src/hooks/query/receipts.js b/src/hooks/query/receipts.js index c2cbeaa22..725e9fecb 100644 --- a/src/hooks/query/receipts.js +++ b/src/hooks/query/receipts.js @@ -27,6 +27,9 @@ const commonInvalidateQueries = (queryClient) => { // Invalidate queryClient.invalidateQueries(t.ITEM_ASSOCIATED_WITH_RECEIPTS); + // Invalidate item warehouses. + queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION); + // Invalidate the settings. queryClient.invalidateQueries([t.SETTING, t.SETTING_RECEIPTS]); }; diff --git a/src/hooks/query/warehouses.js b/src/hooks/query/warehouses.js index acea73d4a..703a66687 100644 --- a/src/hooks/query/warehouses.js +++ b/src/hooks/query/warehouses.js @@ -12,7 +12,6 @@ const commonInvalidateQueries = (queryClient) => { // Invalidate warehouses transfers. queryClient.invalidateQueries(t.WAREHOUSE_TRANSFERS); - // queryClient.invalidateQueries(t.WAREHOUSE_TRANSFER); queryClient.invalidateQueries(t.DASHBOARD_META); }; From 99a23889bcf30e52af9a43631d32166cd0062584 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 24 Mar 2022 12:19:46 +0200 Subject: [PATCH 02/28] feat: add warehouses transfers query. --- src/hooks/query/warehouses.js | 158 ----------------------- src/hooks/query/warehousesTransfers.js | 172 +++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 158 deletions(-) create mode 100644 src/hooks/query/warehousesTransfers.js diff --git a/src/hooks/query/warehouses.js b/src/hooks/query/warehouses.js index 703a66687..b2cd0eaea 100644 --- a/src/hooks/query/warehouses.js +++ b/src/hooks/query/warehouses.js @@ -104,164 +104,6 @@ export function useWarehouse(id, props, requestProps) { ); } -/** - * Create a new warehouse transfer. - */ -export function useCreateWarehouseTransfer(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (values) => apiRequest.post('warehouses/transfers', values), - { - onSuccess: (res, values) => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Edits the given warehouse transfer. - */ -export function useEditWarehouseTransfer(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - ([id, values]) => apiRequest.post(`warehouses/transfers/${id}`, values), - { - onSuccess: (res, [id, values]) => { - // Invalidate specific sale invoice. - queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); - - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * Deletes the given warehouse Transfer. - */ -export function useDeleteWarehouseTransfer(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation((id) => apiRequest.delete(`warehouses/transfers/${id}`), { - onSuccess: (res, id) => { - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }); -} - -const transformWarehousesTransfer = (res) => ({ - warehousesTransfers: res.data.data, - pagination: transformPagination(res.data.pagination), - filterMeta: res.data.filter, -}); - -/** - * Retrieve Warehoues list. - */ -export function useWarehousesTransfers(query, props) { - return useRequestQuery( - [t.WAREHOUSE_TRANSFERS, query], - { method: 'get', url: 'warehouses/transfers', params: query }, - { - select: transformWarehousesTransfer, - defaultData: { - warehousesTransfers: [], - pagination: { - page: 1, - pageSize: 20, - total: 0, - }, - filterMeta: {}, - }, - ...props, - }, - ); -} - -/** - * Retrieve the warehouse transfer details. - * @param {number} - */ -export function useWarehouseTransfer(id, props, requestProps) { - return useRequestQuery( - [t.WAREHOUSE_TRANSFER, id], - { method: 'get', url: `warehouses/transfers/${id}`, ...requestProps }, - { - select: (res) => res.data.data, - defaultData: {}, - ...props, - }, - ); -} - -/** - * - * @param {*} props - * @returns - */ -export function useInitiateWarehouseTransfer(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (id) => apiRequest.put(`warehouses/transfers/${id}/initiate`), - { - onSuccess: (res, id) => { - queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); - - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -/** - * - * @param {*} props - * @returns - */ -export function useTransferredWarehouseTransfer(props) { - const queryClient = useQueryClient(); - const apiRequest = useApiRequest(); - - return useMutation( - (id) => apiRequest.put(`warehouses/transfers/${id}/transferred`), - { - onSuccess: (res, id) => { - queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); - - // Common invalidate queries. - commonInvalidateQueries(queryClient); - }, - ...props, - }, - ); -} - -export function useRefreshWarehouseTransfers() { - const queryClient = useQueryClient(); - - return { - refresh: () => { - queryClient.invalidateQueries(t.WAREHOUSE_TRANSFERS); - }, - }; -} - /** * Activate the given warehouse. */ diff --git a/src/hooks/query/warehousesTransfers.js b/src/hooks/query/warehousesTransfers.js new file mode 100644 index 000000000..414201183 --- /dev/null +++ b/src/hooks/query/warehousesTransfers.js @@ -0,0 +1,172 @@ +import { useQueryClient, useMutation } from 'react-query'; +import { transformPagination } from 'utils'; +import { useRequestQuery } from '../useQueryRequest'; +import useApiRequest from '../useRequest'; +import t from './types'; + +// Common invalidate queries. +const commonInvalidateQueries = (queryClient) => { + // Invalidate warehouses transfers. + queryClient.invalidateQueries(t.WAREHOUSE_TRANSFERS); + + // Invalidate item warehouses. + queryClient.invalidateQueries(t.ITEM_WAREHOUSES_LOCATION); +}; + +/** + * Create a new warehouse transfer. + */ +export function useCreateWarehouseTransfer(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + (values) => apiRequest.post('warehouses/transfers', values), + { + onSuccess: (res, values) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * Edits the given warehouse transfer. + */ +export function useEditWarehouseTransfer(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + ([id, values]) => apiRequest.post(`warehouses/transfers/${id}`, values), + { + onSuccess: (res, [id, values]) => { + // Invalidate specific sale invoice. + queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); + + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * Deletes the given warehouse Transfer. + */ +export function useDeleteWarehouseTransfer(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation((id) => apiRequest.delete(`warehouses/transfers/${id}`), { + onSuccess: (res, id) => { + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }); +} + +const transformWarehousesTransfer = (res) => ({ + warehousesTransfers: res.data.data, + pagination: transformPagination(res.data.pagination), + filterMeta: res.data.filter, +}); + +/** + * Retrieve Warehoues list. + */ +export function useWarehousesTransfers(query, props) { + return useRequestQuery( + [t.WAREHOUSE_TRANSFERS, query], + { method: 'get', url: 'warehouses/transfers', params: query }, + { + select: transformWarehousesTransfer, + defaultData: { + warehousesTransfers: [], + pagination: { + page: 1, + pageSize: 20, + total: 0, + }, + filterMeta: {}, + }, + ...props, + }, + ); +} + +/** + * Retrieve the warehouse transfer details. + * @param {number} + */ +export function useWarehouseTransfer(id, props, requestProps) { + return useRequestQuery( + [t.WAREHOUSE_TRANSFER, id], + { method: 'get', url: `warehouses/transfers/${id}`, ...requestProps }, + { + select: (res) => res.data.data, + defaultData: {}, + ...props, + }, + ); +} + +/** + * + * @param {*} props + * @returns + */ +export function useInitiateWarehouseTransfer(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + (id) => apiRequest.put(`warehouses/transfers/${id}/initiate`), + { + onSuccess: (res, id) => { + queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); + + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +/** + * + * @param {*} props + * @returns + */ +export function useTransferredWarehouseTransfer(props) { + const queryClient = useQueryClient(); + const apiRequest = useApiRequest(); + + return useMutation( + (id) => apiRequest.put(`warehouses/transfers/${id}/transferred`), + { + onSuccess: (res, id) => { + queryClient.invalidateQueries([t.WAREHOUSE_TRANSFER, id]); + + // Common invalidate queries. + commonInvalidateQueries(queryClient); + }, + ...props, + }, + ); +} + +export function useRefreshWarehouseTransfers() { + const queryClient = useQueryClient(); + + return { + refresh: () => { + queryClient.invalidateQueries(t.WAREHOUSE_TRANSFERS); + }, + }; +} From 8404fee10a7bc8a701bd407e5567e7dfa58da78c Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 24 Mar 2022 13:12:14 +0200 Subject: [PATCH 03/28] dump v1.7.0-rc.1 --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03f5da752..ab70adcb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ All notable changes to Bigcapital server-side will be in this file. +## [1.7.0-rc.1] - 24-03-2022 + +## Added + - Multiply currencies with foreign currencies. + - Multiply warehouses to track inventory items. + - Multiply branches to track organization transactions. + - Transfer orders between warehouses. + - Integrate financial reports with multiply branches. + - Integrate inventory reports with multiply warehouses. + +## Changes + - Optimize style of sale invoice form. + - Optimize style of sale receipt form. + - Optimize style of credit note form. + - Optimize style of payment receive form. + - Optimize style of bill form. + - Optimize style of payment made form. + - Optimize style of manual journal form. + - Optimize style of expense form. + ## [1.6.3] - 21-02-2022 ### Fixed From 86cab7988c6cfba4586d80f55ef036edb1f69db2 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 24 Mar 2022 15:03:25 +0200 Subject: [PATCH 04/28] feat: handle item error. --- src/containers/Items/utils.js | 8 ++++++++ src/lang/ar/index.json | 6 ++---- src/lang/en/index.json | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/containers/Items/utils.js b/src/containers/Items/utils.js index 406746786..8031e56ea 100644 --- a/src/containers/Items/utils.js +++ b/src/containers/Items/utils.js @@ -104,6 +104,14 @@ export const handleDeleteErrors = (errors) => { intent: Intent.DANGER, }); } + if ( + errors.find((error) => error.type === 'ITEM_HAS_ASSOCIATED_TRANSACTIONS') + ) { + AppToaster.show({ + message: intl.get('item.error.you_could_not_delete_item_has_associated'), + intent: Intent.DANGER, + }); + } }; /** diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index 3accd9b2f..880af1586 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1795,13 +1795,10 @@ "profit_loss_sheet.percentage_of_row": "% التغير الأفقي", "profit_loss_sheet.percentage_of_expense": "% التغير في المصاريف", "profit_loss_sheet.percentage_of_income": "% التغير الإيرادات", - "report.balance_sheet_comparison.title": "مقارنة الميزانية العمومية", "report.balance_sheet_comparison.desc": "يعرض أصول الشركة والتزاماتها وحقوق المساهمين في نقطة زمنية محددة مقارنة بالسنة الماضية.", - "report.profit_loss_sheet_comparison.title": "مقارنة قائمة الدخل", "report.profit_loss_sheet_comparison.desc": "يعرض الإيرادات والتكاليف والمصاريف المتكبدة في نقطة محددة ومقارنة بالعام السابق.", - "warehouse_locations.label": "المخازن", "warehouse_locations.column.warehouse_name": "اسم المخزن", "warehouse_locations.column.quantity": "الكمية", @@ -2007,5 +2004,6 @@ "receipt.branch_button.label": "الفرع: {label}", "receipt.warehouse_button.label": "المخزن: {label}", "warehouse_transfer.empty_status.title": "", - "warehouse_transfer.empty_status.description": "" + "warehouse_transfer.empty_status.description": "", + "item.error.you_could_not_delete_item_has_associated": "لا يمكنك حذف العنصر لديه معاملات مرتبطة به " } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 41d4ebc9e..fd2ad8d65 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1440,6 +1440,7 @@ "AP_aging_summary.filter_options.label": "Filter vendors", "item.error.type_cannot_change_with_item_has_transactions": "Cannot change item type to inventory with item has associated transactions.", "item.error.cannot_change_inventory_account": "Cannot change item inventory account while the item has transactions.", + "item.error.you_could_not_delete_item_has_associated":"You could not delete item that has associated transactions", "customer.link.customer_details": "Customer details ({amount})", "bad_debt.dialog.written_off_amount": "Written-off amount", "bad_debt.dialog.bad_debt": "Bad debt", From 6a8137729ff7ef2fc53776a6ec9b160fef39a6fb Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Mon, 28 Mar 2022 12:01:29 +0200 Subject: [PATCH 05/28] fix(Account): `BIG-296` Issue when creating a new child account from chart of accounts list. --- src/common/index.js | 1 + src/containers/Accounts/AccountsDataTable.js | 9 +++-- .../CashFlowAccountsActionsBar.js | 11 +++--- .../AccountDialog/AccountDialogContent.js | 16 ++------- .../AccountDialog/AccountDialogForm.js | 13 ++----- .../AccountDialog/AccountDialogFormContent.js | 11 +++--- .../AccountDialog/AccountDialogProvider.js | 36 ++++++++++--------- src/containers/Dialogs/AccountDialog/index.js | 20 ++++------- src/containers/Dialogs/AccountDialog/utils.js | 36 +++++++++++++++---- .../AccountDrawer/AccountDrawerActionBar.js | 17 ++++----- src/lang/ar/index.json | 4 +-- 11 files changed, 90 insertions(+), 84 deletions(-) diff --git a/src/common/index.js b/src/common/index.js index ffd40825e..c2922a515 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -1,3 +1,4 @@ +export * from './accountTypes'; export * from './TableStyle'; export * from './features'; export * from './cellTypes'; diff --git a/src/containers/Accounts/AccountsDataTable.js b/src/containers/Accounts/AccountsDataTable.js index 8d12404ee..ab45025eb 100644 --- a/src/containers/Accounts/AccountsDataTable.js +++ b/src/containers/Accounts/AccountsDataTable.js @@ -15,6 +15,8 @@ import withSettings from '../Settings/withSettings'; import { useAccountsChartContext } from './AccountsChartProvider'; import { useMemorizedColumnsWidths } from '../../hooks'; +import { AccountDialogAction } from '../Dialogs/AccountDialog/utils'; + import withAlertsActions from 'containers/Alert/withAlertActions'; import withDialogActions from 'containers/Dialog/withDialogActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; @@ -58,7 +60,10 @@ function AccountsDataTable({ // Handle edit account action. const handleEditAccount = (account) => { - openDialog('account-form', { action: 'edit', id: account.id }); + openDialog('account-form', { + action: AccountDialogAction.Edit, + id: account.id, + }); }; // Handle view detail account. @@ -69,7 +74,7 @@ function AccountsDataTable({ // Handle new child button click. const handleNewChildAccount = (account) => { openDialog('account-form', { - action: 'new_child', + action: AccountDialogAction.NewChild, parentAccountId: account.id, accountType: account.account_type, }); diff --git a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js index f21b9f463..f4947ee68 100644 --- a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js +++ b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js @@ -16,6 +16,9 @@ import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; import withDialogActions from 'containers/Dialog/withDialogActions'; import withCashflowAccountsTableActions from '../AccountTransactions/withCashflowAccountsTableActions'; +import { AccountDialogAction } from '../../Dialogs/AccountDialog/utils'; +import { ACCOUNT_TYPE } from '../../../common'; + import { compose } from 'utils'; /** @@ -37,15 +40,15 @@ function CashFlowAccountsActionsBar({ // Handle add bank account. const handleAddBankAccount = () => { openDialog('account-form', { - action: 'NEW_ACCOUNT_DEFINED_TYPE', - accountType: 'cash', + action: AccountDialogAction.NewDefinedType, + accountType: ACCOUNT_TYPE.CASH, }); }; // Handle add cash account. const handleAddCashAccount = () => { openDialog('account-form', { - action: 'NEW_ACCOUNT_DEFINED_TYPE', - accountType: 'bank', + action: AccountDialogAction.NewDefinedType, + accountType: ACCOUNT_TYPE.BANK, }); }; // Handle inactive switch changing. diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogContent.js b/src/containers/Dialogs/AccountDialog/AccountDialogContent.js index 2c9856cba..cf373474e 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogContent.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogContent.js @@ -5,21 +5,9 @@ import AccountDialogForm from './AccountDialogForm'; /** * Account dialog content. */ -export default function AccountDialogContent({ - dialogName, - accountId, - action, - parentAccountId, - accountType, -}) { +export default function AccountDialogContent({ dialogName, payload }) { return ( - + ); diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogForm.js b/src/containers/Dialogs/AccountDialog/AccountDialogForm.js index 809ae6ea6..30c9e210f 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogForm.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogForm.js @@ -43,9 +43,7 @@ function AccountFormDialogContent({ account, accountId, - action, - parentAccountId, - accountType, + payload, isNewMode, dialogName, } = useAccountDialogContext(); @@ -101,7 +99,6 @@ function AccountFormDialogContent({ .catch(handleError); } }; - // Form initial values in create and edit mode. const initialValues = { ...defaultInitialValues, @@ -111,11 +108,7 @@ function AccountFormDialogContent({ * as well. */ ...transformToForm( - transformAccountToForm(account, { - action, - parentAccountId, - accountType, - }), + transformAccountToForm(account, payload), defaultInitialValues, ), }; @@ -133,7 +126,7 @@ function AccountFormDialogContent({ > diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js b/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js index 2350b0f4e..4de48166e 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js @@ -39,7 +39,8 @@ function AccountFormDialogFields({ const accountNameFieldRef = useAutofocus(); // Account form context. - const { accounts, accountsTypes, currencies } = useAccountDialogContext(); + const { fieldsDisabled, accounts, accountsTypes, currencies } = + useAccountDialogContext(); return (
@@ -62,11 +63,7 @@ function AccountFormDialogFields({ form.setFieldValue('account_type', accountType.key); form.setFieldValue('currency_code', ''); }} - disabled={ - action === 'edit' || - action === 'new_child' || - action === 'NEW_ACCOUNT_DEFINED_TYPE' - } + disabled={fieldsDisabled.accountType} popoverProps={{ minimal: true }} popoverFill={true} /> @@ -209,7 +206,7 @@ function AccountFormDialogFields({