diff --git a/src/database/schemas/inventory/shipment.schema.js b/src/database/schemas/inventory/shipment.schema.js index 16bf11d..6abb147 100644 --- a/src/database/schemas/inventory/shipment.schema.js +++ b/src/database/schemas/inventory/shipment.schema.js @@ -15,6 +15,10 @@ const shipmentSchema = new Schema( amount: { type: Number, required: true }, amountWithTax: { type: Number, required: true }, taxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false }, + invoicedAmount: { type: Number, required: false, default: 0 }, + invoicedAmountWithTax: { type: Number, required: false, default: 0 }, + invoicedAmountRemaining: { type: Number, required: false, default: 0 }, + invoicedAmountWithTaxRemaining: { type: Number, required: false, default: 0 }, shippedAt: { type: Date, required: false }, expectedAt: { type: Date, required: false }, deliveredAt: { type: Date, required: false }, @@ -50,12 +54,16 @@ shipmentSchema.statics.recalculate = async function (shipment, user) { }); } - const amountWithTax = shipment.amount * (1 + (taxRate?.rate || 0) / 100); + const amountWithTax = parseFloat( + (shipment.amount || 0) * (1 + (taxRate?.rate || 0) / 100) + ).toFixed(2); await editObject({ model: shipmentModel, id: shipment._id, updateData: { amountWithTax: amountWithTax, + invoicedAmountRemaining: shipment.amount - (shipment.invoicedAmount || 0), + invoicedAmountWithTaxRemaining: amountWithTax - (shipment.invoicedAmountWithTax || 0), }, user, recalculate: false,