$93 GRAYBYTE WORDPRESS FILE MANAGER $47

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.162.162 | ADMIN IP 216.73.216.51
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/bravetechrwanda/itiministry.org/plugins/give/src/API/Endpoints/Reports/

HOME
Current File : /home/bravetechrwanda/itiministry.org/plugins/give/src/API/Endpoints/Reports//IncomeBreakdown.php
<?php

/**
 * Income over time endpoint
 *
 * @package Give
 */

namespace Give\API\Endpoints\Reports;

class IncomeBreakdown extends Endpoint
{

    protected $payments;

    public function __construct()
    {
        $this->endpoint = 'income-breakdown';
    }

    public function getReport($request)
    {
        $start = date_create($request->get_param('start'));
        $end = date_create($request->get_param('end'));
        $diff = date_diff($start, $end);

        $dataset = [];

        switch (true) {
            case ($diff->days > 365):
                $data = $this->get_data($start, $end, 'P1M');
                break;
            case ($diff->days > 60):
                $data = $this->get_data($start, $end, 'P1W');
                break;
            case ($diff->days > 5):
                $data = $this->get_data($start, $end, 'P1D');
                break;
            case ($diff->days >= 0):
                $data = $this->get_data($start, $end, 'PT1H');
                break;
        }

        return $data;
    }

    public function get_data($start, $end, $intervalStr)
    {
        $data = [];

        $interval = new \DateInterval($intervalStr);

        $periodStart = clone $start;
        $periodEnd = clone $start;

        // Subtract interval to set up period start
        date_sub($periodStart, $interval);

        while ($periodStart < $end) {
            $values = $this->get_values($periodStart->format('Y-m-d H:i:s'), $periodEnd->format('Y-m-d H:i:s'));

            $incomeForPeriod = $values['income'];
            $donorsForPeriod = $values['donors'];
            $refundsForPeriod = $values['refunds'];
            $netForPeriod = $values['net'];

            switch ($intervalStr) {
                case 'P1M':
                    $periodLabel = $periodEnd->format('F Y');
                    break;
                case 'P1D':
                    $periodLabel = $periodStart->format('F j, Y');
                    break;
                case 'PT1H':
                    $periodLabel = $periodEnd->format('l ga');
                    break;
                default:
                    $periodLabel = $periodEnd->format('F j, Y');
            }

            $data[] = [
                __('Date', 'give') => $periodLabel,
                __('Donors', 'give') => $donorsForPeriod,
                __('Donations', 'give') => $incomeForPeriod,
                __('Refunds', 'give') => $refundsForPeriod,
                __('Net', 'give') => $netForPeriod,
            ];

            // Add interval to set up next period
            date_add($periodStart, $interval);
            date_add($periodEnd, $interval);
        }

        return $data;
    }

    public function get_values($startStr, $endStr)
    {
        $paymentObjects = $this->getPayments($startStr, $endStr);

        $income = 0;
        $refundTotal = 0;
        $refunds = 0;
        $donors = [];

        foreach ($paymentObjects as $paymentObject) {
            if ($paymentObject->date > $startStr && $paymentObject->date <= $endStr) {
                switch ($paymentObject->status) {
                    case 'give_subscription':
                    case 'publish':
                    {
                        $income += $paymentObject->total;
                        $donors[] = $paymentObject->donor_id;
                        break;
                    }
                    case 'refunded':
                    {
                        $refunds += 1;
                        $income += $paymentObject->total;
                        $refundTotal += $paymentObject->total;
                        break;
                    }
                }
            }
        }

        $unique = array_unique($donors);

        return [
            'income' => give_currency_filter(
                give_format_amount($income),
                [
                    'currency_code' => $this->currency,
                    'decode_currency' => true,
                    'sanitize' => false,
                ]
            ),
            'donors' => count($unique),
            'refunds' => $refunds,
            'net' => give_currency_filter(
                give_format_amount($income - $refundTotal),
                [
                    'currency_code' => $this->currency,
                    'decode_currency' => true,
                    'sanitize' => false,
                ]
            ),
        ];
    }

}

Current_dir [ WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
25 May 2026 4.20 PM
bravetechrwanda / bravetechrwanda
0755
AverageDonation.php
6.889 KB
17 Jun 2022 4.03 AM
bravetechrwanda / bravetechrwanda
0644
DonationsVsIncome.php
2.99 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
Endpoint.php
11.735 KB
28 Jan 2026 8.00 PM
bravetechrwanda / bravetechrwanda
0644
FormPerformance.php
4.083 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
Income.php
4.313 KB
17 Jun 2022 4.03 AM
bravetechrwanda / bravetechrwanda
0644
IncomeBreakdown.php
4.339 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
PaymentMethods.php
2.419 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
PaymentStatuses.php
3.766 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
RecentDonations.php
2.134 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
TopDonors.php
2.963 KB
24 Nov 2021 4.55 AM
bravetechrwanda / bravetechrwanda
0644
TotalDonors.php
5.502 KB
17 Jun 2022 4.03 AM
bravetechrwanda / bravetechrwanda
0644
TotalIncome.php
6.009 KB
17 Jun 2022 4.03 AM
bravetechrwanda / bravetechrwanda
0644
TotalRefunds.php
5.35 KB
17 Jun 2022 4.03 AM
bravetechrwanda / bravetechrwanda
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF Static GIF