public function accounts($increaseon = false, $usedAccounts = []) { /* $rows = (new \yii\db\Query()) ->select(["t.id AS id", "case when (t.code < 0) then t.name else concat (t.code,' - ',t.name) end as name,t.increaseon,t.isbalance,t.exchangable"]) ->from(AccountCode::tableName()." AS t") ->leftJoin(AccountCode::tableName()." AS a", "t.id = a.parent_id") ->where(($increaseon?"t.increaseon = :increaseon AND ":"")."a.id is null AND not (t.id = ANY(array".json_encode($usedAccounts)."::integer[]))",$increaseon?['increaseon'=>$increaseon]:[]) ->orderBy("name") ->all(); */ $rows = AccountCodeSearch::find()->select(["" . AccountCode::tableName() . ".id AS id", "case when (" . AccountCode::tableName() . ".code < 0) then " . AccountCode::tableName() . ".name else concat (" . AccountCode::tableName() . ".code,' - '," . AccountCode::tableName() . ".name) end as name," . AccountCode::tableName() . ".increaseon," . AccountCode::tableName() . ".isbalance," . AccountCode::tableName() . ".exchangable"])->leftJoin(AccountCode::tableName() . " AS a", AccountCode::tableName() . ".id = a.parent_id")->andWhere(($increaseon ? "" . AccountCode::tableName() . ".increaseon = :increaseon AND " : "") . "a.id is null AND not (" . AccountCode::tableName() . ".id = ANY(array" . json_encode($usedAccounts) . "::integer[]))", $increaseon ? ['increaseon' => $increaseon] : [])->orderBy("name")->asArray()->all(); return $rows; }
public function actionRe_arrange() { $transaction = Yii::$app->db->beginTransaction(); try { $account = AccountCodeSearch::find()->andWhere("parent_id is null")->orderBy("id")->all(); $res = true; foreach ($account as $m) { $res = $m->re_arrange(); } if ($res) { $transaction->commit(); return $this->redirect(['index']); } else { $transaction->rollBack(); die('Error!'); } } catch (Exception $e) { $transaction->rollBack(); die('Error!'); } /* $transaction = Yii::$app->db->beginTransaction(); try { $accounts = AccountCode::find()->andWhere("parent_id is not null")->orderBy("id")->all(); $res = Yii::$app->db->createCommand("update ".AccountCode::tableName()." SET (id_left,id_right,id_level,isdel) = (-1,0,0,1) WHERE parent_id is not null")->execute(); $res = Yii::$app->db->createCommand("update ".AccountCode::tableName()." SET (id_left,id_right,id_level,isdel) = (1,2,1,0) WHERE parent_id is null")->execute(); foreach ($accounts as $account) { $parent_id = $account->parent_id+0; $res = Yii::$app->db->createCommand("update ".AccountCode::tableName()." SET parent_id = null WHERE id=".$account->id)->execute(); $account0 = AccountCode::findOne($account->id); $account0->parent_id = $parent_id; $account0->isdel = 0; $res = (!$account0->save()?false:$res); } $transaction->commit(); return $this->redirect(['index']); } catch (Exception $e) { $transaction->rollBack(); die('Error saat import'); } */ }
public function getHtmlIndex($id = false, $name = false) { $module = Yii::$app->getModule('cap'); $search = $id; $sql = 'id = :search'; if ($name) { $search = $name; $sql = 'name = :search'; } $account = AccountCodeSearch::find()->where($sql, ['search' => $search])->one(); $value = 0; $value = $account->sisa * ($account->increaseon == 0 ? 1 : -1); $div = pow(10, max(0, floor((strlen($account->max . "") - 1) / 3)) * 3); $html = '<li> ' . ($account->parent_id != null ? $account->code . ' - ' : '<h4>') . Html::a($account->name, ['view', 'id' => $account->id]) . '<span class="pull-right">' . number_format($value / ($div == 0 ? 1 : $div), 2, $module->currency["decimal_separator"], $module->currency["thousand_separator"]) . '</span>' . ($account->parent_id != null ? '' : '</h4>') . ' <ul id="account-codes-' . $account->id . '" class="navs" style="clear:right">'; $children = $account->accountCodes; foreach ($children as $child) { $html .= Account::getHtmlIndex($child->id); } $html .= ' </ul> </li>'; return $html; }