Ejemplo n.º 1
0
 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]);
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * @return LaborQuery
  */
 public function getLabor()
 {
     return $this->hasOne(Labor::className(), ['note_id' => 'id'])->inverseOf('note');
 }
Ejemplo n.º 4
0
 /**
  * @return LaborQuery
  */
 public function getLabors()
 {
     return $this->hasMany(Labor::className(), ['note_id' => 'id'])->via('notes')->inverseOf('ticket');
 }
Ejemplo n.º 5
0
 /**
  * @return LaborQuery
  */
 public function getLabors()
 {
     return $this->hasMany(Labor::className(), ['schedule_id' => 'id'])->inverseOf('schedule');
 }
Ejemplo n.º 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()]);
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 8
0
?>
    <div class="pull-right">
        <?php 
if ($model->inQueue()) {
    echo Html::a('<span class="glyphicon glyphicon-plus"></span> Schedule Ticket', ['schedule/create', 'Schedule' => ['invoice_id' => $model->invoice->location_id, 'ticketIds' => $model->id]], ['class' => 'btn btn-success btn-xs showModalButton']);
}
?>
    </div><div class="clearfix"></div>
    <?php 
Pjax::begin(['id' => 'ticket-labors-pjax', 'linkSelector' => '#ticket-labors-pjax a[data-sort]', 'enablePushState' => !Yii::$app->request->isAjax]);
?>
    <?php 
echo GridView::widget(['id' => 'ticket-labors-grid', 'dataProvider' => $labors, 'showFooter' => $labors->totalCount > 0, 'rowOptions' => function ($m) {
    /** @var $m common\models\Labor */
    return ['class' => $m->schedule->future() ? $m->schedule->onSite ? 'success' : 'info' : ($m->needsUpdate(true) ? 'danger' : '')];
}, 'columns' => [['attribute' => 'schedule.tech_id', 'value' => 'schedule.tech.name'], 'schedule.start_time:datetime', 'schedule.onSite:boolean', ['attribute' => 'hours', 'format' => 'decimal', 'footer' => Yii::$app->formatter->asDecimal(\common\models\Labor::find()->ticket($model->id)->total())], ['class' => 'yii\\grid\\ActionColumn', 'controller' => 'schedule', 'template' => '{view}', 'buttonOptions' => ['class' => 'showModalButton']]]]);
?>
    <?php 
Pjax::end();
?>
    <?php 
$this->endBlock();
?>

    <?php 
$this->beginBlock('PurchasedItems');
// TODO
?>
    <div class="pull-right">
        <?php 
if ($model->isOpen()) {