GroganBurners /
ferveo
| 1 | View Code Duplication | var mongoose = require('mongoose') |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 2 | var invoiceItem = require('./common/line-item') |
||
| 3 | |||
| 4 | var invoiceSchema = new mongoose.Schema({ |
||
| 5 | date: { type: Date, default: Date.now }, |
||
| 6 | customer: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer', required: true }, |
||
| 7 | items: [invoiceItem], |
||
| 8 | totalVat: { type: Number, default: 0.00 }, |
||
| 9 | total: { type: Number, default: 0.00 } |
||
| 10 | }) |
||
| 11 | |||
| 12 | invoiceSchema.pre('save', function (next) { |
||
| 13 | let overallTotal = 0.00 |
||
| 14 | // let overallVat |
||
| 15 | // All the items should give the total |
||
| 16 | for (let item in this.items) { |
||
| 17 | overallTotal += item.total |
||
| 18 | // overallVat += item.subTotal * item.vatRate |
||
| 19 | } |
||
| 20 | |||
| 21 | this.total = overallTotal |
||
| 22 | next() |
||
| 23 | }) |
||
| 24 | |||
| 25 | module.exports = mongoose.model('Invoice', invoiceSchema) |
||
| 26 |