1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\ItemSalesExport;
- use App\Exports\OrderHistoryExport;
- use App\Helpers\CommonMethods;
- use App\Models\Orders;
- use App\Models\Recipes;
- use App\Models\StaticReports;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Excel;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Str;
- class StaticsReport extends Controller
- {
- public function download_order_history(Request $request){
- $start_date = $request->start_date;
- $end_date = $request->end_date;
- $file_name = Str::uuid();
- $dates = ['start_date'=>$start_date,'end_date'=>$end_date,'file_name'=>$file_name];
- Excel::store(new OrderHistoryExport($dates),$request->restoName.'/orders/'.$file_name.'.xlsx','report_files');
- }
- public function static_reports(){
- $resto_id = CommonMethods::getRestuarantID();
- $reports = StaticReports::with(['users'])->whereNull('deleted_at')->where('status','active')->where('resto_id',$resto_id)->orderBy('created_at','DESC')->get();
- $static_reports = [];
- if(isset($reports)&& $reports->count() > 0) {
- foreach($reports as $report){
- $static_reports[$report->report_type][] = array(
- 'id' => $report->id,
- 'file_name'=> $report->file_name,
- 'searched_by'=>$report->users->name,
- 'start_date'=>Carbon::parse($report->start_date)->format('d M Y'),
- 'end_date'=>Carbon::parse($report->end_date)->format('d M Y'),
- 'created_at'=>Carbon::parse($report->created_at)->format('d M Y, H:i'),
- 'data_found'=>$report->is_data_found
- );
- }
- }
- return view('reports.reports',['reports'=>$static_reports]);
- }
- public function load_report_data(Request $request){
- $type = $request->type;
- $resto_id = $request->restoId;
- $reports = StaticReports::with(['users'])
- ->where('status','active')->where('resto_id',$resto_id)->where('order_type',$type)->get();
- $static_reports = [];
- if(isset($reports)&& $reports->count() > 0) {
- foreach($reports as $report){
- $static_reports[] = array(
- 'file_name'=> $report->file_name,
- 'searched_by'=>$report->users->name,
- 'start_date'=>Carbon::parse($report->start_date)->format('d M Y'),
- 'end_date'=>Carbon::parse($report->end_date)->format('d M Y'),
- 'created_at'=>Carbon::parse($report->created_at)->format('d M Y, H:i'),
- 'data_found'=>$report->is_data_found
- );
- }
- }
- return response()->json($static_reports);
- }
- public function getItemSaleCounts(Request $request){
- $start_date = $request->start_date;
- $end_date = $request->end_date;
- $restoName = $request->restoName;
- // $start_date = $request->start_date;
- // $end_date = $request->end_date;
- $file_name = Str::uuid();
- $dates = ['start_date'=>$start_date,'end_date'=>$end_date,'file_name'=>$file_name];
- Excel::store(new ItemSalesExport($dates),$restoName.'/items-sale/'.$file_name.'.xlsx','report_files');
- }
- public function delete_report($id){
- $report = StaticReports::find($id);
- $report->deleted_at = Carbon::now()->format('Y-m-d H:i:s');
- $report->save();
- }
- }
|