first initial
This commit is contained in:
32
app/Console/Kernel.php
Normal file
32
app/Console/Kernel.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
51
app/Exceptions/Handler.php
Normal file
51
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array<int, class-string<Throwable>>
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
|
||||
$this->renderable(function (\Illuminate\Auth\AuthenticationException $e, $request) {
|
||||
if ($request->is('api/*')) {
|
||||
return response()->json([
|
||||
'message' => 'Not authorized',
|
||||
'status' => false,
|
||||
'code' => 401
|
||||
], 401);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
78
app/Exports/TransactionDealerExport.php
Normal file
78
app/Exports/TransactionDealerExport.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class TransactionDealerExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $dealer;
|
||||
protected $month;
|
||||
|
||||
function __construct($request) {
|
||||
$this->month = (isset($request->dealer)) ? $request->query('month') : date('m');
|
||||
$this->dealer = (isset($request->dealer)) ? $request->query('dealer') : 'all';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$dealer_work_trx = DB::statement("SET @sql = NULL");
|
||||
$sql = "SELECT IF(work_id IS NOT NULL, GROUP_CONCAT(DISTINCT CONCAT('SUM(IF(work_id = \"', work_id,'\", qty,\"\")) AS \"',CONCAT(w.name, '|',w.id),'\"')), 's.work_id') INTO @sql FROM transactions t JOIN works w ON w.id = t.work_id WHERE month(t.date) = '". $this->month ."' and year(t.date) = '". date('Y') ."' and t.deleted_at is null";
|
||||
|
||||
if(isset($this->dealer) && $this->dealer != 'all') {
|
||||
$sql .= " and t.dealer_id = '". $this->dealer ."'";
|
||||
}
|
||||
|
||||
$dealer_work_trx = DB::statement($sql);
|
||||
|
||||
if(isset($this->dealer) && $this->dealer != 'all') {
|
||||
$dealer_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id, \", @sql, \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' GROUP BY s.dealer_id ORDER BY s.dealer_id ASC\"), CONCAT(\"SELECT d.name as DEALER \", \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' GROUP BY s.`dealer_id` ORDER BY s.`dealer_id` ASC\"))");
|
||||
}else{
|
||||
$dealer_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id, \", @sql, \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null GROUP BY s.dealer_id ORDER BY s.dealer_id ASC\"), CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id \", \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null GROUP BY s.`dealer_id` ORDER BY s.`dealer_id` ASC\"))");
|
||||
}
|
||||
|
||||
$dealer_work_trx = DB::statement("PREPARE stmt FROM @sql");
|
||||
$dealer_work_trx = DB::select(DB::raw("EXECUTE stmt"));
|
||||
DB::statement('DEALLOCATE PREPARE stmt');
|
||||
|
||||
$work_trx = [];
|
||||
foreach($dealer_work_trx as $index => $dealer_work) {
|
||||
$dealer_work_2 = (array) $dealer_work;
|
||||
unset($dealer_work_2['dealer_id']);
|
||||
$work_names = array_keys($dealer_work_2);
|
||||
if($index == 0) {
|
||||
$work_names_e = [];
|
||||
foreach($work_names as $work) {
|
||||
$arr_work = explode('|', $work);
|
||||
$work_names_e[] = $arr_work[0];
|
||||
}
|
||||
$work_trx[] = $work_names_e;
|
||||
$work_trx[] = array_values($dealer_work_2);
|
||||
}else{
|
||||
$work_trx[] = array_values($dealer_work_2);
|
||||
}
|
||||
}
|
||||
|
||||
return collect($work_trx);
|
||||
}
|
||||
|
||||
|
||||
// public function headings(): array
|
||||
// {
|
||||
// return $this->theads;
|
||||
// }
|
||||
|
||||
// public function actions(Request $request)
|
||||
// {
|
||||
// return [
|
||||
// (new DownloadExcel)->withHeadings('Tanggal', 'Mekanik', 'SA', 'No.Polisi', 'Warranty', 'Kategori', 'Qty')
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
93
app/Exports/TransactionExport.php
Normal file
93
app/Exports/TransactionExport.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class TransactionExport implements FromCollection, WithHeadings
|
||||
{
|
||||
|
||||
protected $date_start;
|
||||
protected $date_end;
|
||||
protected $sa;
|
||||
protected $mechanic;
|
||||
protected $dealer;
|
||||
|
||||
function __construct($request) {
|
||||
$this->date_start = $request->query('date_start');
|
||||
$this->date_end = $request->query('date_end');
|
||||
$this->sa = $request->query('sa');
|
||||
$this->mechanic = $request->query('mechanic');
|
||||
$this->dealer = $request->query('dealer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$data = Transaction::leftJoin('users', 'users.id', '=', 'transactions.user_id')
|
||||
->leftJoin('users as sa', 'sa.id', '=', 'transactions.user_sa_id')
|
||||
->leftJoin('works as w', 'w.id', '=', 'transactions.work_id')
|
||||
->leftJoin('categories as cat', 'cat.id', '=', 'w.category_id')
|
||||
->leftJoin('dealers as d', 'd.id', '=', 'transactions.dealer_id')
|
||||
->select('transactions.id', 'transactions.status', 'transactions.user_id as user_id', 'transactions.user_sa_id as user_sa_id', 'users.name as username', 'sa.name as sa_name', 'cat.name as category_name', 'w.name as workname', 'transactions.qty as qty', 'transactions.date as date', 'transactions.police_number as police_number', 'transactions.warranty as warranty', 'transactions.spk as spk', 'transactions.dealer_id', 'd.name as dealer_name');
|
||||
|
||||
if(isset($this->date_start) && $this->date_start != null) {
|
||||
$data = $data->where('transactions.date', '>=', $this->date_start);
|
||||
}
|
||||
|
||||
if(isset($this->date_end) && $this->date_end != null) {
|
||||
$data = $data->where('transactions.date', '<=', $this->date_end);
|
||||
}
|
||||
|
||||
if(isset($this->sa) && $this->sa != null) {
|
||||
$data = $data->where('transactions.user_sa_id', $this->sa);
|
||||
}
|
||||
|
||||
if(isset($this->mechanic) && $this->mechanic != null) {
|
||||
$data = $data->where('transactions.user_id', $this->mechanic);
|
||||
}
|
||||
|
||||
if(isset($this->dealer) && $this->dealer != null) {
|
||||
$data = $data->where('transactions.dealer_id', $this->dealer);
|
||||
}
|
||||
|
||||
$data = $data->orderBy('date', 'DESC')->get();
|
||||
|
||||
$data2 = [];
|
||||
foreach($data as $item) {
|
||||
$data2[] = [
|
||||
"date" => date('d-m-Y', strtotime($item['date'])),
|
||||
"dealer" => $item['dealer_name'],
|
||||
"spk" => $item['spk'],
|
||||
"mechanic" => $item['username'],
|
||||
"sa" => $item['sa_name'],
|
||||
"police_number" => $item['police_number'],
|
||||
"warranty" => $item['warranty'] == 1 ? 'Ya' : 'Tidak',
|
||||
"category" => $item['category_name'],
|
||||
"work" => $item['workname'],
|
||||
"qty" => $item['qty']
|
||||
];
|
||||
}
|
||||
|
||||
$data2 = collect($data2);
|
||||
|
||||
return $data2;
|
||||
}
|
||||
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return ["Tanggal", "Dealer", "Spk","Mekanik", "SA", "No. Polisi", "Warranty", "Kategori", "Pekerjaan", "Qty"];
|
||||
}
|
||||
|
||||
// public function actions(Request $request)
|
||||
// {
|
||||
// return [
|
||||
// (new DownloadExcel)->withHeadings('Tanggal', 'Mekanik', 'SA', 'No.Polisi', 'Warranty', 'Kategori', 'Qty')
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
90
app/Exports/TransactionSaExport.php
Normal file
90
app/Exports/TransactionSaExport.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class TransactionSaExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $dealer;
|
||||
protected $month;
|
||||
protected $sa;
|
||||
|
||||
function __construct($request) {
|
||||
$this->month = (isset($request->month)) ? $request->query('month') : date('m');
|
||||
$this->dealer = (isset($request->dealer)) ? $request->query('dealer') : 'all';
|
||||
$this->sa = (isset($request->sa)) ? $request->query('sa') : 'all';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$sa_work_trx = DB::statement("SET @sql = NULL");
|
||||
$sql = "SELECT IF(work_id IS NOT NULL, GROUP_CONCAT(DISTINCT CONCAT('SUM(IF(work_id = \"', work_id,'\", qty,\"\")) AS \"',CONCAT(w.name, '|',w.id),'\"')), 's.work_id') INTO @sql FROM transactions t JOIN works w ON w.id = t.work_id WHERE month(t.date) = '". $this->month ."' and year(t.date) = '". date('Y') ."' and t.deleted_at is null";
|
||||
|
||||
if(isset($this->dealer) && $this->dealer != 'all') {
|
||||
$sql .= " and t.dealer_id = '". $this->dealer ."'";
|
||||
}
|
||||
|
||||
if(isset($this->sa) && $this->sa != 'all') {
|
||||
$sql .= " and t.user_sa_id = '". $this->sa ."'";
|
||||
}
|
||||
|
||||
$sa_work_trx = DB::statement($sql);
|
||||
|
||||
if(isset($this->dealer) && $this->dealer != 'all') {
|
||||
if(isset($this->sa) && $this->sa != 'all') {
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' and s.user_sa_id = '". $this->sa ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as sa_id \", \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' and s.user_sa_id = '". $this->sa ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}else{
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as sa_id \", \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.dealer_id = '". $this->dealer ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}
|
||||
}else{
|
||||
if(isset($this->sa) && $this->sa != 'all') {
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.user_sa_id = '". $this->sa ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as user_sa_id \", \"FROM transactions s JOIN dealers d ON d.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null and s.user_sa_id = '". $this->sa ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}else{
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as user_sa_id \", \"FROM transactions s JOIN dealers d ON d.id = s.user_sa_id WHERE month(s.date) = '". $this->month ."' and year(s.date) = '". date('Y') ."' and s.deleted_at is null GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}
|
||||
}
|
||||
|
||||
$sa_work_trx = DB::statement("PREPARE stmt FROM @sql");
|
||||
$sa_work_trx = DB::select(DB::raw("EXECUTE stmt"));
|
||||
DB::statement('DEALLOCATE PREPARE stmt');
|
||||
$work_trx = [];
|
||||
foreach($sa_work_trx as $index => $sa_work) {
|
||||
$sa_work_2 = (array) $sa_work;
|
||||
unset($sa_work_2['sa_id']);
|
||||
$work_names = array_keys($sa_work_2);
|
||||
if($index == 0) {
|
||||
$work_names_e = [];
|
||||
foreach($work_names as $work) {
|
||||
$arr_work = explode('|', $work);
|
||||
$work_names_e[] = $arr_work[0];
|
||||
}
|
||||
$work_trx[] = $work_names_e;
|
||||
$work_trx[] = array_values($sa_work_2);
|
||||
}else{
|
||||
$work_trx[] = array_values($sa_work_2);
|
||||
}
|
||||
}
|
||||
|
||||
return collect($work_trx);
|
||||
}
|
||||
|
||||
|
||||
// public function headings(): array
|
||||
// {
|
||||
// return $this->theads;
|
||||
// }
|
||||
|
||||
// public function actions(Request $request)
|
||||
// {
|
||||
// return [
|
||||
// (new DownloadExcel)->withHeadings('Tanggal', 'Mekanik', 'SA', 'No.Polisi', 'Warranty', 'Kategori', 'Qty')
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
478
app/Http/Controllers/AdminController.php
Normal file
478
app/Http/Controllers/AdminController.php
Normal file
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Models\Work;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function cmp($a, $b){
|
||||
$key = 'work_id';
|
||||
if($a[$key] > $b[$key]){
|
||||
return 1;
|
||||
}else if($a[$key] < $b[$key]){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function dashboard(Request $request) {
|
||||
abort_if(Gate::denies('view', Menu::where('link', 'dashboard')->first()), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
$month = $request->month;
|
||||
$dealer = $request->dealer;
|
||||
$year = $request->year;
|
||||
$dealer_datas = Dealer::all();
|
||||
$ajax_url = route('dashboard_data').'?month='.$month.'&year='.$year.'&dealer='.$dealer;
|
||||
// dd($ajax_url);
|
||||
return view('dashboard', compact('month','year', 'ajax_url', 'dealer', 'dealer_datas'));
|
||||
}
|
||||
|
||||
public function dashboard_data(Request $request) {
|
||||
abort_if(Gate::denies('view', Menu::where('link', 'dashboard')->first()), 403, 'Unauthorized User');
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
if(isset($request->{'amp;dealer'})) {
|
||||
$request['dealer'] = $request->{'amp;dealer'};
|
||||
}
|
||||
|
||||
if(isset($request->{'amp;year'})) {
|
||||
$request['year'] = $request->{'amp;year'};
|
||||
}
|
||||
|
||||
if(!isset($request->dealer)) {
|
||||
$request['dealer'] = 'all';
|
||||
}
|
||||
|
||||
$month = $request->month;
|
||||
$dealer = $request->dealer;
|
||||
$year = $request->year;
|
||||
|
||||
$dealer_work_trx = DB::statement("SET @sql = NULL");
|
||||
$sql = "SELECT IF(work_id IS NOT NULL, GROUP_CONCAT(DISTINCT CONCAT('SUM(IF(work_id = \"', work_id,'\", qty,\"\")) AS \"',CONCAT(w.name, '|',w.id),'\"')), 's.work_id') INTO @sql FROM transactions t JOIN works w ON w.id = t.work_id WHERE month(t.date) = '". $month ."' and year(t.date) = '". $year ."' and t.deleted_at is null";
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$sql .= " and t.dealer_id = '". $dealer ."'";
|
||||
}
|
||||
|
||||
$dealer_work_trx = DB::statement($sql);
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$dealer_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id, \", @sql, \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' GROUP BY s.dealer_id ORDER BY s.dealer_id ASC\"), CONCAT(\"SELECT d.name as DEALER \", \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' GROUP BY s.`dealer_id` ORDER BY s.`dealer_id` ASC\"))");
|
||||
}else{
|
||||
$dealer_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id, \", @sql, \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null GROUP BY s.dealer_id ORDER BY s.dealer_id ASC\"), CONCAT(\"SELECT d.name as DEALER, d.id as dealer_id \", \"FROM transactions s JOIN dealers d ON d.id = s.dealer_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null GROUP BY s.`dealer_id` ORDER BY s.`dealer_id` ASC\"))");
|
||||
}
|
||||
|
||||
$dealer_work_trx = DB::statement("PREPARE stmt FROM @sql");
|
||||
$dealer_work_trx = DB::select(DB::raw("EXECUTE stmt"));
|
||||
DB::statement('DEALLOCATE PREPARE stmt');
|
||||
// DD($dealer_work_trx);
|
||||
$theads = ['DEALER'];
|
||||
$dealer_names = [];
|
||||
$dealer_trx = [];
|
||||
$work_trx = [];
|
||||
$work_ids = [];
|
||||
|
||||
foreach($dealer_work_trx as $index => $dealer_work) {
|
||||
$dealer_work_2 = (array) $dealer_work;
|
||||
unset($dealer_work_2['dealer_id']);
|
||||
$work_trx[$dealer_work->dealer_id] = array_values($dealer_work_2);
|
||||
unset($dealer_work_2['DEALER']);
|
||||
$work_names = array_keys($dealer_work_2);
|
||||
if($index == 0) {
|
||||
foreach($work_names as $work) {
|
||||
$arr_work = explode('|', $work);
|
||||
$theads[] = $arr_work[0];
|
||||
$work_ids[] = $arr_work[1];
|
||||
$dealer_trx[$work] = [
|
||||
'work_name' => $arr_work[0],
|
||||
'qty' => [$dealer_work->{$work}]
|
||||
];
|
||||
}
|
||||
}else{
|
||||
foreach($work_names as $work) {
|
||||
$dealer_trx[$work]['qty'][] = $dealer_work->{$work};
|
||||
}
|
||||
}
|
||||
|
||||
$dealer_names[] = $dealer_work->DEALER;
|
||||
}
|
||||
// dd($dealer_trx);
|
||||
$dealer_trx = array_values($dealer_trx);
|
||||
$dealer = $request->dealer;
|
||||
$month = $request->month;
|
||||
|
||||
$dealer_names = json_encode($dealer_names);
|
||||
$dealer_trx = json_encode($dealer_trx);
|
||||
|
||||
$prev_mth_start = date('Y-m-d', strtotime(date($year.'-'. $request->month .'-1')." -1 month"));
|
||||
$prev_mth = explode('-', $prev_mth_start);
|
||||
if($request->month == date('m')) {
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('d');
|
||||
}else{
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('t');
|
||||
}
|
||||
|
||||
$prev_month_trx = [];
|
||||
$now_month_trx = [];
|
||||
foreach($work_ids as $work_id) {
|
||||
$now_month = Transaction::select(DB::raw("SUM(qty) as qty"))->where('work_id', $work_id)->whereMonth('date', '=', $request->month)->whereYear('date', $year);
|
||||
$prev_month = Transaction::select(DB::raw("SUM(qty) as qty"))->where('work_id', $work_id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end);
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$prev_month = $prev_month->where('dealer_id', $request->dealer);
|
||||
$now_month = $now_month->where('dealer_id', $request->dealer);
|
||||
}
|
||||
|
||||
$prev_month_trx[] = $prev_month->sum('qty');
|
||||
$now_month_trx[] = $now_month->sum('qty');
|
||||
}
|
||||
|
||||
$totals = [];
|
||||
for($i = 0; $i < count($now_month_trx); $i++) {
|
||||
$totals[] = [
|
||||
"prev" => $prev_month_trx[$i],
|
||||
"now" => $now_month_trx[$i],
|
||||
];
|
||||
}
|
||||
|
||||
return view('dashboard_data', compact('theads', 'work_trx', 'month', 'year', 'dealer_names', 'dealer_trx', 'dealer', 'totals'));
|
||||
}
|
||||
|
||||
public function dealer_work_trx(Request $request) {
|
||||
$dealer_work_trx = Work::select(DB::raw('works.name AS work_name'), DB::raw("IFNULL(SUM(t.qty), 0) AS qty"), 'works.id AS work_id')->whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q = $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
|
||||
if(isset($request->dealer_filter) && $request->dealer_filter != 'all') {
|
||||
$q = $q->where('dealer_id', $request->dealer_filter);
|
||||
}
|
||||
|
||||
return $q;
|
||||
})->leftJoin('transactions AS t', function($q) use($request) {
|
||||
$q->on('t.work_id', '=', 'works.id');
|
||||
$q->on(DB::raw('MONTH(t.date)'), '=', DB::raw($request->month));
|
||||
$q->on(DB::raw('YEAR(t.date)'), '=', DB::raw(date('Y')));
|
||||
$q->on('t.dealer_id', '=', DB::raw($request->dealer));
|
||||
})->groupBy('works.id')->orderBy('works.id', 'ASC')->get();
|
||||
return response()->json($dealer_work_trx);
|
||||
}
|
||||
|
||||
public function get_dealer_has_transactions(Request $request) {
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
$dealers = Dealer::whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q = $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
});
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$dealers = $dealers->where('id', $request->dealer);
|
||||
}
|
||||
|
||||
$dealers = $dealers->orderBy('id', 'ASC')->get();
|
||||
|
||||
return response()->json($dealers);
|
||||
}
|
||||
|
||||
public function dashboard_data_old(Request $request) {
|
||||
$trxs = [];
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
$dealers = Dealer::whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
})->orderBy('id', 'ASC')->get();
|
||||
|
||||
$works = Work::select('id', 'name')->whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
})->orderBy('id', 'ASC')->get();
|
||||
|
||||
|
||||
$works_count = $works->count();
|
||||
$month_trxs_total = [];
|
||||
$prev_month_trxs_total = [];
|
||||
foreach ($dealers as $key => $dealer) {
|
||||
foreach($works as $work1) {
|
||||
$prev_mth_start = date('Y-m-d', strtotime(date('Y-'. $request->month .'-1')." -1 month"));
|
||||
$prev_mth = explode('-', $prev_mth_start);
|
||||
if($request->month == date('m')) {
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('d');
|
||||
}else{
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('t');
|
||||
}
|
||||
|
||||
// dd($prev_mth_end);
|
||||
$yesterday_month_trx = Transaction::where('work_id', $work1->id)->where('dealer_id', $dealer->id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end)->sum('qty');
|
||||
|
||||
if(array_key_exists($work1->id, $prev_month_trxs_total)) {
|
||||
$prev_month_trxs_total[$work1->id] += $yesterday_month_trx;
|
||||
}else{
|
||||
$prev_month_trxs_total[$work1->id] = $yesterday_month_trx;
|
||||
}
|
||||
}
|
||||
|
||||
$dealer_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('dealer_id', $dealer->id)->where('work_id', $work->id);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
$month = $request->month;
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
if($d) {
|
||||
if(array_key_exists($work->id, $month_trxs_total)) {
|
||||
$month_trxs_total[$work->id] += $d;
|
||||
}else{
|
||||
$month_trxs_total[$work->id] = $d;
|
||||
}
|
||||
$dealer_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'dealer_id' => $dealer->id,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$dealer_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'dealer_id' => $dealer->id,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$trxs[] = [
|
||||
'dealer_id' => $dealer->id,
|
||||
'dealer_name' => $dealer->name,
|
||||
'works' => $dealer_works
|
||||
];
|
||||
}
|
||||
|
||||
$dealer_names = [];
|
||||
$trx_data = [];
|
||||
foreach($trxs as $trx) {
|
||||
$dealer_names[] = $trx['dealer_name'];
|
||||
$work_data2 = [];
|
||||
foreach($trx['works'] as $work_data) {
|
||||
if(array_key_exists($work_data['work_name'], $trx_data)) {
|
||||
$trx_data[$work_data['work_name']]['qty'][] = $work_data['qty'];
|
||||
}else{
|
||||
$trx_data[$work_data['work_name']] = [
|
||||
'work_name' => $work_data['work_name'],
|
||||
'qty' => [$work_data['qty']]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$month_trxs_total = array_values($month_trxs_total);
|
||||
$prev_month_trxs_total = array_values($prev_month_trxs_total);
|
||||
|
||||
$totals = [];
|
||||
for($i = 0; $i < count($month_trxs_total); $i++) {
|
||||
$totals[] = [
|
||||
"prev" => $prev_month_trxs_total[$i],
|
||||
"now" => $month_trxs_total[$i],
|
||||
];
|
||||
}
|
||||
$dealer_names = json_encode($dealer_names);
|
||||
|
||||
$trx_data = json_encode(array_values($trx_data));
|
||||
$month = $request->month;
|
||||
|
||||
return view('dashboard_data', compact('works', 'works_count', 'trxs', 'month', 'dealer_names', 'trx_data', 'totals'));
|
||||
}
|
||||
|
||||
public function dealer_recap(Request $request, $id)
|
||||
{
|
||||
abort_if(Gate::denies('view', Menu::where('link', 'dashboard')->first()), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
$works = Work::select('id', 'name', 'shortname')->whereHas('transactions', function($q) use($request, $id) {
|
||||
return $q->where('qty', '>', '0')->where('dealer_id', $id)->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
})->get();
|
||||
|
||||
$sas = User::select('id', 'name')->whereHas('sa_transactions', function($q) use($request, $id) {
|
||||
return $q->where('dealer_id', $id)->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
})->get();
|
||||
|
||||
$dealer = Dealer::find($id);
|
||||
|
||||
$dates = Transaction::select(DB::raw('DATE(`date`) as date'))->where('dealer_id', $id)->whereMonth('date', $request->month)->whereYear('date', $request->year)->groupBy(DB::raw('DATE(`date`)'))->get()->toArray();
|
||||
$dates = $this->array_value_recursive('date', $dates);
|
||||
|
||||
$trxs = [];
|
||||
$month_trxs_total = [];
|
||||
$yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$prev_mth_start = date('Y-m-d', strtotime(date($request->year.'-'. $request->month .'-1')." -1 month"));
|
||||
$prev_mth = explode('-', $prev_mth_start);
|
||||
if($request->month == date('m')) {
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('d');
|
||||
}else{
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('t');
|
||||
}
|
||||
|
||||
$yesterday_month_trx = Transaction::where('work_id', $work1->id)->where('dealer_id', $id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end)->sum('qty');
|
||||
|
||||
if(array_key_exists($work1->id, $yesterday_month_trxs_total)) {
|
||||
$yesterday_month_trxs_total[$work1->id] += $yesterday_month_trx;
|
||||
}else{
|
||||
$yesterday_month_trxs_total[$work1->id] = $yesterday_month_trx;
|
||||
}
|
||||
}
|
||||
|
||||
if($dates) {
|
||||
foreach($dates as $key => $date) {
|
||||
$date_works = [];
|
||||
$share_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('work_id', $work->id)->where('dealer_id', $id)->whereDate('date', $date)->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
|
||||
if($d) {
|
||||
$d = $d->sum('qty');
|
||||
if(array_key_exists($work->id, $month_trxs_total)) {
|
||||
$month_trxs_total[$work->id] += $d;
|
||||
}else{
|
||||
$month_trxs_total[$work->id] = $d;
|
||||
}
|
||||
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$trxs[] = [
|
||||
'date' => date('d/m/Y', strtotime($date)),
|
||||
'works' => $date_works
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$dealer_trxs = [];
|
||||
foreach($sas as $key => $sa) {
|
||||
$sa_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('user_sa_id', $sa->id)->where('work_id', $work->id)->where('dealer_id', $id);
|
||||
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
$month = $request->month;
|
||||
|
||||
if($d) {
|
||||
$d = $d->sum('qty');
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$dealer_trxs[] = [
|
||||
'user_sa_id' => $sa->id,
|
||||
'sa_name' => $sa->name,
|
||||
'works' => $sa_works
|
||||
];
|
||||
}
|
||||
|
||||
// $month_trxs_total = array_values($month_trxs_total);
|
||||
// $yesterday_month_trxs_total = array_values($yesterday_month_trxs_total);
|
||||
// dd(["month_trxs_total" => $month_trxs_total, "yesterday_month_trxs_total" => $yesterday_month_trxs_total, "works" => $works->toArray()]);
|
||||
// dd($month_trxs_total);
|
||||
// dd($yesterday_month_trxs_total);
|
||||
$final_month_trxs_total = [];
|
||||
$final_yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$final_month_trxs_total[$work1->id] = array_key_exists($work1->id, $month_trxs_total) ? $month_trxs_total[$work1->id] : 0;
|
||||
$final_yesterday_month_trxs_total[$work1->id] = $yesterday_month_trxs_total[$work1->id];
|
||||
}
|
||||
// dd([$final_month_trxs_total, $final_yesterday_month_trxs_total]);
|
||||
$month_trxs_total = array_values($final_month_trxs_total);
|
||||
$yesterday_month_trxs_total = array_values($final_yesterday_month_trxs_total);
|
||||
$totals = [];
|
||||
for($i = 0; $i < count($month_trxs_total); $i++) {
|
||||
$totals[] = [
|
||||
"prev" => $yesterday_month_trxs_total[$i],
|
||||
"now" => $month_trxs_total[$i],
|
||||
];
|
||||
}
|
||||
|
||||
$works_count = count($works);
|
||||
$month = $request->month;
|
||||
$year = $request->year;
|
||||
return view('dealer_recap', compact('totals', 'month', 'year', 'works', 'works_count', 'trxs', 'dealer', 'dealer_trxs'));
|
||||
}
|
||||
|
||||
private function array_value_recursive($key, array $arr){
|
||||
$val = array();
|
||||
array_walk_recursive($arr, function($v, $k) use($key, &$val){
|
||||
if($k == $key) array_push($val, $v);
|
||||
});
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
}
|
||||
1066
app/Http/Controllers/ApiController.php
Normal file
1066
app/Http/Controllers/ApiController.php
Normal file
File diff suppressed because it is too large
Load Diff
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||
|
||||
class ConfirmPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Confirm Password Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password confirmations and
|
||||
| uses a simple trait to include the behavior. You're free to explore
|
||||
| this trait and override any functions that require customization.
|
||||
|
|
||||
*/
|
||||
|
||||
use ConfirmsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users when the intended url fails.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
}
|
||||
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
}
|
||||
62
app/Http/Controllers/Auth/LoginController.php
Normal file
62
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Privilege;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has been authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param mixed $user
|
||||
* @return mixed
|
||||
*/
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
$user = Privilege::where('menu_id', 10)->where('role_id', Auth::user()->role_id)->where('view', 1)->first();
|
||||
|
||||
if ($user != null) {
|
||||
return redirect()->route('dashboard');
|
||||
}else{
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \App\Models\User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
}
|
||||
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email Verification Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling email verification for any
|
||||
| user that recently registered with the application. Emails may also
|
||||
| be re-sent if the user didn't receive the original email message.
|
||||
|
|
||||
*/
|
||||
|
||||
use VerifiesEmails;
|
||||
|
||||
/**
|
||||
* Where to redirect users after verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('signed')->only('verify');
|
||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||
}
|
||||
}
|
||||
146
app/Http/Controllers/CategoryController.php
Normal file
146
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Menu;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'category.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if ($request->ajax()) {
|
||||
$data = Category::all();
|
||||
return DataTables::of($data)->addIndexColumn()
|
||||
->addColumn('action', function($row) use ($menu) {
|
||||
$btn = '';
|
||||
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('category.destroy', $row->id) .'" id="destroyCategory'. $row->id .'" onclick="destroyCategory('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-warning btn-sm btn-bold" id="editCategory'. $row->id .'" data-url="'. route('category.edit', $row->id) .'" data-action="'. route('category.update', $row->id) .'" onclick="editCategory('. $row->id .')"> Edit </button>';
|
||||
}
|
||||
|
||||
return $btn;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
return view('back.master.category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'category.index')->first();
|
||||
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
|
||||
Category::create($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data created successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Category $category
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Category $category)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Category $category
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
$menu = Menu::where('link', 'category.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$category = Category::find($category->id);
|
||||
$response = [
|
||||
'data' => $category,
|
||||
'status' => 200,
|
||||
'message' => 'get data successfully'
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Category $category
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Category $category)
|
||||
{
|
||||
$menu = Menu::where('link', 'category.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
Category::find($category->id)->update($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Category $category
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$menu = Menu::where('link', 'category.index')->first();
|
||||
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
|
||||
Category::destroy($category->id);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data deleted successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Normal file
13
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
178
app/Http/Controllers/DealerController.php
Normal file
178
app/Http/Controllers/DealerController.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use App\Models\Menu;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
// use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class DealerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if ($request->ajax()) {
|
||||
$data = Dealer::leftJoin('users as u', 'u.id', '=', 'pic')->select('u.name as pic_name', 'dealers.*');
|
||||
return Datatables::of($data)->addIndexColumn()
|
||||
->addColumn('action', function($row) use ($menu) {
|
||||
$btn = '';
|
||||
if($row->pic != null) {
|
||||
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('dealer.destroy', $row->id) .'" id="destroyDealer'. $row->id .'" onclick="destroyDealer('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-warning btn-sm btn-bold" id="editDealer'. $row->id .'" data-url="'. route('dealer.edit', $row->id) .'" data-action="'. route('dealer.update', $row->id) .'" onclick="editDealer('. $row->id .')"> Edit </button>';
|
||||
}
|
||||
}else{
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('dealer.destroy', $row->id) .'" id="destroyDealer'. $row->id .'" onclick="destroyDealer('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-warning btn-sm btn-bold" id="editDealer'. $row->id .'" data-url="'. route('dealer.edit', $row->id) .'" data-action="'. route('dealer.update', $row->id) .'" onclick="editDealer('. $row->id .')"> Edit </button>
|
||||
<button class="btn btn-success btn-sm btn-bold" data-action="'. route('dealer.picstore', $row->id) .'" id="addPic'. $row->id .'" data-url="'. route('dealer.edit', $row->id) .'" onclick="addPic('. $row->id .')"> Tambahkan PIC </button>';
|
||||
}
|
||||
}
|
||||
|
||||
return $btn;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
$mechanics = User::where('role_id', 3)->get();
|
||||
return view('back.master.dealer', compact('mechanics'));
|
||||
}
|
||||
|
||||
public function pic_store(Request $request, $id)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
|
||||
Dealer::find($id)->update([
|
||||
'pic' => $request->pic
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
|
||||
Dealer::create($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data created successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Dealer $dealer)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Dealer $dealer)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$dealer = Dealer::find($dealer->id);
|
||||
$response = [
|
||||
'data' => $dealer,
|
||||
'status' => 200,
|
||||
'message' => 'get data successfully'
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Dealer $dealer)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
Dealer::find($dealer->id)->update($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Dealer $dealer)
|
||||
{
|
||||
$menu = Menu::where('link', 'dealer.index')->first();
|
||||
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
|
||||
Dealer::destroy($dealer->id);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data deleted successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/HomeController.php
Normal file
28
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
565
app/Http/Controllers/ReportController.php
Normal file
565
app/Http/Controllers/ReportController.php
Normal file
@@ -0,0 +1,565 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\TransactionDealerExport;
|
||||
use App\Exports\TransactionExport;
|
||||
use App\Exports\TransactionSaExport;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Models\Work;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function transaction_sa_old2(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction_sa')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->dealer)) {
|
||||
$request['dealer'] = 'all';
|
||||
}
|
||||
|
||||
if(!isset($request->sa)) {
|
||||
$request['sa'] = 'all';
|
||||
}
|
||||
|
||||
$works = Work::select('id', 'name')->whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q = $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$q = $q->where('dealer_id', '=', $request->dealer);
|
||||
}
|
||||
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$q = $q->where('user_sa_id', '=', $request->sa);
|
||||
}
|
||||
|
||||
return $q;
|
||||
})->orderBy('id', 'ASC')->get();
|
||||
|
||||
$dealer_datas = Dealer::orderBy('id', 'ASC')->get();
|
||||
$sa_datas = User::select('id', 'name')->where('role_id', 4)->get();
|
||||
$sa = $request->sa;
|
||||
$dealer = $request->dealer;
|
||||
$month = $request->month;
|
||||
|
||||
return view('back.report.transaction_sa', compact('dealer_datas', 'sa_datas', 'month', 'works', 'sa', 'dealer'));
|
||||
}
|
||||
|
||||
public function transaction_sa(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction_sa')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
if(!isset($request->dealer)) {
|
||||
$request['dealer'] = '20';
|
||||
}
|
||||
|
||||
if(!isset($request->sa)) {
|
||||
$request['sa'] = 'all';
|
||||
}
|
||||
|
||||
$dealer_datas = Dealer::orderBy('id', 'ASC')->get();
|
||||
$sa_datas = User::select('id', 'name')->where('role_id', 4)->get();
|
||||
|
||||
$sa = $request->sa;
|
||||
$dealer = $request->dealer;
|
||||
$month = $request->month;
|
||||
$year = $request->year;
|
||||
|
||||
$ajax_url = route('report.transaction_sa_data').'?month='.$month.'&year='.$year.'&dealer='.$dealer.'&sa='.$sa;
|
||||
|
||||
return view('back.report.transaction_sa', compact('dealer_datas', 'sa_datas', 'month', 'year', 'sa', 'dealer', 'ajax_url'));
|
||||
}
|
||||
|
||||
public function transaction_sa_data(Request $request) {
|
||||
abort_if(Gate::denies('view', Menu::where('link', 'dashboard')->first()), 403, 'Unauthorized User');
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
if(isset($request->{'amp;dealer'})) {
|
||||
$request['dealer'] = $request->{'amp;dealer'};
|
||||
}
|
||||
|
||||
if(isset($request->{'amp;sa'})) {
|
||||
$request['sa'] = $request->{'amp;sa'};
|
||||
}
|
||||
|
||||
if(isset($request->{'amp;year'})) {
|
||||
$request['year'] = $request->{'amp;year'};
|
||||
}
|
||||
|
||||
if(!isset($request->dealer)) {
|
||||
$request['dealer'] = 'all';
|
||||
}
|
||||
|
||||
$month = $request->month;
|
||||
$dealer = $request->dealer;
|
||||
$sa = $request->sa;
|
||||
$year = $request->year;
|
||||
|
||||
$dealer_work_trx = DB::statement("SET @sql = NULL");
|
||||
$sql = "SELECT IF(work_id IS NOT NULL, GROUP_CONCAT(DISTINCT CONCAT('SUM(IF(work_id = \"', work_id,'\", qty,\"\")) AS \"',CONCAT(w.name, '|',w.id),'\"')), 's.work_id') INTO @sql FROM transactions t JOIN works w ON w.id = t.work_id WHERE month(t.date) = '". $month ."' and year(t.date) = '". $year ."' and t.deleted_at is null";
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$sql .= " and t.dealer_id = '". $dealer ."'";
|
||||
}
|
||||
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$sql .= " and t.user_sa_id = '". $sa ."'";
|
||||
}
|
||||
|
||||
$sa_work_trx = DB::statement($sql);
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' and s.user_sa_id = '". $sa ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as sa_id \", \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' and s.user_sa_id = '". $sa ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}else{
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as sa_id \", \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.dealer_id = '". $dealer ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}
|
||||
}else{
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.user_sa_id = '". $sa ."' GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as user_sa_id \", \"FROM transactions s JOIN dealers d ON d.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null and s.user_sa_id = '". $sa ."' GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}else{
|
||||
$sa_work_trx = DB::statement("SET @sql = IF(@sql != 's.work_id' ,CONCAT(\"SELECT sa.name as SA, sa.id as sa_id, \", @sql, \"FROM transactions s JOIN users sa ON sa.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null GROUP BY s.user_sa_id ORDER BY s.user_sa_id ASC\"), CONCAT(\"SELECT sa.name as SA, sa.id as user_sa_id \", \"FROM transactions s JOIN dealers d ON d.id = s.user_sa_id WHERE month(s.date) = '". $month ."' and year(s.date) = '". $year ."' and s.deleted_at is null GROUP BY s.`user_sa_id` ORDER BY s.`user_sa_id` ASC\"))");
|
||||
}
|
||||
}
|
||||
|
||||
$sa_work_trx = DB::statement("PREPARE stmt FROM @sql");
|
||||
$sa_work_trx = DB::select(DB::raw("EXECUTE stmt"));
|
||||
DB::statement('DEALLOCATE PREPARE stmt');
|
||||
$theads = ['SA'];
|
||||
$sa_names = [];
|
||||
$sa_trx = [];
|
||||
$work_trx = [];
|
||||
$work_ids = [];
|
||||
|
||||
foreach($sa_work_trx as $index => $sa_work) {
|
||||
$sa_work_2 = (array) $sa_work;
|
||||
unset($sa_work_2['sa_id']);
|
||||
$work_trx[$sa_work->sa_id] = array_values($sa_work_2);
|
||||
unset($sa_work_2['SA']);
|
||||
$work_names = array_keys($sa_work_2);
|
||||
if($index == 0) {
|
||||
foreach($work_names as $work) {
|
||||
$arr_work = explode('|', $work);
|
||||
$theads[] = $arr_work[0];
|
||||
$work_ids[] = $arr_work[1];
|
||||
$sa_trx[$work] = [
|
||||
'work_name' => $arr_work[0],
|
||||
'qty' => []
|
||||
];
|
||||
|
||||
if($sa_work->{$work} > 0) {
|
||||
$sa_trx[$work]['qty'][] = $sa_work->{$work};
|
||||
}else{
|
||||
$sa_trx[$work]['qty'][] = "N/A";
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach($work_names as $work) {
|
||||
if($sa_work->{$work} > 0) {
|
||||
$sa_trx[$work]['qty'][] = $sa_work->{$work};
|
||||
}else{
|
||||
$sa_trx[$work]['qty'][] = "N/A";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sa_names[] = $sa_work->SA;
|
||||
}
|
||||
|
||||
$sa_trx = array_values($sa_trx);
|
||||
$dealer = $request->dealer;
|
||||
$month = $request->month;
|
||||
$sa = $request->sa;
|
||||
$year = $request->year;
|
||||
|
||||
$sa_names = json_encode($sa_names);
|
||||
$sa_trx = json_encode($sa_trx);
|
||||
|
||||
return view('back.report.transaction_sa_data', compact('theads', 'work_trx', 'month', 'sa_names', 'sa_trx', 'dealer', 'sa', 'year'));
|
||||
}
|
||||
|
||||
public function transaction_sa_old(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction_sa')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
$works = Work::select('id', 'name')->whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q->whereMonth('date', '=', $request->month);
|
||||
}
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$q->where('dealer_id', '=', $request->dealer);
|
||||
}
|
||||
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$q->where('user_sa_id', '=', $request->sa);
|
||||
}
|
||||
})->get();
|
||||
|
||||
$sas = User::select('id', 'name')->where('role_id', 4)->get();
|
||||
|
||||
$trxs = [];
|
||||
foreach($sas as $key => $sa) {
|
||||
$sa_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('user_sa_id', $sa->id)->where('work_id', $work->id);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month);
|
||||
}
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$d = $d->where('dealer_id', '=', $request->dealer);
|
||||
}
|
||||
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$d = $d->where('user_sa_id', '=', $request->sa);
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
if($d) {
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$trxs[] = [
|
||||
'user_sa_id' => $sa->id,
|
||||
'sa_name' => $sa->name,
|
||||
'works' => $sa_works
|
||||
];
|
||||
}
|
||||
|
||||
$sa_names = [];
|
||||
$trx_data = [];
|
||||
foreach($trxs as $trx) {
|
||||
$sa_names[] = $trx['sa_name'];
|
||||
$work_data2 = [];
|
||||
foreach($trx['works'] as $work_data) {
|
||||
if(array_key_exists($work_data['work_name'], $trx_data)) {
|
||||
$trx_data[$work_data['work_name']]['qty'][] = $work_data['qty'];
|
||||
}else{
|
||||
$trx_data[$work_data['work_name']] = [
|
||||
'work_name' => $work_data['work_name'],
|
||||
'qty' => [$work_data['qty']]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sa_names = json_encode($sa_names);
|
||||
$trx_data = json_encode(array_values($trx_data));
|
||||
// dd($trx_data);
|
||||
$work_count = count($works);
|
||||
$month = $request->month;
|
||||
$dealer_id = $request->dealer;
|
||||
$sa_id = $request->sa;
|
||||
$dealers = Dealer::all();
|
||||
$sas = User::where('role_id', 4)->get();
|
||||
|
||||
|
||||
return view('back.report.transaction_sa', compact('sas', 'dealers', 'dealer_id', 'sa_id', 'month', 'trxs', 'works', 'work_count', 'sa_names', 'trx_data'));
|
||||
}
|
||||
|
||||
public function sa_work_trx(Request $request) {
|
||||
$sa_work_trx = Work::select(DB::raw('works.name AS work_name'), DB::raw("IFNULL(SUM(t.qty), 0) AS qty"), 'works.id AS work_id')->whereHas('transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q = $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$q = $q->where('dealer_id', '=', $request->dealer);
|
||||
}
|
||||
|
||||
if(isset($request->sa_filter) && $request->sa_filter != 'all') {
|
||||
$q = $q->where('user_sa_id', '=', $request->sa_filter);
|
||||
}
|
||||
|
||||
return $q;
|
||||
})->leftJoin('transactions AS t', function($q) use($request) {
|
||||
$q->on('t.work_id', '=', 'works.id');
|
||||
$q->on(DB::raw('MONTH(t.date)'), '=', DB::raw($request->month));
|
||||
$q->on(DB::raw('YEAR(t.date)'), '=', DB::raw(date('Y')));
|
||||
$q->on('t.user_sa_id', '=', DB::raw($request->sa));
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$q->on('t.dealer_id', '=', DB::raw($request->dealer));
|
||||
}
|
||||
if(isset($request->sa_filter) && $request->sa_filter != 'all') {
|
||||
$q->on('t.user_sa_id', '=', DB::raw($request->sa_filter));
|
||||
}
|
||||
})->groupBy('works.id')->orderBy('works.id', 'ASC')->get();
|
||||
return response()->json($sa_work_trx);
|
||||
}
|
||||
|
||||
public function get_sa_has_transactions(Request $request) {
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->dealer)) {
|
||||
$request['dealer'] = 'all';
|
||||
}
|
||||
|
||||
if(!isset($request->sa)) {
|
||||
$request['sa'] = 'all';
|
||||
}
|
||||
|
||||
$sas = User::where('role_id', 4)->whereHas('sa_transactions', function($q) use($request) {
|
||||
if(isset($request->month)) {
|
||||
$q = $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
|
||||
if(isset($request->dealer) && $request->dealer != 'all') {
|
||||
$q->where('dealer_id', '=', $request->dealer);
|
||||
}
|
||||
});
|
||||
|
||||
if(isset($request->sa) && $request->sa != 'all') {
|
||||
$sas = $sas->where('id', $request->sa);
|
||||
}
|
||||
|
||||
$sas = $sas->orderBy('id', 'ASC')->get();
|
||||
|
||||
return response()->json($sas);
|
||||
}
|
||||
|
||||
public function transaction_dealer(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction_dealer')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
$year = $request->year;
|
||||
$month = $request->month;
|
||||
$dealer = $request->dealer;
|
||||
$dealer_datas = Dealer::all();
|
||||
$ajax_url = route('dashboard_data').'?month='.$month.'&year='.$year.'&dealer='.$dealer;
|
||||
return view('dashboard', compact('month', 'ajax_url', 'dealer', 'dealer_datas', 'year'));
|
||||
}
|
||||
|
||||
public function transaction(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
$sas = User::where('role_id', 4)->get();
|
||||
$mechanics = User::where('role_id', 3)->get();
|
||||
$dealers = Dealer::all();
|
||||
$works = Work::all();
|
||||
|
||||
return view('back.report.transaction', compact('sas', 'mechanics', 'dealers', 'works'));
|
||||
}
|
||||
|
||||
public function transaction_data(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
|
||||
if ($request->ajax()) {
|
||||
$data = Transaction::leftJoin('users', 'users.id', '=', 'transactions.user_id')
|
||||
->leftJoin('users as sa', 'sa.id', '=', 'transactions.user_sa_id')
|
||||
->leftJoin('works as w', 'w.id', '=', 'transactions.work_id')
|
||||
->leftJoin('categories as cat', 'cat.id', '=', 'w.category_id')
|
||||
->leftJoin('dealers as d', 'd.id', '=', 'transactions.dealer_id')
|
||||
->select('transactions.id', 'transactions.status', 'transactions.user_id as user_id', 'transactions.user_sa_id as user_sa_id', 'users.name as username', 'sa.name as sa_name', 'cat.name as category_name', 'w.name as workname', 'transactions.qty as qty', 'transactions.date as date', 'transactions.police_number as police_number', 'transactions.warranty as warranty', 'transactions.spk as spk', 'transactions.dealer_id', 'd.name as dealer_name');
|
||||
|
||||
if(isset($request->date_start)) {
|
||||
$data->where('transactions.date', '>=', $request->date_start);
|
||||
}
|
||||
|
||||
if(isset($request->date_end)) {
|
||||
$data->where('transactions.date', '<=', $request->date_end);
|
||||
}
|
||||
|
||||
if(isset($request->sa)) {
|
||||
$data->where('transactions.user_sa_id', $request->sa);
|
||||
}
|
||||
|
||||
if(isset($request->mechanic)) {
|
||||
$data->where('transactions.user_id', $request->mechanic);
|
||||
}
|
||||
|
||||
if(isset($request->dealer)) {
|
||||
$data->where('transactions.dealer_id', $request->dealer);
|
||||
}
|
||||
|
||||
$data->orderBy('date', 'DESC');
|
||||
return DataTables::of($data)->addIndexColumn()
|
||||
->addColumn('action', function($row) use ($menu) {
|
||||
$btn = '';
|
||||
if($row->status == 1) {
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= ' <button class="btn btn-danger btn-sm btn-bold" data-action="'. route('report.transaction.destroy', $row->id) .'" id="destroyTransaction'. $row->id .'" onclick="destroyTransaction('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
$btn .= '<span class="badge badge-success">Closed</span>';
|
||||
}else{
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('report.transaction.destroy', $row->id) .'" id="destroyTransaction'. $row->id .'" onclick="destroyTransaction('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-info btn-sm btn-bold" data-url="'. route('report.transaction.edit', $row->id) .'" data-action="'. route('report.transaction.update', $row->id) .'" onclick="editTransaction('. $row->id .')" id="editTransaction'. $row->id .'"> Edit </button>
|
||||
<button class="btn btn-warning btn-sm btn-bold" id="closeTransaction'. $row->id .'" data-url="'. route('report.transaction.close', $row->id) .'" onclick="closeTransaction('. $row->id .')"> Close </button>';
|
||||
}
|
||||
}
|
||||
|
||||
return $btn;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
return Excel::download(new TransactionExport($request), date('dmY_').'pekerjaan.xlsx');
|
||||
}
|
||||
|
||||
public function dealer_export(Request $request)
|
||||
{
|
||||
return Excel::download(new TransactionDealerExport($request), date('dmY_').'dealer.xlsx');
|
||||
}
|
||||
|
||||
public function sa_export(Request $request)
|
||||
{
|
||||
return Excel::download(new TransactionSaExport($request), date('dmY_').'sa.xlsx');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$transaction = Transaction::find($id);
|
||||
$response = [
|
||||
'data' => $transaction,
|
||||
'status' => 200,
|
||||
'message' => 'get data successfully'
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
|
||||
Transaction::find($id)->update([
|
||||
"spk" => $request->spk,
|
||||
"date" => $request->date,
|
||||
"police_number" => $request->police_number,
|
||||
"work_id" => $request->work_id,
|
||||
"dealer_id" => $request->dealer_id,
|
||||
"qty" => $request->qty,
|
||||
"warranty" => $request->warranty,
|
||||
"user_sa_id" => $request->sa_id,
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function close_transaction($id)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
|
||||
Transaction::find($id)->update([
|
||||
'status' => 1
|
||||
]);
|
||||
|
||||
$response = [
|
||||
'message' => 'Data updated successfully',
|
||||
'status' => 200
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function bulk_close_transaction(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
|
||||
Transaction::whereIn('id', $request->selected)->update([
|
||||
'status' => 1
|
||||
]);
|
||||
|
||||
$response = [
|
||||
'message' => 'Data updated successfully',
|
||||
'status' => 200
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function destroy_transaction($id)
|
||||
{
|
||||
$menu = Menu::where('link', 'report.transaction')->first();
|
||||
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
|
||||
|
||||
Transaction::destroy($id);
|
||||
|
||||
$response = [
|
||||
'message' => 'Data deleted successfully',
|
||||
'status' => 200
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
120
app/Http/Controllers/RolePrivilegeController.php
Normal file
120
app/Http/Controllers/RolePrivilegeController.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Menu;
|
||||
use App\Models\Privilege;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class RolePrivilegeController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
$menu = Menu::where('link', 'roleprivileges.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$roles = Role::all();
|
||||
$menus = Menu::all();
|
||||
$users = User::all();
|
||||
return view('back.roleprivileges', compact('roles', 'users', 'menus'));
|
||||
}
|
||||
|
||||
public function store(Request $request) {
|
||||
$menu = Menu::where('link', 'roleprivileges.index')->first();
|
||||
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
|
||||
$request->validate([
|
||||
'role' => 'required',
|
||||
'privileges' => 'required'
|
||||
]);
|
||||
|
||||
|
||||
$role = Role::create(['name' => $request->role]);
|
||||
if($request->has('privileges')) {
|
||||
$role_privileges = [];
|
||||
foreach ($request->privileges as $submenu_id => $privilege) {
|
||||
$privilege['menu_id'] = $submenu_id;
|
||||
$privilege['role_id'] = $role->id;
|
||||
$privilege['created_at'] = date('Y-m-d H:i:s');
|
||||
$role_privileges[] = $privilege;
|
||||
}
|
||||
|
||||
Privilege::insert($role_privileges);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Berhasil tambah Role & Priveleges');
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$menu = Menu::where('link', 'roleprivileges.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$menus = Menu::all();
|
||||
$user_menus = [];
|
||||
|
||||
$role = Role::find($id);
|
||||
foreach($menus as $menu) {
|
||||
$privilege = Privilege::where('menu_id', $menu->id)->where('role_id', $id)->first();
|
||||
$menu_privilege = [
|
||||
'create' => 0,
|
||||
'update' => 0,
|
||||
'delete' => 0,
|
||||
'view' => 0,
|
||||
'menu_id' => $menu->id,
|
||||
'name' => $menu->name,
|
||||
];
|
||||
|
||||
if($privilege) {
|
||||
$menu_privilege = [
|
||||
'create' => (int) $privilege->create,
|
||||
'update' => (int) $privilege->update,
|
||||
'delete' => (int) $privilege->delete,
|
||||
'view' => (int) $privilege->view,
|
||||
'menu_id' => $menu->id,
|
||||
'name' => $menu->name,
|
||||
];
|
||||
}
|
||||
|
||||
$user_menus[] = $menu_privilege;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'role' => $role,
|
||||
'role_privileges' => $user_menus,
|
||||
];
|
||||
|
||||
return response()->json($data, 200);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id) {
|
||||
$menu = Menu::where('link', 'roleprivileges.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
$request->validate([
|
||||
'role' => 'required',
|
||||
'privileges' => 'required'
|
||||
]);
|
||||
|
||||
Role::find($id)->update(['name' => $request->role]);
|
||||
if($request->has('privileges')) {
|
||||
Privilege::where('role_id', $id)->delete();
|
||||
$role_privileges = [];
|
||||
foreach ($request->privileges as $menu_id => $privilege) {
|
||||
$privilege['menu_id'] = $menu_id;
|
||||
$privilege['role_id'] = $id;
|
||||
$privilege['created_at'] = date('Y-m-d H:i:s');
|
||||
$privilege['updated_at'] = date('Y-m-d H:i:s');
|
||||
$role_privileges[] = $privilege;
|
||||
}
|
||||
|
||||
Privilege::insert($role_privileges);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Berhasil ubah Role & Priveleges');
|
||||
}
|
||||
|
||||
public function delete($id) {
|
||||
Privilege::where('role_id', $id)->delete();
|
||||
Role::destroy($id);
|
||||
User::where('role_id', $id)->update(['role_id' => 0]);
|
||||
return redirect()->back()->with('success', 'Berhasil Hapus Role');
|
||||
}
|
||||
}
|
||||
757
app/Http/Controllers/TransactionController.php
Normal file
757
app/Http/Controllers/TransactionController.php
Normal file
@@ -0,0 +1,757 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Models\Work;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$work_works = Work::leftJoin('categories as c', 'c.id', '=', 'works.category_id')->select('c.name as category_name', 'works.*')->where('c.name', 'LIKE', '%kerja%')->get();
|
||||
$wash_work = Work::leftJoin('categories as c', 'c.id', '=', 'works.category_id')->select('c.name as category_name', 'works.*')->where('c.name', 'LIKE', '%cuci%')->first();
|
||||
$user_sas = User::where('role_id', 4)->where('dealer_id', Auth::user()->dealer_id)->get();
|
||||
$count_transaction_users = Transaction::where("user_id", Auth::user()->id)->count();
|
||||
$count_transaction_dealers = Transaction::leftJoin('users', 'users.id', '=', 'transactions.user_id')->where('users.dealer_id', Auth::user()->dealer_id)->count();
|
||||
$mechanic = User::leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->select('d.name as dealer_name', 'd.id as dealer_id', 'users.name', 'users.id', 'users.role', 'users.email', 'd.dealer_code', 'd.address')
|
||||
->where('users.id', Auth::user()->id)->first();
|
||||
$now = Carbon::now()->translatedFormat('d F Y');
|
||||
return view('transaction.index', compact('now', 'wash_work', 'work_works', 'user_sas', 'count_transaction_users', 'count_transaction_dealers', 'mechanic'));
|
||||
}
|
||||
|
||||
public function workcategory($category_id)
|
||||
{
|
||||
$works = Work::where('category_id', $category_id)->get();
|
||||
$response = [
|
||||
"message" => "get work category successfully",
|
||||
"data" => $works,
|
||||
"status" => 200
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function lists(Request $request)
|
||||
{
|
||||
if(!isset($request->date_start)) {
|
||||
$request['date_start'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
if(!isset($request->date_end)) {
|
||||
$request['date_end'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
$transaction_dealers = Transaction::leftJoin('users', 'users.id', '=', 'transactions.user_id')
|
||||
->leftJoin('users as sa', 'sa.id', '=', 'transactions.user_sa_id')
|
||||
->leftJoin('works as w', 'w.id', '=', 'transactions.work_id')
|
||||
->leftJoin('categories as cat', 'cat.id', '=', 'w.category_id')
|
||||
->select('transactions.id as transaction_id', 'transactions.status', 'transactions.user_id as user_id', 'transactions.user_sa_id as user_sa_id', 'users.name as username', 'sa.name as sa_name', 'cat.name as category_name', 'w.name as workname', 'transactions.qty as qty', 'transactions.date as date', 'transactions.police_number as police_number', 'transactions.warranty as warranty', 'transactions.spk as spk')
|
||||
->where('users.dealer_id', Auth::user()->dealer_id);
|
||||
|
||||
|
||||
|
||||
$transaction_works = Work::select('id', 'name', 'shortname')->whereHas('transactions', function($q) {
|
||||
return $q->whereDate('date', '=', date('Y-m-d'))->where('dealer_id', Auth::user()->dealer_id);
|
||||
})->get();
|
||||
|
||||
$tm1 = [];
|
||||
foreach($transaction_works as $index => $work) {
|
||||
$transaction_sas = Transaction::leftJoin('users as sa', 'sa.id', '=', 'transactions.user_sa_id')
|
||||
->select(DB::raw('SUM(transactions.qty) as qty'), 'sa.name as sa_name')
|
||||
->where('sa.dealer_id', Auth::user()->dealer_id)
|
||||
->where('work_id', $work->id)
|
||||
->whereDate('transactions.date', '=', date('Y-m-d'))->groupBy('transactions.user_sa_id')->get();
|
||||
foreach($transaction_sas as $sa) {
|
||||
$tm1[$work['shortname']]['data'][] = $sa['sa_name'].":".$sa['qty'];
|
||||
}
|
||||
|
||||
$month_share_data = Transaction::select(DB::raw('SUM(qty) as qty'), 'u.name')->join('users AS u', 'u.id', '=', 'transactions.user_sa_id')->where('transactions.dealer_id', Auth::user()->dealer->id)->whereMonth('date', date('m'))->whereYear('date', date('Y'))->where('work_id', $work->id)->groupBy('user_sa_id')->get();
|
||||
$tm1[$work['shortname']]['total_title'] = "*[PERIODE 1 - ". Carbon::now()->translatedFormat('d F Y') ."]*\n\n";
|
||||
|
||||
$sum_month_share_trx = 0;
|
||||
$tm_month = [];
|
||||
foreach($month_share_data as $m_trx) {
|
||||
$tm_month[] = $m_trx->name.":".$m_trx->qty." Unit\n";
|
||||
$sum_month_share_trx += $m_trx->qty;
|
||||
}
|
||||
|
||||
$tm1[$work['shortname']]['total_body'] = $tm_month;
|
||||
$tm1[$work['shortname']]['total_total'] = "*TOTAL : ". $sum_month_share_trx." Unit*";
|
||||
}
|
||||
|
||||
if(isset($request->date_start)) {
|
||||
$transaction_dealers = $transaction_dealers->where('transactions.date', '>=', date('Y-m-d', strtotime($request->date_start)));
|
||||
}
|
||||
|
||||
if(isset($request->date_end)){
|
||||
$transaction_dealers = $transaction_dealers->where('transactions.date', '<=', date('Y-m-d', strtotime($request->date_end)));
|
||||
}
|
||||
|
||||
$transaction_dealers = $transaction_dealers->orderBy('date', 'DESC')->paginate(6);
|
||||
|
||||
$date_start = $request->date_start;
|
||||
$date_end = $request->date_end;
|
||||
|
||||
$transaction_mechanics = ["today_date"=> Carbon::now()->translatedFormat('d F Y'), "data"=>$tm1];
|
||||
$mechanic = User::leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->select('d.name as dealer_name', 'users.name', 'users.id', 'users.role', 'users.email', 'd.dealer_code', 'd.address')
|
||||
->where('users.id', Auth::user()->id)->first();
|
||||
|
||||
$sas = User::where('role_id', 4)->get();
|
||||
$dealers = Dealer::all();
|
||||
$works = Work::all();
|
||||
return view('transaction.lists', compact('transaction_dealers', 'transaction_mechanics', 'mechanic', 'sas', 'dealers', 'works', 'date_start', 'date_end'));
|
||||
}
|
||||
|
||||
public function cmp($a, $b){
|
||||
$key = 'work_id';
|
||||
if($a[$key] > $b[$key]){
|
||||
return 1;
|
||||
}else if($a[$key] < $b[$key]){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function cmp2($a, $b){
|
||||
$key = 'id';
|
||||
if($a[$key] > $b[$key]){
|
||||
return 1;
|
||||
}else if($a[$key] < $b[$key]){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function recap_old(Request $request)
|
||||
{
|
||||
$id = Auth::user()->dealer_id;
|
||||
$works = Work::all();
|
||||
$dealer = Dealer::find($id);
|
||||
$works_count = Work::count();
|
||||
|
||||
$mechanic = User::leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->select('d.name as dealer_name', 'users.name', 'users.id', 'users.role', 'users.email', 'd.dealer_code', 'd.address')
|
||||
->where('users.id', Auth::user()->id)->first();
|
||||
$d = Transaction::leftJoin('works as w', 'w.id', '=', 'transactions.work_id')->select('transactions.*', 'w.name as work_name', 'w.shortname as shortname')->where('dealer_id', $id);
|
||||
|
||||
|
||||
if(isset($request->date_start)) {
|
||||
$d = $d->where('transactions.date', '>=', date('Y-m-d', strtotime($request->date_start)));
|
||||
}
|
||||
|
||||
if(isset($request->date_end)){
|
||||
$d = $d->where('transactions.date', '<=', date('Y-m-d', strtotime($request->date_end)));
|
||||
}
|
||||
|
||||
$d = $d->get()->toArray();
|
||||
|
||||
$works2 = [];
|
||||
foreach($d as $d2) {
|
||||
$w1 = Work::find($d2['work_id']);
|
||||
$works2[$d2['work_id']] = $w1;
|
||||
}
|
||||
usort($works2, array($this, 'cmp2'));
|
||||
$works = $works2;
|
||||
$dw = [];
|
||||
foreach($d as $dw2) {
|
||||
$dw[$dw2['date']][] = $dw2;
|
||||
}
|
||||
$works_count = count($works);
|
||||
$dw9 = [];
|
||||
$sharedw = [];
|
||||
foreach($dw as $key => $dw3) {
|
||||
$dw5 = [];
|
||||
foreach($dw3 as $dw4) {
|
||||
if(array_key_exists($dw4['work_id'], $dw5)) {
|
||||
$dw5[$dw4['work_id']]['qty'] += $dw4['qty'];
|
||||
}else{
|
||||
$dw5[$dw4['work_id']] = $dw4;
|
||||
}
|
||||
}
|
||||
|
||||
usort($dw5, array($this, 'cmp'));
|
||||
$dw7 = [];
|
||||
foreach($dw5 as $dw6) {
|
||||
$dw7[$dw6['work_id']] = $dw6;
|
||||
$sharedw[$key][] = [
|
||||
"work_id" => $dw6['work_id'],
|
||||
"shortname" => $dw6['shortname'],
|
||||
"qty" => $dw6['qty'],
|
||||
"date" => date('d/m/Y', strtotime($dw6['date'])),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$dw8 = [];
|
||||
for($i = 0; $i < count($works2); $i++) {
|
||||
if(array_key_exists($works2[$i]['id'], $dw7)) {
|
||||
$dw8[$works2[$i]['id']] = [
|
||||
"work_id" => $dw7[$works2[$i]['id']]['work_id'],
|
||||
"qty" => $dw7[$works2[$i]['id']]['qty'],
|
||||
"work_name" => $dw7[$works2[$i]['id']]['work_name'],
|
||||
"date" => date('d/m/Y', strtotime($dw7[$works2[$i]['id']]['date']))
|
||||
];
|
||||
}else{
|
||||
$dw8[$works2[$i]['id']] = [
|
||||
"work_id" => $works2[$i]['id'],
|
||||
"qty" => 0,
|
||||
"work_name" => '-',
|
||||
"date" => '-'
|
||||
];
|
||||
}
|
||||
}
|
||||
$dw9[$key] = [
|
||||
'date' => $key,
|
||||
'works' => $dw8
|
||||
];
|
||||
}
|
||||
// $works =
|
||||
$trxs = $dw9;
|
||||
$dwd = [];
|
||||
foreach($d as $dwd2) {
|
||||
$dwd[$dwd2['user_sa_id']][] = $dwd2;
|
||||
}
|
||||
|
||||
$dwd9 = [];
|
||||
foreach($dwd as $key2 => $dwd3) {
|
||||
$dwd5 = [];
|
||||
|
||||
foreach($dwd3 as $dwd4) {
|
||||
if(array_key_exists($dwd4['work_id'], $dwd5)) {
|
||||
$dwd5[$dwd4['work_id']]['qty'] += $dwd4['qty'];
|
||||
}else{
|
||||
$dwd5[$dwd4['work_id']] = $dwd4;
|
||||
}
|
||||
}
|
||||
|
||||
usort($dwd5, array($this, 'cmp'));
|
||||
$dwd7 = [];
|
||||
foreach($dwd5 as $dwd6) {
|
||||
$dwd7[$dwd6['work_id']] = $dwd6;
|
||||
}
|
||||
|
||||
$dwd8 = [];
|
||||
for($i = 0; $i < count($works); $i++) {
|
||||
if(array_key_exists($works[$i]['id'], $dwd7)) {
|
||||
$dwd8[$works[$i]['id']] = [
|
||||
"work_id" => $dwd7[$works[$i]['id']]['work_id'],
|
||||
"qty" => $dwd7[$works[$i]['id']]['qty'],
|
||||
"work_name" => $dwd7[$works[$i]['id']]['work_name'],
|
||||
"date" => date('d/m/Y', strtotime($dwd7[$works[$i]['id']]['date']))
|
||||
];
|
||||
}else{
|
||||
$dwd8[$works[$i]['id']] = [
|
||||
"work_id" => $works[$i]['id'],
|
||||
"qty" => 0,
|
||||
"work_name" => '-',
|
||||
"date" => '-'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sa_name = User::find($key2);
|
||||
$dwd9[$sa_name->name] = [
|
||||
'sa_name' => $sa_name->name,
|
||||
'works' => $dwd8
|
||||
];
|
||||
}
|
||||
|
||||
$dealer_trxs = $dwd9;
|
||||
|
||||
return view('transaction.recap_old', compact('works', 'works_count', 'trxs', 'dealer_trxs','dealer', 'sharedw', 'mechanic'));
|
||||
}
|
||||
|
||||
private function array_value_recursive($key, array $arr){
|
||||
$val = array();
|
||||
array_walk_recursive($arr, function($v, $k) use($key, &$val){
|
||||
if($k == $key) array_push($val, $v);
|
||||
});
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function recap2(Request $request)
|
||||
{
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
$id = Auth::user()->dealer_id;
|
||||
$works = Work::select('id', 'name', 'shortname')->whereHas('transactions', function($q) use($request, $id) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'))->where('dealer_id', $id);
|
||||
}
|
||||
})->get();
|
||||
|
||||
$sas = User::select('id', 'name')->whereHas('sa_transactions', function($q) use($request, $id) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'))->where('dealer_id', $id);
|
||||
}
|
||||
})->get();
|
||||
|
||||
$dealer = Dealer::find($id);
|
||||
$mechanic = User::leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->select('d.name as dealer_name', 'users.name', 'users.id', 'users.role', 'users.email', 'd.dealer_code', 'd.address')
|
||||
->where('users.id', Auth::user()->id)->first();
|
||||
|
||||
$dates = Transaction::select(DB::raw('DATE(`date`) as date'))->where('dealer_id', $id)->whereMonth('date', $request->month)->whereYear('date', date('Y'))->groupBy(DB::raw('DATE(`date`)'))->get()->toArray();
|
||||
$dates = $this->array_value_recursive('date', $dates);
|
||||
|
||||
$month_trxs = [];
|
||||
$month_trxs_total = [];
|
||||
$yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$prev_mth_start = date('Y-m-d', strtotime(date('Y-'. $request->month .'-1')." -1 month"));
|
||||
$prev_mth = explode('-', $prev_mth_start);
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('d');
|
||||
|
||||
$yesterday_month_trx = Transaction::where('work_id', $work1->id)->where('dealer_id', $id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end)->sum('qty');
|
||||
|
||||
if(array_key_exists($work1->id, $yesterday_month_trxs_total)) {
|
||||
$yesterday_month_trxs_total[$work1->id] += $yesterday_month_trx;
|
||||
}else{
|
||||
$yesterday_month_trxs_total[$work1->id] = $yesterday_month_trx;
|
||||
}
|
||||
}
|
||||
|
||||
if($dates) {
|
||||
foreach($dates as $key => $date) {
|
||||
$date_works = [];
|
||||
$share_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('work_id', $work->id)->where('dealer_id', $id)->whereDate('date', $date);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
|
||||
if($d) {
|
||||
if(array_key_exists($work->id, $month_trxs_total)) {
|
||||
$month_trxs_total[$work->id] += $d;
|
||||
}else{
|
||||
$month_trxs_total[$work->id] = $d;
|
||||
}
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$month_trxs[] = [
|
||||
'date' => date('d/m/Y', strtotime($date)),
|
||||
'works' => $date_works
|
||||
];
|
||||
}
|
||||
}
|
||||
$trxs = [];
|
||||
foreach($sas as $key => $sa) {
|
||||
$sa_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('user_sa_id', $sa->id)->where('work_id', $work->id)->where('dealer_id', $id);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', date('Y'));
|
||||
$month = $request->month;
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
if($d) {
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$trxs[] = [
|
||||
'user_sa_id' => $sa->id,
|
||||
'sa_name' => $sa->name,
|
||||
'works' => $sa_works
|
||||
];
|
||||
}
|
||||
|
||||
$sa_names = [];
|
||||
$trx_data = [];
|
||||
foreach($trxs as $trx) {
|
||||
$sa_names[] = $trx['sa_name'];
|
||||
$work_data2 = [];
|
||||
foreach($trx['works'] as $work_data) {
|
||||
if(array_key_exists($work_data['work_name'], $trx_data)) {
|
||||
$trx_data[$work_data['work_name']]['qty'][] = $work_data['qty'];
|
||||
}else{
|
||||
$trx_data[$work_data['work_name']] = [
|
||||
'work_name' => $work_data['work_name'],
|
||||
'qty' => [$work_data['qty']]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sa_names = json_encode($sa_names);
|
||||
$trx_data = json_encode(array_values($trx_data));
|
||||
$works_count = count($works);
|
||||
$share = $month_trxs;
|
||||
$month = $request->month;
|
||||
dd($share);
|
||||
|
||||
return view('transaction.recap', compact('month_trxs_total', 'yesterday_month_trxs_total', 'month', 'trx_data', 'sa_names', 'works', 'works_count', 'trxs', 'month_trxs','dealer', 'share', 'mechanic'));
|
||||
}
|
||||
|
||||
public function recap(Request $request)
|
||||
{
|
||||
if(!isset($request->month)) {
|
||||
$request['month'] = date('m');
|
||||
}
|
||||
|
||||
if(!isset($request->year)) {
|
||||
$request['year'] = date('Y');
|
||||
}
|
||||
|
||||
$id = Auth::user()->dealer_id;
|
||||
$works = Work::select('id', 'name', 'shortname')->whereHas('transactions', function($q) use($request, $id) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', $request->year)->where('dealer_id', $id);
|
||||
}
|
||||
})->get();
|
||||
|
||||
$sas = User::select('id', 'name')->whereHas('sa_transactions', function($q) use($request, $id) {
|
||||
if(isset($request->month)) {
|
||||
return $q->whereMonth('date', '=', $request->month)->whereYear('date', $request->year)->where('dealer_id', $id);
|
||||
}
|
||||
})->get();
|
||||
|
||||
$dealer = Dealer::find($id);
|
||||
$mechanic = User::leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->select('d.name as dealer_name', 'users.name', 'users.id', 'users.role', 'users.email', 'd.dealer_code', 'd.address')
|
||||
->where('users.id', Auth::user()->id)->first();
|
||||
|
||||
$dates = Transaction::select(DB::raw('DATE(`date`) as date'))->where('dealer_id', $id)->whereMonth('date', $request->month)->whereYear('date', $request->year)->groupBy(DB::raw('DATE(`date`)'))->get()->toArray();
|
||||
// print_r($dates);die;
|
||||
$dates = $this->array_value_recursive('date', $dates);
|
||||
|
||||
$month_trxs = [];
|
||||
$month_trxs_total = [];
|
||||
$yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$prev_mth_start = date('Y-m-d', strtotime(date($request->year.'-'. $request->month .'-1')." -1 month"));
|
||||
$prev_mth = explode('-', $prev_mth_start);
|
||||
if($request->month == date('m')) {
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('d');
|
||||
}else{
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('t');
|
||||
}
|
||||
|
||||
// dd($prev_mth_end);
|
||||
$yesterday_month_trx = Transaction::where('work_id', $work1->id)->where('dealer_id', $id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end)->sum('qty');
|
||||
|
||||
if(array_key_exists($work1->id, $yesterday_month_trxs_total)) {
|
||||
$yesterday_month_trxs_total[$work1->id] += $yesterday_month_trx;
|
||||
}else{
|
||||
$yesterday_month_trxs_total[$work1->id] = $yesterday_month_trx;
|
||||
}
|
||||
}
|
||||
if($dates) {
|
||||
foreach($dates as $key => $date) {
|
||||
$date_works = [];
|
||||
$share_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('work_id', $work->id)->where('dealer_id', $id)->whereDate('date', $date);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
|
||||
if($d) {
|
||||
if(array_key_exists($work->id, $month_trxs_total)) {
|
||||
$month_trxs_total[$work->id] += $d;
|
||||
}else{
|
||||
$month_trxs_total[$work->id] = $d;
|
||||
}
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$date_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'shortname' => $work->shortname,
|
||||
'date' => $date,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$month_trxs[] = [
|
||||
'date' => date('d/m/Y', strtotime($date)),
|
||||
'works' => $date_works
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this_month_trxs = Transaction::select(DB::raw('SUM(qty) as qty'), 'u.name')->join('users AS u', 'u.id', '=', 'transactions.user_sa_id')->where('transactions.dealer_id', $id)->whereMonth('date', date('m'))->whereYear('date', $request->year)->groupBy('user_sa_id')->get();
|
||||
$today_trxs = Transaction::select(DB::raw('SUM(qty) as qty'), 'u.name')->join('users AS u', 'u.id', '=', 'transactions.user_sa_id')->where('transactions.dealer_id', $id)->whereDate('date', date('Y-m-d'))->groupBy('user_sa_id')->get();
|
||||
|
||||
$trxs = [];
|
||||
foreach($sas as $key => $sa) {
|
||||
$sa_works = [];
|
||||
foreach ($works as $key2 => $work) {
|
||||
$d = Transaction::where('user_sa_id', $sa->id)->where('work_id', $work->id)->where('dealer_id', $id);
|
||||
|
||||
if(isset($request->month)) {
|
||||
$d = $d->whereMonth('date', '=', $request->month)->whereYear('date', $request->year);
|
||||
$month = $request->month;
|
||||
}
|
||||
|
||||
$d = $d->sum('qty');
|
||||
if($d) {
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => $d,
|
||||
];
|
||||
}else{
|
||||
$sa_works[] = [
|
||||
'work_id' => $work->id,
|
||||
'work_name' => $work->name,
|
||||
'user_sa_id' => $sa->id,
|
||||
'qty' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$trxs[] = [
|
||||
'user_sa_id' => $sa->id,
|
||||
'sa_name' => $sa->name,
|
||||
'works' => $sa_works
|
||||
];
|
||||
}
|
||||
|
||||
$sa_names = [];
|
||||
$trx_data = [];
|
||||
foreach($trxs as $trx) {
|
||||
$sa_names[] = $trx['sa_name'];
|
||||
$work_data2 = [];
|
||||
foreach($trx['works'] as $work_data) {
|
||||
if(array_key_exists($work_data['work_name'], $trx_data)) {
|
||||
$trx_data[$work_data['work_name']]['qty'][] = $work_data['qty'];
|
||||
}else{
|
||||
$trx_data[$work_data['work_name']] = [
|
||||
'work_name' => $work_data['work_name'],
|
||||
'qty' => [$work_data['qty']]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dd($works);
|
||||
// dd([$month_trxs_total, $yesterday_month_trxs_total]);
|
||||
$final_month_trxs_total = [];
|
||||
$final_yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$final_month_trxs_total[$work1->id] = $month_trxs_total[$work1->id];
|
||||
$final_yesterday_month_trxs_total[$work1->id] = $yesterday_month_trxs_total[$work1->id];
|
||||
}
|
||||
// dd([$final_month_trxs_total, $final_yesterday_month_trxs_total]);
|
||||
$month_trxs_total = array_values($final_month_trxs_total);
|
||||
$yesterday_month_trxs_total = array_values($final_yesterday_month_trxs_total);
|
||||
|
||||
$totals = [];
|
||||
for($i = 0; $i < count($month_trxs_total); $i++) {
|
||||
$totals[] = [
|
||||
"prev" => $yesterday_month_trxs_total[$i],
|
||||
"now" => $month_trxs_total[$i],
|
||||
];
|
||||
}
|
||||
|
||||
$sa_names = json_encode($sa_names);
|
||||
$trx_data = json_encode(array_values($trx_data));
|
||||
$works_count = count($works);
|
||||
$share = ["this_month_trxs" => $this_month_trxs, "today_trxs" => $today_trxs, 'today_date' => Carbon::now()->translatedFormat('d F Y')];
|
||||
$month = $request->month;
|
||||
$year = $request->year;
|
||||
|
||||
return view('transaction.recap', compact('totals', 'month', 'year', 'trx_data', 'sa_names', 'works', 'works_count', 'trxs', 'month_trxs','dealer', 'share', 'mechanic'));
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Transaction::find($id)->delete();
|
||||
|
||||
$response = [
|
||||
'message' => 'Data deleted successfully',
|
||||
'status' => 200
|
||||
];
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request['quantity'] = array_filter($request['quantity'], function($value) { return !is_null($value) && $value !== ''; });
|
||||
$request->validate([
|
||||
'work_id.*' => ['required', 'integer'],
|
||||
'quantity.*' => ['required', 'integer'],
|
||||
'spk_no' => ['required', function($attribute, $value, $fail) use($request) {
|
||||
$date = explode('/', $request->date);
|
||||
$date = $date[2].'-'.$date[0].'-'.$date[1];
|
||||
|
||||
if(!$request->work_id) {
|
||||
$fail('Pekerjaan harus diisi');
|
||||
}else{
|
||||
$error_work = '';
|
||||
foreach($request->work_id as $work_id) {
|
||||
$check = Transaction::with(['work'])->where('work_id', $work_id)->where('date', $date)->where('spk', $value)->where('police_number', $request->police_number)->orderBy('id', 'DESC')->whereDate('created_at', date('Y-m-d'))->limit(1)->first();
|
||||
if($check) {
|
||||
$error_work .= $check->work->name.', ';
|
||||
}
|
||||
}
|
||||
|
||||
if($error_work) {
|
||||
$fail('SPK ini sudah digunakan untuk pekerjaan '. $error_work .' sebelumnya');
|
||||
}
|
||||
}
|
||||
}],
|
||||
'police_number' => ['required', function($attribute, $value, $fail) use($request) {
|
||||
$date = explode('/', $request->date);
|
||||
$date = $date[2].'-'.$date[0].'-'.$date[1];
|
||||
|
||||
if(!$request->work_id) {
|
||||
$fail('Pekerjaan harus diisi');
|
||||
}else{
|
||||
$error_work = '';
|
||||
foreach($request->work_id as $work_id) {
|
||||
$check = Transaction::with(['work'])->where('work_id', $work_id)->where('date', $date)->where('spk', $request->spk_no)->where('police_number', $value)->orderBy('id', 'DESC')->whereDate('created_at', date('Y-m-d'))->limit(1)->first();
|
||||
if($check) {
|
||||
$error_work .= $check->work->name.', ';
|
||||
}
|
||||
}
|
||||
|
||||
if($error_work) {
|
||||
$fail('No Polisi ini sudah digunakan untuk pekerjaan '. $error_work .' sebelumnya');
|
||||
}
|
||||
}
|
||||
}],
|
||||
'warranty' => ['required'],
|
||||
'date' => ['required', function($attribute, $value, $fail) use($request) {
|
||||
$date = explode('/', $value);
|
||||
$date = $date[2].'-'.$date[0].'-'.$date[1];
|
||||
|
||||
if(!$request->work_id) {
|
||||
$fail('Pekerjaan harus diisi');
|
||||
}else{
|
||||
$error_work = '';
|
||||
foreach($request->work_id as $work_id) {
|
||||
$check = Transaction::with(['work'])->where('work_id', $work_id)->where('date', $date)->where('spk', $request->spk_no)->where('police_number', $request->police_number)->orderBy('id', 'DESC')->whereDate('created_at', date('Y-m-d'))->limit(1)->first();
|
||||
if($check) {
|
||||
$error_work .= $check->work->name.', ';
|
||||
}
|
||||
}
|
||||
|
||||
if($error_work) {
|
||||
$fail('Tanggal ini sudah digunakan untuk pekerjaan '. $error_work .' sebelumnya');
|
||||
}
|
||||
}
|
||||
}],
|
||||
'category' => ['required'],
|
||||
'user_sa_id' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
$request['date'] = explode('/', $request->date);
|
||||
$request['date'] = $request['date'][2].'-'.$request['date'][0].'-'.$request['date'][1];
|
||||
|
||||
$data = [];
|
||||
for($i = 0; $i < count($request->work_id); $i++) {
|
||||
$data[] = [
|
||||
"user_id" => $request->mechanic_id,
|
||||
"dealer_id" => $request->dealer_id,
|
||||
"form" => $request->form,
|
||||
"work_id" => $request->work_id[$i],
|
||||
"qty" => $request->quantity[$i],
|
||||
"spk" => $request->spk_no,
|
||||
"police_number" => $request->police_number,
|
||||
"warranty" => $request->warranty,
|
||||
"user_sa_id" => $request->user_sa_id,
|
||||
"date" => $request->date,
|
||||
"created_at" => date('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
|
||||
Transaction::insert($data);
|
||||
return redirect()->back()->with('success', 'Berhasil input pekerjaan');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$transaction = Transaction::find($id);
|
||||
$response = [
|
||||
'data' => $transaction,
|
||||
'status' => 200,
|
||||
'message' => 'get data successfully'
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
Transaction::find($id)->update([
|
||||
"spk" => $request->spk,
|
||||
"date" => $request->date,
|
||||
"police_number" => $request->police_number,
|
||||
"work_id" => $request->work_id,
|
||||
"qty" => $request->qty,
|
||||
"warranty" => $request->warranty,
|
||||
"user_sa_id" => $request->sa_id,
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
119
app/Http/Controllers/UserController.php
Normal file
119
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'user.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
if ($request->ajax()) {
|
||||
$data = User::select('r.name as role_name', 'd.name as dealer_name', 'users.id', 'users.name', 'users.email')
|
||||
->leftJoin('dealers as d', 'd.id', '=', 'users.dealer_id')
|
||||
->join('roles as r', 'r.id', '=', 'users.role_id');
|
||||
return DataTables::of($data)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', function($row) use ($menu) {
|
||||
$btn = '';
|
||||
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('user.destroy', $row->id) .'" id="destroyUser'. $row->id .'" onclick="destroyUser('. $row->id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-warning btn-sm btn-bold" id="editUser'. $row->id .'" data-url="'. route('user.edit', $row->id) .'" data-action="'. route('user.update', $row->id) .'" onclick="editUser('. $row->id .')"> Edit </button>';
|
||||
}
|
||||
|
||||
return $btn;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make();
|
||||
}
|
||||
|
||||
$dealers = Dealer::all();
|
||||
$roles = Role::all();
|
||||
return view('back.users', compact('dealers', 'roles'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'user.index')->first();
|
||||
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
|
||||
User::create([
|
||||
"name" => $request->name,
|
||||
"dealer_id" => $request->dealer_id,
|
||||
"role_id" => $request->role,
|
||||
"email" => $request->email,
|
||||
"password" => bcrypt($request->password)
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"message" => "Data created succesfully",
|
||||
"status" => 200
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$menu = Menu::where('link', 'user.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$user = User::find($id);
|
||||
$response = [
|
||||
"data" => $user,
|
||||
"message" => "get data successfully",
|
||||
"status" => 200
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$menu = Menu::where('link', 'user.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
User::find($id)
|
||||
->update([
|
||||
"name" => $request->name,
|
||||
"dealer_id" => $request->dealer_id,
|
||||
"role_id" => $request->role,
|
||||
"email" => $request->email,
|
||||
"password" => bcrypt($request->password)
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$menu = Menu::where('link', 'user.index')->first();
|
||||
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
|
||||
User::destroy($id);
|
||||
$response = [
|
||||
"message" => "Data deleted successfully",
|
||||
"status" => 200
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
148
app/Http/Controllers/WorkController.php
Normal file
148
app/Http/Controllers/WorkController.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Work;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class WorkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'work.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
if ($request->ajax()) {
|
||||
$data = DB::table('works as w')->leftJoin('categories as c', 'c.id', '=', 'w.category_id')->select('w.shortname as shortname', 'w.id as work_id', 'w.name as name', 'w.desc as desc', 'c.name as category_name', 'w.category_id as category_id');
|
||||
return DataTables::of($data)->addIndexColumn()
|
||||
->addColumn('action', function($row) use ($menu) {
|
||||
$btn = '';
|
||||
|
||||
if(Auth::user()->can('delete', $menu)) {
|
||||
$btn .= '<button class="btn btn-danger btn-sm btn-bold" data-action="'. route('work.destroy', $row->work_id) .'" id="destroyWork'. $row->work_id .'" onclick="destroyWork('. $row->work_id .')"> Hapus </button>';
|
||||
}
|
||||
|
||||
if(Auth::user()->can('update', $menu)) {
|
||||
$btn .= '<button class="btn btn-warning btn-sm btn-bold" id="editWork'. $row->work_id .'" data-url="'. route('work.edit', $row->work_id) .'" data-action="'. route('work.update', $row->work_id) .'" onclick="editWork('. $row->work_id .')"> Edit </button>';
|
||||
}
|
||||
|
||||
return $btn;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
$categories = Category::all();
|
||||
return view('back.master.work', compact('categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$menu = Menu::where('link', 'work.index')->first();
|
||||
abort_if(Gate::denies('create', $menu), 403, 'Unauthorized User');
|
||||
Work::create($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data created successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Work $work
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Work $work)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Work $work
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Work $work)
|
||||
{
|
||||
$menu = Menu::where('link', 'work.index')->first();
|
||||
abort_if(Gate::denies('view', $menu), 403, 'Unauthorized User');
|
||||
$work = Work::find($work->id);
|
||||
$response = [
|
||||
'data' => $work,
|
||||
'status' => 200,
|
||||
'message' => 'get data successfully'
|
||||
];
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Work $work
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Work $work)
|
||||
{
|
||||
$menu = Menu::where('link', 'work.index')->first();
|
||||
abort_if(Gate::denies('update', $menu), 403, 'Unauthorized User');
|
||||
Work::find($work->id)->update($request->all());
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Work $work
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Work $work)
|
||||
{
|
||||
$menu = Menu::where('link', 'work.index')->first();
|
||||
abort_if(Gate::denies('delete', $menu), 403, 'Unauthorized User');
|
||||
Work::destroy($work->id);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data deleted successfully"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
69
app/Http/Kernel.php
Normal file
69
app/Http/Kernel.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'adminRole' => \App\Http\Middleware\adminRole::class,
|
||||
'mechanicRole' => \App\Http\Middleware\mechanicRole::class,
|
||||
];
|
||||
}
|
||||
21
app/Http/Middleware/Authenticate.php
Normal file
21
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
38
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
38
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Privilege;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param string|null ...$guards
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
$user = Privilege::where('menu_id', 10)->where('role_id', Auth::user()->role_id)->where('view', 1)->first();
|
||||
if ($user != null) {
|
||||
return redirect('dashboard');
|
||||
}else{
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Middleware/TrustProxies.php
Normal file
28
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
30
app/Http/Middleware/adminRole.php
Normal file
30
app/Http/Middleware/adminRole.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Privilege;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class adminRole
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
// check if user can access admin area
|
||||
$user = Privilege::join('menus AS m', 'm.id', '=', 'privileges.menu_id')->where('m.link', 'adminarea')->where('role_id', Auth::user()->role_id)->where('view', 1)->get();
|
||||
// dd($user);
|
||||
if (!$user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
29
app/Http/Middleware/mechanicRole.php
Normal file
29
app/Http/Middleware/mechanicRole.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Privilege;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class mechanicRole
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
// check if user can access mechanic area
|
||||
$user = Privilege::join('menus AS m', 'm.id', '=', 'privileges.menu_id')->where('m.link', 'mechanicarea')->where('role_id', Auth::user()->role_id)->where('view', 1)->get();
|
||||
if (!$user) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
15
app/Models/Category.php
Normal file
15
app/Models/Category.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
"name", "form"
|
||||
];
|
||||
}
|
||||
25
app/Models/Dealer.php
Normal file
25
app/Models/Dealer.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Dealer extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
'dealer_code', 'name', 'address', 'pic'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all of the transactions for the Dealer
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany(Transaction::class, 'dealer_id', 'id');
|
||||
}
|
||||
}
|
||||
14
app/Models/Menu.php
Normal file
14
app/Models/Menu.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'name', 'link'
|
||||
];
|
||||
}
|
||||
14
app/Models/Privilege.php
Normal file
14
app/Models/Privilege.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Privilege extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'role_id', 'menu_id', 'create', 'update', 'view', 'delete'
|
||||
];
|
||||
}
|
||||
14
app/Models/Role.php
Normal file
14
app/Models/Role.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
25
app/Models/Transaction.php
Normal file
25
app/Models/Transaction.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Transaction extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
"user_id", "user_sa_id", "work_id", "form", "spk", "police_number", "warranty", "date", "qty", "status", "dealer_id"
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the work associated with the Transaction
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function work()
|
||||
{
|
||||
return $this->hasOne(Work::class, 'id', 'work_id');
|
||||
}
|
||||
}
|
||||
78
app/Models/User.php
Normal file
78
app/Models/User.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'role',
|
||||
'dealer_id',
|
||||
'password',
|
||||
'role_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all of the transactions for the User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany(Transaction::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the sa_transactions for the User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function sa_transactions()
|
||||
{
|
||||
return $this->hasMany(Transaction::class, 'user_sa_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dealer associated with the User
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function dealer()
|
||||
{
|
||||
return $this->hasOne(Dealer::class, 'id', 'dealer_id');
|
||||
}
|
||||
}
|
||||
25
app/Models/Work.php
Normal file
25
app/Models/Work.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Work extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
"category_id", "name", "desc", "shortname"
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all of the transactions for the Work
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function transactions()
|
||||
{
|
||||
return $this->hasMany(Transaction::class, 'work_id', 'id');
|
||||
}
|
||||
}
|
||||
38
app/Providers/AppServiceProvider.php
Normal file
38
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Menu;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
View::composer(['layouts.partials.sidebarMenu', 'dashboard', 'dealer_recap', 'back.*'], function ($view) {
|
||||
$menuQuery = Menu::all();
|
||||
$menus = [];
|
||||
foreach($menuQuery as $menu) {
|
||||
$menus[$menu->link] = $menu;
|
||||
}
|
||||
|
||||
$view->with('menus', $menus);
|
||||
});
|
||||
}
|
||||
}
|
||||
103
app/Providers/AuthServiceProvider.php
Normal file
103
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Menu;
|
||||
use App\Models\Privilege;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
Gate::define(
|
||||
'create',
|
||||
function (User $user, Menu $menu) {
|
||||
$role_id = $user->role_id;
|
||||
$privilegeData = Privilege::where('role_id', $role_id)
|
||||
->where('menu_id', $menu->id)
|
||||
->where('create', 1)
|
||||
->first();
|
||||
|
||||
$privilegeData ? $privilege = true : $privilege = false;
|
||||
if($role_id == 0) {
|
||||
$privilege = true;
|
||||
}
|
||||
|
||||
return $privilege;
|
||||
}
|
||||
);
|
||||
|
||||
Gate::define(
|
||||
'update',
|
||||
function (User $user, Menu $menu) {
|
||||
$role_id = $user->role_id;
|
||||
$privilegeData = Privilege::where('role_id', $role_id)
|
||||
->where('menu_id', $menu->id)
|
||||
->where('update', 1)
|
||||
->first();
|
||||
|
||||
$privilegeData ? $privilege = true : $privilege = false;
|
||||
if($role_id == 0) {
|
||||
$privilege = true;
|
||||
}
|
||||
|
||||
return $privilege;
|
||||
}
|
||||
);
|
||||
|
||||
Gate::define(
|
||||
'delete',
|
||||
function (User $user, Menu $menu) {
|
||||
$role_id = $user->role_id;
|
||||
$privilegeData = Privilege::where('role_id', $role_id)
|
||||
->where('menu_id', $menu->id)
|
||||
->where('delete', 1)
|
||||
->first();
|
||||
|
||||
$privilegeData ? $privilege = true : $privilege = false;
|
||||
if($role_id == 0) {
|
||||
$privilege = true;
|
||||
}
|
||||
|
||||
return $privilege;
|
||||
}
|
||||
);
|
||||
|
||||
Gate::define(
|
||||
'view',
|
||||
function (User $user, Menu $menu) {
|
||||
$role_id = $user->role_id;
|
||||
$privilegeData = Privilege::where('role_id', $role_id)
|
||||
->where('menu_id', $menu->id)
|
||||
->where('view', 1)
|
||||
->first();
|
||||
|
||||
$privilegeData ? $privilege = true : $privilege = false;
|
||||
if($role_id == 0) {
|
||||
$privilege = true;
|
||||
}
|
||||
|
||||
return $privilege;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
21
app/Providers/BroadcastServiceProvider.php
Normal file
21
app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
32
app/Providers/EventServiceProvider.php
Normal file
32
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
63
app/Providers/RouteServiceProvider.php
Normal file
63
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
// protected $namespace = 'App\\Http\\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user