Add 'name' field and invoicing details to order item schema
- Introduced a new 'name' field as a required attribute in the order item schema. - Added invoicing-related fields: 'invoicedAmountWithTax', 'invoicedAmount', 'invoicedQuantity', 'invoicedAmountRemaining', 'invoicedAmountWithTaxRemaining', and 'invoicedQuantityRemaining' to track invoicing status. - Updated route handlers to accommodate the new 'name' field in order item creation and editing processes. - Enhanced the recalculation logic to include remaining invoiced amounts and quantities.
This commit is contained in:
parent
0f14f0f52c
commit
dd86075734
@ -14,6 +14,7 @@ const orderItemSchema = new Schema(
|
|||||||
{
|
{
|
||||||
_reference: { type: String, default: () => generateId()() },
|
_reference: { type: String, default: () => generateId()() },
|
||||||
orderType: { type: String, required: true },
|
orderType: { type: String, required: true },
|
||||||
|
name: { type: String, required: true },
|
||||||
state: {
|
state: {
|
||||||
type: { type: String, required: true, default: 'draft' },
|
type: { type: String, required: true, default: 'draft' },
|
||||||
},
|
},
|
||||||
@ -26,6 +27,12 @@ const orderItemSchema = new Schema(
|
|||||||
totalAmount: { type: Number, required: true },
|
totalAmount: { type: Number, required: true },
|
||||||
taxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
taxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
||||||
totalAmountWithTax: { type: Number, required: true },
|
totalAmountWithTax: { type: Number, required: true },
|
||||||
|
invoicedAmountWithTax: { type: Number, required: false, default: 0 },
|
||||||
|
invoicedAmount: { type: Number, required: false, default: 0 },
|
||||||
|
invoicedQuantity: { type: Number, required: false, default: 0 },
|
||||||
|
invoicedAmountRemaining: { type: Number, required: false, default: 0 },
|
||||||
|
invoicedAmountWithTaxRemaining: { type: Number, required: false, default: 0 },
|
||||||
|
invoicedQuantityRemaining: { type: Number, required: false, default: 0 },
|
||||||
timestamp: { type: Date, default: Date.now },
|
timestamp: { type: Date, default: Date.now },
|
||||||
shipment: { type: Schema.Types.ObjectId, ref: 'shipment', required: false },
|
shipment: { type: Schema.Types.ObjectId, ref: 'shipment', required: false },
|
||||||
orderedAt: { type: Date, required: false },
|
orderedAt: { type: Date, required: false },
|
||||||
@ -97,6 +104,9 @@ orderItemSchema.statics.recalculate = async function (orderItem, user) {
|
|||||||
model: orderItemModel,
|
model: orderItemModel,
|
||||||
id: orderItem._id,
|
id: orderItem._id,
|
||||||
updateData: {
|
updateData: {
|
||||||
|
invoicedAmountRemaining: orderTotalAmount - orderItem.invoicedAmount,
|
||||||
|
invoicedAmountWithTaxRemaining: orderTotalAmountWithTax - orderItem.invoicedAmountWithTax,
|
||||||
|
invoicedQuantityRemaining: orderItem.quantity - orderItem.invoicedQuantity,
|
||||||
totalAmount: orderTotalAmount,
|
totalAmount: orderTotalAmount,
|
||||||
totalAmountWithTax: orderTotalAmountWithTax,
|
totalAmountWithTax: orderTotalAmountWithTax,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import {
|
|||||||
router.get('/', isAuthenticated, (req, res) => {
|
router.get('/', isAuthenticated, (req, res) => {
|
||||||
const { page, limit, property, search, sort, order } = req.query;
|
const { page, limit, property, search, sort, order } = req.query;
|
||||||
const allowedFilters = [
|
const allowedFilters = [
|
||||||
|
'name',
|
||||||
'itemType',
|
'itemType',
|
||||||
'item',
|
'item',
|
||||||
'item._id',
|
'item._id',
|
||||||
@ -35,6 +36,7 @@ router.get('/', isAuthenticated, (req, res) => {
|
|||||||
router.get('/properties', isAuthenticated, (req, res) => {
|
router.get('/properties', isAuthenticated, (req, res) => {
|
||||||
let properties = convertPropertiesString(req.query.properties);
|
let properties = convertPropertiesString(req.query.properties);
|
||||||
const allowedFilters = [
|
const allowedFilters = [
|
||||||
|
'name',
|
||||||
'itemType',
|
'itemType',
|
||||||
'item',
|
'item',
|
||||||
'item._id',
|
'item._id',
|
||||||
|
|||||||
@ -135,6 +135,7 @@ export const editOrderItemRouteHandler = async (req, res) => {
|
|||||||
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
|
name: req.body.name,
|
||||||
itemType: req.body.itemType,
|
itemType: req.body.itemType,
|
||||||
item: req.body.item,
|
item: req.body.item,
|
||||||
orderType: req.body.orderType,
|
orderType: req.body.orderType,
|
||||||
@ -169,6 +170,7 @@ export const editOrderItemRouteHandler = async (req, res) => {
|
|||||||
export const editMultipleOrderItemsRouteHandler = async (req, res) => {
|
export const editMultipleOrderItemsRouteHandler = async (req, res) => {
|
||||||
const updates = req.body.map((update) => ({
|
const updates = req.body.map((update) => ({
|
||||||
_id: update._id,
|
_id: update._id,
|
||||||
|
name: update.name,
|
||||||
itemType: update.itemType,
|
itemType: update.itemType,
|
||||||
item: update.item,
|
item: update.item,
|
||||||
orderType: update.orderType,
|
orderType: update.orderType,
|
||||||
@ -206,6 +208,7 @@ export const editMultipleOrderItemsRouteHandler = async (req, res) => {
|
|||||||
export const newOrderItemRouteHandler = async (req, res) => {
|
export const newOrderItemRouteHandler = async (req, res) => {
|
||||||
const newData = {
|
const newData = {
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
|
name: req.body.name,
|
||||||
purchaseOrder: req.body.purchaseOrder,
|
purchaseOrder: req.body.purchaseOrder,
|
||||||
state: { type: 'draft' },
|
state: { type: 'draft' },
|
||||||
itemType: req.body.itemType,
|
itemType: req.body.itemType,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user