Add funding validation to clinfields vue component
This commit is contained in:
parent
257fe648a8
commit
bf19add617
@ -6,7 +6,10 @@ import { emitEvent } from '../lib/emitters'
|
|||||||
import Modal from '../mixins/modal'
|
import Modal from '../mixins/modal'
|
||||||
import optionsinput from './options_input'
|
import optionsinput from './options_input'
|
||||||
import textinput from './text_input'
|
import textinput from './text_input'
|
||||||
|
import clindollaramount from './clin_dollar_amount'
|
||||||
|
|
||||||
|
const TOTAL_AMOUNT = 'total_amount'
|
||||||
|
const OBLIGATED_AMOUNT = 'obligated_amount'
|
||||||
const START_DATE = 'start_date'
|
const START_DATE = 'start_date'
|
||||||
const END_DATE = 'end_date'
|
const END_DATE = 'end_date'
|
||||||
const POP = 'period_of_performance'
|
const POP = 'period_of_performance'
|
||||||
@ -19,12 +22,21 @@ export default {
|
|||||||
DateSelector,
|
DateSelector,
|
||||||
optionsinput,
|
optionsinput,
|
||||||
textinput,
|
textinput,
|
||||||
|
clindollaramount,
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [Modal],
|
mixins: [Modal],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
initialClinIndex: Number,
|
initialClinIndex: Number,
|
||||||
|
initialTotal: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
initialObligated: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
initialStartDate: {
|
initialStartDate: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
@ -54,6 +66,10 @@ export default {
|
|||||||
const end = !!this.initialEndDate
|
const end = !!this.initialEndDate
|
||||||
? new Date(this.initialEndDate)
|
? new Date(this.initialEndDate)
|
||||||
: undefined
|
: undefined
|
||||||
|
const fundingValidation =
|
||||||
|
this.initialObligated && this.initialTotal
|
||||||
|
? false
|
||||||
|
: this.initialObligated <= this.initialTotal
|
||||||
const popValidation = !this.initialStartDate ? false : start < end
|
const popValidation = !this.initialStartDate ? false : start < end
|
||||||
const clinNumber = !!this.initialClinNumber
|
const clinNumber = !!this.initialClinNumber
|
||||||
? this.initialClinNumber
|
? this.initialClinNumber
|
||||||
@ -63,6 +79,7 @@ export default {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
clinIndex: this.initialClinIndex,
|
clinIndex: this.initialClinIndex,
|
||||||
|
clinNumber: clinNumber,
|
||||||
startDate: start,
|
startDate: start,
|
||||||
endDate: end,
|
endDate: end,
|
||||||
popValid: popValidation,
|
popValid: popValidation,
|
||||||
@ -93,6 +110,9 @@ export default {
|
|||||||
)}.`,
|
)}.`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
totalAmount: this.initialTotal || 0,
|
||||||
|
obligatedAmount: this.initialObligated || 0,
|
||||||
|
fundingValid: fundingValidation,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -101,14 +121,37 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
created: function() {
|
created: function() {
|
||||||
|
emitEvent('clin-change', this, {
|
||||||
|
id: this._uid,
|
||||||
|
obligatedAmount: this.initialObligated,
|
||||||
|
totalAmount: this.initialTotal,
|
||||||
|
})
|
||||||
emitEvent('field-mount', this, {
|
emitEvent('field-mount', this, {
|
||||||
optional: false,
|
optional: false,
|
||||||
name: 'clins-' + this.clinIndex + '-' + POP,
|
name: 'clins-' + this.clinIndex + '-' + POP,
|
||||||
valid: this.checkPopValid(),
|
valid: this.checkPopValid(),
|
||||||
})
|
})
|
||||||
|
emitEvent('field-mount', this, {
|
||||||
|
optional: false,
|
||||||
|
name: TOTAL_AMOUNT,
|
||||||
|
valid: this.checkFundingValid(),
|
||||||
|
})
|
||||||
|
emitEvent('field-mount', this, {
|
||||||
|
optional: false,
|
||||||
|
name: OBLIGATED_AMOUNT,
|
||||||
|
valid: this.checkFundingValid(),
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
clinChangeEvent: function() {
|
||||||
|
emitEvent('clin-change', this, {
|
||||||
|
id: this._uid,
|
||||||
|
obligatedAmount: this.initialObligated,
|
||||||
|
totalAmount: this.initialTotal,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
checkPopValid: function() {
|
checkPopValid: function() {
|
||||||
return (
|
return (
|
||||||
this.popDateOrder() &&
|
this.popDateOrder() &&
|
||||||
@ -153,9 +196,30 @@ export default {
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
checkFundingValid: function() {
|
||||||
|
return this.obligatedAmount <= this.totalAmount
|
||||||
|
},
|
||||||
|
|
||||||
|
validateFunding: function() {
|
||||||
|
if (this.totalAmount && this.obligatedAmount) {
|
||||||
|
this.fundingValid = this.checkFundingValid()
|
||||||
|
}
|
||||||
|
|
||||||
|
emitEvent('field-change', this, {
|
||||||
|
name: OBLIGATED_AMOUNT,
|
||||||
|
valid: this.checkFundingValid(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
handleFieldChange: function(event) {
|
handleFieldChange: function(event) {
|
||||||
if (this._uid === event.parent_uid) {
|
if (this._uid === event.parent_uid) {
|
||||||
if (event.name.includes(START_DATE)) {
|
if (event.name.includes(TOTAL_AMOUNT)) {
|
||||||
|
this.totalAmount = parseFloat(event.value)
|
||||||
|
this.validateFunding()
|
||||||
|
} else if (event.name.includes(OBLIGATED_AMOUNT)) {
|
||||||
|
this.obligatedAmount = parseFloat(event.value)
|
||||||
|
this.validateFunding()
|
||||||
|
} else if (event.name.includes(START_DATE)) {
|
||||||
if (!!event.value) this.startDate = new Date(event.value)
|
if (!!event.value) this.startDate = new Date(event.value)
|
||||||
if (!!event.valid) this.startDateValid = event.valid
|
if (!!event.valid) this.startDateValid = event.valid
|
||||||
this.validatePop()
|
this.validatePop()
|
||||||
@ -186,6 +250,10 @@ export default {
|
|||||||
return `CLIN`
|
return `CLIN`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
percentObligated: function() {
|
||||||
|
const percentage = (this.obligatedAmount / this.totalAmount) * 100
|
||||||
|
return !!percentage ? `${percentage.toFixed(1)}%` : '0%'
|
||||||
|
},
|
||||||
|
|
||||||
removeModalId: function() {
|
removeModalId: function() {
|
||||||
return `remove-clin-${this.clinIndex}`
|
return `remove-clin-${this.clinIndex}`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user