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 1/4] 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 2/4] 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 3/4] 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 4/4] 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",