StaticsReport.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\ItemSalesExport;
  4. use App\Exports\OrderHistoryExport;
  5. use App\Helpers\CommonMethods;
  6. use App\Models\Orders;
  7. use App\Models\Recipes;
  8. use App\Models\StaticReports;
  9. use Carbon\Carbon;
  10. use Illuminate\Http\Request;
  11. use Excel;
  12. use Illuminate\Support\Facades\Auth;
  13. use Illuminate\Support\Str;
  14. class StaticsReport extends Controller
  15. {
  16. public function download_order_history(Request $request){
  17. $start_date = $request->start_date;
  18. $end_date = $request->end_date;
  19. $file_name = Str::uuid();
  20. $dates = ['start_date'=>$start_date,'end_date'=>$end_date,'file_name'=>$file_name];
  21. Excel::store(new OrderHistoryExport($dates),$request->restoName.'/orders/'.$file_name.'.xlsx','report_files');
  22. }
  23. public function static_reports(){
  24. $resto_id = CommonMethods::getRestuarantID();
  25. $reports = StaticReports::with(['users'])->whereNull('deleted_at')->where('status','active')->where('resto_id',$resto_id)->orderBy('created_at','DESC')->get();
  26. $static_reports = [];
  27. if(isset($reports)&& $reports->count() > 0) {
  28. foreach($reports as $report){
  29. $static_reports[$report->report_type][] = array(
  30. 'id' => $report->id,
  31. 'file_name'=> $report->file_name,
  32. 'searched_by'=>$report->users->name,
  33. 'start_date'=>Carbon::parse($report->start_date)->format('d M Y'),
  34. 'end_date'=>Carbon::parse($report->end_date)->format('d M Y'),
  35. 'created_at'=>Carbon::parse($report->created_at)->format('d M Y, H:i'),
  36. 'data_found'=>$report->is_data_found
  37. );
  38. }
  39. }
  40. return view('reports.reports',['reports'=>$static_reports]);
  41. }
  42. public function load_report_data(Request $request){
  43. $type = $request->type;
  44. $resto_id = $request->restoId;
  45. $reports = StaticReports::with(['users'])
  46. ->where('status','active')->where('resto_id',$resto_id)->where('order_type',$type)->get();
  47. $static_reports = [];
  48. if(isset($reports)&& $reports->count() > 0) {
  49. foreach($reports as $report){
  50. $static_reports[] = array(
  51. 'file_name'=> $report->file_name,
  52. 'searched_by'=>$report->users->name,
  53. 'start_date'=>Carbon::parse($report->start_date)->format('d M Y'),
  54. 'end_date'=>Carbon::parse($report->end_date)->format('d M Y'),
  55. 'created_at'=>Carbon::parse($report->created_at)->format('d M Y, H:i'),
  56. 'data_found'=>$report->is_data_found
  57. );
  58. }
  59. }
  60. return response()->json($static_reports);
  61. }
  62. public function getItemSaleCounts(Request $request){
  63. $start_date = $request->start_date;
  64. $end_date = $request->end_date;
  65. $restoName = $request->restoName;
  66. // $start_date = $request->start_date;
  67. // $end_date = $request->end_date;
  68. $file_name = Str::uuid();
  69. $dates = ['start_date'=>$start_date,'end_date'=>$end_date,'file_name'=>$file_name];
  70. Excel::store(new ItemSalesExport($dates),$restoName.'/items-sale/'.$file_name.'.xlsx','report_files');
  71. }
  72. public function delete_report($id){
  73. $report = StaticReports::find($id);
  74. $report->deleted_at = Carbon::now()->format('Y-m-d H:i:s');
  75. $report->save();
  76. }
  77. }