/** * Displays a single Ticket model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $notes = new ActiveDataProvider(['query' => $model->getNotes()->complete()->with(['author', 'attachment']), 'pagination' => false, 'sort' => ['attributes' => ['public', 'created_at'], 'defaultOrder' => ['created_at' => SORT_ASC]]]); $labors = new ActiveDataProvider(['query' => $model->getLabors()->joinWith('schedule.tech')->with(['note', 'schedule.travel'])->orderBy(Schedule::tableName() . '.start_time'), 'key' => 'schedule_id', 'pagination' => false, 'sort' => ['attributes' => ['schedule.start_time' => ['asc' => [Schedule::tableName() . '.start_time' => SORT_ASC], 'desc' => [Schedule::tableName() . '.start_time' => SORT_DESC]], 'schedule.tech_id' => ['asc' => [Contact::tableName() . '.name' => SORT_ASC], 'desc' => [Contact::tableName() . '.name' => SORT_DESC]]], 'defaultOrder' => ['schedule.start_time' => SORT_DESC]]]); $purchases = new ActiveDataProvider(['query' => $model->getPurchasedItems(), 'pagination' => false, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]); if (Yii::$app->request->isAjax) { return $this->renderAjax('view', ['model' => $model, 'notes' => $notes, 'labors' => $labors, 'purchases' => $purchases]); } Url::remember(); return $this->render('view', ['model' => $model, 'notes' => $notes, 'labors' => $labors, 'purchases' => $purchases]); }
/** * Displays a single Invoice model. * @param integer $id * @throws \yii\web\NotFoundHttpException * @return mixed */ public function actionView($id) { $model = $this->findModel($id); if ($model->status_id == $model::STATUS_CURRENT) { throw new NotFoundHttpException("The selected invoice cannot be displayed"); } $tickets = new ActiveDataProvider(['query' => $model->getTickets()->closed()->totals(), 'pagination' => false, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]); $travels = new ActiveDataProvider(['query' => $model->getTravels()->fee()->joinWith('schedule.tech'), 'pagination' => false, 'sort' => ['attributes' => ['schedule.start_time' => ['asc' => [Schedule::tableName() . '.start_time' => SORT_ASC], 'desc' => [Schedule::tableName() . '.start_time' => SORT_DESC]]], 'defaultOrder' => ['schedule.start_time' => SORT_ASC]]]); if (Yii::$app->request->isAjax) { return $this->renderAjax('view', ['model' => $model, 'tickets' => $tickets, 'travels' => $travels, 'laborTotal' => Labor::find()->ticket($tickets->keys)->total(), 'billableLaborTotal' => Labor::find()->ticket($tickets->keys)->hourly()->total(true), 'purchaseTotal' => PurchasedItem::find()->ticket($tickets->keys)->total(), 'travelFeeTotal' => Travel::find()->invoice($id)->totalFee(), 'travelMilesTotal' => Travel::find()->invoice($id)->totalMiles()]); } Url::remember(); return $this->render('view', ['model' => $model, 'tickets' => $tickets, 'travels' => $travels, 'laborTotal' => Labor::find()->ticket($tickets->keys)->total(), 'billableLaborTotal' => Labor::find()->ticket($tickets->keys)->hourly()->total(true), 'purchaseTotal' => PurchasedItem::find()->ticket($tickets->keys)->total(), 'travelFeeTotal' => Travel::find()->invoice($id)->totalFee(), 'travelMilesTotal' => Travel::find()->invoice($id)->totalMiles()]); }
/** * @return $this */ public function nextScheduled() { $this->joinWith('notes.labor.schedule', false)->groupBy('id')->andWhere('COALESCE(' . Schedule::tableName() . '.start_time > NOW(), true)')->addSelect([Ticket::tableName() . '.*', 'MIN(' . Schedule::tableName() . '.[[start_time]]) AS [[nextScheduled]]']); return $this; }
/** * Lists all tickets and travels for currentInvoice model. * @param integer $id * @return mixed */ public function actionInvoice($id) { $model = $this->findModel($id); $tickets = new ActiveDataProvider(['query' => $model->currentInvoice->getTickets()->closed(true)->totals(), 'pagination' => false, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]); $travels = new ActiveDataProvider(['query' => $model->currentInvoice->getTravels()->before()->fee()->with('schedule.tech'), 'key' => 'schedule_id', 'pagination' => false, 'sort' => ['attributes' => ['schedule.start_time' => ['asc' => [Schedule::tableName() . '.start_time' => SORT_ASC], 'desc' => [Schedule::tableName() . '.start_time' => SORT_DESC]]], 'defaultOrder' => ['schedule.start_time' => SORT_ASC]]]); Url::remember(); return $this->render('invoice', ['model' => $model, 'tickets' => $tickets, 'travels' => $travels, 'laborTotal' => Labor::find()->ticket($tickets->keys)->total(), 'billableLaborTotal' => Labor::find()->ticket($tickets->keys)->hourly()->total(true), 'purchaseTotal' => PurchasedItem::find()->ticket($tickets->keys)->total(), 'travelFeeTotal' => Travel::find()->invoice($id)->before()->totalFee(), 'travelMilesTotal' => Travel::find()->invoice($id)->before()->totalMiles()]); }