58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Exports;
|
|
|
|
use App\Invoice;
|
|
use App\Models\Movimiento;
|
|
use App\Models\Pedido;
|
|
use Illuminate\Contracts\View\View;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
|
|
|
class PedidosExport implements FromView{
|
|
|
|
public $fecha_inicio, $fecha_final;
|
|
public $is_venta_cerrada, $is_venta_entregada;
|
|
|
|
public function __construct($fecha_inicio, $fecha_final, $is_venta_cerrada, $is_venta_entregada)
|
|
{
|
|
$this->fecha_inicio = $fecha_inicio;
|
|
$this->fecha_final = $fecha_final;
|
|
$this->is_venta_cerrada = $is_venta_cerrada;
|
|
$this->is_venta_entregada = $is_venta_entregada;
|
|
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
return Pedido::select(
|
|
'pedido',
|
|
'cuenta',
|
|
'telefono',
|
|
'year',
|
|
'marca',
|
|
'modelo',
|
|
'motor',
|
|
)->get();
|
|
}
|
|
|
|
public function view(): View
|
|
{
|
|
$query = Pedido::query();
|
|
|
|
$query->when($this->is_venta_entregada, function ($query) {
|
|
return $query->where('is_venta_entregada',"=",$this->is_venta_entregada);
|
|
});
|
|
$query->when($this->is_venta_cerrada, function ($query) {
|
|
return $query->where('is_venta_cerrada',"=",$this->is_venta_cerrada);
|
|
});
|
|
|
|
$query->when(($this->fecha_inicio && $this->fecha_final), function ($query) {
|
|
return $query->whereBetween('created_at', [$this->fecha_inicio, $this->fecha_final]);
|
|
});
|
|
|
|
return view('export.reportePedidoExport',[
|
|
// 'pedidos' => Pedido::whereBetween('created_at',[$this->fecha_inicio,$this->fecha_final])->get(),
|
|
'pedidos' => $query->get(),
|
|
]);
|
|
}
|
|
} |