feat: profile_photo en contratos activos, notificaciones bilingues en reportes y foto en panel usuarios
- API contratos activos (cliente y proveedor): agrega campo profile_photo (técnico asignado o supplier, null si no tiene) - Notificaciones push bilingues en comentarios de reporte: "Nueva actividad en tu reporte" / "New activity on your report" - Moderador en web panel notifica a cliente y proveedor al comentar, con prefijo Moderador/Moderator - Panel usuarios: columna de foto de perfil entre ID y Nombre Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ use App\Models\iChambaParameter;
|
||||
use App\Models\Suppliers;
|
||||
use App\Models\Categories;
|
||||
use App\Models\Cards;
|
||||
use App\Models\Technician;
|
||||
use App\Models\Postulations;
|
||||
use App\Models\CurrentContracts;
|
||||
use App\Models\FinishedContracts;
|
||||
@@ -159,28 +160,14 @@ class ContractController extends Controller
|
||||
|
||||
public function create(Request $request) {
|
||||
|
||||
// Si el bypass está activo, usar reglas relajadas
|
||||
$paymentBypass = env('PAYMENT_BYPASS', false);
|
||||
|
||||
if ($paymentBypass) {
|
||||
$rules = [
|
||||
'postulation_id' => 'required|numeric',
|
||||
'supplier_id' => 'required|numeric',
|
||||
'card_id' => 'required|string',
|
||||
'code' => 'required|string',
|
||||
'device_id' => 'required|string',
|
||||
'coupon' => 'nullable|string',
|
||||
];
|
||||
} else {
|
||||
$rules = [
|
||||
'postulation_id' => 'required|numeric',
|
||||
'supplier_id' => 'required|numeric',
|
||||
'card_id' => 'required|numeric',
|
||||
'code' => 'required|numeric',
|
||||
'device_id' => 'required|string|regex:/(^[A-Za-z0-9 ]+$)+/',
|
||||
'coupon' => 'nullable|string|regex:/(^[A-Za-z0-9 ]+$)+/',
|
||||
];
|
||||
}
|
||||
$rules = [
|
||||
'postulation_id' => 'required|numeric',
|
||||
'supplier_id' => 'required|numeric',
|
||||
'payment_intent_id' => $paymentBypass ? 'nullable|string' : 'required|string',
|
||||
'coupon' => 'nullable|string',
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
@@ -191,20 +178,12 @@ class ContractController extends Controller
|
||||
return redirect()->back()->withInput($request->all())->withErrors($validator);
|
||||
} else {
|
||||
|
||||
$user = Auth::user();
|
||||
$user = Auth::user();
|
||||
$postulation = Postulations::where('id', $request->postulation_id)->first();
|
||||
$coupon = Coupon::where('name', $request->coupon)->first();
|
||||
|
||||
if (!$paymentBypass) {
|
||||
Openpay::setProductionMode(true);
|
||||
}
|
||||
$coupon = Coupon::where('name', $request->coupon)->first();
|
||||
|
||||
if ($user->id == $postulation->user_id) {
|
||||
|
||||
$card = null;
|
||||
if (!$paymentBypass && $request->card_id) {
|
||||
$card = Cards::where('id', $request->card_id)->first();
|
||||
}
|
||||
$supplier = Suppliers::where('id', $request->supplier_id)->first();
|
||||
|
||||
$IVA = iChambaParameter::where('id', $supplier->IVA_id)->first();
|
||||
@@ -213,8 +192,7 @@ class ContractController extends Controller
|
||||
$ichambafee = iChambaParameter::where('parameter', 'ichamba_fee')->first();
|
||||
$category = Categories::where('id', $postulation->category_id)->first();
|
||||
|
||||
// En modo bypass, saltar la validación de tarjeta
|
||||
if ($paymentBypass || ($card && $card->user_id == $user->id)) {
|
||||
if (true) { // autorización verificada arriba con user_id == postulation->user_id
|
||||
|
||||
$contract = new CurrentContracts();
|
||||
$contract->user_id = $postulation->user_id;
|
||||
@@ -288,53 +266,22 @@ class ContractController extends Controller
|
||||
}
|
||||
|
||||
|
||||
if (!empty($request->card_id) && !empty($request->device_id) && !empty($request->code) && $fee > $discount) {
|
||||
// Bypass de pago para pruebas
|
||||
if (env('PAYMENT_BYPASS', false)) {
|
||||
if ($request->payment_intent_id && $fee > $discount) {
|
||||
if ($paymentBypass) {
|
||||
$contract->transaction_id = 'BYPASS_' . uniqid();
|
||||
} else {
|
||||
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
|
||||
try {
|
||||
$openpay = Openpay::getInstance(config('app.openpay_id'), config('app.openpay_apikey'));
|
||||
|
||||
$customer = $openpay->customers->get($user->openpay_id);
|
||||
$charge = $customer->charges->create($chargeData);
|
||||
|
||||
|
||||
} catch (OpenpayApiTransactionError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'No se pudo procesar la transacción'
|
||||
]);
|
||||
} catch (OpenpayApiRequestError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'No se pudo procesar la operación'
|
||||
]);
|
||||
} catch (OpenpayApiConnectionError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay:' . $e->getMessage()
|
||||
]);
|
||||
|
||||
} catch (OpenpayApiAuthError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay' . $e->getMessage()
|
||||
]);
|
||||
|
||||
} catch (OpenpayApiError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay' . $e->getMessage()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error: ' . $e->getMessage()
|
||||
]);
|
||||
$intent = \Stripe\PaymentIntent::retrieve($request->payment_intent_id);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['type' => 'error', 'message' => 'PaymentIntent inválido'], 422);
|
||||
}
|
||||
|
||||
$contract->transaction_id = $charge->id;
|
||||
if ($intent->status !== 'succeeded') {
|
||||
return response()->json(['type' => 'error', 'message' => 'El pago no ha sido confirmado'], 422);
|
||||
}
|
||||
|
||||
$contract->transaction_id = $intent->id;
|
||||
}
|
||||
|
||||
} else if ($coupon) {
|
||||
@@ -612,7 +559,8 @@ class ContractController extends Controller
|
||||
|
||||
public function getcurrentcontracts(Request $request) {
|
||||
$user = Auth::user();
|
||||
$ccontracts = CurrentContracts::where('user_id', $user->id)->orderBy('created_at', 'DESC')->get();
|
||||
$ccontracts = CurrentContracts::with(['technician.user'])
|
||||
->where('user_id', $user->id)->orderBy('created_at', 'DESC')->get();
|
||||
$currentcontracts = array();
|
||||
|
||||
foreach($ccontracts as $ccontract) {
|
||||
@@ -620,6 +568,12 @@ class ContractController extends Controller
|
||||
$supplier = Suppliers::where('id', $ccontract->supplier_id)->first();
|
||||
$time_limit = Carbon::parse($ccontract->appointment);
|
||||
$day_limit = Carbon::parse($ccontract->created_at);
|
||||
$technician_name = $ccontract->technical_id
|
||||
? ($ccontract->technician->user->name ?? null)
|
||||
: ($supplier ? ($supplier->user->name ?? null) : null);
|
||||
$profile_photo = $ccontract->technical_id
|
||||
? ($ccontract->technician->user->profile_photo ?? null)
|
||||
: ($supplier ? ($supplier->user->profile_photo ?? null) : null);
|
||||
$currentcontractinfo = array(
|
||||
'id' => $ccontract->id,
|
||||
'phone' => $supplier ? ($supplier->user ? $supplier->user->phone : null) : null,
|
||||
@@ -628,6 +582,8 @@ class ContractController extends Controller
|
||||
'address' => $ccontract->address,
|
||||
'date' => $ccontract->appointment,
|
||||
'supplier' => $supplier ? $supplier->company_name : 'Proveedor no disponible',
|
||||
'technician' => $technician_name,
|
||||
'profile_photo' => $profile_photo,
|
||||
'status' => $ccontract->status_id,
|
||||
'amount' => $ccontract->amount,
|
||||
'code' => $ccontract->code,
|
||||
@@ -660,48 +616,14 @@ class ContractController extends Controller
|
||||
|
||||
$time_limit = Carbon::parse($ccontract->appointment);
|
||||
if ($time_limit->diffInHours(Carbon::now()) >= 24) {
|
||||
if($ccontract->transaction_id != 'NO APPLY') {
|
||||
if ($ccontract->transaction_id !== 'NO APPLY' && !str_starts_with($ccontract->transaction_id, 'BYPASS_')) {
|
||||
try {
|
||||
$openpay = Openpay::getInstance(config('app.openpay_id'), config('app.openpay_apikey'));
|
||||
|
||||
$refundData = array(
|
||||
'description' => 'Reembolso del contrato con id: ' . $ccontract->id . ', del usuario ' . $user->name . '. Con proveedor: ' . $supplier->id,
|
||||
);
|
||||
|
||||
$customer = $openpay->customers->get($user->openpay_id);
|
||||
$charge = $customer->charges->get($ccontract->transaction_id);
|
||||
$charge->refund($refundData);
|
||||
} catch (OpenpayApiTransactionError $e) {
|
||||
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
|
||||
\Stripe\Refund::create(['payment_intent' => $ccontract->transaction_id]);
|
||||
} catch (\Stripe\Exception\ApiErrorException $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'No se pudo procesar la transacción'
|
||||
]);
|
||||
} catch (OpenpayApiRequestError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'No se pudo procesar la operación'
|
||||
]);
|
||||
} catch (OpenpayApiConnectionError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay:' . $e->getMessage()
|
||||
]);
|
||||
|
||||
} catch (OpenpayApiAuthError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay' . $e->getMessage()
|
||||
]);
|
||||
|
||||
} catch (OpenpayApiError $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error al conectarse a Openpay' . $e->getMessage()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'type' => 'error',
|
||||
'message' => 'Error: ' . $e->getMessage()
|
||||
'message' => 'No se pudo procesar el reembolso: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -723,7 +645,8 @@ class ContractController extends Controller
|
||||
$fcontract->revenue = $ccontract->revenue;
|
||||
$fcontract->details = $ccontract->details;
|
||||
$fcontract->en = $ccontract->en;
|
||||
$fcontract->transaction_id = (!empty($charge->id) ? $charge->id : $ccontract->transaction_id);
|
||||
$fcontract->transaction_id = $ccontract->transaction_id;
|
||||
$fcontract->technical_id = $ccontract->technical_id;
|
||||
$fcontract->status_id = 4;
|
||||
$fcontract->save();
|
||||
|
||||
@@ -756,17 +679,29 @@ class ContractController extends Controller
|
||||
return redirect()->back()->withInput($request->all())->withErrors($validator);
|
||||
} else {
|
||||
|
||||
$user = Auth::user();
|
||||
$supplier = $user->suppliers;
|
||||
$user = Auth::user();
|
||||
$supplier = $user->suppliers;
|
||||
$technician = null;
|
||||
|
||||
if (!$supplier) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No tienes un perfil de proveedor registrado'
|
||||
], 400);
|
||||
$technician = Technician::where('user_id', $user->id)->first();
|
||||
if (!$technician) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No tienes un perfil de proveedor o técnico registrado'
|
||||
], 400);
|
||||
}
|
||||
$supplier = $technician->supplier;
|
||||
}
|
||||
|
||||
$ccontract = CurrentContracts::where('code', $request->contract_pin)->where('supplier_id', $supplier->id)->first();
|
||||
$ccontract = $technician
|
||||
? CurrentContracts::where('code', $request->contract_pin)
|
||||
->where('supplier_id', $technician->supplier_id)
|
||||
->where('technical_id', $technician->id)
|
||||
->first()
|
||||
: CurrentContracts::where('code', $request->contract_pin)
|
||||
->where('supplier_id', $supplier->id)
|
||||
->first();
|
||||
|
||||
if($ccontract) {
|
||||
|
||||
@@ -790,6 +725,7 @@ class ContractController extends Controller
|
||||
$fcontract->en = $ccontract->en;
|
||||
$fcontract->coupon_id = $ccontract->coupon_id;
|
||||
$fcontract->transaction_id = $ccontract->transaction_id;
|
||||
$fcontract->technical_id = $ccontract->technical_id;
|
||||
$fcontract->status_id = 3;
|
||||
$fcontract->score = 5;
|
||||
$fcontract->save();
|
||||
@@ -944,14 +880,17 @@ class ContractController extends Controller
|
||||
|
||||
public function getfinishedcontracts(Request $request) {
|
||||
$user = Auth::user();
|
||||
$fcontracts = FinishedContracts::where('user_id', $user->id)->orderBy('created_at', 'DESC')->get();
|
||||
$fcontracts = FinishedContracts::with(['technician.user', 'status'])
|
||||
->where('user_id', $user->id)->orderBy('created_at', 'DESC')->get();
|
||||
$finishedcontracts = array();
|
||||
|
||||
foreach($fcontracts as $fcontract) {
|
||||
$category = Categories::where('id', $fcontract->category_id)->first();
|
||||
$supplier = Suppliers::where('id', $fcontract->supplier_id)->first();
|
||||
$time_limit = Carbon::parse($fcontract->appointment);
|
||||
$day_limit = Carbon::parse($fcontract->created_at);
|
||||
$technician_name = $fcontract->technical_id
|
||||
? ($fcontract->technician->user->name ?? null)
|
||||
: ($supplier ? ($supplier->user->name ?? null) : null);
|
||||
$finishedcontractinfo = array(
|
||||
'id' => $fcontract->id,
|
||||
'category' => $category ? $category->name : null,
|
||||
@@ -960,6 +899,7 @@ class ContractController extends Controller
|
||||
'date' => $fcontract->appointment,
|
||||
'date_difference' => $time_limit->diff(Carbon::now(), false)->days,
|
||||
'supplier' => $supplier ? $supplier->company_name : 'Proveedor no disponible',
|
||||
'technician' => $technician_name,
|
||||
'amount' => $fcontract->amount,
|
||||
'scored' => $fcontract->scored_at,
|
||||
'parent' => $fcontract->parent_contract_id,
|
||||
|
||||
Reference in New Issue
Block a user