ManualPaymentMethodController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\ManualPaymentMethod;
  5. use App\Http\Controllers\OrderController;
  6. use App\Http\Controllers\AffiliateController;
  7. use App\Models\Order;
  8. use App\Models\Category;
  9. use App\Models\BusinessSetting;
  10. use App\Models\Coupon;
  11. use App\Models\CouponUsage;
  12. use App\Models\User;
  13. use Session;
  14. use Auth;
  15. use function back;
  16. use function compact;
  17. use function dd;
  18. use function flash;
  19. use function translate;
  20. use function view;
  21. class ManualPaymentMethodController extends Controller
  22. {
  23. /**
  24. * Display a listing of the resource.
  25. *
  26. * @return \Illuminate\Http\Response
  27. */
  28. public function index() {
  29. $manual_payment_methods = ManualPaymentMethod::all();
  30. return view('manual_payment_methods.index', compact('manual_payment_methods'));
  31. }
  32. /**
  33. * Show the form for creating a new resource.
  34. *
  35. * @return \Illuminate\Http\Response
  36. */
  37. public function create() {
  38. return view('manual_payment_methods.create');
  39. }
  40. /**
  41. * Store a newly created resource in storage.
  42. *
  43. * @param \Illuminate\Http\Request $request
  44. *
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function store( Request $request ) {
  48. $manual_payment_method = new ManualPaymentMethod;
  49. $manual_payment_method->type = $request->type;
  50. $manual_payment_method->photo = $request->photo;
  51. $manual_payment_method->heading = $request->heading;
  52. $manual_payment_method->description = $request->description;
  53. if ( $request->type == 'bank_payment' )
  54. {
  55. $banks_informations = [];
  56. for ( $i = 0; $i < count($request->bank_name); $i++ )
  57. {
  58. $item = [];
  59. $item['bank_name'] = $request->bank_name[$i];
  60. $item['account_name'] = $request->account_name[$i];
  61. $item['account_number'] = $request->account_number[$i];
  62. $item['routing_number'] = $request->routing_number[$i];
  63. array_push($banks_informations, $item);
  64. }
  65. $manual_payment_method->bank_info = json_encode($banks_informations);
  66. }
  67. $manual_payment_method->save();
  68. flash(translate('Method has been inserted successfully'))->success();
  69. return redirect()->route('manual_payment_methods.index');
  70. }
  71. /**
  72. * Display the specified resource.
  73. *
  74. * @param int $id
  75. *
  76. * @return \Illuminate\Http\Response
  77. */
  78. public function show( $id ) {
  79. //
  80. }
  81. /**
  82. * Show the form for editing the specified resource.
  83. *
  84. * @param int $id
  85. *
  86. * @return \Illuminate\Http\Response
  87. */
  88. public function edit( $id ) {
  89. $manual_payment_method = ManualPaymentMethod::findOrFail(decrypt($id));
  90. return view('manual_payment_methods.edit', compact('manual_payment_method'));
  91. }
  92. /**
  93. * Update the specified resource in storage.
  94. *
  95. * @param \Illuminate\Http\Request $request
  96. * @param int $id
  97. *
  98. * @return \Illuminate\Http\Response
  99. */
  100. public function update( Request $request, $id ) {
  101. $manual_payment_method = ManualPaymentMethod::findOrFail($id);
  102. $manual_payment_method->type = $request->type;
  103. $manual_payment_method->heading = $request->heading;
  104. $manual_payment_method->description = $request->description;
  105. if ( $request->type == 'bank_payment' )
  106. {
  107. $banks_informations = [];
  108. for ( $i = 0; $i < count($request->bank_name); $i++ )
  109. {
  110. $item = [];
  111. $item['bank_name'] = $request->bank_name[$i];
  112. $item['account_name'] = $request->account_name[$i];
  113. $item['account_number'] = $request->account_number[$i];
  114. $item['routing_number'] = $request->routing_number[$i];
  115. array_push($banks_informations, $item);
  116. }
  117. $manual_payment_method->bank_info = json_encode($banks_informations);
  118. }
  119. $manual_payment_method->photo = $request->photo;
  120. $manual_payment_method->save();
  121. flash(translate('Method has been updated successfully'))->success();
  122. return redirect()->route('manual_payment_methods.index');
  123. }
  124. /**
  125. * Remove the specified resource from storage.
  126. *
  127. * @param int $id
  128. *
  129. * @return \Illuminate\Http\Response
  130. */
  131. public function destroy( $id ) {
  132. if ( ManualPaymentMethod::destroy($id) )
  133. {
  134. flash(translate('Method has been deleted successfully'))->success();
  135. }
  136. else
  137. {
  138. flash(translate('Something went wrong'))->error();
  139. }
  140. return redirect()->route('manual_payment_methods.index');
  141. }
  142. /**
  143. * Update the specified resource in storage.
  144. *
  145. * @param \Illuminate\Http\Request $request
  146. *
  147. * @return \Illuminate\Http\Response
  148. */
  149. public function show_payment_modal( Request $request ) {
  150. $order = Order::find($request->order_id);
  151. if ( $order != NULL )
  152. {
  153. return view('frontend.user.payment_modal', compact('order'));
  154. }
  155. }
  156. /**
  157. * Update the specified resource in storage.
  158. *
  159. * @param \Illuminate\Http\Request $request
  160. *
  161. * @return \Illuminate\Http\Response
  162. */
  163. public function submit_offline_payment( Request $request ) {
  164. $order = Order::findOrFail($request->order_id);
  165. if ( $request->name != NULL && $request->amount != NULL && $request->trx_id != NULL )
  166. {
  167. $data['name'] = $request->name;
  168. $data['amount'] = $request->amount;
  169. $data['trx_id'] = $request->trx_id;
  170. $data['photo'] = $request->photo;
  171. }
  172. else
  173. {
  174. flash(translate('Please fill all the fields'))->warning();
  175. return back();
  176. }
  177. $order->manual_payment_data = json_encode($data);
  178. $order->payment_type = $request->payment_option;
  179. $order->payment_status = 'Submitted';
  180. $order->manual_payment = 1;
  181. $order->save();
  182. // if (BusinessSetting::where('type', 'category_wise_commission')->first()->value != 1) {
  183. // $commission_percentage = BusinessSetting::where('type', 'vendor_commission')->first()->value;
  184. // foreach ($order->orderDetails as $key => $orderDetail) {
  185. // $orderDetail->payment_status = 'paid';
  186. // $orderDetail->save();
  187. // if($orderDetail->product->user->user_type == 'seller'){
  188. // $seller = $orderDetail->product->user->seller;
  189. // $seller->admin_to_pay = $seller->admin_to_pay + ($orderDetail->price*(100-$commission_percentage))/100;
  190. // $seller->save();
  191. // }
  192. // }
  193. // }
  194. // else{
  195. // foreach ($order->orderDetails as $key => $orderDetail) {
  196. // $orderDetail->payment_status = 'paid';
  197. // $orderDetail->save();
  198. // if($orderDetail->product->user->user_type == 'seller'){
  199. // $commission_percentage = $orderDetail->product->category->commision_rate;
  200. // $seller = $orderDetail->product->user->seller;
  201. // $seller->admin_to_pay = $seller->admin_to_pay + ($orderDetail->price*(100-$commission_percentage))/100;
  202. // $seller->save();
  203. // }
  204. // }
  205. // }
  206. flash(translate('Your payment data has been submitted successfully'))->success();
  207. return redirect()->route('home');
  208. }
  209. public function offline_recharge_modal( Request $request ) {
  210. $type = $request->type ?? 1;
  211. return view('frontend.user.wallet.offline_recharge_modal', compact('type'));
  212. }
  213. public function admin_recharge_modal( Request $request ) {
  214. $type = $request->type ?? 1;
  215. $user_id = $request->user_id;
  216. $user = User::where('id', $user_id)->first();
  217. if (!$user) {
  218. flash(translate('Please select one customer'))->warning();
  219. return back();
  220. }
  221. return view('frontend.user.wallet.admin_recharge_modal', compact('type', 'user'));
  222. }
  223. public function offline_customer_package_purchase_modal( Request $request ) {
  224. $package_id = $request->package_id;
  225. return view('manual_payment_methods.frontend.offline_customer_package_purchase_modal', compact('package_id'));
  226. }
  227. public function offline_seller_package_purchase_modal( Request $request ) {
  228. $package_id = $request->package_id;
  229. return view('manual_payment_methods.frontend.offline_seller_package_purchase_modal', compact('package_id'));
  230. }
  231. public function offline_seller_spread_package_purchase_modal( Request $request ) {
  232. $package_id = $request->package_id;
  233. return view('manual_payment_methods.frontend.offline_seller_spread_package_purchase_modal', compact('package_id'));
  234. }
  235. }