forked from idurar/idurar-erp-crm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Salah Eddine Lalami
committed
Oct 22, 2023
1 parent
1449f00
commit f84d899
Showing
8 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const createCRUDController = require('@/controllers/middlewaresControllers/createCRUDController'); | ||
module.exports = createCRUDController('Inventory'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters