Skip to content

Instantly share code, notes, and snippets.

View codigoconjuan's full-sized avatar

Juan Pablo De la torre Valdez codigoconjuan

View GitHub Profile
@codigoconjuan
codigoconjuan / Manage.tsx
Last active May 15, 2026 00:59
Type de Subscripciones
const statusColors = {
green: 'bg-green-50 text-green-600 border-green-200',
yellow: 'bg-yellow-50 text-yellow-600 border-yellow-200',
orange: 'bg-orange-50 text-orange-600 border-orange-200',
red: 'bg-red-50 text-red-600 border-red-200',
gray: 'bg-gray-50 text-gray-700 border-gray-200',
};
@codigoconjuan
codigoconjuan / SubscriptionController.php
Last active May 15, 2026 01:01
Métodos Auxiliares para Suscripciones CashTrackr
private function getNextBillingDate($subscription): ?string
{
return cache()->remember(
"stripe.next_billing.{$subscription->id}",
now()->addHours(1),
function () use ($subscription) {
try {
$stripe = $subscription->asStripeSubscription();
@codigoconjuan
codigoconjuan / web.php
Created May 5, 2026 23:58
Base de Rutas para Suscripciones en CashTrackr
Route::get('/subscription', [SubscriptionController::class, 'show'])
->name('subscription.manage');
Route::post('/subscription/swap/{plan}', [SubscriptionController::class, 'swap'])
->name('subscription.swap')
->whereIn('plan', ['monthly', 'yearly']);
Route::post('/subscription/cancel', [SubscriptionController::class, 'cancel'])
->name('subscription.cancel');
@codigoconjuan
codigoconjuan / subscription-badge.blade.php
Created May 5, 2026 00:08
Componente que muestra tipo de Cuenta de Usuario desde CashTrackr
@if (auth()->user()->isOnYearlyPlan())
<p class="border-2 text-lg border-amber-500 rounded-lg text-amber-500 py-2 px-5 font-black">PRO Anual</p>
@elseif (auth()->user()->isOnMonthlyPlan())
<p class="border-2 text-lg border-amber-500 rounded-lg text-amber-500 py-2 px-5 font-black">PRO Mensual</p>
@else
<a class="border-2 text-lg border-amber-500 rounded-lg text-amber-500 py-2 px-5 font-black" href="{{ route('plans') }}">Suscribirse a PRO</a>
@endif
@codigoconjuan
codigoconjuan / error.blade.php
Last active May 15, 2026 00:50
Página de Success o Error Al Pagar Cashtrackr
@extends('layouts.app')
@section('title')
Error al Pagar
@endsection
@section('dashboard-contents')
<div class="rounded-md bg-red-50 p-4 dark:bg-red-500/15 dark:outline dark:outline-red-500/25">
<div class="flex">
<div class="shrink-0">
@codigoconjuan
codigoconjuan / PricingTable.tsx
Created May 4, 2026 20:07
Tabla de Precios CashTrackr
import { router } from '@inertiajs/react';
import { useState } from 'react';
import { route } from 'ziggy-js';
export default function PricingTable() {
const [loading, setLoading] = useState<string | null>(null);
const subscribe = (plan: 'monthly' | 'yearly') => {
setLoading(plan);
router.post(route('subscription.checkout', { plan }));
@codigoconjuan
codigoconjuan / .env
Last active May 15, 2026 00:48
Variables de Entorno Cashier y STRIPE
STRIPE_KEY=
STRIPE_SECRET=
STRIPE_WEBHOOK_SECRET=
CASHIER_CURRENCY=
CASHIER_CURRENCY_LOCALE=
STRIPE_PRICE_AI_MONTHLY=
STRIPE_PRICE_AI_YEARLY=
@codigoconjuan
codigoconjuan / TicketScanController
Last active May 15, 2026 00:38
Almacenar Gastos de Ticket
private function createExpenses(Budget $budget, string $store, string $category, array $items): array
{
$created = [];
foreach ($items as $item) {
$expense = Expense::create([
'budget_id' => $budget->id,
'name' => $store . ' - ' . $item['name'],
'amount' => $item['amount'],
'category' => $budget->isGeneral() ? $category : null,
@codigoconjuan
codigoconjuan / TicketScanner.php
Created May 3, 2026 22:47
Instrucciones para Agente de Tickets
public function instructions(): string
{
return <<<'PROMPT'
Eres un asistente que lee tickets de venta a partir de una imagen y extrae la información estructurada.
Reglas:
- Devuelve el nombre del negocio en "store".
- La categoría debe ser EXACTAMENTE una de: food, transportation, health, entertainment, subscriptions, beauty, clothing, home, education, pets, other.
- "items" debe contener cada producto con su nombre y precio numérico (sin símbolos de moneda).
- No inventes productos que no estén claramente visibles en el ticket.
@codigoconjuan
codigoconjuan / AddExpense.php
Created May 2, 2026 00:41
Métodos para el Tool de AddExpense
public function handle(Request $request): Stringable|string
{
$name = $request['name'] ?? null;
$amount = $request['amount'] ?? null;
if (!$name || !$amount) {
return '[EXPENSE_ERROR] Se necesita un nombre y un monto para agregar el gasto.';
}