Skip to content

Commit

Permalink
first simple list of factors
Browse files Browse the repository at this point in the history
  • Loading branch information
arnold-pichler committed Sep 28, 2024
1 parent 1ebf2cf commit 50759b9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/components/TheEntryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ function FloatTrunc(input) {
}
function saveData() {
console.log(entry.value);
if (currentSaved.value !== null) {
savedData.value[currentSaved.value] = { ...entry.value };
} else {
Expand Down
48 changes: 46 additions & 2 deletions src/components/TheFertilizerBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
><v-icon size="small">mdi-alert-box</v-icon>{{ message }}
</v-col></v-row
>
<v-row no-gutters
><v-col>
<table v-for="(kultur, index) in bilanz.bilanz" :key="`bilanztable${index}`" class="bilanz">
<tr>
<th colspan="2">
{{ tableAttribut('kulturen', entry.cultures[index].kultur, 'Kultur') }}
</th>
</tr>
<tr v-for="(value, key) in kultur" :key="`row_${index}_${key}`">
<td v-if="value > 0">{{ labels[key] }}</td>
<td v-if="value > 0">{{ value.toLocaleString('de-DE', { style: 'decimal' }) }}</td>
</tr>
</table>
</v-col>
</v-row>
</v-card>
</template>

Expand All @@ -33,15 +48,44 @@ import { useDataEntries } from '../composables/useDataEntries.js';
import { useBalanceCalculator } from '../composables/useBalanceCalculator.js';
import { ref, computed } from 'vue';
const { dataWindow } = useDataEntries();
const { updateBilanz } = useBalanceCalculator();
const { dataWindow, entry } = useDataEntries();
const { updateBilanz, labels } = useBalanceCalculator();
import { useLookup } from '../composables/useLookUps.js';
const winMaximize = ref(false);
const bilanz = computed(() => updateBilanz());
const { tableAttribut } = useLookup();
</script>

<style scoped>
table.bilanz {
width: 100%;
border-collapse: collapse;
}
table.bilanz tr {
padding: 0px;
}
table.bilanz th {
padding: 2px;
font-size: 11px;
background-color: #eee;
text-align: left;
}
table.bilanz td {
padding: 2px;
border: 1px solid #eee;
font-size: 11px;
}
table.bilanz tr td:nth-child(1) {
width: 85%;
white-space: nowrap;
overflow: hidden;
}
table.bilanz tr td:nth-child(2) {
width: 15%;
}
.fertilizerData {
position: absolute;
left: 10px;
Expand Down
47 changes: 43 additions & 4 deletions src/composables/useBalanceCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ const emptyKulturbilanz = {
};

/**
* @type object
* @type {Object<keyof kulturbilanz, string>}
*/
const labels = {
export const labels = {
nmengehd: 'N-Menge aus Handelsdüngern ',
nmengebw: 'N-Menge aus Bewässerung ',
nmengesr: 'N-Menge aus organischen Sekundärrohstoffen',
Expand Down Expand Up @@ -93,9 +93,48 @@ function calculateBilanz() {
const retVal = [];
for (let c = 0; c < entry.value.cultures.length; c++) {
const current = { ...emptyKulturbilanz };
for (let d = 0; d < entry.value.cultures[c].duengung.length; d++) {
console.log(entry.value.cultures[c].duengung[d]);
// Düngungen iterieren
// 1. Anteile Handelsdünger
if (
entry.value.cultures[c].duengung[d].typ === 'handelsdünger' ||
entry.value.cultures[c].duengung[d].typ === 'eigene'
) {
current.nmengehd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].n / 100);
current.pmengehd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].p / 100);
current.kmengehd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].k / 100);
}
// 2. Anteile Sekundärrohstofe
if (entry.value.cultures[c].duengung[d].typ === 'sekundärrohstoffe') {
current.nmengesr +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].n / 100);
current.pmengesr +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].p / 100);
current.kmengesr +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].k / 100);
}
// 3. Anteile Wirtschaftsdünger
if (entry.value.cultures[c].duengung[d].typ === 'wirtschaftsdünger') {
current.nmengewd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].n / 100);
current.pmengewd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].p / 100);
current.kmengewd +=
entry.value.cultures[c].duengung[d].menge * (entry.value.cultures[c].duengung[d].k / 100);
}

// N-Bilanz und Düngungen
current.nanrechenbar = current.nmengehd + current.nmengesr + current.nmengewd;
current.pduengung = current.pmengehd + current.pmengesr + current.pmengewd;
current.kduengung = current.kmengehd + current.kmengesr + current.kmengewd;
}
retVal.push(current);
}
console.log(retVal);

return retVal;
}

Expand Down Expand Up @@ -165,5 +204,5 @@ export function updateBilanz() {
}

export function useBalanceCalculator() {
return { updateBilanz };
return { updateBilanz, labels };
}

0 comments on commit 50759b9

Please sign in to comment.