Skip to content

Commit

Permalink
chore(app): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
WailanTirajoh committed Apr 10, 2024
1 parent b4ac047 commit 6915fcd
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 103 deletions.
60 changes: 32 additions & 28 deletions app/Http/Controllers/ChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,55 @@

use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Http\Request;

class ChartController extends Controller
{
public function dialyGuestPerMonth()
public function dailyGuestPerMonth()
{
$year = Carbon::now()->format('Y');
$month = Carbon::now()->format('m');
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$currentDate = Carbon::now();
$daysInMonth = $currentDate->daysInMonth;

$day_array = [];
$guests_count_array = [];
$days = collect(range(1, $daysInMonth));
$guests = $days
->map(function ($day) use ($currentDate) {
return $this->dailyTotalGuests($currentDate->year, $currentDate->month, $day);
})
->toArray();

for ($i = 1; $i <= $days_in_month; $i++) {
$day_array[] = $i;
$guests_count_array[] = $this->countGuestsPerDay($year, $month, $i);
}

$max_no = max($guests_count_array);
$max = round(($max_no + 10 / 2) / 10) * 10;
$max = (int) ceil((max($guests) + 10) / 10) * 10;

return [
'day' => $day_array,
'guest_count_data' => $guests_count_array,
'day' => $days->toArray(),
'guest_count_data' => $guests,
'max' => $max,
];
}

private function countGuestsPerDay($year, $month, $day)
{
$time = strtotime($month.'/'.$day.'/'.$year);
$date = date('Y-m-d', $time);

return Transaction::where([['check_in', '<=', $date], ['check_out', '>=', $date]])->count();
}

public function dialyGuest($year, $month, $day)
public function dailyGuest(Request $request)
{
$time = strtotime($month.'/'.$day.'/'.$year);
$date = date('Y-m-d', $time);
$date = Carbon::createFromDate(
year: $request->year,
month: $request->month,
day: $request->day
);

$transactions = Transaction::where([['check_in', '<=', $date], ['check_out', '>=', $date]])->get();
$transactions = Transaction::where('check_in', '<=', $date)
->where('check_out', '>=', $date)
->get();

return view('dashboard.chart_detail', [
'transactions' => $transactions,
'date' => $date,
'date' => $date->format('Y-m-d'),
]);
}

private function dailyTotalGuests($year, $month, $day)
{
$date = Carbon::createFromDate($year, $month, $day);

return Transaction::where('check_in', '<=', $date)
->where('check_out', '>=', $date)
->count();
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function index()
$transactions = Transaction::with('user', 'room', 'customer')
->where([['check_in', '<=', Carbon::now()], ['check_out', '>=', Carbon::now()]])
->orderBy('check_out', 'ASC')
->orderBy('id', 'DESC')->get();
->orderBy('id', 'DESC')
->get();

return view('dashboard.index', [
'transactions' => $transactions,
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ class EventController extends Controller
{
public function sendEvent()
{
// event(new TestEvent('Sent from my Laravel application'));
$message = 'Reservation added';
$superAdmins = User::where('role', 'Super')->get();
foreach ($superAdmins as $superAdmin) {
event(new NewReservationEvent($message, $superAdmin));
}
// return view('event.index');
}

public function seeEvent()
Expand Down
65 changes: 0 additions & 65 deletions app/Http/Controllers/FacilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

class FacilityController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$facilities = Facility::paginate(5);
Expand All @@ -20,64 +15,4 @@ public function index()
'facilities' => $facilities,
]);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function show(Facility $facility)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function edit(Facility $facility)
{
//
}

/**
* Update the specified resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Facility $facility)
{
//
}

/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy(Facility $facility)
{
//
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function __construct(
private TypeRepositoryInterface $typeRepository,
private RoomStatusRepositoryInterface $roomStatusRepositoryInterface
) {
$this->roomRepository = $roomRepository;
}

public function index(Request $request)
Expand Down
6 changes: 3 additions & 3 deletions resources/js/pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ $(function () {
let myVisitorChart;
const charts = {
init: function () {
this.ajaxGetDialyGuestPerMonthData();
this.ajaxGetdailyGuestPerMonthData();
},

ajaxGetDialyGuestPerMonthData: function () {
ajaxGetdailyGuestPerMonthData: function () {
const urlPath = "/get-dialy-guest-chart-data";
const request = $.ajax({
method: "GET",
Expand Down Expand Up @@ -126,7 +126,7 @@ $(function () {
charts.init();

window.Echo.channel("dashboard").listen(".dashboard.event", (e) => {
charts.ajaxGetDialyGuestPerMonthData();
charts.ajaxGetdailyGuestPerMonthData();
// reloadJs("style/js/guestsChart.js");
toastr.warning(e.message, "Hello");
});
Expand Down
2 changes: 1 addition & 1 deletion resources/views/template/include/_sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li class="mb-2 bg-white rounded cursor-pointer">
<a href="{{ route('dashboard.index') }}"
class="nav-link py-3 border-bottom myBtn
{{ in_array(Route::currentRouteName(), ['dashboard.index', 'chart.dialyGuest']) ? 'active' : '' }}
{{ in_array(Route::currentRouteName(), ['dashboard.index', 'chart.dailyGuest']) ? 'active' : '' }}
"
data-bs-toggle="tooltip" data-bs-placement="right" title="Dashboard">
<i class="fas fa-home"></i>
Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
Route::get('/transaction/{transaction}/payment/create', [PaymentController::class, 'create'])->name('transaction.payment.create');
Route::post('/transaction/{transaction}/payment/store', [PaymentController::class, 'store'])->name('transaction.payment.store');

Route::get('/get-dialy-guest-chart-data', [ChartController::class, 'dialyGuestPerMonth']);
Route::get('/get-dialy-guest/{year}/{month}/{day}', [ChartController::class, 'dialyGuest'])->name('chart.dialyGuest');
Route::get('/get-dialy-guest-chart-data', [ChartController::class, 'dailyGuestPerMonth']);
Route::get('/get-dialy-guest/{year}/{month}/{day}', [ChartController::class, 'dailyGuest'])->name('chart.dailyGuest');
});

Route::group(['middleware' => ['auth', 'checkRole:Super,Admin,Customer']], function () {
Expand Down

0 comments on commit 6915fcd

Please sign in to comment.