/** * 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 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.'); }
public function usuarios() { $id_site = \Session::get('id_site'); $id_user = $this->auth->user()->id; $user_role = Sites_users::where('id_site', $id_site)->where('id_user', $id_user)->value('role'); $sites = Sites_users::where('id_user', $id_user)->count(); if ($user_role == 1) { $id_site = \Session::get('id_site'); $sitios = Sites::where('id', $id_site)->get(); $sitio_plan = DB::table('sites')->where('id', $id_site)->value('plan'); $plan = Plans::where('id', $sitio_plan)->get(); $user_count = DB::table('sites_users')->where('id_site', $id_site)->count(); $users = DB::select('select users.*, sites_users.status, sites_users.role, sites_users.type FROM users JOIN sites_users ON sites_users.id_user = users.id AND sites_users.id_site = :id', ['id' => $id_site]); $tipos = Cuotas::where('id_site', $id_site)->lists('concepto', 'id'); return view('/admin/usuarios', ['users' => $users, 'tipos' => $tipos, 'user_count' => $user_count, 'plan' => $plan, 'sitios' => $sitios, 'sites' => $sites]); } else { return Redirect::to('home'); } }
public function loadData(Request $request) { /* Excel::load('file/file.xlsx', function($file) { $result=$file->get(); foreach ($result as $key => $value) { echo $value->nombre.'--'.$value->email.'--'.$value->direccion.'<br>'; } })->get(); */ if ($request->hasFile('file')) { $file = $request->file('file'); $result = Excel::load($file)->get(); } //$result = Excel::load('file/file.xlsx')->get(); /* return response()->json( $result->toArray() ); */ $users = User::all(); $tipos = Cuotas::lists('concepto', 'id'); return view('/admin/usuarios', ['users' => $users, 'tipos' => $tipos, 'result' => $result]); }
/** * 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.']); } }