Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['accountname' => 'required|max:255', 'iban' => 'required|min:20|max:20', 'subject' => 'required|max:255', 'sum' => 'required', 'order_id' => 'required|integer|min:1']);
     $values = $request->all();
     $values = array_map('trim', $values);
     //remove leading and trailing whitespaces on all values
     $values['group'] = Auth::user()->group;
     //try calculating the sum from string
     try {
         $calculator = new \NXP\MathExecutor();
         $values['sum'] = $calculator->execute($values['sum']);
     } catch (Exception $e) {
         Log::Info('Input: "' . $values['sum'] . '" has failed to evaluate');
     }
     // Check whether the order exists and is actually owned by the given group
     $order = Order::where('id', $values['order_id'])->where('group', $values['group'])->firstOrFail();
     if ($validator->fails()) {
         // Return JSON response with 422 HTTP status code
         return $validator->errors()->all();
     }
     // Validation successful, store entity
     $payment = new Payment($values);
     $payment->save();
     return $payment;
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request, $idUser)
 {
     $rules = ['amount' => 'required'];
     try {
         $user = User::find($idUser);
         if (!$user) {
             return response()->json(['code' => 404, 'messages' => 'User not found.'], 404);
         }
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             return response()->json(['code' => 422, 'messages' => $validator->errors()->all()], 422);
         }
         if (!$request->input('amount') > 0) {
             return response()->json(['code' => 422, 'messages' => 'Amount field should be greater than 0'], 422);
         }
         $payment = new Payment();
         $payment->amount = $request->input('amount');
         $payment->user_id = $user->id;
         $payment->save();
         //$newUser = User::create($request->all());
         //$response = Response::make(json_encode(['code'=>201,'data'=>$newUser]), 201);
         return $user->payments()->get();
     } catch (Exception $e) {
         return response()->json(['code' => 500, 'messages' => 'Internal Server Error'], 500);
     }
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $payment = new Payment($request->all());
     $payment->type = "credit";
     $payment->save();
     Flash::success("¡Se ha registrado el pago de manera exitosa!");
     return redirect()->route('admin.member.show', [$request->member_id, '#credit']);
 }
Ejemplo n.º 4
0
 public function offer(Request $request)
 {
     $order_user_id = null;
     $v = Validator::make($request->all(), ['project_id' => 'required|numeric']);
     if ($v->fails()) {
         //            return redirect('post/create')
         //                        ->withErrors($validator)
         //                        ->withInput();
     }
     if ($request->has('fullname') && $request->has('email') && $request->has('phone') && empty($this->user->id)) {
         /*
          *  хэрэв fullname, email, phone 3 орж ирвэл хэрэглэгч шинээр бүртгэнэ
          */
         $user = new User();
         $user->fullname = $request->get('fullname');
         $user->email = $request->get('email');
         $user->phone = $request->get('phone');
         $user->register_ip = $_SERVER['REMOTE_ADDR'];
         $user->registered_with = 'local';
         $user->public = 0;
         $user->status = 1;
         $user->role = 2;
         $user->save();
         $order_user_id = $user->id;
         //user controller-оос авч хэрэглэх /яаж??/
         //$this->sendThankYouEmail($user);
     } else {
         /*
          *  хэрэглэгч нэвтэрсэн гэж ойлгоно
          */
         $order_user_id = $this->user->id;
     }
     $payment = new Payment();
     if ($request->has('reward_id') && $request->has('reward_qty')) {
         /*
          *  хэрэв reward_id, reward_qty 2 орж ирвэл reward авч байна гэж ойлно
          */
         $reward = Reward::find($request->get('reward_id'));
         $payment->reward_id = $reward->id;
         $payment->value = $reward * $request->get('reward_qty');
         $payment->gateway = 'reward';
     } else {
         /*
          *  хэрэв donation орж ирвэл хандив өгч байна гэж ойлно
          */
         $payment->value = $request->get('donation');
         $payment->gateway = 'donation';
     }
     $payment->project_id = $request->get('project_id');
     $payment->user_id = $order_user_id;
     $payment->note = $request->get('note');
     $payment->save();
     $result = $this->process_payment($payment);
     if (!$result) {
         //харгалзах view дуудах
     }
 }
Ejemplo n.º 5
0
 public function storePayment(Request $request)
 {
     $user = Auth::user();
     dump($request->all());
     die;
     $payment = new Payment();
     $payment->bank = $request->input('bank');
     $payment->date = $request->input('date');
     $payment->type = $request->input('type');
     $payment->confirmation_code = $request->input('confirmation_code');
     $payment->amount = $request->input('amount');
     $payment->note = $request->input('note');
     $payment->status = "PENDING";
     $payment->user_id = $user->id;
     $payment->save();
     return redirect(route('profile'));
 }
Ejemplo n.º 6
0
 public function createPayment(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:255', 'email' => 'required|email', 'amount' => 'required', 'date' => 'required', 'time' => 'required']);
     $payment = new Payment();
     $payment->name = $request->name;
     $payment->email = $request->email;
     $payment->amount = $request->amount;
     $payment->checked = false;
     $payment->date = $request->date;
     $payment->time = $request->time;
     $payment->method = $request->paymentMethod;
     $payment->save();
     $this->setMember($request->email);
     $this->sentPaymentEmail($payment);
     $this->sentPurchasedEmail($payment);
     return view('payment.thankyou');
 }
Ejemplo n.º 7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = User::all();
     $banks = array('Mercantil', 'Banesco', 'Banco de Venezuela');
     foreach ($users as $user) {
         for ($i = 1; $i <= 10; ++$i) {
             $payment = new Payment();
             $payment->amount = rand(0, 1000);
             $payment->bank = $banks[rand(0, count($banks) - 1)];
             $payment->confirmation_code = "123456 {$i}";
             $payment->date = "2016-01-01 00:00:00";
             $payment->note = "No estoy de acuerdo :(";
             $payment->type = "DEPOSIT";
             $payment->status = "PENDING";
             $payment->user_id = $user->id;
             $payment->save();
         }
     }
 }
Ejemplo n.º 8
0
 public function process(ProcessRequest $request)
 {
     // Initialize paymill request
     // Create credit card payment
     $payment = new Payment();
     $payment->setToken($request->get('token'));
     $paymentResponse = $paymillRequest->create($payment);
     // Create subscription
     $subscription = new Subscription();
     $subscription->setAmount(30)->setPayment($paymentResponse->getId())->setCurrency('EUR')->setInterval('1 week,monday')->setName('Nova sub')->setPeriodOfValidity('2 YEAR')->setStartAt(time());
     $subscriptionResponse = $paymillRequest->create($subscription);
     // Save in database
     $paymentModel = new PaymentModel();
     $paymentModel->user_id = Auth::user()->id;
     $paymentModel->paymill_payment_id = $paymentResponse->getId();
     $paymentModel->save();
     // Save subscription
     $subscriptionModel = new SubscriptionModel();
     $subscriptionModel->user_id = Auth::user()->id;
     $subscriptionModel->paymill_subscription_id = $subscriptionResponse->getId();
     $subscriptionModel->save();
 }
 public function verifyPayment(Payment $payment, Request $request)
 {
     if ($request->session()->has('email')) {
         $payment->is_paid = "Verified Payment";
         $payment->save();
         return Redirect::action('AdminController@getPayment')->with('message', 'The payment has been successfully verfied');
     } else {
         return Redirect::action('AdminController@getAdminLogin');
     }
 }
Ejemplo n.º 10
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Apartment $apartment, Lease $lease, Payment $payment, Request $request)
 {
     //
     // return $request->all();
     $this->validate($request, ['amount' => 'required | numeric']);
     $input = $request->all();
     $payment->update($request->except('paid_date'));
     $payment->paid_date = Carbon::parse($request->input('paid_date'));
     $payment->save();
     //Remove Current Allocations for a Payment and Create 1 Allocation for the Edited Payment
     \App\PaymentAllocation::destroy($payment->allocations()->lists('id')->toArray());
     PaymentAllocation::create(['amount' => $input['amount'], 'month' => Carbon::parse($input['paid_date'])->month, 'year' => Carbon::parse($input['paid_date'])->year, 'payment_id' => $payment->id]);
     return redirect()->route('apartments.lease.show', ['name' => $lease->apartment->name, 'lease' => $lease->id]);
 }
Ejemplo n.º 11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(AffiliationCreateRequest $request)
 {
     //dd($request);
     /*"_token" => "8s9rQffPRk7lOCtbGidK1Wzvp4fmMQ00GLTvNFQv"
           "member_id" => "1"
           "membership_id" => "1"
           "initiation" => "2016-02-11"
           "type" => "payment"
     
               0 => "initiation"
         1 => "finalization"
         2 => "price"
         3 => "payout"
         4 => "type"
         5 => "active"
         6 => "member_id"
         7 => "membership_id"*/
     $membership = Membership::find($request->membership_id);
     $affiliation = new Affiliation($request->all());
     $payment = new Payment();
     $end = new Carbon($request->initiation);
     if ($membership->month > 0) {
         $end->addMonths($membership->month);
     }
     if ($membership->day > 0) {
         $end->addDays($membership->day - 1);
     }
     $payment->member_id = $request->member_id;
     $affiliation->finalization = $end;
     $affiliation->price = $membership->price;
     if ($request->type == "credit") {
         $payment->amount = $request->payout;
         $payment->type = "payout";
     } else {
         $payment->amount = $membership->price;
         $payment->type = "payment";
     }
     $affiliation->save();
     if ($payment->amount > 0) {
         $payment->save();
     }
     Flash::success("¡Se ha registrado la afiliacion del miembro de manera exitosa!");
     return redirect()->route('admin.member.show', [$request->member_id, '#membership-member']);
 }
 public function postPaynow(Request $request, $affiliate_id)
 {
     $user_is = $request->user_infusionsoft;
     $affiliate_row = Affiliate::where('user_is_id', '=', $user_is->id)->where('aff_id', '=', $affiliate_id)->first();
     define('PAYPAL_SANDBOX', 1);
     define('PAYPAL_ACTION_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr');
     //adaptive payment request
     $payRequest = new \PayRequest();
     $receiver = array();
     $receiver[0] = new \Receiver();
     $receiver[0]->amount = $request->amount;
     $receiver[0]->email = $affiliate_row['paypal_email'];
     $receiverList = new \ReceiverList($receiver);
     $payRequest->receiverList = $receiverList;
     $payRequest->senderEmail = $user_is->paypal_business_account;
     $requestEnvelope = new \RequestEnvelope("en_US");
     $payRequest->requestEnvelope = $requestEnvelope;
     $payRequest->actionType = "PAY";
     $payRequest->cancelUrl = URL::to('affiliates/' . $affiliate_id . '/pay');
     $payRequest->returnUrl = URL::to('affiliates/' . $affiliate_id);
     $payRequest->currencyCode = "USD";
     $payRequest->ipnNotificationUrl = URL::to('paypal/ipn');
     $sdkConfig = array("mode" => PAYPAL_SANDBOX ? "sandbox" : 'live', "acct1.UserName" => $user_is->paypal_api_username, "acct1.Password" => $user_is->paypal_api_password, "acct1.Signature" => $user_is->paypal_api_signature, "acct1.AppId" => $user_is->paypal_app_id);
     $adaptivePaymentsService = new \AdaptivePaymentsService($sdkConfig);
     $payResponse = $adaptivePaymentsService->Pay($payRequest);
     $payment = new Payment();
     $payment->affiliate_id = $affiliate_row->id;
     $payment->payment_key = $payResponse->payKey;
     $payment->amount = $request['amount'];
     $payment->pay_result = json_encode($payResponse);
     $payment->status = 1;
     $payment->save();
     if ($payResponse->responseEnvelope->ack != 'Success') {
         return redirect(URL::to('affiliates/' . $affiliate_id . '/pay'))->with('error', 'Payment was not successful.');
     }
     return redirect(URL::to('affiliates/' . $affiliate_id . '/pay'))->with('success', 'Payment was successful');
 }
 public function postIndex()
 {
     $user = Auth::user();
     $id = Input::get('payment');
     /*
      *There is an invisible field called form that tells what form was submitted
      *
      */
     if (Input::get('form') == 'trans') {
         $monthNum = substr(Input::get('date'), 0, 2);
         $month = date('M', mktime(0, 0, 0, $monthNum, 10));
         $year = substr(Input::get('date'), -4);
         $transaction = new Transaction();
         $transaction->userID = $user->id;
         $transaction->date = Input::get('date');
         $transaction->amount = Input::get('amount');
         $transaction->typeID = Input::get('type');
         $transaction->note = Input::get('note');
         $transaction->year = $year;
         $transaction->month = $month;
         if ($id == 'cash') {
             $month = Month::where('userID', $user->id)->where('name', $month)->where('year', date("Y"))->first();
             $month->cash -= Input::get('amount');
             $month->save();
             $transaction->accountID = 0;
         } else {
             $transaction->accountID = $id;
             $account = Account::find($id);
             //add for credit subtract for bank
             if ($account->accountType == 'c') {
                 $account->balance += Input::get('amount');
             } else {
                 $account->balance -= Input::get('amount');
             }
             $account->save();
         }
         $transaction->save();
         return redirect('options')->with('message', 'Transaction added successfully.');
     } else {
         if (Input::get('form') == 'type') {
             $type = new Type();
             $type->userID = $user->id;
             $type->name = Input::get('name');
             $type->save();
             return redirect('options')->with('message', 'Category added successfully.');
         } else {
             if (Input::get('form') == 'payment') {
                 $monthNum = substr(Input::get('date'), 0, 2);
                 $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                 $year = substr(Input::get('date'), -4);
                 $amount = Input::get('amount');
                 $bankID = Input::get('bank');
                 $ccID = Input::get('payment');
                 $note = Input::get('note');
                 $date = Input::get('date');
                 if ($ccID == 'cash') {
                     $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                     $month2->cash = $month2->cash + $amount;
                     $month2->save();
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     $transfer = new Transfer();
                     $transfer->userID = $user->id;
                     $transfer->creditAccountID = $bankID;
                     $transfer->debitAccountID = 0;
                     $transfer->amount = $amount;
                     $transfer->note = $note;
                     $transfer->date = $date;
                     $transfer->year = $year;
                     $transfer->month = $month;
                     $transfer->save();
                 } else {
                     $cc = Account::find($ccID);
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     if ($cc->accountType == 'b') {
                         //transfer
                         $cc->balance = $cc->balance + $amount;
                         $transfer = new Transfer();
                         $transfer->userID = $user->id;
                         $transfer->creditAccountID = $bankID;
                         $transfer->debitAccountID = $ccID;
                         $transfer->amount = $amount;
                         $transfer->note = $note;
                         $transfer->date = $date;
                         $transfer->year = $year;
                         $transfer->month = $month;
                         $transfer->save();
                     } else {
                         //payment
                         $cc->balance = $cc->balance - $amount;
                         $payment = new Payment();
                         $payment->userID = $user->id;
                         $payment->creditAccountID = $bankID;
                         $payment->debitAccountID = $ccID;
                         $payment->amount = $amount;
                         $payment->note = $note;
                         $payment->date = $date;
                         $payment->year = $year;
                         $payment->month = $month;
                         $payment->save();
                     }
                     $cc->save();
                 }
                 return redirect('options')->with('message', 'Payment saved successfully.');
             } else {
                 if (Input::get('form') == 'cc') {
                     $cc = new Account();
                     $cc->userID = $user->id;
                     $cc->name = Input::get('name');
                     $cc->balance = Input::get('balance');
                     $cc->creditLimit = Input::get('limit');
                     $cc->statementDay = Input::get('date');
                     $cc->accountType = 'c';
                     $cc->save();
                     return redirect('options')->with('message', 'Credit Card added successfully.');
                 } else {
                     if (Input::get('form') == 'bank') {
                         $bank = new Account();
                         $bank->userID = $user->id;
                         $bank->name = Input::get('name');
                         $bank->balance = Input::get('balance');
                         $bank->accountType = 'b';
                         $bank->save();
                         return redirect('options')->with('message', 'Bank Account added successfully.');
                     } else {
                         if (Input::get('form') == 'income') {
                             $date = Input::get('date');
                             $monthNum = substr($date, 0, 2);
                             $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                             $amount = Input::get('amount');
                             $bankID = Input::get('bank');
                             $year = substr(Input::get('date'), -4);
                             $income = new Income();
                             $income->userID = $user->id;
                             $income->month = $month;
                             $income->amount = $amount;
                             $income->note = Input::get('note');
                             $income->date = $date;
                             $income->year = $year;
                             if ($bankID == "cash") {
                                 $income->accountID = 0;
                                 $month = Month::where('userID', $user->id)->where('name', $month)->first();
                                 $month->cash = $month->cash + $amount;
                                 $month->save();
                             } else {
                                 $income->accountID = $bankID;
                                 $bank = Account::find($bankID);
                                 $bank->balance = $bank->balance + $amount;
                                 $bank->save();
                             }
                             $income->save();
                             return redirect('options')->with('message', 'Income added successfully.');
                         }
                     }
                 }
             }
         }
     }
 }
 public function payment_success($offer_id)
 {
     // Set the offer to paied and increase stage
     // Update the Offer
     $offer = Offer::findOrFail($offer_id);
     $offer->paid = 1;
     $offer->status = 4;
     $offer->save();
     // Register the payment
     $cost = $this->getCost($offer_id);
     $payment = new Payment();
     $payment->user_id = Auth::user()->id;
     $payment->offer_id = $offer_id;
     $payment->fee = $cost['fee'];
     $payment->cost = $cost['pro_cost'];
     $payment->bv_cost = $cost['bv_cost'];
     $payment->total = $cost['total'];
     $payment->save();
     // Send email
     $violation = $offer->violation;
     $violation->status = 4;
     $violation->save();
     $email = $offer->author->email;
     $to = $offer->author->username;
     $customer_name = $offer->violation->author->username;
     $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip;
     $offer_id = $offer->id;
     $data = compact('to', 'customer_name', 'address', 'offer_id');
     Mail::send('emails.paymentmade', $data, function ($message) use($email) {
         $message->subject('Offer paid!');
         $message->to($email);
     });
     // Send email to the admin
     $email = config('other.email');
     $to = 'Admin';
     $customer_name = $offer->violation->author->username;
     $pro_name = $offer->author->username;
     $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip;
     $data = compact('to', 'customer_name', 'pro_name', 'address', 'offer_id');
     Mail::send('emails.paymentmadeadmin', $data, function ($message) use($email) {
         $message->subject('New Payment!');
         $message->to($email);
     });
     // Flash message
     Session::flash('message', 'You have made a payment of <b>' . $payment->total . '</b> for this offer. The pro <b>' . $offer->author->username . '</b> can start now working on it.');
     Session::flash('message-type', 'success');
     // Redirect
     return redirect()->action('OfferController@show', [$offer_id]);
 }
Ejemplo n.º 15
0
 public function submitPayment(Request $request)
 {
     $validator = Validator::make($request->all(), ['payment_option' => 'required|integer|exists:payment_infos,id']);
     if ($validator->fails()) {
         // get the error messages from the validator
         $messages = $validator->messages();
         // redirect our user back to the form with the errors from the validator
         return back()->withInput()->withErrors($messages);
     } else {
         $payment = new Payment();
         $payment->text = $request->input('note');
         $payment->payment_info_id = $request->input('payment_option');
         $payment->save();
         foreach ($request->input('checkouts') as $checkOutID) {
             $checkOut = CheckOut::where(['id' => $checkOutID, 'customer_id' => Auth::user()->id, 'payment_id' => null])->first();
             $checkOut->payment_id = $payment->id;
             $checkOut->update();
         }
         return redirect()->action('Dashboard\\CustomerController@showUnpaidOrders')->with(['success' => ['Odeme kaydı oluşturuldu']]);
     }
 }
Ejemplo n.º 16
0
 public function paymentPostIndex($type, $id)
 {
     $user = Auth::user();
     $date = Input::get('date');
     $amount = Input::get('amount');
     $bankID = Input::get('bank');
     $accountID = Input::get('payment');
     $note = Input::get('note');
     //add intial trans back onto
     if ($type == 0) {
         //tansfer
         $trans = Transfer::where('id', $id)->where('userID', $user->id)->first();
         if ($trans->creditAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash + $trans->amount;
             $month->save();
         } else {
             $debit = Account::find($trans->creditAccountID);
             $debit->balance = $debit->balance + $trans->amount;
             $debit->save();
         }
         if ($trans->debitAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash - $trans->amount;
             $month->save();
         } else {
             $debit = Account::find($trans->debitAccountID);
             $debit->balance = $debit->balance + $trans->amount;
             $debit->save();
         }
     } else {
         //payment
         $trans = Payment::where('id', $id)->where('userID', $user->id)->first();
         //add initial payment amount back on
         if ($trans->creditAccountID == 0) {
             $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
             $month->cash = $month->cash + $trans->amount;
             $month->save();
         } else {
             $credit = Account::find($trans->creditAccountID);
             $credit->balance = $credit->balance + $trans->amount;
             $credit->save();
         }
         //add initial payment back on
         $debit = Account::find($trans->debitAccountID);
         $debit->balance = $debit->balance + $trans->amount;
         $debit->save();
     }
     $trans->forceDelete();
     //setup as new transfer/payment
     $monthNum = substr(Input::get('date'), 0, 2);
     $month = date('M', mktime(0, 0, 0, $monthNum, 10));
     if ($accountID == 'cash') {
         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
         $month2->cash = $month2->cash + $amount;
         $month2->save();
         if ($bankID == 'cash') {
             $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
             $month2->cash = $month2->cash - $amount;
             $month2->save();
         } else {
             $bank = Account::find($bankID);
             $bank->balance = $bank->balance - $amount;
             $bank->save();
         }
         $transfer = new Transfer();
         $transfer->userID = $user->id;
         $transfer->creditAccountID = $bankID;
         $transfer->debitAccountID = 0;
         $transfer->amount = $amount;
         $transfer->note = $note;
         $transfer->date = $date;
         $transfer->month = $month;
         $transfer->save();
     } else {
         $cc = Account::find($accountID);
         if ($bankID == 'cash') {
             $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
             $month2->cash = $month2->cash - $amount;
             $month2->save();
         } else {
             $bank = Account::find($bankID);
             $bank->balance = $bank->balance - $amount;
             $bank->save();
         }
         if ($cc->accountType == 'b') {
             //transfer
             $cc->balance = $cc->balance + $amount;
             $transfer = new Transfer();
             $transfer->userID = $user->id;
             $transfer->creditAccountID = $bankID;
             $transfer->debitAccountID = $accountID;
             $transfer->amount = $amount;
             $transfer->note = $note;
             $transfer->date = $date;
             $transfer->month = $month;
             $transfer->save();
         } else {
             //payment
             $cc->balance = $cc->balance - $amount;
             $payment = new Payment();
             $payment->userID = $user->id;
             $payment->creditAccountID = $bankID;
             $payment->debitAccountID = $accountID;
             $payment->amount = $amount;
             $payment->note = $note;
             $payment->date = $date;
             $payment->month = $month;
             $payment->save();
         }
         $cc->save();
     }
     return redirect('home')->with('message', 'Transfer/Payment updated successfully.');
 }
 public function store_payment(CreatePaymentRequest $request)
 {
     $id = Auth::user()->id;
     $payments = new Payment($request->all());
     $payments->user_id = $id;
     $payments->iduser_update = $id;
     $payments->save();
     Session::flash('message', 'El projecto: ' . $payments->project->name . ' realizo un ingreso');
     $role = Auth::user()->role;
     if ($role == 'developer' || $role == 'agent') {
         return redirect()->route('projectos.index');
     } elseif ($role == 'admin') {
         return redirect()->route('admin.projectos.index');
     }
     // if($action=='save_new')
     // {
     // return redirect()->route('admin.projectos.index');
     //
     // }
     //   else {
     //return redirect()->back();
     //  }
 }