/** * @param Schedule $schedule * @return bool * @throws \yii\web\BadRequestHttpException */ public static function sendCalendarInvite($schedule) { if ($schedule->className() !== Schedule::className()) { throw new BadRequestHttpException('Invalid request'); } //Create Email Headers $mime_boundary = '----Meeting Booking----' . MD5(TIME()); $headers = "From: " . self::$from_name . " <" . self::$from_address . ">\n"; $headers .= "Reply-To: " . self::$from_name . " <" . self::$from_address . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"\n"; $headers .= "Content-class: urn:content-classes:calendarmessage\n"; //Create Email Body (HTML) $message = "--{$mime_boundary}\r\n"; $message .= "Content-Type: text/html; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "<html>\n"; $message .= "<body>\n"; $message .= '<p>' . $schedule->description . '</p>'; $message .= "<h4>Tickets:</h4>\n"; $message .= "<ul>\n"; foreach ($schedule->notes as $note) { $message .= '<li>' . Html::a($note->ticket->fullName, Url::base(true) . Url::to(['/ticket/view', 'id' => $note->ticket_id])) . "</li>\n"; } $message .= "</ul>\n"; $message .= '(' . Html::a('view calendar event', Url::to(['/schedule/view', 'id' => $schedule->id], true)) . ")\n"; $message .= "</body>\n"; $message .= "</html>\n"; $message .= "--{$mime_boundary}\r\n"; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST' . "\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= 'BEGIN:VCALENDAR' . "\r\n" . 'METHOD:REQUEST' . "\r\n" . 'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" . 'VERSION:2.0' . "\r\n" . 'BEGIN:VTIMEZONE' . "\r\n" . 'TZID:Pacific Standard Time' . "\r\n" . 'BEGIN:STANDARD' . "\r\n" . 'DTSTART:16010101T020000' . "\r\n" . 'TZOFFSETFROM:-0700' . "\r\n" . 'TZOFFSETTO:-0800' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" . 'END:STANDARD' . "\r\n" . 'BEGIN:DAYLIGHT' . "\r\n" . 'DTSTART:16010101T020000' . "\r\n" . 'TZOFFSETFROM:-0800' . "\r\n" . 'TZOFFSETTO:-0700' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" . 'END:DAYLIGHT' . "\r\n" . 'END:VTIMEZONE' . "\r\n" . 'BEGIN:VEVENT' . "\r\n" . 'ORGANIZER;CN="' . $schedule->createdBy->name . '":MAILTO:' . self::$from_address . "\r\n" . 'ATTENDEE;CN="' . $schedule->tech->name . '";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' . $schedule->tech->email . "\r\n" . 'LAST-MODIFIED:' . date("Ymd\\TGis") . "\r\n" . 'UID:' . date("Ymd\\TGis", strtotime($schedule->start_time)) . rand() . "@" . self::$domain . "\r\n" . 'DTSTAMP:' . date("Ymd\\TGis") . "\r\n" . 'DTSTART;TZID="Pacific Standard Time":' . date("Ymd\\THis", strtotime($schedule->start_time)) . "\r\n" . 'DTEND;TZID="Pacific Standard Time":' . date("Ymd\\THis", strtotime($schedule->endTime)) . "\r\n" . 'TRANSP:OPAQUE' . "\r\n" . 'SEQUENCE:1' . "\r\n" . 'SUMMARY:' . $schedule->invoice->location->fullName . "\r\n" . 'LOCATION:' . $schedule->invoice->location->address . "\r\n" . 'CLASS:PUBLIC' . "\r\n" . 'PRIORITY:5' . "\r\n" . 'BEGIN:VALARM' . "\r\n" . 'TRIGGER:-PT60M' . "\r\n" . 'ACTION:DISPLAY' . "\r\n" . 'DESCRIPTION:Reminder' . "\r\n" . 'END:VALARM' . "\r\n" . 'END:VEVENT' . "\r\n" . 'END:VCALENDAR' . "\r\n"; return self::send($schedule->tech->email, $schedule->invoice->location->fullName, $message, $headers); }
public function addEvent($title) { $event = new Schedule(); $event['title'] = $title; $event['start'] = $this->start; $event['end'] = $this->end; $event['create_at'] = $this->create_at; $event['own_id'] = $this->own_id; $event['color'] = $this->color; $event->save(); return $event['id']; }
public function actionAcceptReceivedSchedule($id) { $scheduleNotify = ScheduleNotification::findOne(['id' => $id]); $schedule = Schedule::findOne(['id' => $scheduleNotify['schedule_id']]); $newSchedule = new Schedule(); $newSchedule['title'] = $schedule['title']; $newSchedule['color'] = $schedule['color']; $newSchedule['start'] = $schedule['start']; $newSchedule['end'] = $schedule['end']; $newSchedule['create_at'] = $schedule['create_at']; $newSchedule['own_id'] = \Yii::$app->user->getId(); $newSchedule->save(); ScheduleNotification::deleteAll(['id' => $id]); $this->redirect('?r=schedule/create-event'); }
public function unscheduled() { // Get a list of all ticket IDs scheduled in the next 2 weeks $scheduled = Schedule::find()->joinWith('labors.note', false)->select(Note::tableName() . '.ticket_id')->between(new Expression('NOW()'), date('Y-m-d', strtotime('+14 days'))); // return tickets not in that list $this->andWhere(['not in', Ticket::tableName() . '.id', $scheduled])->joinWith('invoice.location.client')->orderBy([Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC, Ticket::tableName() . '.id' => SORT_ASC]); return $this; }
/** * 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]); }
public function actionDeleteUser() { $selection = (array) Yii::$app->request->post('selection'); foreach ($selection as $id) { if ($id != Yii::$app->params['adminId']) { User::deleteAll(['id' => $id]); Post::deleteAll(['user_id' => $id]); PostNotification::deleteAll(['action_id' => $id]); PostNotification::deleteAll(['receiver_id' => $id]); Comment::deleteAll(['user_id' => $id]); Like::deleteAll(['user_id' => $id]); Message::deleteAll(['sender_id' => $id]); Message::deleteAll(['receiver_id' => $id]); Relationship::deleteAll(['user_id_1' => $id]); Relationship::deleteAll(['user_id_2' => $id]); RelationshipNotification::deleteAll(['action_id' => $id]); RelationshipNotification::deleteAll(['receive_id' => $id]); Schedule::deleteAll(['own_id' => $id]); ScheduleNotification::deleteAll(['action_id' => $id]); ScheduleNotification::deleteAll(['receiver_id' => $id]); } } return $this->render('user-manage'); }
/** * Finds the Schedule model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Schedule the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Schedule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return ScheduleQuery */ public function getSchedule() { return $this->hasOne(Schedule::className(), ['id' => 'schedule_id'])->inverseOf('labors'); }
/** * @return ScheduleQuery */ public function getSchedules() { return $this->hasMany(Schedule::className(), ['tech_id' => 'contact_id']); }
public function afterSave($insert, $changedAttributes) { if ($insert || isset($changedAttributes['end_at'])) { Schedule::schedule($this); } parent::afterSave($insert, $changedAttributes); }
/** * @return ScheduleQuery */ public function getSchedules() { return $this->hasMany(Schedule::className(), ['invoice_id' => 'id'])->inverseOf('invoice'); }
<?php /** * Created by PhpStorm. * User: Nguyen * Date: 12/1/2015 * Time: 10:15 PM */ $schedule = \common\models\Schedule::findOne(['id' => $model['schedule_id']]); $actionUser = \common\models\User::findOne(['id' => $model['action_id']]); ?> <div class="row"> <div class="col-md-2"> </div> <div class="col-md-8"> <div class="box box-info"> <div class="box-header with-border"> <h3 class="box-title"><?php if ($actionUser['fullname'] != '') { echo $actionUser['fullname']; } else { echo $actionUser['username']; } ?> </h3> </div><!-- /.box-header --> <!-- form start --> <div class="box-body"> <p> <?php
<?php use common\models\Relationship; use kartik\datetime\DateTimePicker; use kartik\select2\Select2; $this->title = 'Lịch làm việc'; $this->params['breadcrumbs'][] = $this->title; $listE = \common\models\Schedule::find()->where(['own_id' => Yii::$app->user->getId()])->asArray()->all(); $events = array(); foreach ($listE as $item) { $event = new \yii2fullcalendar\models\Event(); $event->id = $item['id']; $event->title = $item['title']; $event->start = date($item['start']); $event->end = date($item['end']); $event->color = $item['color']; $events[] = $event; } $sql = 'SELECT * FROM relationship WHERE ((user_id_1=:user_id) OR (user_id_2=:user_id)) AND status=1'; $arrRelationship = Relationship::findBySql($sql, [':user_id' => Yii::$app->user->getId()])->asArray()->all(); $arrUserName = array(); foreach ($arrRelationship as $rel) { if ($rel['user_id_1'] == Yii::$app->user->getId()) { $arrUserName[$rel['user_id_2']] = \common\models\User::findOne(['id' => $rel['user_id_2']])->username; } else { $arrUserName[$rel['user_id_1']] = \common\models\User::findOne(['id' => $rel['user_id_1']])->username; } } ?>
/** * 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()]); }
/** * Creates a new Invoice model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $id The Current Invoice ID to create the new invoice from * @return mixed */ public function actionCreate($id) { $currentInvoice = $this->findModel($id, false); $ticketsIds = ArrayHelper::getColumn($currentInvoice->getTickets()->closed(true)->all(), 'id'); $billableLaborTotal = Labor::find()->ticket($ticketsIds)->hourly()->total(true); $purchaseTotal = PurchasedItem::find()->ticket($ticketsIds)->total(); $travelFeeTotal = Travel::find()->invoice($id)->before()->totalFee(); $model = new Invoice(); $model->loadDefaultValues(); $model->location_id = $currentInvoice->location_id; $model->total = $billableLaborTotal + $purchaseTotal + $travelFeeTotal; if ($model->load(Yii::$app->request->post()) && $model->save()) { Ticket::updateAll(['invoice_id' => $model->id], ['id' => $ticketsIds]); Schedule::updateAll(['invoice_id' => $model->id], ['and', 'invoice_id=:invoice_id', 'start_time<:start_time'], [':invoice_id' => $model->location_id, ':start_time' => date(Invoice::BILLING_CUTOFF_DAY)]); return $this->redirect(['view', 'id' => $model->id]); } elseif (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } if (Yii::$app->request->isAjax) { return $this->renderAjax('_form', ['model' => $model]); } return $this->render('create', ['model' => $model]); }