Implementacion de modulo de pedidos
This commit is contained in:
63
app/Http/Livewire/ReportePedidoController.php
Normal file
63
app/Http/Livewire/ReportePedidoController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Exports\PedidosExport;
|
||||
use App\Models\Pedido;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ReportePedidoController extends Component
|
||||
{
|
||||
public $fecha_inicio, $fecha_final;
|
||||
public $fn_inicio, $fn_final;
|
||||
public $is_venta_cerrada = "", $is_venta_entregada ="";
|
||||
|
||||
public function render()
|
||||
{
|
||||
$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->fn_inicio && $this->fn_final), function ($query) {
|
||||
return $query->whereBetween('created_at', [$this->fn_inicio, $this->fn_final]);
|
||||
});
|
||||
return view('pedido.reporte-pedido',[
|
||||
'pedidos' => $query->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()
|
||||
{
|
||||
$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->fn_inicio && $this->fn_final), function ($query) {
|
||||
return $query->whereBetween('created_at', [$this->fn_inicio, $this->fn_final]);
|
||||
});
|
||||
|
||||
return Excel::download(new PedidosExport($this->fn_inicio, $this->fn_final,$this->is_venta_cerrada,$this->is_venta_entregada),'pedido-'.Carbon::now()->format('Y-m-d').'.xlsx');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user