/** * @param integer $id * @return mixed * @throws NotFoundHttpException */ public function actionTravel($id) { /** @var \common\models\Travel $model */ if (($model = Travel::findOne($id)) == null) { throw new NotFoundHttpException('The requested page does not exist.'); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(Url::previous()); } if (Yii::$app->request->isAjax) { return $this->renderAjax('travel', ['model' => $model]); } return $this->render('travel', ['model' => $model]); }
/** * @return TravelQuery */ public function getTravel() { return $this->hasOne(Travel::className(), ['schedule_id' => 'id'])->inverseOf('schedule'); }
/** * 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()]); }
/** * @return TravelQuery */ public function getTravels() { return $this->hasMany(Travel::className(), ['schedule_id' => 'id'])->via('schedules')->inverseOf('invoice'); }
public function actionTest($id) { $model = self::findModel($id); $tickets = new ActiveDataProvider(['query' => $model->getTickets()->closed()->totals()->with(['notes.labor', 'notes.author']), 'pagination' => false, 'sort' => false]); $travels = new ActiveDataProvider(['query' => $model->getTravels()->fee()->with('schedule.tech'), 'pagination' => false, 'sort' => false]); $mPDF = new Pdf(['destination' => Pdf::DEST_BROWSER]); $mPDF->content = $this->renderPartial('_pdf-template', ['model' => $model, 'tickets' => $tickets, 'travels' => $travels, 'billableLaborTotal' => Labor::find()->ticket($tickets->keys)->hourly()->total(true), 'purchaseTotal' => PurchasedItem::find()->ticket($tickets->keys)->total(), 'travelFeeTotal' => Travel::find()->invoice($id)->totalFee(), 'mPDF' => $mPDF]); Yii::$app->response->format = Response::FORMAT_RAW; Yii::$app->response->headers->set('Content-Type', 'application/pdf'); return $mPDF->render(); }