/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(PagoUpdateRequest $request) { if ($request->ajax()) { $id_site = \Session::get('id_site'); $id_user = $request->id_user; $user = User::find($id_user); $cuota = Cuotas::find($user->type); $pagos = DB::table('pagos')->where('id_user', $id_user)->where('id_site', $id_site)->get(); $newDate = explode("-", $request->date); $flag = true; if (empty($pagos)) { DB::table('pagos')->insert(['id_user' => $id_user, 'date' => $request->date, 'status' => $request->status, 'amount' => $cuota->amount, 'user_name' => $user->name, 'id_site' => $id_site]); $data = ['msg' => 'pago generado', 'subj' => 'Pago acreditado', 'user_mail' => $user->email]; Mail::send('emails.msg', $data, function ($msj) use($data) { $msj->subject($data['subj']); $msj->to($data['user_mail']); }); return response()->json(["tipo" => 'success']); } else { foreach ($pagos as $value) { $date = explode("-", $value->date); if ($date[0] == $newDate[0] && $date[1] == $newDate[1]) { $flag = false; break; } } if ($flag) { $ultimo = DB::table('pagos')->where('id_user', $id_user)->where('id_site', $id_site)->orderBy('date', 'dsc')->take(1)->value('date'); //get next year and month $ultimo_pago = explode("-", $ultimo); if (intval($ultimo_pago[1]) == 12) { $next_m = 1; $next_y = intval($ultimo_pago[0]) + 1; } else { $next_m = intval($ultimo_pago[1]) + 1; $next_y = intval($ultimo_pago[0]); } if (intval($newDate[0]) == $next_y && intval($newDate[1]) == $next_m) { DB::table('pagos')->insert(['id_user' => $id_user, 'date' => $request->date, 'status' => $request->status, 'amount' => $cuota->amount, 'user_name' => $user->name, 'id_site' => $id_site]); $data = ['msg' => 'pago generado', 'subj' => 'Pago acreditado', 'user_mail' => $user->email]; Mail::send('emails.msg', $data, function ($msj) use($data) { $msj->subject($data['subj']); $msj->to($data['user_mail']); }); return response()->json(["tipo" => 'success']); } else { return response()->json(["tipo" => 'fail', "message" => 'No estan permitido intervalos sin pagos creados. Se debe crear un pago con fecha inmediata al ultimo creado.']); } } else { return response()->json(["tipo" => 'fail', "message" => 'Ya existe un pago para este mes y usuario.']); } } } // end request ajax }
public function cuenta() { $id_site = \Session::get('id_site'); $sitios = Sites::where('id', $id_site)->get(); $pagos = Pagos::where(function ($query) { $id_site = \Session::get('id_site'); $query->where('id_user', $this->auth->user()->id)->where('id_site', $id_site)->orderBy('date', 'asc'); })->get(); $id_user = $this->auth->user()->id; $ultimo_p = DB::table('pagos')->where('id_user', $id_user)->where('status', 1)->where('id_site', $id_site)->orderBy('date', 'dsc')->get(); $vencidos = DB::table('pagos')->where('id_user', $id_user)->where('status', 0)->where('id_site', $id_site)->orderBy('date', 'asc')->get(); $user = User::find($id_user); $cuotas = Cuotas::find($user->type); if (empty($cuota)) { $cuota = 0; } else { $cuota = $cuotas->amount; } $sites = Sites_users::where('id_user', $id_user)->count(); return view('cuenta', ['vencidos' => $vencidos, 'pagos' => $pagos, 'cuotas' => $cuotas, 'sitios' => $sitios, 'ultimo_p' => $ultimo_p, 'cuota' => $cuota, 'sites' => $sites]); }
public function getPaymentStatus() { // Get the payment ID before session clear $payment_id = \Session::get('paypal_payment_id'); // clear the session payment ID \Session::forget('paypal_payment_id'); $payerId = \Input::get('PayerID'); $token = \Input::get('token'); //if (empty(\Input::get('PayerID')) || empty(\Input::get('token'))) { if (empty($payerId) || empty($token)) { return redirect()->to('micuenta')->with('error', 'Hubo un problema al intentar pagar con Paypal'); } $payment = Payment::get($payment_id, $this->_api_context); // PaymentExecution object includes information necessary // to execute a PayPal account payment. // The payer_id is added to the request query parameters // when the user is redirected from paypal back to your site $execution = new PaymentExecution(); $execution->setPayerId(\Input::get('PayerID')); //Execute the payment $result = $payment->execute($execution, $this->_api_context); //echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later if ($result->getState() == 'approved') { // payment made // Registrar el pedido --- ok // Registrar el Detalle del pedido --- ok // Enviar correo a user // Enviar correo a admin // Redireccionar // Update de pagos $pagos_id = \Session::get('pagos_id'); $pagos_data = \Session::get('pagos_data'); $message = 'Su pago ha sido registrado. Gracias.'; if (!empty($pagos_id)) { foreach ($pagos_id as $pago) { DB::table('pagos')->where('id', $pago)->update(['status' => 1]); DB::table('users')->where('id', $this->auth->user()->id)->update(['status' => 1]); } } else { if (!empty($pagos_data)) { $user = User::find($this->auth->user()->id); $cuota = Cuotas::find($user->type); foreach ($pagos_data as $date) { DB::table('pagos')->insert(['id_user' => $user->id, 'date' => $date, 'status' => 1, 'amount' => $cuota->amount, 'user_name' => $user->name]); } } } return redirect()->to('micuenta')->with('message', $message); } return redirect()->to('micuenta')->with('message', 'El pago ha sido cancelado.'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $id_cuota = $id; $cuotas = Cuotas::find($id); $users = DB::table('users')->where('type', $id)->get(); if (empty($users)) { $cuotas->delete(); return response()->json(["tipo" => 'success', "message" => 'Cuota eliminada exitosamente.']); } else { return response()->json(["tipo" => 'warning', "message" => 'Atencion: Esta cuota no puede ser eliminada porque esta asignada a usuarios.']); } }