From 43558afc5786a19391f7ba01a0b20f3a954fb300 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Sat, 5 Dec 2020 13:17:50 +0800 Subject: [PATCH] x1 and x2 reports --- routes/web.php | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/routes/web.php b/routes/web.php index 07ea1436..e637e93d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,25 +23,21 @@ Route::post('password/reset', 'Auth\ResetPasswordController@postReset')->name('p Route::get('/report/x1', function(){ - if($this->middleware('role:admin')){ - $bookings = Booking::where('admin_status', '>=', 3)->where('term', 'like', 'x1_%')->where('is_cancel', false)->where('user_id', '!=', 1)->get(); - $months = $bookings->groupBy(function($item) { - return $item->created_at->format('Y-m'); + $bookings = Booking::where('admin_status', '>=', 3)->where('term', 'like', 'x1_%')->where('is_cancel', false)->where('user_id', '!=', 1)->get(); + $months = $bookings->groupBy(function($item) { + return $item->created_at->format('Y-m'); + }); + + foreach($months as $month => $bookings){ + echo "

".Carbon::parse($month)->format('m-Y').": ".$bookings->sum('bia')." MYR

"; + $days = $bookings->groupBy(function($item){ + return $item->created_at->format('Y-m-d'); }); - foreach($months as $month => $bookings){ - echo "

".Carbon::parse($month)->format('m-Y').": ".$bookings->sum('bia')." MYR

"; - $days = $bookings->groupBy(function($item){ - return $item->created_at->format('Y-m-d'); - }); - - foreach($days as $day => $bookings ){ - echo "

".Carbon::parse($day)->format('d-m-Y').": ".$bookings->sum('bia')." MYR

"; - } - + foreach($days as $day => $bookings ){ + echo "

".Carbon::parse($day)->format('d-m-Y').": ".$bookings->sum('bia')." MYR

"; } - } else { - return redirect('/'); + } }); @@ -68,9 +64,6 @@ Route::get('/report/x2', function(){ }); Route::get('/po-approval', function(){ - if(Auth()::user()->role !== 'admin'){ - return redirect('/'); - } $approvedInvoices = InvoiceStatuses::where('status', 'approve')->distinct()->get(['invoice_id'])->pluck('invoice_id'); $pendingChangeInvoices = InvoiceStatuses::where('status', 'request_change')->distinct()->get(['invoice_id'])->pluck('invoice_id'); $invoices = InvoiceStatuses::whereNotIn('invoice_id', $approvedInvoices)->whereNotIn('invoice_id', $pendingChangeInvoices)->get(); @@ -97,9 +90,6 @@ Route::get('/po-approval', function(){ })->name('po.approval'); Route::get('/po-approved', function(){ - if(Auth()::user()->role !== 'admin'){ - return redirect('/'); - } $approvedInvoices = InvoiceStatuses::where('status', 'approve')->distinct()->get(['invoice_id'])->pluck('invoice_id'); $oldCompletedInvoices = Invoice::where('invoice_path', '!=', '')->orWhereNotNull('invoice_path')->get(); $newCompletedInvoices = Invoice::whereIn('id', $approvedInvoices)->get(); @@ -114,9 +104,7 @@ Route::get('/po-approved', function(){ })->name('po.approved'); Route::get('/old-invoices', function(){ - if(Auth()::user()->role !== 'admin'){ - return redirect('/'); - } + $bookings = \App\Booking::where('status', 6)->where('user_id', '!=', 1)->whereHas('purchaseOrder', function($q){ $q->whereNotNull('image_path'); })->get();