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()() },
|
||||
orderType: { type: String, required: true },
|
||||
name: { type: String, required: true },
|
||||
state: {
|
||||
type: { type: String, required: true, default: 'draft' },
|
||||
},
|
||||
@ -26,6 +27,12 @@ const orderItemSchema = new Schema(
|
||||
totalAmount: { type: Number, required: true },
|
||||
taxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
||||
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 },
|
||||
shipment: { type: Schema.Types.ObjectId, ref: 'shipment', required: false },
|
||||
orderedAt: { type: Date, required: false },
|
||||
@ -97,6 +104,9 @@ orderItemSchema.statics.recalculate = async function (orderItem, user) {
|
||||
model: orderItemModel,
|
||||
id: orderItem._id,
|
||||
updateData: {
|
||||
invoicedAmountRemaining: orderTotalAmount - orderItem.invoicedAmount,
|
||||
invoicedAmountWithTaxRemaining: orderTotalAmountWithTax - orderItem.invoicedAmountWithTax,
|
||||
invoicedQuantityRemaining: orderItem.quantity - orderItem.invoicedQuantity,
|
||||
totalAmount: orderTotalAmount,
|
||||
totalAmountWithTax: orderTotalAmountWithTax,
|
||||
},
|
||||
|
||||
@ -19,6 +19,7 @@ import {
|
||||
router.get('/', isAuthenticated, (req, res) => {
|
||||
const { page, limit, property, search, sort, order } = req.query;
|
||||
const allowedFilters = [
|
||||
'name',
|
||||
'itemType',
|
||||
'item',
|
||||
'item._id',
|
||||
@ -35,6 +36,7 @@ router.get('/', isAuthenticated, (req, res) => {
|
||||
router.get('/properties', isAuthenticated, (req, res) => {
|
||||
let properties = convertPropertiesString(req.query.properties);
|
||||
const allowedFilters = [
|
||||
'name',
|
||||
'itemType',
|
||||
'item',
|
||||
'item._id',
|
||||
|
||||
@ -135,6 +135,7 @@ export const editOrderItemRouteHandler = async (req, res) => {
|
||||
|
||||
const updateData = {
|
||||
updatedAt: new Date(),
|
||||
name: req.body.name,
|
||||
itemType: req.body.itemType,
|
||||
item: req.body.item,
|
||||
orderType: req.body.orderType,
|
||||
@ -169,6 +170,7 @@ export const editOrderItemRouteHandler = async (req, res) => {
|
||||
export const editMultipleOrderItemsRouteHandler = async (req, res) => {
|
||||
const updates = req.body.map((update) => ({
|
||||
_id: update._id,
|
||||
name: update.name,
|
||||
itemType: update.itemType,
|
||||
item: update.item,
|
||||
orderType: update.orderType,
|
||||
@ -206,6 +208,7 @@ export const editMultipleOrderItemsRouteHandler = async (req, res) => {
|
||||
export const newOrderItemRouteHandler = async (req, res) => {
|
||||
const newData = {
|
||||
updatedAt: new Date(),
|
||||
name: req.body.name,
|
||||
purchaseOrder: req.body.purchaseOrder,
|
||||
state: { type: 'draft' },
|
||||
itemType: req.body.itemType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user