ReportController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Product;
  5. use App\Models\CommissionHistory;
  6. use App\Models\Wallet;
  7. use App\Models\Seller;
  8. use App\Models\User;
  9. use App\Models\Search;
  10. use App\Models\Shop;
  11. use Auth;
  12. class ReportController extends Controller
  13. {
  14. public function stock_report(Request $request)
  15. {
  16. $sort_by =null;
  17. $products = Product::orderBy('created_at', 'desc');
  18. if ($request->has('category_id')){
  19. $sort_by = $request->category_id;
  20. $products = $products->where('category_id', $sort_by);
  21. }
  22. $products = $products->paginate(15);
  23. return view('backend.reports.stock_report', compact('products','sort_by'));
  24. }
  25. public function in_house_sale_report(Request $request)
  26. {
  27. $sort_by =null;
  28. $products = Product::orderBy('num_of_sale', 'desc')->where('added_by', 'admin');
  29. if ($request->has('category_id')){
  30. $sort_by = $request->category_id;
  31. $products = $products->where('category_id', $sort_by);
  32. }
  33. $products = $products->paginate(15);
  34. return view('backend.reports.in_house_sale_report', compact('products','sort_by'));
  35. }
  36. public function seller_sale_report(Request $request)
  37. {
  38. $sort_by =null;
  39. // $sellers = User::where('user_type', 'seller')->orderBy('created_at', 'desc');
  40. $sellers = Shop::with('user')->orderBy('created_at', 'desc');
  41. if ($request->has('verification_status')){
  42. $sort_by = $request->verification_status;
  43. $sellers = $sellers->where('verification_status', $sort_by);
  44. }
  45. $sellers = $sellers->paginate(10);
  46. return view('backend.reports.seller_sale_report', compact('sellers','sort_by'));
  47. }
  48. public function wish_report(Request $request)
  49. {
  50. $sort_by =null;
  51. $products = Product::orderBy('created_at', 'desc');
  52. if ($request->has('category_id')){
  53. $sort_by = $request->category_id;
  54. $products = $products->where('category_id', $sort_by);
  55. }
  56. $products = $products->paginate(10);
  57. return view('backend.reports.wish_report', compact('products','sort_by'));
  58. }
  59. public function user_search_report(Request $request){
  60. $searches = Search::orderBy('count', 'desc')->paginate(10);
  61. return view('backend.reports.user_search_report', compact('searches'));
  62. }
  63. public function commission_history(Request $request) {
  64. $seller_id = null;
  65. $date_range = null;
  66. if(Auth::user()->user_type == 'seller') {
  67. $seller_id = Auth::user()->id;
  68. } if($request->seller_id) {
  69. $seller_id = $request->seller_id;
  70. }
  71. $commission_history = CommissionHistory::orderBy('created_at', 'desc');
  72. if ($request->date_range) {
  73. $date_range = $request->date_range;
  74. $date_range1 = explode(" / ", $request->date_range);
  75. $commission_history = $commission_history->where('created_at', '>=', $date_range1[0]);
  76. $commission_history = $commission_history->where('created_at', '<=', $date_range1[1]);
  77. }
  78. if ($seller_id){
  79. $commission_history = $commission_history->where('seller_id', '=', $seller_id);
  80. }
  81. $commission_history = $commission_history->paginate(10);
  82. if(Auth::user()->user_type == 'seller') {
  83. return view('seller.reports.commission_history_report', compact('commission_history', 'seller_id', 'date_range'));
  84. }
  85. return view('backend.reports.commission_history_report', compact('commission_history', 'seller_id', 'date_range'));
  86. }
  87. public function wallet_transaction_history(Request $request) {
  88. $user_id = null;
  89. $date_range = null;
  90. if($request->user_id) {
  91. $user_id = $request->user_id;
  92. }
  93. $users_with_wallet = User::whereIn('id', function($query) {
  94. $query->select('user_id')->from(with(new Wallet)->getTable());
  95. })->get();
  96. $wallet_history = Wallet::orderBy('created_at', 'desc');
  97. if ($request->date_range) {
  98. $date_range = $request->date_range;
  99. $date_range1 = explode(" / ", $request->date_range);
  100. $wallet_history = $wallet_history->where('created_at', '>=', $date_range1[0]);
  101. $wallet_history = $wallet_history->where('created_at', '<=', $date_range1[1]);
  102. }
  103. if ($user_id){
  104. $wallet_history = $wallet_history->where('user_id', '=', $user_id);
  105. }
  106. $wallets = $wallet_history->paginate(10);
  107. return view('backend.reports.wallet_history_report', compact('wallets', 'users_with_wallet', 'user_id', 'date_range'));
  108. }
  109. }