public function actionIndex() { $model = $this->findModel(Yii::$app->user->id); $laborTally = []; $laborTally['Hourly'] = Labor::find()->hourly()->tech($model->contact_id)->total(); $laborTally['Proactive'] = Labor::find()->hourly(false)->tech($model->contact_id)->total(); $openTickets = new ActiveDataProvider(['query' => Ticket::find()->active()->joinWith('invoice.location.client', false), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['status_id' => SORT_ASC, 'id' => SORT_ASC]]]); $openTickets->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; Url::remember(); return $this->render('index', ['model' => $model, 'laborTally' => $laborTally, 'openTickets' => $openTickets]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Invoice::find()->andWhere(['not', ['status_id' => Invoice::STATUS_CURRENT]])->with('location.client'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([Invoice::tableName() . '.location_id' => $this->location_id, Invoice::tableName() . '.status_id' => $this->status_id]); $query->andFilterWhere(['like', Invoice::tableName() . '.id', (int) $this->id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ticket::find()->current()->joinWith(['invoice.location', 'invoice.location.client']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50], 'sort' => ['defaultOrder' => ['status_id' => SORT_ASC]]]); $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]]; $dataProvider->sort->attributes['status_id'] = ['asc' => [Ticket::tableName() . '.status_id' => SORT_DESC], 'desc' => [Ticket::tableName() . '.status_id' => SORT_ASC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([Location::tableName() . '.id' => $this->location_id, Ticket::tableName() . '.status_id' => $this->status_id, Ticket::tableName() . '.priority_id' => $this->priority_id, Ticket::tableName() . '.bill_type_id' => $this->bill_type_id]); $query->andFilterWhere(['like', Ticket::tableName() . '.id', $this->id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Location::find()->joinWith('client')->andWhere([Client::tableName() . '.active' => true]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['client_id' => SORT_ASC, 'name' => SORT_ASC]]]); $dataProvider->sort->attributes['client_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC]]; if (Yii::$app->user->can('Accounting')) { $query->joinWith('lastInvoice'); $dataProvider->sort->attributes['lastInvoiceStatus'] = ['asc' => [Invoice::tableName() . '.status_id' => SORT_ASC], 'desc' => [Invoice::tableName() . '.status_id' => SORT_DESC]]; } $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([self::tableName() . '.client_id' => $this->client_id, self::tableName() . '.proactive' => $this->proactive, self::tableName() . '.active' => $this->active]); if (Yii::$app->user->can('Accounting')) { $query->andFilterWhere([Invoice::tableName() . '.status_id' => $this->lastInvoiceStatus]); } $query->andFilterWhere(['or', ['like', self::tableName() . '.name', $this->name], ['like', Client::tableName() . '.name', $this->name]])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
public function actionAjaxBillType() { Yii::$app->response->format = Response::FORMAT_JSON; if (!empty($parents = Yii::$app->request->post('depdrop_parents'))) { /** @var Location $location */ $location = Location::findOne($parents[0]); $output = []; foreach (Ticket::$BILL_TYPE_SELECT as $bill_type_id => $bill_type) { $option = ['id' => (string) $bill_type_id, 'name' => $bill_type]; if ($bill_type_id == Ticket::BILL_PROACTIVE) { $option['options'] = ['disabled' => !($location && $location->proactive)]; } $output[] = $option; } return ['output' => $output, 'selected' => (string) ($location ? $location->proactive : Ticket::BILL_HOURLY)]; } return ['output' => '']; }
<?php use yii\helpers\Html; use yii\grid\GridView; use yii\widgets\Pjax; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\InvoiceSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Invoices'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="invoice-index"> <h3><?php echo Html::encode($this->title); ?> </h3> <?php Pjax::begin(['id' => 'invoices-pjax', 'linkSelector' => '#invoices-pjax a[data-sort]', 'enablePushState' => !Yii::$app->request->isAjax]); ?> <?php echo GridView::widget(['id' => 'invoices-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'value' => 'idNum'], ['attribute' => 'location_id', 'value' => 'location.fullName', 'filter' => \yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName')], ['attribute' => 'status_id', 'value' => 'status', 'filter' => $searchModel::$STATUSES], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}', 'buttonOptions' => ['class' => 'showModalButton']]]]); ?> <?php Pjax::end(); ?> </div>
/** * @param integer $client_id * @return $this */ public function client($client_id) { $this->joinWith(['invoice.location'])->andWhere([Location::tableName() . '.client_id' => $client_id]); return $this; }
public function saveLocations($locations) { $user = User::thisUser(); Location::deleteAll(['entity' => self::THIS_ENTITY, 'entity_id' => $this->id]); if (is_array($locations)) { $locations = array_slice($locations, 0, self::MAX_LOCATION_SCHOOL); foreach ($locations as $location) { $newLocation = new Location(); $newLocation->user_id = $user->id; $newLocation->entity = self::THIS_ENTITY; $newLocation->entity_id = $this->id; $newLocation->title = $location['title']; $newLocation->description = $location['description']; $newLocation->lat = $location['lat']; $newLocation->lng = $location['lng']; $newLocation->zoom = $location['zoom']; $newLocation->type = $location['type']; $newLocation->save(); } } }
/** * @inheritdoc */ public function rules() { return [[['invoice_id', 'title'], 'required', 'on' => self::SCENARIO_DEFAULT], [['invoice_id', 'priority_id', 'bill_type_id', 'task_id'], 'integer'], [['title'], 'string', 'max' => 100], [['description'], 'string'], [['priority_id'], 'in', 'range' => array_keys(self::$PRIORITIES)], [['bill_type_id'], 'in', 'range' => array_keys(self::$BILL_TYPES)], [['invoice_id'], 'exist', 'targetClass' => Location::className(), 'targetAttribute' => 'id'], [['dup_id'], 'required', 'on' => self::SCENARIO_DUPLICATE], [['dup_id'], 'exist', 'targetClass' => self::className(), 'targetAttribute' => 'id', 'on' => self::SCENARIO_DUPLICATE]]; }
/** * Finds the Location model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Location the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Location::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @inheritdoc */ public function rules() { return [[['invoice_id', 'tech_id', 'start_time', 'duration', 'ticketIds'], 'required', 'on' => self::SCENARIO_DEFAULT], [['invoice_id', 'start_time', 'duration'], 'required', 'on' => self::SCENARIO_REMOTE], [['invoice_id', 'tech_id'], 'integer'], [['onSite'], 'boolean'], [['start_time'], 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'], [['duration'], 'integer', 'min' => '15'], [['description'], 'string'], [['ticketIds'], 'each', 'rule' => ['integer']], [['invoice_id'], 'exist', 'targetClass' => Location::className(), 'targetAttribute' => 'id'], [['tech_id'], 'exist', 'targetClass' => Tech::className(), 'targetAttribute' => 'contact_id'], [['ticketIds'], 'each', 'rule' => ['exist', 'targetClass' => Ticket::className(), 'targetAttribute' => 'id']]]; }
/** * @return LocationQuery */ public function getLocation() { return $this->hasOne(Location::className(), ['id' => 'location_id'])->inverseOf('invoices'); }
$this->title = 'Tickets'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="ticket-index"> <p class="pull-right"> <?php echo Html::a('<span class="glyphicon glyphicon-map-marker"></span> Map', ['map'], ['class' => 'btn btn-info btn-xs']); ?> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> New Ticket', ['create'], ['class' => 'btn btn-success btn-xs showModalButton']); ?> </p> <h3><?php echo Html::encode($this->title); ?> </h3> <?php Pjax::begin(['id' => 'tickets-pjax', 'linkSelector' => '#tickets-pjax a[data-sort]', 'enablePushState' => !Yii::$app->request->isAjax]); ?> <?php echo GridView::widget(['id' => 'tickets-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'location_id', 'label' => 'Location', 'value' => 'invoice.location.fullName', 'filter' => \yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName')], ['attribute' => 'id', 'format' => 'raw', 'value' => function ($m) { /** @var \common\models\Ticket $m */ return Html::a($m->fullName, ['view', 'id' => $m->id]); }, 'headerOptions' => ['class' => 'primary'], 'filterInputOptions' => ['placeholder' => '(TT# or Title)', 'class' => 'form-control']], ['attribute' => 'status_id', 'value' => 'status', 'filter' => $searchModel::$STATUSES], ['attribute' => 'priority_id', 'value' => 'priority', 'filter' => $searchModel::$PRIORITIES], ['attribute' => 'bill_type_id', 'value' => 'billType', 'filter' => $searchModel::$BILL_TYPE_SELECT], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}', 'buttonOptions' => ['class' => 'showModalButton']]]]); ?> <?php Pjax::end(); ?> </div>
<div class="schedule-form"> <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?> <div> <?php echo $form->errorSummary([$model, $note, $ticket]); ?> <?php $this->beginBlock('main'); ?> <p> <?php echo $form->field($model, 'invoice_id')->widget(Select2::className(), ['data' => yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), 'options' => ['placeholder' => '', 'id' => 'location-select'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($note, 'body')->label('Notes')->textarea(['rows' => 12]); ?> <?php echo $form->field($model, 'start_time')->widget(DateTimePicker::className(), ['disabled' => $remote, 'pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:00', 'startDate' => date('Y-m-d', strtotime('-1 month')), 'initialDate' => date('Y-m-d H:00:00', strtotime('+1 hour')), 'todayHighlight' => true, 'showMeridian' => true, 'minuteStep' => 15, 'autoclose' => true]]); ?> <?php echo $form->field($model, 'duration')->input('number', ['min' => 15, 'step' => 5]); ?> </p>
$form = ActiveForm::begin(['layout' => 'horizontal']); ?> <div> <?php echo $form->errorSummary($model); ?> <?php $this->beginBlock('main'); ?> <p> <?php /*= $form->field($model, 'invoice_id')->dropDownList(yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), ['id' => 'location-select','prompt' => '']) */ ?> <?php echo $form->field($model, 'invoice_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), 'options' => ['prompt' => '', 'id' => 'location-select']]); ?> <?php echo $form->field($model, 'tech_id')->dropDownList(yii\helpers\ArrayHelper::map(\common\models\Tech::find()->contact()->all(), 'contact_id', 'contact.name'), ['prompt' => '']); ?> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> New Ticket', ['ticket/create', 'close' => true, 'Ticket' => ['invoice_id' => $model->invoice_id]], ['id' => 'new-ticket-btn', 'class' => 'btn btn-success btn-xs pull-right', 'target' => '_blank']); ?> <?php echo Html::button('<span class="glyphicon glyphicon-refresh"></span>', ['class' => 'btn btn-default btn-xs pull-right', 'title' => 'Refresh tickets for selected location', 'onclick' => '$("#location-select").trigger("depdrop.change")']); ?> <?php echo $form->field($model, 'ticketIds')->widget(\kartik\depdrop\DepDrop::className(), ['type' => \kartik\depdrop\DepDrop::TYPE_SELECT2, 'data' => yii\helpers\ArrayHelper::map(\common\models\Ticket::find()->location($model->invoice_id)->open()->all(), 'id', 'fullName'), 'options' => ['multiple' => true], 'select2Options' => ['pluginOptions' => ['allowClear' => true]], 'pluginOptions' => ['depends' => ['location-select'], 'url' => Url::to(['/location/ajax-tickets']), 'placeholder' => false], 'pluginEvents' => ['depdrop.change' => 'function(event, id, value, count) { console.log(event, id, value);
/** * @return LocationQuery */ public function getLocations() { return $this->hasMany(Location::className(), ['client_id' => 'client_id'])->inverseOf('contacts'); }
echo Lang::t('main/dialogs', 'modalAddLocation_title'); ?> </h4> </div> <div class="modal-body"> <?php $form = ActiveForm::begin(['id' => 'locationAddForm']); echo $form->field($location, 'lat')->label(false)->hiddenInput(); echo $form->field($location, 'lng')->label(false)->hiddenInput(); echo $form->field($location, 'zoom')->label(false)->hiddenInput(); if (!empty($setLocationType)) { $location->type = $setLocationType; echo $form->field($location, 'type')->label(false)->hiddenInput(); echo Html::hiddenInput('type_local', Lang::t('main/location', 'school'), ['id' => 'location-type-local']); } else { echo $form->field($location, 'type')->dropDownList(Location::getLocationTypeLocal()); } echo $form->field($location, 'title')->label(Lang::t('main/dialogs', 'modalAddLocation_fieldTitle')); echo $form->field($location, 'description')->textarea(['maxlength' => 255])->label(Lang::t('main/dialogs', 'modalAddLocation_fieldDescription')); ActiveForm::end(); ?> <div id="map"></div> </div> <div class="modal-footer"> <button type="button" id="btnAddLocation" class="btn btn-primary" data-dismiss="modal"><?php echo Lang::t('main/dialogs', 'modalAddLocation_btn'); ?> </button> <button type="button" id="btnEditLocation" class="btn btn-primary" data-dismiss="modal"><?php echo Lang::t('main/dialogs', 'modalEditLocation_btn'); ?>