nueva tabla pendientes

This commit is contained in:
Felipe
2023-10-17 15:38:54 -05:00
parent 0c15e3c3b0
commit c7ba02a974
5 changed files with 296 additions and 186 deletions
+80 -39
View File
@@ -7,9 +7,11 @@ use App\Models\Configuracione;
use App\Models\Cuentas; use App\Models\Cuentas;
use App\Models\Historial_cuenta; use App\Models\Historial_cuenta;
use App\Models\Historiale; use App\Models\Historiale;
use App\Models\Pendientes;
use App\Models\Promocion_tarifa; use App\Models\Promocion_tarifa;
use App\Models\Promociones; use App\Models\Promociones;
use App\Models\Saldo; use App\Models\Saldo;
use App\Models\Servicio;
use App\Models\Tarifas; use App\Models\Tarifas;
use App\Models\User; use App\Models\User;
use App\Notifications\compra; use App\Notifications\compra;
@@ -191,6 +193,17 @@ class ShowPromociones extends Component
/* ---------------- Btn Comprar ---------------- */ /* ---------------- Btn Comprar ---------------- */
public function getListeners()
{
return [
'confirmed', 'confirmarCompra', 'denegarCompra'
];
}
public $historial;
public $n = [];
public $f = [];
public $r = 0;
public function pagar() public function pagar()
{ {
@@ -227,18 +240,20 @@ class ShowPromociones extends Component
$historial->utilidad = $this->utilidad * $this->cantidad_comprarPromo; $historial->utilidad = $this->utilidad * $this->cantidad_comprarPromo;
$historial->save(); $historial->save();
$this->historial = $historial;
for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) { for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) {
//dd($this->cantidad_comprarPromo); //dd($this->cantidad_comprarPromo);
$n=[]; $this->n = [];
$r=0; $this->f = [];
$this->r = 0;
foreach ($this->consulta->tarifas as $tarifa) { foreach ($this->consulta->tarifas as $tarifa) {
$r=$r+$tarifa->pantallas; $this->r = $this->r + $tarifa->pantallas;
//dd($this->consulta->tarifas->count());
$pantallas_tarifa = $tarifa->pantallas; $pantallas_tarifa = $tarifa->pantallas;
$servicio_id = $tarifa->servicio_id; $servicio_id = $tarifa->servicio_id;
$pantalla_servicio = $tarifa->servicio->pantallas; $pantalla_servicio = $tarifa->servicio->pantallas;
$pantalla_servicio_completa = $tarifa->servicio->completa; $pantalla_servicio_completa = $tarifa->servicio->completa;
$faltante = $pantalla_servicio - $pantallas_tarifa; $faltante = $pantalla_servicio - $pantallas_tarifa;
//dd($tarifa); //dd($tarifa);
@@ -259,18 +274,16 @@ class ShowPromociones extends Component
for ($y = 0; $y < (int)$pantallas_tarifa; $y++) { for ($y = 0; $y < (int)$pantallas_tarifa; $y++) {
$historial_cuenta = new Historial_cuenta(); $historial_cuenta = new Historial_cuenta();
$historial_cuenta->cuenta_id = $cuenta->id;
$historial_cuenta->historial_id = $historial->id; $historial_cuenta->historial_id = $historial->id;
$historial_cuenta->cuenta_id = $cuenta->id;
$historial_cuenta->perfil = (int)$perfil + (int)$y + 1; $historial_cuenta->perfil = (int)$perfil + (int)$y + 1;
$historial_cuenta->save(); $historial_cuenta->save();
if (!empty($historial_cuenta->id)) { if (!empty($historial_cuenta->id)) {
array_push($n,$historial_cuenta->id); array_push($this->n, $historial_cuenta->id);
} }
} }
} else { } else {
array_push($this->f, $servicio_id);
$this->alert('warning', 'No hay cuentas disponibles de ' . $tarifa->servicio->nombre, [ $this->alert('warning', 'No hay cuentas disponibles de ' . $tarifa->servicio->nombre, [
'position' => 'top' 'position' => 'top'
]); ]);
@@ -278,42 +291,83 @@ class ShowPromociones extends Component
$cuenta = null; $cuenta = null;
} }
} }
//dump($r, count($n)); if (count($this->f) > 0) {
if ($r == count($n) ) { $resultados = Servicio::whereIn('id', $this->f)->get();
// $eliminar = Historial_cuenta::whereIn('id', $n)->delete();
$message = '';
if ($resultados->count() > 0) {
$nombresServicios = $resultados->pluck('nombre')->toArray();
$message = implode(', ', $nombresServicios);
$this->alert('warning', 'No hay disponibilidad de ' . $message . ' en este momento.', [
'position' => 'center',
'timer' => '30000',
'toast' => false,
'text' => '¿Te gustaría realizar la compra ahora y recibir tu pedido tan pronto como haya disponibilidad? anticipamos que estará disponible en un plazo máximo de 48 horas.',
'showConfirmButton' => true,
'onConfirmed' => 'confirmarCompra',
'showDenyButton' => false,
'onDenied' => 'denegarCompra',
'showCancelButton' => true,
'onDismissed' => 'denegarCompra',
'cancelButtonText' => 'No, abandonar.',
'confirmButtonText' => 'Sí, comprar.',
]);
}
}
}
public function confirmarCompra()
{
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first(); $descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
$saldo_anterior = $descuento->valor; $saldo_anterior = $descuento->valor;
$nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo); $nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo);
$cobro = $descuento->update(['valor' => $nuevo_saldo]); $cobro = $descuento->update(['valor' => $nuevo_saldo]);
//dd($cobro);
if ($cobro) { if ($cobro) {
$historial->update(['estado' => 'activo']); $this->historial->update(['estado' => 'activo']);
$this->modalComprarPromo = false; $this->modalComprarPromo = false;
$this->credenciales($historial);
foreach ($this->f as $serviceId) {
$pendiente = new Pendientes();
$pendiente->historial_id = $this->historial->id;
$pendiente->cantidad = $this->cantidad_comprarPromo;
$pendiente->estado = 'pendiente';
$pendiente->servicio_id = $serviceId;
$pendiente->save();
}
$this->credenciales($this->historial);
} else { } else {
Historial_cuenta::whereIn('id', $this->n)->delete();
$eliminar = Historial_cuenta::whereIn('id',$n)->delete();
//dd($eliminar);
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ $this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
'position' => 'top' 'position' => 'top'
]); ]);
} }
$n=null;
}else{
$eliminar = Historial_cuenta::whereIn('id',$n)->delete(); $this->alert('success', 'Compra exitosa!', [
//dump($eliminar);
$this->alert('warning', 'No hay promociones disponibles, comuniquese con soporte!', [
'position' => 'top' 'position' => 'top'
]); ]);
$n=null;
$this->f = null;
$this->n = null;
$this->r = 0;
$this->modalComprarPromo = false;
} }
public function denegarCompra()
{
Historial_cuenta::whereIn('id', $this->n)->delete();
$this->alert('success', 'Compra cancelada!', [
'position' => 'top'
]);
$this->f = null;
$this->n = null;
$this->r = 0;
$this->modalComprarPromo = false;
} }
public function credenciales($historial) public function credenciales($historial)
@@ -387,7 +441,6 @@ class ShowPromociones extends Component
$this->alert('warning', 'Error enviando SMS!' . $err, [ $this->alert('warning', 'Error enviando SMS!' . $err, [
'position' => 'top' 'position' => 'top'
]); ]);
} else { } else {
if (!empty(json_decode($response)->subid)) { if (!empty(json_decode($response)->subid)) {
@@ -399,7 +452,6 @@ class ShowPromociones extends Component
'position' => 'top' 'position' => 'top'
]); ]);
} }
} }
} }
@@ -505,8 +557,6 @@ class ShowPromociones extends Component
$this->limpiarInputPromocion(); $this->limpiarInputPromocion();
} }
public function eliminar($id) public function eliminar($id)
{ {
$this->eliminar_id = $id; $this->eliminar_id = $id;
@@ -526,13 +576,6 @@ class ShowPromociones extends Component
]); ]);
} }
public function getListeners()
{
return [
'confirmed'
];
}
public function confirmed() public function confirmed()
{ {
$consulta_promociones = Promociones::findOrFail($this->eliminar_id); $consulta_promociones = Promociones::findOrFail($this->eliminar_id);
@@ -646,8 +689,6 @@ class ShowPromociones extends Component
$this->list2->add($promocionTarifa); $this->list2->add($promocionTarifa);
} }
} }
public function del_item_list2($id, $n) public function del_item_list2($id, $n)
{ {
+12 -6
View File
@@ -22,27 +22,33 @@ class Historiale extends Model
'nombre_cliente' 'nombre_cliente'
]; ];
public function vendedor(){ public function vendedor()
{
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
public function tarifa(){ public function tarifa()
{
return $this->belongsTo(Tarifas::class); return $this->belongsTo(Tarifas::class);
} }
public function promocion(){ public function promocion()
{
return $this->belongsTo(Promociones::class); return $this->belongsTo(Promociones::class);
} }
public function cliente(){ public function cliente()
{
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
public function cuentas(){ public function cuentas()
{
return $this->belongsToMany(Cuentas::class, 'historial_cuentas', 'historial_id', 'cuenta_id'); return $this->belongsToMany(Cuentas::class, 'historial_cuentas', 'historial_id', 'cuenta_id');
} }
public function cuentas_obsoletas(){ public function cuentas_obsoletas()
{
return $this->belongsToMany(Cuentas::class, 'logs', 'historial_id', 'cuenta_id'); return $this->belongsToMany(Cuentas::class, 'logs', 'historial_id', 'cuenta_id');
} }
} }
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pendientes extends Model
{
use HasFactory;
protected $fillable = [
'historial_id',
'servicio_id',
'cantidad',
'estado',
];
public function servicio()
{
return $this->hasMany(Servicio::class, 'servicio_id');
}
public function historial()
{
return $this->hasMany(Historiale::class, 'historial_id');
}
}
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pendientes', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('historial_id')->nullable();;
$table->unsignedBigInteger('servicio_id')->nullable();;
$table->string('cantidad')->nullable();
$table->string('estado')->nullable();
$table->foreign('historial_id')->references('id')->on('historiales')->onDelete('cascade');
$table->foreign('servicio_id')->references('id')->on('servicios')->onUpdate('cascade');;
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pendientes');
}
};
@@ -9,9 +9,8 @@
verPro: false, verPro: false,
copiar: '' copiar: ''
}" class="h-full w-full md:my-2"> }" class="h-full w-full md:my-2">
<div class="fixed backdrop-blur-sm bg-white/70 left-0 bottom-0 top-0 right-0 h-full z-40" wire:loading <div class="fixed backdrop-blur-sm bg-white/70 left-0 bottom-0 top-0 right-0 h-full z-40" wire:loading
wire:target="add_tarifa_list2,del_item_list2,photo,verPromocion,comprarPromo,editarPromo,editarPromoUpdate,comprar,pagar,create_newCategoria,add_tarifa,del_item,guardar,eliminar"> wire:target="confirmarCompra,denegarCompra,add_tarifa_list2,del_item_list2,photo,verPromocion,comprarPromo,editarPromo,editarPromoUpdate,comprar,pagar,create_newCategoria,add_tarifa,del_item,guardar,eliminar">
<div class="grid h-full place-items-center "> <div class="grid h-full place-items-center ">
<div class="max-w-xs"> <div class="max-w-xs">
<img src="./img/loading.gif" alt="" class="w-full text-center"> <img src="./img/loading.gif" alt="" class="w-full text-center">