From 9f466ba4df8faa166525b30e3965cb24fd320dff Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 14 Feb 2022 09:32:31 +0200 Subject: [PATCH] feat(item): add item warehouse locations. --- .../WarehousesLocations/components.js | 12 +++++++-- .../WarehousesLocations/index.js | 26 ++++++++++++++++--- src/hooks/query/items.js | 15 +++++++++++ src/hooks/query/types.js | 1 + src/lang/ar/index.json | 7 ++++- src/lang/en/index.json | 8 +----- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/components.js b/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/components.js index 0e866a724..6c65f2770 100644 --- a/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/components.js +++ b/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/components.js @@ -1,8 +1,7 @@ import React from 'react'; import intl from 'react-intl-universal'; +import { FormatNumberCell, FormattedMessage as T } from '../../../../components'; -import clsx from 'classnames'; -import { CLASSES } from '../../../../common/classes'; /** * Warehouse locations columns @@ -12,12 +11,21 @@ export const useWarehouseLocationsColumns = () => { () => [ { id: 'warehouse_name', + accessor: 'warehouse_name', Header: intl.get('warehouse_locations.column.warehouse_name'), width: 120, }, + { + id: 'warehouse_code', + accessor: 'warehouse_code', + Header: intl.get('warehouse_locations.column.warehouse_code'), + width: 100, + }, { id: 'quantity', + accessor: 'quantity_on_hand_formatted', Header: intl.get('warehouse_locations.column.quantity'), + Cell: FormatNumberCell, align: 'right', width: 100, }, diff --git a/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/index.js b/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/index.js index 39978b19c..b3f054073 100644 --- a/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/index.js +++ b/src/containers/Drawers/ItemDetailDrawer/WarehousesLocations/index.js @@ -2,10 +2,12 @@ import React from 'react'; import styled from 'styled-components'; import { DataTable, CommercialDocEntriesTable, Card } from 'components'; - -import { useWarehouseLocationsColumns } from './components'; - import { TableStyle } from '../../../../common'; +import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; + +import { useItemDetailDrawerContext } from '../ItemDetailDrawerProvider'; +import { useWarehouseLocationsColumns } from './components'; +import { useItemWarehouseLocation } from 'hooks/query'; /** * Warehouses locations table columns. @@ -14,9 +16,25 @@ export default function WarehouseLocationsTable() { // Warehouses locations table columns. const columns = useWarehouseLocationsColumns(); + const { itemId } = useItemDetailDrawerContext(); + + // Handle fetch Estimate associated transactions. + const { + isLoading: isItemWarehousesLoading, + isFetching: isItemWarehousesFetching, + data: itemWarehouses, + } = useItemWarehouseLocation(itemId, { enabled: !!itemId }); + console.log(itemWarehouses, 'XXX'); return ( - + ); } diff --git a/src/hooks/query/items.js b/src/hooks/query/items.js index 78fc18533..dce969689 100644 --- a/src/hooks/query/items.js +++ b/src/hooks/query/items.js @@ -231,3 +231,18 @@ export function useItemAssociatedBillTransactions(id, props) { }, ); } + +export function useItemWarehouseLocation(id, props) { + return useRequestQuery( + [t.ITEM_WAREHOUSES_LOCATION, id], + { + method: 'get', + url: `items/${id}/warehouses`, + }, + { + select: (res) => res.data.item_warehouses, + defaultData: [], + ...props, + }, + ); +} diff --git a/src/hooks/query/types.js b/src/hooks/query/types.js index 85c9c26f1..46e4bb607 100644 --- a/src/hooks/query/types.js +++ b/src/hooks/query/types.js @@ -53,6 +53,7 @@ const ITEMS = { ITEM_ASSOCIATED_WITH_ESTIMATES: 'ITEM_ASSOCIATED_WITH_ESTIMATES', ITEM_ASSOCIATED_WITH_RECEIPTS: 'ITEM_ASSOCIATED_WITH_RECEIPTS', ITEMS_ASSOCIATED_WITH_BILLS: 'ITEMS_ASSOCIATED_WITH_BILLS', + ITEM_WAREHOUSES_LOCATION: 'ITEM_WAREHOUSES_LOCATION', }; const SALE_ESTIMATES = { diff --git a/src/lang/ar/index.json b/src/lang/ar/index.json index dc9e10edc..fd0a4a941 100644 --- a/src/lang/ar/index.json +++ b/src/lang/ar/index.json @@ -1782,5 +1782,10 @@ "profit_loss_sheet.percentage_of_column": "% التغير العمودي", "profit_loss_sheet.percentage_of_row": "% التغير الأفقي", "profit_loss_sheet.percentage_of_expense": "% التغير في المصاريف", - "profit_loss_sheet.percentage_of_income": "% التغير الإيرادات" + "profit_loss_sheet.percentage_of_income": "% التغير الإيرادات", + "warehouse_locations.label": "Warehouses Locations", + "warehouse_locations.column.warehouse_name": "Warehouse name", + "warehouse_locations.column.quantity": "Quantity", + "warehouse_locations.column.available_for_sale": "Available for sale", + "warehouse_locations.column.warehouse_code": "Warehouse code" } \ No newline at end of file diff --git a/src/lang/en/index.json b/src/lang/en/index.json index ddf72b474..cd209dc94 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1739,7 +1739,6 @@ "global_error.you_dont_have_permissions": "You do not have permissions to access this page.", "global_error.transactions_locked": "Transactions before {lockedToDate} has been locked. Hence action cannot be performed.", "global_error.authorized_user_inactive": "The authorized user is inactive.", - "balance_sheet.comparisons": "Comparisons", "balance_sheet.percentage_of_column": "% of Columns", "balance_sheet.percentage_of_row": "% of Rows", @@ -1756,18 +1755,15 @@ "profit_loss_sheet.percentage_of_row": "% of Row", "profit_loss_sheet.percentage_of_expense": "% of Expense", "profit_loss_sheet.percentage_of_income": "% of Income", - "the_vendor_has_been_inactivated_successfully": "The contact has been inactivated successfully.", "vendor.alert.activated_message": "The vendor has been activated successfully.", "vendor.alert.are_you_sure_want_to_inactivate_this_vendor": "Are you sure want to inactivate this vendor? You will to able to activate it later.", "vendor.alert.inactivated_message": "The vendor has been inactivated successfully.", "vendor.alert.are_you_sure_want_to_activate_this_vendor": "Are you sure want to activate this vendor? You will to able to inactivate it later.", - "customer.alert.activated_message": "The customer has been activated successfully.", "customer.alert.are_you_sure_want_to_activate_this_customer": "Are you sure want to activate this customer? You will to able to inactivate it later.", "customer.alert.inactivated_message": "The customer has been inactivated successfully.", "customer.alert.are_you_sure_want_to_inactivate_this_customer": "Are you sure want to inactivate this customer? You will to able to activate it later.", - "credit_note_preview.dialog.title": "Credit Note PDF Preview", "payment_receive_preview.dialog.title": "Payment Receive PDF Preview", "warehouses.label": "Warehouses", @@ -1789,12 +1785,12 @@ "warehouse_locations.column.warehouse_name": "Warehouse name", "warehouse_locations.column.quantity": "Quantity", "warehouse_locations.column.available_for_sale": "Available for sale", + "warehouse_locations.column.warehouse_code": "Warehouse code", "warehouses.action.edit_warehouse": "Edit Warehouse", "warehouses.action.delete_warehouse": "Delete Warehouse", "warehouses.action.make_as_parimary": "Mark as Primary", "warehouse.alert.delete_message": "The warehouse has been deleted successfully", "warehouse.once_delete_this_warehouse": "Once you delete this warehouse, you won't be able to restore it later. Are you sure you want to delete this warehouse?", - "sidebar_warehouse_transfer": "Warehouse Transfers", "warehouse_transfer.label.transfer_no": "Transfer No", "warehouse_transfer.label.form_warehouse": "Form Warehouse", @@ -1824,7 +1820,6 @@ "warehouse_transfer.alert.delete_message": "The warehouse transfer transaction has been deleted successfully", "warehouse_transfer.once_delete_this_warehouse_transfer": "Once you delete this warehouse transfer, you won't be able to restore it later. Are you sure you want to delete this warehouse transfer?", "warehouse_transfer.error.could_not_transfer_item_from_source_to_destination": "Could not transfer item from source to destination on the same warehouse", - "branches.label": "Branches", "branches.label.new_branch": "New Branch", "branches.action.edit_branch": "Edit Branch", @@ -1852,7 +1847,6 @@ "unrealized_gain_or_loss.label": "Unrealized Gain or Loss", "branch_activate.dialog_success_message": "Multi-branches feature has been activated successfully.", "branch.alert.mark_primary_message": "The branch has been marked as primary.", - "branch.alert.are_you_sure_you_want_to_make": "Are you sure you want to make a primary branch?", "warehouse_activate.dialog_success_message": "Multi-branches feature has been activated successfully.", "warehouse.alert.mark_primary_message": "The given warehouse has been marked as primary.",