public function delete() { $users = User::model()->findAll(); foreach ($users as $user) { $IncomeMap = UserIncomeMap::model()->findByPk(array('user_id' => $user->id, 'itemVatCat_id' => $this->id)); if ($IncomeMap) { //'user_id', 'itemVatCat_id' $IncomeMap->delete(); } } parent::delete(); }
public function findByPk($id, $condition = '', $params = array()) { $model = parent::findByPk($id, $condition = '', $params = array()); if ($model !== null) { $incomeMap = UserIncomeMap::model()->findByPk(array('user_id' => Yii::app()->user->id, 'itemVatCat_id' => $model->itemVatCat_id)); if ($incomeMap !== null) { $model->vat = Accounts::model()->getSrcTax($incomeMap->account_id); } else { $model->vat = 0; } } return $model; }
private function compSave() { $catagories = ItemVatCat::model()->findAll(); foreach ($catagories as $catagory) { if (!UserIncomeMap::model()->findByPk(array('user_id' => $this->id, 'itemVatCat_id' => $catagory->id))) { //'user_id', 'itemVatCat_id' $model = new UserIncomeMap(); $attr = array("user_id" => $this->id, "itemVatCat_id" => $catagory->id, "account_id" => 100); $model->attributes = $attr; if (!$model->save()) { return false; } } } Yii::log('user save catagory', 'info', 'app'); $tmps = CUploadedFile::getInstanceByName('User[certfile]'); if ($tmps) { Yii::log('saved', 'info', 'app'); if ($tmps->saveAs($this->getCertFilePath($this->id))) { // add it to the main model now } else { echo 'Cannot upload!'; } //} } }
public function transaction($transaction, $action, $optacc) { $this->ini(); if (is_null($this->Item)) { throw new CHttpException(500, 'The item ' . $this->item_id . ' does not exsits.'); } $vatcat = $this->Item->itemVatCat_id; $vatCatAcc = UserIncomeMap::model()->findByPk(array('user_id' => Yii::app()->user->id, 'itemVatCat_id' => $vatcat)); if ($vatCatAcc === null) { throw new CHttpException(500, 'The item ' . $this->item_id . ' does not have a vat catagory.'); } $sum = 0; if (is_null($optacc)) { $incomeacc = $vatCatAcc->account_id; $sum = $this->ihTotal * $action; } else { $incomeacc = $optacc; $vat = $this->iTotalVat - $this->iTotal; if ($oppt = Accounts::model()->findByPk($incomeacc)) { $multi = 1 - $oppt->src_tax / 100; } $vat = round($vat * $multi, $this->_precision); //$multi=$this->iTotalVat*$multi; Yii::log($this, CLogger::LEVEL_INFO, __METHOD__); Yii::log($multi, CLogger::LEVEL_INFO, __METHOD__); $sum = ($this->ihTotal + $vat) * $action; } if ($sum) { return $transaction->addSingleLine($incomeacc, round($sum, $this->_precision)); } return $transaction; }