Keep track of children CLINS to update amount
- emit CLIN amount and type when amount changes - totals are added correctly based on CLIN type
This commit is contained in:
parent
c775c7322c
commit
23b7df2153
@ -3,8 +3,8 @@ import { emitEvent } from '../lib/emitters'
|
|||||||
import optionsinput from './options_input'
|
import optionsinput from './options_input'
|
||||||
import textinput from './text_input'
|
import textinput from './text_input'
|
||||||
|
|
||||||
const JEDI_CLIN_TYPE = "jedi_clin_type"
|
const JEDI_CLIN_TYPE = 'jedi_clin_type'
|
||||||
const OBLIGATED_AMOUNT = "obligated_amount"
|
const OBLIGATED_AMOUNT = 'obligated_amount'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'clin-fields',
|
name: 'clin-fields',
|
||||||
@ -22,6 +22,10 @@ export default {
|
|||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
initialClinType: String,
|
initialClinType: String,
|
||||||
|
initialAmount: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
@ -40,6 +44,14 @@ export default {
|
|||||||
this.$root.$on('field-change', this.handleFieldChange)
|
this.$root.$on('field-change', this.handleFieldChange)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created: function() {
|
||||||
|
emitEvent('clin-change', this, {
|
||||||
|
id: this._uid,
|
||||||
|
clinType: this.clinType,
|
||||||
|
amount: this.initialAmount,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addLoa: function(event) {
|
addLoa: function(event) {
|
||||||
++this.loas
|
++this.loas
|
||||||
@ -56,12 +68,12 @@ export default {
|
|||||||
}
|
}
|
||||||
else if (event.name.includes(OBLIGATED_AMOUNT)) {
|
else if (event.name.includes(OBLIGATED_AMOUNT)) {
|
||||||
emitEvent('clin-change', this, {
|
emitEvent('clin-change', this, {
|
||||||
|
id: this._uid,
|
||||||
clinType: this.clinType,
|
clinType: this.clinType,
|
||||||
amount: event.value,
|
amount: parseFloat(event.value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ export default {
|
|||||||
clinIndex,
|
clinIndex,
|
||||||
obligated: this.initialObligated || 0,
|
obligated: this.initialObligated || 0,
|
||||||
total: this.initialTotal || 0,
|
total: this.initialTotal || 0,
|
||||||
|
clinChildren: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -52,11 +53,24 @@ export default {
|
|||||||
++this.clinIndex
|
++this.clinIndex
|
||||||
},
|
},
|
||||||
|
|
||||||
calculateClinAmounts: function (event) {
|
calculateClinAmounts: function(event) {
|
||||||
this.total += parseFloat(event.amount - this.total)
|
this.clinChildren[event.id] = {
|
||||||
if (event.clinType.includes('1') || event.clinType.includes('3')) {
|
amount: event.amount,
|
||||||
this.obligated += parseFloat(event.amount - this.obligated)
|
type: event.clinType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let newTotal = 0
|
||||||
|
let newObligated = 0
|
||||||
|
Object.values(this.clinChildren).forEach(
|
||||||
|
function(clin) {
|
||||||
|
newTotal += clin.amount
|
||||||
|
if (clin.type.includes('1', '3')) {
|
||||||
|
newObligated += clin.amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this.total = newTotal
|
||||||
|
this.obligated = newObligated
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -10,10 +10,10 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
formattedObligated: function () {
|
formattedObligated: function() {
|
||||||
return formatDollars(this.obligated)
|
return formatDollars(this.obligated)
|
||||||
},
|
},
|
||||||
formattedContractAmount: function () {
|
formattedContractAmount: function() {
|
||||||
return formatDollars(this.contractAmount)
|
return formatDollars(this.contractAmount)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
v-bind:initial-clin-index='{{ index }}'
|
v-bind:initial-clin-index='{{ index }}'
|
||||||
v-bind:initial-loa-count="{{ fields.loas.data | length }}"
|
v-bind:initial-loa-count="{{ fields.loas.data | length }}"
|
||||||
v-bind:initial-clin-type="'{{ fields.jedi_clin_type.data }}'"
|
v-bind:initial-clin-type="'{{ fields.jedi_clin_type.data }}'"
|
||||||
|
v-bind:initial-amount='{{ fields.obligated_amount.data }}'
|
||||||
inline-template>
|
inline-template>
|
||||||
<div>
|
<div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
@ -159,7 +160,10 @@
|
|||||||
|
|
||||||
<div v-for="clin in clins">
|
<div v-for="clin in clins">
|
||||||
<hr v-if="clinIndex !== 0">
|
<hr v-if="clinIndex !== 0">
|
||||||
<clin-fields v-bind:initial-clin-index='clinIndex' inline-template>
|
<clin-fields
|
||||||
|
v-bind:initial-clin-index='clinIndex'
|
||||||
|
v-bind:initial-clin-type="'JEDICLINType.JEDI_CLIN_1'"
|
||||||
|
inline-template>
|
||||||
<div>
|
<div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-col form-col--two-thirds">
|
<div class="form-col form-col--two-thirds">
|
||||||
@ -214,6 +218,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</textinput>
|
</textinput>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user