PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / Subscriptions / resources / admin / components / SubscriptionDetailsPage / Tabs / Overview / SubscriptionAnnualProjection / utils.ts

utils.ts in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/Subscriptions/resources/admin/components/SubscriptionDetailsPage/Tabs/Overview/SubscriptionAnnualProjection/utils.ts

83 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Donation } from '@givewp/donations/admin/components/types';
2 import { ApexOptions } from 'apexcharts';
3 import { getCompletedDonations } from '../SubscriptionStats';
4
5 /**
6 * Get completed donations for the current year
7 *
8 * @since 4.8.0
9 */
10 export const getCurrentYearCompletedDonations = (donations: Donation[]): Donation[] => {
11 const completedDonations = getCompletedDonations(donations);
12 const currentYear = new Date().getFullYear();
13
14 return completedDonations?.filter(donation => {
15 const donationDate = new Date(donation.createdAt);
16 return donationDate.getFullYear() === currentYear;
17 });
18 };
19
20 /**
21 * Calculate total contributions from completed donations
22 *
23 * @since 4.8.0
24 */
25 export const calculateTotalContributions = (completedDonations: Donation[]): number => {
26 if (!completedDonations) {
27 return 0;
28 }
29
30 return completedDonations?.reduce((acc, donation) => acc + Number(donation.amount.value), 0);
31 };
32
33 /**
34 * Calculate progress percentage based on completed vs projected amounts
35 *
36 * @since 4.8.0
37 */
38 export const calculateProgressPercentage = (completedAmount: number, projectedAmount: number): number => {
39 const progress = Math.ceil((completedAmount / projectedAmount) * 100);
40
41 return Math.min(progress, 100);
42 };
43
44 /**
45 * @since 4.8.0
46 */
47 export const chartOptions = (label: string): ApexOptions => {
48 return {
49 chart: {
50 height: 1024,
51 type: 'radialBar',
52 },
53 plotOptions: {
54 radialBar: {
55 hollow: {
56 margin: 15,
57 size: '60%',
58 },
59 dataLabels: {
60 /**
61 * The "name" is the top label, here it is the value/amount
62 * The "value" is the percent progress
63 */
64 name: {
65 offsetY: 20,
66 show: true,
67 color: '#4B5563',
68 fontSize: '12px',
69 },
70 value: {
71 offsetY: -20,
72 color: '#060C1A',
73 fontSize: '24px',
74 show: true,
75 },
76 },
77 },
78 },
79 colors: ['#459948'],
80 labels: [label],
81 };
82 };
83