public static function baseQuery() { $query = Budget::find(); $query->andWhere(['user_id' => CurrentUser::getId()]); $query->andWhere(['active' => true]); return $query; }
/** * 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; }
/** * 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; }
/** * 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); } } }
<td width="100" align="right">2</td> <td>นางสาวxxxx 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>
/** * @test * @return void */ public function it_changes_a_budget_type_from_unassigned_to_fixed() { $this->logInUser(); $budget = Budget::find(1); $this->assertEquals('unassigned', $budget->type); $startingDate = Carbon::today()->subMonths(14); $response = $this->apiCall('PUT', '/api/budgets/' . $budget->id, ['type' => 'fixed', 'starting_date' => $startingDate->copy()->format('Y-m-d'), 'amount' => 5]); $content = json_decode($response->getContent(), true); // dd($content); $this->checkBudgetKeysExist($content, true); $this->assertEquals(1, $content['id']); $this->assertEquals('http://localhost/api/budgets/1', $content['path']); $this->assertEquals('bank fees', $content['name']); $this->assertEquals(5, $content['amount']); // $this->assertEquals(1300, $content['calculatedAmount']); $this->assertEquals('fixed', $content['type']); $this->assertEquals($startingDate->copy()->format('d/m/y'), $content['formattedStartingDate']); $this->assertEquals(-5, $content['spent']); $this->assertEquals(0, $content['received']); $this->assertEquals(-5, $content['spentOnOrAfterStartingDate']); $this->assertEquals(0, $content['spentBeforeStartingDate']); $this->assertEquals(0, $content['receivedOnOrAfterStartingDate']); $this->assertEquals(15, $content['cumulativeMonthNumber']); $this->assertEquals(75, $content['cumulative']); $this->assertEquals(70, $content['remaining']); $this->assertEquals(1, $content['transactionsCount']); $this->assertEquals(200, $response->getStatusCode()); }
?> </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>