public function initAccounts() { //create default account for balance Item $account = new Account(); $account->name = $this->name; $account->balance_item_id = $this->id; $errors = []; if ($account->save()) { //for all existed balance items create amount for default account $bSheets = BalanceSheet::find()->all(); $success = true; foreach ($bSheets as $sheet) { if (isset($sheet->id)) { $amount = new BalanceAmount(); $amount->account_id = $account->id; $amount->balance_sheet_id = $sheet->id; $amount->amount = 0; if (!$amount->save()) { $success = false; $errors['amount'] = $amount->errors; } } } if ($success) { return false; } } else { $errors['account'] = $account->errors; } $errors['message'] = "Errors in BalanceItem::initAccounts()"; return $errors; }
public function prepareNext() { $this->is_month = true; $last = BalanceSheet::find()->orderBy('period_start DESC')->limit(1)->one(); if ($last) { $this->period_start = date("Y-m-d", strtotime("+1 month", strtotime($last->period_start))); } else { $this->period_start = (new \DateTime('first day of previous month'))->format("Y-m-d"); } }
public function actionDrop() { $list = \app\models\BalanceItem::find()->all(); foreach ($list as $item) { $item->delete(); } $list = \app\models\BalanceSheet::find()->all(); foreach ($list as $item) { $item->delete(); } return $this->redirect(['index']); }
/** * Lists all BalanceSheet models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => BalanceSheet::find()->orderBy('period_start')]); return $this->render('index', ['dataProvider' => $dataProvider]); }