43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Exports\VentasExport;
|
|
use App\Models\Movimiento;
|
|
use App\Models\Venta;
|
|
use Carbon\Carbon;
|
|
use Livewire\Component;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class ReporteController extends Component
|
|
{
|
|
public $fecha_inicio, $fecha_final;
|
|
public $fn_inicio, $fn_final;
|
|
|
|
public function render()
|
|
{
|
|
return view('venta.reporte',[
|
|
'movimientos' => Movimiento::whereBetween('created_at',[$this->fn_inicio,$this->fn_final])->get(),
|
|
]);
|
|
}
|
|
|
|
public function updatedFechaInicio()
|
|
{
|
|
$this->fn_inicio= Carbon::parse($this->fecha_inicio)->startOfDay();
|
|
}
|
|
|
|
public function updatedFechaFinal()
|
|
{
|
|
$this->fn_final= Carbon::parse($this->fecha_final)->endOfDay();
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
$this->validate([
|
|
'fecha_inicio' => 'required|date',
|
|
'fecha_final' => 'required|date',
|
|
]);
|
|
return Excel::download(new VentasExport($this->fn_inicio, $this->fn_final),'venta-'.Carbon::now()->format('Y-m-d').'.xlsx');
|
|
}
|
|
}
|