public function delete($id) { $deposit = Deposit::findOrFail($id); $deposit->delete(); return redirect()->back(); }
/** * makeDeposit * Data insert into deposit, transaction and roirecords table * Upade carries table * * @return string */ public function makeDeposit(Request $request) { // return $request->pmethod; $depositAmount = $request->deposit; if ($depositAmount) { if ($request->pmethod == 'pm') { return "Processing with Perfect Money"; } else { $account = Account::where('user_id', Auth::user()->id)->first(); if ($account->balance < $depositAmount) { return redirect()->back()->with('message', 'You do not have sufficient balance'); } else { Deposit::insert(['user_id' => Auth::user()->id, 'amount' => $depositAmount, 'pmnt_method' => $request->pmethod, 'pmnt_account' => 'Wallet Balance', 'rcvd_date' => Carbon::now()]); // return "Successfully deposited"; $newDepBalance = $account->balance - $depositAmount; Account::where('user_id', Auth::user()->id)->update(['balance' => $newDepBalance]); // return "Successfully updated"; Transaction::insert(['tnx_id' => 'nd_' . rand(1, 99999999), 'amount' => $depositAmount, 'sign' => '-', 'purpose' => 11, 'date' => Carbon::now(), 'user_id' => Auth::user()->id]); // return "Successfully transaction inserted"; // Create ROI (Return of Income) Schedule $depositTableRow = Deposit::where('user_id', Auth::user()->id)->first(); $roiAmount = $depositAmount * 20 / 100; for ($i = 1; $i <= 10; $i++) { Roirecord::insert(['deposit_id' => $depositTableRow->id, 'amount' => $roiAmount, 'pmnt_date' => Carbon::now()->addMonths($i), 'terms' => $i, 'status' => 0]); } // end for loop // Create ROI (Return of Income) Schedule End // Add Referrar's Comission $referrarId = Auth::user()->referrar_id; $comissionAmount = 10 * $depositAmount / 100; $referrarBalance = Account::where('user_id', $referrarId)->first()->balance; $newRefBalance = $referrarBalance + $comissionAmount; Account::where('user_id', $referrarId)->update(['balance' => $newRefBalance]); // Add Referrar's Comission End //Insert Transaction Table Start Transaction::insert(['tnx_id' => 'drc_' . rand(1, 99999999), 'amount' => $comissionAmount, 'sign' => '+', 'purpose' => 12, 'date' => Carbon::now(), 'user_id' => $referrarId, 'related_id' => Auth::user()->id]); //Insert Transaction Table End $this->carry(Auth::user()->id, Auth::user()->upline_id, $depositAmount); $this->updateMatchingQualify(); return redirect()->back()->with('message', "Successfully Deposited"); } } } else { return redirect()->back()->with('message', 'Request could not processd'); } }