Пример #1
0
 public static function baseQuery()
 {
     $query = Budget::find();
     $query->andWhere(['user_id' => CurrentUser::getId()]);
     $query->andWhere(['active' => true]);
     return $query;
 }
Пример #2
0
 public function run()
 {
     $users = User::all();
     foreach ($users as $user) {
         /**
          * @VP:
          * Why didn't this syntax work?
          * $budgets = Config::get('budgets.seeder{$user->id}');
          */
         $budgets = Config::get('budgets.seeder' . $user->id);
         foreach ($budgets as $budget) {
             $tmp = new Budget($budget);
             $tmp->user()->associate($user);
             $tmp->save();
         }
     }
 }
Пример #3
0
 /**
  * @test
  * @return void
  */
 public function it_deletes_a_budget()
 {
     $this->logInUser();
     $budget = Budget::forCurrentUser()->first();
     $response = $this->apiCall('DELETE', '/api/budgets/' . $budget->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('budgets', ['user_id' => $this->user->id, 'name' => $budget->name]);
 }
Пример #4
0
 /**
  * For the pie chart
  * GET api/totals/spentOnBudgets
  * @param Request $request
  * @return array
  */
 public function spentOnBudgets(Request $request)
 {
     $budgets = Budget::forCurrentUser()->with('transactions')->get();
     $totals = [];
     foreach ($budgets as $budget) {
         $totals[] = ['id' => $budget->id, 'name' => $budget->name, 'spentInDateRange' => $budget->getSpentInDateRange($request->get('from'), $request->get('to'))];
     }
     return $totals;
 }
Пример #5
0
 /**
  * Change to a static constructor or not, up to you
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_FLEX;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FLEX)->get();
     $this->amount = $this->calculate('amount');
     $this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
     $this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
     $this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
     $this->unallocatedAmount = 100 - $this->amount;
     $this->allocatedPlusUnallocatedAmount = 100;
 }
 /**
  * Update the allocation for the transaction's budgets
  * @param $content
  * @return mixed
  */
 private function updateAllocation($content)
 {
     $budget = Budget::find(2);
     $response = $this->call('PUT', '/api/budgets/' . $budget->id . '/transactions/' . $content['id'], ['type' => 'fixed', 'value' => 52.05]);
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     $budget = Budget::find(3);
     $response = $this->call('PUT', '/api/budgets/' . $budget->id . '/transactions/' . $content['id'], ['type' => 'fixed', 'value' => 29.99]);
     $updatedTransaction = json_decode($response->getContent(), true);
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     return $updatedTransaction;
 }
Пример #7
0
 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();
 }
Пример #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Budget::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(['id' => $this->id, 'price' => $this->price]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #9
0
 /**
  * Change to a static constructor or not, up to you
  * @param null $budgets
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_FIXED;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FIXED)->get();
     $this->amount = $this->calculate('amount');
     $this->remaining = $this->calculate('remaining');
     $this->cumulative = $this->calculate('cumulative');
     $this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
     $this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
     $this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
     //Transform budgets
     $resource = createCollection($this->budgets, new BudgetTransformer());
     $this->budgets = transform($resource);
 }
 /**
  * For when a new transaction is entered, so that the calculated allocation
  * for each tag is not 100%, which makes no sense.
  * Give the first tag an allocation of 100% and the rest 0%.
  * @param Transaction $transaction
  * @param $budgetIds
  * @return mixed
  */
 public function attachBudgetsWithDefaultAllocation(Transaction $transaction, $budgetIds)
 {
     $assignedCount = 0;
     foreach ($budgetIds as $budgetId) {
         $budget = Budget::find($budgetId);
         if ($budget->isAssigned()) {
             $assignedCount++;
             if ($assignedCount === 1) {
                 //Allocate 100% of the transaction to the first assigned budget
                 $transaction->budgets()->attach($budget->id, ['allocated_percent' => 100, 'calculated_allocation' => $transaction->total]);
             } else {
                 //Allocate 0% of the transaction to the other assigned budgets
                 $transaction->budgets()->attach($budget->id, ['allocated_percent' => 0, 'calculated_allocation' => 0]);
             }
         } else {
             //Budget is unassigned. No need to allocate.
             $transaction->budgets()->attach($budget->id);
         }
     }
 }
Пример #11
0
 /**
  * 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);
     });
 }
 /**
  *
  */
 public function run()
 {
     $users = User::all();
     foreach ($users as $user) {
         foreach ($this->favourites as $favourite) {
             $newFavourite = new FavouriteTransaction(['name' => $favourite['name'], 'type' => $favourite['type'], 'description' => $favourite['description'], 'merchant' => $favourite['merchant'], 'total' => $favourite['total']]);
             $newFavourite->user()->associate($user);
             if ($favourite['type'] === 'transfer') {
                 $newFavourite->fromAccount()->associate(Account::where('user_id', $user->id)->where('name', $favourite['fromAccount'])->first());
                 $newFavourite->toAccount()->associate(Account::where('user_id', $user->id)->where('name', $favourite['toAccount'])->first());
             } else {
                 $newFavourite->account()->associate(Account::where('user_id', $user->id)->where('name', $favourite['account'])->first());
             }
             $newFavourite->save();
             $budgetIds = [];
             foreach ($favourite['budgets'] as $budgetName) {
                 $budgetIds[] = Budget::where('user_id', $user->id)->where('name', $budgetName)->pluck('id');
             }
             $newFavourite->budgets()->attach($budgetIds);
         }
     }
 }
Пример #13
0
                        <td width="100" align="right">2</td>
                        <td>นางสาวxxxx&nbsp;&nbsp;xxxx</td>
                        <td>พยาบาลวิชาชีพ ชำนาญการ</td>
                        <td>ประธานกรรมการ</td>
                    </tr>
                </table>
                <table class="table table-bordered" style="font-size:15pt;">
                    <tr align="center">
                        <td align="center">ยอดเงินที่ได้รับจัดสรร</td>
                        <td align="center">ยอดเงินที่จัดสรรแล้ว</td>
                        <td align="center">ยอดเงินที่จัดสรรครั้งนี้</td>
                        <td align="center">ยอดเงินคงเหลือ</td>
                    </tr>
                    <tr>
                        <td align="center"><?php 
echo $cart->format_number(Budget::find()->where(['id' => $model->budget_id])->one()->name);
?>
</td>
                        <td align="center"><?php 
echo $cart->format_number(Inventorydetail::find()->sum('price'));
?>
</td>
                        <td align="center"><?php 
echo $cart->format_number(1800);
?>
</td>
                        <td align="center"><?php 
echo $cart->format_number(1800);
?>
</td>
                    </tr>
Пример #14
0
        <div class="budget-item-form">

            <?php 
$form = ActiveForm::begin(['id' => 'Report', 'layout' => 'horizontal', 'enableClientValidation' => true, 'errorSummaryCssClass' => 'error-summary alert alert-error']);
?>

            <div class="">
                <?php 
$this->beginBlock('main');
?>


                <p></p>
                <?php 
echo $form->field($model, 'budget_id')->dropDownList(ArrayHelper::map(\app\models\Budget::baseQuery()->all(), 'id', 'title'), ['prompt' => Yii::t('app', 'Select')]);
?>
                <?php 
echo $form->field($model, 'currency_id')->dropDownList(app\models\Currency::getActiveCurrency(), ['prompt' => Yii::t('app', 'Select')]);
?>
                <?php 
echo $form->field($model, 'type_id')->dropDownList(ArrayHelper::merge([0 => 'Все операции'], ArrayHelper::map(app\models\TypeBudgetItem::find()->all(), 'id', 'type')), ['prompt' => Yii::t('app', 'Select')]);
?>
                <div class="form-group">
                    <label class="control-label col-sm-3" for="budgetitem-date">Период</label>
                    <div class="col-sm-6">
                        <?php 
echo DatePicker::widget(['model' => $model, 'name' => 'Report[date_from]', 'type' => DatePicker::TYPE_RANGE, 'name2' => 'Report[date_to]', 'separator' => '-', 'pluginOptions' => ['format' => 'dd.mm.yyyy', 'class' => 'col-sm-6']]);
?>
                    </div>
                </div>
Пример #15
0
 /**
  * Change to a static constructor or not, up to you
  * @param null $budgets
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_UNASSIGNED;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_UNASSIGNED)->get();
 }
Пример #16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBudget()
 {
     return $this->hasOne(\app\models\Budget::className(), ['id' => 'budget_id']);
 }
Пример #17
0
 /**
  * A basic functional test example.
  * @test
  * @return void
  */
 public function it_does_not_update_an_assigned_budget_if_values_are_the_same()
 {
     $this->logInUser();
     $budget = Budget::forCurrentUser()->where('type', '!=', 'unassigned')->first();
     $response = $this->apiCall('PUT', '/api/budgets/' . $budget->id, ['name' => $budget->name, 'amount' => $budget->amount]);
     $this->seeInDatabase('budgets', ['user_id' => $this->user->id, 'name' => $budget->name, 'amount' => $budget->amount]);
     $this->assertEquals(304, $response->getStatusCode());
 }
Пример #18
0
 public function get_budget()
 {
     try {
         $user = auth()->user();
         $budget = Budget::get($user);
         return view('/budget', ["user" => $user, "budget" => $budget]);
     } catch (PDOException $e) {
         die($e->getMessage());
     }
 }
Пример #19
0
 public function attributes()
 {
     // add related fields to searchable attributes
     return array_merge(parent::attributes(), []);
 }
Пример #20
0
 /**
  * Delete a budget
  * DELETE api/budgets/{budgets}
  * @param Budget $budget
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  */
 public function destroy(Budget $budget)
 {
     $budget->delete();
     return response([], 204);
 }
Пример #21
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBudgets()
 {
     return $this->hasMany(\app\models\Budget::className(), ['user_id' => 'id']);
 }
Пример #22
0
 /**
  * Finds the Budget model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Budget the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Budget::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #23
0
?>

            </div>
            <div class="col-md-2">
                <?php 
echo $form->field($model, 'd_date')->widget(DatePicker::className(), ['clientOptions' => ['changeMonth' => true, 'changeYear' => true], 'dateFormat' => 'yyyy-MM-dd', 'options' => ['class' => 'form-control']]);
?>
            </div>
            <div class="col-md-3">
                <?php 
echo $form->field($model, 'bill_no')->textInput();
?>
            </div>
            <div class="col-md-2">
                <?php 
echo $form->field($model, 'budget_id')->dropdownList(ArrayHelper::map(Budget::find()->all(), 'id', 'name'), ['id' => 'budget_id', 'prompt' => '--- เลือกข้อมูล ---', 'required' => '']);
?>
            </div>
        </div>
        <div class="row">
            <div class="col-md-3">          
                <?php 
echo $form->field($model, 'partner_id')->dropdownList(ArrayHelper::map(Partner::find()->all(), 'id', 'name'), ['id' => 'partner_id', 'prompt' => '--- เลือกข้อมูล ---', 'required' => '']);
?>
            </div>
            <div class="col-md-2">

            </div>
        </div>
        <table cellpadding="6" cellspacing="1" style="width:100%" border="0" class="table table-bordered">
            <tr>
Пример #24
0
 /**
  *
  * @param $user
  * @return mixed
  */
 private function getRandomUnassignedBudgetIds($user)
 {
     $budgetIds = Budget::where('user_id', $user->id)->whereType('unassigned')->lists('id')->all();
     return $this->faker->randomElements($budgetIds, $this->faker->numberBetween(1, 3));
 }