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); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $adminRole = Role::create(['name' => 'admin']); $tyler = User::create(['name' => 'Tyler Getsay', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'key_id' => '1', 'picture_id' => '1', 'balance' => 100]); $tyler->roles()->attach($adminRole); \App\Models\TransactionType::create(['name' => 'stripe_deposit', 'description' => 'Deposit from Stripe', 'cost' => 0, 'locked' => true]); \App\Models\TransactionType::create(['name' => 'user_gift', 'description' => 'Gift from/to another user.', 'cost' => 0, 'locked' => true]); \App\Models\TransactionType::create(['name' => 'member_fee', 'description' => 'Membership Fee', 'cost' => 50]); //Myspace Tom Feature User::created(function ($user) use($tyler) { //$user->befriend($tyler); }); }
<?php use app\widgets\app\widgets\MiniForm; use app\models\Transactions; use yii\grid\GridView; use yii\data\ActiveDataProvider; /* * ********************************************************************************* * The contents of this file are subject to the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 * ("License"); You may not use this file except in compliance with the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 * The Original Code is: Linet 3.0 Open Source * The Initial Developer of the Original Code is Adam Ben Hur. * All portions are Copyright (C) Adam Ben Hur. * All Rights Reserved. * ********************************************************************************** */ app\widgets\MiniForm::begin(array('header' => Yii::t('app', "Transactions"))); echo app\widgets\GridView::widget(['dataProvider' => $model->search([]), 'filterModel' => $model, 'id' => 'transactions-grid', 'columns' => array(array('attribute' => 'num'), 'linenum', array('attribute' => 'type', 'filter' => \yii\helpers\ArrayHelper::map(\app\models\TransactionType::find()->All(), 'id', 'name'), 'value' => function ($data) { return Yii::t("app", $data->ttype->name); }), array('attribute' => 'account_id', 'value' => function ($data) { return \yii\helpers\Html::a(\app\models\Accounts::findName($data->account_id), yii\helpers\BaseUrl::base() . ("/accounts/transaction/" . $data->account_id)); }, 'format' => 'raw'), array('attribute' => 'refnum1', 'value' => function ($data) { return $data->refnumDocsLink(); }, 'format' => 'raw'), 'refnum2', 'details', ['attribute' => 'valuedate', 'filterType' => \kartik\grid\GridView::FILTER_DATE_RANGE, 'filterWidgetOptions' => ['convertFormat' => true, 'useWithAddon' => true, 'pluginOptions' => ['format' => 'Y-m-d', 'separator' => ' to '], 'hideInput' => true, 'presetDropdown' => false], 'width' => '150px', 'value' => function ($data) { return $data->readDateFormat($data->valuedate); }], ['attribute' => 'reg_date', 'filterType' => \kartik\grid\GridView::FILTER_DATE_RANGE, 'filterWidgetOptions' => ['convertFormat' => true, 'useWithAddon' => true, 'pluginOptions' => ['format' => 'Y-m-d', 'separator' => ' to '], 'hideInput' => true, 'presetDropdown' => false], 'width' => '150px', 'value' => function ($data) { return $data->readDateFormat($data->reg_date); }], array('header' => Yii::t('app', 'Debit'), 'attribute' => 'sum', 'filter' => '', 'value' => function ($data) { return $data->sum < 0 ? $data->sum : ""; }), array('header' => Yii::t('app', 'Credit'), 'attribute' => 'sum', 'filter' => '', 'value' => function ($data) { return $data->sum > 0 ? $data->sum : ""; }))]); ?>
/** * 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('/'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $transactionType = TransactionType::create($request->all()); }
public function getTtype() { return $this->hasOne(TransactionType::className(), array('id' => 'type')); }
public static function byName($typeName) { return TransactionType::where('name', $typeName)->firstOrFail(); }