Finalizacion de la primera version del proyecto
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Venta;
|
||||
use App\Models\CajaMovimiento;
|
||||
use App\Models\Movimiento;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Component;
|
||||
@@ -10,36 +11,74 @@ use Livewire\Component;
|
||||
class DashboardController extends Component
|
||||
{
|
||||
const ESTADO_VENTA =1, ESTADO_ABONO = 2, ESTADO_CANCELACION = 3;
|
||||
public $cajaModal = false, $cajaInicial;
|
||||
public function render()
|
||||
{
|
||||
$venta = $this->totalDiaTipoVenta(DashboardController::ESTADO_VENTA);
|
||||
$abono = $this->totalDiaTipoVenta(DashboardController::ESTADO_ABONO);
|
||||
$cancelacion = $this->totalDiaTipoVenta(DashboardController::ESTADO_CANCELACION);
|
||||
// dd(Movimiento::where([
|
||||
// ['estado_movimiento_id','=', DashboardController::ESTADO_VENTA],
|
||||
// [DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
|
||||
// ])->count());
|
||||
$movimiento = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_VENTA);
|
||||
$abono = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_ABONO);
|
||||
$cancelacion = $this->totalDiaTipoMovimiento(DashboardController::ESTADO_CANCELACION);
|
||||
|
||||
$this->validarCaja();
|
||||
|
||||
return view('dashboard',[
|
||||
'venta' => $venta,
|
||||
'movimiento' => $movimiento,
|
||||
'abono' => $abono,
|
||||
'cancelacion' => $cancelacion
|
||||
'cancelacion' => $cancelacion,
|
||||
'num_movimiento' => Movimiento::where([
|
||||
['estado_movimiento_id','=', DashboardController::ESTADO_VENTA],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
|
||||
])->count(),
|
||||
'num_abono' => Movimiento::where([
|
||||
['estado_movimiento_id','=', DashboardController::ESTADO_ABONO],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
|
||||
])->count(),
|
||||
'num_cancelacion' => Movimiento::where([
|
||||
['estado_movimiento_id','=', DashboardController::ESTADO_CANCELACION],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')]
|
||||
])->count(),
|
||||
'caja' => CajaMovimiento::cajaInicial(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function totalDiaTipoVenta($tipo_venta)
|
||||
public function totalDiaTipoMovimiento($tipo_movimiento)
|
||||
{
|
||||
return
|
||||
Venta::where([
|
||||
['estado_venta_id','=', $tipo_venta],
|
||||
Movimiento::where([
|
||||
['estado_movimiento_id','=', $tipo_movimiento],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
|
||||
])->sum('pago_efectivo') +
|
||||
Venta::where([
|
||||
['estado_venta_id','=', $tipo_venta],
|
||||
Movimiento::where([
|
||||
['estado_movimiento_id','=', $tipo_movimiento],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
|
||||
])->sum('pago_tarjeta_debito') +
|
||||
Venta::where([
|
||||
['estado_venta_id','=', $tipo_venta],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
|
||||
])->sum('pago_tarjeta_credito') +
|
||||
Venta::where([
|
||||
['estado_venta_id','=', $tipo_venta],
|
||||
])->sum('pago_tarjeta') +
|
||||
Movimiento::where([
|
||||
['estado_movimiento_id','=', $tipo_movimiento],
|
||||
[DB::raw('DATE(created_at)'),'=',Carbon::now()->format('Y-m-d')],
|
||||
])->sum('pago_vales');
|
||||
}
|
||||
|
||||
public function validarCaja()
|
||||
{
|
||||
if(!CajaMovimiento::cajaInicial()->count())
|
||||
{
|
||||
$this->cajaModal = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate([
|
||||
'cajaInicial' => 'required|numeric',
|
||||
]);
|
||||
CajaMovimiento::create([
|
||||
'cantidad' => $this->cajaInicial,
|
||||
'estado_caja_movimiento_id' => CajaMovimiento::CODIGO_CAJA,
|
||||
'user_id' => auth()->user()->id,
|
||||
]);
|
||||
$this->cajaModal = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user