162 lines
4.6 KiB
PHP
162 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Log;
|
|
use App\Repositories\Customer\CustomerRepositoryInterface;
|
|
use App\Repositories\Invoice\InvoiceRepositoryInterface;
|
|
use App\Repositories\Log\LogRepositoryInterface;
|
|
use App\Repositories\Module\Hosting\HostingRepositoryInterface;
|
|
use App\Repositories\Module\Vmware\VmwareRepositoryInterface;
|
|
use App\Repositories\Order\OrderRepositoryInterface;
|
|
use App\Repositories\Post\PostRepositoryInterface;
|
|
use App\Repositories\Staff\StaffRepositoryInterface;
|
|
use App\Repositories\Ticket\TicketRepositoryInterface;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
class MainController extends Controller
|
|
{
|
|
//
|
|
public function __construct(
|
|
public InvoiceRepositoryInterface $invoiceRepository,
|
|
public OrderRepositoryInterface $orderRepository,
|
|
public TicketRepositoryInterface $ticketRepository,
|
|
public CustomerRepositoryInterface $customerRepository,
|
|
public PostRepositoryInterface $postRepository,
|
|
public LogRepositoryInterface $logRepository,
|
|
public VmwareRepositoryInterface $vmwareRepository,
|
|
public HostingRepositoryInterface $moduleHostingRepository,
|
|
public StaffRepositoryInterface $staffRepository,
|
|
) {}
|
|
public function index()
|
|
{
|
|
|
|
$title = 'CRM - Quản trị hệ thống';
|
|
|
|
$pending_order = $this->orderRepository->filter([
|
|
'status' => 0
|
|
]);
|
|
|
|
$invocie_unpaid = $this->invoiceRepository->filter(
|
|
[
|
|
'status' => 0
|
|
]
|
|
);
|
|
|
|
$tickets = $this->ticketRepository->filter(
|
|
[
|
|
'status' => 1
|
|
]
|
|
)->unique('ticket_num');
|
|
|
|
$customers = $this->customerRepository->getCount();
|
|
|
|
$total_amount = $this->invoiceRepository->filter()->sum('total');
|
|
$total_amount_year = $this->invoiceRepository->get_billing_year(date('Y'));
|
|
$total_amount_month = $this->invoiceRepository->get_billing_month(date('m'));
|
|
$total_amount_day = $this->invoiceRepository->get_billing_day(Carbon::today());
|
|
|
|
$posts = $this->postRepository->filter([
|
|
'limit' => 6
|
|
]);
|
|
$logs = $this->logRepository->filter(
|
|
[
|
|
'limit' => 6
|
|
]
|
|
);
|
|
|
|
$vmwares = $this->vmwareRepository->filter(
|
|
[
|
|
'limit' => 6,
|
|
'status' => [
|
|
'key' => 'status',
|
|
'condition' => 'NotIn',
|
|
'value' => [3]
|
|
]
|
|
],
|
|
[
|
|
'ipaddress',
|
|
'customer'
|
|
]
|
|
);
|
|
|
|
$hostings = $this->moduleHostingRepository->filter(
|
|
[
|
|
'status' => [
|
|
'key' => 'status',
|
|
'condition' => 'NotIn',
|
|
'value' => [3]
|
|
],
|
|
'limit' => 6
|
|
],
|
|
[
|
|
'customer'
|
|
]
|
|
);
|
|
|
|
$orders = $this->orderRepository->filter(
|
|
[
|
|
'limit' => 6,
|
|
'invoice_id' => [
|
|
'key' => 'invoice_id',
|
|
'condition' => 'NotIn',
|
|
'value' => [0]
|
|
]
|
|
],
|
|
[
|
|
'customer'
|
|
]
|
|
);
|
|
|
|
$staffs = $this->staffRepository->filter([], ['user']);
|
|
|
|
return view(
|
|
'administrator.home',
|
|
compact(
|
|
'title',
|
|
'pending_order',
|
|
'invocie_unpaid',
|
|
'tickets',
|
|
'customers',
|
|
'total_amount',
|
|
'total_amount_year',
|
|
'total_amount_month',
|
|
'total_amount_day',
|
|
'posts',
|
|
'logs',
|
|
'vmwares',
|
|
'hostings',
|
|
'orders',
|
|
'staffs'
|
|
)
|
|
);
|
|
}
|
|
|
|
public function SystemLog(Request $request)
|
|
{
|
|
$logs = $this->logRepository->filter(
|
|
[
|
|
'page' => $request->get('page') ?? 1
|
|
],
|
|
[
|
|
'customer'
|
|
]
|
|
);
|
|
$title = 'System Activity Log';
|
|
|
|
return view('administrator.pages.log', compact('title', 'logs'));
|
|
}
|
|
|
|
public function ClearCache()
|
|
{
|
|
Artisan::call('cache:clear');
|
|
Artisan::call('config:clear');
|
|
Artisan::call('route:clear');
|
|
Artisan::call('view:clear');
|
|
return redirect()->back()->with('success', 'Cache cleared successfully');
|
|
}
|
|
}
|