public function makeTransaction($amount, $description, $txid = NULL, $status = 1) { //status: 0 = error 1 = success 2 = pending $transaction = new Transaction(); if ($txid == NULL) { // generating txid $txid = ""; $seed = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); while (true) { shuffle($seed); foreach (array_rand($seed, 9) as $k) { $txid .= $seed[$k]; } try { $t = Transaction::findorfail(array('txid', $txid)); } catch (ModelNotFoundException $e) { break; } } } // insert transaction record $transaction->txid = $txid; $transaction->user_id = $this->id; $transaction->amount = $amount; $transaction->description = $description; $transaction->status = $status; // process yeah $transaction->save(); }
public function makeTransaction($keyID, $typeName, $customAmount = "0") { if (!($user = User::byKey($keyID))) { return "false"; } $transType = TransactionType::byName($typeName); if (is_null($transType->cost)) { if ($customAmount > 0) { $cost = $customAmount; } else { $cost = 0; } } else { $cost = $transType->cost; } if (is_null($transType->permission) || $user->has($transType->permission)) { if ($transType->cost <= $user->balance) { if ($cost > 0) { $trans = new Transaction(); $trans->transaction_type_id = $transType->id; $trans->user_id = $user->id; $trans->amount = '-' . $cost; if ($trans->save()) { return "true"; } } } } return \Illuminate\Http\Response::create('false', 418); }
/** * For one transaction, change the amount that is allocated for one budget * PUT /api/budgets/{budgets}/transactions/{transactions} * @param Request $request * @param Budget $budget * @param Transaction $transaction * @return Response */ public function update(Request $request, Budget $budget, Transaction $transaction) { $type = $request->get('type'); $value = $request->get('value'); if ($type === 'percent') { $transaction->updateAllocatedPercent($value, $budget); } elseif ($type === 'fixed') { $transaction->updateAllocatedFixed($value, $budget); } $transaction = $this->transform($this->createItem($transaction, new TransactionTransformer()))['data']; return response($transaction, Response::HTTP_OK); }
public function __construct($uniqueId, array $rewards, $shipping) { parent::__construct(); $this->user = $this->request->session('user'); $this->cart = $this->request->session('cart'); $transaction = ['rewards' => $rewards, 'shipping_address' => $shipping]; $transaction = json_decode($this->rewards->createUserTransaction($uniqueId, $transaction)); if ($transaction->success !== true) { $transactionModel = new Models\Transaction(); $transactionModel->queueTransaction($uniqueId, $rewards, $shipping); } return true; }
public static function create() { $login = Yii::$app->getSession()->get('payer.login'); $accountType = Yii::$app->getSession()->get('payer.account_type'); $payAmount = Yii::$app->request->get('pay_amount'); $transaction = new Transaction(); $transaction->pay_id = uniqid(uniqid()); $transaction->is_fulfilled = false; $transaction->login = $login; $transaction->pay_amount = $payAmount; $transaction->account_type = $accountType; $transaction->save(); return $transaction; }
public function actionPayment() { $headers = Yii::$app->request->getHeaders(); if ($headers->has('X-TERMINAL')) { Yii::$app->response->format = Response::FORMAT_JSON; $model = new PaymentForm(); if ($model->hasError()) { return $model->getError(); } $transaction = Transaction::create(); $connector = new CateringConnector(); $response = $connector->pay($transaction); if (in_array($response['status'], ['error', 'redirect'])) { return $response; } $transaction->is_fulfilled = true; $transaction->save(); return ['status' => 'success']; } Yii::$app->getSession()->set('payer.account_type', Yii::$app->request->get('account_type')); $bills = Bill::find()->where(['enabled' => true])->select('denomination')->asArray()->all(); $denominations = []; foreach ($bills as $bill) { $denominations[] = $bill['denomination']; } Yii::$app->get('xmlrpc')->enableBillTypes(); return $this->render('payment', ['denominations' => implode(', ', $denominations)]); }
public function getIndex() { $user = Auth::User(); $user->load('permissions')->load('activities'); $user->transactions = Transaction::recent()->where('user_id', $user->id)->take(15)->get(); $user->transactions->load('type'); return view('welcome')->withUser($user); }
public function getSpecificTransactions($id) { $acc_name = Transaction::with('banks')->DefaultApartment()->where('account_id', '=', $id)->first(); $lists = Transaction::where('account_id', '=', $id)->DefaultApartment()->latest()->paginate(20); $accounts = Bankncash::DefaultApartment()->get(); $last = Transaction::with('banks')->where('account_id', '=', $id)->DefaultApartment()->latest()->first(); return view('transaction.specifictransactions', compact('lists', 'accounts', 'acc_name', 'last')); }
public function lastTransactions($total = 20) { $transacions = Transaction::where('project_id', $this->id)->orderBy('created_at', 'DESC')->take($total)->get(); $textResult = ""; foreach ($transacions as $transacion) { $textResult .= $transacion->created_at . " - " . $transacion->transtype . " - " . $transacion->params . "<br>"; } return $textResult; }
/** * For mass transaction updating * (adding the same budgets to many transactions) * Called from TransactionsController update method * @param Request $request * @param Transaction $transaction * @return Transaction */ public function addBudgets(Request $request, Transaction $transaction) { $budgetIds = $request->get('budget_ids'); //Prepare the data for the pivot table $pivotData = array_fill(0, count($budgetIds), ['allocated_percent' => 100, 'calculated_allocation' => $transaction->total]); $syncData = array_combine($budgetIds, $pivotData); $transaction->budgets()->sync($syncData, false); return $transaction; }
/** * BasicTotal constructor. */ public function __construct($transactions = NULL) { $this->transactions = $transactions ?: Transaction::forCurrentUser()->get(); $this->setDebit(); $this->setCredit(); $this->setBalance(); $this->setReconciledSum(); $this->setExpensesWithoutBudget(); $this->setSavings(); }
/** * @test * @return void */ public function it_does_not_change_the_savings_when_an_expense_transaction_is_deleted() { $this->logInUser(); $this->assertEquals('50.00', Savings::forCurrentUser()->first()->amount); $transaction = Transaction::forCurrentUser()->where('type', 'expense')->first(); $response = $this->apiCall('DELETE', '/api/transactions/' . $transaction->id); $this->assertEquals(204, $response->getStatusCode()); $this->missingFromDatabase('transactions', ['user_id' => $this->user->id, 'id' => $transaction->id]); //Check the savings decreased $this->assertEquals('50.00', Savings::forCurrentUser()->first()->amount); }
/** * * @param $query * @param $value * @return mixed */ private function filterOutNumBudgets($query, $value) { if ($value['out'] === "zero") { $ids = Transaction::forCurrentUser()->has('assignedBudgets', 0)->lists('id'); } elseif ($value['out'] === "single") { $ids = Transaction::forCurrentUser()->has('assignedBudgets', 1)->lists('id'); } elseif ($value['out'] === "multiple") { $ids = Transaction::forCurrentUser()->has('assignedBudgets', '>', 1)->lists('id'); } return $query->whereNotIn('transactions.id', $ids); }
private function truncate() { User::truncate(); Savings::truncate(); Budget::truncate(); Account::truncate(); Transaction::truncate(); FavouriteTransaction::truncate(); SavedFilter::truncate(); DB::table('budgets_favourite_transactions')->truncate(); DB::table('budgets_transactions')->truncate(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Transaction::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['transaction_id' => $this->transaction_id, 'transaction_person_id' => $this->transaction_person_id, 'transaction_time' => $this->transaction_time, 'is_closed' => $this->is_closed]); return $dataProvider; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if ($request->holder_name == ('Suchay Janbandhu' && 'suchay janbandhu') && $request->card_number == '1234567890' && $request->month == 'Jul (07)' && $request->year == '2021' && $request->cvv == '123') { $account = Bankncash::DefaultApartment()->find(18); $bal = $account->balance; $amount = 787; $nbal = $bal + $amount; Bankncash::find(18)->update(['balance' => $nbal]); Transaction::create(['apartment_id' => Auth::user()->profile->defaultApartment, 'account_id' => 18, 'type' => 'Income', 'category_id' => 61, 'amount' => 787, 'payer_id' => Auth::user()->profile->id, 'payment_id' => $request->payment_id, 'cr' => 787, 'bal' => $nbal, 'description' => 'Maintenance Payment for the Month of ' . Carbon::now()->month, 'date' => Carbon::now()]); return redirect()->route('user.home')->withMessage('Transaction Completed Successfully')->withStatus('success'); } else { return redirect()->route('user.home')->withMessage('Transaction Could not complete')->withStatus('error'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Transaction::find()->orderBy(['id' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 200]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'is_fulfilled' => $this->is_fulfilled, 'pay_amount' => $this->pay_amount, 'account_type' => $this->account_type]); $query->andFilterWhere(['like', 'pay_id', $this->pay_id])->andFilterWhere(['like', 'login', $this->login])->andFilterWhere(['like', 'date', $this->date]); return $dataProvider; }
/** * Bootstrap the application services. * * @return void */ public function boot() { Transaction::saving(function ($trans) { $user = User::find($trans->user_id); if ($user->balance < -$trans->amount) { return false; } else { $trans->running = $user->balance + $trans->amount; } }); Transaction::saved(function ($trans) { $user = User::find($trans->user_id); $user->balance = $user->balance + $trans->amount; $user->save(); }); }
public function search() { $type = \Input::get('type'); $userId = \Input::get('userId'); $data = Transaction::with('users', 'categories'); if ($type) { $data = $data->where('transaction_type', '=', $type); } if ($userId) { $data = $data->where('user_id', '=', $userId); } $data = $data->get(); // $data['ty']=$type; // $data['us']=$userId; return \Response::json($data); }
/** * @test */ public function it_can_calculate_if_the_budget_allocations_for_the_transaction_match_the_total_of_the_transaction() { $this->logInUser(); //Find a transaction with multiple budgets $transaction = Transaction::forCurrentUser()->has('assignedBudgets', '>', 1)->first(); $this->assertEquals(1, $transaction->validAllocation); //Check the data is as expected before adding a budget $this->assertEquals(2, $transaction->budgets[0]->id); $this->assertEquals(3, $transaction->budgets[1]->id); //Add a budget to the transaction. This should make the budget allocations for transaction not equal the transaction total //so the transaction should now be unallocated $response = $this->call('PUT', '/api/transactions/' . $transaction->id, ['addingBudgets' => true, 'budget_ids' => [4]]); $content = json_decode($response->getContent(), true); // dd($content); $this->checkTransactionKeysExist($content); $this->assertEquals(0, $content['validAllocation']); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); }
public function actionResendFailed() { $transactions = Transaction::findAll(['is_fulfilled' => false]); if (count($transactions) === 0) { echo "There are no failed transactions\n"; return; } $connector = new CateringConnector(); foreach ($transactions as $transaction) { $response = $connector->pay($transaction); if ($response['status'] === 'success') { echo 'Transaction ' . $transaction->id . " SUCCEEDED\n"; $transaction->is_fulfilled = true; $transaction->save(); } else { echo 'Transaction ' . $transaction->id . " FAILED\n"; } } }
/** * * @param array $filter * @return mixed */ public function buildQueryForCalculatingBalance(array $filter) { // Prepare the query $query = Transaction::where('transactions.user_id', Auth::user()->id); // Apply filters to the transaction query foreach ($filter as $type => $value) { switch ($type) { case "singleDate": case "fromDate": case "toDate": $query = $this->filterBasicsRepository->filterDates($query, $type, $value, true); break; case "accounts": $query = $this->filterBasicsRepository->filterAccounts($query, $value); break; } } return $query; }
/** * @test * @return void */ public function it_cannot_add_a_budget_to_a_transaction_that_already_has_that_budget() { DB::beginTransaction(); $this->logInUser(); //Find a transaction with a budged_id of one, and no other budgets $transaction = Transaction::forCurrentUser()->whereHas('budgets', function ($q) { $q->where('budgets.id', 1); })->has('budgets', '<', 2)->first(); $response = $this->call('PUT', '/api/transactions/' . $transaction->id, ['addingBudgets' => true, 'budget_ids' => [1]]); $content = json_decode($response->getContent(), true); // dd($content); $this->checktransactionKeysExist($content); $this->assertCount(1, $content['budgets']); $this->assertEquals(1, $content['budgets'][0]['id']); //Check a couple of fields are the same because only the budgets should be changed $this->assertEquals($transaction->description, $content['description']); $this->assertEquals($transaction->merchant, $content['merchant']); $this->assertEquals(200, $response->getStatusCode()); DB::rollBack(); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); // $router->model('accounts', Account::class); Route::bind('accounts', function ($id) { return Account::forCurrentUser()->findOrFail($id); }); Route::bind('budgets', function ($id) { return Budget::forCurrentUser()->findOrFail($id); }); Route::bind('transactions', function ($id) { return Transaction::forCurrentUser()->findOrFail($id); }); Route::bind('favouriteTransactions', function ($id) { return FavouriteTransaction::forCurrentUser()->findOrFail($id); }); Route::bind('savedFilters', function ($id) { return SavedFilter::forCurrentUser()->findOrFail($id); }); }
/** * @test * @return void */ public function it_does_not_filter_out_more_transactions_than_it_should_when_the_description_filter_out_is_used() { $this->setFilterDefaults(); $this->logInUser(); //Count the number of transactions that do contain 'e' in the description //Todo: perhaps make seeder consistent so it's the same each time $count = Transaction::forCurrentUser()->where('description', 'LIKE', '%e%')->count(); $filter = ['description' => ['in' => '', 'out' => 'e']]; $this->filter = array_merge($this->defaults, $filter); $data = ['filter' => $this->filter]; $this->setTransactions($data); $this->checkTransactionKeysExist($this->transactions[0]); foreach ($this->transactions as $transaction) { if ($transaction['merchant']) { $this->assertNotContains('e', $transaction['description'], '', true); } } //There are 16 transactions in total, so there should be 16 - $count in the filtered results $this->assertCount(16 - $count, $this->transactions); $this->assertEquals(Response::HTTP_OK, $this->response->getStatusCode()); }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); \App\Models\Owner::saving(function ($owner) { if (empty($owner->owner_name)) { $owner->owner_name = null; } $owner->org_id = \Auth::User()->org_id; return $owner; }); \App\Models\Property::saving(function ($property) { if (empty($property->property_name)) { $property->property_name = null; } $property->org_id = \Auth::User()->org_id; return $property; }); \App\Models\Unit::saving(function ($unit) { if (empty($unit->unit_name)) { $unit->unit_name = null; } $unit->org_id = \Auth::User()->org_id; return $unit; }); \App\Models\Tenant::saving(function ($tenant) { if (empty($tenant->tenant_name)) { $tenant->tenant_name = null; } $tenant->org_id = \Auth::User()->org_id; return $tenant; }); \App\Models\Transaction::saving(function ($transaction) { $transaction->org_id = \Auth::User()->org_id; return $transaction; }); }
/** * */ private function makeSomeTransactionsHaveInvalidAllocation() { //Find a transaction with a budged_id of one, and no other budgets $transaction = Transaction::forCurrentUser()->whereHas('budgets', function ($q) { $q->where('budgets.id', 2); })->has('budgets', '<', 2)->first(); $this->assertEquals(12, $transaction->id); $response = $this->call('PUT', '/api/transactions/' . $transaction->id, ['addingBudgets' => true, 'budget_ids' => [3]]); // dd(count(Transaction::find(12)->budgets)); //Find a transaction with a budged_id of one, and no other budgets $transaction = Transaction::forCurrentUser()->whereHas('budgets', function ($q) { $q->where('budgets.id', 3); })->first(); $this->assertEquals(5, $transaction->id); //Check the budgets for the transaction are as expected, so we know that adding a budget should make the allocation invalid $this->assertEquals('fixed', $transaction->budgets[0]->type); $this->assertEquals(2, $transaction->budgets[0]->id); $this->assertEquals('fixed', $transaction->budgets[1]->type); $this->assertEquals(3, $transaction->budgets[1]->id); $this->assertCount(2, $transaction->budgets); $response = $this->call('PUT', '/api/transactions/' . $transaction->id, ['addingBudgets' => true, 'budget_ids' => [4]]); $content = json_decode($response->getContent(), true); // dd(count(Transaction::find(5)->budgets)); }
public function getTransactions($id = Null) { if ($id == Null) { \App::abort(404, 'Invalid User Id'); } else { $user_id = $id; } $user = \App\User::where('id', $user_id)->first(); $myTransactions = \App\Models\Transaction::where('user_id', $user_id)->orderBy('created_at', 'desc')->get(); //dd($myTransactions); return view('user.transactions', ['_menus' => $this->menuItems, 'login_url' => $this->login_url, 'transactions' => $myTransactions, 'user' => $user, 'dashBoardDetailsByAuthUser' => $this->userrepo->generalOverViewByAuthUser($user_id)]); }
/** * This function is for when a user donates money to another user via their profile. * * @param Request $request */ public function processGift(Request $request) { $giftTransactionType = TransactionType::where(['name' => 'user_gift'])->get()->first(); $recievingUser = User::find($request->input('user_id')); $sendingTransaction = new Transaction(['user_id' => $this->user->id, 'transaction_type_id' => $giftTransactionType->id, 'amount' => -$request->input('amount'), 'description' => "You sent money to " . $recievingUser->name]); $recievingTransaction = new Transaction(['user_id' => $request->input('user_id'), 'transaction_type_id' => $giftTransactionType->id, 'amount' => $request->input('amount'), 'description' => "You recieved a gift from " . $this->user->name]); if ($sendingTransaction->save()) { $recievingTransaction->save(); Flash::success('You have sent ' . $recievingTransaction->present()->amount . ' to ' . $recievingTransaction->user->name); } else { Flash::error('There was an error, please contact support.'); } return redirect('/'); }
/** * boot * observing model * */ public static function boot() { parent::boot(); Sale::observe(new SaleObserver()); }