exportar-planillas #9

Merged
atasistro merged 4 commits from exportar-planillas into master 2022-09-06 21:48:11 -03:00
5 changed files with 28 additions and 2 deletions
Showing only changes of commit 1aa112aac2 - Show all commits

View file

@ -3,6 +3,7 @@
namespace App; namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Mpdf\Mpdf;
class GrupoDeCompra extends Model class GrupoDeCompra extends Model
{ {
@ -15,4 +16,18 @@ class GrupoDeCompra extends Model
return $this->hasMany('App\Subpedido'); return $this->hasMany('App\Subpedido');
} }
public function exportarPlanillasAPdf() {
$subpedidos = $this->subpedidos;
//generar pdf
$mpdf = new Mpdf();;
foreach ($subpedidos as $subpedido) {
$tabla = $subpedido->generarHTML();
// agregar la tabla al pdf en una nueva página
$mpdf->WriteHTML($tabla);
$mpdf->AddPage();
}
// imprimir el pdf
$mpdf->Output();
}
} }

View file

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\GrupoDeCompra;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class AdminController extends Controller class AdminController extends Controller
@ -14,4 +15,8 @@ class AdminController extends Controller
public function index() { public function index() {
return view('auth/admin_subpedidos'); return view('auth/admin_subpedidos');
} }
public function exportarPlanillasAPdf(GrupoDeCompra $gdc) {
return $gdc->exportarPlanillasAPdf();
}
} }

View file

@ -24,7 +24,7 @@ class Subpedido extends Model
return $this->productos()->where('bono',1); return $this->productos()->where('bono',1);
} }
private function productosSinBonos() public function productosSinBonos()
{ {
return $this->productos()->where('bono',false); return $this->productos()->where('bono',false);
} }
@ -90,4 +90,9 @@ class Subpedido extends Model
$this->save(); $this->save();
} }
public function generarHTML() {
$view = view("pdfgen.subpedido_tabla", ["subpedido" => $this]);
return $view->render();
}
} }

View file

@ -0,0 +1 @@
<?php