feat: API de reportes, fix distancia espacial y protección OneSignal
- GET/POST /api/contracts/reports y /api/postulations/reports
- GET/POST /api/contracts/reports/{id}/comments con verificación de autoría
- Fix distancia withinDistanceTo: 0.5 grados → 5000 metros (SRID 4326)
- Fix FK Report::finishedcontracts() → contract_id
- Wrap todas las llamadas OneSignal en try/catch para evitar crashes
- Chat UI de comentarios: burbujas por rol, botón veredicto fijo, estilos
- Botón veredicto movido de reports/index a reports/comments
- Ruta POST veredict y restructura reports/{id}/comments en web
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -356,22 +356,16 @@ class ContractController extends Controller
|
||||
|
||||
Postulations::destroy($request->postulation_id);
|
||||
|
||||
//Notify the suppliers that they have been hired
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Dirígete a la sección de postulaciones contratadas en la app para ver más detalles",
|
||||
(string) $supplier->user_id,
|
||||
null, null, null, null,
|
||||
"Proveedor: has sido contratado"
|
||||
);
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($supplier->user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('suppplier_hired')
|
||||
// ->language('es_US')
|
||||
// ->body(Messages\Components\Body::create([
|
||||
// Messages\Components\Parameters\Text::create('Proveedor has sido contratado: dirígete a la sección de postulaciones contratadas en JobHero para ver más detalles'),
|
||||
// ])));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
//Schedule a notification for the suppliers about their appointment
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Tienes un servicio en " . $contract->address . " hoy en 30 minutos. Dirígete a la sección de postulaciones contratados para más detalles",
|
||||
(string) $supplier->user_id,
|
||||
@@ -379,16 +373,9 @@ class ContractController extends Controller
|
||||
$delay_UTC,
|
||||
"Proveedor, no olvides tu cita de hoy"
|
||||
);
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($supplier->user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('suppplier_appointment')
|
||||
// ->language('es_US')
|
||||
// ->body(Messages\Components\Body::create([
|
||||
// Messages\Components\Parameters\Text::create('Proveedor no olvides tu cita de hoy: Tienes un servicio en ' . $contract->address . ' hoy en 30 minutos. Dírigeta a la sección de postulaciones contratados para más detalles'),
|
||||
// ])));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
|
||||
//Schedule a notification for the users about their appointment
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Tienes un servicio agendado hoy en " . $contract->address . " en 30 minutos. Dirígete a la sección de contratos confirmados para más detalles",
|
||||
(string) $user->id,
|
||||
@@ -396,13 +383,7 @@ class ContractController extends Controller
|
||||
$delay_UTC,
|
||||
$user->name . ", no olvides tu cita de hoy"
|
||||
);
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('user_appointment')
|
||||
// ->language('es_US')
|
||||
// ->body(Messages\Components\Body::create([
|
||||
// Messages\Components\Parameters\Text::create($user->name . ' no olvides tu cita de hoy: Tienes un servicio agendado hoy en ' . $contract->address . ' en 30 minutos. Dírigeta a la sección de contratos confirmados para más detalles'),
|
||||
// ])));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Servicio contratado exitosamente'
|
||||
@@ -483,22 +464,16 @@ class ContractController extends Controller
|
||||
|
||||
Postulations::destroy($request->postulation_id);
|
||||
|
||||
//Notify the suppliers that they have been hired
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Dirígete a la sección de postulaciones contratadas en la app para ver más detalles",
|
||||
(string) $supplier->user_id,
|
||||
null, null, null, null,
|
||||
"Proveedor: has sido contratado"
|
||||
);
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($supplier->user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('suppplier_hired')
|
||||
// ->language('es_US')
|
||||
// ->body(Messages\Components\Body::create([
|
||||
// Messages\Components\Parameters\Text::create('Proveedor has sido contratado: dirígete a la sección de postulaciones contratadas en JobHero para ver más detalles'),
|
||||
// ])));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
//Schedule a notification for the suppliers about their appointment
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Tienes un servicio en " . $contract->address . " hoy en 30 minutos. Dirígete a la sección de postulaciones contratados para más detalles",
|
||||
(string) $supplier->user_id,
|
||||
@@ -506,16 +481,9 @@ class ContractController extends Controller
|
||||
$delay_UTC,
|
||||
"Proveedor, no olvides tu cita de hoy"
|
||||
);
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($supplier->user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('suppplier_appointment')
|
||||
// ->language('es_US')
|
||||
// ->body(Messages\Components\Body::create([
|
||||
// Messages\Components\Parameters\Text::create('Proveedor no olvides tu cita de hoy: Tienes un servicio en ' . $contract->address . ' hoy en 30 minutos. Dírigeta a la sección de postulaciones contratados para más detalles'),
|
||||
// ])));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
|
||||
//Schedule a notification for the users about their appointment
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Tienes un servicio agendado hoy en " . $contract->address . " en 30 minutos. Dirígete a la sección de contratos confirmados para más detalles",
|
||||
(string) $user->id,
|
||||
@@ -523,6 +491,7 @@ class ContractController extends Controller
|
||||
$delay_UTC,
|
||||
$user->name . ", no olvides tu cita de hoy"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($user->phone, Messages\TemplateMessage::create()
|
||||
// ->name('user_appointment')
|
||||
@@ -760,12 +729,14 @@ class ContractController extends Controller
|
||||
|
||||
CurrentContracts::destroy($request->contract_id);
|
||||
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"El servicio en " . $fcontract->address . " el día " . substr($fcontract->appointment, 0, 10) . "ha sido cancelado. Dírigeta a la sección de servicios contratados para más detalles",
|
||||
(string) $supplier->user_id,
|
||||
null, null, null, null,
|
||||
"Proveedor: un servicio ha sido cancelado"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Servicio cancelado exitosamente'
|
||||
@@ -836,12 +807,14 @@ class ContractController extends Controller
|
||||
$payment->status_id = null;
|
||||
$payment->save();
|
||||
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"El servicio en " . $fcontract->address . " el día " . substr($fcontract->appointment, 0, 10) . " ha sido iniciado. Dírigeta a la sección de servicios contratados para más detalles",
|
||||
(string) $fcontract->user_id,
|
||||
null, null, null, null,
|
||||
"Usuario: el proveedor ha iniciado el servicio"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Servicio iniciado exitosamente'
|
||||
|
||||
@@ -137,12 +137,14 @@ class NoHomeController extends Controller
|
||||
if (Carbon::now()->diffInMinutes($contract->appointment, false) < 10) {
|
||||
return response()->json($contract);
|
||||
} else {
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"El proveedor para el servicio en " . $contract->address . " ha llegado. Dírigeta a la sección de contratos confirmados para más detalles",
|
||||
(string) $client->id,
|
||||
null, null, null, null,
|
||||
$client->name . ", tu proveedor del servicio ha llegado"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
return response()->json([
|
||||
//'message' => 'Por favor espere a los 10 minutos de tolerancia de la hora acordada'
|
||||
'message' => 'wait'
|
||||
@@ -227,12 +229,14 @@ class NoHomeController extends Controller
|
||||
'message' => 'Ausencia registrada con éxito, nos comunicaremos con usted por correo electrónico en caso de alguna circunstancia'
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"El proveedor para el servicio en " . $ccontract->address . " ha llegado. Dírigeta a la sección de contratos confirmados para más detalles",
|
||||
(string) $client->id,
|
||||
null, null, null, null,
|
||||
$client->name . ", tu proveedor del servicio ha llegado"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
return response()->json([
|
||||
'order' => 'wait',
|
||||
'message' => 'Por favor espere a los 10 minutos de tolerancia de la hora acordada'
|
||||
|
||||
@@ -109,7 +109,7 @@ class PostulationController extends Controller
|
||||
$geometry = new Point($request->lat, $request->lng);
|
||||
$category = Categories::where('name', strip_tags($request->category))->orwhere('en_name', strip_tags($request->category))->first();
|
||||
|
||||
$distance = 0.5;
|
||||
$distance = 5000; // metros (5 km)
|
||||
$suppliers = Suppliers::withinDistanceTo('location', $geometry, $distance)->get();
|
||||
|
||||
if ($suppliers != '[]') {
|
||||
@@ -129,21 +129,25 @@ class PostulationController extends Controller
|
||||
$postulation->details = preg_replace('/\d+/', '', strip_tags($request->details));
|
||||
$postulation->save();
|
||||
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Coméntele al Ing. que hay una postulación",
|
||||
"128",
|
||||
null, null, null, null,
|
||||
"Admin: hay nueva postulación"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
foreach ($suppliers as $supplier) {
|
||||
if (in_array($category->id, $supplier->categories->pluck('id')->toArray())) {
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Dirígete a la sección de postulaciones en la app para ver más detalles",
|
||||
(string) $supplier->user_id,
|
||||
null, null, null, null,
|
||||
"Proveedor: hay nueva postulación"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($supplier->user->phone, Messages\TemplateMessage::create()
|
||||
@@ -171,6 +175,7 @@ class PostulationController extends Controller
|
||||
|
||||
$delay_UTC = Carbon::now()->addMinutes(15)->toString();
|
||||
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Dirígete a la sección de contratos en la app para ver más detalles",
|
||||
(string) $user->id,
|
||||
@@ -178,6 +183,7 @@ class PostulationController extends Controller
|
||||
$delay_UTC,
|
||||
"Búsqueda Finalizada"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Servicio solicitado, espere a que un proveedor se postule'
|
||||
@@ -217,12 +223,14 @@ class PostulationController extends Controller
|
||||
if ($time_limit > 0) {
|
||||
if (in_array($postulation->category_id, $supplier->categories->pluck('id')->toArray())) {
|
||||
if($supplier->membership == 1) {
|
||||
try {
|
||||
OneSignal::sendNotificationToExternalUser(
|
||||
"Dirígete a la sección de contratos en la app para ver más detalles",
|
||||
(string) $postulation->user_id,
|
||||
null, null, null, null,
|
||||
"Un proveedor certificado se ha postulado"
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
// TODO: Configurar WhatsApp cuando esté disponible
|
||||
// Whatsapp::send($postulation->user->phone, Messages\TemplateMessage::create()
|
||||
|
||||
@@ -2,111 +2,51 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Report;
|
||||
use App\Models\ReportComment;
|
||||
use App\Models\FinishedContracts;
|
||||
use App\Models\NoHome;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ReportCommentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request, $id, $contract_id)
|
||||
public function index(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$request->session()->put('search', $request
|
||||
->has('search') ? strip_tags($request->get('search')) : ($request->session()
|
||||
->has('search') ? strip_tags($request->session()->get('search')) : ''));
|
||||
$report = Report::find($id);
|
||||
$contract = FinishedContracts::with(['user', 'suppliers.user', 'categories'])->find($report->contract_id);
|
||||
$nohome = NoHome::where('contract_id', $contract->id)->first();
|
||||
$comments = ReportComment::with('user')
|
||||
->where('report_id', $id)
|
||||
->orderBy('created_at', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$request->session()->put('field', $request
|
||||
->has('field') ? strip_tags($request->get('field')) : ($request->session()
|
||||
->has('field') ? strip_tags($request->session()->get('field')) : 'id'));
|
||||
|
||||
$request->session()->put('sort', $request
|
||||
->has('sort') ? strip_tags($request->get('sort')) : ($request->session()
|
||||
->has('sort') ? strip_tags($request->session()->get('sort')) : 'asc'));
|
||||
|
||||
//$headers = $request->get('header') != '' ? $request->get('header') : -1;
|
||||
|
||||
$contract = FinishedContracts::where('id', $contract_id)->first();
|
||||
$nohome = NoHome::where('contract_id', $contract_id)->first();
|
||||
$comments = new ReportComment();
|
||||
$comments = $comments->where('report_id', $id)
|
||||
->orderBy(strip_tags($request->session()->get('field')), strip_tags($request->session()->get('sort')))
|
||||
->paginate(10);
|
||||
|
||||
if ($request->isMethod('get'))
|
||||
return view('reports.comments', compact('comments', 'contract', 'nohome'));
|
||||
return view('reports.comments', compact('comments', 'contract', 'nohome', 'report'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
public function store(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$validator = Validator::make($request->all(), [
|
||||
'comment' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect()->back()->withErrors($validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$comment = new ReportComment();
|
||||
$comment->report_id = $id;
|
||||
$comment->user_id = Auth::id();
|
||||
$comment->comment = strip_tags($request->comment);
|
||||
$comment->save();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\ReportComment $reportComment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(ReportComment $reportComment)
|
||||
public function destroy($id, $comment_id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\ReportComment $reportComment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(ReportComment $reportComment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\ReportComment $reportComment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, ReportComment $reportComment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\ReportComment $reportComment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id, $contract_id)
|
||||
{
|
||||
//
|
||||
ReportComment::destroy($id);
|
||||
return redirect('reports/comments/'.$id.'/'.$contract_id);
|
||||
ReportComment::destroy($comment_id);
|
||||
return redirect('reports/' . $id . '/comments');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class ReportController extends Controller
|
||||
|
||||
$report = Report::find($id);
|
||||
$report->veredict = strip_tags($request->veredict);
|
||||
$coupon->save();
|
||||
$report->save();
|
||||
|
||||
return redirect('reports');
|
||||
}
|
||||
@@ -138,6 +138,155 @@ class ReportController extends Controller
|
||||
return redirect('reports');
|
||||
}
|
||||
|
||||
public function getcomments(Request $request, $id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$report = Report::with('finishedcontracts.suppliers')->find($id);
|
||||
|
||||
if (!$report) {
|
||||
return response()->json(['message' => 'Reporte no encontrado'], 404);
|
||||
}
|
||||
|
||||
$contract = $report->finishedcontracts;
|
||||
$supplierUserId = $contract->suppliers->user_id ?? null;
|
||||
|
||||
if ($user->id !== $contract->user_id && $user->id !== $supplierUserId) {
|
||||
return response()->json(['message' => 'No autorizado'], 403);
|
||||
}
|
||||
|
||||
$comments = ReportComment::with('user')
|
||||
->where('report_id', $id)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->map(function ($c) use ($contract, $supplierUserId) {
|
||||
$isSupplier = $c->user_id === $supplierUserId;
|
||||
$isClient = $c->user_id === $contract->user_id;
|
||||
return [
|
||||
'id' => $c->id,
|
||||
'sender_id' => $c->user_id,
|
||||
'sender_name' => $isSupplier
|
||||
? ($contract->suppliers->company_name ?? null)
|
||||
: ($c->user->name ?? null),
|
||||
'role_id' => $c->user->role_id ?? null,
|
||||
'sender_type' => !$isClient && !$isSupplier ? 'moderator' : null,
|
||||
'comment' => $c->comment,
|
||||
'created_at' => $c->created_at,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($comments);
|
||||
}
|
||||
|
||||
public function storecomment(Request $request, $id)
|
||||
{
|
||||
$validator = Validator::make($request->all(), ['comment' => 'required|string']);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$report = Report::with('finishedcontracts.suppliers')->find($id);
|
||||
|
||||
if (!$report) {
|
||||
return response()->json(['message' => 'Reporte no encontrado'], 404);
|
||||
}
|
||||
|
||||
$contract = $report->finishedcontracts;
|
||||
$supplierUserId = $contract->suppliers->user_id ?? null;
|
||||
|
||||
if ($user->id !== $contract->user_id && $user->id !== $supplierUserId) {
|
||||
return response()->json(['message' => 'No autorizado'], 403);
|
||||
}
|
||||
|
||||
$comment = new ReportComment();
|
||||
$comment->report_id = $id;
|
||||
$comment->user_id = $user->id;
|
||||
$comment->comment = strip_tags($request->comment);
|
||||
$comment->save();
|
||||
|
||||
$supplierUserId = $contract->suppliers->user_id ?? null;
|
||||
$isSupplier = $user->id === $supplierUserId;
|
||||
$isClient = $user->id === $contract->user_id;
|
||||
|
||||
return response()->json([
|
||||
'id' => $comment->id,
|
||||
'sender_id' => $user->id,
|
||||
'sender_name' => $isSupplier ? ($contract->suppliers->company_name ?? null) : $user->name,
|
||||
'role_id' => $user->role_id,
|
||||
'sender_type' => !$isClient && !$isSupplier ? 'moderator' : null,
|
||||
'comment' => $comment->comment,
|
||||
'created_at' => $comment->created_at,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function getsupplierreports(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if (!$user->suppliers) {
|
||||
return response()->json(['success' => false, 'message' => 'No tienes un perfil de proveedor registrado'], 400);
|
||||
}
|
||||
|
||||
$contractIds = FinishedContracts::where('supplier_id', $user->suppliers->id)->pluck('id');
|
||||
|
||||
$reports = Report::with([
|
||||
'finishedcontracts.suppliers.user',
|
||||
'finishedcontracts.categories',
|
||||
])
|
||||
->whereIn('contract_id', $contractIds)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$data = $reports->map(function ($report) {
|
||||
$contract = $report->finishedcontracts;
|
||||
return [
|
||||
'id' => $report->id,
|
||||
'supplier' => $contract->suppliers->user->name ?? null,
|
||||
'company' => $contract->suppliers->company_name ?? null,
|
||||
'category' => $contract->categories->name ?? null,
|
||||
'en_category' => $contract->categories->en_name ?? null,
|
||||
'appointment' => $contract->appointment,
|
||||
'address' => $contract->address,
|
||||
'amount' => $contract->amount,
|
||||
'veredict' => $report->veredict,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function getreports(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$contractIds = FinishedContracts::where('user_id', $user->id)->pluck('id');
|
||||
|
||||
$reports = Report::with([
|
||||
'finishedcontracts.suppliers.user',
|
||||
'finishedcontracts.categories',
|
||||
])
|
||||
->whereIn('contract_id', $contractIds)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$data = $reports->map(function ($report) {
|
||||
$contract = $report->finishedcontracts;
|
||||
return [
|
||||
'id' => $report->id,
|
||||
'supplier' => $contract->suppliers->user->name ?? null,
|
||||
'company' => $contract->suppliers->company_name ?? null,
|
||||
'category' => $contract->categories->name ?? null,
|
||||
'en_category' => $contract->categories->en_name ?? null,
|
||||
'appointment' => $contract->appointment,
|
||||
'address' => $contract->address,
|
||||
'amount' => $contract->amount,
|
||||
'veredict' => $report->veredict,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function report(Request $request) {
|
||||
|
||||
$rules = [
|
||||
|
||||
@@ -1237,7 +1237,7 @@ class SupplierController extends Controller
|
||||
], 400);
|
||||
}
|
||||
|
||||
$distance = 0.5;
|
||||
$distance = 5000; // metros (5 km)
|
||||
$postulations = Postulations::withinDistanceTo('location', $supplier->location, $distance)->orderBy('created_at', 'DESC')->get();
|
||||
|
||||
$postulationsinfo = array();
|
||||
|
||||
@@ -20,7 +20,7 @@ class Report extends Model
|
||||
|
||||
public function finishedcontracts()
|
||||
{
|
||||
return $this->belongsTo(FinishedContracts::class);
|
||||
return $this->belongsTo(FinishedContracts::class, 'contract_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
||||
@@ -17,6 +17,7 @@ class PushNotificationService
|
||||
*/
|
||||
public function sendToUser(int $userId, string $message, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
try {
|
||||
return OneSignal::sendNotificationToExternalUser(
|
||||
$message,
|
||||
(string) $userId,
|
||||
@@ -26,6 +27,7 @@ class PushNotificationService
|
||||
null,
|
||||
$heading
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +60,7 @@ class PushNotificationService
|
||||
*/
|
||||
public function sendScheduledToUser(int $userId, string $message, string $sendAt, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
try {
|
||||
return OneSignal::sendNotificationToExternalUser(
|
||||
$message,
|
||||
(string) $userId,
|
||||
@@ -67,6 +70,7 @@ class PushNotificationService
|
||||
$sendAt,
|
||||
$heading
|
||||
);
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +84,7 @@ class PushNotificationService
|
||||
*/
|
||||
public function sendToRole(int $roleId, string $message, string $heading = 'JobHero', array $data = [])
|
||||
{
|
||||
return OneSignal::sendNotificationUsingTags(
|
||||
try { return OneSignal::sendNotificationUsingTags(
|
||||
$message,
|
||||
[
|
||||
['field' => 'tag', 'key' => 'iChamba_Role', 'relation' => '=', 'value' => (string) $roleId]
|
||||
@@ -107,7 +111,7 @@ class PushNotificationService
|
||||
null,
|
||||
null,
|
||||
$data
|
||||
);
|
||||
); } catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,116 +1,199 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@push('styles')
|
||||
<style>
|
||||
.chat-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
padding: 1rem;
|
||||
}
|
||||
.chat-info {
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 8px;
|
||||
padding: 0.75rem 3.5rem 0.75rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.85rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
.chat-info .btn-verdict {
|
||||
position: absolute;
|
||||
right: 1rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
.chat-info span { color: #495057; }
|
||||
.chat-info strong { color: #212529; }
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.bubble-row {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.bubble-row.right { justify-content: flex-end; }
|
||||
.bubble-row.left { justify-content: flex-start; }
|
||||
.bubble-row.center { justify-content: center; }
|
||||
.bubble {
|
||||
max-width: 60%;
|
||||
padding: 0.6rem 0.9rem;
|
||||
border-radius: 16px;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.4;
|
||||
position: relative;
|
||||
}
|
||||
.bubble-row.right .bubble {
|
||||
background: #0d6efd;
|
||||
color: #fff;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.bubble-row.left .bubble {
|
||||
background: #198754;
|
||||
color: #fff;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.bubble-row.center .bubble {
|
||||
background: #e9ecef;
|
||||
color: #495057;
|
||||
border-radius: 16px;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
max-width: 70%;
|
||||
}
|
||||
.bubble-meta {
|
||||
font-size: 0.7rem;
|
||||
margin-top: 0.25rem;
|
||||
opacity: 0.75;
|
||||
}
|
||||
.bubble-row.right .bubble-meta { text-align: right; color: rgba(255,255,255,0.85); }
|
||||
.bubble-row.left .bubble-meta { text-align: left; color: rgba(255,255,255,0.85); }
|
||||
.bubble-row.center .bubble-meta { text-align: center; color: #6c757d; }
|
||||
.bubble-label {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.2rem;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.chat-input {
|
||||
border-top: 1px solid #dee2e6;
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
.chat-input form {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.chat-input textarea {
|
||||
flex: 1;
|
||||
resize: none;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
.chat-input button {
|
||||
border-radius: 20px;
|
||||
padding: 0.5rem 1.25rem;
|
||||
}
|
||||
.verdict-badge {
|
||||
background: #fff3cd;
|
||||
border: 1px solid #ffc107;
|
||||
border-radius: 8px;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<script src="{{ asset('js/ajaxcrud.js') }}"></script>
|
||||
@if (Auth::user()->role_id >= 5)
|
||||
<div class="container-fluid" style="height:100%">
|
||||
@php
|
||||
$clientId = $contract->user_id;
|
||||
$supplierId = $contract->suppliers->user_id ?? null;
|
||||
@endphp
|
||||
|
||||
<div class="chat-wrapper">
|
||||
|
||||
{{-- Info del contrato --}}
|
||||
<div class="chat-info">
|
||||
<span><strong>Contrato #{{ $contract->id }}</strong></span>
|
||||
<span>Cliente: <strong>{{ $contract->user->name ?? '—' }}</strong></span>
|
||||
<span>Proveedor: <strong>{{ $contract->suppliers->company_name ?? '—' }}</strong></span>
|
||||
<span>Categoría: <strong>{{ $contract->categories->name ?? '—' }}</strong></span>
|
||||
<span>Monto: <strong>${{ $contract->amount }}</strong></span>
|
||||
<span>Cita: <strong>{{ $contract->appointment }}</strong></span>
|
||||
@if($report->veredict)
|
||||
<span>Veredicto: <strong>{{ $report->veredict }}</strong></span>
|
||||
@endif
|
||||
<a class="btn btn-secondary btn-xs btn-verdict" title="Veredict"
|
||||
href="{{ url('reports/veredict/' . $report->id) }}">
|
||||
<i class="fa fa-gavel"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- Leyenda --}}
|
||||
<div class="d-flex gap-3 mb-2" style="font-size:0.78rem; gap:1rem;">
|
||||
<span><span style="display:inline-block;width:12px;height:12px;background:#0d6efd;border-radius:3px;"></span> Cliente</span>
|
||||
<span><span style="display:inline-block;width:12px;height:12px;background:#198754;border-radius:3px;"></span> Proveedor</span>
|
||||
<span><span style="display:inline-block;width:12px;height:12px;background:#e9ecef;border:1px solid #ccc;border-radius:3px;"></span> Moderador</span>
|
||||
</div>
|
||||
|
||||
{{-- Mensajes --}}
|
||||
<div class="chat-messages">
|
||||
@forelse($comments as $comment)
|
||||
@php
|
||||
if ($comment->user_id == $clientId) {
|
||||
$side = 'right';
|
||||
$label = 'Cliente';
|
||||
} elseif ($comment->user_id == $supplierId) {
|
||||
$side = 'left';
|
||||
$label = 'Proveedor';
|
||||
} else {
|
||||
$side = 'center';
|
||||
$label = 'Moderador';
|
||||
}
|
||||
@endphp
|
||||
|
||||
<div class="bubble-row {{ $side }}">
|
||||
<div>
|
||||
@else
|
||||
<div class="container" style="margin:0 1em">
|
||||
<div class="bubble-label text-muted">{{ $label }} — {{ $comment->user->name ?? '—' }}</div>
|
||||
<div class="bubble">
|
||||
{{ $comment->comment }}
|
||||
<div class="bubble-meta">{{ $comment->created_at->format('d/m/Y H:i') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-center text-muted mt-4">Sin comentarios aún.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
{{-- Paginación --}}
|
||||
@if($comments->hasPages())
|
||||
<div class="mb-2">{{ $comments->links() }}</div>
|
||||
@endif
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
<h3>Comentarios del reporte</h3>
|
||||
</div>
|
||||
{{-- Input del moderador --}}
|
||||
<div class="chat-input">
|
||||
<form method="POST" action="{{ url('reports/' . $report->id . '/comments') }}">
|
||||
@csrf
|
||||
@error('comment')
|
||||
<div class="text-danger mb-1" style="font-size:0.8rem;">{{ $message }}</div>
|
||||
@enderror
|
||||
<textarea name="comment" rows="2" class="form-control" placeholder="Escribir comentario como moderador..."></textarea>
|
||||
<button type="submit" class="btn btn-primary mt-2">Enviar</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<h5>Contrato:</h5>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="vertical-align: middle">ID</th>
|
||||
|
||||
<th style="vertical-align: middle">Usuario</th>
|
||||
|
||||
<th style="vertical-align: middle">Proveedor</th>
|
||||
|
||||
<th style="vertical-align: middle">Categoría</th>
|
||||
|
||||
<th style="vertical-align: middle">Dirección</th>
|
||||
|
||||
<th style="vertical-align: middle">Cita</th>
|
||||
|
||||
<th style="vertical-align: middle">Monto</th>
|
||||
|
||||
<th style="vertical-align: middle">Calificación</th>
|
||||
|
||||
<th style="vertical-align: middle">Comentarios</th>
|
||||
|
||||
<th style="vertical-align: middle">Transacción ID</th>
|
||||
|
||||
<th style="vertical-align: middle">Fecha de creación</th>
|
||||
|
||||
<th style="vertical-align: middle">Fecha de fuera de casa</th>
|
||||
|
||||
<th style="vertical-align: middle">Confirmación de descripción de la casa</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$i=1;
|
||||
@endphp
|
||||
<tr>
|
||||
<th>{{ $contract->id }}</th>
|
||||
<td>{{ $contract->user->name ?? null }}</td>
|
||||
<td>{{ $contract->suppliers->company_name ?? null }}</td>
|
||||
<td>{{ $contract->categories->name ?? null }}</td>
|
||||
<td>{{ $contract->address }}</td>
|
||||
<td>{{ $contract->appointment }}</td>
|
||||
<td>${{ $contract->amount }}</td>
|
||||
<td>{{ $contract->score }}</td>
|
||||
<td>{{ $contract->comments }}</td>
|
||||
<td>{{ $contract->transaction_id }}</td>
|
||||
<td>{{ $contract->created_at }}</td>
|
||||
<td>{{ isset($nohome->confirmed_at) }}</td>
|
||||
<td>{{ isset($nohome->house_description) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br><br>
|
||||
<h5>Comentarios:</h5>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="vertical-align: middle"><a href="{{url('comments?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Usuario</a></th>
|
||||
{{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}
|
||||
|
||||
<th style="vertical-align: middle"><a href="{{url('comments?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Teléfono</a></th>
|
||||
{{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}
|
||||
|
||||
<th style="vertical-align: middle"><a href="{{url('comments?field=comment&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Comentario</a></th>
|
||||
{{request()->session()->get('field')=='comment'?(request()->session()->get('sort')=='asc'?'':''):''}}
|
||||
|
||||
<th style="vertical-align: middle"><a href="{{url('contracts?field=created_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Fecha de creación</a></th>
|
||||
{{request()->session()->get('field')=='created_at'?(request()->session()->get('sort')=='asc'?'':''):''}}
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$i=1;
|
||||
@endphp
|
||||
@foreach ($comments as $comment)
|
||||
<tr>
|
||||
<td>{{ $comment->user->name }}</td>
|
||||
<td>{{ $comment->user->phone }}</td>
|
||||
<td>{{ $comment->comment }}</td>
|
||||
<td>{{ $comment->created_at }}</td>
|
||||
<td style="width: 3em">
|
||||
<input type="hidden" name="_method" value="delete"/>
|
||||
<a class="btn btn-danger btn-xs" title="Delete"
|
||||
href="javascript:if(confirm('¿Estás seguro de que quieres eliminar este comentario?')) javascript:if(confirm('Usualmente no se deben eliminar comentarios, solo editarlos ¿Estás seguro?')) ajaxDeleteComments('{{url('reports/comments/delete/'.$comment->id.'/'.$contract->id)}}','{{csrf_token()}}')">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ $comments->links() }}
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -57,13 +57,9 @@
|
||||
<td>{{ $report->veredict }}</td>
|
||||
<td style="width: 10em">
|
||||
<a class="btn btn-primary btn-xs" title="Comments"
|
||||
href="{{url('reports/comments/'.$report->id.'/'.$report->contract_id)}}">
|
||||
href="{{url('reports/'.$report->id.'/comments')}}">
|
||||
<i class="fa fa-comments"></i>
|
||||
</a>
|
||||
<a class="btn btn-secondary btn-xs" title="Veredict"
|
||||
href="{{url('reports/veredict/'.$report->id)}}">
|
||||
<i class="fa fa-gavel"></i>
|
||||
</a>
|
||||
<input type="hidden" name="_method" value="delete"/>
|
||||
<a class="btn btn-danger btn-xs" title="Delete"
|
||||
href="javascript:if(confirm('¿Estás seguro de que quieres eliminar este reporte?')) javascript:if(confirm('Usualmente no se deben eliminar reportes, solo editarlos ¿Estás seguro?')) ajaxDelete('{{url('reports/delete/'.$report->id)}}','{{csrf_token()}}')">
|
||||
|
||||
@@ -57,6 +57,9 @@ Route::group([
|
||||
Route::post('review', 'ContractController@reviewcontract');
|
||||
Route::post('extra', 'ContractController@extra');
|
||||
Route::post('report', 'ReportController@report');
|
||||
Route::get('reports', 'ReportController@getreports');
|
||||
Route::get('reports/{id}/comments', 'ReportController@getcomments');
|
||||
Route::post('reports/{id}/comments', 'ReportController@storecomment');
|
||||
Route::get('nohome-check', 'NoHomeController@nohomecheck');
|
||||
Route::post('nohome-confirm', 'NoHomeController@nohomeconfirm');
|
||||
//Route::post('nohome-test', 'NoHomeController@test');
|
||||
@@ -74,6 +77,7 @@ Route::group([
|
||||
Route::get('get-postulations', 'SupplierController@getpostulation');
|
||||
Route::get('get-contracted-postulations', 'SupplierController@getcontractedpostulation');
|
||||
Route::get('get-finished-postulations', 'PostulationController@getfinishedpostulations');
|
||||
Route::get('postulations/reports', 'ReportController@getsupplierreports');
|
||||
Route::get('get-postulants', 'PostulationController@getpostulants');
|
||||
Route::post('postulate', 'PostulationController@postulate');
|
||||
});
|
||||
|
||||
@@ -126,9 +126,10 @@ Route::group([
|
||||
], function() {
|
||||
Route::get('/', 'ReportController@index')->middleware('rolecheck:6');
|
||||
Route::delete('delete/{id}', 'ReportController@destroy')->middleware('superadmin');
|
||||
Route::get('comments/{id}/{contract_id}', 'ReportCommentController@index')->middleware('rolecheck:6');
|
||||
Route::delete('comments/delete/{id}/{contract_id}', 'ReportCommentController@destroy')->middleware('superadmin');
|
||||
Route::get('veredict/{id}', 'ReportController@veredict')->middleware('rolecheck:6');
|
||||
Route::get('{id}/comments', 'ReportCommentController@index')->middleware('rolecheck:6');
|
||||
Route::post('{id}/comments', 'ReportCommentController@store')->middleware('rolecheck:6');
|
||||
Route::delete('{id}/comments/{comment_id}', 'ReportCommentController@destroy')->middleware('superadmin');
|
||||
Route::match(['get', 'post'], 'veredict/{id}', 'ReportController@veredict')->middleware('rolecheck:6');
|
||||
//Route::match(['get', 'post'], 'create', 'CouponController@create')->middleware('rolecheck:6');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user