Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PurchasedItem::find()->joinWith('ticket');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['ticket_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(['item_type_id' => $this->item_type_id]);
     $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['or', ['ticket_id' => $this->ticket_id], ['like', Ticket::tableName() . '.title', $this->ticket_id]]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * @return PurchasedItemQuery
  */
 public function getPurchase()
 {
     return $this->hasOne(PurchasedItem::className(), ['id' => 'purchase_id'])->inverseOf('reimbursement');
 }
Пример #3
0
 /**
  * @return $this
  */
 public function totals()
 {
     $this->joinWith(['labors', 'purchasedItems'], false)->groupBy('id')->addSelect([Ticket::tableName() . '.*', 'COALESCE(SUM(' . Labor::tableName() . '.[[hours]]), 0) * COUNT(DISTINCT ' . Note::tableName() . '.[[id]]) / COUNT(*) AS [[totalHours]]', 'COALESCE(SUM(' . PurchasedItem::tableName() . '.[[cost]] * ' . PurchasedItem::tableName() . '.[[quantity]]), 0) * COUNT(DISTINCT ' . PurchasedItem::tableName() . '.[[id]]) / COUNT(*) AS [[totalPurchases]]']);
     return $this;
 }
Пример #4
0
 /**
  * @return PurchasedItemQuery
  */
 public function getPurchasedItems()
 {
     return $this->hasMany(PurchasedItem::className(), ['ticket_id' => 'id'])->inverseOf('ticket');
 }
Пример #5
0
 /**
  * Finds the PurchasedItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PurchasedItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PurchasedItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #6
0
 /**
  * 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()]);
 }
Пример #7
0
 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();
 }
Пример #8
0
$this->endBlock();
?>

    <?php 
$this->beginBlock('PurchasedItems');
// TODO
?>
    <div class="pull-right">
        <?php 
if ($model->isOpen()) {
    echo Html::a('<span class="glyphicon glyphicon-plus"></span> New Purchased Item', ['purchased-item/create', 'PurchasedItem' => ['ticket_id' => $model->id]], ['class' => 'btn btn-success btn-xs showModalButton']);
}
?>
    </div><div class="clearfix"></div>
    <?php 
Pjax::begin(['id' => 'ticket-purchases-pjax', 'linkSelector' => '#ticket-purchases-pjax a[data-sort]', 'enablePushState' => !Yii::$app->request->isAjax]);
?>
    <?php 
echo GridView::widget(['id' => 'ticket-purchases-grid', 'dataProvider' => $purchases, 'showFooter' => $purchases->totalCount > 0, 'columns' => ['item_name', ['attribute' => 'item_type_id', 'value' => 'itemType'], 'cost:currency', 'quantity', ['attribute' => 'total', 'format' => 'currency', 'footer' => Yii::$app->formatter->asCurrency(\common\models\PurchasedItem::find()->ticket($model->id)->total())], ['class' => 'yii\\grid\\ActionColumn', 'controller' => 'purchased-item', 'template' => '{update}', 'buttonOptions' => ['class' => 'showModalButton']]]]);
?>
    <?php 
Pjax::end();
?>
    <?php 
$this->endBlock();
?>

    <?php 
echo TabsX::widget(['encodeLabels' => false, 'bordered' => true, 'items' => [['label' => '<small><span class="glyphicon glyphicon-globe"></span> ' . $model->invoice->location->fullName . '</small>', 'content' => $this->blocks['Location']], ['label' => '<small><span class="glyphicon glyphicon-list-alt"></span> Notes</small>', 'content' => $this->blocks['Notes'], 'active' => true], ['label' => '<small><span class="glyphicon glyphicon-calendar"></span> Scheduled Work</small>', 'content' => $this->blocks['Labors'], 'linkOptions' => $needsUpdate ? ['class' => 'bg-danger'] : []], ['label' => '<small><span class="glyphicon glyphicon-shopping-cart"></span> Purchased Items</small>', 'content' => $this->blocks['PurchasedItems']]]]);
?>
</div>