示例#1
0
 /**
  * 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
 }
示例#2
0
 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.');
 }
示例#3
0
 public function update_info_user($id, UserUpdateRequest $request)
 {
     $user = User::find($id);
     $user->fill($request->all());
     $user->save();
     return response()->json(["message" => 'listo']);
 }
示例#4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id, UserUpdateRequest $request)
 {
     $user = User::find($id);
     $id_site = \Session::get('id_site');
     $user->name = $request->name;
     $user->email = $request->email;
     $user->address = $request->address;
     $user->phone = $request->phone;
     $user->celphone = $request->celphone;
     $user->save();
     DB::table('sites_users')->where('id_user', $id)->where('id_site', $id_site)->update(['role' => $request->role, 'type' => $request->type]);
     return response()->json(["message" => 'listo']);
 }
示例#5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $user = User::find($id);
     $user->delete();
     return response()->json(["mensaje" => 'eliminado']);
 }