diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index 273237d..3395925 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -12,6 +12,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use League\Csv\Exception; +use Mpdf\MpdfException; class GrupoDeCompra extends Model { @@ -37,7 +38,14 @@ class GrupoDeCompra extends Model public function pedidosAprobados() { - return $this->subpedidos->where('aprobado', 1); + return $this->pedidosHogares() + ->where('aprobado', 1); + } + + public function pedidosHogares() + { + return $this->subpedidos + ->where('tipo_pedido_id', '=', 1); } public function totalARecaudar() @@ -120,11 +128,15 @@ class GrupoDeCompra extends Model return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte()); } + /** + * @throws MpdfException + */ public function exportarPedidosAPdf() { $subpedidos = $this->pedidosAprobados(); $fecha = now()->format('Y-m-d'); - PdfHelper::exportarPedidos($this->nombre . '-' . $fecha . '.pdf', $subpedidos); + $filepath = $this->nombre . '-' . $fecha . '.pdf'; + PdfHelper::exportarPedidos($filepath, $subpedidos); } function pedidoParaPdf(): array @@ -154,11 +166,15 @@ class GrupoDeCompra extends Model return $view->render(); } + /** + * @throws MpdfException + */ public static function exportarPedidosBarrialesAPdf() { $barrios = GrupoDeCompra::barriosMenosPrueba()->get(); $fecha = now()->format('Y-m-d'); - PdfHelper::exportarPedidos('pedidos_por_barrio-' . $fecha . '.pdf', $barrios); + $filepath = 'pedidos_por_barrio-' . $fecha . '.pdf'; + PdfHelper::exportarPedidos($filepath, $barrios); } static function filaVacia(string $product, int $columns): array