Skip to content

Commit 99a910e

Browse files
committed
Förpopulera resultaträkning och balansräkning
1 parent 74eb748 commit 99a910e

17 files changed

+354
-122
lines changed

src/assets/extendables.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
%text-input {
22
border: 1px solid var(--bs-border-color);
33
border-radius: 4px;
4-
background-color: #fff;
54
transition: border-color 0.3s,
65
box-shadow 0.3s;
76

src/components/edit/blocks/EditBelopprad.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const props = defineProps<{
2222
/** TaxonomyManager för att hantera taxonomiobjekt för beloppraden. */
2323
taxonomyManager: TaxonomyManager;
2424
25+
/** Huruvida borttag ska tillåtas. */
26+
allowDelete?: boolean;
27+
2528
/** Antal tidigare räkenskapsår som ska visas för belopprader där man kan jämföra mellan år. */
2629
comparableNumPreviousYears?: number;
2730
@@ -69,6 +72,7 @@ const taxonomyItem = computed(() => {
6972
>
7073
<EditBeloppradString
7174
v-if="isBeloppradString(belopprad)"
75+
:allow-delete="allowDelete || false"
7276
:belopprad="belopprad"
7377
:comparable-num-previous-years="comparableNumPreviousYears || 0"
7478
:multiline="stringMultiline || false"
@@ -77,6 +81,7 @@ const taxonomyItem = computed(() => {
7781
/>
7882
<EditBeloppradMonetary
7983
v-else-if="isBeloppradMonetary(belopprad)"
84+
:allow-delete="allowDelete || false"
8085
:allow-not="comparableAllowNot || false"
8186
:belopprad="belopprad"
8287
:belopprader="belopprader"
@@ -87,6 +92,7 @@ const taxonomyItem = computed(() => {
8792
/>
8893
<EditBeloppradNonmonetaryComparable
8994
v-else-if="isBeloppradComparable(belopprad)"
95+
:allow-delete="allowDelete || false"
9096
:allow-not="comparableAllowNot || false"
9197
:belopprad="belopprad"
9298
:num-previous-years="comparableNumPreviousYears || 0"

src/components/edit/blocks/belopprad/BaseEditBeloppradComparable.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface EditBeloppradComparablePropsBase {
1616
/** TaxonomyManager för att hantera taxonomiobjekt för beloppraden. */
1717
taxonomyManager: TaxonomyManager;
1818
19+
/** Huruvida borttag ska tillåtas. */
20+
allowDelete: boolean;
21+
1922
/** Antal tidigare räkenskapsår som ska visas för jämförelse. */
2023
numPreviousYears: number;
2124
@@ -128,7 +131,7 @@ function onBeforeValueInput(event: InputEvent) {
128131
/>
129132
</div>
130133
</td>
131-
<td>
134+
<td v-if="allowDelete">
132135
<BaseEditBeloppradDeleteButton @delete="emit('delete')" />
133136
</td>
134137
</BaseEditBeloppradContainer>

src/components/edit/blocks/belopprad/EditBeloppradMonetary.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ const taxonomyItem = computed(() => {
4141
return getTaxonomyItemForBelopprad(props.taxonomyManager, belopprad.value);
4242
});
4343
44-
onMounted(() => {
44+
// Räkna automatiskt ut summor
45+
function createSumWatcher(
46+
belopprad: BeloppradMonetary,
47+
belopprader: Belopprad[],
48+
) {
4549
if (taxonomyItem.value.additionalData.isCalculatedItem) {
46-
// Räkna automatiskt ut summor
47-
48-
const sumPartBelopprader = belopprader.value.filter((otherBelopprad) =>
50+
const sumPartBelopprader = belopprader.filter((otherBelopprad) =>
4951
props.taxonomyManager.calculationProcessor.isConceptIncludedInSum(
5052
otherBelopprad.taxonomyItemName,
51-
belopprad.value.taxonomyItemName,
53+
belopprad.taxonomyItemName,
5254
),
5355
);
5456
@@ -57,16 +59,26 @@ onMounted(() => {
5759
calculateValuesIntoBelopprad(
5860
props.taxonomyManager.calculationProcessor,
5961
sumPartBelopprader,
60-
belopprad.value,
62+
belopprad,
6163
);
6264
});
6365
}
6466
}
65-
});
67+
}
68+
69+
onMounted(() => createSumWatcher(belopprad.value, belopprader.value));
70+
watch(
71+
[belopprad, belopprader],
72+
([newBelopprad, newBelopprader]) => {
73+
createSumWatcher(newBelopprad, newBelopprader);
74+
},
75+
{ deep: false },
76+
);
6677
</script>
6778

6879
<template>
6980
<BaseEditBeloppradComparable
81+
:allow-delete="allowDelete"
7082
:allow-not="allowNot"
7183
:allowed-value-regex="/^-?\d*$/"
7284
:belopprad="belopprad"

src/components/edit/blocks/belopprad/EditBeloppradNonmonetaryComparable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const belopprad = defineModel<BaseBeloppradComparable>("belopprad", {
2222

2323
<template>
2424
<BaseEditBeloppradComparable
25+
:allow-delete="allowDelete"
2526
:allow-not="allowNot"
2627
:belopprad="belopprad"
2728
:num-previous-years="numPreviousYears"

src/components/edit/blocks/belopprad/EditBeloppradString.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const props = defineProps<{
2020
/** TaxonomyManager för att hantera taxonomiobjekt för beloppraden. */
2121
taxonomyManager: TaxonomyManager;
2222
23+
/** Huruvida borttag ska tillåtas. */
24+
allowDelete: boolean;
25+
2326
/** Huruvida radbrytningar ska vara tillåtna. */
2427
multiline: boolean;
2528
@@ -63,7 +66,13 @@ const trClasses = computed(() => [
6366
/>
6467
</td>
6568
<td>
66-
<button class="btn btn-danger" @click="emit('delete')">X</button>
69+
<button
70+
v-if="allowDelete"
71+
class="btn btn-danger"
72+
@click="emit('delete')"
73+
>
74+
X
75+
</button>
6776
</td>
6877
</tr>
6978
<tr :class="trClasses">
@@ -93,7 +102,7 @@ const trClasses = computed(() => [
93102
<td v-if="!isAbstract" :colspan="comparableNumPreviousYears + 1">
94103
<input v-model="belopprad.text" type="text" />
95104
</td>
96-
<td>
105+
<td v-if="allowDelete">
97106
<BaseEditBeloppradDeleteButton
98107
v-if="!isAbstract"
99108
@delete="emit('delete')"
@@ -111,7 +120,7 @@ const trClasses = computed(() => [
111120
112121
textarea {
113122
@extend %text-input;
114-
123+
115124
min-height: 6rem;
116125
resize: vertical;
117126
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import {
2+
type Belopprad,
3+
createBelopprad,
4+
createBeloppradInList,
5+
deleteBelopprad,
6+
isBeloppradCorrespondsToTaxonomyItem
7+
} from "@/model/arsredovisning/Belopprad.ts";
8+
import { reactive, type Ref, ref, watch } from "vue";
9+
import { type TaxonomyItem, TaxonomyManager } from "@/util/TaxonomyManager.ts";
10+
import type { Arsredovisning, BeloppradSectionName } from "@/model/arsredovisning/Arsredovisning.ts";
11+
import {
12+
isBeloppradHasValidMonetaryValue,
13+
isBeloppradMonetary
14+
} from "@/model/arsredovisning/beloppradtyper/BeloppradMonetary.ts";
15+
16+
/**
17+
* Argument som krävs för att generera en iXBRL-årsredovisning.
18+
*
19+
* @property taxonomyManager - Hanterar taxonomin och ger åtkomst till
20+
* taxonomiobjekt
21+
* @property availableTaxonomyItems - Rotobjekt som innehåller de taxonomiobjekt
22+
* att förpopulera med
23+
* @property arsredovisning - Vue-referens till den aktuella årsredovisningen
24+
* @property sectionName - Namnet på avsnittet i årsredovisningen som ska
25+
* förpopuleras
26+
* @property maxNumPreviousYears - Maximalt antal tidigare räkenskapsår i
27+
* avsnittet.
28+
*/
29+
type Args = {
30+
taxonomyManager: TaxonomyManager;
31+
availableTaxonomyItems: TaxonomyItem;
32+
arsredovisning: Ref<Arsredovisning>;
33+
sectionName: BeloppradSectionName;
34+
maxNumPreviousYears: number;
35+
};
36+
37+
/**
38+
* Funktion för att förpopulera ett specifikt avsnitt i årsredovisningen med
39+
* belopprader baserade på tillgängliga taxonomiobjekt.
40+
*
41+
* @param args - Argument som krävs för förpopuleringen.
42+
*/
43+
44+
function prepopulateSection(args: Args) {
45+
const belopprader = ref<Belopprad[]>([]);
46+
innerPrepopulateSection(args, belopprader);
47+
return belopprader;
48+
}
49+
50+
/**
51+
* Intern hjälpfunktion för att utföra den faktiska förpopuleringen.
52+
*
53+
* TODO: Få att funka med icke-monetära belopprader
54+
*
55+
* @param args - Argument som krävs för förpopuleringen.
56+
* @param belopprader - Vue-referens till resulterande listan med belopprader.
57+
*/
58+
function innerPrepopulateSection(args: Args, belopprader: Ref<Belopprad[]>) {
59+
const {
60+
taxonomyManager,
61+
availableTaxonomyItems,
62+
arsredovisning,
63+
sectionName,
64+
maxNumPreviousYears,
65+
} = args;
66+
67+
const section: Belopprad[] = arsredovisning.value[sectionName];
68+
69+
for (const taxonomyItem of availableTaxonomyItems.childrenFlat) {
70+
// Kontrollera om en belopprad redan finns för det aktuella taxonomiobjektet
71+
let belopprad = section.find((b) =>
72+
isBeloppradCorrespondsToTaxonomyItem(b, taxonomyItem),
73+
);
74+
75+
// Om ingen belopprad finns, skapa en ny reaktiv belopprad
76+
if (!belopprad) {
77+
belopprad = reactive(createBelopprad(taxonomyItem));
78+
}
79+
80+
// Skapa en watcher som triggas när man ändrar beloppraden
81+
watch(belopprad, (newBelopprad: Belopprad) => {
82+
if (isBeloppradMonetary(newBelopprad)) {
83+
if (
84+
(newBelopprad.not?.length ?? 0) > 0 ||
85+
isBeloppradHasValidMonetaryValue(
86+
taxonomyManager,
87+
newBelopprad,
88+
arsredovisning.value,
89+
section,
90+
maxNumPreviousYears,
91+
)
92+
) {
93+
// Om beloppraden innehåller värden, lägg till den i den faktiska
94+
// årsredovisningen
95+
createBeloppradInList(
96+
taxonomyManager,
97+
section,
98+
taxonomyItem,
99+
belopprad,
100+
"all",
101+
);
102+
} else {
103+
// Om beloppraden inte innehåller värden tar vi bort den från den
104+
// faktiska årsredovisningen
105+
deleteBelopprad(taxonomyManager, newBelopprad, section);
106+
}
107+
}
108+
});
109+
110+
belopprader.value.push(belopprad);
111+
}
112+
113+
// Vi måste bevaka ifall en ny årsredovisning skapas - i så fall måste vi
114+
// förpopulera den på nytt
115+
const arsredovisningWatcher = watch(
116+
arsredovisning,
117+
() => {
118+
// Viktigt att stoppa den gamla watchern i och med att det kommer skapas
119+
// en ny när vi kör `innerPrepopulateSection`
120+
arsredovisningWatcher.stop();
121+
122+
belopprader.value.length = 0;
123+
innerPrepopulateSection(args, belopprader);
124+
},
125+
{ deep: false },
126+
);
127+
}
128+
129+
export function usePrepopulateSection(args: Args) {
130+
return {
131+
prepopulateSection: () => prepopulateSection(args),
132+
};
133+
}

0 commit comments

Comments
 (0)