123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\BusinessSetting;
- use App\Models\RefundRequest;
- use App\Models\OrderDetail;
- use App\Models\Shop;
- use App\Models\Wallet;
- use App\Models\User;
- use Artisan;
- use Auth;
- class RefundRequestController extends Controller
- {
- /**
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- //Store Customer Refund Request
- public function request_store(Request $request, $id)
- {
- $order_detail = OrderDetail::where('id', $id)->first();
- $refund = new RefundRequest;
- $refund->user_id = Auth::user()->id;
- $refund->order_id = $order_detail->order_id;
- $refund->order_detail_id = $order_detail->id;
- $refund->seller_id = $order_detail->seller_id;
- $refund->seller_approval = 0;
- $refund->reason = $request->reason;
- $refund->admin_approval = 0;
- $refund->admin_seen = 0;
- $refund->refund_amount = $order_detail->price + $order_detail->tax;
- $refund->refund_status = 0;
- if ($refund->save()) {
- flash( translate("Refund Request has been sent successfully") )->success();
- return redirect()->route('purchase_history.index');
- }
- else {
- flash( translate("Something went wrong") )->error();
- return back();
- }
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function vendor_index()
- {
- $refunds = RefundRequest::where('seller_id', Auth::user()->id)->latest()->paginate(10);
-
- return view('refund_request.frontend.recieved_refund_request.index', compact('refunds'));
-
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function customer_index()
- {
- $refunds = RefundRequest::where('user_id', Auth::user()->id)->latest()->paginate(10);
- return view('refund_request.frontend.refund_request.index', compact('refunds'));
- }
- //Set the Refund configuration
- public function refund_config()
- {
- return view('refund_request.config');
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function refund_time_update(Request $request)
- {
- $business_settings = BusinessSetting::where('type', $request->type)->first();
- if ($business_settings != null) {
- $business_settings->value = $request->value;
- $business_settings->save();
- }
- else {
- $business_settings = new BusinessSetting;
- $business_settings->type = $request->type;
- $business_settings->value = $request->value;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash( translate("Refund Request sending time has been updated successfully") )->success();
- return back();
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function refund_sticker_update(Request $request)
- {
- $business_settings = BusinessSetting::where('type', $request->type)->first();
- if ($business_settings != null) {
- $business_settings->value = $request->logo;
- $business_settings->save();
- }
- else {
- $business_settings = new BusinessSetting;
- $business_settings->type = $request->type;
- $business_settings->value = $request->logo;
- $business_settings->save();
- }
- Artisan::call('cache:clear');
- flash( translate("Refund Sticker has been updated successfully"))->success();
- return back();
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function admin_index()
- {
- $refunds = RefundRequest::where('refund_status', 0)->latest()->paginate(15);
- return view('refund_request.index', compact('refunds'));
- }
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function paid_index()
- {
- $refunds = RefundRequest::where('refund_status', 1)->latest()->paginate(15);
- return view('refund_request.paid_refund', compact('refunds'));
- }
- public function rejected_index()
- {
- $refunds = RefundRequest::where('refund_status', 2)->latest()->paginate(15);
- return view('refund_request.rejected_refund', compact('refunds'));
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function request_approval_vendor(Request $request)
- {
- $refund = RefundRequest::findOrFail($request->el);
- if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
- $refund->seller_approval = 1;
- $refund->admin_approval = 1;
- }
- else {
- $refund->seller_approval = 1;
- }
- if ($refund->save()) {
- return 1;
- }
- else {
- return 0;
- }
- }
- /**
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function refund_pay(Request $request)
- {
- $refund = RefundRequest::findOrFail($request->el);
- if ($refund->seller_approval == 1) {
- $seller = Shop::where('user_id', $refund->seller_id)->first();
- if ($seller != null) {
- $seller->admin_to_pay -= $refund->refund_amount;
- }
- $seller->save();
- }
- $wallet = new Wallet;
- $wallet->user_id = $refund->user_id;
- $wallet->amount = $refund->refund_amount;
- $wallet->payment_method = 'Refund';
- $wallet->payment_details = 'Product Money Refund';
- $wallet->save();
- $user = User::findOrFail($refund->user_id);
- $user->balance += $refund->refund_amount;
- $user->save();
- if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
- $refund->admin_approval = 1;
- $refund->refund_status = 1;
- }
- if ($refund->save()) {
- return 1;
- }
- else {
- return 0;
- }
- }
- public function reject_refund_request(Request $request){
- $refund = RefundRequest::findOrFail($request->refund_id);
- if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
- $refund->admin_approval = 2;
- $refund->refund_status = 2;
- $refund->reject_reason = $request->reject_reason;
- }
- else{
- $refund->seller_approval = 2;
- $refund->reject_reason = $request->reject_reason;
- }
-
- if ($refund->save()) {
- flash(translate('Refund request rejected successfully.'))->success();
- return back();
- }
- else {
- return back();
- }
- }
- /**
- * Show the form for creating a new resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function refund_request_send_page($id)
- {
- $order_detail = OrderDetail::findOrFail($id);
- if ($order_detail->product != null && $order_detail->product->refundable == 1) {
- return view('refund_request.frontend.refund_request.create', compact('order_detail'));
- }
- else {
- return back();
- }
- }
- /**
- * Show the form for view the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- //Shows the refund reason
- public function reason_view($id)
- {
- $refund = RefundRequest::findOrFail($id);
- if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
- if ($refund->orderDetail != null) {
- $refund->admin_seen = 1;
- $refund->save();
- return view('refund_request.reason', compact('refund'));
- }
- }
- else {
- return view('refund_request.frontend.refund_request.reason', compact('refund'));
- }
- }
- public function reject_reason_view($id)
- {
- $refund = RefundRequest::findOrFail($id);
- return $refund->reject_reason;
- }
- }
|