Example #1
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Time the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Time::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #2
0
	</div>

	<div class="row">
		 <span>Placar Visitante</span>
		<?php 
echo $form->textField($model, 'placar_visitante');
?>
		<?php 
echo $form->error($model, 'placar_visitante');
?>
	</div>

	<div class="row">
		 <span>Vencedor</span>
		<?php 
echo $form->dropDownList($model, 'vencedor', CHtml::listData(Time::model()->findAll(), 'id', 'nome'));
?>
		<?php 
echo $form->error($model, 'vencedor');
?>
	</div>

	<div class="row">
		 <span>Empate</span>
		<?php 
echo $form->textField($model, 'empate');
?>
		<?php 
echo $form->error($model, 'empate');
?>
	</div>
Example #3
0
  <h3 class="w3-regular"><?php 
            echo Yii::t('t', 'Unknown project');
            ?>
</h3>
<?php 
        }
        $tn = 0;
        foreach ($project['allTask'] as $task) {
            if ($tn >= 1) {
                ?>
  <div class="w3-between-boxes-small">&nbsp;</div>
<?php 
            }
            $this->widget('application.components.WGrid', array('displayButtonClose' => true, 'importantRowsBottom' => array(array(array('align' => 'right', 'colspan' => 3, 'content' => Yii::t('math', 'Total')), array('align' => 'right', 'content' => Time::model()->getAttributeView('billedMinute', $task['total']['billedMinute'])), array('align' => 'right', 'content' => Time::model()->getAttributeView('spentMinute', $task['total']['spentMinute']))), array(array('align' => 'right', 'colspan' => 3, 'content' => Yii::t('t', 'Amount')), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($task['total']['billedAmount']))), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($task['total']['spentAmount']))))), 'maxRow' => count($task['gridRows']), 'minRow' => count($task['gridRows']) >= 1 ? 1 : 0, 'rows' => $task['gridRows'], 'sColumns' => array(array('title' => Yii::app()->user->checkAccess(User::CLIENT) || Yii::app()->user->checkAccess(User::CONSULTANT) ? Yii::t('t', 'Manager') : Yii::t('t', 'Consultant'), 'width' => 100), array('title' => Yii::t('t', 'Date'), 'width' => 60), array('title' => Yii::t('t', 'Note')), array('nowrap' => true, 'title' => Yii::t('t', 'Billed'), 'width' => 90), array('nowrap' => true, 'title' => Yii::t('t', 'Spent'), 'width' => 90)), 'sGridId' => 'timeGrid' . (isset($task['task']) ? $task['task']->id : microtime(true) * 10000), 'title' => isset($task['task']) ? '<span title="' . Yii::t('t', 'Task') . '">' . CHtml::encode($task['task']->title) . '</span><span class="w3-position-absolute">' . CHtml::link('', array('task/show', 'id' => $task['task']->id), array('class' => 'ui-icon ui-icon-extlink', 'rel' => 'external', 'title' => Yii::t('link', 'Show task'))) . '</span>' : Yii::t('t', 'Unknown task'), 'totalRecords' => count($task['gridRows'])));
            $tn++;
        }
        /*task*/
        ?>
  <div class="w3-between-boxes-small">&nbsp;</div>
<?php 
        $this->widget('application.components.WGrid', array('displaySGrid' => true, 'displaySGridPager' => false, 'importantRowsBottom' => array(array(array('align' => 'right', 'content' => Yii::t('math', 'Total')), array('align' => 'right', 'content' => Time::model()->getAttributeView('billedMinute', $project['total']['billedMinute'])), array('align' => 'right', 'content' => Time::model()->getAttributeView('spentMinute', $project['total']['spentMinute']))), array(array('align' => 'right', 'content' => Yii::t('t', 'Amount')), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($project['total']['billedAmount']))), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($project['total']['spentAmount']))))), 'sColumns' => array(array('title' => isset($project['project']) ? $project['project']->title !== '' ? CHtml::encode($project['project']->title) : $project['project']->id : Yii::t('t', 'Unknown project')), array('nowrap' => true, 'title' => Yii::t('t', 'Billed'), 'width' => 90), array('nowrap' => true, 'title' => Yii::t('t', 'Spent'), 'width' => 90)), 'sGridId' => 'projectTotal' . (isset($project['project']) ? $project['project']->id : microtime(true) * 10000), 'title' => Yii::t('t', 'Project')));
        $pn++;
    }
    /*project*/
    ?>
  <div class="w3-between-boxes">&nbsp;</div>
<?php 
    $this->widget('application.components.WGrid', array('displaySGrid' => true, 'displaySGridPager' => false, 'importantRowsBottom' => array(array(array('align' => 'right', 'content' => Yii::t('math', 'Total')), array('align' => 'right', 'content' => Time::model()->getAttributeView('billedMinute', $company['total']['billedMinute'])), array('align' => 'right', 'content' => Time::model()->getAttributeView('spentMinute', $company['total']['spentMinute']))), array(array('align' => 'right', 'content' => Yii::t('t', 'Amount')), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($company['total']['billedAmount']))), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($company['total']['spentAmount']))))), 'sColumns' => array(array('title' => isset($company['company']) ? $company['company']->title !== '' ? CHtml::encode($company['company']->title) : $company['company']->id : Yii::t('t', 'Unknown company')), array('nowrap' => true, 'title' => Yii::t('t', 'Billed'), 'width' => 90), array('nowrap' => true, 'title' => Yii::t('t', 'Spent'), 'width' => 90)), 'sGridId' => 'companyTotal' . (isset($company['company']) ? $company['company']->id : microtime(true) * 10000), 'title' => Yii::t('t', 'Company')));
    $cn++;
}
/*company*/
Example #4
0
 /**
  * Time report.
  */
 public function actionReport()
 {
     $criteria = new CDbCriteria();
     $criteria->select = "`t`.billedMinute, `t`.spentMinute, `t`.timeDate, `t`.title";
     //$criteria->select="`t`.`billedMinute`, `t`.`spentMinute`, `t`.`timeDate`, `t`.`title`"; // uncomment in yii-1.1.2
     $criteria->condition = "TO_DAYS(`t`.`timeDate`) >= TO_DAYS('2009-09-09')";
     $criteria->order = "`t`.`timeDate` ASC, `t`.`createTime` ASC";
     $with = array('task' => array('select' => 'hourlyRate,title'), 'task.company' => array('select' => 'title'), 'task.project' => array('select' => 'title'));
     if (Yii::app()->user->checkAccess(User::CLIENT)) {
         $with['manager'] = array('select' => 'screenName');
     } else {
         $with['consultant'] = array('select' => 'screenName');
     }
     $models = Time::model()->with($with)->findAll($criteria);
     $data = array();
     foreach ($models as $model) {
         $companyId = isset($model->task->company->id) ? $model->task->company->id : 0;
         if (!isset($data[$companyId]['company']) && isset($model->task->company->id)) {
             $data[$companyId]['company'] = $model->task->company;
         }
         $projectId = isset($model->task->project->id) ? $model->task->project->id : 0;
         if (!isset($data[$companyId]['allProject'][$projectId]['project']) && isset($model->task->project->id)) {
             $data[$companyId]['allProject'][$projectId]['project'] = $model->task->project;
         }
         $taskId = isset($model->task->id) ? $model->task->id : 0;
         if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['task']) && isset($model->task->id)) {
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['task'] = $model->task;
         }
         $timeId = $model->id;
         if (Yii::app()->user->checkAccess(User::CLIENT) || Yii::app()->user->checkAccess(User::CONSULTANT)) {
             $member = isset($model->manager->id) ? $model->manager : null;
         } else {
             $member = isset($model->consultant->id) ? $model->consultant : null;
         }
         $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['gridRows'][] = array(array('content' => $member !== null ? CHtml::link($member->screenName !== '' ? CHtml::encode($member->screenName) : $member->id, array('user/show', 'id' => $member->id)) : ''), array('align' => 'right', 'content' => CHtml::encode(MDate::format($model->timeDate, 'short', null)), 'title' => CHtml::encode(MDate::format($model->timeDate, 'full', null))), array('content' => CHtml::link($model->title !== '' ? CHtml::encode($model->title) : $model->id, array('time/show', 'id' => $model->id))), array('align' => 'right', 'content' => $model->getAttributeView('billedMinute'), 'title' => Yii::t('t', 'Hourly rate') . ': ' . (isset($model->task->id) ? (int) $model->task->hourlyRate : '?')), array('align' => 'right', 'content' => $model->getAttributeView('spentMinute'), 'title' => Yii::t('t', 'Hourly rate') . ': ' . (isset($model->task->id) ? (int) $model->task->hourlyRate : '?')));
         if (!isset($data[$companyId]['total']['billedMinute'])) {
             $data[$companyId]['total']['billedMinute'] = 0;
         }
         if (!isset($data[$companyId]['total']['spentMinute'])) {
             $data[$companyId]['total']['spentMinute'] = 0;
         }
         if (!isset($data[$companyId]['total']['billedAmount'])) {
             $data[$companyId]['total']['billedAmount'] = 0;
         }
         if (!isset($data[$companyId]['total']['spentAmount'])) {
             $data[$companyId]['total']['spentAmount'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['total']['billedMinute'])) {
             $data[$companyId]['allProject'][$projectId]['total']['billedMinute'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['total']['spentMinute'])) {
             $data[$companyId]['allProject'][$projectId]['total']['spentMinute'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['total']['billedAmount'])) {
             $data[$companyId]['allProject'][$projectId]['total']['billedAmount'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['total']['spentAmount'])) {
             $data[$companyId]['allProject'][$projectId]['total']['spentAmount'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'])) {
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'])) {
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'])) {
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'] = 0;
         }
         if (!isset($data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'])) {
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'] = 0;
         }
         $data[$companyId]['total']['billedMinute'] += $model->billedMinute;
         $data[$companyId]['total']['spentMinute'] += $model->spentMinute;
         $data[$companyId]['allProject'][$projectId]['total']['billedMinute'] += $model->billedMinute;
         $data[$companyId]['allProject'][$projectId]['total']['spentMinute'] += $model->spentMinute;
         $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedMinute'] += $model->billedMinute;
         $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentMinute'] += $model->spentMinute;
         if (isset($model->task->id)) {
             $data[$companyId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate;
             $data[$companyId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate;
             $data[$companyId]['allProject'][$projectId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate;
             $data[$companyId]['allProject'][$projectId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate;
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['billedAmount'] += $model->billedMinute / 60 * (int) $model->task->hourlyRate;
             $data[$companyId]['allProject'][$projectId]['allTask'][$taskId]['total']['spentAmount'] += $model->spentMinute / 60 * (int) $model->task->hourlyRate;
         }
     }
     $this->render($this->action->id, array('data' => $data, 'models' => $models, 'cn', 'pn', 'tn'));
 }
Example #5
0
 public function GetPosicaoTime($posicao, $grupo)
 {
     $modelGrupo = new Grupo();
     $Criteria = new CDbCriteria();
     $Criteria->condition = "nome = '{$grupo}'";
     $classificacao = array();
     $modelGrupo = Grupo::model()->find($Criteria);
     $Criteria = new CDbCriteria();
     $Criteria->condition = "id_grupo={$modelGrupo->id}";
     $model = GrupoTime::model()->findAll($Criteria);
     foreach ($model as $item) {
         $itemArray = array("id" => $item->id_time, "id_grupo" => $item->id_grupo, "nome" => $item->idTime->nome, "escudo" => $item->idTime->escudo, "pontos" => ConfrontoController::GetPontosDoTime($item->id_time));
         array_push($classificacao, $itemArray);
     }
     $classificacao = ConfrontoController::aasort($classificacao, "pontos");
     $conta = 1;
     foreach ($classificacao as $item) {
         if ($conta == $posicao) {
             $time = Time::model()->findByPk($item["id"]);
         }
         $conta = $conta + 1;
     }
     return $time;
 }
Example #6
0
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     if (isset($_POST['id'])) {
         if (Time::model()->deleteByPk($_POST['id'])) {
             Yii::app()->user->setFlash('status', 'Выбранное время удалено');
         }
     }
     $dataProvider = new CActiveDataProvider('Quests');
     $this->render('index', array('dataProvider' => $dataProvider));
 }
Example #7
0
 /**
  * Migrate from old project management system.
  */
 public function actionIndex()
 {
     // check rights
     if (!Yii::app()->user->checkAccess(User::ADMINISTRATOR)) {
         throw new CHttpException(403, Yii::t('Yii', 'You are not authorized to perform this action.'));
     }
     // models to migrate
     $migrate = array('User' => false, 'Company' => false, 'CompanyPayment' => false, 'Project' => false, 'Task' => false, 'Time' => true, 'Invoice' => false, 'Expense' => false);
     // start
     $message = '';
     // we won't migrate unless form is submitted
     if (Yii::app()->request->isPostRequest) {
         // default criteria
         $findAllCriteria = new CDbCriteria();
         $findAllCriteria->order = "`id` ASC";
         if ($migrate['User']) {
             // user
             $mUsers = MUser::model()->findAll($findAllCriteria);
             if (is_array($mUsers)) {
                 $i = $j = $c = 0;
                 $accessType = array('customer' => 'client', 'consultant' => 'consultant', 'manager' => 'manager', 'admin' => 'administrator');
                 $accessLevel = array('customer' => 2, 'consultant' => 3, 'manager' => 4, 'admin' => 5);
                 foreach ($mUsers as $oldModel) {
                     if (($model = User::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     // old model validation
                     if (User::model()->findByAttributes(array('email' => $oldModel->email))) {
                         $oldModel->email = rand(10, 99) . $oldModel->email;
                     }
                     $closeTime = strtotime($oldModel->close_date);
                     $isActive = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || $closeTime === false;
                     // new model
                     $model = new User('migrate');
                     $model->username = $oldModel->email;
                     $model->password = md5($oldModel->password);
                     $model->email = $oldModel->email;
                     $model->screenName = $oldModel->name;
                     $model->accessType = isset($accessType[$oldModel->class]) ? $accessType[$oldModel->class] : 'member';
                     $model->accessLevel = isset($accessLevel[$oldModel->class]) ? $accessLevel[$oldModel->class] : 1;
                     $model->isActive = $isActive ? '1' : '0';
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                         if (($userDetails = UserDetails::model()->findByPk($model->id)) !== null) {
                             $userDetails->delete();
                         }
                         $userDetails = new UserDetails('migrate');
                         $userDetails->emailConfirmationKey = md5(uniqid(rand(), true));
                         $userDetails->initials = $oldModel->inits;
                         $userDetails->occupation = $oldModel->title;
                         $userDetails->deactivationTime = $isActive ? null : $closeTime;
                         $userDetails->administratorNote = '[from migration]';
                         $userDetails->userId = $model->id;
                         $userDetails->save();
                         // relation between user and company
                         if ($oldModel->customer_id >= 1) {
                             $user2Company = new User2Company('migrate');
                             $user2Company->userId = $model->id;
                             $user2Company->companyId = $oldModel->customer_id;
                             $user2Company->position = 'owner';
                             //$oldModel->title
                             if ($user2Company->save()) {
                                 $c++;
                             }
                         }
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' users' . ($i === $c ? '' : ' with ' . $c . ' company (relations)') . ' have been migrated.<br/>';
             }
         }
         if ($migrate['Company']) {
             // company
             $mCustomers = MCustomer::model()->findAll($findAllCriteria);
             if (is_array($mCustomers)) {
                 $i = $j = $l = 0;
                 foreach ($mCustomers as $oldModel) {
                     if (($model = Company::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $closeTime = strtotime($oldModel->close_date);
                     $isActive = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || $closeTime === false;
                     $model = new Company('migrate');
                     $model->title = $oldModel->name;
                     $model->titleAbbr = $oldModel->inits;
                     $model->contactName = $oldModel->contact;
                     $model->contactEmail = $oldModel->contact_email;
                     $model->content = '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->invoiceDueDay = $oldModel->terms_days;
                     $model->isActive = $isActive ? '1' : '0';
                     $model->deactivationTime = $isActive ? null : $closeTime;
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                         // associated location
                         $location = new Location('migrate');
                         $location->address1 = $oldModel->addr;
                         $location->address2 = $oldModel->addr2;
                         $location->city = $oldModel->city;
                         $location->state = $oldModel->state;
                         $location->zipcode = $oldModel->zip;
                         $location->content = '[from migration]';
                         $location->contentMarkup = 'text';
                         $location->createTime = strtotime($oldModel->last);
                         if ($location->save()) {
                             // relation between company and location
                             $location2Record = new Location2Record('migrate');
                             $location2Record->locationId = $location->id;
                             $location2Record->record = get_class($model);
                             $location2Record->recordId = $model->id;
                             if ($location2Record->save()) {
                                 $l++;
                             }
                         }
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' companies' . ($i === $l ? '' : ' with ' . $l . ' locations') . ' have been migrated.<br/>';
             }
         }
         if ($migrate['CompanyPayment']) {
             // company payment
             $mCustomerPayments = MCustomerPayment::model()->findAll($findAllCriteria);
             if (is_array($mCustomerPayments)) {
                 $i = $j = 0;
                 $paymentMethod = array('cash' => 'cash', 'check' => 'check', 'credit card' => 'creditCard');
                 foreach ($mCustomerPayments as $oldModel) {
                     if (($model = CompanyPayment::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $model = new CompanyPayment('migrate');
                     $model->companyId = $oldModel->id;
                     $model->paymentDate = MDate::formatToDb($oldModel->payment_date, 'date');
                     $model->amount = $oldModel->amount;
                     $model->paymentMethod = $paymentMethod[$oldModel->payment_method];
                     $model->paymentNumber = $oldModel->payment_number;
                     $model->content = $oldModel->note . "\n" . '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' company payments have been migrated.<br/>';
             }
         }
         if ($migrate['Project']) {
             // project
             $mProjects = MProject::model()->findAll($findAllCriteria);
             if (is_array($mProjects)) {
                 $i = $j = $c = $u = 0;
                 foreach ($mProjects as $oldModel) {
                     if (($model = Project::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $openDateNotSet = empty($oldModel->open_date) || $oldModel->open_date === '0000-00-00' || strtotime($oldModel->open_date) === false;
                     $closeDateNotSet = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || strtotime($oldModel->close_date) === false;
                     $model = new Project('migrate');
                     $model->title = $oldModel->name;
                     $model->content = $oldModel->description . "\n" . '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->hourlyRate = $oldModel->rate;
                     $model->openDate = $openDateNotSet ? null : MDate::formatToDb($oldModel->open_date, 'date');
                     $model->closeDate = $closeDateNotSet ? null : MDate::formatToDb($oldModel->close_date, 'date');
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                         // relation between project and company
                         if ($oldModel->customer_id >= 1) {
                             $company2Project = new Company2Project('migrate');
                             $company2Project->companyId = $oldModel->customer_id;
                             $company2Project->projectId = $model->id;
                             if ($company2Project->save()) {
                                 $c++;
                             }
                         }
                         // relation between project and manager
                         if ($oldModel->manager_id >= 1) {
                             $user2Project = new User2Project('migrate');
                             $user2Project->userId = $oldModel->manager_id;
                             $user2Project->projectId = $model->id;
                             $user2Project->role = 'manager';
                             if ($user2Project->save()) {
                                 $u++;
                             }
                         }
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' projects' . ($i === $c ? '' : ' with ' . $c . ' company (relations)') . ($i === $u ? '' : ' with ' . $u . ' manager (relations)') . ' have been migrated.<br/>';
             }
         }
         if ($migrate['Task']) {
             // task
             $mTasks = MTask::model()->findAll($findAllCriteria);
             if (is_array($mTasks)) {
                 $i = $j = $u = $m = 0;
                 $priority = array('A' => 2, 'B' => 3, 'C' => 4, '' => 3);
                 $status = array('' => 'completed', 'Open' => 'completed', '0' => 'notStarted', 'New' => 'notStarted', 'Done' => 'completed', 'In Progress' => 'inProgress', 'Ready to Test' => 'readyToTest');
                 foreach ($mTasks as $oldModel) {
                     if (($model = Task::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $hourlyRate = null;
                     if ($oldModel->project_id >= 1 && ($project = Project::model()->findByPk($oldModel->project_id)) !== null) {
                         $hourlyRate = $project->hourlyRate;
                     }
                     $dueDateNotSet = empty($oldModel->due_date) || $oldModel->due_date === '0000-00-00' || strtotime($oldModel->due_date) === false;
                     $openDateNotSet = empty($oldModel->open_date) || $oldModel->open_date === '0000-00-00' || strtotime($oldModel->open_date) === false;
                     $closeDateNotSet = empty($oldModel->close_date) || $oldModel->close_date === '0000-00-00' || strtotime($oldModel->close_date) === false;
                     $model = new Task('migrate');
                     $model->title = $oldModel->name;
                     $model->content = $oldModel->description . "\n" . '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->companyId = $oldModel->customer_id;
                     $model->projectId = $oldModel->project_id;
                     $model->estimateMinute = (int) $oldModel->hours_estimate * 60;
                     $model->dueDate = $dueDateNotSet ? null : MDate::formatToDb($oldModel->due_date, 'date');
                     $model->priority = $priority[$oldModel->priority];
                     $model->openDate = $openDateNotSet ? null : MDate::formatToDb($oldModel->open_date, 'date');
                     $model->closeDate = $closeDateNotSet ? null : MDate::formatToDb($oldModel->close_date, 'date');
                     $model->status = $status[$oldModel->task_status];
                     $model->report = $oldModel->work_report;
                     $model->reportMarkup = 'text';
                     $model->hourlyRate = $hourlyRate;
                     $model->isConfirmed = '1';
                     $model->confirmationTime = strtotime($oldModel->last);
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                         // relation between task and consultant
                         if ($oldModel->leader_id >= 1) {
                             $user2Task = new User2Task('migrate');
                             $user2Task->userId = $oldModel->leader_id;
                             $user2Task->taskId = $model->id;
                             $user2Task->role = User2Task::CONSULTANT;
                             if ($user2Task->save()) {
                                 $u++;
                             }
                         }
                         // relation between task and manager
                         if ($model->projectId >= 1) {
                             $criteria = new CDbCriteria();
                             $criteria->order = "`" . User2Project::model()->tableName() . "`.`userPriority` ASC";
                             $criteria->order .= ",`" . User2Project::model()->tableName() . "`.`id` ASC";
                             if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $model->projectId, 'role' => 'manager'), $criteria)) !== null) {
                                 $user2Task = new User2Task('migrate');
                                 $user2Task->userId = $user2Project->userId;
                                 $user2Task->taskId = $model->id;
                                 $user2Task->role = 'manager';
                                 if ($user2Task->save()) {
                                     $m++;
                                 }
                             }
                         }
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' tasks' . ($i === $u ? '' : ' with ' . $u . ' consultant (relations)') . ($i === $m ? '' : ' with ' . $m . ' manager (relations)') . ' have been migrated.<br/>';
             }
         }
         if ($migrate['Time']) {
             // time
             $mTime = MTime::model()->findAll($findAllCriteria);
             if (is_array($mTime)) {
                 $i = $j = $t = 0;
                 foreach ($mTime as $oldModel) {
                     if (($model = Time::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $taskId = $oldModel->task_id;
                     if (empty($taskId) && $oldModel->project_id >= 1) {
                         $criteria = new CDbCriteria();
                         $criteria->order = "`" . Task::model()->tableName() . "`.`id` ASC";
                         if (($task = Task::model()->findByAttributes(array('projectId' => $oldModel->project_id), $criteria)) !== null) {
                             $taskId = $task->id;
                         } else {
                             // auto-generate a task
                             $companyId = 0;
                             $criteria = new CDbCriteria();
                             $criteria->order = "`" . Company2Project::model()->tableName() . "`.`companyPriority` ASC";
                             $criteria->order .= ", `" . Company2Project::model()->tableName() . "`.`id` ASC";
                             if (($company2Project = Company2Project::model()->findByAttributes(array('projectId' => $oldModel->project_id), $criteria)) !== null) {
                                 $companyId = $company2Project->companyId;
                             }
                             $hourlyRate = null;
                             if (($project = Project::model()->findByPk($oldModel->project_id)) !== null) {
                                 $hourlyRate = $project->hourlyRate;
                             }
                             $task = new Task('migrate');
                             $task->projectId = $oldModel->project_id;
                             $task->companyId = $companyId;
                             $task->title = '[Auto Generated]';
                             $task->status = 'completed';
                             $task->dueDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date');
                             $task->openDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date');
                             $task->closeDate = MDate::formatToDb($project === null ? 1234567890 : $project->createTime, 'date');
                             $task->hourlyRate = $hourlyRate;
                             $task->isConfirmed = 1;
                             $task->confirmationTime = $project === null ? 1234567890 : $project->createTime;
                             if ($task->save()) {
                                 $t++;
                                 $taskId = $task->id;
                                 // assigned consultant
                                 if ($oldModel->user_id >= 1) {
                                     $consultant2Task = new User2Task('migrate');
                                     $consultant2Task->userId = $oldModel->user_id;
                                     $consultant2Task->taskId = $task->id;
                                     $consultant2Task->role = User2Task::CONSULTANT;
                                     $consultant2Task->save();
                                 }
                                 // assigned manager
                                 $criteria = new CDbCriteria();
                                 $criteria->order = "`" . User2Project::model()->tableName() . "`.`userPriority` ASC";
                                 $criteria->order .= ", `" . User2Project::model()->tableName() . "`.`id` ASC";
                                 if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $oldModel->project_id, 'role' => 'manager'), $criteria)) !== null) {
                                     $manager2Task = new User2Task('migrate');
                                     $manager2Task->userId = $user2Project->userId;
                                     $manager2Task->taskId = $task->id;
                                     $manager2Task->role = User2Task::MANAGER;
                                     $manager2Task->save();
                                 }
                             }
                         }
                     }
                     $managerId = null;
                     if (!empty($taskId)) {
                         $criteria = new CDbCriteria();
                         $criteria->order = "`" . User2Task::model()->tableName() . "`.`userPriority` ASC";
                         $criteria->order .= ",`" . User2Task::model()->tableName() . "`.`id` ASC";
                         if (($user2Task = User2Task::model()->findByAttributes(array('taskId' => $taskId, 'role' => 'manager'), $criteria)) !== null) {
                             $managerId = $user2Task->userId;
                         }
                     }
                     $timeDateNotSet = empty($oldModel->time_date) || $oldModel->time_date === '0000-00-00' || strtotime($oldModel->time_date) === false;
                     $model = new Time('migrate');
                     $model->consultantId = $oldModel->user_id;
                     $model->taskId = $taskId;
                     $model->spentMinute = (int) $oldModel->hours_spent * 60;
                     $model->timeDate = $timeDateNotSet ? null : MDate::formatToDb($oldModel->time_date, 'date');
                     $model->title = $oldModel->note;
                     $model->content = $oldModel->details . "\n" . '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->managerId = $managerId;
                     $model->billedMinute = (int) $oldModel->hours_billed * 60;
                     $model->invoiceId = $oldModel->invoice_id;
                     $model->invoiceAmount = $oldModel->invoice_amount;
                     $model->isConfirmed = '1';
                     $model->confirmationTime = strtotime($oldModel->last);
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' time records' . ($i === $t ? '' : ' with ' . $t . ' tasks') . ' have been migrated.<br/>';
             }
         }
         if ($migrate['Invoice']) {
             // invoice
             $mInvoices = MInvoice::model()->findAll($findAllCriteria);
             if (is_array($mInvoices)) {
                 $i = $j = 0;
                 foreach ($mInvoices as $oldModel) {
                     if (($model = Invoice::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $invoiceDateNotSet = empty($oldModel->invoice_date) || $oldModel->invoice_date === '0000-00-00' || strtotime($oldModel->invoice_date) === false;
                     $startDateNotSet = empty($oldModel->start_date) || $oldModel->start_date === '0000-00-00' || strtotime($oldModel->start_date) === false;
                     $endDateNotSet = empty($oldModel->end_date) || $oldModel->end_date === '0000-00-00' || strtotime($oldModel->end_date) === false;
                     $dueDateNotSet = empty($oldModel->due_date) || $oldModel->due_date === '0000-00-00' || strtotime($oldModel->due_date) === false;
                     $model = new Invoice('migrate');
                     $model->invoiceDate = $invoiceDateNotSet ? null : MDate::formatToDb($oldModel->invoice_date, 'date');
                     $model->companyId = $oldModel->customer_id;
                     $model->billedMinute = (int) $oldModel->hours_billed * 60;
                     $model->amountTotal = number_format($oldModel->total, 2, '.', '');
                     $model->startDate = $startDateNotSet ? null : MDate::formatToDb($oldModel->start_date, 'date');
                     $model->endDate = $endDateNotSet ? null : MDate::formatToDb($oldModel->end_date, 'date');
                     $model->dueDate = $dueDateNotSet ? null : MDate::formatToDb($oldModel->due_date, 'date');
                     $model->amountTime = number_format($oldModel->total, 2, '.', '');
                     $model->amountExpense = 0;
                     $model->content = '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->createTime = $invoiceDateNotSet ? null : strtotime($oldModel->invoice_date);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' invoices have been migrated.<br/>';
             }
         }
         if ($migrate['Expense']) {
             // expense
             $mExpenses = MExpense::model()->findAll($findAllCriteria);
             if (is_array($mExpenses)) {
                 $i = $j = 0;
                 $billToCompany = array('Yes' => '1', 'No' => '0');
                 foreach ($mExpenses as $oldModel) {
                     if (($model = Expense::model()->findByPk($oldModel->id)) !== null) {
                         $model->delete();
                     }
                     $expenseDateNotSet = empty($oldModel->expense_date) || $oldModel->expense_date === '0000-00-00' || strtotime($oldModel->expense_date) === false;
                     $model = new Expense('migrate');
                     $model->managerId = $oldModel->user_id;
                     $model->companyId = $oldModel->customer_id;
                     $model->projectId = $oldModel->project_id;
                     $model->invoiceId = $oldModel->invoice_id;
                     $model->expenseDate = $expenseDateNotSet ? null : MDate::formatToDb($oldModel->expense_date, 'date');
                     $model->amount = $oldModel->amount;
                     $model->billToCompany = $billToCompany[$oldModel->bill_to_customer];
                     $model->content = $oldModel->note . "\n" . '[from migration]';
                     $model->contentMarkup = 'text';
                     $model->createTime = strtotime($oldModel->last);
                     $model->id = $oldModel->id;
                     if ($model->save()) {
                         $i++;
                     }
                     $j++;
                 }
                 $message .= $i . ' of ' . $j . ' expenses have been migrated.<br/>';
             }
         }
         // last message line
         $message .= 'done';
     }
     $this->render($this->action->id, array('message' => $message));
 }