185 lines
6.8 KiB
PHP
185 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Cabel;
|
|
use App\Models\Loan;
|
|
use App\Models\LoanType;
|
|
use App\Models\Log;
|
|
use App\Models\LogAction;
|
|
use App\Models\Product;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OtherController extends Controller
|
|
{
|
|
public function logs(Request $request){
|
|
$search_types = [];
|
|
array_push($search_types,array("value" => "building", "name" => "building"));
|
|
array_push($search_types,array("value" => "room", "name" => "room"));
|
|
|
|
$PerPagination = $request->input('p') ?? 10;
|
|
$search_term = $request->input('search_term');
|
|
$search_type = $request->input('search_type');
|
|
$search_compare = $request->input('search_compare');
|
|
|
|
$logs = Log::orderBy('created_at','desc')->Paginate($PerPagination);
|
|
|
|
return view('logs')
|
|
->with('search_types',$search_types)
|
|
->with('data',$logs)
|
|
->with('data_name','log')
|
|
->with('data_names','logs')
|
|
->with('no_deleted',true)
|
|
;
|
|
}
|
|
|
|
public function statistics(Request $request){
|
|
$search_types = [];
|
|
array_push($search_types,array("value" => "building", "name" => "building"));
|
|
array_push($search_types,array("value" => "room", "name" => "room"));
|
|
|
|
$PerPagination = $request->input('p') ?? 10;
|
|
$search_term = $request->input('search_term');
|
|
$search_type = $request->input('search_type');
|
|
$search_compare = $request->input('search_compare');
|
|
|
|
$products = Product::all();
|
|
$cabels = Cabel::all();
|
|
$loans = Loan::where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
|
->select('*',DB::raw('count(loanable_id) as amount'))
|
|
->groupBy('loanable_type','loanable_id')
|
|
->get()
|
|
;
|
|
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
|
->select('*',DB::raw('count(loanable_id) as amount'))
|
|
->groupBy('loanable_type','loanable_id')
|
|
->get()
|
|
;
|
|
|
|
$log_returned = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)->get();
|
|
$log_returned_placement = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id','created_at')
|
|
->orderBy('sum','desc')
|
|
->get()
|
|
;
|
|
$log_lent = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)->get();
|
|
$log_lent_placement = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id')
|
|
->orderBy('sum','desc')
|
|
->get()
|
|
;
|
|
$log_reserved = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)->get();
|
|
$log_reserved_placement = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id')
|
|
->orderBy('sum','desc')
|
|
->get()
|
|
;
|
|
$log_validated = Log::where('log_action_id','=',LogAction::where('name','=','validated')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id')
|
|
->orderBy('amount','desc')
|
|
->get()
|
|
;
|
|
$log_setups = Log::where('log_action_id','=',LogAction::where('name','=','set up')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id')
|
|
->orderBy('amount','desc')
|
|
->get()
|
|
;
|
|
$log_pickups = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)->get();
|
|
$log_pickups_placement = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)
|
|
->select('*',DB::raw('SUM(amount) as sum'))
|
|
->groupBy('user_id')
|
|
->orderBy('amount','desc')
|
|
->get()
|
|
;
|
|
$log_notes = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)->get();
|
|
$log_notes_placement = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)
|
|
->select('*',DB::raw('count(user_id) as amount'))
|
|
->groupBy('user_id')
|
|
->orderBy('amount','desc')
|
|
->get()
|
|
;
|
|
$total_lent = 0;
|
|
$total_reserved = 0;
|
|
$total_total = 0;
|
|
|
|
$lastday_date = Carbon::now()->subDays(1)->toDateTimeString();
|
|
$lastday_lent = 0;
|
|
$lastday_reserved = 0;
|
|
$lastday_returned = 0;
|
|
$lastday_notes = 0;
|
|
|
|
foreach($products as $product){
|
|
$total_total += $product->total;
|
|
}
|
|
|
|
foreach($cabels as $cabel){
|
|
$total_total += $cabel->total;
|
|
}
|
|
|
|
foreach($loans as $loan){
|
|
$total_lent += $loan->amount;
|
|
}
|
|
|
|
foreach($reservations as $reservation){
|
|
$total_reserved += $reservation->amount;
|
|
}
|
|
|
|
foreach($log_lent as $loan){
|
|
if($loan->created_at >= $lastday_date){
|
|
$lastday_lent += $loan->amount;
|
|
}
|
|
}
|
|
|
|
foreach($log_reserved as $loan){
|
|
if($loan->created_at >= $lastday_date){
|
|
$lastday_reserved += $loan->amount;
|
|
}
|
|
}
|
|
|
|
foreach($log_returned as $return){
|
|
if($return->created_at >= $lastday_date){
|
|
$lastday_returned += $return->amount;
|
|
}
|
|
}
|
|
|
|
foreach($log_pickups as $pickup){
|
|
if($pickup->created_at >= $lastday_date){
|
|
$lastday_returned += $pickup->amount;
|
|
}
|
|
}
|
|
|
|
foreach($log_notes as $note){
|
|
if($note->created_at >= $lastday_date){
|
|
$lastday_notes += 1;
|
|
}
|
|
}
|
|
|
|
return view('statistics')
|
|
->with('search_types',$search_types)
|
|
->with('data_name','statistic')
|
|
->with('data_names','statistics')
|
|
->with('lastday_lent',$lastday_lent)
|
|
->with('lastday_reserved',$lastday_reserved)
|
|
->with('lastday_returned',$lastday_returned)
|
|
->with('lastday_notes',$lastday_notes)
|
|
->with('total_lent',$total_lent)
|
|
->with('total_reserved',$total_reserved)
|
|
->with('total_total',$total_total)
|
|
->with('validated',$log_validated)
|
|
->with('lent',$log_lent_placement)
|
|
->with('reserved',$log_reserved_placement)
|
|
->with('setups',$log_setups)
|
|
->with('pickups',$log_pickups_placement)
|
|
->with('returned',$log_returned_placement)
|
|
->with('notes',$log_notes_placement)
|
|
;
|
|
}
|
|
}
|