Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Classes/Dashboard/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Classes/Dashboard/Entries.php
<?php

namespace Corals\Modules\Timesheet\Classes\Dashboard;

use Corals\Modules\Timesheet\Facades\Timesheet;
use Corals\Modules\Timesheet\Models\Entry;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class Entries
{
    protected $from_date;
    protected $to_date;

    public function __construct(Request $request)
    {
        $this->from_date = $request->get('from_date', now()->subMonth()->startOfMonth());
        $this->to_date = $request->get('to_date', now()->subMonth()->endOfMonth());
    }

    public function entriesLatest()
    {
        $tableData = [];
        Entry::query()
            ->whereBetween('spent_at', [$this->from_date, $this->to_date])
            ->with(['invoice', 'project', 'project.client'])
            ->join('users', 'users.id', '=', 'timesheet_entries.user_id')
            ->join('timesheet_projects', 'timesheet_projects.id', '=', 'timesheet_entries.project_id')
            ->join('timesheet_activities', 'timesheet_activities.id', '=', 'timesheet_entries.activity_id')
            ->select('timesheet_entries.spent_at', 'timesheet_entries.hours', 'timesheet_entries.minutes',
                'timesheet_entries.project_id',
                'timesheet_entries.evaluation_hours', 'timesheet_entries.evaluation_minutes', 'timesheet_entries.amount',
                'timesheet_entries.cost', 'users.name as user', 'users.id as user_id',
                'timesheet_activities.title as activity', 'timesheet_entries.description', 'timesheet_entries.invoice_id')
            ->latest('timesheet_entries.spent_at')
            ->take(5)
            ->get()
            ->each(function (Entry $entry) use (&$tableData) {
                $entryArr = $entry->toArray();
                $entryArr['time'] = Timesheet::formatHoursAndMinutes($entryArr['hours'], $entryArr['minutes']);
                $entryArr['evaluation'] = Timesheet::formatHoursAndMinutes($entryArr['evaluation_hours'], $entryArr['evaluation_minutes']);

                $entryArr['invoice'] = '-';

                if ($entryArr['invoice_id']) {
                    $entryArr['invoice'] = '<a href="' . '/invoices/' . $entry->invoice->id . '">'
                        . $entry->invoice->code . '</a>';
                }

                if ($entryArr['project_id']) {
                    $project = $entry->project;
                    $client = $project->client;

                    $entryArr['project'] = '<a href="' . '/clients/' . $project->client_id . '/projects/' . $project->id . '">'
                        . $client->name . ' - ' . $project->name . '</a>';
                }
                if ($entryArr['user_id']) {
                    $entryArr['user'] = '<a href="' . '/users/' . $entryArr['user_id'] . '">' . $entryArr['user'] . '</a>';
                }

                $tableData[] = Arr::except($entryArr, [
                    'hours',
                    'minutes',
                    'evaluation_minutes',
                    'evaluation_hours',
                    'invoice_id',
                    'user_id',
                    'project_id'
                ]);
            });

        return [
            'label' => ucwords('latest entries'),
            'tableData' => $tableData,
        ];
    }

    public function getTimePerProject()
    {
        $data = Entry::query()
            ->whereBetween('spent_at', [$this->from_date, $this->to_date])
            ->join('timesheet_projects', 'timesheet_projects.id', '=', 'timesheet_entries.project_id')
            ->join('timesheet_clients', 'timesheet_clients.id', '=', 'timesheet_projects.client_id')
            ->selectRaw("round(((SUM(ifNull(hours*60,0)) + SUM(ifNull(minutes,0)))/60),2) as hours,
            CONCAT(timesheet_clients.name,' - ',timesheet_projects.name) as label")
            ->groupBy('project_id')
            ->get()->toArray();


        $chartData = [];
        if ($data) {
            $chartData['labels'] = array_column($data, 'label');
            $chartData['datasets'] = [[
                'backgroundColor' => ["rgb(255, 205, 86)", "#e092d8", "#666cba", "rgb(255, 99, 132)", "#5e4548",
                    "#28a745", "#d9534a", "#4d0702", "#2bcccc", "#5c0e54", "rgb(54, 162, 235)", "#a67189", "#296666", "#182080"],
                'data' => array_column($data, 'hours')
            ]];
        }
        return [
            'chartData' => $chartData,
            'label' => 'Projects Hours',
        ];

    }

}

Spamworldpro Mini