<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"> </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"> </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"> </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*/
/** * Shows a particular model. */ public function actionShow() { if (!User::isClient() && !User::isManager() && !User::isAdministrator()) { // not enough rights MUserFlash::setTopError(Yii::t('hint', 'We are sorry, but you don\'t have enough rights to browse companies.')); $this->redirect($this->getGotoUrl()); } if (isset($_GET['my'])) { // show client's company if (Yii::app()->user->isGuest) { // guest may not have any company MUserFlash::setTopError(Yii::t('hint', 'Please authorize to view your company.')); $this->redirect($this->getGotoUrl()); } if (($user2Company = User2Company::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'position' => Company::OWNER), array('order' => "`companyPriority` ASC"))) !== null) { $id = $user2Company->companyId; } else { // user is not an owner yet MUserFlash::setTopError(Yii::t('hint', 'We are sorry, but you are not the owner of any company yet.')); $this->redirect($this->getGotoUrl()); } } else { // get id from the url $id = isset($_GET['id']) ? $_GET['id'] : 0; } // load model $with = array('allUser'); /*if(User::isClient()) $with[]='allUser2Company';*/ $model = $this->loadModel(array('id' => $id, 'with' => $with)); // may member view this record? if (User::isClient()) { /*$allOwner=array(); foreach($model->allUser2Company as $user2Company) { if($user2Company->position===Company::OWNER) $allOwner[]=$user2Company->userId; } if(!in_array(Yii::app()->user->id,$allOwner))*/ if (!$model->isOwner()) { MUserFlash::setTopError(Yii::t('hint', 'We are sorry, but you don\'t have enough rights to view the company record number {id}.', array('{id}' => MHtml::wrapInTag($model->id, 'strong')))); $this->redirect($this->getGotoUrl()); } } // FIXME: check is owner or manager or admin // transaction's payments $companyPayments = CompanyPayment::model()->findAllByAttributes(array('companyId' => $model->id), new CDbCriteria(array('order' => "`t`.`paymentDate` ASC, `t`.`id` ASC"))); // transaction's invoices $invoices = Invoice::model()->findAllByAttributes(array('companyId' => $model->id), new CDbCriteria(array('order' => "`t`.`invoiceDate` ASC, `t`.`id` ASC"))); // construct tmp array of all transactions. use time as index $array = array(); foreach ($companyPayments as $companyPayment) { $time = strtotime($companyPayment->paymentDate); while (array_key_exists($time, $array)) { $time++; } $array[$time] = array('date' => $companyPayment->paymentDate, 'credit' => $companyPayment->amount, 'number' => $companyPayment->paymentNumber, 'method' => $companyPayment->getAttributeView('paymentMethod'), 'id' => $companyPayment->id, 'controllerId' => 'companyPayment'); } foreach ($invoices as $invoice) { $time = strtotime($invoice->invoiceDate); while (array_key_exists($time, $array)) { $time++; } $array[$time] = array('date' => $invoice->invoiceDate, 'debit' => $invoice->amountTotal, 'id' => $invoice->id, 'controllerId' => 'invoice'); } // sort by index ksort($array); // construct transaction history array $transactions = array(); $balance = $debit = $credit = 0; foreach ($array as $row) { $d = isset($row['debit']) ? $row['debit'] : 0; $c = isset($row['credit']) ? $row['credit'] : 0; $balance = $balance - $d + $c; $debit += $d; $credit += $c; $transactions[] = array('date' => $row['date'], 'debit' => isset($row['debit']) ? $row['debit'] : null, 'credit' => isset($row['credit']) ? $row['credit'] : null, 'number' => isset($row['number']) ? $row['number'] : null, 'method' => isset($row['method']) ? $row['method'] : null, 'balance' => $balance, 'id' => $row['id'], 'controllerId' => $row['controllerId']); } // rows for the static grid $gridRows = array(); foreach ($transactions as $transaction) { $gridRows[] = array(array('align' => 'right', 'content' => CHtml::encode(MDate::format($transaction['date'], 'long', null)), 'title' => CHtml::encode(MDate::format($transaction['date'], 'full', null))), array('content' => CHtml::link($transaction['controllerId'] === 'invoice' ? Yii::t('link', 'Invoice {number}', array('{number}' => $transaction['number'] === null ? $transaction['id'] : $transaction['number'])) : Yii::t('link', 'Payment {number} ({method})', array('{number}' => $transaction['number'] === null ? $transaction['id'] : $transaction['number'], '{method}' => $transaction['method'])), array($transaction['controllerId'] . '/show', 'id' => $transaction['id']))), array('align' => 'right', 'content' => is_numeric($transaction['debit']) ? CHtml::encode(MCurrency::format($transaction['debit'])) : ''), array('align' => 'right', 'content' => is_numeric($transaction['credit']) ? CHtml::encode(MCurrency::format($transaction['credit'])) : ''), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($transaction['balance'])))); } // render the view file $this->render($this->action->id, array('model' => $model, 'debit' => $debit, 'credit' => $credit, 'balance' => $credit - $debit, 'gridRows' => $gridRows)); }
?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode($model->id); ?> </div> <div class="clear"> </div> </div> <div class="w3-detail-row"> <div class="w3-detail-row-label"><?php echo CHtml::encode($model->getAttributeLabel('content')); ?> </div> <div class="w3-detail-row-value"><?php echo CHtml::encode($model->content); ?> </div> <div class="clear"> </div> </div> </div> <?php if ($model->isOwner() || Yii::app()->user->checkAccess(User::MANAGER) || Yii::app()->user->checkAccess(User::ADMINISTRATOR)) { MUserFlash::setSidebarInfo(Yii::t('hint', 'Company transaction history is open for owner, manager and administrator only.')); ?> <div class="w3-between-boxes"> </div> <?php $this->widget('application.components.WGrid', array('displayButtonClose' => true, 'importantRowsBottom' => array(array(array('align' => 'right', 'colspan' => 2, 'content' => Yii::t('math', 'Total')), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($debit))), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($credit))), array('align' => 'right', 'content' => CHtml::encode(MCurrency::format($balance))))), 'maxRow' => count($gridRows), 'minRow' => count($gridRows) >= 1 ? 1 : 0, 'rows' => $gridRows, 'sColumns' => array(array('title' => Yii::t('t', 'Date')), array('title' => Yii::t('t', 'Description')), array('title' => Yii::t('payment', 'Debit')), array('title' => Yii::t('payment', 'Credit[accounting]')), array('title' => Yii::t('payment', 'Balance'))), 'sGridId' => 'w3TransactionGrid', 'title' => CHtml::encode(Yii::t('t', 'Transaction history')), 'totalRecords' => count($gridRows))); }