Skip to content

Commit

Permalink
add inventory model
Browse files Browse the repository at this point in the history
  • Loading branch information
Salah Eddine Lalami committed Oct 22, 2023
1 parent 1449f00 commit f84d899
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/controllers/appControllers/inventoryController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const createCRUDController = require('@/controllers/middlewaresControllers/createCRUDController');
module.exports = createCRUDController('Inventory');
34 changes: 34 additions & 0 deletions backend/models/appModels/Inventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;

const inventorySchema = new mongoose.Schema({
removed: {
type: Boolean,
default: false,
},
enabled: {
type: Boolean,
default: true,
},
product: {
type: String,
trim: true,
required: true,
},
quantity: {
type: Number,
required: true,
min: 0, // Ensure non-negative numbers
},
unitPrice: {
type: Number,
required: true,
min: 0, // Ensure non-negative numbers
},
created: {
type: Date,
default: Date.now,
},
});

module.exports = mongoose.model('Inventory', inventorySchema);
11 changes: 11 additions & 0 deletions backend/routes/appRoutes/appApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const orderController = require('@/controllers/appControllers/orderController');
const offerController = require('@/controllers/appControllers/offerController');

const kycController = require('@/controllers/appControllers/kycController');
const inventoryController = require('@/controllers/appControllers/inventoryController');

// //_________________________________ API for employees_____________________
router.route('/employee/create').post(catchErrors(employeeController.create));
Expand Down Expand Up @@ -181,6 +182,16 @@ router.route('/order/search').get(catchErrors(orderController.search));
router.route('/order/list').get(catchErrors(orderController.list));
router.route('/order/filter').get(catchErrors(orderController.filter));

// //_________________________________________________________________API for Inventory

router.route('/inventory/create').post(catchErrors(inventoryController.create));
router.route('/inventory/read/:id').get(catchErrors(inventoryController.read));
router.route('/inventory/update/:id').patch(catchErrors(inventoryController.update));
router.route('/inventory/delete/:id').delete(catchErrors(inventoryController.delete));
router.route('/inventory/search').get(catchErrors(inventoryController.search));
router.route('/inventory/list').get(catchErrors(inventoryController.list));
router.route('/inventory/filter').get(catchErrors(inventoryController.filter));

// //_________________________________________________________________API for Kyc________________

const kycFileStorage = multer.diskStorage({
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/Navigation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
SettingOutlined,
CustomerServiceOutlined,
ShopOutlined,
ShoppingCartOutlined,
InboxOutlined,
FileTextOutlined,
FileSyncOutlined,
DashboardOutlined,
Expand All @@ -27,7 +29,9 @@ const SIDEBAR_MENU = [
{ key: '/lead', icon: <UserAddOutlined />, title: 'Lead' },
{ key: '/offer', icon: <FileOutlined />, title: 'Offer' },
{ key: '/customer', icon: <CustomerServiceOutlined />, title: 'Customer' },
{ key: '/order', icon: <ShopOutlined />, title: 'Order' },
// { key: '/order', icon: <ShopOutlined />, title: 'Order' },
// { key: '/inventory', icon: <InboxOutlined />, title: 'Inventory' },
// { key: '/kyc', icon: <ShoppingCartOutlined />, title: 'Kyc' },
{ key: '/invoice', icon: <FileTextOutlined />, title: 'Invoice' },
{ key: '/quote', icon: <FileSyncOutlined />, title: 'Quote' },
{ key: '/payment/invoice', icon: <CreditCardOutlined />, title: 'Payment Invoice' },
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/forms/InventoryForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { Form, Input, InputNumber } from 'antd';

export default function InventoryForm() {
// Renamed to InventoryForm for clarity
return (
<>
<Form.Item
label="Product"
name="product"
rules={[
{
required: true,
message: 'Please input Product name!',
},
]}
>
<Input />
</Form.Item>

<Form.Item
label="Quantity"
name="quantity"
rules={[
{
required: true,
message: 'Please input Quantity!',
type: 'number',
min: 0, // Ensure non-negative numbers
},
]}
>
<InputNumber />
</Form.Item>

<Form.Item
label="Unit Price"
name="unitPrice"
rules={[
{
required: true,
message: 'Please input Unit Price!',
type: 'number',
min: 0, // Ensure non-negative numbers
},
]}
>
<InputNumber
formatter={(value) => `$ ${value}`} // Optional: format value as currency
parser={(value) => value.replace(/\$\s?|(,*)/g, '')} // Optional: parse input as number
/>
</Form.Item>
</>
);
}
18 changes: 18 additions & 0 deletions frontend/src/pages/Inventory/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const entity = 'inventory'; // Updated entity name

const Labels = {
PANEL_TITLE: 'Inventory Management',
dataTableTitle: 'Inventory List',
ADD_NEW_ENTITY: 'Add New Item',
DATATABLE_TITLE: 'Inventory List',
ENTITY_NAME: 'Inventory Item',
CREATE_ENTITY: 'Add Item',
UPDATE_ENTITY: 'Update Item',
};

const configPage = {
entity,
...Labels,
};

export default configPage;
58 changes: 58 additions & 0 deletions frontend/src/pages/Inventory/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import CrudModule from '@/modules/CrudModule';
import InventoryForm from '@/forms/InventoryForm'; // Retaining InventoryForm
import configPage from './config';

export default function Inventory() {
const searchConfig = {
displayLabels: ['product'], // Adjusted to search by product
searchFields: 'product',
outputValue: '_id',
};
const entityDisplayLabels = ['product', 'quantity', 'unitPrice']; // Adjusted to display inventory item labels

const readColumns = [
{
title: 'Product',
dataIndex: 'product',
},
{
title: 'Quantity',
dataIndex: 'quantity',
},
{
title: 'Unit Price',
dataIndex: 'unitPrice',
},
];

const dataTableColumns = [
{
title: 'Product',
dataIndex: ['product'],
},
{
title: 'Quantity',
dataIndex: ['quantity'],
},
{
title: 'Unit Price in $',
dataIndex: ['unitPrice'],
},
];

const config = {
...configPage,
readColumns,
dataTableColumns,
searchConfig,
entityDisplayLabels,
};
return (
<CrudModule
createForm={<InventoryForm />} // Retaining InventoryForm
updateForm={<InventoryForm isUpdateForm={true} />} // Retaining InventoryForm
config={config}
/>
);
}
4 changes: 4 additions & 0 deletions frontend/src/router/RoutesConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const routesConfig = [
path: '/customer',
component: 'Customer',
},
{
path: '/inventory',
component: 'Inventory',
},
{
path: '/order',
component: 'Order',
Expand Down

0 comments on commit f84d899

Please sign in to comment.