GroganBurners /
ferveo
| 1 | View Code Duplication | var mongoose = require('mongoose') |
|
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
| 2 | var expenseItem = require('./common/line-item') |
||
| 3 | |||
| 4 | var expenseSchema = new mongoose.Schema({ |
||
| 5 | date: { type: Date, default: Date.now }, |
||
| 6 | company: { type: mongoose.Schema.Types.ObjectId, ref: 'Company', required: true }, |
||
| 7 | category: ['Purchases', 'Motor Fuel', 'Motor Serv/Repair', |
||
| 8 | 'Motor Tax/Ins', 'Van DOE', 'Public Laibility Insurance', |
||
| 9 | 'Advertising', 'Tele/bband', 'Training', 'Office Expenses', |
||
| 10 | 'Sub Contractor', 'Landfill', 'Ber Cert Fees', 'Bank Fees', |
||
| 11 | 'Sundry', 'Heating', 'Sponsorship', 'Equipment Hire', 'Electricity'], |
||
| 12 | items: [expenseItem], |
||
| 13 | totalVat: { type: Number, default: 0.00 }, |
||
| 14 | totalExVat: { type: Number, default: 0.00 }, |
||
| 15 | total: { type: Number, default: 0.00 } |
||
| 16 | }) |
||
| 17 | |||
| 18 | expenseSchema.pre('save', function (next) { |
||
| 19 | let overallTotal = 0.00 |
||
| 20 | // All the items should give the total |
||
| 21 | this.items.forEach(function (item) { |
||
| 22 | overallTotal = overallTotal + item.total |
||
| 23 | }) |
||
| 24 | |||
| 25 | this.total = overallTotal |
||
| 26 | next() |
||
| 27 | }) |
||
| 28 | |||
| 29 | module.exports = mongoose.model('Expense', expenseSchema) |
||
| 30 |