Update ShowServicios.php
This commit is contained in:
+195
-182
@@ -26,6 +26,7 @@ use Illuminate\Support\Facades\Crypt;
|
|||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Twilio\Rest\Client;
|
use Twilio\Rest\Client;
|
||||||
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class ShowServicios extends Component
|
class ShowServicios extends Component
|
||||||
{
|
{
|
||||||
@@ -239,89 +240,125 @@ class ShowServicios extends Component
|
|||||||
/* ---------------- Btn Comprar ---------------- */
|
/* ---------------- Btn Comprar ---------------- */
|
||||||
public function comprar()
|
public function comprar()
|
||||||
{
|
{
|
||||||
$this->validate([
|
DB::beginTransaction();
|
||||||
'cantidad_tarjetaPlan' => 'required|numeric|min:1',
|
try {
|
||||||
]);
|
|
||||||
|
|
||||||
if ($this->cantidad_tarjetaPlan == 0) {
|
$this->validate([
|
||||||
$this->alert('error', 'La cantidad debe ser mayor a 0', [
|
'cantidad_tarjetaPlan' => 'required|numeric|min:1',
|
||||||
'position' => 'top'
|
|
||||||
]);
|
]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth()->user()->saldo->valor < $this->valor_tarjetaPlan * $this->cantidad_tarjetaPlan) {
|
if ($this->cantidad_tarjetaPlan == 0) {
|
||||||
$this->alert('error', 'Saldo insuficiente', [
|
$this->alert('error', 'La cantidad debe ser mayor a 0', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
|
if (auth()->user()->saldo->valor < $this->valor_tarjetaPlan * $this->cantidad_tarjetaPlan) {
|
||||||
$total_valor = (int) $this->valor_tarjetaPlan * (int) $this->cantidad_tarjetaPlan;
|
$this->alert('error', 'Saldo insuficiente', [
|
||||||
$utilidad_total = (int) $this->utilidad * (int) $this->cantidad_tarjetaPlan;
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
|
||||||
$usuario_id = $usuario_existe;
|
$total_valor = (int) $this->valor_tarjetaPlan * (int) $this->cantidad_tarjetaPlan;
|
||||||
|
$utilidad_total = (int) $this->utilidad * (int) $this->cantidad_tarjetaPlan;
|
||||||
|
|
||||||
if (is_null($usuario_existe)) {
|
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
||||||
$usuario = new User;
|
$usuario_id = $usuario_existe;
|
||||||
$usuario->name = $this->nombre_tarjetaPlan;
|
|
||||||
$usuario->email = $this->email_tarjetaPlan;
|
|
||||||
$usuario->password = '123';
|
|
||||||
$usuario->celular = '+57' . $this->celular_tarjetaPlan;
|
|
||||||
$usuario->save();
|
|
||||||
|
|
||||||
$usuario_id = $usuario->id;
|
if (is_null($usuario_existe)) {
|
||||||
}
|
$usuario = new User;
|
||||||
|
$usuario->name = $this->nombre_tarjetaPlan;
|
||||||
|
$usuario->email = $this->email_tarjetaPlan;
|
||||||
|
$usuario->password = '123';
|
||||||
|
$usuario->celular = '+57' . $this->celular_tarjetaPlan;
|
||||||
|
$usuario->save();
|
||||||
|
|
||||||
//dd($this->fechaFinal);
|
$usuario_id = $usuario->id;
|
||||||
$historial = new Historiale;
|
}
|
||||||
$historial->fecha_inicio = Carbon::now();
|
|
||||||
$historial->fecha_final = $this->fechaFinal;
|
|
||||||
$historial->valor = $total_valor;
|
|
||||||
$historial->tipo_pago = 'manual';
|
|
||||||
$historial->estado = 'pendiente';
|
|
||||||
$historial->vendedor_id = Auth()->user()->id;
|
|
||||||
$historial->tarifa_id = $this->tarifa_id;
|
|
||||||
$historial->cliente_id = $usuario_id;
|
|
||||||
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
|
||||||
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
|
|
||||||
$historial->utilidad = $utilidad_total;
|
|
||||||
$historial->save();
|
|
||||||
|
|
||||||
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
|
//dd($this->fechaFinal);
|
||||||
|
$historial = new Historiale;
|
||||||
|
$historial->fecha_inicio = Carbon::now();
|
||||||
|
$historial->fecha_final = $this->fechaFinal;
|
||||||
|
$historial->valor = $total_valor;
|
||||||
|
$historial->tipo_pago = 'manual';
|
||||||
|
$historial->estado = 'pendiente';
|
||||||
|
$historial->vendedor_id = Auth()->user()->id;
|
||||||
|
$historial->tarifa_id = $this->tarifa_id;
|
||||||
|
$historial->cliente_id = $usuario_id;
|
||||||
|
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
||||||
|
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
|
||||||
|
$historial->utilidad = $utilidad_total;
|
||||||
|
$historial->save();
|
||||||
|
|
||||||
|
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
|
||||||
|
|
||||||
|
|
||||||
$servicioNombre = $pantallas->servicio->nombre;
|
$servicioNombre = $pantallas->servicio->nombre;
|
||||||
$servicio_id = $pantallas->servicio_id;
|
$servicio_id = $pantallas->servicio_id;
|
||||||
$pantalla_servicio_completa = $pantallas->servicio->completa;
|
$pantalla_servicio_completa = $pantallas->servicio->completa;
|
||||||
$pantalla_servicio = $pantallas->servicio->pantallas;
|
$pantalla_servicio = $pantallas->servicio->pantallas;
|
||||||
|
|
||||||
$pantallas = $pantallas->pantallas ?? null;
|
$pantallas = $pantallas->pantallas ?? null;
|
||||||
|
|
||||||
|
|
||||||
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
||||||
$suma = $pantalla_servicio - $cantidad_solicitada;
|
$suma = $pantalla_servicio - $cantidad_solicitada;
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
->whereDate('inicio', '>=', $this->fecha)
|
||||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||||
// ->whereDate('vencimiento','>=', $this->fechaFinal)
|
// ->whereDate('vencimiento','>=', $this->fechaFinal)
|
||||||
->Orderby('inicio', 'ASC')
|
->Orderby('inicio', 'ASC')
|
||||||
->withCount('historiales')
|
->withCount('historiales')
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
->having('historiales_count', '<=', $suma)
|
->having('historiales_count', '<=', $suma)
|
||||||
//->with('perfil')
|
//->with('perfil')
|
||||||
//->whereDoesntHave('perfil', function ($query) use ($suma) {
|
//->whereDoesntHave('perfil', function ($query) use ($suma) {
|
||||||
// $query->select('cuenta_id')
|
// $query->select('cuenta_id')
|
||||||
// ->groupBy('cuenta_id')
|
// ->groupBy('cuenta_id')
|
||||||
// ->havingRaw("COUNT(*) >= $suma");
|
// ->havingRaw("COUNT(*) >= $suma");
|
||||||
//})
|
//})
|
||||||
->get();
|
->get();
|
||||||
if ($cuenta->isEmpty()) {
|
if ($cuenta->isEmpty()) {
|
||||||
$suma3 = $pantalla_servicio - $pantallas;
|
$suma3 = $pantalla_servicio - $pantallas;
|
||||||
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
|
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
||||||
|
->whereDate('inicio', '>=', $this->fecha)
|
||||||
|
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||||
|
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||||
|
->Orderby('inicio', 'ASC')
|
||||||
|
->withCount('historiales')
|
||||||
|
->where('estado', 'activo')
|
||||||
|
->having('historiales_count', '<=', $suma3)
|
||||||
|
//->with('perfil')
|
||||||
|
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
||||||
|
//$query->select('cuenta_id')
|
||||||
|
// ->groupBy('cuenta_id')
|
||||||
|
// ->havingRaw("COUNT(*) >= $suma2");
|
||||||
|
//})
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
// dd($cuenta);
|
||||||
|
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
|
||||||
|
|
||||||
|
//Cuentas completas
|
||||||
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
|
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
||||||
|
//->whereDate('inicio', '>=', $this->fecha)
|
||||||
|
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||||
|
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||||
|
->Orderby('inicio', 'ASC')
|
||||||
|
->withCount('historiales')
|
||||||
|
->where('estado', 'pendiente')
|
||||||
|
->doesntHave('perfil')
|
||||||
|
->get();
|
||||||
|
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
||||||
|
$suma2 = $pantalla_servicio - $pantallas;
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
||||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
->whereDate('inicio', '>=', $this->fecha)
|
||||||
@@ -330,7 +367,7 @@ class ShowServicios extends Component
|
|||||||
->Orderby('inicio', 'ASC')
|
->Orderby('inicio', 'ASC')
|
||||||
->withCount('historiales')
|
->withCount('historiales')
|
||||||
->where('estado', 'activo')
|
->where('estado', 'activo')
|
||||||
->having('historiales_count', '<=', $suma3)
|
->having('historiales_count', '<=', $suma2)
|
||||||
//->with('perfil')
|
//->with('perfil')
|
||||||
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
||||||
//$query->select('cuenta_id')
|
//$query->select('cuenta_id')
|
||||||
@@ -338,133 +375,109 @@ class ShowServicios extends Component
|
|||||||
// ->havingRaw("COUNT(*) >= $suma2");
|
// ->havingRaw("COUNT(*) >= $suma2");
|
||||||
//})
|
//})
|
||||||
->get();
|
->get();
|
||||||
}
|
|
||||||
// dd($cuenta);
|
|
||||||
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
|
|
||||||
|
|
||||||
//Cuentas completas
|
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
|
||||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
|
||||||
//->whereDate('inicio', '>=', $this->fecha)
|
|
||||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
|
||||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
|
||||||
->Orderby('inicio', 'ASC')
|
|
||||||
->withCount('historiales')
|
|
||||||
->where('estado', 'pendiente')
|
|
||||||
->doesntHave('perfil')
|
|
||||||
->get();
|
|
||||||
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
|
||||||
$suma2 = $pantalla_servicio - $pantallas;
|
|
||||||
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
|
|
||||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)
|
|
||||||
->whereDate('inicio', '>=', $this->fecha)
|
|
||||||
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
|
||||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
|
||||||
->Orderby('inicio', 'ASC')
|
|
||||||
->withCount('historiales')
|
|
||||||
->where('estado', 'activo')
|
|
||||||
->having('historiales_count', '<=', $suma2)
|
|
||||||
//->with('perfil')
|
|
||||||
//->whereDoesntHave('perfil', function ($query) use ($suma2) {
|
|
||||||
//$query->select('cuenta_id')
|
|
||||||
// ->groupBy('cuenta_id')
|
|
||||||
// ->havingRaw("COUNT(*) >= $suma2");
|
|
||||||
//})
|
|
||||||
->get();
|
|
||||||
} else {
|
|
||||||
$cuenta = null;
|
|
||||||
$cantidad_necesaria = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cuentasMostar = '';
|
|
||||||
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
|
|
||||||
//dd($cuenta);
|
|
||||||
|
|
||||||
if (!empty($cuenta) && isset($cuenta[$h])) {
|
|
||||||
$esta_error = false;
|
|
||||||
$cuentasMostar = '';
|
|
||||||
|
|
||||||
$perfil = $cuenta[$h]->historiales_count;
|
|
||||||
|
|
||||||
for ($y = 0; $y < (int) $pantallas; $y++) {
|
|
||||||
|
|
||||||
$historial_cuenta = new Historial_cuenta;
|
|
||||||
$historial_cuenta->cuenta_id = $cuenta[$h]->id;
|
|
||||||
$historial_cuenta->historial_id = $historial->id;
|
|
||||||
$historial_cuenta->perfil = (int) $perfil + (int) $y + 1;
|
|
||||||
$historial_cuenta->save();
|
|
||||||
|
|
||||||
if ($cuenta[$h]->correo != $cuentasMostar) {
|
|
||||||
$cuentasMostar .= $cuenta[$h]->correo . ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$esta_error = true;
|
$cuenta = null;
|
||||||
$historial->update(['estado' => 'cancelado']);
|
$cantidad_necesaria = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cuentasMostar = '';
|
||||||
|
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
|
||||||
|
//dd($cuenta);
|
||||||
|
|
||||||
|
if (!empty($cuenta) && isset($cuenta[$h])) {
|
||||||
|
$esta_error = false;
|
||||||
|
$cuentasMostar = '';
|
||||||
|
|
||||||
|
$perfil = $cuenta[$h]->historiales_count;
|
||||||
|
|
||||||
|
for ($y = 0; $y < (int) $pantallas; $y++) {
|
||||||
|
|
||||||
|
$historial_cuenta = new Historial_cuenta;
|
||||||
|
$historial_cuenta->cuenta_id = $cuenta[$h]->id;
|
||||||
|
$historial_cuenta->historial_id = $historial->id;
|
||||||
|
$historial_cuenta->perfil = (int) $perfil + (int) $y + 1;
|
||||||
|
$historial_cuenta->save();
|
||||||
|
|
||||||
|
if ($cuenta[$h]->correo != $cuentasMostar) {
|
||||||
|
$cuentasMostar .= $cuenta[$h]->correo . ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$esta_error = true;
|
||||||
|
$historial->update(['estado' => 'cancelado']);
|
||||||
|
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
||||||
|
$logsGeneral = new Log_general();
|
||||||
|
$logsGeneral->user_id = Auth::user()->id;
|
||||||
|
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' Se desligaron todas las cuentas.';
|
||||||
|
$logsGeneral->tipo = 'compra_error';
|
||||||
|
$logsGeneral->historial_id = $historial->id;
|
||||||
|
$logsGeneral->save();
|
||||||
|
$this->alert('warning', 'No hay cuentas disponibles!', [
|
||||||
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$esta_error && !empty($historial->cuentas)) {
|
||||||
|
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
|
||||||
|
|
||||||
|
$saldo_anterior = $descuento->valor ?? 0;
|
||||||
|
$nuevo_saldo = $saldo_anterior - $total_valor;
|
||||||
|
$cobro = $descuento->update(['valor' => $nuevo_saldo]);
|
||||||
|
if ($cobro) {
|
||||||
|
|
||||||
|
$historial->update(['estado' => 'activo']);
|
||||||
|
|
||||||
|
$logsGeneral = new Log_general();
|
||||||
|
$logsGeneral->user_id = Auth::user()->id;
|
||||||
|
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo;
|
||||||
|
$logsGeneral->historial_id = $historial->id;
|
||||||
|
$logsGeneral->tipo = 'compra';
|
||||||
|
$logsGeneral->save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->credenciales($historial);
|
||||||
|
} else {
|
||||||
|
$historial->update(['estado' => 'cancelado']);
|
||||||
|
$logsGeneral = new Log_general();
|
||||||
|
$logsGeneral->user_id = Auth::user()->id;
|
||||||
|
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo un error con el cobro del servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor;
|
||||||
|
$logsGeneral->tipo = 'compra_error';
|
||||||
|
$logsGeneral->historial_id = $historial->id;
|
||||||
|
$logsGeneral->save();
|
||||||
|
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
||||||
|
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
||||||
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
||||||
$logsGeneral = new Log_general();
|
$logsGeneral = new Log_general();
|
||||||
$logsGeneral->user_id = Auth::user()->id;
|
$logsGeneral->user_id = Auth::user()->id;
|
||||||
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' Se desligaron todas las cuentas.';
|
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' No se desconto el saldo, ni se asignaron cuentas.';
|
||||||
$logsGeneral->tipo = 'compra_error';
|
$logsGeneral->tipo = 'compra_error';
|
||||||
$logsGeneral->historial_id= $historial->id;
|
$logsGeneral->historial_id = $historial->id;
|
||||||
$logsGeneral->save();
|
$logsGeneral->save();
|
||||||
$this->alert('warning', 'No hay cuentas disponibles!', [
|
$this->alert('warning', 'No hay cuentas disponibles!', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$esta_error && !empty($historial->cuentas)) {
|
|
||||||
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
|
|
||||||
|
|
||||||
$saldo_anterior = $descuento->valor ?? 0;
|
|
||||||
$nuevo_saldo = $saldo_anterior - $total_valor;
|
|
||||||
$cobro = $descuento->update(['valor' => $nuevo_saldo]);
|
|
||||||
if ($cobro) {
|
|
||||||
|
|
||||||
$historial->update(['estado' => 'activo']);
|
|
||||||
|
|
||||||
$logsGeneral = new Log_general();
|
|
||||||
$logsGeneral->user_id = Auth::user()->id;
|
|
||||||
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo;
|
|
||||||
$logsGeneral->historial_id= $historial->id;
|
|
||||||
$logsGeneral->tipo = 'compra';
|
|
||||||
$logsGeneral->save();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->credenciales($historial);
|
|
||||||
} else {
|
|
||||||
$historial->update(['estado' => 'cancelado']);
|
|
||||||
$logsGeneral = new Log_general();
|
|
||||||
$logsGeneral->user_id = Auth::user()->id;
|
|
||||||
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo un error con el cobro del servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor;
|
|
||||||
$logsGeneral->tipo = 'compra_error';
|
|
||||||
$logsGeneral->historial_id= $historial->id;
|
|
||||||
$logsGeneral->save();
|
|
||||||
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
|
||||||
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
|
||||||
'position' => 'top'
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
DB::commit();
|
||||||
|
|
||||||
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
|
$this->tarjetaPlan = false;
|
||||||
$logsGeneral = new Log_general();
|
$this->cantidad_tarjetaPlan = 1;
|
||||||
$logsGeneral->user_id = Auth::user()->id;
|
} catch (Exception $e) {
|
||||||
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' No se desconto el saldo, ni se asignaron cuentas.';
|
|
||||||
$logsGeneral->tipo = 'compra_error';
|
DB::rollBack();
|
||||||
$logsGeneral->historial_id= $historial->id;
|
$this->alert('error', 'Error al comprar: ' . $e->getMessage(), [
|
||||||
$logsGeneral->save();
|
|
||||||
$this->alert('warning', 'No hay cuentas disponibles!', [
|
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->tarjetaPlan = false;
|
|
||||||
$this->cantidad_tarjetaPlan = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function credenciales($historial)
|
public function credenciales($historial)
|
||||||
|
|||||||
Reference in New Issue
Block a user