Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Infracciones::find()->joinWith(['concepto', 'multaUnidad']);
     $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['infracciones.defaultPageSize'];
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['id' => SORT_DESC], 'enableMultiSort' => true]]);
     // Agregado a mano, para que incluya el ordenamiento por concepto y unidad
     $dataProvider->sort->attributes['rConcepto'] = ['asc' => ['infrac_conceptos.concepto' => SORT_ASC], 'desc' => ['infrac_conceptos.concepto' => SORT_DESC]];
     $dataProvider->sort->attributes['rUnidad'] = ['asc' => ['infrac_unidades.unidad' => SORT_ASC], 'desc' => ['infrac_unidades.unidad' => 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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['infracciones.id' => $this->id, 'id_uf' => $this->id_uf, 'id_vehiculo' => $this->id_vehiculo, 'id_persona' => $this->id_persona, 'fecha' => $this->fecSP2EN($this->fecha), 'hora' => $this->hora, 'id_concepto' => $this->rConcepto, 'id_informante' => $this->id_informante, 'notificado' => $this->notificado, 'fecha_verif' => $this->fecSP2EN($this->fecha_verif), 'verificado' => $this->verificado, 'multa_unidad' => $this->rUnidad, 'multa_monto' => str_replace(",", ".", $this->multa_monto), 'multa_pers_cant' => $this->multa_pers_cant, 'multa_pers_monto' => str_replace(",", ".", $this->multa_pers_monto), 'multa_pers_total' => str_replace(",", ".", $this->multa_pers_total), 'multa_total' => str_replace(",", ".", $this->multa_total), 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at, 'infracciones.estado' => $this->estado]);
     $query->andFilterWhere(['like', 'nro_acta', $this->nro_acta])->andFilterWhere(['like', 'lugar', $this->lugar])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'foto', $this->foto])->andFilterWhere(['like', 'motivo_baja', $this->motivo_baja]);
     if (isset($params['resetFechas'])) {
         \Yii::$app->session->remove('infracFecDesde');
         \Yii::$app->session->remove('infracFecHasta');
         $this->fecdesde = null;
         $this->fechasta = null;
         unset($params['resetFechas']);
     }
     if (!empty($this->fecdesde) && !empty($this->fechasta)) {
         // cada vez que se envia el form con el rango de fechas se guardan las fechas en sesion
         \Yii::$app->session->set('infracFecDesde', $this->fecdesde);
         \Yii::$app->session->set('infracFecHasta', $this->fechasta);
         // para el between entre datetimes se debe agregar un dia mas a la fecha hasta
         $f = new \DateTime($this->fechasta);
         //$f->add(new \DateInterval('P1D'));
         $query->andFilterWhere(['between', 'fecha', $this->fecdesde, $f->format('Y-m-d')]);
     } else {
         $sfd = \Yii::$app->session->get('infracFecDesde') ? \Yii::$app->session->get('infracFecDesde') : '';
         $sfh = \Yii::$app->session->get('infracFecHasta') ? \Yii::$app->session->get('infracFecHasta') : '';
         // si todavia están en sesion las variables del rango de fechas se hace el between y se elimina created_at
         if ($sfd && $sfh) {
             // para el between entre datetimes se debe agregar un dia mas a la fecha hasta
             $f = new \DateTime(\Yii::$app->session->get('infracFecHasta'));
             //$f->add(new \DateInterval('P1D'));
             $query->andFilterWhere(['between', 'fecha', \Yii::$app->session->get('infracFecDesde'), $f->format('Y-m-d')]);
             $this->fecha = '';
         } else {
             //$query->andFilterWhere(['like', 'fecha', $this->fecha]);
         }
     }
     return $dataProvider;
 }
Exemplo n.º 2
0
    return $model->informante->apellido . ' ' . $model->informante->nombre;
}], 'multaUnidad.unidad', ['attribute' => 'multa_total', 'hAlign' => 'right', 'format' => ['decimal', 2], 'pageSummary' => true], ['attribute' => 'foto', 'value' => function ($model, $index, $widget) {
    return empty($model->foto) ? 'No' : 'Si';
}]];
$toolbar = ['{export}'];
$lbl1 = 'Informe para el cobro de multas';
$lbl2 = '(' . Yii::$app->formatter->asDate($fd) . ' - ' . Yii::$app->formatter->asDate($fh) . ')';
$pdfHeader = ['L' => ['content' => Html::img(Yii::$app->homeUrl . 'images/logoreportes.png')], 'C' => ['content' => $lbl1 . ' ' . $lbl2, 'font-style' => 'B'], 'R' => ['content' => \Yii::$app->params['lblName']]];
$pdfFooter = ['L' => ['content' => \Yii::$app->params['lblName2']], 'C' => ['content' => 'página {PAGENO} de {nb}'], 'R' => ['content' => 'Fecha:{DATE d/m/Y}']];
echo "<h3>{$lbl1} {$lbl2}</h3>";
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['id' => 'gridInfracciones'], 'columns' => $columns, 'condensed' => true, 'showPageSummary' => true, 'layout' => '{toolbar}{items}', 'export' => ['label' => 'Exportar', 'fontAwesome' => true, 'showConfirmAlert' => true, 'target' => GridView::TARGET_BLANK], 'toolbar' => $toolbar, 'exportConfig' => [GridView::PDF => ['filename' => $lbl1, 'config' => ['destination' => 'D', 'methods' => ['SetHeader' => [['odd' => $pdfHeader, 'even' => $pdfHeader]], 'SetFooter' => [['odd' => $pdfFooter, 'even' => $pdfFooter]]], 'options' => ['title' => $lbl1, 'subject' => '', 'keywords' => ''], 'contentBefore' => '', 'contentAfter' => '']], GridView::EXCEL => ['filename' => $lbl1, 'config' => ['worksheet' => $lbl1, 'cssFile' => '']], GridView::CSV => ['filename' => $lbl1, 'config' => ['colDelimiter' => ";", 'rowDelimiter' => "\r\n"]]]]);
// Detalle de reincidencias para expensas-------------------------------------------------------------
$columnsR = [['attribute' => 'concepto.concepto', 'group' => true], 'id_uf', 'cant', ['attribute' => 'tot', 'hAlign' => 'right', 'format' => ['decimal', 2]], ['label' => 'Cant.Reincidencias', 'value' => function ($m) use($fd) {
    // cuenta todas las multas para la unidad funcional desde la fecha de reinc hasta el dia anterior al periodo informado
    $fh = date('Y-m-d', mktime(0, 0, 0, date('m', strtotime($fd)), 0, date('Y', strtotime($fd))));
    $cantMultas = Infracciones::find()->where(['id_uf' => $m->id_uf, 'estado' => Infracciones::ESTADO_ACTIVO, 'id_concepto' => $m->id_concepto])->andWhere(['between', 'fecha', $m->multa_fec_reinc, $fh])->count();
    if ($cantMultas > 1) {
        $cantMultas = $cantMultas - 1;
    }
    $gfd = Yii::$app->formatter->asDate($m->multa_fec_reinc);
    $gfh = Yii::$app->formatter->asDate($fh);
    return "desde {$gfd} hasta {$gfh}: {$cantMultas}";
}]];
$toolbar = ['{export}'];
$lbl1 = 'Detalle de reincidencias';
$lbl2 = '(' . Yii::$app->formatter->asDate($fd) . ' - ' . Yii::$app->formatter->asDate($fh) . ')';
$pdfHeader = ['L' => ['content' => Html::img(Yii::$app->homeUrl . 'images/logoreportes.png')], 'C' => ['content' => $lbl1 . ' ' . $lbl2, 'font-style' => 'B'], 'R' => ['content' => \Yii::$app->params['lblName']]];
$pdfFooter = ['L' => ['content' => \Yii::$app->params['lblName2']], 'C' => ['content' => 'página {PAGENO} de {nb}'], 'R' => ['content' => 'Fecha:{DATE d/m/Y}']];
echo "<h3>{$lbl1} {$lbl2}</h3>";
echo GridView::widget(['dataProvider' => $dataProviderR, 'options' => ['id' => 'gridReinc'], 'columns' => $columnsR, 'condensed' => true, 'layout' => '{toolbar}{items}', 'export' => ['label' => 'Exportar', 'fontAwesome' => true, 'showConfirmAlert' => true, 'target' => GridView::TARGET_BLANK], 'toolbar' => $toolbar, 'exportConfig' => [GridView::PDF => ['filename' => $lbl1, 'config' => ['destination' => 'D', 'methods' => ['SetHeader' => [['odd' => $pdfHeader, 'even' => $pdfHeader]], 'SetFooter' => [['odd' => $pdfFooter, 'even' => $pdfFooter]]], 'options' => ['title' => $lbl1, 'subject' => '', 'keywords' => ''], 'contentBefore' => '', 'contentAfter' => '']], GridView::EXCEL => ['filename' => $lbl1, 'config' => ['worksheet' => $lbl1, 'cssFile' => '']], GridView::CSV => ['filename' => $lbl1, 'config' => ['colDelimiter' => ";", 'rowDelimiter' => "\r\n"]]]]);
?>
Exemplo n.º 3
0
 private function calculaReinc($model, $ic, $alta)
 {
     $fecAtras = date('Y-m-d', strtotime($model->multa_fec_reinc));
     $fecMulta = date('Y-m-d', strtotime($model->fecha));
     // cuenta todas las multas para la unidad funcional desde la fecha de reinc
     $cantMultas = Infracciones::find()->where(['id_uf' => $model->id_uf, 'estado' => Infracciones::ESTADO_ACTIVO, 'id_concepto' => $model->id_concepto])->andWhere(['between', 'fecha', $fecAtras, $fecMulta])->count();
     // se suma tambien la que se está grabando (si es modif.no es necesario porque ya está incluido en el select)
     if ($alta) {
         $cantMultas = $cantMultas + 1;
     }
     $monto = $ic->multa_precio + $ic->multa_precio * (($cantMultas - 1) * $ic->multa_reinc_porc) / 100;
     return $monto;
 }