Skip to content

Commit

Permalink
Fix some more bugs
Browse files Browse the repository at this point in the history
- When adding more budget lines, the primary and secondary cost centre
is now correcly copied agin.
- When choosing the cost centre `Centralt` for an invoice it now
realises that something has been chosen even though the ID is 0
  • Loading branch information
foodelevator committed Jul 15, 2024
1 parent 732503c commit a7f81e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
22 changes: 10 additions & 12 deletions templates/expenses/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,19 @@ <h2>Kvittodelar</h2>
},
addPart: function () {
this.expense_parts.push({
committeeId: this.expense_parts[this.expense_parts.length - 1].committeeId,
costCentreId: this.expense_parts[this.expense_parts.length - 1].costCentreId,
budgetLineId: 0,
amount: 0
})
costCentre: this.expense_parts[this.expense_parts.length - 1].costCentre,
secondaryCostCentre: this.expense_parts[this.expense_parts.length - 1].secondaryCostCentre,
budgetLine: '',
amount: 0,
});
},
removePart: function (i) {
if (this.expense_parts <= 2) {
return
}
this.expense_parts.splice(i, 1)
if (this.expense_parts.length > 1)
this.expense_parts.splice(i, 1)
},
validateBudgetLines: function () {
return Array.prototype.filter.call((this.expense_parts), (budget => budget.budgetLine != '')).length == this.expense_parts.length
}
validateBudgetLines: function () {
return Array.prototype.filter.call(this.expense_parts, budget => budget.budgetLine != '').length == this.expense_parts.length
}
}
})
</script>
Expand Down
37 changes: 16 additions & 21 deletions templates/invoices/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ <h2>Fakturadelar</h2>
<div class="input">
<div class="select">
<select name="costCentres[]" v-model="expense_part.costCentreId" required v-on:change="updateSecondaryCostCentres()">
<option value="0">- Välj -</option>
<option value="">- Välj -</option>
<optgroup label="Nämnder">
<option v-for="costCentre in costCentres.filter(c => c.CostCentreType == 'committee')"
:key="costCentre.CostCentreID" v-text="costCentre.CostCentreName" v-bind:value="costCentre.CostCentreID"></option>
Expand All @@ -198,9 +198,9 @@ <h2>Fakturadelar</h2>
</label>
</span>
<div class="input">
<div class="select" v-if="expense_part.costCentreId > 0">
<div class="select" v-if="expense_part.costCentreId !== ''">
<select name="secondaryCostCentres[]" v-model="expense_part.secondaryCostCentreId" required v-on:change="updateBudgetLines()">
<option value="0">- Välj -</option>
<option value="">- Välj -</option>
<option
v-for="secondaryCostCentre in secondaryCostCentres.get(expense_part.costCentreId)"
v-text="secondaryCostCentre.SecondaryCostCentreName"
Expand All @@ -221,9 +221,9 @@ <h2>Fakturadelar</h2>
</label>
</span>
<div class="input">
<div class="select" v-if="expense_part.costCentreId > 0 && expense_part.secondaryCostCentreId > 0">
<div class="select" v-if="expense_part.costCentreId !== '' && expense_part.secondaryCostCentreId !== ''">
<select name="budgetLines[]" v-model="expense_part.budgetLineId" required>
<option value="0">- Välj -</option>
<option value="">- Välj -</option>
<option
v-for="budgetLine in budgetLines.get(expense_part.secondaryCostCentreId)"
v-text="budgetLine.BudgetLineName"
Expand Down Expand Up @@ -297,9 +297,9 @@ <h2>Fakturadelar</h2>
secondaryCostCentres: new Map(),
budgetLines: new Map(),
expense_parts: [{
costCentreId: 0,
secondaryCostCentreId: 0,
budgetLineId: 0,
costCentreId: '',
secondaryCostCentreId: '',
budgetLineId: '',
amount: 0,
}],
}
Expand All @@ -313,8 +313,9 @@ <h2>Fakturadelar</h2>
},
methods: {
updateSecondaryCostCentres: function () {
console.log(this.expense_parts);
for (const part of this.expense_parts) {
if (part.costCentreId == 0) continue;
if (part.costCentreId === '') continue;
if (!this.secondaryCostCentres.has(part.costCentreId)) {
fetch('{{ budget_url }}/api/SecondaryCostCentres?id=' + part.costCentreId)
.then(res => res.json())
Expand All @@ -328,7 +329,7 @@ <h2>Fakturadelar</h2>
},
updateBudgetLines: function () {
for (const part of this.expense_parts) {
if (part.secondaryCostCentreId == 0) continue;
if (part.secondaryCostCentreId === '') continue;
if (!this.budgetLines.has(part.secondaryCostCentreId)) {
fetch('{{ budget_url }}/api/BudgetLines?id=' + part.secondaryCostCentreId)
.then(res => res.json())
Expand All @@ -340,23 +341,17 @@ <h2>Fakturadelar</h2>
}
}
},
secondaryConstCentre: function(id) {
console.log("getting", id, this.secondaryCostCentres);
return this.secondaryCostCentres.get(id);
},
addPart: function () {
this.expense_parts.push({
costCentreId: this.expense_parts[this.expense_parts.length - 1].costCentreId,
secondaryCostCentreId: this.expense_parts[this.expense_parts.length - 1].secondaryCostCentreId,
budgetLineId: 0,
amount: 0
})
budgetLineId: '',
amount: 0,
});
},
removePart: function (i) {
if (this.expense_parts <= 2) {
return
}
this.expense_parts.splice(i, 1)
if (this.expense_parts.length > 1)
this.expense_parts.splice(i, 1)
}
}
})
Expand Down

0 comments on commit a7f81e1

Please sign in to comment.