90 lines
3.8 KiB
PHP
90 lines
3.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\Business\App\Http\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Models\PlanSubscribe;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Services\PdfService;
|
||
|
|
use App\Traits\DateFilterTrait;
|
||
|
|
use App\Traits\DateRangeTrait;
|
||
|
|
use Maatwebsite\Excel\Facades\Excel;
|
||
|
|
use Modules\Business\App\Exports\ExportSubscription;
|
||
|
|
|
||
|
|
class AcnooSubscriptionReportController extends Controller
|
||
|
|
{
|
||
|
|
use DateFilterTrait, DateRangeTrait;
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->middleware('check.permission:subscription-reports.read')->only(['index']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function index(Request $request)
|
||
|
|
{
|
||
|
|
$subscriberQuery = PlanSubscribe::with(['plan:id,subscriptionName','business:id,companyName,business_category_id,pictureUrl','business.category:id,name','gateway:id,name'])->where('business_id', auth()->user()->business_id);
|
||
|
|
|
||
|
|
// Date Filter
|
||
|
|
$duration = $request->custom_days ?: 'today';
|
||
|
|
[$filter_from_date, $filter_to_date] = $this->applyDateRange($duration, $request->from_date, $request->to_date);
|
||
|
|
|
||
|
|
$this->applyDateFilter($subscriberQuery, $duration, 'created_at', $request->from_date, $request->to_date);
|
||
|
|
|
||
|
|
// Search Filter
|
||
|
|
if ($request->filled('search')) {
|
||
|
|
$search = $request->search;
|
||
|
|
$subscriberQuery->where(function ($query) use ($search) {
|
||
|
|
$query->where('duration', 'like', '%' . $search . '%')
|
||
|
|
->orWhereHas('plan', function ($q) use ($search) {
|
||
|
|
$q->where('subscriptionName', 'like', '%' . $search . '%');
|
||
|
|
})
|
||
|
|
->orWhereHas('gateway', function ($q) use ($search) {
|
||
|
|
$q->where('name', 'like', '%' . $search . '%');
|
||
|
|
})
|
||
|
|
->orWhereHas('business', function ($q) use ($search) {
|
||
|
|
$q->where('companyName', 'like', '%' . $search . '%')
|
||
|
|
->orWhereHas('category', function ($q) use ($search) {
|
||
|
|
$q->where('name', 'like', '%' . $search . '%');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
$perPage = $request->input('per_page', 20);
|
||
|
|
$subscribers = $subscriberQuery->latest()->paginate($perPage)->appends($request->query());
|
||
|
|
|
||
|
|
if ($request->ajax()) {
|
||
|
|
return response()->json([
|
||
|
|
'data' => view('business::reports.subscription-reports.datas', compact('subscribers', 'filter_from_date', 'filter_to_date', 'duration'))->render()
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('business::reports.subscription-reports.subscription-reports', compact('subscribers', 'filter_from_date', 'filter_to_date', 'duration'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function exportExcel()
|
||
|
|
{
|
||
|
|
return Excel::download(new ExportSubscription, 'subscribers.xlsx');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function exportCsv()
|
||
|
|
{
|
||
|
|
return Excel::download(new ExportSubscription, 'subscribers.csv');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function exportPdf()
|
||
|
|
{
|
||
|
|
$subscribers = PlanSubscribe::with(['plan:id,subscriptionName','business:id,companyName,business_category_id,pictureUrl','business.category:id,name','gateway:id,name'])->where('business_id', auth()->user()->business_id)
|
||
|
|
->latest()
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return PdfService::render('business::reports.subscription-reports.pdf', compact('subscribers'),'subscription-reports.pdf');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getInvoice($invoice_id)
|
||
|
|
{
|
||
|
|
$subscriber = PlanSubscribe::with(['plan:id,subscriptionName','business:id,companyName,business_category_id,pictureUrl,phoneNumber,email,address,meta','business.category:id,name','gateway:id,name'])->where('business_id', auth()->user()->business_id)->findOrFail($invoice_id);
|
||
|
|
return view('business::reports.subscription-reports.invoice', compact('subscriber'));
|
||
|
|
}
|
||
|
|
}
|