public static function registre($fixr_id, $fdm2_ref, $fdm2_name, $fdm3_ref, $fdm3_name) { //get fixr record $fixr = FixrFiitXRef::model()->findByPk($fixr_id); if (empty($fixr->fixr_period_fret_id)) { return; } //found fret record - definitiom if (empty($fixr->fixrPeriodFret)) { return; } $period_model = $fixr->fixrPeriodFret->fret_model; $period_model_fixr_field = $fixr->fixrPeriodFret->fret_model_fixr_id_field; //get period $attributes = array($period_model_fixr_field => $fixr->fixr_id); //$fped = FpedPeriodDate::model()->findByAttributes($attributes); $period = call_user_func(array($period_model, 'model'))->findByAttributes($attributes); if (empty($period)) { return; } //save dim data $fdda = FddaDimData::findByFixrId($fixr->fixr_id); $fdda->fdda_fret_id = $fixr->fixr_position_fret_id; $fdda->setFdm2Id($fdm2_ref, $fdm2_name); $fdda->setFdm3Id($fdm3_ref, $fdm3_name); $fdda->fdda_date_from = $period->getFddaDateFrom(); $fdda->fdda_date_to = $period->getFddaDateTo(); $fdda->save(); }
public function beforeSave() { //validate rigts to record if (!$this->isNewRecord && !FpeoPeriodOdo::model()->findByPk($this->primaryKey)) { return false; } //get fixr for truck $fixr = FixrFiitXRef::model()->findByPk($this->fpeo_fixr_id); if (!$fixr) { $this->addError('fpeo_id', 'Can not find fixr record'); return false; } //found fret record - definitiom if (empty($fixr->fixrPositionFret)) { $this->addError('fpeo_id', 'No defined position'); return false; } $position_model = $fixr->fixrPositionFret->fret_model; $position_model_fixr_field = $fixr->fixrPositionFret->fret_model_fixr_id_field; //process position model $position = new $position_model(); $position_data = $position->findByAttributes(array($position_model_fixr_field => $this->fpeo_fixr_id)); if (empty($fixr->fixrPositionFret)) { $this->addError('fpeo_id', 'No found position data'); return false; } //find in position model vtrc_id - truck field $vtrc_id = false; foreach ($position_data->attributes as $col_name => $col_value) { if (substr($col_name, -7) == 'vtrc_id') { $vtrc_id = $col_value; break; } } if (!$vtrc_id) { $this->addError('fpeo_id', 'In position data no exist vtrc_id columns'); return false; } //get nearest odometer reading by date $vodo = VodoOdometer::getOdoByDate($vtrc_id, $this->fpeo_start_date); if (!$vodo) { $this->addError('fpeo_id', 'No found odometer readings for car'); return false; } //get data from odometer reading $this->fpeo_vodo_id = $vodo->vodo_id; $this->fpeo_start_abs_odo = $vodo->vodo_abs_odo; $this->fpeo_end_abs_odo = $vodo->vodo_abs_odo + $this->fpeo_distance; //end date $vtrc = VtrcTruck::model()->findByPk($vtrc_id); if (empty($vtrc->vtrc_year_mileage)) { $this->addError('fpeo_id', 'Pleas set for truc Yearly Run'); return false; } $sql_expr = new CDbExpression("ADDDATE(:date,:days)"); $sql_expr->params = array(':date' => $this->fpeo_start_date, ':days' => round($this->fpeo_distance / $vtrc->vtrc_year_mileage * 365)); $this->fpeo_end_date = $sql_expr; return parent::beforeSave(); }
/** * create record with default values * @param type $fiit_id * @return boolean * @throws CHttpException */ public function addRecord($fiit_id) { $fiit = FiitInvoiceItem::model()->findByPk($fiit_id); if (!$fiit) { throw new CHttpException(400, 'Invalid fiit_id value: ' . $fiit_id); } //calculate amt $sql = " \n SELECT \n SUM(fixr_amt) as amt_sum \n FROM \n fixr_fiit_x_ref \n WHERE \n fixr_fiit_id = " . $fiit_id; $fixr_sum = Yii::app()->db->createCommand($sql)->queryScalar(); //create fixr record $model = new FixrFiitXRef(); $model->fixr_fiit_id = $fiit_id; $model->fixr_fcrn_date = $fiit->fiitFinv->finv_date; $model->fixr_fcrn_id = $fiit->fiitFinv->finv_fcrn_id; $model->fixr_base_fcrn_id = $fiit->fiitFinv->finv_basic_fcrn_id; $model->fixr_amt = $fiit->fiit_amt - $fixr_sum; //save try { if ($model->save()) { return TRUE; } else { throw new CHttpException(500, var_export($model->getErrors())); } } catch (Exception $e) { throw new CHttpException(500, $e->getMessage()); } }
public function loadModel($id) { $m = FixrFiitXRef::model(); // apply scope, if available $scopes = $m->scopes(); if (isset($scopes[$this->scope])) { $m->{$this->scope}(); } $model = $m->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('D2fixrModule.crud', 'The requested page does not exist.')); } return $model; }
?> <?php //$this->widget("TbBreadcrumbs", array("links" => $this->breadcrumbs)) ?> <div class="clearfix"> <div class="btn-toolbar pull-left"> <div class="btn-group"> <?php $this->widget('bootstrap.widgets.TbButton', array('label' => Yii::t('D2fixrModule.crud', 'Create'), 'icon' => 'icon-plus', 'size' => 'large', 'type' => 'success', 'url' => array('create'), 'visible' => Yii::app()->user->checkAccess('D2finv.FpedPeriodDate.*') || Yii::app()->user->checkAccess('D2finv.FpedPeriodDate.Create'))); ?> </div> <div class="btn-group"> <h1> <i class=""></i> <?php echo Yii::t('D2fixrModule.model', 'Fped Period Dates'); ?> </h1> </div> </div> </div> <?php Yii::beginProfile('FpedPeriodDate.view.grid'); ?> <?php $this->widget('TbGridView', array('id' => 'fped-period-date-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'template' => '{summary}{pager}{items}{pager}', 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array(array('class' => 'CLinkColumn', 'header' => '', 'labelExpression' => '$data->itemLabel', 'urlExpression' => 'Yii::app()->controller->createUrl("view", array("fped_id" => $data["fped_id"]))'), array('class' => 'editable.EditableColumn', 'name' => 'fped_id', 'editable' => array('url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fped_fixr_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'), 'source' => CHtml::listData(FixrFiitXRef::model()->findAll(array('limit' => 1000)), 'fixr_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fped_start_date', 'editable' => array('type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fped_end_date', 'editable' => array('type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fped_month', 'editable' => array('type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'))), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'Yii::app()->user->checkAccess("D2finv.FpedPeriodDate.View")'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'Yii::app()->user->checkAccess("D2finv.FpedPeriodDate.Delete")')), 'viewButtonUrl' => 'Yii::app()->controller->createUrl("view", array("fped_id" => $data->fped_id))', 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("delete", array("fped_id" => $data->fped_id))', 'viewButtonOptions' => array('data-toggle' => 'tooltip'), 'deleteButtonOptions' => array('data-toggle' => 'tooltip'))))); Yii::endProfile('FpedPeriodDate.view.grid');
<td class="numeric-column"><?php echo $fiit->fiit_amt; ?> </td> </tr> <tr> <td colspan="5" class="rel_grid-sub"> <h3 class="rel_grid-sub"> <?php $sub_grid_id = 'fixr-grid-' . $fiit->primaryKey; $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'ajaxButton', 'type' => 'primary', 'size' => 'mini', 'icon' => 'icon-plus', 'url' => array('//d2fixr/fixrFiitXRef/ajaxCreate', 'field' => 'fixr_fiit_id', 'value' => $fiit->primaryKey, 'ajax' => $sub_grid_id), 'ajaxOptions' => array('success' => 'function(html) {$.fn.yiiGridView.update(\'' . $sub_grid_id . '\');}'), 'htmlOptions' => array('title' => Yii::t('D2fixrModule.crud', 'Add new record'), 'data-toggle' => 'tooltip'))); ?> </h3> <?php if (empty($fiit->fixrFiitXRefs)) { $model = new FixrFiitXRef(); $model->addRecord($fiit->primaryKey); unset($model); } $model = new FixrFiitXRef(); $model->fixr_fiit_id = $fiit->primaryKey; $this->renderPartial('_fixr_grid', array('model' => $model, 'sub_grid_id' => $sub_grid_id)); ?> </td> </tr> <?php } ?> </tbody>
'); } if (!$ajax || $ajax == 'fixr-fiit-xref-grid') { Yii::beginProfile('fixr_fret_id.view.grid'); ?> <h3 class="rel_grid"> <?php echo Yii::t('D2finvModule.model', 'Fixr Fiit Xref'); ?> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'ajaxButton', 'type' => 'primary', 'size' => 'mini', 'icon' => 'icon-plus', 'url' => array('//d2finv/fixrFiitXRef/ajaxCreate', 'field' => 'fixr_fret_id', 'value' => $modelMain->primaryKey, 'ajax' => 'fixr-fiit-xref-grid'), 'ajaxOptions' => array('success' => 'function(html) {$.fn.yiiGridView.update(\'fixr-fiit-xref-grid\');}'), 'htmlOptions' => array('title' => Yii::t('D2finvModule.crud', 'Add new record'), 'data-toggle' => 'tooltip'))); ?> </h3> <?php if (empty($modelMain->fixrFiitXRefs)) { $model = new FixrFiitXRef(); $model->fixr_fret_id = $modelMain->primaryKey; $model->save(); unset($model); } $model = new FixrFiitXRef(); $model->fixr_fret_id = $modelMain->primaryKey; // render grid view $this->widget('TbGridView', array('id' => 'fixr-fiit-xref-grid', 'dataProvider' => $model->search(), 'template' => '{summary}{items}', 'summaryText' => ' ', 'htmlOptions' => array('class' => 'rel-grid-view'), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'fixr_fiit_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'), 'source' => CHtml::listData(FiitInvoiceItem::model()->findAll(array('limit' => 1000)), 'fiit_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fixr_ref_id', 'editable' => array('url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fuxr_fcrn_date', 'editable' => array('type' => 'date', 'url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fuxr_fcrn_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'), 'source' => CHtml::listData(FcrnCurrency::model()->findAll(array('limit' => 1000)), 'fcrn_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fuxr_amt', 'editable' => array('url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fuxr_base_fcrn_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'), 'source' => CHtml::listData(FcrnCurrency::model()->findAll(array('limit' => 1000)), 'fcrn_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fixr_base_amt', 'editable' => array('url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fixr_start_date', 'editable' => array('type' => 'date', 'url' => $this->createUrl('//d2finv/fixrFiitXRef/editableSaver'))), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'FALSE'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'Yii::app()->user->checkAccess("D2finv.FretRefType.DeletefixrFiitXRefs")')), 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("/d2finv/fixrFiitXRef/delete", array("fixr_id" => $data->fixr_id))', 'deleteButtonOptions' => array('data-toggle' => 'tooltip'))))); ?> <?php Yii::endProfile('FixrFiitXRef.view.grid'); }
<div class="row"> <div class="span12"> <h2> <?php echo Yii::t('D2fixrModule.crud', 'Data'); ?> <small> #<?php echo $model->fped_id; ?> </small> </h2> <?php $this->widget('TbDetailView', array('data' => $model, 'attributes' => array(array('name' => 'fped_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'attribute' => 'fped_id', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver')), true)), array('name' => 'fped_fixr_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'select', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'), 'source' => CHtml::listData(FixrFiitXRef::model()->findAll(array('limit' => 1000)), 'fixr_id', 'itemLabel'), 'attribute' => 'fped_fixr_id'), true)), array('name' => 'fped_start_date', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'), 'attribute' => 'fped_start_date'), true)), array('name' => 'fped_end_date', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'), 'attribute' => 'fped_end_date'), true)), array('name' => 'fped_month', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'date', 'url' => $this->createUrl('/d2finv/fpedPeriodDate/editableSaver'), 'attribute' => 'fped_month'), true))))); ?> </div> </div> <div class="row"> <div class="span12"> <div class="well"> <?php $this->renderPartial('_view-relations_grids', array('modelMain' => $model, 'ajax' => false)); ?> </div> </div> </div>
<div class="row"> <div class="span12"> <h2> <?php echo Yii::t('TrucksModule.crud_static', 'Data'); ?> <small> #<?php echo $model->vtdc_id; ?> </small> </h2> <?php $this->widget('TbDetailView', array('data' => $model, 'attributes' => array(array('name' => 'vtdc_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'attribute' => 'vtdc_id', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver')), true)), array('name' => 'vtdc_vtrc_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'select', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver'), 'source' => CHtml::listData(VtrcTruck::model()->findAll(array('limit' => 1000)), 'vtrc_id', 'itemLabel'), 'attribute' => 'vtdc_vtrc_id'), true)), array('name' => 'vtdc_vtdt_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'select', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver'), 'source' => CHtml::listData(VtdtTruckDocType::model()->findAll(array('limit' => 1000)), 'vtdt_id', 'itemLabel'), 'attribute' => 'vtdc_vtdt_id'), true)), array('name' => 'vtdc_fixr_id', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'select', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver'), 'source' => CHtml::listData(FixrFiitXRef::model()->findAll(array('limit' => 1000)), 'fixr_id', 'itemLabel'), 'attribute' => 'vtdc_fixr_id'), true)), array('name' => 'vtdc_number', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'attribute' => 'vtdc_number', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver')), true)), array('name' => 'vtdc_issue_date', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'date', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver'), 'attribute' => 'vtdc_issue_date'), true)), array('name' => 'vtdc_expire_date', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'type' => 'date', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver'), 'attribute' => 'vtdc_expire_date'), true)), array('name' => 'vtdc_notes', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'attribute' => 'vtdc_notes', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver')), true)), array('name' => 'vtdc_deleted', 'type' => 'raw', 'value' => $this->widget('EditableField', array('model' => $model, 'attribute' => 'vtdc_deleted', 'url' => $this->createUrl('/trucks/vtdcTruckDoc/editableSaver')), true))))); ?> </div> </div> <div class="row"> <div class="span12"> <?php $this->renderPartial('_view-relations_grids', array('modelMain' => $model, 'ajax' => false)); ?> </div> </div> <?php echo $cancel_buton;