1
0
Fork 0
forked from Kispi/Core

feat(webapp): add seed capital to state portal
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Giesel 2023-07-12 16:00:52 +02:00
parent cd5c7d1569
commit f1e7c0b514
2 changed files with 66 additions and 2 deletions

View file

@ -152,6 +152,22 @@
<TableCellsIcon class="h-5 w-5" /> <TableCellsIcon class="h-5 w-5" />
Stammdaten importieren Stammdaten importieren
</button> </button>
<div>
<span>Startkapital auszahlen:</span>
<div class="flex gap-2">
<AtomCurrencyInput
v-model="seedCapital"
class="w-1/2"
placeholder="Startkapital"
/>
<button
class="btn grow"
@click="verifySeedCapitalModal?.show()"
>
Auszahlen
</button>
</div>
</div>
</div> </div>
<div <div
v-if="importPending" v-if="importPending"
@ -169,6 +185,22 @@
<span>Daten wurden erfolgreich importiert.</span> <span>Daten wurden erfolgreich importiert.</span>
</div> </div>
</div> </div>
<div
v-if="capitalPending"
class="toast z-10"
>
<div class="alert alert-info">
<span>Startkapital wird überwiesen. Bitte warten...</span>
</div>
</div>
<div
v-if="capitalDone"
class="toast z-10"
>
<div class="alert alert-success">
<span>Startkapital wurden erfolgreich überwiesen.</span>
</div>
</div>
</AtomCard> </AtomCard>
<MoleculeErrorModal <MoleculeErrorModal
id="error-modal" id="error-modal"
@ -176,13 +208,21 @@
v-model="errorMsg" v-model="errorMsg"
title="Fehler beim Importieren bei folgenden Datensätzen" title="Fehler beim Importieren bei folgenden Datensätzen"
/> />
<MoleculeVerifyModal
id="verify-seed-capital-modal"
ref="verifySeedCapitalModal"
title="Startkapital auszahlen"
@confirm="paySeedCapital"
>
<p>Wirklich jedem Bürger ein Startkapital von {{ CurrencyService.toString((seedCapital ?? 0) * 100) }} auszahlen?</p>
</MoleculeVerifyModal>
</OrganismAuthWrapper> </OrganismAuthWrapper>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { SettingsResponse } from '../../types/pocketbase.types'; import { SettingsResponse, TransactionsResponse } from '../../types/pocketbase.types';
import { AccountService } from '../../services/account.service'; import { AccountService } from '../../services/account.service';
import { CompanyService } from '../../services/company.service'; import { CompanyService } from '../../services/company.service';
import { SettingsService } from '../../services/settings.service'; import { SettingsService } from '../../services/settings.service';
@ -207,9 +247,13 @@ import OrganismAuthWrapper from '../organisms/OrganismAuthWrapper.vue';
import MoleculeImportDataModal from '../molecules/MoleculeImportDataModal.vue'; import MoleculeImportDataModal from '../molecules/MoleculeImportDataModal.vue';
import MoleculeErrorModal from '../molecules/MoleculeErrorModal.vue'; import MoleculeErrorModal from '../molecules/MoleculeErrorModal.vue';
import { DateService } from '../../services/date.service'; import { DateService } from '../../services/date.service';
import MoleculeVerifyModal from '../molecules/MoleculeVerifyModal.vue';
import { CurrencyService } from '../../services/currency.service';
import { BankService } from '../../services/bank.service';
const importAccountsModal = ref<InstanceType<typeof MoleculeImportDataModal>>(); const importAccountsModal = ref<InstanceType<typeof MoleculeImportDataModal>>();
const importCompaniesModal = ref<InstanceType<typeof MoleculeImportDataModal>>(); const importCompaniesModal = ref<InstanceType<typeof MoleculeImportDataModal>>();
const verifySeedCapitalModal = ref<InstanceType<typeof MoleculeVerifyModal>>();
const errorModal = ref<InstanceType<typeof MoleculeErrorModal>>(); const errorModal = ref<InstanceType<typeof MoleculeErrorModal>>();
const minWage = ref<number>(); const minWage = ref<number>();
const incomeTax = ref<number>(); const incomeTax = ref<number>();
@ -221,7 +265,10 @@ const settingsSaveSuccess = ref<boolean>(false);
const settingsSaveError = ref<boolean>(false); const settingsSaveError = ref<boolean>(false);
const importPending = ref<boolean>(false); const importPending = ref<boolean>(false);
const importDone = ref<boolean>(false); const importDone = ref<boolean>(false);
const capitalPending = ref<boolean>(false);
const capitalDone = ref<boolean>(false);
const errorMsg = ref<string>(); const errorMsg = ref<string>();
const seedCapital = ref<number>();
const createdCompanies = ref<{ name: string, password: string }[]>([]); const createdCompanies = ref<{ name: string, password: string }[]>([]);
const serverTime = ref<Date>(); const serverTime = ref<Date>();
@ -336,6 +383,23 @@ async function saveSettings() {
}, 5000); }, 5000);
} }
} }
async function paySeedCapital() {
capitalPending.value = true;
verifySeedCapitalModal.value?.close();
const accounts = await AccountService.getAccounts();
const promises: Promise<TransactionsResponse>[] = [];
accounts.forEach((account) => {
promises.push(BankService.addTransaction(account.id, (seedCapital.value ?? 0), 'Startkapital'));
});
await Promise.all(promises);
capitalPending.value = false;
capitalDone.value = true;
const timeout = setTimeout(() => {
capitalDone.value = false;
clearTimeout(timeout);
}, 5000);
}
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View file

@ -20,7 +20,7 @@ export class BankService {
public static async addTransaction(accountId: string, public static async addTransaction(accountId: string,
amount: number, amount: number,
type: TransactionType | string, type: TransactionType | string,
accountType: AccountType = AccountType.ACCOUNT, accountType = AccountType.ACCOUNT,
): Promise<TransactionsResponse> { ): Promise<TransactionsResponse> {
let label = ''; let label = '';
switch (type) { switch (type) {