parent
cac34db1fd
commit
ccf865687b
@ -5,18 +5,16 @@
|
|||||||
import Toastify from "toastify-js";
|
import Toastify from "toastify-js";
|
||||||
import DonationsEmptyState from "./DonationsEmptyState.svelte";
|
import DonationsEmptyState from "./DonationsEmptyState.svelte";
|
||||||
import AddDonationPaymentModal from "./AddDonationPaymentModal.svelte";
|
import AddDonationPaymentModal from "./AddDonationPaymentModal.svelte";
|
||||||
|
import { onMount } from "svelte";
|
||||||
$: searchvalue = "";
|
$: searchvalue = "";
|
||||||
$: active_deletes = [];
|
$: active_deletes = [];
|
||||||
|
$: dataLoaded = false;
|
||||||
export let current_donations = [];
|
export let current_donations = [];
|
||||||
export let payment_modal_open = false;
|
export let payment_modal_open = false;
|
||||||
export let editable = {};
|
export let editable = {};
|
||||||
export let original_data = {};
|
export let original_data = {};
|
||||||
export let paid_amount_input = 0;
|
export let paid_amount_input = 0;
|
||||||
const donations_promise = DonationService.donationControllerGetAll().then(
|
|
||||||
(val) => {
|
|
||||||
current_donations = val;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
function should_display_based_on_id(id) {
|
function should_display_based_on_id(id) {
|
||||||
if (searchvalue.toString().slice(-1) === "*") {
|
if (searchvalue.toString().slice(-1) === "*") {
|
||||||
return id.toString().startsWith(searchvalue.replace("*", ""));
|
return id.toString().startsWith(searchvalue.replace("*", ""));
|
||||||
@ -26,210 +24,252 @@
|
|||||||
function open_payment_modal(donation) {
|
function open_payment_modal(donation) {
|
||||||
editable = Object.assign({}, donation);
|
editable = Object.assign({}, donation);
|
||||||
original_data = Object.assign({}, donation);
|
original_data = Object.assign({}, donation);
|
||||||
paid_amount_input = (donation.paidAmount/100).toFixed(2);
|
paid_amount_input = (donation.paidAmount / 100).toFixed(2);
|
||||||
payment_modal_open = true;
|
payment_modal_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
let page = 0;
|
||||||
|
while (page >= 0) {
|
||||||
|
const donations = await DonationService.donationControllerGetAll(
|
||||||
|
page,
|
||||||
|
500
|
||||||
|
);
|
||||||
|
if (donations.length == 0) {
|
||||||
|
page = -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_donations = current_donations.concat(...donations);
|
||||||
|
|
||||||
|
if (page == 0) {
|
||||||
|
dataLoaded = true;
|
||||||
|
}
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
console.log("All donations loaded");
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AddDonationPaymentModal bind:current_donations bind:original_data bind:editable bind:paid_amount_input bind:payment_modal_open />
|
<AddDonationPaymentModal
|
||||||
{#if store.state.jwtinfo.userdetails.permissions.includes('DONATION:GET')}
|
bind:current_donations
|
||||||
{#await donations_promise}
|
bind:original_data
|
||||||
|
bind:editable
|
||||||
|
bind:paid_amount_input
|
||||||
|
bind:payment_modal_open
|
||||||
|
/>
|
||||||
|
{#if store.state.jwtinfo.userdetails.permissions.includes("DONATION:GET")}
|
||||||
|
{#if !dataLoaded}
|
||||||
<div
|
<div
|
||||||
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
|
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
|
||||||
role="alert">
|
role="alert"
|
||||||
|
>
|
||||||
<p class="font-bold">donations are being loaded</p>
|
<p class="font-bold">donations are being loaded</p>
|
||||||
<p class="text-sm">{$_('this-might-take-a-moment')}</p>
|
<p class="text-sm">{$_("this-might-take-a-moment")}</p>
|
||||||
</div>
|
</div>
|
||||||
{:then}
|
{:else if current_donations.length === 0}
|
||||||
{#if current_donations.length === 0}
|
<DonationsEmptyState />
|
||||||
<DonationsEmptyState />
|
{:else}
|
||||||
{:else}
|
<input
|
||||||
<input
|
type="search"
|
||||||
type="search"
|
bind:value={searchvalue}
|
||||||
bind:value={searchvalue}
|
placeholder={$_("datatable.search")}
|
||||||
placeholder={$_('datatable.search')}
|
aria-label={$_("datatable.search")}
|
||||||
aria-label={$_('datatable.search')}
|
class="mb-4"
|
||||||
class="mb-4" />
|
/>
|
||||||
<div
|
<div
|
||||||
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll">
|
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll"
|
||||||
<table class="divide-y divide-gray-200 w-full">
|
>
|
||||||
<thead class="bg-gray-50">
|
<table class="divide-y divide-gray-200 w-full">
|
||||||
<tr>
|
<thead class="bg-gray-50">
|
||||||
<th
|
<tr>
|
||||||
scope="col"
|
<th
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
scope="col"
|
||||||
{$_('donor')}
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
</th>
|
>
|
||||||
<th
|
{$_("donor")}
|
||||||
scope="col"
|
</th>
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th
|
||||||
{$_('runner')}
|
scope="col"
|
||||||
</th>
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
<th
|
>
|
||||||
scope="col"
|
{$_("runner")}
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
</th>
|
||||||
{$_('amount-per-kilometer')}
|
<th
|
||||||
</th>
|
scope="col"
|
||||||
<th
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
scope="col"
|
>
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
{$_("amount-per-kilometer")}
|
||||||
{$_('donation-amount')}
|
</th>
|
||||||
</th>
|
<th
|
||||||
<th
|
scope="col"
|
||||||
scope="col"
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
>
|
||||||
{$_('paid-amount')}
|
{$_("donation-amount")}
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
{$_('status')}
|
>
|
||||||
</th>
|
{$_("paid-amount")}
|
||||||
<th scope="col" class="relative px-6 py-3">
|
</th>
|
||||||
<span class="sr-only">{$_('action')}</span>
|
<th
|
||||||
</th>
|
scope="col"
|
||||||
</tr>
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
</thead>
|
>
|
||||||
<tbody class="divide-y divide-gray-200">
|
{$_("status")}
|
||||||
{#each current_donations as donation}
|
</th>
|
||||||
{#if donation.donor.firstname
|
<th scope="col" class="relative px-6 py-3">
|
||||||
|
<span class="sr-only">{$_("action")}</span>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-200">
|
||||||
|
{#each current_donations as donation}
|
||||||
|
{#if donation.donor.firstname
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(searchvalue.toLowerCase()) || donation.donor.lastname
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.includes(
|
.includes(searchvalue.toLowerCase()) || donation.runner?.firstname
|
||||||
searchvalue.toLowerCase()
|
.toLowerCase()
|
||||||
) || donation.donor.lastname
|
.includes(searchvalue.toLowerCase()) || donation.runner?.lastname
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.includes(
|
.includes(searchvalue.toLowerCase()) || should_display_based_on_id(donation.id)}
|
||||||
searchvalue.toLowerCase()
|
<tr data-rowid="donation_{donation.id}">
|
||||||
) || donation.runner?.firstname
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
.toLowerCase()
|
<div class="flex items-center">
|
||||||
.includes(
|
<a
|
||||||
searchvalue.toLowerCase()
|
href="../donors/{donation.donor.id}"
|
||||||
) || donation.runner?.lastname
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
||||||
.toLowerCase()
|
>{donation.donor.firstname}
|
||||||
.includes(
|
{donation.donor.middlename || ""}
|
||||||
searchvalue.toLowerCase()
|
{donation.donor.lastname}</a
|
||||||
) || should_display_based_on_id(donation.id)}
|
>
|
||||||
<tr data-rowid="donation_{donation.id}">
|
</div>
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
</td>
|
||||||
<div class="flex items-center">
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
|
{#if donation.runner}
|
||||||
|
<div class="text-sm font-medium text-gray-900">
|
||||||
<a
|
<a
|
||||||
href="../donors/{donation.donor.id}"
|
href="../runners/{donation.runner.id}"
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">{donation.donor.firstname}
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
||||||
{donation.donor.middlename || ''}
|
>{donation.runner.firstname}
|
||||||
{donation.donor.lastname}</a>
|
{donation.runner.middlename || ""}
|
||||||
|
{donation.runner.lastname}</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
{#if donation.runner}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
<a
|
|
||||||
href="../runners/{donation.runner.id}"
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">{donation.runner.firstname}
|
|
||||||
{donation.runner.middlename || ''}
|
|
||||||
{donation.runner.lastname}</a>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{$_('fixed-donation')}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
{#if donation.amountPerDistance}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.amountPerDistance / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString('de-DE', { valute: 'EUR' })}€
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{$_('fixed-donation')}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.amount / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString('de-DE', { valute: 'EUR' })}€
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.paidAmount / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString('de-DE', { valute: 'EUR' })}€
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
{#if donation.status =="PAID"}
|
|
||||||
<span
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">{$_('paid')}</span>
|
|
||||||
{:else}
|
|
||||||
<span
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">{$_('open')}</span>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
{#if active_deletes[donation.id] === true}
|
|
||||||
<td
|
|
||||||
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
active_deletes[donation.id] = false;
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer">{$_('cancel-delete')}</button>
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
DonationService.donationControllerRemove(donation.id, false).then(
|
|
||||||
(resp) => {
|
|
||||||
current_donations = current_donations.filter(
|
|
||||||
(obj) => obj.id !== donation.id
|
|
||||||
);
|
|
||||||
Toastify({
|
|
||||||
text: $_('donation-deleted'),
|
|
||||||
duration: 500,
|
|
||||||
backgroundColor:
|
|
||||||
'linear-gradient(to right, #00b09b, #96c93d)',
|
|
||||||
}).showToast();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">{$_('confirm-delete')}</button>
|
|
||||||
</td>
|
|
||||||
{:else}
|
{:else}
|
||||||
<td
|
<div class="text-sm font-medium text-gray-900">
|
||||||
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
{$_("fixed-donation")}
|
||||||
<button
|
</div>
|
||||||
on:click={() => {open_payment_modal(donation);}}
|
|
||||||
class="text-[#025a21] hover:text-green-900 mr-4">{$_('enter-payment')}</button>
|
|
||||||
<a
|
|
||||||
href="./{donation.id}"
|
|
||||||
class="text-indigo-600 hover:text-indigo-900">{$_('details')}</a>
|
|
||||||
{#if store.state.jwtinfo.userdetails.permissions.includes('DONATION:DELETE')}
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
active_deletes[donation.id] = true;
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">{$_('delete')}</button>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
{/if}
|
{/if}
|
||||||
</tr>
|
</td>
|
||||||
{/if}
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
{/each}
|
{#if donation.amountPerDistance}
|
||||||
</tbody>
|
<div class="text-sm font-medium text-gray-900">
|
||||||
</table>
|
{(donation.amountPerDistance / 100)
|
||||||
</div>
|
.toFixed(2)
|
||||||
{/if}
|
.toLocaleString("de-DE", { valute: "EUR" })}€
|
||||||
{:catch error}
|
</div>
|
||||||
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
|
{:else}
|
||||||
<span class="inline-block align-middle mr-8">
|
<div class="text-sm font-medium text-gray-900">
|
||||||
<b class="capitalize">{$_('general_promise_error')}</b>
|
{$_("fixed-donation")}
|
||||||
{error}
|
</div>
|
||||||
</span>
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
|
<div class="text-sm font-medium text-gray-900">
|
||||||
|
{(donation.amount / 100)
|
||||||
|
.toFixed(2)
|
||||||
|
.toLocaleString("de-DE", { valute: "EUR" })}€
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
|
<div class="text-sm font-medium text-gray-900">
|
||||||
|
{(donation.paidAmount / 100)
|
||||||
|
.toFixed(2)
|
||||||
|
.toLocaleString("de-DE", { valute: "EUR" })}€
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
|
{#if donation.status == "PAID"}
|
||||||
|
<span
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"
|
||||||
|
>{$_("paid")}</span
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<span
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800"
|
||||||
|
>{$_("open")}</span
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
{#if active_deletes[donation.id] === true}
|
||||||
|
<td
|
||||||
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
active_deletes[donation.id] = false;
|
||||||
|
}}
|
||||||
|
tabindex="0"
|
||||||
|
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer"
|
||||||
|
>{$_("cancel-delete")}</button
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
DonationService.donationControllerRemove(
|
||||||
|
donation.id,
|
||||||
|
false
|
||||||
|
).then((resp) => {
|
||||||
|
current_donations = current_donations.filter(
|
||||||
|
(obj) => obj.id !== donation.id
|
||||||
|
);
|
||||||
|
Toastify({
|
||||||
|
text: $_("donation-deleted"),
|
||||||
|
duration: 500,
|
||||||
|
backgroundColor:
|
||||||
|
"linear-gradient(to right, #00b09b, #96c93d)",
|
||||||
|
}).showToast();
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
tabindex="0"
|
||||||
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
|
||||||
|
>{$_("confirm-delete")}</button
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
{:else}
|
||||||
|
<td
|
||||||
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
open_payment_modal(donation);
|
||||||
|
}}
|
||||||
|
class="text-[#025a21] hover:text-green-900 mr-4"
|
||||||
|
>{$_("enter-payment")}</button
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="./{donation.id}"
|
||||||
|
class="text-indigo-600 hover:text-indigo-900"
|
||||||
|
>{$_("details")}</a
|
||||||
|
>
|
||||||
|
{#if store.state.jwtinfo.userdetails.permissions.includes("DONATION:DELETE")}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
active_deletes[donation.id] = true;
|
||||||
|
}}
|
||||||
|
tabindex="0"
|
||||||
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
|
||||||
|
>{$_("delete")}</button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
{/if}
|
||||||
|
</tr>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{/await}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user