瀏覽代碼

Cambio de los exceles

Jogibeda 5 月之前
父節點
當前提交
6c78c8555f

+ 571 - 204
modules/excel/controllers/ObraController.php

@@ -1,257 +1,624 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
+
 use v1\models\ObraEmpleado;
 use v1\models\ObraEmpleado;
 use v1\models\Usuario;
 use v1\models\Usuario;
 use DateTime;
 use DateTime;
 use DateTimeZone;
 use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
-use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use v1\models\Obra;
 use v1\models\Obra;
 use v1\models\ObraHerramienta;
 use v1\models\ObraHerramienta;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
+use v1\models\Gasto;
+use v1\models\Nomina;
+use v1\models\ObraRubro;
+use v1\models\Pago;
+use yii\web\Response;
 
 
 class ObraController extends Controller
 class ObraController extends Controller
 {
 {
+  public static $estiloCeldaIzquierda12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 12,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER,
+    ],
+  ];
+
+  public static $celdaVertical = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FFFFFFFF'],
+    ],
+    'alignment' => [
+      // 'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FF625FF5"]
+    ],
+  ];
+
+  public static $celdaHorizontal = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+
+  public static $celdaFuente12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+  ];
+
+  public static $celdaVerticalF12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+  public function encabezadoHoja($logo)
+  {
+
+    $celdas = [
+      "A1" => [
+        "valor" => $logo,
+        "combinar" => "G4",
+      ],
+    ];
+
+    foreach ($celdas as $coordenada => $valor) {
+      $this->agregarCelda($coordenada, $valor);
+    }
+
+    $this->renglonActual = 6;
+
+    return $this;
+  }
 
 
   public function actionExcelObra($idObra)
   public function actionExcelObra($idObra)
   {
   {
+    $json = intval($this->req->get("json", ""));
     $obra = Obra::findOne($idObra);
     $obra = Obra::findOne($idObra);
     $request = Yii::$app->request;
     $request = Yii::$app->request;
-
-    $spreadsheet = new Spreadsheet();
-    $sheet = $spreadsheet->getActiveSheet();
-    $sheet->setTitle('Informacion General');
-
+    if ($json) {
+      \Yii::$app->getResponse()->format = Response::FORMAT_JSON;
+      return $json;
+    }
     $BASEPATH = \Yii::getAlias('@app') . "/web";
     $BASEPATH = \Yii::getAlias('@app') . "/web";
     $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
     $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
     $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
     $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
     $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
     $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-    $drawing = new Drawing();
-    $drawing->setName('Logotipo');
-    $drawing->setDescription('Logotipo de la empresa');
-    $drawing->setPath($logo);
-    $drawing->setHeight(70);
-    $drawing->setCoordinates('A1');
-    $drawing->setOffsetX(10);
-    $drawing->setOffsetY(10);
-    $drawing->setWorksheet($sheet);
-
-    $sheet->mergeCells('A5:N5');
-    $sheet->setCellValue('A5', 'Obra: ' . $obra->nombre);
-    $sheet->mergeCells('A6:G6');
-    $sheet->setCellValue('A6', 'Fecha Inicial: ' . $fechaInicio);
-    $sheet->mergeCells('H6:N6');
-    $sheet->setCellValue('H6', 'Fecha Final: ' . $fechaFin);
-    $sheet->getStyle('A5')->getFont()->setBold(true);
-    $sheet->getStyle('A5')->getFont()->setSize(16);
-
-    $headerStyle = [
-      'font' => [
-        'bold' => true,
-        'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-      ],
-      'alignment' => [
-        'horizontal' => Alignment::HORIZONTAL_CENTER,
-        'vertical' => Alignment::VERTICAL_CENTER,
-        'wrapText' => true
-      ],
-      'fill' => [
-        'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-        'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-      ],
-      'borders' => [
-        'allBorders' => [
-          'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-          'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-        ],
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Obra: $obra->nombre",
+        "combinar" => "D6",
+        "estilo" => $estiloEncabezado
+      ],
+      "A7" => [
+        "valor" => "Fecha Inicial: $fechaInicio ",
+        "combinar" => "B7",
+        "estilo" => $estiloEncabezado
       ],
       ],
+      "C7" => [
+        "valor" => "Fecha Final: $fechaFin",
+        "combinar" => "D7",
+        "estilo" => $estiloEncabezado
+      ]
     ];
     ];
 
 
-
-
-    // Aplicar el borde a las celdas combinadas
-    $sheet->getStyle('A5:N5')->applyFromArray($headerStyle);
-    $sheet->getStyle('A6:G6')->applyFromArray($headerStyle);
-    $sheet->getStyle('H6:N6')->applyFromArray($headerStyle);
-
-    //Empleados
+    $this->agregarRenglones($encabezadoTabla);
     $empleados = ObraEmpleado::find()
     $empleados = ObraEmpleado::find()
       ->joinWith('empleado')
       ->joinWith('empleado')
       ->andWhere(['{{ObraEmpleado}}.[[eliminado]]' => null])->andWhere(['{{ObraEmpleado}}.[[idObra]]' => $idObra]);
       ->andWhere(['{{ObraEmpleado}}.[[eliminado]]' => null])->andWhere(['{{ObraEmpleado}}.[[idObra]]' => $idObra]);
     $empleados->orderBy(['creado' => SORT_DESC]);
     $empleados->orderBy(['creado' => SORT_DESC]);
 
 
-    $sheet->mergeCells('A8:G8');
-    $sheet->setCellValue('A8', 'Empleados');
-    $sheet->getStyle('A8:G8')->applyFromArray($headerStyle);
-    $sheet->mergeCells('A9:D9');
-    $sheet->setCellValue('A9', 'Nombre');
-    $sheet->getStyle('A9:D9')->applyFromArray($headerStyle);
-    $sheet->mergeCells('E9:G9');
-    $sheet->setCellValue('E9', 'Fecha Alta');
-    $sheet->getStyle('E9:G9')->applyFromArray($headerStyle);
-    $cellBorderStyle = [
-      'borders' => [
-        'allBorders' => [
-          'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-          'color' => ['argb' => 'FF000000'], // Color negro
-        ],
+    $encabezadoTabla = [
+      "A9" => [
+        "valor" => "Empleados",
+        "estilo" => $estiloEncabezado,
+        "combinar" => "B9",
+
+      ],
+      "A10" => [
+        "valor" => "Nombre",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "B10" => [
+        "valor" => "Fecha Alta",
+        "estilo" => $estiloEncabezado,
       ],
       ],
+      "C9" => [
+        "valor" => "Empleados",
+        "estilo" => $estiloEncabezado,
+        "combinar" => "D9",
+
+      ],
+      "C10" => [
+        "valor" => "Nombre",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "D10" => [
+        "valor" => "Fecha Alta",
+        "estilo" => $estiloEncabezado,
+
+      ],
+
     ];
     ];
-    $rowEmpleados = 10;
+
+    $rEmpleado = 11;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
 
 
     foreach ($empleados->each() as $obraEmpleado) {
     foreach ($empleados->each() as $obraEmpleado) {
       $empleado = $obraEmpleado->empleado;
       $empleado = $obraEmpleado->empleado;
       $fecha = (new DateTime($empleado->fechaAlta))->format('d-m-Y');
       $fecha = (new DateTime($empleado->fechaAlta))->format('d-m-Y');
+      $renglones = [
+        "A{$rEmpleado}" => [
+          "valor" => $empleado->nombre,
+          "estilo" => $estiloCeldaIzquierda,
 
 
-      $sheet->mergeCells('A' . $rowEmpleados  . ':D' . $rowEmpleados);
-      $sheet->setCellValue('A' . $rowEmpleados, $empleado->nombre);
-      $sheet->getStyle('A' . $rowEmpleados  . ':D' . $rowEmpleados)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-      $sheet->getStyle('A' . $rowEmpleados  . ':D' . $rowEmpleados)->applyFromArray($cellBorderStyle);
-
+        ],
+        "B{$rEmpleado}" => [
+          "valor" => $fecha,
+          "estilo" => $estiloCeldaIzquierda,
 
 
-      $sheet->mergeCells('E' . $rowEmpleados  . ':G' . $rowEmpleados);
-      $sheet->setCellValue('E' . $rowEmpleados, $fecha);
-      $sheet->getStyle('E' . $rowEmpleados  . ':G' . $rowEmpleados)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-      $sheet->getStyle('E' . $rowEmpleados  . ':G' . $rowEmpleados)->applyFromArray($cellBorderStyle);
-      $rowEmpleados++;
+        ],
+      ];
+      $this->agregarRenglones($renglones);
+      $rEmpleado += 1;
     }
     }
 
 
-    //Herramientas
-    $query = ObraHerramienta::find()
+    $herramienta = ObraHerramienta::find()
       ->joinWith('herramienta')
       ->joinWith('herramienta')
       ->andWhere(['{{ObraHerramienta}}.[[eliminado]]' => null])->andWhere(['{{ObraHerramienta}}.[[idObra]]' => $idObra]);
       ->andWhere(['{{ObraHerramienta}}.[[eliminado]]' => null])->andWhere(['{{ObraHerramienta}}.[[idObra]]' => $idObra]);
-    $query->orderBy(['creado' => SORT_DESC]);
-    $sheet->mergeCells('H8:N8');
-    $sheet->setCellValue('H8', 'Herramientas');
-    $sheet->getStyle('H8:N8')->applyFromArray($headerStyle);
-    $sheet->mergeCells('H9:K9');
-    $sheet->setCellValue('H9', 'Herramienta');
-    $sheet->getStyle('H9:K9')->applyFromArray($headerStyle);
-    $sheet->mergeCells('L9:N9');
-    $sheet->setCellValue('L9', 'Cantidad');
-    $sheet->getStyle('L9:N9')->applyFromArray($headerStyle);
-    $rowHerramientas = 10;
-
-    foreach ($query->each() as $obraHerramienta) {
+    $herramienta->orderBy(['creado' => SORT_DESC]);
+    $rHerramienta = 11;
+    foreach ($herramienta->each() as $obraHerramienta) {
       $herramienta = $obraHerramienta->herramienta;
       $herramienta = $obraHerramienta->herramienta;
-      $sheet->mergeCells('H' .  $rowHerramientas . ':K' .  $rowHerramientas);
-      $sheet->setCellValue('H' .  $rowHerramientas, $herramienta->nombre); // Nombre del empleado
-      $sheet->getStyle('H' .  $rowHerramientas . ':K' .  $rowHerramientas)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-      $sheet->getStyle('H' .  $rowHerramientas . ':K' .  $rowHerramientas)->applyFromArray($cellBorderStyle);
+      $renglones = [
+        "C{$rHerramienta}" => [
+          "valor" => $herramienta->nombre,
+          "estilo" => $estiloCeldaIzquierda,
+
+        ],
+        "D{$rHerramienta}" => [
+          "valor" => $obraHerramienta->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+      ];
+      $this->agregarRenglones($renglones);
+      $rHerramienta += 1;
+    }
+    $totalesController = new \v1\controllers\ObraController('totales', Yii::$app);
+
+    $totalGasto = $totalesController->actionTotalGasto($idObra);
+    $totalPago = $totalesController->actionTotalPago($idObra);
+    $totalNomina = $totalesController->actionTotalNomina($idObra);
+    $totalRubro = $totalesController->actionTotalRubro($idObra);
+    $saldo = $totalesController->actionSaldo($totalGasto, $totalNomina, $totalPago);
+    $ejercidoObra = $totalesController->actionEjercidoObra($totalGasto, $totalRubro);
+    $ejercer = $totalesController->actionEjercer($totalRubro, $totalPago);
+
+    $startRowTotales = max($rEmpleado, $rHerramienta) + 2;
+
+    $encabezadoTablaTotales = [
+      "A{$startRowTotales}" => [
+        "valor" => "Gasto Total",
+        "estilo" => $estiloEncabezado,
+
+      ],
+
+      "B{$startRowTotales}" => [
+        "valor" => "Pago Total",
+        "estilo" => $estiloEncabezado,
+      ],
+      "C{$startRowTotales}" => [
+        "valor" => "Nómina total",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "D{$startRowTotales}" => [
+        "valor" => "Rubro de Obra",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "E{$startRowTotales}" => [
+        "valor" => "Saldo total",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "F{$startRowTotales}" => [
+        "valor" => "Ejercido obra",
+        "estilo" => $estiloEncabezado,
+
+      ],
+      "G{$startRowTotales}" => [
+        "valor" => "Por ejercer",
+        "estilo" => $estiloEncabezado,
+
+      ],
+    ];
+
+    $this->agregarRenglones($encabezadoTablaTotales);
+    $datos = $startRowTotales + 1;
+    $renglones = [
+      "A{$datos}" => [
+        "valor" => $totalGasto,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional
+
+      ],
+      "B{$datos}" => [
+        "valor" => $totalPago,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+      "C{$datos}" => [
+        "valor" => $totalNomina,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+      "D{$datos}" => [
+        "valor" => $totalRubro,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+      "E{$datos}" => [
+        "valor" => $saldo,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+      "F{$datos}" => [
+        "valor" => $ejercidoObra,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "#,##0.00%",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+      "G{$datos}" => [
+        "valor" => $ejercer,
+        "estilo" => $estiloCeldaIzquierda,
+        "formato" => "$#,##0.00",
+        "estiloCondicional" => $estiloCondicional,
+      ],
+    ];
+    $this->agregarRenglones($renglones);
+
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+      "E" => ["ancho" => 20],
+      "F" => ["ancho" => 20],
+      "G" => ["ancho" => 20],
+
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+    //Gastos
+    $this->nuevaHoja(1, 'Gasto');
+    $gasto = Gasto::find()
+      ->joinWith('conceptosObra')
+      ->andWhere(['{{Gasto}}.[[eliminado]]' => null])->andWhere(['{{Gasto}}.[[idObra]]' => $idObra]);
+    $gasto->orderBy(['fechaCompra' => SORT_DESC]);
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B6" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C6" => [
+        "valor" => "Fecha Compra",
+        "estilo" => $estiloEncabezado
+      ],
+      "D6" => [
+        "valor" => "Descripción",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
 
 
-      $sheet->mergeCells('L' .  $rowHerramientas . ':N' .  $rowHerramientas);
-      $sheet->setCellValue('L' .  $rowHerramientas, $obraHerramienta->cantidad); // Nombre del empleado
-      $sheet->getStyle('L' .  $rowHerramientas . ':N' .  $rowHerramientas)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-      $sheet->getStyle('L' .  $rowHerramientas . ':N' .  $rowHerramientas)->applyFromArray($cellBorderStyle);
+    $r = 7;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
 
 
-      $rowHerramientas++;
+    foreach ($gasto->each() as $obraGasto) {
+      $fecha = (new DateTime($obraGasto->fechaCompra))->format('d-m-Y');
+      $gasto = $obraGasto->conceptosObra;
+
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $gasto->concepto,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraGasto->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" => $fecha,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" => $obraGasto->descripcion,
+          "estilo" => $estiloCeldaIzquierda
+        ]
+      ];
+      $this->agregarRenglones($renglones);
+      $r += 1;
     }
     }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+
+    //Pagos
+    $this->nuevaHoja(2, 'Pago');
+    $pago = Pago::find()
+      ->joinWith('conceptosObra')
+      ->andWhere(['{{Pago}}.[[eliminado]]' => null])->andWhere(['{{Pago}}.[[idObra]]' => $idObra]);
+    $pago->orderBy(['fechaPago' => SORT_DESC]);
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B6" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C6" => [
+        "valor" => "Fecha Pago",
+        "estilo" => $estiloEncabezado
+      ],
+      "D6" => [
+        "valor" => "Descripción",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+
+    $r = 7;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+
+    foreach ($pago->each() as $obraPago) {
+      $fecha = (new DateTime($obraPago->fechaPago))->format('d-m-Y');
+      $Pago = $obraPago->conceptosObra;
 
 
-//Totales
-$totalesController = new \v1\controllers\ObraController('totales', Yii::$app);
-
-$totalGasto = $totalesController->actionTotalGasto($idObra);
-$totalPago = $totalesController->actionTotalPago($idObra);
-$totalNomina = $totalesController->actionTotalNomina($idObra);
-$totalRubro = $totalesController->actionTotalRubro($idObra);
-$saldo = $totalesController->actionSaldo($totalGasto, $totalNomina, $totalPago);
-$ejercidoObra = $totalesController->actionEjercidoObra($totalGasto, $totalRubro);
-$ejercer = $totalesController->actionEjercer($totalRubro, $totalPago);
-
-    $startRowTotales = max($rowEmpleados, $rowHerramientas) + 2;
-
-// Gasto total
-$sheet->mergeCells("A{$startRowTotales}:B{$startRowTotales}");
-$sheet->getStyle("A{$startRowTotales}:B{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("A{$startRowTotales}", 'Gasto total');
-$sheet->mergeCells("A" . ($startRowTotales + 1) . ":B" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("A" . ($startRowTotales + 1), $totalGasto);
-$sheet->getStyle("A" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("A" . ($startRowTotales + 1). ":B" . ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Pago total
-$sheet->mergeCells("C{$startRowTotales}:D{$startRowTotales}");
-$sheet->getStyle("C{$startRowTotales}:D{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("C{$startRowTotales}", 'Pago total');
-$sheet->mergeCells("C" . ($startRowTotales + 1) . ":D" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("C" . ($startRowTotales + 1), $totalPago);
-$sheet->getStyle("C" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("C" . ($startRowTotales + 1). ":D". ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Nómina total
-$sheet->mergeCells("E{$startRowTotales}:F{$startRowTotales}");
-$sheet->getStyle("E{$startRowTotales}:F{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("E{$startRowTotales}", 'Nómina total');
-$sheet->mergeCells("E" . ($startRowTotales + 1) . ":F" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("E" . ($startRowTotales + 1), $totalNomina);
-$sheet->getStyle("E" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("E" . ($startRowTotales + 1).":F". ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Rubro de Obra total
-$sheet->mergeCells("G{$startRowTotales}:H{$startRowTotales}");
-$sheet->getStyle("G{$startRowTotales}:H{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("G{$startRowTotales}", 'Rubro de Obra total');
-$sheet->mergeCells("G" . ($startRowTotales + 1) . ":H" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("G" . ($startRowTotales + 1), $totalRubro);
-$sheet->getStyle("G" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("G" . ($startRowTotales + 1). ":H". ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Saldo total
-$sheet->mergeCells("I{$startRowTotales}:J{$startRowTotales}");
-$sheet->getStyle("I{$startRowTotales}:J{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("I{$startRowTotales}", 'Saldo total');
-$sheet->mergeCells("I" . ($startRowTotales + 1) . ":J" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("I" . ($startRowTotales + 1), $saldo);
-$sheet->getStyle("I" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("I" . ($startRowTotales + 1). ":J" . ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Ejercido obra
-$sheet->mergeCells("K{$startRowTotales}:L{$startRowTotales}");
-$sheet->getStyle("K{$startRowTotales}:L{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("K{$startRowTotales}", 'Ejercido obra');
-$sheet->mergeCells("K" . ($startRowTotales + 1) . ":L" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("K" . ($startRowTotales + 1), $ejercidoObra);
-$sheet->getStyle("K" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("K" . ($startRowTotales + 1). ":L". ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-// Por ejercer
-$sheet->mergeCells("M{$startRowTotales}:N{$startRowTotales}");
-$sheet->getStyle("M{$startRowTotales}:N{$startRowTotales}")->applyFromArray($headerStyle);
-$sheet->setCellValue("M{$startRowTotales}", 'Por ejercer');
-$sheet->mergeCells("M" . ($startRowTotales + 1) . ":N" . ($startRowTotales + 1)); // Merge en la fila de resultados
-$sheet->setCellValue("M" . ($startRowTotales + 1), $ejercer);
-$sheet->getStyle("M" . ($startRowTotales + 1))->getNumberFormat()->setFormatCode('"$"#,##0');
-$sheet->getStyle("M" . ($startRowTotales + 1). ":N" . ($startRowTotales + 1))->applyFromArray($cellBorderStyle);
-
-$excelGasto= new \app\modules\excel\controllers\ObraGastoController('totales', Yii::$app);
-$sheetGasto = $excelGasto->actionExcelGasto($idObra);
-$spreadsheet->addSheet($sheetGasto);
-
-$excelPago= new \app\modules\excel\controllers\ObraPagoController('totales', Yii::$app);
-$sheetPago = $excelPago->actionExcelPago($idObra);
-$spreadsheet->addSheet($sheetPago);
-
-$excelNomina= new \app\modules\excel\controllers\ObraNominaController('totales', Yii::$app);
-$sheetNomina = $excelNomina->actionExcelNomina($idObra);
-$spreadsheet->addSheet($sheetNomina);
-
-$excelRubro= new \app\modules\excel\controllers\ObraRubroController('totales', Yii::$app);
-$sheetRubro = $excelRubro->actionExcelRubro($idObra);
-$spreadsheet->addSheet($sheetRubro);
-    $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-    $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-    try {
-      ob_start();
-      $writer->save("php://output");
-      $documento = ob_get_contents();
-      ob_clean();
-      Yii::$app->getResponse()->sendContentAsFile($documento, "Obra.xlsx");
-    } catch (\Exception $exception) {
-      return null;
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $Pago->concepto,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraPago->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" => $fecha,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" => $obraPago->descripcion,
+          "estilo" => $estiloCeldaIzquierda
+        ]
+      ];
+      $this->agregarRenglones($renglones);
+      $r += 1;
     }
     }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+    $this->nuevaHoja(3, 'Nomina');
+    $nomina = Nomina::find()
+      ->joinWith('empleado')
+      ->andWhere(['{{Nomina}}.[[eliminado]]' => null])->andWhere(['{{Nomina}}.[[idObra]]' => $idObra]);
+    $nomina->orderBy(['fechaInicio' => SORT_DESC]);
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B6" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C6" => [
+        "valor" => "Fecha Inicio",
+        "estilo" => $estiloEncabezado
+      ],
+      "D6" => [
+        "valor" => "Fecha Fin",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+    $r = 7;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+    foreach ($nomina->each() as $obraNomina) {
+      $fechaInicio = (new DateTime($obraNomina->fechaInicio))->format('d-m-Y');
+      $fechaFin = (new DateTime($obraNomina->fechaFin))->format('d-m-Y');
+      $empleado = $obraNomina->empleado;
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $empleado->nombre,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraNomina->montoPagado,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" =>  $fechaInicio,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" =>  $fechaFin,
+          "estilo" => $estiloCeldaIzquierda
+        ]
+      ];
+      $this->agregarRenglones($renglones);
+      $r += 1;
+    
+    }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+    $this->nuevaHoja(4, 'Rubro');
+    $rubro = ObraRubro::find()
+      ->joinWith('conceptoObra')
+      ->andWhere(['{{ObraRubro}}.[[eliminado]]' => null])->andWhere(['{{ObraRubro}}.[[idObra]]' => $idObra]);
+    $rubro->orderBy(['creado' => SORT_DESC]);
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B6" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C6" => [
+        "valor" => "Fecha Compra",
+        "estilo" => $estiloEncabezado
+      ],
+      "D6" => [
+        "valor" => "Descripción",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+    $r = 7;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+    foreach ($rubro->each() as $obraRubro) {
+      $fecha = (new DateTime($obraRubro->fechaCompra))->format('d-m-Y');
+
+      $rubro = $obraRubro->conceptoObra;
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $rubro->concepto,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraRubro->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" =>  $fecha,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" => $obraRubro->descripcion,
+          "estilo" => $estiloCeldaIzquierda
+        ]
+      ];
+      $this->agregarRenglones($renglones);
+      $r += 1;
+    }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+
+
+    $documento = $this->obtenerHojaDeCalculo();
+    $this->crear($documento,  "Obra_" . date("YmdHis"), self::TIPO_EXCEL);
+    \Yii::$app->end();
   }
   }
+
+
+ 
 }
 }

+ 169 - 90
modules/excel/controllers/ObraEmpleadoController.php

@@ -1,117 +1,196 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
+
 use v1\models\ObraEmpleado;
 use v1\models\ObraEmpleado;
 use v1\models\Usuario;
 use v1\models\Usuario;
 use DateTime;
 use DateTime;
 use DateTimeZone;
 use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use v1\models\Obra;
 use v1\models\Obra;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
+use yii\web\Response;
+
+class ObraEmpleadoController extends Controller
+{
+    public static $estiloCeldaIzquierda12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 12,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_LEFT,
+            'vertical' => Alignment::VERTICAL_CENTER,
+        ],
+    ];
+
+    public static $celdaVertical = [
+        'font' => [
+            'bold' => true,
+            'size' => 14,
+            'color' => ['argb' => 'FFFFFFFF'],
+        ],
+        'alignment' => [
+            // 'textRotation' => 90,
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FF625FF5"]
+        ],
+    ];
+
+    public static $celdaHorizontal = [
+        'font' => [
+            'bold' => true,
+            'size' => 14,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FFE7E7E7"]
+        ],
+    ];
+
+    public static $celdaFuente12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 10,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_LEFT,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+    ];
+
+    public static $celdaVerticalF12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 10,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'textRotation' => 90,
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FFE7E7E7"]
+        ],
+    ];
+    public function encabezadoHoja($logo)
+    {
+
+        $celdas = [
+            "A1" => [
+                "valor" => $logo,
+                "combinar" => "G4",
+            ],
+        ];
+
+        foreach ($celdas as $coordenada => $valor) {
+            $this->agregarCelda($coordenada, $valor);
+        }
+
+        $this->renglonActual = 6;
 
 
-class ObraEmpleadoController extends Controller {
+        return $this;
+    }
+
+    public function actionExcelObraEmpleado($idObra)
+    {
+        $json = intval($this->req->get("json", ""));
 
 
-    public function actionExcelObraEmpleado($idObra) {
-      $obra = Obra::findOne($idObra);
+        $obra = Obra::findOne($idObra);
         $request = Yii::$app->request;
         $request = Yii::$app->request;
-        $query= ObraEmpleado::find()	
-        ->joinWith('empleado')
-        ->andWhere(['{{ObraEmpleado}}.[[eliminado]]'=>null])->andWhere(['{{ObraEmpleado}}.[[idObra]]'=>$idObra]);
+        $query = ObraEmpleado::find()
+            ->joinWith('empleado')
+            ->andWhere(['{{ObraEmpleado}}.[[eliminado]]' => null])->andWhere(['{{ObraEmpleado}}.[[idObra]]' => $idObra]);
         $query->orderBy(['creado' => SORT_DESC]);
         $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Empleados');
-
+        if ($json) {
+            \Yii::$app->getResponse()->format = Response::FORMAT_JSON;
+            return $json;
+        }
         $BASEPATH = \Yii::getAlias('@app') . "/web";
         $BASEPATH = \Yii::getAlias('@app') . "/web";
         $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
         $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+        $this->encabezadoHoja($this->logo($logo, 'A1'));
         $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
         $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
         $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
         $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
-
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Empleados relacionados a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
-
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:J8');
-      $sheet->setCellValue('A8', 'Nombre');
-      $sheet->getStyle('A8:J8')->applyFromArray( $headerStyle);
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
+        $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+        $encabezadoTabla = [
+            "A6" => [
+                "valor" => "Empleados relacionado a la obra: $obra->nombre",
+                "combinar" => "D6",
+                "estilo" => $estiloEncabezado
             ],
             ],
-        ],
-    ];
-      $row = 9;
+            "A7" => [
+                "valor" => "Fecha Inicial: $fechaInicio ",
+                "combinar" => "B7",
+                "estilo" => $estiloEncabezado
+            ],
+            "C7" => [
+                "valor" => "Fecha Final: $fechaFin",
+                "combinar" => "D7",
+                "estilo" => $estiloEncabezado
+            ]
+        ];
+
+        $this->agregarRenglones($encabezadoTabla);
+        $encabezadoTabla = [
+            "A9" => [
+                "valor" => "Nombre",
+                "estilo" => $estiloEncabezado,
+                "combinar" => "D9",
+
+            ],
+
+        ];
+
+        $r = 10;
+        $this->agregarRenglones($encabezadoTabla);
+        $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+        $estiloCondicional = $this->estiloCondicional();
 
 
         foreach ($query->each() as $obraEmpleado) {
         foreach ($query->each() as $obraEmpleado) {
-            $empleado = $obraEmpleado->empleado; 
-            $sheet->mergeCells('A' . $row . ':J' . $row);
-            $sheet->setCellValue('A' . $row, $empleado->nombre); // Nombre del empleado
-            $sheet->getStyle('A' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
+            $empleado = $obraEmpleado->empleado;
+            $renglones = [
+                "A{$r}" => [
+                    "valor" => $empleado->nombre,
+                    "estilo" => $estiloCeldaIzquierda,
+                    "combinar" => "D{$r}",
 
 
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Empleados.xlsx");
-        } catch (\Exception $exception) {
-          return null;
+                ],
+            ];
+            $this->agregarRenglones($renglones);
+            $r += 1;
         }
         }
+        $anchoColumnas = [
+            "A" => ["ancho" => 20],
+            "B" => ["ancho" => 20],
+            "C" => ["ancho" => 20],
+            "D" => ["ancho" => 20],
+        ];
+        $this->anchoColumnas($anchoColumnas);
+        $documento = $this->obtenerHojaDeCalculo();
+        $this->crear($documento,  "Empleados_" . date("YmdHis"), self::TIPO_EXCEL);
+        \Yii::$app->end();
     }
     }
-}
+
+
+
+
+    
+}

+ 195 - 250
modules/excel/controllers/ObraGastoController.php

@@ -1,270 +1,215 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
-use v1\models\ObraEmpleado;
-use v1\models\Usuario;
+
 use DateTime;
 use DateTime;
-use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
-use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use v1\models\Gasto;
 use v1\models\Gasto;
 use v1\models\Obra;
 use v1\models\Obra;
-use v1\models\ObraHerramienta;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
+use yii\web\Response;
+use excel\web\Controller;
 
 
-class ObraGastoController extends Controller {
+class ObraGastoController extends Controller
+{
+//Version de hugo
+public static $estiloCeldaIzquierda12 = [
+  'font' => [
+    'bold' => true,
+    'size' => 12,
+    'color' => ['argb' => 'FF000000'],
+  ],
+  'alignment' => [
+    'horizontal' => Alignment::HORIZONTAL_LEFT,
+    'vertical' => Alignment::VERTICAL_CENTER,
+  ],
+];
 
 
-    public function actionExcelObraGasto($idObra) {
-      $obra = Obra::findOne($idObra);
-        $request = Yii::$app->request;
-        $query= Gasto::find()	
-        ->joinWith('conceptosObra')
-        ->andWhere(['{{Gasto}}.[[eliminado]]'=>null])->andWhere(['{{Gasto}}.[[idObra]]'=>$idObra]);
-        $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Gastos de la obra');
+public static $celdaVertical = [
+  'font' => [
+    'bold' => true,
+    'size' => 14,
+    'color' => ['argb' => 'FFFFFFFF'],
+  ],
+  'alignment' => [
+    // 'textRotation' => 90,
+    'horizontal' => Alignment::HORIZONTAL_CENTER,
+    'vertical' => Alignment::VERTICAL_CENTER
+  ],
+  'fill' => [
+    'fillType' => Fill::FILL_SOLID,
+    'startColor' => ['argb' => "FF625FF5"]
+  ],
+];
 
 
-        $BASEPATH = \Yii::getAlias('@app') . "/web";
-        $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-        $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-        $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
+public static $celdaHorizontal = [
+  'font' => [
+    'bold' => true,
+    'size' => 14,
+    'color' => ['argb' => 'FF000000'],
+  ],
+  'alignment' => [
+    'horizontal' => Alignment::HORIZONTAL_CENTER,
+    'vertical' => Alignment::VERTICAL_CENTER
+  ],
+  'fill' => [
+    'fillType' => Fill::FILL_SOLID,
+    'startColor' => ['argb' => "FFE7E7E7"]
+  ],
+];
 
 
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Gastos relacionado a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
+public static $celdaFuente12 = [
+  'font' => [
+    'bold' => true,
+    'size' => 10,
+    'color' => ['argb' => 'FF000000'],
+  ],
+  'alignment' => [
+    'horizontal' => Alignment::HORIZONTAL_LEFT,
+    'vertical' => Alignment::VERTICAL_CENTER
+  ],
+];
 
 
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:C8');
-      $sheet->setCellValue('A8', 'Concepto Obra');
-      $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('D8:E8');
-      $sheet->setCellValue('D8', 'Cantidad');
-      $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('F8:G8');
-      $sheet->setCellValue('F8', 'Fecha Compra');
-      $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('H8:J8');
-      $sheet->setCellValue('H8', 'Descripción');
-      $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
-            ],
-        ],
-    ];
-      $row = 9;
+public static $celdaVerticalF12 = [
+  'font' => [
+    'bold' => true,
+    'size' => 10,
+    'color' => ['argb' => 'FF000000'],
+  ],
+  'alignment' => [
+    'textRotation' => 90,
+    'horizontal' => Alignment::HORIZONTAL_CENTER,
+    'vertical' => Alignment::VERTICAL_CENTER
+  ],
+  'fill' => [
+    'fillType' => Fill::FILL_SOLID,
+    'startColor' => ['argb' => "FFE7E7E7"]
+  ],
+];
+public function encabezadoHoja($logo)
+{
+
+  $celdas = [
+    "A1" => [
+      "valor" => $logo,
+      "combinar" => "G4",
+    ],
+  ];
+
+  foreach ($celdas as $coordenada => $valor) {
+    $this->agregarCelda($coordenada, $valor);
+  }
 
 
-        foreach ($query->each() as $obraGasto) {
-            $fecha = (new DateTime($obraGasto->fechaCompra))->format('d-m-Y');
+  $this->renglonActual = 6;
 
 
-            $gasto = $obraGasto->conceptosObra; 
-            $sheet->mergeCells('A' . $row . ':C' . $row);
-           $sheet->setCellValue('A' . $row, $gasto->concepto); 
-            $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
+  return $this;
+}
 
 
-            $sheet->mergeCells('D' . $row . ':E' . $row);
-            $sheet->setCellValue('D' . $row, $obraGasto->cantidad); 
-            $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-            $sheet->getStyle('D' . $row)
-            ->getNumberFormat()
-            ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-            $sheet->mergeCells('F' . $row . ':G' . $row);
-            $sheet->setCellValue('F' . $row, $fecha); 
-            $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-            
-            $sheet->mergeCells('H' . $row . ':J' . $row);
-            $sheet->setCellValue('H' . $row, $obraGasto->descripcion);
-            $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Gasto.xlsx");
-        } catch (\Exception $exception) {
-          return null;
-        }
-        
+  public function actionGastoExcel($idObra)
+  {
+    $json = intval($this->req->get("json", ""));
+
+    $obra = Obra::findOne($idObra);
+    $query = Gasto::find()
+      ->joinWith('conceptosObra')
+      ->andWhere(['{{Gasto}}.[[eliminado]]' => null])->andWhere(['{{Gasto}}.[[idObra]]' => $idObra]);
+    $query->orderBy(['fechaCompra' => SORT_DESC]);
+    if ($json) {
+      \Yii::$app->getResponse()->format = Response::FORMAT_JSON;
+      return $json;
     }
     }
-    public function actionExcelGasto($idObra) {
-        $obra = Obra::findOne($idObra);
-          $request = Yii::$app->request;
-          $query= Gasto::find()	
-          ->joinWith('conceptosObra')
-          ->andWhere(['{{Gasto}}.[[eliminado]]'=>null])->andWhere(['{{Gasto}}.[[idObra]]'=>$idObra]);
-          $query->orderBy(['creado' => SORT_DESC]);
-          $spreadsheet = new Spreadsheet();
-          $sheet = $spreadsheet->getActiveSheet();
-          $sheet->setTitle('Gastos de la obra');
-  
-          $BASEPATH = \Yii::getAlias('@app') . "/web";
-          $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-          $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-          $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-          $drawing = new Drawing();
-          $drawing->setName('Logotipo');
-          $drawing->setDescription('Logotipo de la empresa');
-          $drawing->setPath($logo);
-          $drawing->setHeight(70);
-          $drawing->setCoordinates('A1');
-          $drawing->setOffsetX(10);
-          $drawing->setOffsetY(10);
-          $drawing->setWorksheet($sheet);
-  
-          $sheet->mergeCells('A5:J5');
-          $sheet->setCellValue('A5','Gastos relacionado a la obra: ' . $obra->nombre);
-          $sheet->mergeCells('A6:E6');
-          $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-          $sheet->mergeCells('F6:J6');
-          $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-          $sheet->getStyle('A5')->getFont()->setBold(true);
-          $sheet->getStyle('A5')->getFont()->setSize(16);
-  
-          $headerStyle = [
-            'font' => [
-                'bold' => true,
-                'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-            ],
-            'alignment' => [
-                'horizontal' => Alignment::HORIZONTAL_CENTER,
-                'vertical' => Alignment::VERTICAL_CENTER,
-                'wrapText' => true
-            ],
-            'fill' => [
-                'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-                'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-            ],
-            'borders' => [
-                'allBorders' => [
-                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                    'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-                ],
-            ],
-        ];
-        
-        
-        
-        // Aplicar el borde a las celdas combinadas
-        $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-        $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-        $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-         
-        $sheet->mergeCells('A8:C8');
-        $sheet->setCellValue('A8', 'Concepto Obra');
-        $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('D8:E8');
-        $sheet->setCellValue('D8', 'Cantidad');
-        $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('F8:G8');
-        $sheet->setCellValue('F8', 'Fecha Compra');
-        $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('H8:J8');
-        $sheet->setCellValue('H8', 'Descripción');
-        $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-        $cellBorderStyle = [
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF000000'], // Color negro
-              ],
-          ],
+
+    $BASEPATH = \Yii::getAlias('@app') . "/web";
+    $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
+    $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
+    $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Gastos relacionado a la obra: $obra->nombre",
+        "combinar" => "D6",
+        "estilo" => $estiloEncabezado
+      ],
+      "A7" => [
+        "valor" => "Fecha Inicial: $fechaInicio ",
+        "combinar" => "B7",
+        "estilo" => $estiloEncabezado
+      ],
+      "C7" => [
+        "valor" => "Fecha Final: $fechaFin",
+        "combinar" => "D7",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+
+    $this->agregarRenglones($encabezadoTabla);
+
+    $encabezadoTabla = [
+      "A9" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B9" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C9" => [
+        "valor" => "Fecha Compra",
+        "estilo" => $estiloEncabezado
+      ],
+      "D9" => [
+        "valor" => "Descripción",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+
+    $r = 10;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+
+    foreach ($query->each() as $obraGasto) {
+      $fecha = (new DateTime($obraGasto->fechaCompra))->format('d-m-Y');
+      $gasto = $obraGasto->conceptosObra;
+
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $gasto->concepto,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraGasto->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" => $fecha,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" => $obraGasto->descripcion,
+          "estilo" => $estiloCeldaIzquierda
+        ]
       ];
       ];
-        $row = 9;
-  
-          foreach ($query->each() as $obraGasto) {
-              $fecha = (new DateTime($obraGasto->fechaCompra))->format('d-m-Y');
-  
-              $gasto = $obraGasto->conceptosObra; 
-              $sheet->mergeCells('A' . $row . ':C' . $row);
-             $sheet->setCellValue('A' . $row, $gasto->concepto); 
-              $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
-  
-              $sheet->mergeCells('D' . $row . ':E' . $row);
-              $sheet->setCellValue('D' . $row, $obraGasto->cantidad); 
-              $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-              $sheet->getStyle('D' . $row)
-              ->getNumberFormat()
-              ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-              $sheet->mergeCells('F' . $row . ':G' . $row);
-              $sheet->setCellValue('F' . $row, $fecha); 
-              $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-              
-              $sheet->mergeCells('H' . $row . ':J' . $row);
-              $sheet->setCellValue('H' . $row, $obraGasto->descripcion);
-              $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-              $row++;
-          }
-         
-         
-          $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-          $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-          try {
-           return $sheet;
-          } catch (\Exception $exception) {
-            return null;
-          }
-          
-      }
-}
+      $this->agregarRenglones($renglones);
+      $r += 1;
+    }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+    $documento = $this->obtenerHojaDeCalculo();
+    $this->crear($documento,  "Gasto_" . date("YmdHis"), self::TIPO_EXCEL);
+    \Yii::$app->end();
+    return $documento;
+  }
+}

+ 168 - 90
modules/excel/controllers/ObraHerramientaController.php

@@ -12,115 +12,193 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use v1\models\Obra;
 use v1\models\Obra;
 use v1\models\ObraHerramienta;
 use v1\models\ObraHerramienta;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
+use yii\web\Response;
 
 
 class ObraHerramientaController extends Controller {
 class ObraHerramientaController extends Controller {
+    public static $estiloCeldaIzquierda12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 12,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_LEFT,
+            'vertical' => Alignment::VERTICAL_CENTER,
+        ],
+    ];
+
+    public static $celdaVertical = [
+        'font' => [
+            'bold' => true,
+            'size' => 14,
+            'color' => ['argb' => 'FFFFFFFF'],
+        ],
+        'alignment' => [
+            // 'textRotation' => 90,
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FF625FF5"]
+        ],
+    ];
+
+    public static $celdaHorizontal = [
+        'font' => [
+            'bold' => true,
+            'size' => 14,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FFE7E7E7"]
+        ],
+    ];
+
+    public static $celdaFuente12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 10,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'horizontal' => Alignment::HORIZONTAL_LEFT,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+    ];
+
+    public static $celdaVerticalF12 = [
+        'font' => [
+            'bold' => true,
+            'size' => 10,
+            'color' => ['argb' => 'FF000000'],
+        ],
+        'alignment' => [
+            'textRotation' => 90,
+            'horizontal' => Alignment::HORIZONTAL_CENTER,
+            'vertical' => Alignment::VERTICAL_CENTER
+        ],
+        'fill' => [
+            'fillType' => Fill::FILL_SOLID,
+            'startColor' => ['argb' => "FFE7E7E7"]
+        ],
+    ];
+    public function encabezadoHoja($logo)
+    {
+
+        $celdas = [
+            "A1" => [
+                "valor" => $logo,
+                "combinar" => "G4",
+            ],
+        ];
+
+        foreach ($celdas as $coordenada => $valor) {
+            $this->agregarCelda($coordenada, $valor);
+        }
+
+        $this->renglonActual = 6;
+
+        return $this;
+    }
 
 
     public function actionExcelObraHerramienta($idObra) {
     public function actionExcelObraHerramienta($idObra) {
-      $obra = Obra::findOne($idObra);
+        $json = intval($this->req->get("json", ""));
+
+        $obra = Obra::findOne($idObra);
         $request = Yii::$app->request;
         $request = Yii::$app->request;
         $query= ObraHerramienta::find()	
         $query= ObraHerramienta::find()	
         ->joinWith('herramienta')
         ->joinWith('herramienta')
         ->andWhere(['{{ObraHerramienta}}.[[eliminado]]'=>null])->andWhere(['{{ObraHerramienta}}.[[idObra]]'=>$idObra]);
         ->andWhere(['{{ObraHerramienta}}.[[eliminado]]'=>null])->andWhere(['{{ObraHerramienta}}.[[idObra]]'=>$idObra]);
         $query->orderBy(['creado' => SORT_DESC]);
         $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Herramientas de la obra');
-
+        if ($json) {
+            \Yii::$app->getResponse()->format = Response::FORMAT_JSON;
+            return $json;
+        }
         $BASEPATH = \Yii::getAlias('@app') . "/web";
         $BASEPATH = \Yii::getAlias('@app') . "/web";
         $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
         $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+        $this->encabezadoHoja($this->logo($logo, 'A1'));
         $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
         $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
         $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
         $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
-
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Herramientas relacionadas a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
-
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:D8');
-      $sheet->setCellValue('A8', 'Herramienta');
-      $sheet->getStyle('A8:D8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('E8:J8');
-      $sheet->setCellValue('E8', 'Cantidad');
-      $sheet->getStyle('E8:J8')->applyFromArray( $headerStyle);
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
+        $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+        $encabezadoTabla = [
+            "A6" => [
+                "valor" => "Herramientas relacionadas a la obra: $obra->nombre",
+                "combinar" => "D6",
+                "estilo" => $estiloEncabezado
             ],
             ],
-        ],
-    ];
-      $row = 9;
+            "A7" => [
+                "valor" => "Fecha Inicial: $fechaInicio ",
+                "combinar" => "B7",
+                "estilo" => $estiloEncabezado
+            ],
+            "C7" => [
+                "valor" => "Fecha Final: $fechaFin",
+                "combinar" => "D7",
+                "estilo" => $estiloEncabezado
+            ]
+        ];
+        $this->agregarRenglones($encabezadoTabla);
+        $encabezadoTabla = [
+            "A9" => [
+                "valor" => "Nombre",
+                "estilo" => $estiloEncabezado,
+                "combinar" => "B9",
+
+            ],
+            "C9" => [
+                "valor" => "Cantidad",
+                "estilo" => $estiloEncabezado,
+                "combinar" => "D9",
 
 
+            ],
+
+        ];
+        $r = 10;
+        $this->agregarRenglones($encabezadoTabla);
+        $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+        $estiloCondicional = $this->estiloCondicional();
+        
         foreach ($query->each() as $obraHerramienta) {
         foreach ($query->each() as $obraHerramienta) {
             $herramienta = $obraHerramienta->herramienta; 
             $herramienta = $obraHerramienta->herramienta; 
-            $sheet->mergeCells('A' . $row . ':D' . $row);
-            $sheet->setCellValue('A' . $row, $herramienta->nombre); // Nombre del empleado
-            $sheet->getStyle('A' . $row . ':D' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':D' . $row)->applyFromArray($cellBorderStyle);
+            $renglones = [
+                "A{$r}" => [
+                    "valor" => $herramienta->nombre,
+                    "estilo" => $estiloCeldaIzquierda,
+                    "combinar" => "B{$r}",
 
 
-            $sheet->mergeCells('E' . $row . ':J' . $row);
-            $sheet->setCellValue('E' . $row, $obraHerramienta->cantidad); // Nombre del empleado
-            $sheet->getStyle('E' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('E' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
+                ],
+                "C{$r}" => [
+                    "valor" => $obraHerramienta->cantidad,
+                    "estilo" => $estiloCeldaIzquierda,
+                    "combinar" => "D{$r}",
+                    "formato" => "#,##0",
+                    "estiloCondicional" => $estiloCondicional
 
 
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Herramientas.xlsx");
-        } catch (\Exception $exception) {
-          return null;
+                ],
+            ];
+            $this->agregarRenglones($renglones);
+            $r += 1;
         }
         }
+        $anchoColumnas = [
+            "A" => ["ancho" => 20],
+            "B" => ["ancho" => 20],
+            "C" => ["ancho" => 20],
+            "D" => ["ancho" => 20],
+        ];
+        $this->anchoColumnas($anchoColumnas);
+        $documento = $this->obtenerHojaDeCalculo();
+        $this->crear($documento,  "Empleados_" . date("YmdHis"), self::TIPO_EXCEL);
+        \Yii::$app->end();
     }
     }
+
+
+  
 }
 }

+ 188 - 235
modules/excel/controllers/ObraNominaController.php

@@ -1,259 +1,212 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
+
 use DateTime;
 use DateTime;
 use DateTimeZone;
 use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use v1\models\Nomina;
 use v1\models\Nomina;
 use v1\models\Obra;
 use v1\models\Obra;
 use v1\models\Pago;
 use v1\models\Pago;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
 
 
-class ObraNominaController extends Controller {
+class ObraNominaController extends Controller
+{
+  public static $estiloCeldaIzquierda12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 12,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER,
+    ],
+  ];
 
 
-    public function actionExcelObraNomina($idObra) {
-      $obra = Obra::findOne($idObra);
-        $request = Yii::$app->request;
-        $query= Nomina::find()	
-        ->joinWith('empleado')
-        ->andWhere(['{{Nomina}}.[[eliminado]]'=>null])->andWhere(['{{Nomina}}.[[idObra]]'=>$idObra]);
-        $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Nomina de la obra');
+  public static $celdaVertical = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FFFFFFFF'],
+    ],
+    'alignment' => [
+      // 'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FF625FF5"]
+    ],
+  ];
 
 
-        $BASEPATH = \Yii::getAlias('@app') . "/web";
-        $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-        $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-        $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
+  public static $celdaHorizontal = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
 
 
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Nomina relacionado a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
+  public static $celdaFuente12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+  ];
 
 
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:C8');
-      $sheet->setCellValue('A8', 'Concepto Obra');
-      $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('D8:F8');
-      $sheet->setCellValue('D8', 'Cantidad');
-      $sheet->getStyle('D8:F8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('G8:J8');
-      $sheet->setCellValue('G8', 'Fecha Inicio y Fecha Fin');
-      $sheet->getStyle('G8:J8')->applyFromArray( $headerStyle);
-      
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
-            ],
-        ],
+  public static $celdaVerticalF12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+  public function encabezadoHoja($logo)
+  {
+
+    $celdas = [
+      "A1" => [
+        "valor" => $logo,
+        "combinar" => "G4",
+      ],
     ];
     ];
-      $row = 9;
 
 
-        foreach ($query->each() as $obraNomina) {
-            $fechaInicio = (new DateTime($obraNomina->fechaInicio))->format('d-m-Y');
-            $fechaFin = (new DateTime($obraNomina->fechaFin))->format('d-m-Y');
+    foreach ($celdas as $coordenada => $valor) {
+      $this->agregarCelda($coordenada, $valor);
+    }
+
+    $this->renglonActual = 6;
 
 
-            $empleado = $obraNomina->empleado; 
-            $sheet->mergeCells('A' . $row . ':C' . $row);
-           $sheet->setCellValue('A' . $row, $empleado->nombre);
-            $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
+    return $this;
+  }
 
 
-            $sheet->mergeCells('D' . $row . ':F' . $row);
-            $sheet->setCellValue('D' . $row, $obraNomina->montoPagado); 
-            $sheet->getStyle('D' . $row . ':F' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('D' . $row . ':F' . $row)->applyFromArray($cellBorderStyle);
-            $sheet->getStyle('D' . $row)
-            ->getNumberFormat()
-            ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-            $sheet->mergeCells('G' . $row . ':J' . $row);
-            $sheet->setCellValue('G' . $row, $fechaInicio . ' al ' .$fechaFin); 
-            $sheet->getStyle('G' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('G' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-            
-            
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Nomina.xlsx");
-        } catch (\Exception $exception) {
-          return null;
-        }
-    }
+  public function actionExcelObraNomina($idObra)
+  {
+    $json = intval($this->req->get("json", ""));
+    $obra = Obra::findOne($idObra);
+    $query = Nomina::find()
+      ->joinWith('empleado')
+      ->andWhere(['{{Nomina}}.[[eliminado]]' => null])->andWhere(['{{Nomina}}.[[idObra]]' => $idObra]);
+    $query->orderBy(['fechaInicio' => SORT_DESC]);
+    $BASEPATH = \Yii::getAlias('@app') . "/web";
+    $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
+    $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
+    $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
 
 
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Nomina relacionada a la obra: $obra->nombre",
+        "combinar" => "D6",
+        "estilo" => $estiloEncabezado
+      ],
+      "A7" => [
+        "valor" => "Fecha Inicial: $fechaInicio ",
+        "combinar" => "B7",
+        "estilo" => $estiloEncabezado
+      ],
+      "C7" => [
+        "valor" => "Fecha Final: $fechaFin",
+        "combinar" => "D7",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+
+    $this->agregarRenglones($encabezadoTabla);
+    $encabezadoTabla = [
+      "A9" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B9" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C9" => [
+        "valor" => "Fecha Inicio",
+        "estilo" => $estiloEncabezado
+      ],
+      "D9" => [
+        "valor" => "Fecha Fin",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+    $r = 10;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+    foreach ($query->each() as $obraNomina) {
+      $fechaInicio = (new DateTime($obraNomina->fechaInicio))->format('d-m-Y');
+      $fechaFin = (new DateTime($obraNomina->fechaFin))->format('d-m-Y');
+      $empleado = $obraNomina->empleado;
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $empleado->nombre,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraNomina->montoPagado,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
 
 
-    public function actionExcelNomina($idObra) {
-        $obra = Obra::findOne($idObra);
-          $request = Yii::$app->request;
-          $query= Nomina::find()	
-          ->joinWith('empleado')
-          ->andWhere(['{{Nomina}}.[[eliminado]]'=>null])->andWhere(['{{Nomina}}.[[idObra]]'=>$idObra]);
-          $query->orderBy(['creado' => SORT_DESC]);
-          $spreadsheet = new Spreadsheet();
-          $sheet = $spreadsheet->getActiveSheet();
-          $sheet->setTitle('Nomina de la obra');
-  
-          $BASEPATH = \Yii::getAlias('@app') . "/web";
-          $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-          $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-          $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-          $drawing = new Drawing();
-          $drawing->setName('Logotipo');
-          $drawing->setDescription('Logotipo de la empresa');
-          $drawing->setPath($logo);
-          $drawing->setHeight(70);
-          $drawing->setCoordinates('A1');
-          $drawing->setOffsetX(10);
-          $drawing->setOffsetY(10);
-          $drawing->setWorksheet($sheet);
-  
-          $sheet->mergeCells('A5:J5');
-          $sheet->setCellValue('A5','Nomina relacionado a la obra: ' . $obra->nombre);
-          $sheet->mergeCells('A6:E6');
-          $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-          $sheet->mergeCells('F6:J6');
-          $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-          $sheet->getStyle('A5')->getFont()->setBold(true);
-          $sheet->getStyle('A5')->getFont()->setSize(16);
-  
-          $headerStyle = [
-            'font' => [
-                'bold' => true,
-                'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-            ],
-            'alignment' => [
-                'horizontal' => Alignment::HORIZONTAL_CENTER,
-                'vertical' => Alignment::VERTICAL_CENTER,
-                'wrapText' => true
-            ],
-            'fill' => [
-                'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-                'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-            ],
-            'borders' => [
-                'allBorders' => [
-                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                    'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-                ],
-            ],
-        ];
-        
-        
-        
-        // Aplicar el borde a las celdas combinadas
-        $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-        $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-        $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-         
-        $sheet->mergeCells('A8:C8');
-        $sheet->setCellValue('A8', 'Concepto Obra');
-        $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('D8:F8');
-        $sheet->setCellValue('D8', 'Cantidad');
-        $sheet->getStyle('D8:F8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('G8:J8');
-        $sheet->setCellValue('G8', 'Fecha Inicio y Fecha Fin');
-        $sheet->getStyle('G8:J8')->applyFromArray( $headerStyle);
-        
-        $cellBorderStyle = [
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF000000'], // Color negro
-              ],
-          ],
+        ],
+        "C{$r}" => [
+          "valor" =>  $fechaInicio,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" =>  $fechaFin,
+          "estilo" => $estiloCeldaIzquierda
+        ]
       ];
       ];
-        $row = 9;
-  
-          foreach ($query->each() as $obraNomina) {
-              $fechaInicio = (new DateTime($obraNomina->fechaInicio))->format('d-m-Y');
-              $fechaFin = (new DateTime($obraNomina->fechaFin))->format('d-m-Y');
-  
-              $empleado = $obraNomina->empleado; 
-              $sheet->mergeCells('A' . $row . ':C' . $row);
-             $sheet->setCellValue('A' . $row, $empleado->nombre);
-              $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
-  
-              $sheet->mergeCells('D' . $row . ':F' . $row);
-              $sheet->setCellValue('D' . $row, $obraNomina->montoPagado); 
-              $sheet->getStyle('D' . $row . ':F' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('D' . $row . ':F' . $row)->applyFromArray($cellBorderStyle);
-              $sheet->getStyle('D' . $row)
-              ->getNumberFormat()
-              ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-              $sheet->mergeCells('G' . $row . ':J' . $row);
-              $sheet->setCellValue('G' . $row, $fechaInicio . ' al ' .$fechaFin); 
-              $sheet->getStyle('G' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('G' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-              
-              
-              $row++;
-          }
-         
-         
-          $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-          $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-          try {
-           return $sheet;
-          } catch (\Exception $exception) {
-            return null;
-          }
-      }
-}
+      $this->agregarRenglones($renglones);
+      $r += 1;
+    
+    }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+    $documento = $this->obtenerHojaDeCalculo();
+    $this->crear($documento,  "Nomina_" . date("YmdHis"), self::TIPO_EXCEL);
+    \Yii::$app->end();
+  }
+
+
+
+
+}

+ 183 - 238
modules/excel/controllers/ObraPagoController.php

@@ -1,271 +1,216 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
-use v1\models\ObraEmpleado;
-use v1\models\Usuario;
+
 use DateTime;
 use DateTime;
 use DateTimeZone;
 use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
-use v1\models\Gasto;
 use v1\models\Obra;
 use v1\models\Obra;
-use v1\models\ObraHerramienta;
 use v1\models\Pago;
 use v1\models\Pago;
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
+use yii\web\Response;
 
 
 class ObraPagoController extends Controller {
 class ObraPagoController extends Controller {
 
 
-    public function actionExcelObraPago($idObra) {
-      $obra = Obra::findOne($idObra);
-        $request = Yii::$app->request;
-        $query= Pago::find()	
-        ->joinWith('conceptosObra')
-        ->andWhere(['{{Pago}}.[[eliminado]]'=>null])->andWhere(['{{Pago}}.[[idObra]]'=>$idObra]);
-        $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Pagos de la obra');
+//Version de hugo
+public static $estiloCeldaIzquierda12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 12,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER,
+    ],
+  ];
 
 
-        $BASEPATH = \Yii::getAlias('@app') . "/web";
-        $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-        $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-        $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
+  public static $celdaVertical = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FFFFFFFF'],
+    ],
+    'alignment' => [
+      // 'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FF625FF5"]
+    ],
+  ];
 
 
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Pagos relacionado a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
+  public static $celdaHorizontal = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
 
 
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:C8');
-      $sheet->setCellValue('A8', 'Concepto Obra');
-      $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('D8:E8');
-      $sheet->setCellValue('D8', 'Cantidad');
-      $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('F8:G8');
-      $sheet->setCellValue('F8', 'Fecha Pago');
-      $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('H8:J8');
-      $sheet->setCellValue('H8', 'Descripción');
-      $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
-            ],
-        ],
-    ];
-      $row = 9;
+  public static $celdaFuente12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+  ];
 
 
-        foreach ($query->each() as $obraPago) {
-            $fecha = (new DateTime($obraPago->fechaPago))->format('d-m-Y');
+  public static $celdaVerticalF12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+  public function encabezadoHoja($logo)
+  {
 
 
-            $gasto = $obraPago->conceptosObra; 
-            $sheet->mergeCells('A' . $row . ':C' . $row);
-           $sheet->setCellValue('A' . $row, $gasto->concepto);
-            $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
+    $celdas = [
+      "A1" => [
+        "valor" => $logo,
+        "combinar" => "G4",
+      ],
+    ];
 
 
-            $sheet->mergeCells('D' . $row . ':E' . $row);
-            $sheet->setCellValue('D' . $row, $obraPago->cantidad); 
-            $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-            $sheet->getStyle('D' . $row)
-            ->getNumberFormat()
-            ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-            $sheet->mergeCells('F' . $row . ':G' . $row);
-            $sheet->setCellValue('F' . $row, $fecha); 
-            $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-            
-            $sheet->mergeCells('H' . $row . ':J' . $row);
-            $sheet->setCellValue('H' . $row, $obraPago->descripcion);
-            $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Pago.xlsx");
-        } catch (\Exception $exception) {
-          return null;
-        }
+    foreach ($celdas as $coordenada => $valor) {
+      $this->agregarCelda($coordenada, $valor);
     }
     }
 
 
+    $this->renglonActual = 6;
+
+    return $this;
+  }
+
+    public function actionExcelObraPago($idObra) {
+        $json = intval($this->req->get("json", ""));
 
 
-    public function actionExcelPago($idObra) {
         $obra = Obra::findOne($idObra);
         $obra = Obra::findOne($idObra);
-          $request = Yii::$app->request;
-          $query= Pago::find()	
+        $query= Pago::find()	
           ->joinWith('conceptosObra')
           ->joinWith('conceptosObra')
           ->andWhere(['{{Pago}}.[[eliminado]]'=>null])->andWhere(['{{Pago}}.[[idObra]]'=>$idObra]);
           ->andWhere(['{{Pago}}.[[eliminado]]'=>null])->andWhere(['{{Pago}}.[[idObra]]'=>$idObra]);
-          $query->orderBy(['creado' => SORT_DESC]);
-          $spreadsheet = new Spreadsheet();
-          $sheet = $spreadsheet->getActiveSheet();
-          $sheet->setTitle('Pagos de la obra');
-  
-          $BASEPATH = \Yii::getAlias('@app') . "/web";
-          $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-          $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-          $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-          $drawing = new Drawing();
-          $drawing->setName('Logotipo');
-          $drawing->setDescription('Logotipo de la empresa');
-          $drawing->setPath($logo);
-          $drawing->setHeight(70);
-          $drawing->setCoordinates('A1');
-          $drawing->setOffsetX(10);
-          $drawing->setOffsetY(10);
-          $drawing->setWorksheet($sheet);
-  
-          $sheet->mergeCells('A5:J5');
-          $sheet->setCellValue('A5','Pagos relacionado a la obra: ' . $obra->nombre);
-          $sheet->mergeCells('A6:E6');
-          $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-          $sheet->mergeCells('F6:J6');
-          $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-          $sheet->getStyle('A5')->getFont()->setBold(true);
-          $sheet->getStyle('A5')->getFont()->setSize(16);
-  
-          $headerStyle = [
-            'font' => [
-                'bold' => true,
-                'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-            ],
-            'alignment' => [
-                'horizontal' => Alignment::HORIZONTAL_CENTER,
-                'vertical' => Alignment::VERTICAL_CENTER,
-                'wrapText' => true
+          $query->orderBy(['fechaPago' => SORT_DESC]);
+        if ($json) {
+          \Yii::$app->getResponse()->format = Response::FORMAT_JSON;
+          return $json;
+        }
+    
+        $BASEPATH = \Yii::getAlias('@app') . "/web";
+        $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+        $this->encabezadoHoja($this->logo($logo, 'A1'));
+        $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
+        $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
+        $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+        $encabezadoTabla = [
+          "A6" => [
+            "valor" => "Pagos relacionado a la obra: $obra->nombre",
+            "combinar" => "D6",
+            "estilo" => $estiloEncabezado
+          ],
+          "A7" => [
+            "valor" => "Fecha Inicial: $fechaInicio ",
+            "combinar" => "B7",
+            "estilo" => $estiloEncabezado
+          ],
+          "C7" => [
+            "valor" => "Fecha Final: $fechaFin",
+            "combinar" => "D7",
+            "estilo" => $estiloEncabezado
+          ]
+        ];
+    
+        $this->agregarRenglones($encabezadoTabla);
+    
+        $encabezadoTabla = [
+          "A9" => [
+            "valor" => "Concepto Obra",
+            "estilo" => $estiloEncabezado
+          ],
+          "B9" => [
+            "valor" => "Cantidad ",
+            "estilo" => $estiloEncabezado
+          ],
+          "C9" => [
+            "valor" => "Fecha Pago",
+            "estilo" => $estiloEncabezado
+          ],
+          "D9" => [
+            "valor" => "Descripción",
+            "estilo" => $estiloEncabezado
+          ]
+        ];
+    
+        $r = 10;
+        $this->agregarRenglones($encabezadoTabla);
+        $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+        $estiloCondicional = $this->estiloCondicional();
+    
+        foreach ($query->each() as $obraPago) {
+          $fecha = (new DateTime($obraPago->fechaPago))->format('d-m-Y');
+          $Pago = $obraPago->conceptosObra;
+    
+          $renglones = [
+            "A{$r}" => [
+              "valor" => $Pago->concepto,
+              "estilo" => $estiloCeldaIzquierda
             ],
             ],
-            'fill' => [
-                'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-                'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
+            "B{$r}" => [
+              "valor" => $obraPago->cantidad,
+              "estilo" => $estiloCeldaIzquierda,
+              "formato" => "$#,##0.00",
+              "estiloCondicional" => $estiloCondicional
+    
             ],
             ],
-            'borders' => [
-                'allBorders' => [
-                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                    'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-                ],
+            "C{$r}" => [
+              "valor" => $fecha,
+              "estilo" => $estiloCeldaIzquierda
             ],
             ],
+            "D{$r}" => [
+              "valor" => $obraPago->descripcion,
+              "estilo" => $estiloCeldaIzquierda
+            ]
+          ];
+          $this->agregarRenglones($renglones);
+          $r += 1;
+        }
+        $anchoColumnas = [
+          "A" => ["ancho" => 20],
+          "B" => ["ancho" => 20],
+          "C" => ["ancho" => 20],
+          "D" => ["ancho" => 20],
         ];
         ];
-        
-        
-        
-        // Aplicar el borde a las celdas combinadas
-        $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-        $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-        $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-         
-        $sheet->mergeCells('A8:C8');
-        $sheet->setCellValue('A8', 'Concepto Obra');
-        $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('D8:E8');
-        $sheet->setCellValue('D8', 'Cantidad');
-        $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('F8:G8');
-        $sheet->setCellValue('F8', 'Fecha Pago');
-        $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('H8:J8');
-        $sheet->setCellValue('H8', 'Descripción');
-        $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-        $cellBorderStyle = [
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF000000'], // Color negro
-              ],
-          ],
-      ];
-        $row = 9;
-  
-          foreach ($query->each() as $obraPago) {
-              $fecha = (new DateTime($obraPago->fechaPago))->format('d-m-Y');
-  
-              $gasto = $obraPago->conceptosObra; 
-              $sheet->mergeCells('A' . $row . ':C' . $row);
-             $sheet->setCellValue('A' . $row, $gasto->concepto);
-              $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
-  
-              $sheet->mergeCells('D' . $row . ':E' . $row);
-              $sheet->setCellValue('D' . $row, $obraPago->cantidad); 
-              $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-              $sheet->getStyle('D' . $row)
-              ->getNumberFormat()
-              ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-              $sheet->mergeCells('F' . $row . ':G' . $row);
-              $sheet->setCellValue('F' . $row, $fecha); 
-              $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-              
-              $sheet->mergeCells('H' . $row . ':J' . $row);
-              $sheet->setCellValue('H' . $row, $obraPago->descripcion);
-              $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-              $row++;
-          }
-         
-         
-          $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-          $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-          try {
-           return $sheet;
-          } catch (\Exception $exception) {
-            return null;
-          }
+        $this->anchoColumnas($anchoColumnas);
+        $documento = $this->obtenerHojaDeCalculo();
+        $this->crear($documento,  "Pago_" . date("YmdHis"), self::TIPO_EXCEL);
+        \Yii::$app->end();
       }
       }
+
   }
   }

+ 189 - 247
modules/excel/controllers/ObraRubroController.php

@@ -1,269 +1,211 @@
 <?php
 <?php
 
 
 namespace app\modules\excel\controllers;
 namespace app\modules\excel\controllers;
+
 use DateTime;
 use DateTime;
 use DateTimeZone;
 use DateTimeZone;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
-use v1\models\Nomina;
 use v1\models\Obra;
 use v1\models\Obra;
 use v1\models\ObraRubro;
 use v1\models\ObraRubro;
-use v1\models\Pago;
+
 use Yii;
 use Yii;
-use yii\web\Controller;
+use excel\web\Controller;
 
 
-class ObraRubroController extends Controller {
+class ObraRubroController extends Controller
+{
 
 
-    public function actionExcelObraRubro($idObra) {
-      $obra = Obra::findOne($idObra);
-        $request = Yii::$app->request;
-        $query= ObraRubro::find()	
-        ->joinWith('conceptoObra')
-        ->andWhere(['{{ObraRubro}}.[[eliminado]]'=>null])->andWhere(['{{ObraRubro}}.[[idObra]]'=>$idObra]);
-        $query->orderBy(['creado' => SORT_DESC]);
-        $spreadsheet = new Spreadsheet();
-        $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('Rubro de la obra');
 
 
-        $BASEPATH = \Yii::getAlias('@app') . "/web";
-        $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-        $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-        $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-        $drawing = new Drawing();
-        $drawing->setName('Logotipo');
-        $drawing->setDescription('Logotipo de la empresa');
-        $drawing->setPath($logo);
-        $drawing->setHeight(70);
-        $drawing->setCoordinates('A1');
-        $drawing->setOffsetX(10);
-        $drawing->setOffsetY(10);
-        $drawing->setWorksheet($sheet);
+  public static $estiloCeldaIzquierda12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 12,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER,
+    ],
+  ];
 
 
-        $sheet->mergeCells('A5:J5');
-        $sheet->setCellValue('A5','Rubro relacionado a la obra: ' . $obra->nombre);
-        $sheet->mergeCells('A6:E6');
-        $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-        $sheet->mergeCells('F6:J6');
-        $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-        $sheet->getStyle('A5')->getFont()->setBold(true);
-        $sheet->getStyle('A5')->getFont()->setSize(16);
+  public static $celdaVertical = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FFFFFFFF'],
+    ],
+    'alignment' => [
+      // 'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FF625FF5"]
+    ],
+  ];
 
 
-        $headerStyle = [
-          'font' => [
-              'bold' => true,
-              'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-          ],
-          'alignment' => [
-              'horizontal' => Alignment::HORIZONTAL_CENTER,
-              'vertical' => Alignment::VERTICAL_CENTER,
-              'wrapText' => true
-          ],
-          'fill' => [
-              'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-              'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-          ],
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-              ],
-          ],
-      ];
-      
-      
-      
-      // Aplicar el borde a las celdas combinadas
-      $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-      $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-      $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-       
-      $sheet->mergeCells('A8:C8');
-      $sheet->setCellValue('A8', 'Concepto Obra');
-      $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('D8:E8');
-      $sheet->setCellValue('D8', 'Cantidad');
-      $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('F8:G8');
-      $sheet->setCellValue('F8', 'Fecha Compra');
-      $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-      $sheet->mergeCells('H8:J8');
-      $sheet->setCellValue('H8', 'Descripción');
-      $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-      
-      $cellBorderStyle = [
-        'borders' => [
-            'allBorders' => [
-                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                'color' => ['argb' => 'FF000000'], // Color negro
-            ],
-        ],
-    ];
-      $row = 9;
+  public static $celdaHorizontal = [
+    'font' => [
+      'bold' => true,
+      'size' => 14,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+
+  public static $celdaFuente12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'horizontal' => Alignment::HORIZONTAL_LEFT,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+  ];
 
 
-        foreach ($query->each() as $obraRubro) {
-            $fecha = (new DateTime($obraRubro->fechaCompra))->format('d-m-Y');
+  public static $celdaVerticalF12 = [
+    'font' => [
+      'bold' => true,
+      'size' => 10,
+      'color' => ['argb' => 'FF000000'],
+    ],
+    'alignment' => [
+      'textRotation' => 90,
+      'horizontal' => Alignment::HORIZONTAL_CENTER,
+      'vertical' => Alignment::VERTICAL_CENTER
+    ],
+    'fill' => [
+      'fillType' => Fill::FILL_SOLID,
+      'startColor' => ['argb' => "FFE7E7E7"]
+    ],
+  ];
+  public function encabezadoHoja($logo)
+  {
 
 
-            $gasto = $obraRubro->conceptoObra; 
-            $sheet->mergeCells('A' . $row . ':C' . $row);
-           $sheet->setCellValue('A' . $row, $gasto->concepto); 
-            $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
+    $celdas = [
+      "A1" => [
+        "valor" => $logo,
+        "combinar" => "G4",
+      ],
+    ];
 
 
-            $sheet->mergeCells('D' . $row . ':E' . $row);
-            $sheet->setCellValue('D' . $row, $obraRubro->cantidad); 
-            $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-            $sheet->getStyle('D' . $row)
-            ->getNumberFormat()
-            ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-            $sheet->mergeCells('F' . $row . ':G' . $row);
-            $sheet->setCellValue('F' . $row, $fecha); 
-            $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-            
-            $sheet->mergeCells('H' . $row . ':J' . $row);
-            $sheet->setCellValue('H' . $row, $obraRubro->descripcion);
-            $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-            $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-            $row++;
-        }
-       
-       
-        $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-        try {
-          ob_start();
-          $writer->save("php://output");
-          $documento = ob_get_contents();
-          ob_clean();
-          Yii::$app->getResponse()->sendContentAsFile($documento, "Rubro.xlsx");
-        } catch (\Exception $exception) {
-          return null;
-        }
+    foreach ($celdas as $coordenada => $valor) {
+      $this->agregarCelda($coordenada, $valor);
     }
     }
 
 
-    public function actionExcelRubro($idObra) {
-        $obra = Obra::findOne($idObra);
-          $request = Yii::$app->request;
-          $query= ObraRubro::find()	
-          ->joinWith('conceptoObra')
-          ->andWhere(['{{ObraRubro}}.[[eliminado]]'=>null])->andWhere(['{{ObraRubro}}.[[idObra]]'=>$idObra]);
-          $query->orderBy(['creado' => SORT_DESC]);
-          $spreadsheet = new Spreadsheet();
-          $sheet = $spreadsheet->getActiveSheet();
-          $sheet->setTitle('Rubro de la obra');
-  
-          $BASEPATH = \Yii::getAlias('@app') . "/web";
-          $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
-          $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
-          $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
-          $drawing = new Drawing();
-          $drawing->setName('Logotipo');
-          $drawing->setDescription('Logotipo de la empresa');
-          $drawing->setPath($logo);
-          $drawing->setHeight(70);
-          $drawing->setCoordinates('A1');
-          $drawing->setOffsetX(10);
-          $drawing->setOffsetY(10);
-          $drawing->setWorksheet($sheet);
-  
-          $sheet->mergeCells('A5:J5');
-          $sheet->setCellValue('A5','Rubro relacionado a la obra: ' . $obra->nombre);
-          $sheet->mergeCells('A6:E6');
-          $sheet->setCellValue('A6','Fecha Inicial: ' .$fechaInicio);
-          $sheet->mergeCells('F6:J6');
-          $sheet->setCellValue('F6','Fecha Final: ' .$fechaFin);
-          $sheet->getStyle('A5')->getFont()->setBold(true);
-          $sheet->getStyle('A5')->getFont()->setSize(16);
-  
-          $headerStyle = [
-            'font' => [
-                'bold' => true,
-                'color' => ['argb' => 'FFFFFFFF'] // Letras en blanco
-            ],
-            'alignment' => [
-                'horizontal' => Alignment::HORIZONTAL_CENTER,
-                'vertical' => Alignment::VERTICAL_CENTER,
-                'wrapText' => true
-            ],
-            'fill' => [
-                'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
-                'startColor' => ['argb' => 'FF625FF5'] // Fondo azul (con opacidad FF)
-            ],
-            'borders' => [
-                'allBorders' => [
-                    'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                    'color' => ['argb' => 'FF020073'], // Bordes azul oscuro (con opacidad FF)
-                ],
-            ],
-        ];
-        
-        
-        
-        // Aplicar el borde a las celdas combinadas
-        $sheet->getStyle('A5:J5')->applyFromArray( $headerStyle);
-        $sheet->getStyle('A6:E6')->applyFromArray( $headerStyle);
-        $sheet->getStyle('F6:J6')->applyFromArray( $headerStyle);
-         
-        $sheet->mergeCells('A8:C8');
-        $sheet->setCellValue('A8', 'Concepto Obra');
-        $sheet->getStyle('A8:C8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('D8:E8');
-        $sheet->setCellValue('D8', 'Cantidad');
-        $sheet->getStyle('D8:E8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('F8:G8');
-        $sheet->setCellValue('F8', 'Fecha Compra');
-        $sheet->getStyle('F8:G8')->applyFromArray( $headerStyle);
-        $sheet->mergeCells('H8:J8');
-        $sheet->setCellValue('H8', 'Descripción');
-        $sheet->getStyle('H8:J8')->applyFromArray( $headerStyle);
-        
-        $cellBorderStyle = [
-          'borders' => [
-              'allBorders' => [
-                  'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
-                  'color' => ['argb' => 'FF000000'], // Color negro
-              ],
-          ],
+    $this->renglonActual = 6;
+
+    return $this;
+  }
+
+  public function actionExcelObraRubro($idObra)
+  {
+    $obra = Obra::findOne($idObra);
+    $request = Yii::$app->request;
+    $query = ObraRubro::find()
+      ->joinWith('conceptoObra')
+      ->andWhere(['{{ObraRubro}}.[[eliminado]]' => null])->andWhere(['{{ObraRubro}}.[[idObra]]' => $idObra]);
+    $query->orderBy(['creado' => SORT_DESC]);
+    $BASEPATH = \Yii::getAlias('@app') . "/web";
+    $logo = $BASEPATH . '/img/logos/edesarrollos-unicolor-azul.png';
+    $fechaInicio = (new DateTime($obra->fechaInicio))->format('d-m-Y');
+    $fechaFin = (new DateTime($obra->fechaFinal))->format('d-m-Y');
+    $this->encabezadoHoja($this->logo($logo, 'A1'));
+    $estiloEncabezado = array_merge(self::$celdaVertical, self::$bordes);
+
+    $encabezadoTabla = [
+      "A6" => [
+        "valor" => "Rubro relacionado a la obra: $obra->nombre",
+        "combinar" => "D6",
+        "estilo" => $estiloEncabezado
+      ],
+      "A7" => [
+        "valor" => "Fecha Inicial: $fechaInicio ",
+        "combinar" => "B7",
+        "estilo" => $estiloEncabezado
+      ],
+      "C7" => [
+        "valor" => "Fecha Final: $fechaFin",
+        "combinar" => "D7",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+
+    $this->agregarRenglones($encabezadoTabla);
+
+    $encabezadoTabla = [
+      "A9" => [
+        "valor" => "Concepto Obra",
+        "estilo" => $estiloEncabezado
+      ],
+      "B9" => [
+        "valor" => "Cantidad ",
+        "estilo" => $estiloEncabezado
+      ],
+      "C9" => [
+        "valor" => "Fecha Compra",
+        "estilo" => $estiloEncabezado
+      ],
+      "D9" => [
+        "valor" => "Descripción",
+        "estilo" => $estiloEncabezado
+      ]
+    ];
+    $r = 10;
+    $this->agregarRenglones($encabezadoTabla);
+    $estiloCeldaIzquierda = array_merge(self::$bordes, self::$celdaFuente12);
+    $estiloCondicional = $this->estiloCondicional();
+    foreach ($query->each() as $obraRubro) {
+      $fecha = (new DateTime($obraRubro->fechaCompra))->format('d-m-Y');
+
+      $rubro = $obraRubro->conceptoObra;
+      $renglones = [
+        "A{$r}" => [
+          "valor" => $rubro->concepto,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "B{$r}" => [
+          "valor" => $obraRubro->cantidad,
+          "estilo" => $estiloCeldaIzquierda,
+          "formato" => "$#,##0.00",
+          "estiloCondicional" => $estiloCondicional
+
+        ],
+        "C{$r}" => [
+          "valor" =>  $fecha,
+          "estilo" => $estiloCeldaIzquierda
+        ],
+        "D{$r}" => [
+          "valor" => $obraRubro->descripcion,
+          "estilo" => $estiloCeldaIzquierda
+        ]
       ];
       ];
-        $row = 9;
-  
-          foreach ($query->each() as $obraRubro) {
-              $fecha = (new DateTime($obraRubro->fechaCompra))->format('d-m-Y');
-  
-              $gasto = $obraRubro->conceptoObra; 
-              $sheet->mergeCells('A' . $row . ':C' . $row);
-             $sheet->setCellValue('A' . $row, $gasto->concepto); 
-              $sheet->getStyle('A' . $row . ':C' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('A' . $row . ':C' . $row)->applyFromArray($cellBorderStyle);
-  
-              $sheet->mergeCells('D' . $row . ':E' . $row);
-              $sheet->setCellValue('D' . $row, $obraRubro->cantidad); 
-              $sheet->getStyle('D' . $row . ':E' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('D' . $row . ':E' . $row)->applyFromArray($cellBorderStyle);
-              $sheet->getStyle('D' . $row)
-              ->getNumberFormat()
-              ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
-              $sheet->mergeCells('F' . $row . ':G' . $row);
-              $sheet->setCellValue('F' . $row, $fecha); 
-              $sheet->getStyle('F' . $row . ':G' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('F' . $row . ':G' . $row)->applyFromArray($cellBorderStyle);
-              
-              $sheet->mergeCells('H' . $row . ':J' . $row);
-              $sheet->setCellValue('H' . $row, $obraRubro->descripcion);
-              $sheet->getStyle('H' . $row . ':J' . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY);
-              $sheet->getStyle('H' . $row . ':J' . $row)->applyFromArray($cellBorderStyle);
-              $row++;
-          }
-         
-         
-          $sheet->getStyle('A5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-          $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
-          try {
-           return $sheet;
-          } catch (\Exception $exception) {
-            return null;
-          }
-      }
-}
+      $this->agregarRenglones($renglones);
+      $r += 1;
+    }
+    $anchoColumnas = [
+      "A" => ["ancho" => 20],
+      "B" => ["ancho" => 20],
+      "C" => ["ancho" => 20],
+      "D" => ["ancho" => 20],
+    ];
+    $this->anchoColumnas($anchoColumnas);
+
+    $documento = $this->obtenerHojaDeCalculo();
+    $this->crear($documento,  "Rubro_" . date("YmdHis"), self::TIPO_EXCEL);
+    \Yii::$app->end();
+  }
+
+}

+ 37 - 0
modules/excel/web/Controller.php

@@ -9,6 +9,8 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 use PhpOffice\PhpSpreadsheet\IOFactory;
 use PhpOffice\PhpSpreadsheet\IOFactory;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Border;
 use PhpOffice\PhpSpreadsheet\Style\Border;
+use PhpOffice\PhpSpreadsheet\Style\Color;
+use PhpOffice\PhpSpreadsheet\Style\Conditional;
 use PhpOffice\PhpSpreadsheet\Style\Fill;
 use PhpOffice\PhpSpreadsheet\Style\Fill;
 use yii\filters\auth\CompositeAuth;
 use yii\filters\auth\CompositeAuth;
 use yii\filters\auth\QueryParamAuth;
 use yii\filters\auth\QueryParamAuth;
@@ -520,4 +522,39 @@ class Controller extends WebController {
       echo $e->getMessage();
       echo $e->getMessage();
     }
     }
   }
   }
+  public function estiloCondicional() {
+    $condicionalRojo = new Conditional();
+    $condicionalRojo->setConditionType(Conditional::CONDITION_CELLIS)
+      ->setOperatorType(Conditional::OPERATOR_LESSTHAN)
+      ->addCondition('0');
+    $colorRojo = "FFFEC7CF";
+    $condicionalRojo->getStyle()->getFont()->setBold(true)->getColor()->setARGB(Color::COLOR_BLACK);
+    $condicionalRojo->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
+    $condicionalRojo->getStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
+    $condicionalRojo->getStyle()->getFill()->setFillType(Fill::FILL_SOLID);
+    $condicionalRojo->getStyle()->getFill()->getStartColor()->setARGB($colorRojo);
+    $condicionalRojo->getStyle()->getFill()->getEndColor()->setARGB($colorRojo);
+    $condicionalRojo->getStyle()->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalRojo->getStyle()->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalRojo->getStyle()->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalRojo->getStyle()->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+
+    $condicionalVerde = new Conditional();
+    $condicionalVerde->setConditionType(Conditional::CONDITION_CELLIS)
+      ->setOperatorType(Conditional::OPERATOR_GREATERTHAN)
+      ->addCondition('0');
+    $colorVerde = "FFC6EFCD";
+    $condicionalVerde->getStyle()->getFont()->setBold(true)->getColor()->setARGB(Color::COLOR_BLACK);
+    $condicionalVerde->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
+    $condicionalVerde->getStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
+    $condicionalVerde->getStyle()->getFill()->setFillType(Fill::FILL_SOLID);
+    $condicionalVerde->getStyle()->getFill()->getStartColor()->setARGB($colorVerde);
+    $condicionalVerde->getStyle()->getFill()->getEndColor()->setARGB($colorVerde);
+    $condicionalVerde->getStyle()->getBorders()->getTop()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalVerde->getStyle()->getBorders()->getBottom()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalVerde->getStyle()->getBorders()->getLeft()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+    $condicionalVerde->getStyle()->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FF000000');
+
+    return [$condicionalRojo, $condicionalVerde];
+  }
 }
 }