95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Reports;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Exports\LaporanKeseluruhan\PelangganbaruAllExportExcel;
|
|
use App\Exports\LaporanKeseluruhan\PelangganaktifAllExportExcel;
|
|
|
|
class AnalisaController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$current = new Carbon();
|
|
$request->hostname = config('api.url');
|
|
// dd($request->hostname );
|
|
$kod_cawangan = $request->kod_cawangan;
|
|
$action = $request->input('action', 'search');
|
|
// dd($action);
|
|
|
|
$getReportDate = function ($date_string) use ($current) {
|
|
if ($date_string == null) {
|
|
return $current->toDateString();
|
|
}
|
|
|
|
return $date_string;
|
|
};
|
|
|
|
$request->hostname = config('api.url');
|
|
|
|
$pelangganbaru = Http::get($request->hostname . '/api/reports/pelangganbaru', [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
// dd($pelangganbaru);
|
|
|
|
$startDate = $getReportDate($request->startDate);
|
|
$endDate = $getReportDate($request->endDate);
|
|
|
|
if ($action === 'excel') {
|
|
$file_title = sprintf("LaporanPelangganBaru(%s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new PelangganbaruAllExportExcel($pelangganbaru,$startDate,$endDate), $file_title);
|
|
}
|
|
|
|
$pelangganbaru = $pelangganbaru ?? [];
|
|
|
|
return view('reports.pelangganbaru.index', compact('pelangganbaru', 'startDate', 'endDate'));
|
|
}
|
|
|
|
public function pelangganaktif(Request $request)
|
|
{
|
|
$current = new Carbon();
|
|
$request->hostname = config('api.url');
|
|
// dd($request->hostname );
|
|
$kod_cawangan = $request->kod_cawangan;
|
|
$action = $request->input('action', 'search');
|
|
// dd($action);
|
|
|
|
$getReportDate = function ($date_string) use ($current) {
|
|
if ($date_string == null) {
|
|
return $current->toDateString();
|
|
}
|
|
|
|
return $date_string;
|
|
};
|
|
|
|
$request->hostname = config('api.url');
|
|
|
|
$pelangganaktif = Http::get($request->hostname . '/api/reports/pelangganaktif', [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
// dd($pelangganbaru);
|
|
|
|
$startDate = $getReportDate($request->startDate);
|
|
$endDate = $getReportDate($request->endDate);
|
|
|
|
if ($action === 'excel') {
|
|
$file_title = sprintf("LaporanPelangganAktif(%s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new PelangganaktifAllExportExcel($pelangganaktif,$startDate,$endDate), $file_title);
|
|
}
|
|
|
|
$pelangganaktif = $pelangganaktif ?? [];
|
|
|
|
return view('reports.pelangganaktif.index', compact('pelangganaktif', 'startDate', 'endDate'));
|
|
}
|
|
|
|
|
|
}
|