Add invoicing fields to shipment schema and update recalculation logic
- Introduced new fields: 'invoicedAmount', 'invoicedAmountWithTax', 'invoicedAmountRemaining', and 'invoicedAmountWithTaxRemaining' to the shipment schema for better tracking of invoicing status. - Updated the recalculation logic to compute remaining invoiced amounts based on the newly added fields.
This commit is contained in:
parent
dd86075734
commit
d3cbea45c5
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user