Server IP : 213.176.29.180  /  Your IP : 3.131.38.184
Web Server : Apache
System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
User : webtaragh ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/webtaragh/public_html/whmcs/assets/../modules/reports/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/webtaragh/public_html/whmcs/assets/../modules/reports/support_ticket_replies.php
<?php

use WHMCS\Carbon;
use WHMCS\Database\Capsule;

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

/** @type string $currentmonth */
/** @type int $currentyear */

$dateRange = Carbon::create($year, $month, 1);

$reportdata['title'] = "Support Ticket Replies for " . $currentmonth . " " . $currentyear;
$reportdata['description'] = "This report shows a breakdown of support tickets dealt with per admin for a given month";
$reportdata['monthspagination'] = true;

$reportdata['tableheadings'][] = "Admin";
for ($day = 1; $day <= $dateRange->endOfMonth()->day; $day++) {
    $reportdata['tableheadings'][] = $day;
}

$reportvalues = array();

$result = Capsule::table('tblticketreplies')
    ->where('admin', '!=', '')
    ->whereBetween(
        'date',
        [
            $dateRange->firstOfMonth()->toDateTimeString(),
            $dateRange->endOfMonth()->toDateTimeString(),
        ]
    )
    ->orderBy('admin')
    ->orderBy('date')
    ->groupBy(
        [
            'admin',
            Capsule::raw('date_format(date, \'%e\')'),
        ]
    )
    ->get(
        [
            'admin',
            Capsule::raw('date_format(date, \'%e\') as day_of_month'),
            Capsule::raw('COUNT(tid) as total_replies'),
            Capsule::raw('COUNT(DISTINCT tid) as total_tickets'),
        ]
    )
    ->all();

foreach ($result as $data) {
    $adminname = $data->admin;
    $day = $data->day_of_month;
    $reportvalues[$adminname][$day] = array(
        "totalreplies" => $data->total_replies,
        "totaltickets" => $data->total_tickets,
    );
}

$rc = 0;
foreach ($reportvalues as $adminname => $values) {
    $reportdata['tablevalues'][$rc][] = "**$adminname";

    $rc++;

    $reportdata['tablevalues'][$rc][] = "Tickets";
    $reportdata['tablevalues'][$rc+1][] = "Replies";

    for ($day = 1; $day <= $dateRange->endOfMonth()->day; $day++) {
        $reportdata['tablevalues'][$rc][] = isset($reportvalues[$adminname][$day]['totaltickets'])
            ? $reportvalues[$adminname][$day]['totaltickets']
            : '';
        $reportdata['tablevalues'][$rc+1][] = isset($reportvalues[$adminname][$day]['totalreplies'])
            ? $reportvalues[$adminname][$day]['totalreplies']
            : '';
    }
    $rc += 2;
}