132 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			132 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <script lang="ts">
 | |
| import { defineComponent } from "vue"
 | |
| import { IMPORT_YNAB } from "../store/action-types";
 | |
| import { TITLE } from "../store/mutation-types"
 | |
| 
 | |
| export default defineComponent({
 | |
|     data() {
 | |
|         return {
 | |
|             transactionsFile: null,
 | |
|             assignmentsFile: null
 | |
|         }
 | |
|     },
 | |
|     computed: {
 | |
|         filesIncomplete() {
 | |
|             return this.$data.transactionsFile == null || this.$data.assignmentsFile == null;
 | |
|         }
 | |
|     },
 | |
|     mounted() {
 | |
|         this.$store.commit(TITLE, "Settings")
 | |
|     },
 | |
|     methods: {
 | |
|         gotAssignments(e) {
 | |
|             this.$data.assignmentsFile = e.target.files[0];
 | |
|         },
 | |
|         gotTransactions(e) {
 | |
|             this.$data.transactionsFile = e.target.files[0];
 | |
|         },
 | |
|         deleteBudget() {
 | |
|             fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID, {
 | |
|                 method: "DELETE",
 | |
|                 headers: {
 | |
|                     'Authorization': 'Bearer ' + this.$store.state.Session.Token
 | |
|                 },
 | |
|             });
 | |
|             this.$store.commit("deleteBudget", this.$store.getters.CurrentBudget.ID)
 | |
|             this.$router.push("/")
 | |
|         },
 | |
|         clearBudget() {
 | |
|             fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", {
 | |
|                 method: "POST",
 | |
|                 headers: {
 | |
|                     'Authorization': 'Bearer ' + this.$store.state.Session.Token
 | |
|                 },
 | |
|             })
 | |
|         },
 | |
|         cleanNegative() {
 | |
|             // <a href="/budget/{{.Budget.ID}}/settings/clean-negative">Fix all historic negative category-balances</a>
 | |
|         },
 | |
|         ynabImport() {
 | |
|             let formData = new FormData();
 | |
|             formData.append("transactions", this.$data.transactionsFile);
 | |
|             formData.append("assignments", this.$data.assignmentsFile);
 | |
|             this.$store.dispatch(IMPORT_YNAB, formData);
 | |
|         }
 | |
|     }
 | |
| })
 | |
| </script>
 | |
| 
 | |
| <template>
 | |
|     <v-container>
 | |
|         <h1>Danger Zone</h1>
 | |
|         <v-row>
 | |
|             <v-col cols="12" md="6" xl="3">
 | |
|                 <v-card>
 | |
|                     <v-card-header>
 | |
|                         <v-card-header-text>
 | |
|                             <v-card-title>Clear Budget</v-card-title>
 | |
|                             <v-card-subtitle>This removes transactions and assignments to start from scratch. Accounts and categories are kept. Not undoable!</v-card-subtitle>
 | |
|                         </v-card-header-text>
 | |
|                     </v-card-header>
 | |
|                     <v-card-actions class="justify-center">
 | |
|                         <v-btn @click="clearBudget" color="error">Clear budget</v-btn>
 | |
|                     </v-card-actions>
 | |
|                 </v-card>
 | |
|             </v-col>
 | |
|             <v-col cols="12" md="6" xl="3">
 | |
|                 <v-card>
 | |
|                     <v-card-header>
 | |
|                         <v-card-header-text>
 | |
|                             <v-card-title>Delete Budget</v-card-title>
 | |
|                             <v-card-subtitle>This deletes the whole bugdet including all transactions, assignments, accounts and categories. Not undoable!</v-card-subtitle>
 | |
|                         </v-card-header-text>
 | |
|                     </v-card-header>
 | |
|                     <v-card-actions class="justify-center">
 | |
|                         <v-btn @click="deleteBudget" color="error">Delete budget</v-btn>
 | |
|                     </v-card-actions>
 | |
|                 </v-card>
 | |
|             </v-col>
 | |
|             <v-col cols="12" md="6" xl="3">
 | |
|                 <v-card>
 | |
|                     <v-card-header>
 | |
|                         <v-card-header-text>
 | |
|                             <v-card-title>Fix all historic negative category-balances</v-card-title>
 | |
|                             <v-card-subtitle>This restores YNABs functionality, that would substract any overspent categories' balances from next months inflows.</v-card-subtitle>
 | |
|                         </v-card-header-text>
 | |
|                     </v-card-header>
 | |
|                     <v-card-actions class="justify-center">
 | |
|                         <v-btn @click="cleanNegative" color="primary">Fix negative</v-btn>
 | |
|                     </v-card-actions>
 | |
|                 </v-card>
 | |
|             </v-col>
 | |
|             <v-col cols="12" xl="6">
 | |
|                 <v-card>
 | |
|                     <v-card-header>
 | |
|                         <v-card-header-text>
 | |
|                             <v-card-title>Import YNAB Budget</v-card-title>
 | |
|                         </v-card-header-text>
 | |
|                     </v-card-header>
 | |
| 
 | |
|                     <label for="transactions_file">
 | |
|                         Transaktionen:
 | |
|                         <input type="file" @change="gotTransactions" accept="text/*" />
 | |
|                     </label>
 | |
|                     <br />
 | |
|                     <label for="assignments_file">
 | |
|                         Budget:
 | |
|                         <input type="file" @change="gotAssignments" accept="text/*" />
 | |
|                     </label>
 | |
| 
 | |
|                     <v-card-actions class="justify-center">
 | |
|                         <v-btn
 | |
|                             :disabled="filesIncomplete"
 | |
|                             @click="ynabImport"
 | |
|                             color="primary"
 | |
|                         >Importieren</v-btn>
 | |
|                     </v-card-actions>
 | |
|                 </v-card>
 | |
|             </v-col>
 | |
|         </v-row>
 | |
|         <v-card></v-card>
 | |
|     </v-container>
 | |
| </template> |