Compare commits
3 Commits
5e541f7cd0
...
test/stres
| Author | SHA1 | Date | |
|---|---|---|---|
| c4ff695f2e | |||
| 703158bd06 | |||
| 900ef6cf98 |
@@ -2,7 +2,7 @@
|
|||||||
"info": {
|
"info": {
|
||||||
"_postman_id": "76fd6fd2-53b9-4d92-8e02-1ddcc6207fa2",
|
"_postman_id": "76fd6fd2-53b9-4d92-8e02-1ddcc6207fa2",
|
||||||
"name": "ShopIt API — Complete",
|
"name": "ShopIt API — Complete",
|
||||||
"description": "Colección canónica generada desde las rutas reales de Laravel. Incluye 122 operaciones HTTP, ejemplos de payload, filtros, archivos y tokens separados para Storefront, Admin App y Scanner.\n\nUso rápido:\n1. Ajustá `base_url` y las credenciales.\n2. Ejecutá el Login de la aplicación correspondiente; el token se guarda automáticamente.\n3. Ajustá los IDs y códigos de las variables de colección.\n\nRegeneración: `php postman/generate-shopit-collection.php`.",
|
"description": "Colección canónica generada desde las rutas reales de Laravel. Incluye 137 operaciones HTTP, ejemplos de payload, filtros, archivos y tokens separados para Storefront, Admin App y Scanner.\n\nUso rápido:\n1. Ajustá `base_url` y las credenciales.\n2. Ejecutá el Login de la aplicación correspondiente; el token se guarda automáticamente.\n3. Ajustá los IDs y códigos de las variables de colección.\n\nRegeneración: `php postman/generate-shopit-collection.php`.",
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
},
|
},
|
||||||
"item": [
|
"item": [
|
||||||
@@ -385,6 +385,42 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "redirect Google Auth",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /auth/google/redirect`\n\nControlador: `App\\Domains\\Auth\\Controllers\\GoogleAuthController@redirect`",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/auth/google/redirect?tenant={{tenant_code}}&return_url={{storefront_url}}",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"auth",
|
||||||
|
"google",
|
||||||
|
"redirect"
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
{
|
||||||
|
"key": "tenant",
|
||||||
|
"value": "{{tenant_code}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "return_url",
|
||||||
|
"value": "{{storefront_url}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -572,60 +608,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Checkout Cart Item Cart",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/tenants/{tenant:codigo}/checkout-carts/{cart}/items/{cartItem}`\n\nControlador: `App\\Domains\\Cart\\Controllers\\CartController@updateCheckoutItem`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/checkout-carts/{{cart}}/items/{{cart_item_id}}",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"tenants",
|
|
||||||
"{{tenant_code}}",
|
|
||||||
"checkout-carts",
|
|
||||||
"{{cart}}",
|
|
||||||
"items",
|
|
||||||
"{{cart_item_id}}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\n \"cantidad\": 2\n}",
|
|
||||||
"options": {
|
|
||||||
"raw": {
|
|
||||||
"language": "json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -1169,99 +1151,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Prepare Item Editing Purchase",
|
|
||||||
"request": {
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `POST /api/tenants/{tenant:codigo}/compras/{compra}/edit-items`\n\nControlador: `App\\Domains\\Purchase\\Controllers\\PurchaseController@prepareItemEditing`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/compras/{{purchase_id}}/edit-items",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"tenants",
|
|
||||||
"{{tenant_code}}",
|
|
||||||
"compras",
|
|
||||||
"{{purchase_id}}",
|
|
||||||
"edit-items"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Item Purchase",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/tenants/{tenant:codigo}/compras/{compra}/items/{item}`\n\nControlador: `App\\Domains\\Purchase\\Controllers\\PurchaseController@updateItem`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/compras/{{purchase_id}}/items/{{purchase_item_id}}",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"tenants",
|
|
||||||
"{{tenant_code}}",
|
|
||||||
"compras",
|
|
||||||
"{{purchase_id}}",
|
|
||||||
"items",
|
|
||||||
"{{purchase_item_id}}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\n \"quantity\": 2,\n \"variant_id\": {{variant_id}}\n}",
|
|
||||||
"options": {
|
|
||||||
"raw": {
|
|
||||||
"language": "json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Create Payment Intent Purchase",
|
"name": "Create Payment Intent Purchase",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -2214,7 +2103,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2280,7 +2169,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2320,7 +2209,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2663,6 +2552,45 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Ticket Form",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/forms/fiesta-futbol-infantil/ticket`\n\nControlador: `App\\Domains\\Forms\\Controllers\\AdminApp\\TicketFormController`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"forms",
|
||||||
|
"fiesta-futbol-infantil",
|
||||||
|
"ticket"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Sale Form",
|
"name": "Sale Form",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -2738,6 +2666,44 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ticket Filter Form",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/forms/tickets-filter`\n\nControlador: `App\\Domains\\Forms\\Controllers\\AdminApp\\TicketFilterFormController`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/forms/tickets-filter",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"forms",
|
||||||
|
"tickets-filter"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -3058,6 +3024,84 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Get Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/accommodations/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/accommodations/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"accommodations",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/accommodations/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/accommodations/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"accommodations",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Delete Accommodation",
|
"name": "Delete Accommodation",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3187,6 +3231,84 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Get Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/entries/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/entries/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"entries",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/entries/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/entries/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"entries",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Delete Entry",
|
"name": "Delete Entry",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3316,6 +3438,84 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Get Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/foods/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/foods/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"foods",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/foods/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/foods/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"foods",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Delete Food",
|
"name": "Delete Food",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3445,6 +3645,84 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Get Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/merchandise/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/merchandise/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"merchandise",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Category Visibility",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/merchandise/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/merchandise/visibility",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"merchandise",
|
||||||
|
"visibility"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Delete Merchandise",
|
"name": "Delete Merchandise",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4049,6 +4327,45 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "download Excel Sale",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/sales/excel`\n\nControlador: `App\\Domains\\Sale\\Controllers\\AdminApp\\SaleController@downloadExcel`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/sales/excel",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"sales",
|
||||||
|
"excel"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "List Modifications Sale",
|
"name": "List Modifications Sale",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4088,6 +4405,46 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "download Modifications Excel Sale",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/sales/modifications/excel`\n\nControlador: `App\\Domains\\Sale\\Controllers\\AdminApp\\SaleController@downloadModificationsExcel`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/sales/modifications/excel",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"sales",
|
||||||
|
"modifications",
|
||||||
|
"excel"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Download Modifications PDF Sale",
|
"name": "Download Modifications PDF Sale",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4601,6 +4958,127 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Ticket",
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "List Ticket",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@index`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"tickets"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "download Excel Ticket",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets/excel`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@downloadExcel`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets/excel",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"tickets",
|
||||||
|
"excel"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Download PDF Ticket",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets/pdf`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@downloadPdf`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets/pdf",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"v1",
|
||||||
|
"adminapp",
|
||||||
|
"tenant",
|
||||||
|
"tickets",
|
||||||
|
"pdf"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{admin_token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Tenant",
|
"name": "Tenant",
|
||||||
"item": [
|
"item": [
|
||||||
@@ -5254,6 +5732,11 @@
|
|||||||
"value": "http://localhost:8000",
|
"value": "http://localhost:8000",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "storefront_url",
|
||||||
|
"value": "http://localhost:4200",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "token",
|
"key": "token",
|
||||||
"value": "",
|
"value": "",
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
|
||||||
|
|
||||||
use App\Domains\Forms\Resources\TicketFilterFormResource;
|
|
||||||
use App\Domains\Forms\Services\TicketFilterFormService;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class TicketFilterFormController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(private readonly TicketFilterFormService $formService) {}
|
|
||||||
|
|
||||||
public function __invoke(Request $request): TicketFilterFormResource
|
|
||||||
{
|
|
||||||
$tenant = $request->user('sanctum')->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return TicketFilterFormResource::make($this->formService->get($tenant));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
|
||||||
|
|
||||||
use App\Domains\Forms\Resources\TicketFormResource;
|
|
||||||
use App\Domains\Forms\Services\TicketFormService;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class TicketFormController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(protected TicketFormService $ticketFormService) {}
|
|
||||||
|
|
||||||
public function __invoke(Request $request): TicketFormResource
|
|
||||||
{
|
|
||||||
return TicketFormResource::make(
|
|
||||||
$this->ticketFormService->get(
|
|
||||||
$request->user('sanctum')->tenant()->firstOrFail()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
|
||||||
|
|
||||||
class TicketFilterFormResource extends JsonResource
|
|
||||||
{
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'code' => $this->resource['code'],
|
|
||||||
'action' => $this->resource['action'],
|
|
||||||
'method' => $this->resource['method'],
|
|
||||||
'fields' => $this->resource['fields'],
|
|
||||||
'columns' => $this->resource['columns'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
|
||||||
|
|
||||||
class TicketFormResource extends JsonResource
|
|
||||||
{
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'statuses' => $this->resource['statuses'],
|
|
||||||
'categories' => $this->resource['categories'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Services;
|
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketColumnService;
|
|
||||||
|
|
||||||
class TicketFilterFormService
|
|
||||||
{
|
|
||||||
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly TicketFormService $ticketFormService,
|
|
||||||
private readonly AdminAppTicketColumnService $columnService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function get(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
$fields = $this->commonFields();
|
|
||||||
|
|
||||||
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
|
||||||
$fields = [
|
|
||||||
...$this->fiestaFutbolInfantilFields($tenant),
|
|
||||||
...$fields,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'code' => 'tickets_filter',
|
|
||||||
'action' => '/api/v1/adminapp/tenant/tickets',
|
|
||||||
'method' => 'GET',
|
|
||||||
'fields' => $fields,
|
|
||||||
'columns' => $this->columnService->publicColumns($tenant),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array<string, mixed>> */
|
|
||||||
private function fiestaFutbolInfantilFields(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
$form = $this->ticketFormService->getForFilters($tenant);
|
|
||||||
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'name' => 'category',
|
|
||||||
'query_param' => 'category',
|
|
||||||
'label' => 'Categoría',
|
|
||||||
'type' => 'select',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
'placeholder' => 'Categoría',
|
|
||||||
'options' => array_map(
|
|
||||||
fn (array $category): array => [
|
|
||||||
'value' => $category['value'],
|
|
||||||
'label' => $category['label'],
|
|
||||||
'children' => [
|
|
||||||
'field' => 'product',
|
|
||||||
'disabled' => $category['products'] === [],
|
|
||||||
'options' => array_map(
|
|
||||||
fn (array $product): array => [
|
|
||||||
'value' => $product['value'],
|
|
||||||
'label' => $product['label'],
|
|
||||||
'children' => [
|
|
||||||
'field' => 'type',
|
|
||||||
'disabled' => $product['types'] === [],
|
|
||||||
'options' => $product['types'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
$category['products'],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
$form['categories'],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
$this->dependentSelect('product', 'Producto', 'category'),
|
|
||||||
$this->dependentSelect('type', 'Tipo', 'product'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array<string, mixed>> */
|
|
||||||
private function commonFields(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'name' => 'date',
|
|
||||||
'query_param' => 'date',
|
|
||||||
'label' => 'Fecha',
|
|
||||||
'type' => 'date',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'status',
|
|
||||||
'query_param' => 'status',
|
|
||||||
'label' => 'Estado',
|
|
||||||
'type' => 'select',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
'placeholder' => 'Estado',
|
|
||||||
'options' => [
|
|
||||||
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
|
|
||||||
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
|
|
||||||
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
private function dependentSelect(string $name, string $label, string $dependency): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => $name,
|
|
||||||
'query_param' => $name,
|
|
||||||
'label' => $label,
|
|
||||||
'type' => 'select',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
'placeholder' => $label,
|
|
||||||
'depends_on' => $dependency,
|
|
||||||
'disabled' => true,
|
|
||||||
'options' => [],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,336 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Forms\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Catalog\Models\Variant;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
|
|
||||||
class TicketFormService
|
|
||||||
{
|
|
||||||
private const PRODUCT = 'product';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array<string, array{label: string|null, product: string, type: string|null, order: int}>
|
|
||||||
*/
|
|
||||||
private const CATEGORY_PRESENTATIONS = [
|
|
||||||
'entradas' => [
|
|
||||||
'label' => null,
|
|
||||||
'product' => self::PRODUCT,
|
|
||||||
'type' => null,
|
|
||||||
'order' => 1,
|
|
||||||
],
|
|
||||||
'alojamientos' => [
|
|
||||||
'label' => 'Camping',
|
|
||||||
'product' => 'tipo_alojamiento',
|
|
||||||
'type' => null,
|
|
||||||
'order' => 2,
|
|
||||||
],
|
|
||||||
'camping' => [
|
|
||||||
'label' => null,
|
|
||||||
'product' => 'tipo_alojamiento',
|
|
||||||
'type' => null,
|
|
||||||
'order' => 2,
|
|
||||||
],
|
|
||||||
'comidas' => [
|
|
||||||
'label' => 'Comida',
|
|
||||||
'product' => 'event_date',
|
|
||||||
'type' => 'horario',
|
|
||||||
'order' => 3,
|
|
||||||
],
|
|
||||||
'comida' => [
|
|
||||||
'label' => null,
|
|
||||||
'product' => 'event_date',
|
|
||||||
'type' => 'horario',
|
|
||||||
'order' => 3,
|
|
||||||
],
|
|
||||||
'merchandising' => [
|
|
||||||
'label' => null,
|
|
||||||
'product' => self::PRODUCT,
|
|
||||||
'type' => 'color',
|
|
||||||
'order' => 4,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array{
|
|
||||||
* statuses: list<array{value: string, label: string}>,
|
|
||||||
* categories: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* products: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* types: list<array{value: string, label: string}>
|
|
||||||
* }>
|
|
||||||
* }>
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public function get(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
$items = CatalogItem::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('has_tickets', true)
|
|
||||||
->whereHas('category')
|
|
||||||
->with($this->relations())
|
|
||||||
->orderBy('group_order')
|
|
||||||
->orderBy('nombre')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return $this->build($items);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return active catalog options plus soft-deleted sources still referenced by
|
|
||||||
* tickets, so historical tickets never become impossible to filter.
|
|
||||||
*
|
|
||||||
* @return array{
|
|
||||||
* statuses: list<array{value: string, label: string}>,
|
|
||||||
* categories: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* products: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* types: list<array{value: string, label: string}>
|
|
||||||
* }>
|
|
||||||
* }>
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public function getForFilters(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
$historicalVariantIds = Ticket::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->whereNotNull('source_variant_id')
|
|
||||||
->distinct()
|
|
||||||
->pluck('source_variant_id')
|
|
||||||
->map(fn ($id): int => (int) $id)
|
|
||||||
->all();
|
|
||||||
$historicalCatalogItemIds = Ticket::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->whereNotNull('source_catalog_item_id')
|
|
||||||
->distinct()
|
|
||||||
->pluck('source_catalog_item_id')
|
|
||||||
->map(fn ($id): int => (int) $id)
|
|
||||||
->merge(
|
|
||||||
Variant::withTrashed()
|
|
||||||
->whereKey($historicalVariantIds)
|
|
||||||
->pluck('catalog_item_id')
|
|
||||||
->map(fn ($id): int => (int) $id),
|
|
||||||
)
|
|
||||||
->unique()
|
|
||||||
->values()
|
|
||||||
->all();
|
|
||||||
|
|
||||||
$items = CatalogItem::withTrashed()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->whereHas('category')
|
|
||||||
->where(function ($query) use ($historicalCatalogItemIds): void {
|
|
||||||
$query
|
|
||||||
->where(function ($activeQuery): void {
|
|
||||||
$activeQuery
|
|
||||||
->whereNull('catalog_items.deleted_at')
|
|
||||||
->where('has_tickets', true);
|
|
||||||
})
|
|
||||||
->orWhereIn('catalog_items.id', $historicalCatalogItemIds);
|
|
||||||
})
|
|
||||||
->with([
|
|
||||||
'category',
|
|
||||||
'itemAttributes.attribute.options',
|
|
||||||
'variants' => fn ($query) => $query
|
|
||||||
->withTrashed()
|
|
||||||
->where(function ($variantQuery) use ($historicalVariantIds): void {
|
|
||||||
$variantQuery
|
|
||||||
->whereNull('variantes.deleted_at')
|
|
||||||
->orWhereIn('variantes.id', $historicalVariantIds);
|
|
||||||
}),
|
|
||||||
'variants.definitions.itemAttribute.attribute.options',
|
|
||||||
'variants.eventDates',
|
|
||||||
'variants.eventDate',
|
|
||||||
])
|
|
||||||
->orderBy('group_order')
|
|
||||||
->orderBy('nombre')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return $this->build($items);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, CatalogItem> $items
|
|
||||||
* @return array{
|
|
||||||
* statuses: list<array{value: string, label: string}>,
|
|
||||||
* categories: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* products: list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* types: list<array{value: string, label: string}>
|
|
||||||
* }>
|
|
||||||
* }>
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
private function build(Collection $items): array
|
|
||||||
{
|
|
||||||
$categories = [];
|
|
||||||
|
|
||||||
foreach ($items as $item) {
|
|
||||||
$sourceCategory = trim((string) $item->category?->nombre);
|
|
||||||
$categoryValue = mb_strtolower($sourceCategory);
|
|
||||||
$presentation = self::CATEGORY_PRESENTATIONS[$categoryValue] ?? [
|
|
||||||
'label' => null,
|
|
||||||
'product' => self::PRODUCT,
|
|
||||||
'type' => null,
|
|
||||||
'order' => PHP_INT_MAX,
|
|
||||||
];
|
|
||||||
|
|
||||||
$categories[$categoryValue] ??= [
|
|
||||||
'value' => $categoryValue,
|
|
||||||
'label' => $presentation['label'] ?? $sourceCategory,
|
|
||||||
'order' => $presentation['order'],
|
|
||||||
'products' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($this->products($item, $presentation['product'], $presentation['type']) as $product) {
|
|
||||||
$productValue = $product['value'];
|
|
||||||
$existingProduct = $categories[$categoryValue]['products'][$productValue] ?? [
|
|
||||||
'value' => $productValue,
|
|
||||||
'label' => $product['label'],
|
|
||||||
'types' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($product['types'] as $type) {
|
|
||||||
$existingProduct['types'][$type['value']] = $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categories[$categoryValue]['products'][$productValue] = $existingProduct;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uasort($categories, fn (array $left, array $right): int => $left['order'] <=> $right['order']
|
|
||||||
?: $left['label'] <=> $right['label']);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'statuses' => [
|
|
||||||
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
|
|
||||||
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
|
|
||||||
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
|
|
||||||
],
|
|
||||||
'categories' => array_values(array_map(
|
|
||||||
fn (array $category): array => [
|
|
||||||
'value' => $category['value'],
|
|
||||||
'label' => $category['label'],
|
|
||||||
'products' => array_values(array_map(
|
|
||||||
fn (array $product): array => [
|
|
||||||
'value' => $product['value'],
|
|
||||||
'label' => $product['label'],
|
|
||||||
'types' => array_values($product['types']),
|
|
||||||
],
|
|
||||||
$category['products'],
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
$categories,
|
|
||||||
)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<string> */
|
|
||||||
private function relations(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'category',
|
|
||||||
'itemAttributes.attribute.options',
|
|
||||||
'variants.definitions.itemAttribute.attribute.options',
|
|
||||||
'variants.eventDates',
|
|
||||||
'variants.eventDate',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<array{
|
|
||||||
* value: string,
|
|
||||||
* label: string,
|
|
||||||
* types: list<array{value: string, label: string}>
|
|
||||||
* }>
|
|
||||||
*/
|
|
||||||
private function products(CatalogItem $item, string $productCode, ?string $typeCode): array
|
|
||||||
{
|
|
||||||
if ($productCode === self::PRODUCT) {
|
|
||||||
return [[
|
|
||||||
'value' => $item->slug,
|
|
||||||
'label' => $item->nombre,
|
|
||||||
'types' => $this->types($item, $typeCode),
|
|
||||||
]];
|
|
||||||
}
|
|
||||||
|
|
||||||
$products = [];
|
|
||||||
|
|
||||||
foreach ($item->variants as $variant) {
|
|
||||||
foreach ($this->variantOptions($variant, $productCode) as $productOption) {
|
|
||||||
$productValue = $productOption['value'];
|
|
||||||
$products[$productValue] ??= [
|
|
||||||
'value' => $productValue,
|
|
||||||
'label' => $this->optionLabel($productOption['label'], $productCode),
|
|
||||||
'types' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
|
||||||
$products[$productValue]['types'][$typeOption['value']] = $typeOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values(array_map(
|
|
||||||
fn (array $product): array => [
|
|
||||||
'value' => $product['value'],
|
|
||||||
'label' => $product['label'],
|
|
||||||
'types' => array_values($product['types']),
|
|
||||||
],
|
|
||||||
$products,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array{value: string, label: string}> */
|
|
||||||
private function types(CatalogItem $item, ?string $typeCode): array
|
|
||||||
{
|
|
||||||
$types = [];
|
|
||||||
|
|
||||||
foreach ($item->variants as $variant) {
|
|
||||||
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
|
||||||
$types[$typeOption['value']] = $typeOption;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values($types);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array{value: string, label: string}> */
|
|
||||||
private function variantOptions(Variant $variant, ?string $attributeCode): array
|
|
||||||
{
|
|
||||||
if ($attributeCode === null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$selection = $variant->selectionOptions($variant->catalogItem->itemAttributes)
|
|
||||||
->get($attributeCode);
|
|
||||||
|
|
||||||
if ($selection === null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_is_list($selection) ? $selection : [$selection];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function optionLabel(string $label, string $attributeCode): string
|
|
||||||
{
|
|
||||||
if ($attributeCode !== 'event_date') {
|
|
||||||
return $label;
|
|
||||||
}
|
|
||||||
|
|
||||||
[$day, $month] = array_pad(explode('/', $label), 2, null);
|
|
||||||
|
|
||||||
return $day !== null && $month !== null ? "{$day}/{$month}" : $label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ Provee catálogos y opciones auxiliares para construir formularios del panel adm
|
|||||||
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
||||||
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
||||||
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
||||||
- `TicketFormService`: expone estados y opciones anidadas de categoría, producto y tipo para los tickets de Fiesta Fútbol Infantil.
|
|
||||||
|
|
||||||
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ Bajo `/v1/adminapp/forms`, con `auth:sanctum` y `adminapp.tenant`:
|
|||||||
- `GET /event`.
|
- `GET /event`.
|
||||||
- `GET /sale`.
|
- `GET /sale`.
|
||||||
- `GET /staff`.
|
- `GET /staff`.
|
||||||
- `GET /fiesta-futbol-infantil/ticket`: estados y jerarquía categoría → producto → tipo para filtros de tickets.
|
|
||||||
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
||||||
|
|
||||||
## Dependencias
|
## Dependencias
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ use App\Domains\Forms\Controllers\AdminApp\FoodFormController;
|
|||||||
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\TicketFilterFormController;
|
|
||||||
use App\Domains\Forms\Controllers\AdminApp\TicketFormController;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::prefix('v1/adminapp/forms')
|
Route::prefix('v1/adminapp/forms')
|
||||||
@@ -15,13 +13,6 @@ Route::prefix('v1/adminapp/forms')
|
|||||||
Route::get('event', EventFormController::class);
|
Route::get('event', EventFormController::class);
|
||||||
Route::get('sale', SaleFormController::class);
|
Route::get('sale', SaleFormController::class);
|
||||||
Route::get('staff', StaffFormController::class);
|
Route::get('staff', StaffFormController::class);
|
||||||
Route::get('tickets-filter', TicketFilterFormController::class)
|
|
||||||
->middleware('tenant.menu:adminapp.tickets')
|
|
||||||
->name('adminapp.forms.tickets-filter');
|
|
||||||
Route::get(
|
|
||||||
'fiesta-futbol-infantil/ticket',
|
|
||||||
TicketFormController::class
|
|
||||||
);
|
|
||||||
Route::get(
|
Route::get(
|
||||||
'fiesta-futbol-infantil/merchandise',
|
'fiesta-futbol-infantil/merchandise',
|
||||||
MerchandiseFormController::class
|
MerchandiseFormController::class
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Controllers\AdminApp;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Requests\AdminAppTicketExportRequest;
|
|
||||||
use App\Domains\Ticket\Requests\AdminAppTicketIndexRequest;
|
|
||||||
use App\Domains\Ticket\Resources\AdminApp\AdminAppTicketCollection;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketExcelService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketPdfService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketService;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class TicketController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly AdminAppTicketService $ticketService,
|
|
||||||
private readonly AdminAppTicketPdfService $ticketPdfService,
|
|
||||||
private readonly AdminAppTicketExcelService $ticketExcelService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function index(AdminAppTicketIndexRequest $request): AdminAppTicketCollection
|
|
||||||
{
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return new AdminAppTicketCollection(
|
|
||||||
$this->ticketService->search($tenant, $request->validated())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function downloadPdf(AdminAppTicketExportRequest $request): Response
|
|
||||||
{
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return $this->ticketPdfService->download(
|
|
||||||
$tenant,
|
|
||||||
$this->ticketService->ticketsForExport($tenant, $request->validated()),
|
|
||||||
$request->validated('timezone'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function downloadExcel(AdminAppTicketExportRequest $request): StreamedResponse
|
|
||||||
{
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return $this->ticketExcelService->download(
|
|
||||||
$tenant,
|
|
||||||
$this->ticketService->ticketsForExport($tenant, $request->validated()),
|
|
||||||
$request->validated('timezone'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Requests;
|
|
||||||
|
|
||||||
use App\Domains\Shared\Rules\ValidTimezone;
|
|
||||||
|
|
||||||
class AdminAppTicketExportRequest extends AdminAppTicketIndexRequest
|
|
||||||
{
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
...parent::rules(),
|
|
||||||
'timezone' => ['required', 'string', new ValidTimezone],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Requests;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketColumnService;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class AdminAppTicketIndexRequest extends FormRequest
|
|
||||||
{
|
|
||||||
public function authorize(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, list<string>> */
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
$tenant = $this->user()?->tenant()->first();
|
|
||||||
$sortableKeys = $tenant === null
|
|
||||||
? []
|
|
||||||
: app(AdminAppTicketColumnService::class)->sortableKeys($tenant);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
||||||
'category' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
||||||
'product' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
||||||
'type' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
||||||
'date' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
|
||||||
'status' => [
|
|
||||||
'sometimes',
|
|
||||||
'nullable',
|
|
||||||
Rule::in([
|
|
||||||
Ticket::STATUS_ACTIVE,
|
|
||||||
Ticket::STATUS_USED,
|
|
||||||
Ticket::STATUS_EXPIRED,
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
'page' => ['sometimes', 'integer', 'min:1'],
|
|
||||||
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
|
||||||
'sort_by' => ['sometimes', 'nullable', 'string', Rule::in($sortableKeys)],
|
|
||||||
'sort_direction' => ['sometimes', 'nullable', 'string', Rule::in(['asc', 'desc'])],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Resources\AdminApp;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketResult;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
||||||
|
|
||||||
class AdminAppTicketCollection extends ResourceCollection
|
|
||||||
{
|
|
||||||
/** @var class-string<AdminAppTicketResource> */
|
|
||||||
public $collects = AdminAppTicketResource::class;
|
|
||||||
|
|
||||||
private readonly int $scannedTickets;
|
|
||||||
|
|
||||||
private readonly int $totalTickets;
|
|
||||||
|
|
||||||
public function __construct(AdminAppTicketResult $result)
|
|
||||||
{
|
|
||||||
parent::__construct($result->tickets);
|
|
||||||
|
|
||||||
$this->scannedTickets = $result->scannedTickets;
|
|
||||||
$this->totalTickets = $result->totalTickets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array{scanned_tickets: int, total_tickets: int} */
|
|
||||||
public function with(Request $request): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'scanned_tickets' => $this->scannedTickets,
|
|
||||||
'total_tickets' => $this->totalTickets,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Resources\AdminApp;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use App\Domains\Ticket\Resources\TicketResource;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketRowService;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
/** @mixin Ticket */
|
|
||||||
class AdminAppTicketResource extends TicketResource
|
|
||||||
{
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
$rowService = app(AdminAppTicketRowService::class);
|
|
||||||
$details = $rowService->details($this->resource);
|
|
||||||
|
|
||||||
return [
|
|
||||||
...parent::toArray($request),
|
|
||||||
...$details,
|
|
||||||
'values' => $rowService->values($this->resource, $details),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
|
|
||||||
class AdminAppTicketColumnService
|
|
||||||
{
|
|
||||||
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
|
|
||||||
|
|
||||||
/** @return list<array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string, excel_width: int}> */
|
|
||||||
public function columns(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
$keys = $tenant->codigo === self::FIESTA_FUTBOL_INFANTIL
|
|
||||||
? ['order_number', 'category', 'product', 'type', 'amount', 'client', 'id', 'status', 'scanned_by']
|
|
||||||
: ['order_number', 'product', 'amount', 'client', 'id', 'status', 'scanned_by'];
|
|
||||||
|
|
||||||
$columns = array_map(fn (string $key): array => $this->definitions()[$key], $keys);
|
|
||||||
|
|
||||||
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
|
||||||
$columns = array_map(function (array $column): array {
|
|
||||||
if (in_array($column['key'], ['product', 'type'], true)) {
|
|
||||||
$column['sortable'] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $column;
|
|
||||||
}, $columns);
|
|
||||||
} else {
|
|
||||||
$widths = [
|
|
||||||
'order_number' => '11%',
|
|
||||||
'product' => '15%',
|
|
||||||
'amount' => '10%',
|
|
||||||
'client' => '15%',
|
|
||||||
'id' => '8%',
|
|
||||||
'status' => '8%',
|
|
||||||
'scanned_by' => '11%',
|
|
||||||
];
|
|
||||||
$columns = array_map(function (array $column) use ($widths): array {
|
|
||||||
$column['width'] = $widths[$column['key']];
|
|
||||||
|
|
||||||
return $column;
|
|
||||||
}, $columns);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string}> */
|
|
||||||
public function publicColumns(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
return array_map(function (array $column): array {
|
|
||||||
unset($column['excel_width']);
|
|
||||||
|
|
||||||
return $column;
|
|
||||||
}, $this->columns($tenant));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<string> */
|
|
||||||
public function sortableKeys(Tenant $tenant): array
|
|
||||||
{
|
|
||||||
return array_values(array_map(
|
|
||||||
fn (array $column): string => $column['sort_param'],
|
|
||||||
array_filter($this->columns($tenant), fn (array $column): bool => $column['sortable']),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string, excel_width: int}> */
|
|
||||||
private function definitions(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'order_number' => $this->column('order_number', 'N° de orden', 'order_number', '10.5%', 14),
|
|
||||||
'category' => $this->column('category', 'Categoría', 'text', '11%', 18),
|
|
||||||
'product' => $this->column('product', 'Producto', 'text', '11%', 22),
|
|
||||||
'type' => $this->column('type', 'Tipo', 'text', '8%', 18),
|
|
||||||
'amount' => $this->column('amount', 'Importe', 'currency', '9%', 15),
|
|
||||||
'client' => $this->column('client', 'Cliente', 'text', '13%', 30),
|
|
||||||
'id' => $this->column('id', 'ID', 'text', '7%', 12),
|
|
||||||
'status' => $this->column('status', 'Estado', 'status', '7%', 13),
|
|
||||||
'scanned_by' => $this->column('scanned_by', 'Escaneado por', 'text', '9%', 28),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string, excel_width: int} */
|
|
||||||
private function column(
|
|
||||||
string $key,
|
|
||||||
string $label,
|
|
||||||
string $type,
|
|
||||||
string $width,
|
|
||||||
int $excelWidth,
|
|
||||||
): array {
|
|
||||||
return [
|
|
||||||
'key' => $key,
|
|
||||||
'label' => $label,
|
|
||||||
'type' => $type,
|
|
||||||
'sortable' => true,
|
|
||||||
'sort_param' => $key,
|
|
||||||
'width' => $width,
|
|
||||||
'excel_width' => $excelWidth,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Carbon\CarbonInterface;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class AdminAppTicketExcelService
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly AdminAppTicketReportService $reportService,
|
|
||||||
private readonly AdminAppTicketColumnService $columnService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/** @param Collection<int, Ticket> $tickets */
|
|
||||||
public function download(Tenant $tenant, Collection $tickets, string $timeZone): StreamedResponse
|
|
||||||
{
|
|
||||||
$generatedAt = now();
|
|
||||||
$rows = $this->reportService->rows($tickets);
|
|
||||||
$columns = $this->columnService->columns($tenant);
|
|
||||||
$spreadsheet = new Spreadsheet;
|
|
||||||
$spreadsheet->getProperties()
|
|
||||||
->setCreator('Shopit')
|
|
||||||
->setTitle('Listado de tickets')
|
|
||||||
->setSubject($tenant->nombre);
|
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
|
||||||
$sheet->setTitle('Tickets');
|
|
||||||
$sheet->fromArray([array_column($columns, 'label')], null, 'A1');
|
|
||||||
|
|
||||||
foreach ($rows as $index => $ticket) {
|
|
||||||
$row = $index + 2;
|
|
||||||
foreach ($columns as $columnIndex => $column) {
|
|
||||||
$coordinate = Coordinate::stringFromColumnIndex($columnIndex + 1).$row;
|
|
||||||
$value = $ticket[$column['key']] ?? null;
|
|
||||||
|
|
||||||
if ($column['type'] === 'currency' && $value !== null) {
|
|
||||||
$sheet->setCellValue($coordinate, (float) $value);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($column['type'] === 'date' && $value instanceof CarbonInterface) {
|
|
||||||
$sheet->setCellValue(
|
|
||||||
$coordinate,
|
|
||||||
Date::dateTimeToExcel($value->copy()->timezone($timeZone)),
|
|
||||||
);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
$coordinate,
|
|
||||||
$this->reportService->displayValue($value, $column['type'], $timeZone),
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastRow = max(2, $rows->count() + 1);
|
|
||||||
$lastColumn = Coordinate::stringFromColumnIndex(count($columns));
|
|
||||||
foreach ($columns as $columnIndex => $column) {
|
|
||||||
$letter = Coordinate::stringFromColumnIndex($columnIndex + 1);
|
|
||||||
if ($column['type'] === 'currency') {
|
|
||||||
$sheet->getStyle("{$letter}2:{$letter}{$lastRow}")
|
|
||||||
->getNumberFormat()->setFormatCode('$ #,##0.00');
|
|
||||||
}
|
|
||||||
if ($column['type'] === 'date') {
|
|
||||||
$sheet->getStyle("{$letter}2:{$letter}{$lastRow}")
|
|
||||||
->getNumberFormat()->setFormatCode('dd/mm/yyyy hh:mm');
|
|
||||||
}
|
|
||||||
$sheet->getColumnDimension($letter)->setWidth($column['excel_width']);
|
|
||||||
}
|
|
||||||
$sheet->getStyle("A1:{$lastColumn}1")->applyFromArray([
|
|
||||||
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
|
||||||
'fill' => [
|
|
||||||
'fillType' => Fill::FILL_SOLID,
|
|
||||||
'startColor' => ['rgb' => '26382E'],
|
|
||||||
],
|
|
||||||
'alignment' => ['vertical' => Alignment::VERTICAL_CENTER],
|
|
||||||
]);
|
|
||||||
$sheet->getRowDimension(1)->setRowHeight(24);
|
|
||||||
$sheet->freezePane('A2');
|
|
||||||
$sheet->setAutoFilter("A1:{$lastColumn}{$lastRow}");
|
|
||||||
|
|
||||||
$filename = 'tickets_'.$tenant->codigo.'_'
|
|
||||||
.$generatedAt->copy()->timezone($timeZone)->format('Ymd_His').'.xlsx';
|
|
||||||
|
|
||||||
return response()->streamDownload(function () use ($spreadsheet): void {
|
|
||||||
(new Xlsx($spreadsheet))->save('php://output');
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
|
||||||
}, $filename, [
|
|
||||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
|
||||||
use Barryvdh\DomPDF\PDF as DomPdf;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class AdminAppTicketPdfService
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly AdminAppTicketReportService $reportService,
|
|
||||||
private readonly AdminAppTicketColumnService $columnService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/** @param Collection<int, Ticket> $tickets */
|
|
||||||
public function download(Tenant $tenant, Collection $tickets, string $timeZone): Response
|
|
||||||
{
|
|
||||||
$generatedAt = now();
|
|
||||||
$columns = $this->columnService->columns($tenant);
|
|
||||||
$rows = $this->reportService->rows($tickets);
|
|
||||||
$pdf = Pdf::loadView('pdf.adminapp.tickets', [
|
|
||||||
'tenant' => $tenant,
|
|
||||||
'columns' => $columns,
|
|
||||||
'tickets' => $this->reportService->displayRows($rows, $columns, $timeZone),
|
|
||||||
'generatedAt' => $generatedAt,
|
|
||||||
'timeZone' => $timeZone,
|
|
||||||
])->setPaper('a3', 'landscape');
|
|
||||||
|
|
||||||
$this->addPageNumbers($pdf);
|
|
||||||
|
|
||||||
return $pdf->download(
|
|
||||||
'tickets_'.$tenant->codigo.'_'
|
|
||||||
.$generatedAt->copy()->timezone($timeZone)->format('Ymd_His').'.pdf'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addPageNumbers(DomPdf $pdf): void
|
|
||||||
{
|
|
||||||
$pdf->render();
|
|
||||||
$domPdf = $pdf->getDomPDF();
|
|
||||||
$font = $domPdf->getFontMetrics()->getFont('DejaVu Sans');
|
|
||||||
|
|
||||||
$domPdf->getCanvas()->page_text(
|
|
||||||
565,
|
|
||||||
805,
|
|
||||||
'Página {PAGE_NUM} de {PAGE_COUNT}',
|
|
||||||
$font,
|
|
||||||
7,
|
|
||||||
[0.48, 0.52, 0.49],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class AdminAppTicketReportService
|
|
||||||
{
|
|
||||||
public function __construct(private readonly AdminAppTicketRowService $rowService) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
* @return Collection<int, array<string, mixed>>
|
|
||||||
*/
|
|
||||||
public function rows(Collection $tickets): Collection
|
|
||||||
{
|
|
||||||
return $this->rowService->rows($tickets);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, array<string, mixed>> $rows
|
|
||||||
* @param list<array<string, mixed>> $columns
|
|
||||||
* @return Collection<int, array<string, string>>
|
|
||||||
*/
|
|
||||||
public function displayRows(Collection $rows, array $columns, string $timeZone): Collection
|
|
||||||
{
|
|
||||||
return $this->rowService->displayRows($rows, $columns, $timeZone);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayValue(mixed $value, string $type, string $timeZone): string
|
|
||||||
{
|
|
||||||
return $this->rowService->displayValue($value, $type, $timeZone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
|
||||||
|
|
||||||
final readonly class AdminAppTicketResult
|
|
||||||
{
|
|
||||||
/** @param LengthAwarePaginator<Ticket> $tickets */
|
|
||||||
public function __construct(
|
|
||||||
public LengthAwarePaginator $tickets,
|
|
||||||
public int $scannedTickets,
|
|
||||||
public int $totalTickets,
|
|
||||||
) {}
|
|
||||||
}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\ItemAttribute;
|
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class AdminAppTicketRowService
|
|
||||||
{
|
|
||||||
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
|
|
||||||
|
|
||||||
private const CATEGORY_PRESENTATIONS = [
|
|
||||||
'alojamientos' => ['category' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null],
|
|
||||||
'camping' => ['category' => null, 'product' => 'tipo_alojamiento', 'type' => null],
|
|
||||||
'entradas' => ['category' => null, 'product' => 'product', 'type' => null],
|
|
||||||
'comidas' => ['category' => 'Comida', 'product' => 'event_date', 'type' => 'horario'],
|
|
||||||
'comida' => ['category' => null, 'product' => 'event_date', 'type' => 'horario'],
|
|
||||||
'merchandising' => ['category' => null, 'product' => 'product', 'type' => 'color'],
|
|
||||||
];
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
public function details(Ticket $ticket): array
|
|
||||||
{
|
|
||||||
$purchaseItem = $this->sourcePurchaseItem($ticket);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'source_purchase_id' => $ticket->source_purchase_id,
|
|
||||||
'order_number' => $ticket->source_purchase_id,
|
|
||||||
'product' => $purchaseItem?->item_nombre
|
|
||||||
?? $ticket->sourceCatalogItem?->nombre
|
|
||||||
?? $ticket->name,
|
|
||||||
'amount' => $purchaseItem?->precio_unitario,
|
|
||||||
'client' => $ticket->sourcePurchase?->nombre_apellido ?? $ticket->user?->nombre_apellido,
|
|
||||||
'status' => $ticket->status,
|
|
||||||
'scanned_by' => $ticket->scannerUser?->nombre_apellido,
|
|
||||||
'variant_properties' => $this->variantProperties($ticket),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed>|null $details */
|
|
||||||
public function values(Ticket $ticket, ?array $details = null): array
|
|
||||||
{
|
|
||||||
$details ??= $this->details($ticket);
|
|
||||||
$presentation = $this->presentation($ticket, $details);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'order_number' => $details['order_number'],
|
|
||||||
'category' => $presentation['category'],
|
|
||||||
'product' => $presentation['product'],
|
|
||||||
'type' => $presentation['type'],
|
|
||||||
'amount' => $details['amount'] === null ? null : (float) $details['amount'],
|
|
||||||
'client' => $details['client'] ?? 'Sin nombre',
|
|
||||||
'id' => $ticket->id,
|
|
||||||
'status' => $details['status'],
|
|
||||||
'scanned_by' => $details['scanned_by'] ?? '-',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
* @return Collection<int, array<string, mixed>>
|
|
||||||
*/
|
|
||||||
public function rows(Collection $tickets): Collection
|
|
||||||
{
|
|
||||||
return $tickets->values()->map(fn (Ticket $ticket): array => $this->values($ticket));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, array<string, mixed>> $rows
|
|
||||||
* @param list<array<string, mixed>> $columns
|
|
||||||
* @return Collection<int, array<string, string>>
|
|
||||||
*/
|
|
||||||
public function displayRows(Collection $rows, array $columns, string $timeZone): Collection
|
|
||||||
{
|
|
||||||
return $rows->map(fn (array $row): array => collect($columns)
|
|
||||||
->mapWithKeys(fn (array $column): array => [
|
|
||||||
$column['key'] => $this->displayValue(
|
|
||||||
$row[$column['key']] ?? null,
|
|
||||||
$column['type'],
|
|
||||||
$timeZone,
|
|
||||||
),
|
|
||||||
])
|
|
||||||
->all());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayValue(mixed $value, string $type, string $timeZone): string
|
|
||||||
{
|
|
||||||
if ($value === null || $value === '') {
|
|
||||||
return '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
return match ($type) {
|
|
||||||
'order_number' => '#'.$value,
|
|
||||||
'currency' => '$'.number_format((float) $value, 2, ',', '.'),
|
|
||||||
'status' => match ((string) $value) {
|
|
||||||
Ticket::STATUS_USED => 'Usado',
|
|
||||||
Ticket::STATUS_EXPIRED => 'Vencido',
|
|
||||||
default => 'Activo',
|
|
||||||
},
|
|
||||||
default => (string) $value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $details */
|
|
||||||
private function presentation(Ticket $ticket, array $details): array
|
|
||||||
{
|
|
||||||
$sourceCategory = trim((string) ($ticket->sourceCatalogItem?->category?->nombre ?? '')) ?: '-';
|
|
||||||
|
|
||||||
if ($ticket->tenant_code !== self::FIESTA_FUTBOL_INFANTIL) {
|
|
||||||
return [
|
|
||||||
'category' => $sourceCategory,
|
|
||||||
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
|
||||||
'type' => $this->allPropertyLabels($details) ?: '-',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$configuration = self::CATEGORY_PRESENTATIONS[mb_strtolower($sourceCategory)] ?? null;
|
|
||||||
if ($configuration === null) {
|
|
||||||
return [
|
|
||||||
'category' => $sourceCategory,
|
|
||||||
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
|
||||||
'type' => $this->allPropertyLabels($details) ?: '-',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'category' => $configuration['category'] ?? $sourceCategory,
|
|
||||||
'product' => $configuration['product'] === 'product'
|
|
||||||
? (string) ($details['product'] ?: $ticket->name ?: '-')
|
|
||||||
: ($this->propertyLabels($details, $configuration['product']) ?: '-'),
|
|
||||||
'type' => $configuration['type'] === null
|
|
||||||
? '-'
|
|
||||||
: ($this->propertyLabels($details, $configuration['type']) ?: '-'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $details */
|
|
||||||
private function propertyLabels(array $details, string $code): string
|
|
||||||
{
|
|
||||||
$property = collect($details['variant_properties'] ?? [])->firstWhere('code', $code);
|
|
||||||
$labels = collect($property['values'] ?? [])->pluck('label')->filter();
|
|
||||||
|
|
||||||
if ($code === 'event_date') {
|
|
||||||
$labels = $labels->map(function (string $label): string {
|
|
||||||
[$day, $month] = array_pad(explode('/', $label), 2, null);
|
|
||||||
|
|
||||||
return $day !== null && $month !== null ? "{$day}/{$month}" : $label;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $labels->implode(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $details */
|
|
||||||
private function allPropertyLabels(array $details): string
|
|
||||||
{
|
|
||||||
return collect($details['variant_properties'] ?? [])
|
|
||||||
->flatMap(fn (array $property): array => $property['values'] ?? [])
|
|
||||||
->pluck('label')
|
|
||||||
->filter()
|
|
||||||
->implode(', ');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sourcePurchaseItem(Ticket $ticket): ?PurchaseItem
|
|
||||||
{
|
|
||||||
return $ticket->sourcePurchase?->items->first(function (PurchaseItem $item) use ($ticket): bool {
|
|
||||||
if ($ticket->source_variant_id !== null) {
|
|
||||||
return $item->source_variant_id === $ticket->source_variant_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $item->source_catalog_item_id === $ticket->source_catalog_item_id
|
|
||||||
&& $item->source_variant_id === null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array{code: string, label: string, values: list<array{value: string, label: string}>}> */
|
|
||||||
private function variantProperties(Ticket $ticket): array
|
|
||||||
{
|
|
||||||
$variant = $ticket->sourceVariant;
|
|
||||||
if ($variant === null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$itemAttributes = $variant->definitions
|
|
||||||
->map(fn ($definition) => $definition->itemAttribute)
|
|
||||||
->filter()
|
|
||||||
->merge($variant->catalogItem?->itemAttributes ?? collect())
|
|
||||||
->unique('id')
|
|
||||||
->values();
|
|
||||||
|
|
||||||
return $variant->selectionOptions($itemAttributes)
|
|
||||||
->map(function (array $selection, string $attributeCode) use ($itemAttributes): array {
|
|
||||||
$itemAttribute = $itemAttributes->first(
|
|
||||||
fn (ItemAttribute $itemAttribute): bool => $itemAttribute->attribute?->codigo
|
|
||||||
=== $attributeCode,
|
|
||||||
);
|
|
||||||
$values = array_is_list($selection) ? $selection : [$selection];
|
|
||||||
|
|
||||||
return [
|
|
||||||
'code' => $attributeCode,
|
|
||||||
'label' => $itemAttribute?->attribute?->nombre
|
|
||||||
?? ($attributeCode === 'event_date' ? 'Fecha' : $attributeCode),
|
|
||||||
'values' => array_values($values),
|
|
||||||
];
|
|
||||||
})
|
|
||||||
->values()
|
|
||||||
->all();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,334 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class AdminAppTicketService
|
|
||||||
{
|
|
||||||
private const RELATIONS = [
|
|
||||||
...TicketValidityResolver::RELATIONS,
|
|
||||||
...TicketPresentationResolver::RELATIONS,
|
|
||||||
'user',
|
|
||||||
'scannerUser',
|
|
||||||
'sourceCatalogItem.category',
|
|
||||||
'sourcePurchase.items',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly AdminAppTicketColumnService $columnService,
|
|
||||||
private readonly AdminAppTicketRowService $rowService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, page?: int, per_page?: int, sort_by?: string|null, sort_direction?: string|null} $filters
|
|
||||||
*/
|
|
||||||
public function search(Tenant $tenant, array $filters = []): AdminAppTicketResult
|
|
||||||
{
|
|
||||||
$query = $this->baseQuery($tenant, $filters);
|
|
||||||
$countQuery = clone $query;
|
|
||||||
|
|
||||||
$databaseSorted = $this->applyDatabaseSort($query, $tenant, $filters);
|
|
||||||
|
|
||||||
if (($filters['sort_by'] ?? null) && ! $databaseSorted) {
|
|
||||||
$matchingTickets = (clone $query)
|
|
||||||
->with(self::RELATIONS)
|
|
||||||
->get();
|
|
||||||
$matchingTickets = $this->sortTickets($matchingTickets, $tenant, $filters);
|
|
||||||
$tickets = $this->paginate($matchingTickets, $filters);
|
|
||||||
$scannedTickets = $matchingTickets->whereNotNull('used_at')->count();
|
|
||||||
} else {
|
|
||||||
$tickets = (clone $query)
|
|
||||||
->with(self::RELATIONS)
|
|
||||||
->when(! $databaseSorted, fn (Builder $query): Builder => $query->orderByDesc('id'))
|
|
||||||
->paginateFromRequest()
|
|
||||||
->withQueryString();
|
|
||||||
$scannedTickets = $countQuery->whereNotNull('used_at')->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AdminAppTicketResult(
|
|
||||||
tickets: $tickets,
|
|
||||||
scannedTickets: $scannedTickets,
|
|
||||||
totalTickets: $tickets->total(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, sort_by?: string|null, sort_direction?: string|null} $filters
|
|
||||||
* @return Collection<int, Ticket>
|
|
||||||
*/
|
|
||||||
public function ticketsForExport(Tenant $tenant, array $filters = []): Collection
|
|
||||||
{
|
|
||||||
$query = $this->baseQuery($tenant, $filters);
|
|
||||||
$databaseSorted = $this->applyDatabaseSort($query, $tenant, $filters);
|
|
||||||
$tickets = $query
|
|
||||||
->with(self::RELATIONS)
|
|
||||||
->when(! $databaseSorted, fn (Builder $query): Builder => $query->orderByDesc('id'))
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return $databaseSorted ? $tickets : $this->sortTickets($tickets, $tenant, $filters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, page?: int, per_page?: int} $filters
|
|
||||||
* @return Builder<Ticket>
|
|
||||||
*/
|
|
||||||
private function baseQuery(Tenant $tenant, array $filters): Builder
|
|
||||||
{
|
|
||||||
$search = trim((string) ($filters['q'] ?? ''));
|
|
||||||
|
|
||||||
$query = Ticket::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->when($search !== '', function (Builder $query) use ($search): void {
|
|
||||||
$query->when(
|
|
||||||
ctype_digit($search),
|
|
||||||
fn (Builder $searchQuery): Builder => $searchQuery
|
|
||||||
->where('tickets.id', (int) $search),
|
|
||||||
fn (Builder $searchQuery): Builder => $searchQuery
|
|
||||||
->where('ticket', 'like', "%{$search}%"),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
->when($filters['category'] ?? null, function (Builder $query, string $category): void {
|
|
||||||
$query->whereHas('sourceCatalogItem.category', fn (Builder $categoryQuery): Builder => $categoryQuery
|
|
||||||
->whereRaw('LOWER(nombre) = ?', [mb_strtolower(trim($category))]));
|
|
||||||
})
|
|
||||||
->when($filters['product'] ?? null, function (Builder $query, string $product) use ($filters): void {
|
|
||||||
$this->applyProductFilter($query, (string) ($filters['category'] ?? ''), $product);
|
|
||||||
})
|
|
||||||
->when($filters['type'] ?? null, function (Builder $query, string $type) use ($filters): void {
|
|
||||||
$this->applyTypeFilter($query, (string) ($filters['category'] ?? ''), $type);
|
|
||||||
})
|
|
||||||
->when($filters['date'] ?? null, fn (Builder $query, string $date): Builder => $query
|
|
||||||
->whereHas('sourcePurchase', fn (Builder $purchaseQuery): Builder => $purchaseQuery
|
|
||||||
->whereDate('created_at', $date)));
|
|
||||||
|
|
||||||
$this->applyStatusFilter($query, $filters['status'] ?? null);
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
|
||||||
private function applyProductFilter(Builder $query, string $category, string $product): void
|
|
||||||
{
|
|
||||||
$category = $this->normalizedCategory($category);
|
|
||||||
|
|
||||||
if (in_array($category, ['alojamientos', 'camping'], true)) {
|
|
||||||
$this->whereVariantDefinition($query, 'tipo_alojamiento', $product);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($category, ['comidas', 'comida'], true)) {
|
|
||||||
$query->whereHas('sourceVariant', function (Builder $variantQuery) use ($product): void {
|
|
||||||
$variantQuery->where(function (Builder $dateQuery) use ($product): void {
|
|
||||||
$dateQuery
|
|
||||||
->where('event_date_id', $product)
|
|
||||||
->orWhereHas('eventDates', fn (Builder $eventDateQuery): Builder => $eventDateQuery
|
|
||||||
->whereKey($product));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query->whereHas('sourceCatalogItem', fn (Builder $itemQuery): Builder => $itemQuery
|
|
||||||
->where('slug', $product));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
|
||||||
private function applyTypeFilter(Builder $query, string $category, string $type): void
|
|
||||||
{
|
|
||||||
$attribute = match ($this->normalizedCategory($category)) {
|
|
||||||
'comidas', 'comida' => 'horario',
|
|
||||||
'merchandising' => 'color',
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($attribute !== null) {
|
|
||||||
$this->whereVariantDefinition($query, $attribute, $type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
|
||||||
private function whereVariantDefinition(Builder $query, string $attribute, string $value): void
|
|
||||||
{
|
|
||||||
$query->whereHas('sourceVariant.definitions', fn (Builder $definitionQuery): Builder => $definitionQuery
|
|
||||||
->where('value', $value)
|
|
||||||
->whereHas('itemAttribute.attribute', fn (Builder $attributeQuery): Builder => $attributeQuery
|
|
||||||
->where('codigo', $attribute)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
|
||||||
private function applyStatusFilter(Builder $query, ?string $status): void
|
|
||||||
{
|
|
||||||
if ($status === null || $status === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($status === Ticket::STATUS_USED) {
|
|
||||||
$query->whereNotNull('used_at');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$matchingIds = (clone $query)
|
|
||||||
->whereNull('used_at')
|
|
||||||
->with(TicketValidityResolver::RELATIONS)
|
|
||||||
->get()
|
|
||||||
->filter(fn (Ticket $ticket): bool => $ticket->status === $status)
|
|
||||||
->pluck('id');
|
|
||||||
|
|
||||||
$query->whereIn('tickets.id', $matchingIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function normalizedCategory(string $category): string
|
|
||||||
{
|
|
||||||
return mb_strtolower(trim($category));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Builder<Ticket> $query
|
|
||||||
* @param array{sort_by?: string|null, sort_direction?: string|null} $filters
|
|
||||||
*/
|
|
||||||
private function applyDatabaseSort(Builder $query, Tenant $tenant, array $filters): bool
|
|
||||||
{
|
|
||||||
$sortBy = (string) ($filters['sort_by'] ?? '');
|
|
||||||
if ($sortBy === '') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$direction = ($filters['sort_direction'] ?? 'asc') === 'desc' ? 'desc' : 'asc';
|
|
||||||
|
|
||||||
$sortExpression = match ($sortBy) {
|
|
||||||
'order_number' => 'tickets.source_purchase_id',
|
|
||||||
'id' => 'tickets.id',
|
|
||||||
'amount' => $this->purchaseItemSortQuery('precio_unitario'),
|
|
||||||
'scanned_by' => User::query()
|
|
||||||
->select('nombre_apellido')
|
|
||||||
->whereColumn('users.id', 'tickets.scanner_user_id'),
|
|
||||||
'product' => $tenant->codigo === 'fiesta_futbol_infantil'
|
|
||||||
? null
|
|
||||||
: $this->purchaseItemSortQuery('item_nombre'),
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if ($sortExpression === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query->orderBy($sortExpression, $direction)->orderByDesc('tickets.id');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return Builder<PurchaseItem> */
|
|
||||||
private function purchaseItemSortQuery(string $column): Builder
|
|
||||||
{
|
|
||||||
return PurchaseItem::query()
|
|
||||||
->select($column)
|
|
||||||
->whereColumn('compra_items.compra_id', 'tickets.source_purchase_id')
|
|
||||||
->where(function (Builder $query): void {
|
|
||||||
$query
|
|
||||||
->where(function (Builder $variantQuery): void {
|
|
||||||
$variantQuery
|
|
||||||
->whereNotNull('tickets.source_variant_id')
|
|
||||||
->whereColumn('compra_items.source_variant_id', 'tickets.source_variant_id');
|
|
||||||
})
|
|
||||||
->orWhere(function (Builder $itemQuery): void {
|
|
||||||
$itemQuery
|
|
||||||
->whereNull('tickets.source_variant_id')
|
|
||||||
->whereNull('compra_items.source_variant_id')
|
|
||||||
->whereColumn('compra_items.source_catalog_item_id', 'tickets.source_catalog_item_id');
|
|
||||||
});
|
|
||||||
})
|
|
||||||
->limit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
* @param array{sort_by?: string|null, sort_direction?: string|null} $filters
|
|
||||||
* @return Collection<int, Ticket>
|
|
||||||
*/
|
|
||||||
private function sortTickets(Collection $tickets, Tenant $tenant, array $filters): Collection
|
|
||||||
{
|
|
||||||
$sortBy = (string) ($filters['sort_by'] ?? '');
|
|
||||||
if ($sortBy === '') {
|
|
||||||
return $tickets;
|
|
||||||
}
|
|
||||||
|
|
||||||
$column = collect($this->columnService->columns($tenant))
|
|
||||||
->firstWhere('sort_param', $sortBy);
|
|
||||||
if ($column === null) {
|
|
||||||
return $tickets;
|
|
||||||
}
|
|
||||||
|
|
||||||
$direction = ($filters['sort_direction'] ?? 'asc') === 'desc' ? -1 : 1;
|
|
||||||
$values = $tickets->mapWithKeys(fn (Ticket $ticket): array => [
|
|
||||||
$ticket->getKey() => $this->rowService->values($ticket)[$column['key']] ?? null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $tickets->sort(function (Ticket $left, Ticket $right) use ($column, $direction, $values): int {
|
|
||||||
$leftValue = $values->get($left->getKey());
|
|
||||||
$rightValue = $values->get($right->getKey());
|
|
||||||
|
|
||||||
if ($leftValue === null || $leftValue === '') {
|
|
||||||
return $rightValue === null || $rightValue === '' ? $right->id <=> $left->id : 1;
|
|
||||||
}
|
|
||||||
if ($rightValue === null || $rightValue === '') {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$comparison = $this->compareValues($leftValue, $rightValue, $column['type']);
|
|
||||||
|
|
||||||
return $comparison === 0
|
|
||||||
? $right->id <=> $left->id
|
|
||||||
: $comparison * $direction;
|
|
||||||
})->values();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function compareValues(mixed $left, mixed $right, string $type): int
|
|
||||||
{
|
|
||||||
if (in_array($type, ['currency', 'order_number'], true)) {
|
|
||||||
return (float) $left <=> (float) $right;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type === 'date') {
|
|
||||||
$leftTimestamp = $left instanceof \DateTimeInterface ? $left->getTimestamp() : strtotime((string) $left);
|
|
||||||
$rightTimestamp = $right instanceof \DateTimeInterface ? $right->getTimestamp() : strtotime((string) $right);
|
|
||||||
|
|
||||||
return $leftTimestamp <=> $rightTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type === 'status') {
|
|
||||||
$left = $this->rowService->displayValue($left, $type, 'UTC');
|
|
||||||
$right = $this->rowService->displayValue($right, $type, 'UTC');
|
|
||||||
}
|
|
||||||
|
|
||||||
return strnatcasecmp((string) $left, (string) $right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
* @param array{page?: int, per_page?: int} $filters
|
|
||||||
* @return LengthAwarePaginator<Ticket>
|
|
||||||
*/
|
|
||||||
private function paginate(Collection $tickets, array $filters): LengthAwarePaginator
|
|
||||||
{
|
|
||||||
$page = (int) ($filters['page'] ?? 1);
|
|
||||||
$perPage = (int) ($filters['per_page'] ?? 15);
|
|
||||||
|
|
||||||
return (new LengthAwarePaginator(
|
|
||||||
$tickets->forPage($page, $perPage)->values(),
|
|
||||||
$tickets->count(),
|
|
||||||
$perPage,
|
|
||||||
$page,
|
|
||||||
['path' => request()->url()],
|
|
||||||
))->withQueryString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
229
app/Domains/Ticket/Services/LoadTestTicketDatasetService.php
Normal file
229
app/Domains/Ticket/Services/LoadTestTicketDatasetService.php
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class LoadTestTicketDatasetService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly TicketGeneratorService $ticketGenerator,
|
||||||
|
private readonly TicketValidityResolver $validityResolver,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* run_id: string,
|
||||||
|
* tenant_code: string,
|
||||||
|
* catalog_item_id: int,
|
||||||
|
* variant_id: int|null,
|
||||||
|
* tickets: int,
|
||||||
|
* scanners: int,
|
||||||
|
* owners: int,
|
||||||
|
* rows: array<int, array{scanner_token: string, ticket_uuid: string, expected_status: int}>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function prepare(
|
||||||
|
string $tenantCode,
|
||||||
|
int $ticketCount,
|
||||||
|
int $scannerCount,
|
||||||
|
int $ownerCount,
|
||||||
|
?int $catalogItemId = null,
|
||||||
|
?int $variantId = null,
|
||||||
|
?string $runId = null,
|
||||||
|
): array {
|
||||||
|
$this->validateInput($tenantCode, $ticketCount, $scannerCount, $ownerCount);
|
||||||
|
|
||||||
|
$tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
|
||||||
|
$catalogItem = $this->resolveCatalogItem($tenant, $catalogItemId);
|
||||||
|
$variant = $this->resolveVariant($catalogItem, $variantId);
|
||||||
|
$runId ??= now()->format('Ymd-His').'-'.Str::lower(Str::random(6));
|
||||||
|
|
||||||
|
if (preg_match('/\A[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}\z/', $runId) !== 1) {
|
||||||
|
throw new InvalidArgumentException('run_id contiene caracteres inválidos o es demasiado largo.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($variant !== null && ! $this->validityResolver->resolveVariant($variant)->isValid()) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'La variante seleccionada no tiene una vigencia activa y resoluble.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scanners = $this->scanners($tenant, $catalogItem, $scannerCount);
|
||||||
|
$owners = $this->owners($tenant, $ownerCount);
|
||||||
|
$tokens = $scanners->map(function (User $scanner): string {
|
||||||
|
$scanner->tokens()->where('name', 'load-test-scanner')->delete();
|
||||||
|
|
||||||
|
return $scanner->createToken(
|
||||||
|
'load-test-scanner',
|
||||||
|
['scanner'],
|
||||||
|
now()->addMinutes((int) config('sanctum.expiration', 720)),
|
||||||
|
)->plainTextToken;
|
||||||
|
})->values();
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
$remaining = $ticketCount;
|
||||||
|
$ownerIndex = 0;
|
||||||
|
$scannerIndex = 0;
|
||||||
|
$batchSize = min(500, max(1, (int) ceil($ticketCount / $ownerCount)));
|
||||||
|
|
||||||
|
while ($remaining > 0) {
|
||||||
|
$quantity = min($batchSize, $remaining);
|
||||||
|
$owner = $owners[$ownerIndex % $owners->count()];
|
||||||
|
$tickets = $this->ticketGenerator->generate(
|
||||||
|
$catalogItem,
|
||||||
|
$owner,
|
||||||
|
$quantity,
|
||||||
|
$variant?->getKey(),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($tickets as $ticket) {
|
||||||
|
if (! $ticket->is_valid) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'La configuración seleccionada genera tickets que no están vigentes.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows[] = [
|
||||||
|
'scanner_token' => $tokens[$scannerIndex % $tokens->count()],
|
||||||
|
'ticket_uuid' => $ticket->ticket,
|
||||||
|
'expected_status' => 200,
|
||||||
|
];
|
||||||
|
$scannerIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining -= $quantity;
|
||||||
|
$ownerIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'run_id' => $runId,
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'catalog_item_id' => $catalogItem->getKey(),
|
||||||
|
'variant_id' => $variant?->getKey(),
|
||||||
|
'tickets' => count($rows),
|
||||||
|
'scanners' => $scanners->count(),
|
||||||
|
'owners' => $owners->count(),
|
||||||
|
'rows' => $rows,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateInput(
|
||||||
|
string $tenantCode,
|
||||||
|
int $ticketCount,
|
||||||
|
int $scannerCount,
|
||||||
|
int $ownerCount,
|
||||||
|
): void {
|
||||||
|
foreach ([
|
||||||
|
'tickets' => [$ticketCount, 100_000],
|
||||||
|
'scanners' => [$scannerCount, 10_000],
|
||||||
|
'owners' => [$ownerCount, 100_000],
|
||||||
|
] as $name => [$value, $maximum]) {
|
||||||
|
if ($value < 1 || $value > $maximum) {
|
||||||
|
throw new InvalidArgumentException("{$name} debe estar entre 1 y {$maximum}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($scannerCount > $ticketCount || $ownerCount > $ticketCount) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'La cantidad de scanners y propietarios no puede superar la cantidad de tickets.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveCatalogItem(Tenant $tenant, ?int $catalogItemId): CatalogItem
|
||||||
|
{
|
||||||
|
$query = $tenant->catalogItems()
|
||||||
|
->where('has_tickets', true)
|
||||||
|
->where('type', CatalogItemType::Standard->value);
|
||||||
|
|
||||||
|
if ($catalogItemId !== null) {
|
||||||
|
$query->whereKey($catalogItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$catalogItem = $query->first();
|
||||||
|
|
||||||
|
if ($catalogItem === null) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'No se encontró un producto estándar con tickets habilitados para el tenant.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tenant->requiresScannerCategoryValidation() && $catalogItem->category_id === null) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'El producto debe tener una categoría para autorizar a los scanners.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $catalogItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveVariant(CatalogItem $catalogItem, ?int $variantId): ?Variant
|
||||||
|
{
|
||||||
|
if ($variantId === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$variant = $catalogItem->variants()->whereKey($variantId)->first();
|
||||||
|
|
||||||
|
if ($variant === null) {
|
||||||
|
throw new InvalidArgumentException('La variante no pertenece al producto seleccionado.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, User> */
|
||||||
|
private function scanners(Tenant $tenant, CatalogItem $catalogItem, int $count): Collection
|
||||||
|
{
|
||||||
|
return Collection::times($count, function (int $number) use ($tenant, $catalogItem): User {
|
||||||
|
$scanner = User::query()->updateOrCreate(
|
||||||
|
['email' => $this->email($tenant, 'scanner', $number)],
|
||||||
|
[
|
||||||
|
'nombre_apellido' => "Load test scanner {$number}",
|
||||||
|
'password' => Str::password(32),
|
||||||
|
'rol_codigo' => RoleCode::Scanner->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if ($tenant->requiresScannerCategoryValidation()) {
|
||||||
|
$scanner->scanCategories()->syncWithoutDetaching([$catalogItem->category_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $scanner;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, User> */
|
||||||
|
private function owners(Tenant $tenant, int $count): Collection
|
||||||
|
{
|
||||||
|
return Collection::times($count, function (int $number) use ($tenant): User {
|
||||||
|
$owner = User::query()->updateOrCreate(
|
||||||
|
['email' => $this->email($tenant, 'owner', $number)],
|
||||||
|
[
|
||||||
|
'nombre_apellido' => "Load test owner {$number}",
|
||||||
|
'password' => Str::password(32),
|
||||||
|
'rol_codigo' => RoleCode::User->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return $owner;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function email(Tenant $tenant, string $kind, int $number): string
|
||||||
|
{
|
||||||
|
$tenantSlug = Str::lower(preg_replace('/[^a-z0-9]+/i', '-', $tenant->codigo));
|
||||||
|
|
||||||
|
return "loadtest+{$tenantSlug}.{$kind}.{$number}@shopit.test";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,33 @@ vigente, vencido o usado, y resuelve sus fechas efectivas de inicio y fin sin pe
|
|||||||
3. `TicketGeneratorService` crea los tickets requeridos según ítems, cantidades y vigencia.
|
3. `TicketGeneratorService` crea los tickets requeridos según ítems, cantidades y vigencia.
|
||||||
4. `Notification` envía la confirmación de compra después de la generación y adjunta los tickets cuando existen.
|
4. `Notification` envía la confirmación de compra después de la generación y adjunta los tickets cuando existen.
|
||||||
|
|
||||||
|
## Datos descartables para pruebas de carga
|
||||||
|
|
||||||
|
En ambientes `local`, `testing`, `staging`, `homo` u `homologation`, el comando siguiente crea tickets
|
||||||
|
válidos, identidades scanner con tokens Sanctum y un dataset JSON importable por Postman:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan load-test:tickets:prepare loadtest-evento \
|
||||||
|
--tickets=40000 \
|
||||||
|
--scanners=100 \
|
||||||
|
--owners=1000 \
|
||||||
|
--catalog-item=123 \
|
||||||
|
--run=evento-001
|
||||||
|
```
|
||||||
|
|
||||||
|
El tenant debe existir y se recomienda que sea exclusivo para carga. Si no se indica `--catalog-item`,
|
||||||
|
se usa el primer producto estándar del tenant con tickets habilitados. `--variant`
|
||||||
|
es opcional; al indicarlo, su configuración de vigencia debe estar activa y ser resoluble. Sin variante,
|
||||||
|
los tickets tienen vigencia irrestricta.
|
||||||
|
|
||||||
|
El archivo se escribe por defecto en `storage/app/private/load-tests/` y contiene tokens secretos, por
|
||||||
|
lo que no debe versionarse. Para limpiar el tenant después de la ejecución:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan tenants:reset-transactions loadtest-evento --dry-run
|
||||||
|
php artisan tenants:reset-transactions loadtest-evento
|
||||||
|
```
|
||||||
|
|
||||||
## Endpoints
|
## Endpoints
|
||||||
|
|
||||||
Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
||||||
@@ -30,12 +57,6 @@ Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
|||||||
- `GET /tickets`.
|
- `GET /tickets`.
|
||||||
- `POST /tickets/pdf`.
|
- `POST /tickets/pdf`.
|
||||||
|
|
||||||
Bajo `/v1/adminapp/tenant`, protegido por `auth:sanctum`, `adminapp.tenant` y el menú
|
|
||||||
`adminapp.tickets`:
|
|
||||||
|
|
||||||
- `GET /tickets`, paginado y con búsqueda opcional mediante `q`. La respuesta incluye
|
|
||||||
`scanned_tickets` y `total_tickets` para el tenant autenticado.
|
|
||||||
|
|
||||||
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
||||||
|
|
||||||
## Dependencias y reglas
|
## Dependencias y reglas
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Domains\Ticket\Controllers\AdminApp\TicketController;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
|
||||||
|
|
||||||
Route::prefix('v1/adminapp/tenant')
|
|
||||||
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
|
||||||
->group(function (): void {
|
|
||||||
Route::get('tickets', [TicketController::class, 'index'])
|
|
||||||
->middleware('tenant.menu:adminapp.tickets')
|
|
||||||
->name('adminapp.tickets.index');
|
|
||||||
Route::get('tickets/pdf', [TicketController::class, 'downloadPdf'])
|
|
||||||
->middleware('tenant.menu:adminapp.tickets')
|
|
||||||
->name('adminapp.tickets.pdf');
|
|
||||||
Route::get('tickets/excel', [TicketController::class, 'downloadExcel'])
|
|
||||||
->middleware('tenant.menu:adminapp.tickets')
|
|
||||||
->name('adminapp.tickets.excel');
|
|
||||||
});
|
|
||||||
@@ -11,4 +11,3 @@ Route::prefix('tenants/{tenant:codigo}')
|
|||||||
});
|
});
|
||||||
|
|
||||||
require __DIR__.'/scanner.php';
|
require __DIR__.'/scanner.php';
|
||||||
require __DIR__.'/adminapp.php';
|
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
private const MENU_CODE = 'adminapp.tickets';
|
|
||||||
|
|
||||||
private const TENANT_CODE = 'fiesta_futbol_infantil';
|
|
||||||
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
if (! DB::table('menues')->where('code', 'main.adminapp')->exists()) {
|
|
||||||
// Reference data is added by seeders on fresh installations.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$now = now();
|
|
||||||
|
|
||||||
DB::transaction(function () use ($now): void {
|
|
||||||
DB::table('menues')->updateOrInsert(
|
|
||||||
['code' => self::MENU_CODE],
|
|
||||||
[
|
|
||||||
'label' => 'Tickets',
|
|
||||||
'parent_menu_code' => 'main.adminapp',
|
|
||||||
'content_type' => 'dynamic',
|
|
||||||
'static_content_schema' => null,
|
|
||||||
'route' => '/admin/tickets',
|
|
||||||
'created_at' => $now,
|
|
||||||
'updated_at' => $now,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
DB::table('tenants_menues')
|
|
||||||
->where('menu_code', self::MENU_CODE)
|
|
||||||
->where('tenant_code', '!=', self::TENANT_CODE)
|
|
||||||
->delete();
|
|
||||||
|
|
||||||
if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
|
||||||
DB::table('tenants_menues')->updateOrInsert(
|
|
||||||
[
|
|
||||||
'tenant_code' => self::TENANT_CODE,
|
|
||||||
'menu_code' => self::MENU_CODE,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'static_content' => null,
|
|
||||||
'created_at' => $now,
|
|
||||||
'updated_at' => $now,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::table('roles')
|
|
||||||
->whereIn('codigo', ['admin', 'adminapp'])
|
|
||||||
->pluck('codigo')
|
|
||||||
->each(function (string $roleCode): void {
|
|
||||||
DB::table('roles_menues')->updateOrInsert([
|
|
||||||
'rol_codigo' => $roleCode,
|
|
||||||
'menu_codigo' => self::MENU_CODE,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
DB::transaction(function (): void {
|
|
||||||
DB::table('tenants_menues')
|
|
||||||
->where('menu_code', self::MENU_CODE)
|
|
||||||
->delete();
|
|
||||||
|
|
||||||
DB::table('roles_menues')
|
|
||||||
->where('menu_codigo', self::MENU_CODE)
|
|
||||||
->delete();
|
|
||||||
|
|
||||||
DB::table('menues')
|
|
||||||
->where('code', self::MENU_CODE)
|
|
||||||
->delete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -78,12 +78,6 @@ class MenuSeeder extends Seeder
|
|||||||
'parent_menu_code' => 'main.adminapp',
|
'parent_menu_code' => 'main.adminapp',
|
||||||
'route' => '/admin/staff',
|
'route' => '/admin/staff',
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'code' => 'adminapp.tickets',
|
|
||||||
'label' => 'Tickets',
|
|
||||||
'parent_menu_code' => 'main.adminapp',
|
|
||||||
'route' => '/admin/tickets',
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'label' => 'Entradas',
|
'label' => 'Entradas',
|
||||||
@@ -276,7 +270,6 @@ class MenuSeeder extends Seeder
|
|||||||
'fiesta_futbol_infantil',
|
'fiesta_futbol_infantil',
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenuCodes = [
|
$fiestaCategoryMenuCodes = [
|
||||||
'adminapp.tickets',
|
|
||||||
'adminapp.fiesta-futbol-infantil.entradas',
|
'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</include>
|
</include>
|
||||||
</source>
|
</source>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing" force="true"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="DB_DATABASE" value="shopit_test" force="true"/>
|
<env name="DB_DATABASE" value="shopit_test" force="true"/>
|
||||||
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
||||||
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ declare(strict_types=1);
|
|||||||
$root = dirname(__DIR__);
|
$root = dirname(__DIR__);
|
||||||
chdir($root);
|
chdir($root);
|
||||||
|
|
||||||
$command = escapeshellarg(PHP_BINARY).' artisan route:list --path=api --json';
|
$command = escapeshellarg(PHP_BINARY).' artisan route:list --json';
|
||||||
$routeJson = shell_exec($command);
|
$routeJson = shell_exec($command);
|
||||||
|
|
||||||
if (! is_string($routeJson) || trim($routeJson) === '') {
|
if (! is_string($routeJson) || trim($routeJson) === '') {
|
||||||
@@ -20,6 +20,11 @@ if (! is_string($routeJson) || trim($routeJson) === '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$routes = json_decode($routeJson, true, flags: JSON_THROW_ON_ERROR);
|
$routes = json_decode($routeJson, true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
$routes = array_values(array_filter(
|
||||||
|
$routes,
|
||||||
|
fn (array $route): bool => str_starts_with($route['uri'], 'api/')
|
||||||
|
|| $route['uri'] === 'auth/google/redirect',
|
||||||
|
));
|
||||||
|
|
||||||
const TINY_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
const TINY_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
@@ -177,6 +182,10 @@ function bodyFor(string $method, string $uri): ?array
|
|||||||
function queryFor(string $uri): array
|
function queryFor(string $uri): array
|
||||||
{
|
{
|
||||||
return match ($uri) {
|
return match ($uri) {
|
||||||
|
'auth/google/redirect' => [
|
||||||
|
['key' => 'tenant', 'value' => '{{tenant_code}}'],
|
||||||
|
['key' => 'return_url', 'value' => '{{storefront_url}}'],
|
||||||
|
],
|
||||||
'api/tenants/bootstrap' => [['key' => 'dominio', 'value' => '{{tenant_domain}}'], ['key' => 'path', 'value' => '/']],
|
'api/tenants/bootstrap' => [['key' => 'dominio', 'value' => '{{tenant_domain}}'], ['key' => 'path', 'value' => '/']],
|
||||||
'api/v1/adminapp/bootstrap/{dominio}', 'api/v1/scanner/bootstrap/{dominio}' => [['key' => 'path', 'value' => '/']],
|
'api/v1/adminapp/bootstrap/{dominio}', 'api/v1/scanner/bootstrap/{dominio}' => [['key' => 'path', 'value' => '/']],
|
||||||
'api/tenants/{tenant:codigo}/catalog-items' => [['key' => 'q', 'value' => 'demo'], ['key' => 'page', 'value' => '1']],
|
'api/tenants/{tenant:codigo}/catalog-items' => [['key' => 'q', 'value' => 'demo'], ['key' => 'page', 'value' => '1']],
|
||||||
@@ -415,6 +424,7 @@ foreach ($tree as $section => $folders) {
|
|||||||
|
|
||||||
$variables = [
|
$variables = [
|
||||||
'base_url' => 'http://localhost:8000',
|
'base_url' => 'http://localhost:8000',
|
||||||
|
'storefront_url' => 'http://localhost:4200',
|
||||||
'token' => '', 'admin_token' => '', 'scanner_token' => '',
|
'token' => '', 'admin_token' => '', 'scanner_token' => '',
|
||||||
'user_email' => 'usuario@example.com', 'user_password' => 'Password!123',
|
'user_email' => 'usuario@example.com', 'user_password' => 'Password!123',
|
||||||
'admin_email' => 'admin@example.com', 'admin_password' => 'Password!123',
|
'admin_email' => 'admin@example.com', 'admin_password' => 'Password!123',
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="es">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
||||||
<style>
|
|
||||||
@page { margin: 28px 34px 58px; }
|
|
||||||
body { color: #17211b; font-family: DejaVu Sans, sans-serif; font-size: 11px; margin: 0; }
|
|
||||||
h1 { font-size: 21px; margin: 0 0 3px; }
|
|
||||||
.subtitle { color: #66736b; margin: 0 0 15px; }
|
|
||||||
.summary { background: #eef5f1; border-left: 4px solid #198754; margin-bottom: 14px; padding: 8px 11px; }
|
|
||||||
.summary strong { font-size: 12px; }
|
|
||||||
table { border-collapse: collapse; width: 100%; }
|
|
||||||
thead { display: table-header-group; }
|
|
||||||
tr { page-break-inside: avoid; }
|
|
||||||
th { background: #26382e; color: #fff; font-size: 11px; letter-spacing: .25px; padding: 6px 5px; text-align: left; text-transform: uppercase; }
|
|
||||||
td { border-bottom: 1px solid #dfe7e2; overflow-wrap: break-word; padding: 6px 5px; vertical-align: top; }
|
|
||||||
tbody tr:nth-child(even) { background: #f7f9f8; }
|
|
||||||
.number { text-align: right; }
|
|
||||||
.ticket-id { font-size: 11px; word-break: break-all; }
|
|
||||||
.empty { color: #66736b; padding: 24px; text-align: center; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Listado de tickets</h1>
|
|
||||||
<p class="subtitle">{{ $tenant->nombre }} · Generado el {{ $generatedAt->copy()->timezone($timeZone)->format('d/m/Y H:i') }}</p>
|
|
||||||
|
|
||||||
<div class="summary">
|
|
||||||
Tickets incluidos: <strong>{{ $tickets->count() }}</strong>
|
|
||||||
·
|
|
||||||
Escaneados: <strong>{{ $tickets->where('status', 'Usado')->count() }}</strong>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
@foreach ($columns as $column)
|
|
||||||
<th @class(['number' => $column['type'] === 'currency'])>{{ $column['label'] }}</th>
|
|
||||||
@endforeach
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@forelse ($tickets as $ticket)
|
|
||||||
<tr>
|
|
||||||
@foreach ($columns as $column)
|
|
||||||
<td @class([
|
|
||||||
'number' => $column['type'] === 'currency',
|
|
||||||
'ticket-id' => $column['key'] === 'ticket',
|
|
||||||
])>{{ $ticket[$column['key']] }}</td>
|
|
||||||
@endforeach
|
|
||||||
</tr>
|
|
||||||
@empty
|
|
||||||
<tr><td class="empty" colspan="{{ count($columns) }}">No hay tickets para los criterios seleccionados.</td></tr>
|
|
||||||
@endforelse
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -3,9 +3,11 @@
|
|||||||
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
||||||
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
||||||
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
||||||
|
use App\Domains\Ticket\Services\LoadTestTicketDatasetService;
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Schedule;
|
use Illuminate\Support\Facades\Schedule;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
Artisan::command('inspire', function () {
|
Artisan::command('inspire', function () {
|
||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
@@ -24,6 +26,79 @@ Schedule::command('reservations:expire')
|
|||||||
->everyMinute()
|
->everyMinute()
|
||||||
->withoutOverlapping();
|
->withoutOverlapping();
|
||||||
|
|
||||||
|
Artisan::command(
|
||||||
|
'load-test:tickets:prepare
|
||||||
|
{tenant : Código del tenant que recibirá los datos de carga}
|
||||||
|
{--tickets=1000 : Cantidad de tickets válidos}
|
||||||
|
{--scanners=10 : Cantidad de identidades scanner}
|
||||||
|
{--owners=100 : Cantidad de propietarios de tickets}
|
||||||
|
{--catalog-item= : Producto estándar con tickets habilitados}
|
||||||
|
{--variant= : Variante opcional que define la vigencia}
|
||||||
|
{--run= : Identificador opcional de la ejecución}
|
||||||
|
{--output= : Ruta relativa dentro del disco local}',
|
||||||
|
function (LoadTestTicketDatasetService $datasetService): int {
|
||||||
|
if (! app()->environment(['local', 'testing', 'staging', 'homo', 'homologation'])) {
|
||||||
|
$this->error('Este comando sólo puede ejecutarse en local u homologación.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestedOutput = filled($this->option('output'))
|
||||||
|
? ltrim((string) $this->option('output'), '/\\')
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if ($requestedOutput !== null
|
||||||
|
&& ($requestedOutput === '' || str_contains(str_replace('\\', '/', $requestedOutput), '../'))) {
|
||||||
|
$this->error('La ruta de salida debe permanecer dentro del disco local.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dataset = $datasetService->prepare(
|
||||||
|
(string) $this->argument('tenant'),
|
||||||
|
(int) $this->option('tickets'),
|
||||||
|
(int) $this->option('scanners'),
|
||||||
|
(int) $this->option('owners'),
|
||||||
|
filled($this->option('catalog-item')) ? (int) $this->option('catalog-item') : null,
|
||||||
|
filled($this->option('variant')) ? (int) $this->option('variant') : null,
|
||||||
|
filled($this->option('run')) ? (string) $this->option('run') : null,
|
||||||
|
);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
$this->error($exception->getMessage());
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$relativePath = $requestedOutput !== null
|
||||||
|
? $requestedOutput
|
||||||
|
: "load-tests/{$dataset['run_id']}.postman.json";
|
||||||
|
$payload = json_encode($dataset['rows'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
|
if (! is_string($payload) || ! Storage::disk('local')->put($relativePath, $payload.PHP_EOL)) {
|
||||||
|
$this->error('No se pudo escribir el dataset.');
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('Dataset de carga generado.');
|
||||||
|
$this->table(['Dato', 'Valor'], [
|
||||||
|
['run_id', $dataset['run_id']],
|
||||||
|
['tenant', $dataset['tenant_code']],
|
||||||
|
['catalog_item_id', $dataset['catalog_item_id']],
|
||||||
|
['variant_id', $dataset['variant_id'] ?? 'sin variante (vigencia irrestricta)'],
|
||||||
|
['tickets', $dataset['tickets']],
|
||||||
|
['scanners', $dataset['scanners']],
|
||||||
|
['owners', $dataset['owners']],
|
||||||
|
['archivo', Storage::disk('local')->path($relativePath)],
|
||||||
|
]);
|
||||||
|
$this->warn('El archivo contiene tokens secretos. No lo subas al repositorio.');
|
||||||
|
$this->comment("Limpieza: php artisan tenants:reset-transactions {$dataset['tenant_code']}");
|
||||||
|
|
||||||
|
return self::SUCCESS;
|
||||||
|
},
|
||||||
|
)->purpose('Prepare disposable scanner tickets and a Postman performance dataset');
|
||||||
|
|
||||||
Artisan::command(
|
Artisan::command(
|
||||||
'tenants:reset-transactions
|
'tenants:reset-transactions
|
||||||
{tenant : Código del tenant que se limpiará}
|
{tenant : Código del tenant que se limpiará}
|
||||||
|
|||||||
@@ -1,308 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Forms;
|
|
||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Catalog\Services\CatalogService;
|
|
||||||
use App\Domains\Menu\Models\Menu;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Database\Seeders\AttributeSeeder;
|
|
||||||
use Database\Seeders\AuthorizationSeeder;
|
|
||||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Laravel\Sanctum\Sanctum;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AdminAppTicketFilterFormControllerTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->seed(AuthorizationSeeder::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_authentication_is_required(): void
|
|
||||||
{
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertUnauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_the_tenant_must_have_the_tickets_menu(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('tenant_without_tickets');
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_returns_the_common_ticket_filter_fields_for_other_tenants(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('another_tenant');
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/tickets-filter')
|
|
||||||
->assertOk()
|
|
||||||
->assertExactJson([
|
|
||||||
'data' => [
|
|
||||||
'code' => 'tickets_filter',
|
|
||||||
'action' => '/api/v1/adminapp/tenant/tickets',
|
|
||||||
'method' => 'GET',
|
|
||||||
'columns' => $this->commonColumns(),
|
|
||||||
'fields' => [
|
|
||||||
[
|
|
||||||
'name' => 'date',
|
|
||||||
'query_param' => 'date',
|
|
||||||
'label' => 'Fecha',
|
|
||||||
'type' => 'date',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'status',
|
|
||||||
'query_param' => 'status',
|
|
||||||
'label' => 'Estado',
|
|
||||||
'type' => 'select',
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
'placeholder' => 'Estado',
|
|
||||||
'options' => [
|
|
||||||
['value' => 'active', 'label' => 'Activo'],
|
|
||||||
['value' => 'used', 'label' => 'Usado'],
|
|
||||||
['value' => 'expired', 'label' => 'Vencido'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_returns_the_complete_nested_form_for_fiesta_futbol_infantil(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createFiestaFutbolInfantilTenant();
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.fields.0.name', 'category')
|
|
||||||
->assertJsonPath('data.fields.0.query_param', 'category')
|
|
||||||
->assertJsonPath('data.fields.1.name', 'product')
|
|
||||||
->assertJsonPath('data.fields.1.query_param', 'product')
|
|
||||||
->assertJsonPath('data.fields.1.depends_on', 'category')
|
|
||||||
->assertJsonPath('data.fields.2.name', 'type')
|
|
||||||
->assertJsonPath('data.fields.2.query_param', 'type')
|
|
||||||
->assertJsonPath('data.fields.2.depends_on', 'product')
|
|
||||||
->assertJsonPath('data.fields.3.name', 'date')
|
|
||||||
->assertJsonPath('data.fields.3.query_param', 'date')
|
|
||||||
->assertJsonPath('data.fields.4.name', 'status')
|
|
||||||
->assertJsonPath('data.fields.4.query_param', 'status')
|
|
||||||
->assertJsonPath('data.columns.0.key', 'order_number')
|
|
||||||
->assertJsonPath('data.columns.0.sort_param', 'order_number')
|
|
||||||
->assertJsonPath('data.columns.1.key', 'category')
|
|
||||||
->assertJsonPath('data.columns.2.key', 'product')
|
|
||||||
->assertJsonPath('data.columns.2.sortable', false)
|
|
||||||
->assertJsonPath('data.columns.3.key', 'type')
|
|
||||||
->assertJsonPath('data.columns.3.sortable', false);
|
|
||||||
|
|
||||||
$categories = collect($response->json('data.fields.0.options'));
|
|
||||||
$this->assertSame(
|
|
||||||
['Entradas', 'Camping', 'Comida', 'Merchandising'],
|
|
||||||
$categories->pluck('label')->all(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$entries = $categories->firstWhere('value', 'entradas');
|
|
||||||
$this->assertSame('Abono', $entries['children']['options'][0]['label']);
|
|
||||||
$this->assertTrue($entries['children']['options'][0]['children']['disabled']);
|
|
||||||
|
|
||||||
$camping = $categories->firstWhere('value', 'alojamientos');
|
|
||||||
$this->assertSame(
|
|
||||||
['Carpa', 'Motorhome'],
|
|
||||||
collect($camping['children']['options'])->pluck('label')->all(),
|
|
||||||
);
|
|
||||||
$this->assertTrue($camping['children']['options'][0]['children']['disabled']);
|
|
||||||
|
|
||||||
$merchandise = $categories->firstWhere('value', 'merchandising');
|
|
||||||
$this->assertSame('Camiseta', $merchandise['children']['options'][0]['label']);
|
|
||||||
$this->assertSame(
|
|
||||||
['Verde', 'Blanco'],
|
|
||||||
collect($merchandise['children']['options'][0]['children']['options'])->pluck('label')->all(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_a_food_schedule_is_only_returned_when_a_variant_exists_for_the_date(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createFiestaFutbolInfantilTenant();
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$date = $tenant->eventDates()->orderByDesc('date')->firstOrFail();
|
|
||||||
$food = CatalogItem::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('slug', 'comida')
|
|
||||||
->with([
|
|
||||||
'itemAttributes.attribute.options',
|
|
||||||
'variants.definitions.itemAttribute.attribute.options',
|
|
||||||
'variants.eventDates',
|
|
||||||
'variants.eventDate',
|
|
||||||
])
|
|
||||||
->firstOrFail();
|
|
||||||
|
|
||||||
$food->variants
|
|
||||||
->filter(fn ($variant): bool => $variant->selectedEventDates()->contains('id', $date->id)
|
|
||||||
&& $variant->selectionValues()->get('horario') === 'Almuerzo')
|
|
||||||
->each->delete();
|
|
||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
|
||||||
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
|
||||||
$dateProduct = collect($foodCategory['children']['options'])
|
|
||||||
->firstWhere('value', (string) $date->id);
|
|
||||||
$schedules = collect($dateProduct['children']['options'])->pluck('value');
|
|
||||||
|
|
||||||
$this->assertNotContains('Almuerzo', $schedules);
|
|
||||||
$this->assertContains('Desayuno', $schedules);
|
|
||||||
$this->assertContains('Cena', $schedules);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_a_deleted_food_variant_remains_in_the_filter_when_a_ticket_references_it(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createFiestaFutbolInfantilTenant();
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$food = CatalogItem::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('slug', 'comida')
|
|
||||||
->with([
|
|
||||||
'itemAttributes.attribute.options',
|
|
||||||
'variants.definitions.itemAttribute.attribute.options',
|
|
||||||
'variants.eventDates',
|
|
||||||
'variants.eventDate',
|
|
||||||
])
|
|
||||||
->firstOrFail();
|
|
||||||
$historicalVariant = $food->variants->first(function ($variant): bool {
|
|
||||||
return $variant->selectedEventDates()->first()?->date->format('d/m') === '12/10'
|
|
||||||
&& $variant->selectionValues()->get('horario') === 'Cena';
|
|
||||||
});
|
|
||||||
$this->assertNotNull($historicalVariant);
|
|
||||||
|
|
||||||
$ticket = Ticket::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'ticket' => (string) Str::uuid(),
|
|
||||||
'user_id' => $admin->id,
|
|
||||||
'source_catalog_item_id' => $food->id,
|
|
||||||
'source_variant_id' => $historicalVariant->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$catalogService = app(CatalogService::class);
|
|
||||||
foreach ($food->variants as $variant) {
|
|
||||||
$catalogService->deleteVariant($variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertTrue(CatalogItem::withTrashed()->findOrFail($food->id)->trashed());
|
|
||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
|
||||||
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
|
||||||
$products = collect($foodCategory['children']['options']);
|
|
||||||
|
|
||||||
$this->assertCount(1, $products);
|
|
||||||
$this->assertSame('12/10', $products->first()['label']);
|
|
||||||
$this->assertSame(
|
|
||||||
['Cena'],
|
|
||||||
collect($products->first()['children']['options'])->pluck('label')->all(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
|
||||||
'category' => 'comidas',
|
|
||||||
'product' => $products->first()['value'],
|
|
||||||
'type' => 'Cena',
|
|
||||||
]))
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $ticket->id)
|
|
||||||
->assertJsonPath('data.0.values.category', 'Comida')
|
|
||||||
->assertJsonPath('data.0.values.product', '12/10')
|
|
||||||
->assertJsonPath('data.0.values.type', 'Cena');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createFiestaFutbolInfantilTenant(): Tenant
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
|
||||||
|
|
||||||
return $tenant->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array<string, mixed>> */
|
|
||||||
private function commonColumns(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
['key' => 'order_number', 'label' => 'N° de orden', 'type' => 'order_number', 'sortable' => true, 'sort_param' => 'order_number', 'width' => '11%'],
|
|
||||||
['key' => 'product', 'label' => 'Producto', 'type' => 'text', 'sortable' => true, 'sort_param' => 'product', 'width' => '15%'],
|
|
||||||
['key' => 'amount', 'label' => 'Importe', 'type' => 'currency', 'sortable' => true, 'sort_param' => 'amount', 'width' => '10%'],
|
|
||||||
['key' => 'client', 'label' => 'Cliente', 'type' => 'text', 'sortable' => true, 'sort_param' => 'client', 'width' => '15%'],
|
|
||||||
['key' => 'id', 'label' => 'ID', 'type' => 'text', 'sortable' => true, 'sort_param' => 'id', 'width' => '8%'],
|
|
||||||
['key' => 'status', 'label' => 'Estado', 'type' => 'status', 'sortable' => true, 'sort_param' => 'status', 'width' => '8%'],
|
|
||||||
['key' => 'scanned_by', 'label' => 'Escaneado por', 'type' => 'text', 'sortable' => true, 'sort_param' => 'scanned_by', 'width' => '11%'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTenant(string $code): Tenant
|
|
||||||
{
|
|
||||||
$headerLogo = $this->createAttachment("{$code}-header.png");
|
|
||||||
$footerLogo = $this->createAttachment("{$code}-footer.png");
|
|
||||||
|
|
||||||
return Tenant::query()->create([
|
|
||||||
'codigo' => $code,
|
|
||||||
'nombre' => ucfirst($code),
|
|
||||||
'dominio' => "{$code}.test",
|
|
||||||
'primary_color' => '#111111',
|
|
||||||
'secondary_color' => '#222222',
|
|
||||||
'danger_color' => '#333333',
|
|
||||||
'success_color' => '#444444',
|
|
||||||
'header_bg_color' => '#ffffff',
|
|
||||||
'footer_bg_color' => '#ffffff',
|
|
||||||
'header_logo_id' => $headerLogo->id,
|
|
||||||
'footer_logo_id' => $footerLogo->id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAttachment(string $filename): Attachment
|
|
||||||
{
|
|
||||||
return Attachment::query()->create([
|
|
||||||
'path' => "tests/{$filename}",
|
|
||||||
'filename' => $filename,
|
|
||||||
'type' => AttachmentType::Image,
|
|
||||||
'mime_type' => 'image/png',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAdminAppUser(Tenant $tenant): User
|
|
||||||
{
|
|
||||||
return User::factory()->create([
|
|
||||||
'rol_codigo' => RoleCode::AdminApp->value,
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function grantTicketsMenu(Tenant $tenant): void
|
|
||||||
{
|
|
||||||
$menu = Menu::query()->create([
|
|
||||||
'code' => 'adminapp.tickets',
|
|
||||||
'label' => 'Tickets',
|
|
||||||
'route' => '/admin/tickets',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$tenant->menues()->attach($menu->code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Forms;
|
|
||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use Database\Seeders\AttributeSeeder;
|
|
||||||
use Database\Seeders\AuthorizationSeeder;
|
|
||||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Laravel\Sanctum\Sanctum;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AdminAppTicketFormControllerTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->seed(AuthorizationSeeder::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_authentication_is_required(): void
|
|
||||||
{
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
|
||||||
->assertUnauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_returns_nested_ticket_options_using_the_frontend_presentation_mapping(): void
|
|
||||||
{
|
|
||||||
$headerLogo = $this->createAttachment('header.png');
|
|
||||||
$footerLogo = $this->createAttachment('footer.png');
|
|
||||||
$tenant = Tenant::query()->create([
|
|
||||||
'codigo' => 'fiesta_futbol_infantil',
|
|
||||||
'nombre' => 'Fiesta Fútbol Infantil',
|
|
||||||
'dominio' => 'fiesta-futbol-infantil.test',
|
|
||||||
'primary_color' => '#00973F',
|
|
||||||
'secondary_color' => '#A0A0A0',
|
|
||||||
'danger_color' => '#FF8888',
|
|
||||||
'success_color' => '#198754',
|
|
||||||
'header_bg_color' => '#ffffff',
|
|
||||||
'footer_bg_color' => '#015327',
|
|
||||||
'header_logo_id' => $headerLogo->id,
|
|
||||||
'footer_logo_id' => $footerLogo->id,
|
|
||||||
]);
|
|
||||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
|
||||||
|
|
||||||
Sanctum::actingAs(User::factory()->create([
|
|
||||||
'rol_codigo' => RoleCode::AdminApp->value,
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
]));
|
|
||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
|
||||||
->assertOk()
|
|
||||||
->assertExactJson([
|
|
||||||
'data' => [
|
|
||||||
'statuses' => [
|
|
||||||
['value' => 'active', 'label' => 'Activo'],
|
|
||||||
['value' => 'used', 'label' => 'Usado'],
|
|
||||||
['value' => 'expired', 'label' => 'Vencido'],
|
|
||||||
],
|
|
||||||
'categories' => [
|
|
||||||
[
|
|
||||||
'value' => 'entradas',
|
|
||||||
'label' => 'Entradas',
|
|
||||||
'products' => [[
|
|
||||||
'value' => 'abono',
|
|
||||||
'label' => 'Abono',
|
|
||||||
'types' => [],
|
|
||||||
]],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => 'alojamientos',
|
|
||||||
'label' => 'Camping',
|
|
||||||
'products' => [
|
|
||||||
['value' => 'Carpa', 'label' => 'Carpa', 'types' => []],
|
|
||||||
['value' => 'Motorhome', 'label' => 'Motorhome', 'types' => []],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => 'comidas',
|
|
||||||
'label' => 'Comida',
|
|
||||||
'products' => [
|
|
||||||
[
|
|
||||||
'value' => (string) $tenant->eventDates[0]->id,
|
|
||||||
'label' => '09/10',
|
|
||||||
'types' => [
|
|
||||||
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
|
||||||
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
|
||||||
['value' => 'Cena', 'label' => 'Cena'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => (string) $tenant->eventDates[1]->id,
|
|
||||||
'label' => '10/10',
|
|
||||||
'types' => [
|
|
||||||
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
|
||||||
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
|
||||||
['value' => 'Cena', 'label' => 'Cena'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => (string) $tenant->eventDates[2]->id,
|
|
||||||
'label' => '11/10',
|
|
||||||
'types' => [
|
|
||||||
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
|
||||||
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
|
||||||
['value' => 'Cena', 'label' => 'Cena'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => (string) $tenant->eventDates[3]->id,
|
|
||||||
'label' => '12/10',
|
|
||||||
'types' => [
|
|
||||||
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
|
||||||
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
|
||||||
['value' => 'Cena', 'label' => 'Cena'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'value' => 'merchandising',
|
|
||||||
'label' => 'Merchandising',
|
|
||||||
'products' => [[
|
|
||||||
'value' => 'camiseta',
|
|
||||||
'label' => 'Camiseta',
|
|
||||||
'types' => [
|
|
||||||
['value' => 'Verde', 'label' => 'Verde'],
|
|
||||||
['value' => 'Blanco', 'label' => 'Blanco'],
|
|
||||||
],
|
|
||||||
]],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertJsonMissingPath('data.categories.0.products.0.category');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAttachment(string $filename): Attachment
|
|
||||||
{
|
|
||||||
return Attachment::query()->create([
|
|
||||||
'path' => "tests/{$filename}",
|
|
||||||
'filename' => $filename,
|
|
||||||
'type' => AttachmentType::Image,
|
|
||||||
'mime_type' => 'image/png',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,6 @@ class MenuSeederTest extends TestCase
|
|||||||
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenus = [
|
$fiestaCategoryMenus = [
|
||||||
'adminapp.tickets' => ['Tickets', '/admin/tickets'],
|
|
||||||
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
||||||
@@ -50,11 +49,7 @@ class MenuSeederTest extends TestCase
|
|||||||
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
||||||
$this->assertSame('/', $adminApp->route);
|
$this->assertSame('/', $adminApp->route);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
collect(array_keys([
|
array_keys([...$expectedMenus, ...$fiestaCategoryMenus]),
|
||||||
...$expectedMenus,
|
|
||||||
...$fiestaCategoryMenus,
|
|
||||||
'adminapp.desfile.entradas' => ['Entradas', '/admin/desfile/entradas'],
|
|
||||||
]))->sort()->values()->all(),
|
|
||||||
$adminApp->children->pluck('code')->sort()->values()->all()
|
$adminApp->children->pluck('code')->sort()->values()->all()
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
|
|||||||
@@ -1,458 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Ticket;
|
|
||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
|
||||||
use App\Domains\Catalog\Models\Attribute;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Catalog\Models\Inventory;
|
|
||||||
use App\Domains\Catalog\Models\Variant;
|
|
||||||
use App\Domains\Menu\Models\Menu;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
|
||||||
use App\Domains\Shared\Enums\FieldType;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Barryvdh\DomPDF\ServiceProvider as DomPdfServiceProvider;
|
|
||||||
use Database\Seeders\AttributeSeeder;
|
|
||||||
use Database\Seeders\AuthorizationSeeder;
|
|
||||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Laravel\Sanctum\Sanctum;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AdminAppTicketControllerTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->app->register(DomPdfServiceProvider::class);
|
|
||||||
|
|
||||||
$this->seed(AuthorizationSeeder::class);
|
|
||||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_authentication_is_required(): void
|
|
||||||
{
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertUnauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_the_tenant_must_have_the_tickets_menu(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_lists_only_tickets_from_the_authenticated_tenant(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$otherTenant = $this->createTenant('other');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$otherUser = $this->createAdminAppUser($otherTenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$ticket = $this->createTicket($tenant, $admin);
|
|
||||||
$this->createTicket($otherTenant, $otherUser);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $ticket->id)
|
|
||||||
->assertJsonPath('data.0.tenant_code', $tenant->codigo)
|
|
||||||
->assertJsonPath('data.0.values.id', $ticket->id)
|
|
||||||
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
|
|
||||||
->assertJsonMissingPath('data.0.values.ticket')
|
|
||||||
->assertJsonMissingPath('data.0.values.date')
|
|
||||||
->assertJsonMissingPath('data.0.date')
|
|
||||||
->assertJsonPath('meta.total', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_supports_id_and_uuid_search(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$matching = $this->createTicket($tenant, $admin);
|
|
||||||
$this->createTicket($tenant, $admin);
|
|
||||||
|
|
||||||
$this->getJson("/api/v1/adminapp/tenant/tickets?q={$matching->id}")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $matching->id);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?q='.substr($matching->ticket, 0, 8))
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.ticket', $matching->ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_sorts_by_ticket_id_before_paginating(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$ids = collect(range(1, 4))
|
|
||||||
->map(fn (): int => $this->createTicket($tenant, $admin)->id)
|
|
||||||
->all();
|
|
||||||
|
|
||||||
$query = http_build_query([
|
|
||||||
'sort_by' => 'id',
|
|
||||||
'sort_direction' => 'asc',
|
|
||||||
'per_page' => 2,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query)
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.0.values.id', $ids[0])
|
|
||||||
->assertJsonPath('data.1.values.id', $ids[1])
|
|
||||||
->assertJsonPath('meta.total', 4)
|
|
||||||
->assertJsonPath('meta.last_page', 2);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query.'&page=2')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.0.values.id', $ids[2])
|
|
||||||
->assertJsonPath('data.1.values.id', $ids[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_rejects_sort_columns_not_enabled_for_the_tenant(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('other');
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?sort_by=category&sort_direction=sideways')
|
|
||||||
->assertUnprocessable()
|
|
||||||
->assertJsonValidationErrors(['sort_by', 'sort_direction']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_rejects_product_and_type_sorting_for_fiesta_futbol_infantil(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
foreach (['product', 'type'] as $column) {
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?sort_by='.$column)
|
|
||||||
->assertUnprocessable()
|
|
||||||
->assertJsonValidationErrors('sort_by');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_includes_tenant_scanned_and_total_ticket_counts(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$otherTenant = $this->createTenant('other');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$otherUser = $this->createAdminAppUser($otherTenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$this->createTicket($tenant, $admin)->update(['used_at' => now()]);
|
|
||||||
$this->createTicket($tenant, $admin);
|
|
||||||
$this->createTicket($otherTenant, $otherUser)->update(['used_at' => now()]);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?q=does-not-match')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(0, 'data')
|
|
||||||
->assertJsonPath('scanned_tickets', 0)
|
|
||||||
->assertJsonPath('total_tickets', 0);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('scanned_tickets', 1)
|
|
||||||
->assertJsonPath('total_tickets', 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_returns_structured_variant_properties(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$item = CatalogItem::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'slug' => 'remera',
|
|
||||||
'nombre' => 'Remera',
|
|
||||||
'precio' => '8000.00',
|
|
||||||
'has_tickets' => true,
|
|
||||||
]);
|
|
||||||
$attribute = Attribute::query()->create([
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
'codigo' => 'size',
|
|
||||||
'nombre' => 'Talle',
|
|
||||||
'type' => FieldType::Select,
|
|
||||||
]);
|
|
||||||
$attribute->options()->create(['value' => 'xl', 'label' => 'XL']);
|
|
||||||
$itemAttribute = $item->itemAttributes()->create([
|
|
||||||
'attribute_id' => $attribute->id,
|
|
||||||
'sort_order' => 1,
|
|
||||||
]);
|
|
||||||
$variant = Variant::query()->create([
|
|
||||||
'catalog_item_id' => $item->id,
|
|
||||||
'inventory_id' => Inventory::query()->create()->id,
|
|
||||||
]);
|
|
||||||
$variant->definitions()->create([
|
|
||||||
'item_attribute_id' => $itemAttribute->id,
|
|
||||||
'value' => 'xl',
|
|
||||||
]);
|
|
||||||
$purchase = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
'user_id' => $admin->id,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'nombre_apellido' => 'Nombre Apellido',
|
|
||||||
'total' => '8000.00',
|
|
||||||
]);
|
|
||||||
PurchaseItem::query()->create([
|
|
||||||
'compra_id' => $purchase->id,
|
|
||||||
'source_catalog_item_id' => $item->id,
|
|
||||||
'source_variant_id' => $variant->id,
|
|
||||||
'nombre' => 'Remera',
|
|
||||||
'descripcion' => '',
|
|
||||||
'slug' => 'remera',
|
|
||||||
'item_nombre' => 'Remera',
|
|
||||||
'cantidad' => 1,
|
|
||||||
'precio_unitario' => '8000.00',
|
|
||||||
'total' => '8000.00',
|
|
||||||
]);
|
|
||||||
$ticket = $this->createTicket($tenant, $admin, [
|
|
||||||
'source_purchase_id' => $purchase->id,
|
|
||||||
'source_catalog_item_id' => $item->id,
|
|
||||||
'source_variant_id' => $variant->id,
|
|
||||||
'scanner_user_id' => $admin->id,
|
|
||||||
'used_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.0.id', $ticket->id)
|
|
||||||
->assertJsonPath('data.0.order_number', $purchase->id)
|
|
||||||
->assertJsonPath('data.0.product', 'Remera')
|
|
||||||
->assertJsonPath('data.0.amount', '8000.00')
|
|
||||||
->assertJsonPath('data.0.status', Ticket::STATUS_USED)
|
|
||||||
->assertJsonPath('data.0.scanned_by', $admin->nombre_apellido)
|
|
||||||
->assertJsonPath('data.0.variant_properties.0.code', 'size')
|
|
||||||
->assertJsonPath('data.0.variant_properties.0.label', 'Talle')
|
|
||||||
->assertJsonPath('data.0.variant_properties.0.values.0.value', 'xl')
|
|
||||||
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_applies_the_ticket_filter_form_values(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$date = $tenant->eventDates()->orderByDesc('date')->firstOrFail();
|
|
||||||
$food = CatalogItem::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('slug', 'comida')
|
|
||||||
->with([
|
|
||||||
'variants.definitions.itemAttribute.attribute.options',
|
|
||||||
'variants.eventDates',
|
|
||||||
'variants.eventDate',
|
|
||||||
])
|
|
||||||
->firstOrFail();
|
|
||||||
$dinner = $food->variants->first(fn (Variant $variant): bool => $variant
|
|
||||||
->selectedEventDates()->contains('id', $date->id)
|
|
||||||
&& $variant->selectionValues()->get('horario') === 'Cena');
|
|
||||||
$lunch = $food->variants->first(fn (Variant $variant): bool => $variant
|
|
||||||
->selectedEventDates()->contains('id', $date->id)
|
|
||||||
&& $variant->selectionValues()->get('horario') === 'Almuerzo');
|
|
||||||
$this->assertNotNull($dinner);
|
|
||||||
$this->assertNotNull($lunch);
|
|
||||||
|
|
||||||
$matchingPurchase = $this->createPurchase($tenant, $admin, '2026-08-20 10:00:00');
|
|
||||||
$otherPurchase = $this->createPurchase($tenant, $admin, '2026-08-21 10:00:00');
|
|
||||||
$matching = $this->createTicket($tenant, $admin, [
|
|
||||||
'source_purchase_id' => $matchingPurchase->id,
|
|
||||||
'source_catalog_item_id' => $food->id,
|
|
||||||
'source_variant_id' => $dinner->id,
|
|
||||||
'used_at' => now(),
|
|
||||||
]);
|
|
||||||
$this->createTicket($tenant, $admin, [
|
|
||||||
'source_purchase_id' => $matchingPurchase->id,
|
|
||||||
'source_catalog_item_id' => $food->id,
|
|
||||||
'source_variant_id' => $lunch->id,
|
|
||||||
'used_at' => now(),
|
|
||||||
]);
|
|
||||||
$this->createTicket($tenant, $admin, [
|
|
||||||
'source_purchase_id' => $otherPurchase->id,
|
|
||||||
'source_catalog_item_id' => $food->id,
|
|
||||||
'source_variant_id' => $dinner->id,
|
|
||||||
'used_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
|
||||||
'category' => 'comidas',
|
|
||||||
'product' => (string) $date->id,
|
|
||||||
'type' => 'Cena',
|
|
||||||
'date' => '2026-08-20',
|
|
||||||
'status' => Ticket::STATUS_USED,
|
|
||||||
]))
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $matching->id)
|
|
||||||
->assertJsonPath('scanned_tickets', 1)
|
|
||||||
->assertJsonPath('total_tickets', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_filters_computed_active_and_expired_statuses(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$food = CatalogItem::query()
|
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->where('slug', 'comida')
|
|
||||||
->with('variants')
|
|
||||||
->firstOrFail();
|
|
||||||
$expired = $this->createTicket($tenant, $admin, [
|
|
||||||
'source_catalog_item_id' => $food->id,
|
|
||||||
'source_variant_id' => $food->variants->firstOrFail()->id,
|
|
||||||
]);
|
|
||||||
$active = $this->createTicket($tenant, $admin);
|
|
||||||
|
|
||||||
$this->travelTo('2026-10-20 12:00:00');
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?status=expired')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $expired->id);
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?status=active')
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(1, 'data')
|
|
||||||
->assertJsonPath('data.0.id', $active->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_downloads_filtered_ticket_reports(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($admin);
|
|
||||||
|
|
||||||
$ticket = $this->createTicket($tenant, $admin);
|
|
||||||
$query = http_build_query([
|
|
||||||
'q' => (string) $ticket->id,
|
|
||||||
'timezone' => 'America/Argentina/Buenos_Aires',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->get('/api/v1/adminapp/tenant/tickets/pdf?'.$query)
|
|
||||||
->assertOk()
|
|
||||||
->assertHeader('content-type', 'application/pdf');
|
|
||||||
|
|
||||||
$this->get('/api/v1/adminapp/tenant/tickets/excel?'.$query)
|
|
||||||
->assertOk()
|
|
||||||
->assertHeader(
|
|
||||||
'content-type',
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_ticket_reports_require_a_valid_timezone(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
|
||||||
$this->grantTicketsMenu($tenant);
|
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets/pdf')->assertUnprocessable();
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets/excel?timezone=Invalid')
|
|
||||||
->assertUnprocessable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTenant(string $code): Tenant
|
|
||||||
{
|
|
||||||
$headerLogo = $this->createAttachment("{$code}-header.png");
|
|
||||||
$footerLogo = $this->createAttachment("{$code}-footer.png");
|
|
||||||
|
|
||||||
return Tenant::query()->create([
|
|
||||||
'codigo' => $code,
|
|
||||||
'nombre' => ucfirst($code),
|
|
||||||
'dominio' => "{$code}.test",
|
|
||||||
'website_type_code' => 'onticket',
|
|
||||||
'primary_color' => '#111111',
|
|
||||||
'secondary_color' => '#222222',
|
|
||||||
'danger_color' => '#333333',
|
|
||||||
'success_color' => '#444444',
|
|
||||||
'header_bg_color' => '#ffffff',
|
|
||||||
'footer_bg_color' => '#ffffff',
|
|
||||||
'header_logo_id' => $headerLogo->id,
|
|
||||||
'footer_logo_id' => $footerLogo->id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAttachment(string $filename): Attachment
|
|
||||||
{
|
|
||||||
return Attachment::query()->create([
|
|
||||||
'path' => "test/{$filename}",
|
|
||||||
'filename' => $filename,
|
|
||||||
'type' => AttachmentType::Image,
|
|
||||||
'mime_type' => 'image/png',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAdminAppUser(Tenant $tenant): User
|
|
||||||
{
|
|
||||||
return User::factory()->create([
|
|
||||||
'rol_codigo' => RoleCode::AdminApp->value,
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createPurchase(Tenant $tenant, User $user, string $createdAt): Purchase
|
|
||||||
{
|
|
||||||
$purchase = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'nombre_apellido' => $user->nombre_apellido,
|
|
||||||
'total' => '0.00',
|
|
||||||
]);
|
|
||||||
$purchase->forceFill(['created_at' => $createdAt, 'updated_at' => $createdAt])->saveQuietly();
|
|
||||||
|
|
||||||
return $purchase;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function grantTicketsMenu(Tenant $tenant): void
|
|
||||||
{
|
|
||||||
$menu = Menu::query()->create([
|
|
||||||
'code' => 'adminapp.tickets',
|
|
||||||
'label' => 'Tickets',
|
|
||||||
'route' => '/admin/tickets',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$tenant->menues()->attach($menu->code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $attributes */
|
|
||||||
private function createTicket(Tenant $tenant, User $user, array $attributes = []): Ticket
|
|
||||||
{
|
|
||||||
return Ticket::query()->create(array_merge([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'ticket' => (string) Str::uuid(),
|
|
||||||
'user_id' => $user->id,
|
|
||||||
], $attributes));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
107
tests/Feature/Ticket/PrepareLoadTestTicketsCommandTest.php
Normal file
107
tests/Feature/Ticket/PrepareLoadTestTicketsCommandTest.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Ticket;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Category;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class PrepareLoadTestTicketsCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_generates_a_postman_dataset_that_can_scan_the_tickets(): void
|
||||||
|
{
|
||||||
|
Storage::fake('local');
|
||||||
|
$this->seed(AuthorizationSeeder::class);
|
||||||
|
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||||
|
$tenant = $this->createTenant('acme');
|
||||||
|
$category = Category::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'nombre' => 'Entradas de carga',
|
||||||
|
]);
|
||||||
|
$catalogItem = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'category_id' => $category->id,
|
||||||
|
'slug' => 'entrada-load-test',
|
||||||
|
'nombre' => 'Entrada load test',
|
||||||
|
'descripcion' => 'Ticket descartable',
|
||||||
|
'precio' => 100,
|
||||||
|
'has_tickets' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$exitCode = Artisan::call('load-test:tickets:prepare', [
|
||||||
|
'tenant' => $tenant->codigo,
|
||||||
|
'--tickets' => 4,
|
||||||
|
'--scanners' => 2,
|
||||||
|
'--owners' => 2,
|
||||||
|
'--catalog-item' => $catalogItem->id,
|
||||||
|
'--run' => 'test-run',
|
||||||
|
'--output' => 'load-tests/test-run.postman.json',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $exitCode, Artisan::output());
|
||||||
|
|
||||||
|
Storage::disk('local')->assertExists('load-tests/test-run.postman.json');
|
||||||
|
$rows = json_decode(
|
||||||
|
Storage::disk('local')->get('load-tests/test-run.postman.json'),
|
||||||
|
true,
|
||||||
|
flags: JSON_THROW_ON_ERROR,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(4, $rows);
|
||||||
|
$this->assertCount(4, collect($rows)->pluck('ticket_uuid')->unique());
|
||||||
|
$this->assertCount(2, collect($rows)->pluck('scanner_token')->unique());
|
||||||
|
$this->assertSame([200], collect($rows)->pluck('expected_status')->unique()->values()->all());
|
||||||
|
$this->assertDatabaseCount('tickets', 4);
|
||||||
|
$this->assertCount(2, Ticket::query()->distinct()->pluck('user_id'));
|
||||||
|
$this->assertDatabaseCount('category_scanners', 2);
|
||||||
|
|
||||||
|
$first = $rows[0];
|
||||||
|
$this->withToken($first['scanner_token'])
|
||||||
|
->postJson("/api/v1/scanner/tickets/{$first['ticket_uuid']}/scan")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.ticket', $first['ticket_uuid']);
|
||||||
|
|
||||||
|
$this->assertNotNull(
|
||||||
|
Ticket::query()->where('ticket', $first['ticket_uuid'])->firstOrFail()->used_at
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$logo = Attachment::query()->create([
|
||||||
|
'key' => (string) Str::uuid(),
|
||||||
|
'path' => "tests/{$code}-logo.png",
|
||||||
|
'filename' => "{$code}-logo.png",
|
||||||
|
'type' => 'image',
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
'extension' => 'png',
|
||||||
|
'size' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => ucfirst($code),
|
||||||
|
'dominio' => "{$code}.test",
|
||||||
|
'primary_color' => '#ff7006',
|
||||||
|
'secondary_color' => '#777777',
|
||||||
|
'danger_color' => '#e04a4a',
|
||||||
|
'success_color' => '#81bc73',
|
||||||
|
'header_bg_color' => '#313131',
|
||||||
|
'footer_bg_color' => '#313131',
|
||||||
|
'header_logo_id' => $logo->id,
|
||||||
|
'footer_logo_id' => $logo->id,
|
||||||
|
'website_type_code' => 'onticket',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,22 +8,17 @@ use RuntimeException;
|
|||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Boot the application only when the test database is explicitly isolated.
|
|
||||||
*/
|
|
||||||
public function createApplication(): Application
|
public function createApplication(): Application
|
||||||
{
|
{
|
||||||
$app = parent::createApplication();
|
$app = parent::createApplication();
|
||||||
|
$connection = (string) $app['config']->get('database.default');
|
||||||
|
$database = (string) $app['config']->get("database.connections.{$connection}.database");
|
||||||
|
$usesInMemorySqlite = $connection === 'sqlite' && $database === ':memory:';
|
||||||
|
|
||||||
$database = (string) $app['config']->get(
|
if (! $usesInMemorySqlite && ! str_ends_with(strtolower($database), '_test')) {
|
||||||
'database.connections.'.$app['config']->get('database.default').'.database'
|
throw new RuntimeException(
|
||||||
|
"Unsafe test database [{$database}]. Tests may only use an in-memory SQLite database or a database ending in _test.",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! preg_match('/^shopit_(?:test|testing)(?:_\d+)?$/', $database)) {
|
|
||||||
throw new RuntimeException(sprintf(
|
|
||||||
'Refusing to run tests against database [%s]. Use [shopit_test] or [shopit_testing].',
|
|
||||||
$database !== '' ? $database : '(empty)'
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Ticket;
|
|
||||||
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketColumnService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketExcelService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketPdfService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketReportService;
|
|
||||||
use App\Domains\Ticket\Services\AdminAppTicketRowService;
|
|
||||||
use Barryvdh\DomPDF\ServiceProvider;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Mockery;
|
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AdminAppTicketExportServiceTest extends TestCase
|
|
||||||
{
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->app->register(ServiceProvider::class);
|
|
||||||
Carbon::setTestNow(Carbon::parse('2026-08-24 17:53:00', 'UTC'));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
|
||||||
{
|
|
||||||
Carbon::setTestNow();
|
|
||||||
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_downloads_the_ticket_report_as_an_excel_file(): void
|
|
||||||
{
|
|
||||||
$response = (new AdminAppTicketExcelService($this->reportService(), $this->columnService()))
|
|
||||||
->download($this->tenant(), collect(), 'America/La_Paz');
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
$response->headers->get('content-type'),
|
|
||||||
);
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
'attachment; filename=tickets_fiesta_futbol_infantil_20260824_135300.xlsx',
|
|
||||||
(string) $response->headers->get('content-disposition'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$path = $this->spreadsheetPath($response);
|
|
||||||
try {
|
|
||||||
$sheet = IOFactory::load($path)->getActiveSheet();
|
|
||||||
|
|
||||||
$this->assertSame('Tickets', $sheet->getTitle());
|
|
||||||
$this->assertSame('N° de orden', $sheet->getCell('A1')->getValue());
|
|
||||||
$this->assertSame('#15', $sheet->getCell('A2')->getValue());
|
|
||||||
$this->assertSame('Cena', $sheet->getCell('D2')->getValue());
|
|
||||||
$this->assertSame(8000.0, $sheet->getCell('E2')->getValue());
|
|
||||||
$this->assertSame('25', $sheet->getCell('G2')->getValue());
|
|
||||||
$this->assertSame('Usado', $sheet->getCell('H2')->getValue());
|
|
||||||
} finally {
|
|
||||||
@unlink($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_downloads_the_ticket_report_as_a_pdf(): void
|
|
||||||
{
|
|
||||||
$response = (new AdminAppTicketPdfService($this->reportService(), $this->columnService()))
|
|
||||||
->download($this->tenant(), collect(), 'America/La_Paz');
|
|
||||||
|
|
||||||
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
'attachment; filename=tickets_fiesta_futbol_infantil_20260824_135300.pdf',
|
|
||||||
(string) $response->headers->get('content-disposition'),
|
|
||||||
);
|
|
||||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_the_pdf_view_contains_the_report_data_and_requested_timezone(): void
|
|
||||||
{
|
|
||||||
$columns = $this->columnService()->columns($this->tenant());
|
|
||||||
$html = view('pdf.adminapp.tickets', [
|
|
||||||
'tenant' => $this->tenant(),
|
|
||||||
'columns' => $columns,
|
|
||||||
'tickets' => (new AdminAppTicketRowService)->displayRows(
|
|
||||||
collect([$this->row()]),
|
|
||||||
$columns,
|
|
||||||
'America/La_Paz',
|
|
||||||
),
|
|
||||||
'generatedAt' => now(),
|
|
||||||
'timeZone' => 'America/La_Paz',
|
|
||||||
])->render();
|
|
||||||
|
|
||||||
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $html);
|
|
||||||
$this->assertStringContainsString('25', $html);
|
|
||||||
$this->assertStringNotContainsString('00000000-0000-0000-0000-000000000001', $html);
|
|
||||||
$this->assertStringContainsString('Cena', $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function reportService(): AdminAppTicketReportService
|
|
||||||
{
|
|
||||||
$rowService = Mockery::mock(AdminAppTicketRowService::class)->makePartial();
|
|
||||||
$rowService->shouldReceive('rows')->once()->andReturn(collect([$this->row()]));
|
|
||||||
|
|
||||||
return new AdminAppTicketReportService($rowService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
private function row(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'order_number' => 15,
|
|
||||||
'category' => 'Comida',
|
|
||||||
'product' => '12/10',
|
|
||||||
'type' => 'Cena',
|
|
||||||
'amount' => 8000.0,
|
|
||||||
'client' => 'Cliente Test',
|
|
||||||
'id' => 25,
|
|
||||||
'status' => 'used',
|
|
||||||
'scanned_by' => 'Admin Test',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function tenant(): Tenant
|
|
||||||
{
|
|
||||||
return (new Tenant)->forceFill([
|
|
||||||
'codigo' => 'fiesta_futbol_infantil',
|
|
||||||
'nombre' => 'Fiesta del Fútbol Infantil',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function columnService(): AdminAppTicketColumnService
|
|
||||||
{
|
|
||||||
return new AdminAppTicketColumnService;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function spreadsheetPath(StreamedResponse $response): string
|
|
||||||
{
|
|
||||||
ob_start();
|
|
||||||
($response->getCallback())();
|
|
||||||
$contents = ob_get_clean();
|
|
||||||
$this->assertIsString($contents);
|
|
||||||
$this->assertStringStartsWith('PK', $contents);
|
|
||||||
|
|
||||||
$path = tempnam(sys_get_temp_dir(), 'shopit_ticket_excel_');
|
|
||||||
$this->assertNotFalse($path);
|
|
||||||
file_put_contents($path, $contents);
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user