From 322ff0671ff9419c583c009c19436a9445c0fda6 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 13 Apr 2025 07:21:58 +0000 Subject: [PATCH] Edit shipment table --- .gitignore | 5 + backend/src/db/api/shipments.js | 16 ++ backend/src/db/migrations/1744527865779.js | 49 ++++ backend/src/db/models/shipments.js | 4 + .../db/seeders/20231127130745-sample-data.js | 272 +++++------------- backend/src/routes/shipments.js | 4 + backend/src/services/search.js | 2 + .../src/components/Products/CardProducts.tsx | 2 +- .../components/Shipments/CardShipments.tsx | 11 + .../components/Shipments/ListShipments.tsx | 5 + .../Shipments/configureShipmentsCols.tsx | 244 +++++----------- frontend/src/menuAside.ts | 65 ++--- frontend/src/pages/quotes/quotes-view.tsx | 4 + .../src/pages/shipments/[shipmentsId].tsx | 6 + .../src/pages/shipments/shipments-edit.tsx | 6 + .../src/pages/shipments/shipments-list.tsx | 1 + .../src/pages/shipments/shipments-new.tsx | 6 + .../src/pages/shipments/shipments-table.tsx | 1 + .../src/pages/shipments/shipments-view.tsx | 5 + 19 files changed, 288 insertions(+), 420 deletions(-) create mode 100644 backend/src/db/migrations/1744527865779.js diff --git a/.gitignore b/.gitignore index e427ff3..d0eb167 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ node_modules/ */node_modules/ */build/ + +**/node_modules/ +**/build/ +.DS_Store +.env \ No newline at end of file diff --git a/backend/src/db/api/shipments.js b/backend/src/db/api/shipments.js index e14bcb7..b5197b7 100644 --- a/backend/src/db/api/shipments.js +++ b/backend/src/db/api/shipments.js @@ -24,6 +24,7 @@ module.exports = class ShipmentsDBApi { state: data.state || null, customerCharge: data.customerCharge || null, actualCharge: data.actualCharge || null, + businessname: data.businessname || null, importHash: data.importHash || null, createdById: currentUser.id, updatedById: currentUser.id, @@ -59,6 +60,7 @@ module.exports = class ShipmentsDBApi { state: item.state || null, customerCharge: item.customerCharge || null, actualCharge: item.actualCharge || null, + businessname: item.businessname || null, importHash: item.importHash || null, createdById: currentUser.id, updatedById: currentUser.id, @@ -104,6 +106,9 @@ module.exports = class ShipmentsDBApi { if (data.actualCharge !== undefined) updatePayload.actualCharge = data.actualCharge; + if (data.businessname !== undefined) + updatePayload.businessname = data.businessname; + updatePayload.updatedById = currentUser.id; await shipments.update(updatePayload, { transaction }); @@ -299,6 +304,17 @@ module.exports = class ShipmentsDBApi { }; } + if (filter.businessname) { + where = { + ...where, + [Op.and]: Utils.ilike( + 'shipments', + 'businessname', + filter.businessname, + ), + }; + } + if (filter.customerChargeRange) { const [start, end] = filter.customerChargeRange; diff --git a/backend/src/db/migrations/1744527865779.js b/backend/src/db/migrations/1744527865779.js new file mode 100644 index 0000000..0994445 --- /dev/null +++ b/backend/src/db/migrations/1744527865779.js @@ -0,0 +1,49 @@ +module.exports = { + /** + * @param {QueryInterface} queryInterface + * @param {Sequelize} Sequelize + * @returns {Promise} + */ + async up(queryInterface, Sequelize) { + /** + * @type {Transaction} + */ + const transaction = await queryInterface.sequelize.transaction(); + try { + await queryInterface.addColumn( + 'shipments', + 'businessname', + { + type: Sequelize.DataTypes.TEXT, + }, + { transaction }, + ); + + await transaction.commit(); + } catch (err) { + await transaction.rollback(); + throw err; + } + }, + /** + * @param {QueryInterface} queryInterface + * @param {Sequelize} Sequelize + * @returns {Promise} + */ + async down(queryInterface, Sequelize) { + /** + * @type {Transaction} + */ + const transaction = await queryInterface.sequelize.transaction(); + try { + await queryInterface.removeColumn('shipments', 'businessname', { + transaction, + }); + + await transaction.commit(); + } catch (err) { + await transaction.rollback(); + throw err; + } + }, +}; diff --git a/backend/src/db/models/shipments.js b/backend/src/db/models/shipments.js index 112e8dd..8c7f6f1 100644 --- a/backend/src/db/models/shipments.js +++ b/backend/src/db/models/shipments.js @@ -50,6 +50,10 @@ module.exports = function (sequelize, DataTypes) { type: DataTypes.DECIMAL, }, + businessname: { + type: DataTypes.TEXT, + }, + importHash: { type: DataTypes.STRING(255), allowNull: true, diff --git a/backend/src/db/seeders/20231127130745-sample-data.js b/backend/src/db/seeders/20231127130745-sample-data.js index d6f776a..d878c8b 100644 --- a/backend/src/db/seeders/20231127130745-sample-data.js +++ b/backend/src/db/seeders/20231127130745-sample-data.js @@ -9,7 +9,7 @@ const Shipments = db.shipments; const ProductsData = [ { - productName: 'Andreas Vesalius', + productName: 'John Dalton', // type code here for "images" field @@ -23,7 +23,7 @@ const ProductsData = [ }, { - productName: 'Thomas Hunt Morgan', + productName: 'Edward Teller', // type code here for "images" field @@ -37,7 +37,7 @@ const ProductsData = [ }, { - productName: 'Willard Libby', + productName: 'Richard Feynman', // type code here for "images" field @@ -49,73 +49,29 @@ const ProductsData = [ height: 5, }, - - { - productName: 'Theodosius Dobzhansky', - - // type code here for "images" field - - weight: 4, - - length: 25, - - width: 12, - - height: 6, - }, - - { - productName: 'Gertrude Belle Elion', - - // type code here for "images" field - - weight: 5, - - length: 30, - - width: 15, - - height: 8, - }, ]; const QuotesData = [ { - carrierName: 'Rudolf Virchow', + carrierName: 'Paul Dirac', - quotePrice: 51.15, + quotePrice: 78.38, // type code here for "relation_one" field }, { - carrierName: 'Tycho Brahe', + carrierName: 'Paul Ehrlich', - quotePrice: 62.23, + quotePrice: 99.12, // type code here for "relation_one" field }, { - carrierName: 'Karl Landsteiner', + carrierName: 'Michael Faraday', - quotePrice: 48.62, - - // type code here for "relation_one" field - }, - - { - carrierName: 'Jean Baptiste Lamarck', - - quotePrice: 52.37, - - // type code here for "relation_one" field - }, - - { - carrierName: 'Sheldon Glashow', - - quotePrice: 43.24, + quotePrice: 93.69, // type code here for "relation_one" field }, @@ -123,123 +79,81 @@ const QuotesData = [ const ShipmentsData = [ { - customer: 'Alfred Wegener', + customer: 'Edward Teller', - phoneNumber: 'Charles Sherrington', + phoneNumber: 'Emil Kraepelin', - address: 'Heike Kamerlingh Onnes', - - address2: 'Konrad Lorenz', - - zipCode: 'Frederick Gowland Hopkins', - - city: 'Nicolaus Copernicus', - - state: 'Edward O. Wilson', - - // type code here for "relation_many" field - - // type code here for "relation_one" field - - customerCharge: 30.03, - - actualCharge: 95.91, - }, - - { - customer: 'Hermann von Helmholtz', - - phoneNumber: 'Justus Liebig', - - address: 'Marie Curie', - - address2: 'Alfred Wegener', - - zipCode: 'Hans Bethe', - - city: 'Enrico Fermi', - - state: 'Sigmund Freud', - - // type code here for "relation_many" field - - // type code here for "relation_one" field - - customerCharge: 53.43, - - actualCharge: 58.21, - }, - - { - customer: 'B. F. Skinner', - - phoneNumber: 'Gregor Mendel', - - address: 'Carl Gauss (Karl Friedrich Gauss)', - - address2: 'Alfred Wegener', - - zipCode: 'Frederick Sanger', - - city: 'Galileo Galilei', - - state: 'James Watson', - - // type code here for "relation_many" field - - // type code here for "relation_one" field - - customerCharge: 13.46, - - actualCharge: 92.16, - }, - - { - customer: 'Ernest Rutherford', - - phoneNumber: 'Carl Gauss (Karl Friedrich Gauss)', - - address: 'John von Neumann', - - address2: 'Jonas Salk', - - zipCode: 'Leonard Euler', - - city: 'Claude Levi-Strauss', - - state: 'Pierre Simon de Laplace', - - // type code here for "relation_many" field - - // type code here for "relation_one" field - - customerCharge: 35.87, - - actualCharge: 33.48, - }, - - { - customer: 'Arthur Eddington', - - phoneNumber: 'J. Robert Oppenheimer', - - address: 'Francis Crick', + address: 'Frederick Sanger', address2: 'Anton van Leeuwenhoek', - zipCode: 'George Gaylord Simpson', + zipCode: 'Ernst Mayr', - city: 'Claude Levi-Strauss', + city: 'Stephen Hawking', - state: 'Nicolaus Copernicus', + state: 'Max Born', // type code here for "relation_many" field // type code here for "relation_one" field - customerCharge: 57.76, + customerCharge: 71.54, - actualCharge: 52.63, + actualCharge: 83.68, + + businessname: 'Willard Libby', + }, + + { + customer: 'Rudolf Virchow', + + phoneNumber: 'Comte de Buffon', + + address: 'Hans Bethe', + + address2: 'Edward Teller', + + zipCode: 'Willard Libby', + + city: 'Ernst Mayr', + + state: 'Joseph J. Thomson', + + // type code here for "relation_many" field + + // type code here for "relation_one" field + + customerCharge: 38.34, + + actualCharge: 45.04, + + businessname: 'Frederick Sanger', + }, + + { + customer: 'James Clerk Maxwell', + + phoneNumber: 'Charles Sherrington', + + address: 'Trofim Lysenko', + + address2: 'Werner Heisenberg', + + zipCode: 'Charles Darwin', + + city: 'Joseph J. Thomson', + + state: 'Carl Gauss (Karl Friedrich Gauss)', + + // type code here for "relation_many" field + + // type code here for "relation_one" field + + customerCharge: 43.34, + + actualCharge: 10.66, + + businessname: 'James Clerk Maxwell', }, ]; @@ -278,28 +192,6 @@ async function associateQuoteWithShipment() { if (Quote2?.setShipment) { await Quote2.setShipment(relatedShipment2); } - - const relatedShipment3 = await Shipments.findOne({ - offset: Math.floor(Math.random() * (await Shipments.count())), - }); - const Quote3 = await Quotes.findOne({ - order: [['id', 'ASC']], - offset: 3, - }); - if (Quote3?.setShipment) { - await Quote3.setShipment(relatedShipment3); - } - - const relatedShipment4 = await Shipments.findOne({ - offset: Math.floor(Math.random() * (await Shipments.count())), - }); - const Quote4 = await Quotes.findOne({ - order: [['id', 'ASC']], - offset: 4, - }); - if (Quote4?.setShipment) { - await Quote4.setShipment(relatedShipment4); - } } // Similar logic for "relation_many" @@ -337,28 +229,6 @@ async function associateShipmentWithQuote() { if (Shipment2?.setQuote) { await Shipment2.setQuote(relatedQuote2); } - - const relatedQuote3 = await Quotes.findOne({ - offset: Math.floor(Math.random() * (await Quotes.count())), - }); - const Shipment3 = await Shipments.findOne({ - order: [['id', 'ASC']], - offset: 3, - }); - if (Shipment3?.setQuote) { - await Shipment3.setQuote(relatedQuote3); - } - - const relatedQuote4 = await Quotes.findOne({ - offset: Math.floor(Math.random() * (await Quotes.count())), - }); - const Shipment4 = await Shipments.findOne({ - order: [['id', 'ASC']], - offset: 4, - }); - if (Shipment4?.setQuote) { - await Shipment4.setQuote(relatedQuote4); - } } module.exports = { diff --git a/backend/src/routes/shipments.js b/backend/src/routes/shipments.js index 5c8fdea..0db56b1 100644 --- a/backend/src/routes/shipments.js +++ b/backend/src/routes/shipments.js @@ -41,6 +41,9 @@ router.use(checkCrudPermissions('shipments')); * state: * type: string * default: state + * businessname: + * type: string + * default: businessname * customerCharge: * type: integer @@ -338,6 +341,7 @@ router.get( 'zipCode', 'city', 'state', + 'businessname', 'customerCharge', 'actualCharge', diff --git a/backend/src/services/search.js b/backend/src/services/search.js index dda4049..f4648cc 100644 --- a/backend/src/services/search.js +++ b/backend/src/services/search.js @@ -61,6 +61,8 @@ module.exports = class SearchService { 'city', 'state', + + 'businessname', ], }; const columnsInt = { diff --git a/frontend/src/components/Products/CardProducts.tsx b/frontend/src/components/Products/CardProducts.tsx index 1a843a7..383597f 100644 --- a/frontend/src/components/Products/CardProducts.tsx +++ b/frontend/src/components/Products/CardProducts.tsx @@ -59,7 +59,7 @@ const CardProducts = ({ className={`flex items-center ${bgColor} p-6 md:p-0 md:block gap-x-4 border-b border-gray-900/5 bg-gray-50 dark:bg-dark-800 relative`} > + +
+
+ Businessname +
+
+
+ {item.businessname} +
+
+
))} diff --git a/frontend/src/components/Shipments/ListShipments.tsx b/frontend/src/components/Shipments/ListShipments.tsx index 684633b..cfe4c87 100644 --- a/frontend/src/components/Shipments/ListShipments.tsx +++ b/frontend/src/components/Shipments/ListShipments.tsx @@ -119,6 +119,11 @@ const ListShipments = ({

Actual Charge

{item.actualCharge}

+ +
+

Businessname

+

{item.businessname}

+
- dataFormatter.productsManyListFormatter(value).join(', '), - renderEditCell: (params) => ( - - ), - }, - - { - field: 'quote', - headerName: 'Quote', - flex: 1, - minWidth: 120, - filterable: false, - headerClassName: 'datagrid--header', - cellClassName: 'datagrid--cell', - - editable: hasUpdatePermission, - - sortable: false, - type: 'singleSelect', - getOptionValue: (value: any) => value?.id, - getOptionLabel: (value: any) => value?.label, - valueOptions: await callOptionsApi('quotes'), - valueGetter: (params: GridValueGetterParams) => - params?.value?.id ?? params?.value, - }, - - { - field: 'customerCharge', - headerName: 'Customer Charge', - flex: 1, - minWidth: 120, - filterable: false, - headerClassName: 'datagrid--header', - cellClassName: 'datagrid--cell', - - editable: hasUpdatePermission, - - type: 'number', - }, - - { - field: 'actualCharge', - headerName: 'Actual Charge', - flex: 1, - minWidth: 120, - filterable: false, - headerClassName: 'datagrid--header', - cellClassName: 'datagrid--cell', - - editable: hasUpdatePermission, - - type: 'number', - }, - - { - field: 'actions', - type: 'actions', - minWidth: 30, - headerClassName: 'datagrid--header', - cellClassName: 'datagrid--cell', - getActions: (params: GridRowParams) => { - return [ - , - ]; + return [ + { + field: 'businessname', + headerName: 'Business Name', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, }, - }, - ]; + { + field: 'customer', + headerName: 'Customer', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + }, + { + field: 'address', + headerName: 'Address', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + }, + { + field: 'state', + headerName: 'State', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + }, + { + field: 'zipCode', + headerName: 'Zip Code', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + }, + { + field: 'customerCharge', + headerName: 'Customer Charge', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + type: 'number', + }, + { + field: 'actualCharge', + headerName: 'Actual Charge', + flex: 1, + minWidth: 120, + filterable: false, + headerClassName: 'datagrid--header', + cellClassName: 'datagrid--cell', + editable: hasUpdatePermission, + type: 'number', + }, + ]; }; diff --git a/frontend/src/menuAside.ts b/frontend/src/menuAside.ts index 228929a..b839683 100644 --- a/frontend/src/menuAside.ts +++ b/frontend/src/menuAside.ts @@ -7,71 +7,42 @@ const menuAside: MenuAsideItem[] = [ icon: icon.mdiViewDashboardOutline, label: 'Dashboard', }, - - { - href: '/users/users-list', - label: 'Users', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - icon: icon.mdiAccountGroup ? icon.mdiAccountGroup : icon.mdiTable, - permissions: 'READ_USERS', - }, - { - href: '/products/products-list', - label: 'Products', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - icon: icon.mdiPackageVariant ? icon.mdiPackageVariant : icon.mdiTable, - permissions: 'READ_PRODUCTS', - }, - { - href: '/quotes/quotes-list', - label: 'Quotes', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - icon: icon.mdiCurrencyUsd ? icon.mdiCurrencyUsd : icon.mdiTable, - permissions: 'READ_QUOTES', - }, { href: '/shipments/shipments-list', - label: 'Shipments', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore icon: icon.mdiTruck ? icon.mdiTruck : icon.mdiTable, + label: 'Shipments', permissions: 'READ_SHIPMENTS', }, + { + href: '/products/products-list', + icon: icon.mdiPackageVariant ? icon.mdiPackageVariant : icon.mdiTable, + label: 'Products', + permissions: 'READ_PRODUCTS', + }, + { divider: true }, + { + href: '/users/users-list', + icon: icon.mdiAccountGroup ? icon.mdiAccountGroup : icon.mdiTable, + label: 'Users', + permissions: 'READ_USERS', + }, { href: '/roles/roles-list', + icon: icon.mdiShieldAccountVariantOutline ? icon.mdiShieldAccountVariantOutline : icon.mdiTable, label: 'Roles', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - icon: icon.mdiShieldAccountVariantOutline - ? icon.mdiShieldAccountVariantOutline - : icon.mdiTable, permissions: 'READ_ROLES', }, { href: '/permissions/permissions-list', + icon: icon.mdiShieldAccountOutline ? icon.mdiShieldAccountOutline : icon.mdiTable, label: 'Permissions', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - icon: icon.mdiShieldAccountOutline - ? icon.mdiShieldAccountOutline - : icon.mdiTable, permissions: 'READ_PERMISSIONS', }, + { divider: true }, { href: '/profile', - label: 'Profile', icon: icon.mdiAccountCircle, - }, - - { - href: '/api-docs', - target: '_blank', - label: 'Swagger API', - icon: icon.mdiFileCode, - permissions: 'READ_API_DOCS', + label: 'Profile', }, ]; diff --git a/frontend/src/pages/quotes/quotes-view.tsx b/frontend/src/pages/quotes/quotes-view.tsx index 0dd0a3b..88277cf 100644 --- a/frontend/src/pages/quotes/quotes-view.tsx +++ b/frontend/src/pages/quotes/quotes-view.tsx @@ -97,6 +97,8 @@ const QuotesView = () => { Customer Charge Actual Charge + + Businessname @@ -130,6 +132,8 @@ const QuotesView = () => { {item.actualCharge} + + {item.businessname} ))} diff --git a/frontend/src/pages/shipments/[shipmentsId].tsx b/frontend/src/pages/shipments/[shipmentsId].tsx index aa147f9..5148a77 100644 --- a/frontend/src/pages/shipments/[shipmentsId].tsx +++ b/frontend/src/pages/shipments/[shipmentsId].tsx @@ -57,6 +57,8 @@ const EditShipments = () => { customerCharge: '', actualCharge: '', + + businessname: '', }; const [initialValues, setInitialValues] = useState(initVals); @@ -177,6 +179,10 @@ const EditShipments = () => { /> + + + + diff --git a/frontend/src/pages/shipments/shipments-edit.tsx b/frontend/src/pages/shipments/shipments-edit.tsx index 80e949b..1452964 100644 --- a/frontend/src/pages/shipments/shipments-edit.tsx +++ b/frontend/src/pages/shipments/shipments-edit.tsx @@ -57,6 +57,8 @@ const EditShipmentsPage = () => { customerCharge: '', actualCharge: '', + + businessname: '', }; const [initialValues, setInitialValues] = useState(initVals); @@ -175,6 +177,10 @@ const EditShipmentsPage = () => { /> + + + + diff --git a/frontend/src/pages/shipments/shipments-list.tsx b/frontend/src/pages/shipments/shipments-list.tsx index c48fb92..5ddf5d7 100644 --- a/frontend/src/pages/shipments/shipments-list.tsx +++ b/frontend/src/pages/shipments/shipments-list.tsx @@ -36,6 +36,7 @@ const ShipmentsTablesPage = () => { { label: 'Zip Code', title: 'zipCode' }, { label: 'City', title: 'city' }, { label: 'State', title: 'state' }, + { label: 'Businessname', title: 'businessname' }, { label: 'Customer Charge', title: 'customerCharge', number: 'true' }, { label: 'Actual Charge', title: 'actualCharge', number: 'true' }, diff --git a/frontend/src/pages/shipments/shipments-new.tsx b/frontend/src/pages/shipments/shipments-new.tsx index 6a865e2..6be0ff2 100644 --- a/frontend/src/pages/shipments/shipments-new.tsx +++ b/frontend/src/pages/shipments/shipments-new.tsx @@ -54,6 +54,8 @@ const initialValues = { customerCharge: '', actualCharge: '', + + businessname: '', }; const ShipmentsNew = () => { @@ -147,6 +149,10 @@ const ShipmentsNew = () => { /> + + + + diff --git a/frontend/src/pages/shipments/shipments-table.tsx b/frontend/src/pages/shipments/shipments-table.tsx index d25de31..d42d971 100644 --- a/frontend/src/pages/shipments/shipments-table.tsx +++ b/frontend/src/pages/shipments/shipments-table.tsx @@ -36,6 +36,7 @@ const ShipmentsTablesPage = () => { { label: 'Zip Code', title: 'zipCode' }, { label: 'City', title: 'city' }, { label: 'State', title: 'state' }, + { label: 'Businessname', title: 'businessname' }, { label: 'Customer Charge', title: 'customerCharge', number: 'true' }, { label: 'Actual Charge', title: 'actualCharge', number: 'true' }, diff --git a/frontend/src/pages/shipments/shipments-view.tsx b/frontend/src/pages/shipments/shipments-view.tsx index e85b79d..94efba1 100644 --- a/frontend/src/pages/shipments/shipments-view.tsx +++ b/frontend/src/pages/shipments/shipments-view.tsx @@ -161,6 +161,11 @@ const ShipmentsView = () => {

{shipments?.actualCharge || 'No data'}

+
+

Businessname

+

{shipments?.businessname}

+
+ <>

Quotes Shipment